Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Uzi-Granot committed Jul 16, 2019
1 parent fe54adb commit 1d8da40
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 88 deletions.
7 changes: 6 additions & 1 deletion PdfFileWriter/FontApi.cs
Expand Up @@ -1020,11 +1020,13 @@ public WinTextMetric GetTextMetricsApi()
/// <summary>
/// Gets font data tables
/// </summary>
/// <param name="TableTag">Table Tag</param>
/// <param name="Offset">Table offset</param>
/// <param name="BufSize">Table size</param>
/// <returns>Table info as byte array</returns>
public byte[] GetFontDataApi
(
uint TableTag,
int Offset,
int BufSize
)
Expand All @@ -1035,8 +1037,11 @@ int BufSize
// allocate buffer to receive outline text metrics information
AllocateBuffer((int) BufSize);

// microsoft tag is in little endian format
uint MSTag = TableTag << 24 | (TableTag << 8) & 0xff0000 | (TableTag >> 8) & 0xff00 | (TableTag >> 24) & 0xff;

// get outline text metrics information
if((int) GetFontData(GDIHandle, 0, (uint) Offset, Buffer, (uint) BufSize) != BufSize) ThrowSystemErrorException("Get font data file header failed");
if((int) GetFontData(GDIHandle, MSTag, (uint) Offset, Buffer, (uint) BufSize) != BufSize) ThrowSystemErrorException("Get font data file header failed");

// copy api result buffer to managed memory buffer
byte[] DataBuffer = new byte[BufSize];
Expand Down
30 changes: 20 additions & 10 deletions PdfFileWriter/PdfDocument.cs
Expand Up @@ -153,6 +153,10 @@
// Add support for sticky notes.
// Version 1.24.0 2019/06/06
// Support for layers control of images and annotations.
// Version 1.24.1 2019/06/20
// Add meter as unit of measue and fix version number and data strings.
// Version 1.25.0 2019/07/15
// Support for collection of fonts. Support for non ascii font names
//
/////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -194,6 +198,11 @@ public enum UnitOfMeasure
/// MM
/// </summary>
mm,

/// <summary>
/// Meter
/// </summary>
m,
}

/////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -338,12 +347,12 @@ public class PdfDocument : IDisposable
/// <summary>
/// Library revision number
/// </summary>
public static readonly string RevisionNumber = "1.23.0";
public static readonly string RevisionNumber = "1.25.0";

/// <summary>
/// Library revision date
/// </summary>
public static readonly string RevisionDate = "2019/05/26";
public static readonly string RevisionDate = "2019/07/15";

/// <summary>
/// Scale factor
Expand Down Expand Up @@ -444,6 +453,7 @@ int Index
72.0, // Inch
72.0 / 2.54, // cm
72.0 / 25.4, // mm
72.0 / 0.0254, // meter
};

// standard paper sizes (in points)
Expand Down Expand Up @@ -586,15 +596,15 @@ Stream Stream
/// as per width and height arguments in user units.</para>
/// <para>Page orientation is portrait if width is less than height.
/// Otherwise it is landscape.</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm)</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm, m)</para>
/// <para>The PDF document will be saved in a file named FileName.</para>
/// </remarks>
////////////////////////////////////////////////////////////////////
public PdfDocument
(
double Width, // page width
double Height, // page height
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm, m
string FileName
)
{
Expand All @@ -617,7 +627,7 @@ string FileName
/// as per width and height arguments in user units.</para>
/// <para>Page orientation is portrait if width is less than height.
/// Otherwise it is landscape.</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm)</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm, m)</para>
/// <para>The PDF document will be saved in the stream argument. The stream can
/// be either a MemoryStream or a FileStream. It is the calling program
/// responsibiliy to close the stream after CreateFile() method
Expand All @@ -628,7 +638,7 @@ public PdfDocument
(
double Width, // page width
double Height, // page height
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm, m
Stream Stream
)
{
Expand All @@ -650,15 +660,15 @@ Stream Stream
/// <para>This constructor generates a document with default page size
/// of Letter, Leagal, A3, A4 or A5.</para>
/// <para>Page orientation is determined by the landscape argument.</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm)</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm, m)</para>
/// <para>The PDF document will be saved in a file named FileName.</para>
/// </remarks>
////////////////////////////////////////////////////////////////////
public PdfDocument
(
PaperType PaperType,
bool Landscape,
UnitOfMeasure UnitOfMeasure,
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm, m
string FileName
)
{
Expand All @@ -685,7 +695,7 @@ string FileName
/// <para>This constructor generates a document with default page size
/// of Letter, Leagal, A3, A4 or A5.</para>
/// <para>Page orientation is determined by the landscape argument.</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm)</para>
/// <para>Unit of measure is a an enumeration constant (Point, Inch, cm, mm, m)</para>
/// <para>The PDF document will be saved in the stream argument. The stream can
/// be either a MemoryStream or a FileStream. It is the calling program
/// responsibiliy to close the stream after CreateFile() method
Expand All @@ -696,7 +706,7 @@ public PdfDocument
(
PaperType PaperType,
bool Landscape,
UnitOfMeasure UnitOfMeasure,
UnitOfMeasure UnitOfMeasure, // unit of measure: Point, Inch, cm, mm, m
Stream Stream
)
{
Expand Down
59 changes: 31 additions & 28 deletions PdfFileWriter/PdfFont.cs
Expand Up @@ -104,15 +104,15 @@ public class KerningAdjust
/// <summary>
/// Gets or sets Text
/// </summary>
public string Text {get; set;}
public string Text {get; set;}

/// <summary>
/// Gets or sets adjustment
/// </summary>
/// <remarks>
/// Adjustment units are in PDF design unit. To convert to user units: Adjust * FontSize / (1000.0 * ScaleFactor)
/// </remarks>
public double Adjust {get; set;}
public double Adjust {get; set;}

/// <summary>
/// Kerning adjustment constructor
Expand All @@ -121,8 +121,8 @@ public class KerningAdjust
/// <param name="Adjust">Adjustment</param>
public KerningAdjust
(
string Text,
double Adjust
string Text,
double Adjust
)
{
this.Text = Text;
Expand Down Expand Up @@ -194,10 +194,10 @@ public class PdfFont : PdfObject, IDisposable, IComparable<PdfFont>

public static PdfFont CreatePdfFont
(
PdfDocument Document, // PDF document main object
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
PdfDocument Document, // PDF document main object
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
)
{
if(Document.FontArray == null) Document.FontArray = new List<PdfFont>();
Expand All @@ -211,9 +211,9 @@ public static PdfFont CreatePdfFont
// for search only
private PdfFont
(
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
)
{
// save parameters
Expand All @@ -225,10 +225,10 @@ private PdfFont

private PdfFont
(
PdfDocument Document, // PDF document main object
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
PdfDocument Document, // PDF document main object
string FontFamilyName, // font family name
FontStyle FontStyle, // font style (Regular, Bold, Italic or Bold | Italic
bool EmbeddedFont = true // embed font in PDF document file
) : base(Document, ObjectType.Dictionary, "/Font")
{
// save parameters
Expand Down Expand Up @@ -704,8 +704,8 @@ char CharValue
////////////////////////////////////////////////////////////////////
public double TextWidth
(
double FontSize,
string Text
double FontSize,
string Text
)
{
// text width
Expand All @@ -729,11 +729,11 @@ string Text
////////////////////////////////////////////////////////////////////
public bool TextFitToWidth
(
double FontSize,
double ReqWidth,
out double WordSpacing,
out double CharSpacing,
string Text
double FontSize,
double ReqWidth,
out double WordSpacing,
out double CharSpacing,
string Text
)
{
WordSpacing = 0;
Expand Down Expand Up @@ -793,8 +793,8 @@ string Text
////////////////////////////////////////////////////////////////////
public PdfRectangle TextBoundingBox
(
double FontSize,
string Text
double FontSize,
string Text
)
{
if(string.IsNullOrEmpty(Text)) return null;
Expand Down Expand Up @@ -845,7 +845,7 @@ string Text
////////////////////////////////////////////////////////////////////
public KerningAdjust[] TextKerning
(
string Text
string Text
)
{
// string is empty or one character
Expand Down Expand Up @@ -906,8 +906,8 @@ string Text
////////////////////////////////////////////////////////////////////
public double TextKerningWidth
(
double FontSize, // in points
KerningAdjust[] KerningArray
double FontSize, // in points
KerningAdjust[] KerningArray
)
{
// text is null or empty
Expand Down Expand Up @@ -949,8 +949,11 @@ internal override void WriteObjectToPdfFile()
}
}

// invariant name
string PostScriptName = FontFamily.GetName(127);

// PDF readers are not happy with space in font name
PdfFontName.Append(FontFamily.Name.Replace(" ", "#20"));
PdfFontName.Append(PostScriptName.Replace(" ", "#20"));

// font name
if((DesignFont.Style & FontStyle.Bold) != 0)
Expand Down

0 comments on commit 1d8da40

Please sign in to comment.