complete move of truetype, afm and standard14 fonts

the 3 font types mentioned are moved to the new fonts project, any referenced types are moved to the core project. most truetype classes are made public #8.
This commit is contained in:
Eliot Jones
2020-01-04 22:39:13 +00:00
parent 7c0ef111ea
commit 74774995d6
75 changed files with 447 additions and 205 deletions

View File

@@ -182,7 +182,7 @@
/// <param name="x">The X coordinate.</param>
/// <returns>The transformed X coordinate.</returns>
[Pure]
internal double TransformX(double x)
public double TransformX(double x)
{
var xt = A * x + C * 0 + E;
@@ -205,8 +205,11 @@
);
}
/// <summary>
/// Generate a <see cref="TransformationMatrix"/> translated by the specified amount.
/// </summary>
[Pure]
internal TransformationMatrix Translate(double x, double y)
public TransformationMatrix Translate(double x, double y)
{
var a = A;
var b = B;

View File

@@ -2,8 +2,14 @@
{
using TrueType;
internal interface ISystemFontFinder
/// <summary>
/// Used to find named fonts from the host operating/file system.
/// </summary>
public interface ISystemFontFinder
{
/// <summary>
/// Get the TrueType font with the specified name.
/// </summary>
TrueTypeFont GetTrueTypeFont(string name);
}
}

View File

@@ -10,7 +10,8 @@
using TrueType;
using TrueType.Parser;
internal class SystemFontFinder : ISystemFontFinder
/// <inheritdoc />
public class SystemFontFinder : ISystemFontFinder
{
private static readonly IReadOnlyDictionary<string, string[]> NameSubstitutes;
@@ -67,16 +68,16 @@
NameSubstitutes = dict;
}
private readonly TrueTypeFontParser trueTypeFontParser;
private readonly Lazy<IReadOnlyList<SystemFontRecord>> availableFonts;
private readonly Dictionary<string, string> nameToFileNameMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
private readonly HashSet<string> readFiles = new HashSet<string>();
public SystemFontFinder(TrueTypeFontParser trueTypeFontParser)
/// <summary>
/// Create a new <see cref="SystemFontFinder"/>.
/// </summary>
public SystemFontFinder()
{
this.trueTypeFontParser = trueTypeFontParser;
ISystemFontLister lister;
#if NETSTANDARD2_0
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
@@ -102,6 +103,7 @@
availableFonts = new Lazy<IReadOnlyList<SystemFontRecord>>(() => lister.GetAllFonts().ToList());
}
/// <inheritdoc />
public TrueTypeFont GetTrueTypeFont(string name)
{
var result = GetTrueTypeFontNamed(name);
@@ -227,7 +229,7 @@
if (readNameFirst)
{
var name = trueTypeFontParser.GetNameTable(data);
var name = TrueTypeFontParser.GetNameTable(data);
if (name == null)
{
@@ -245,7 +247,7 @@
}
data.Seek(0);
font = trueTypeFontParser.Parse(data);
font = TrueTypeFontParser.Parse(data);
var psName = font.TableRegister.NameTable?.GetPostscriptName() ?? font.Name;
lock (CacheLock)

View File

@@ -6,7 +6,7 @@
/// <summary>
/// The set of tables in a TrueType font interpreted by the library.
/// </summary>
internal class TableRegister
public class TableRegister
{
/// <summary>
/// This table contains global information about the font.
@@ -16,7 +16,7 @@
/// <summary>
/// This table contains the data that defines the appearance of the glyphs in the font.
/// </summary>
public GlyphDataTable GlyphTable { get; }
internal GlyphDataTable GlyphTable { get; }
/// <summary>
/// This table contains information needed to layout fonts whose characters are written horizontally.
@@ -36,10 +36,17 @@
/// <summary>
/// This table establishes the memory requirements for the font.
/// </summary>
public BasicMaximumProfileTable MaximumProfileTable { get; }
internal BasicMaximumProfileTable MaximumProfileTable { get; }
/// <summary>
/// This table defines strings used by the font.
/// </summary>
public NameTable NameTable { get; }
/// <summary>
/// This table contains information needed to use a TrueType font on a PostScript printer.
/// It contains the PostScript names for all of the glyphs in the font
/// </summary>
public PostScriptTable PostScriptTable { get; }
/// <summary>
@@ -49,15 +56,18 @@
/// </summary>
public CMapTable CMapTable { get; }
public KerningTable KerningTable { get; }
internal KerningTable KerningTable { get; }
/// <summary>
/// This table consists of a set of metrics that are required by Windows.
/// </summary>
public Os2Table Os2Table { get; }
/// <summary>
/// Create a new <see cref="TableRegister"/>.
/// </summary>
/// <param name="builder">The builder with necessary tables set.</param>
public TableRegister(Builder builder)
internal TableRegister(Builder builder)
{
if (builder == null)
{

View File

@@ -4,9 +4,15 @@
using System.Collections.Generic;
using Tables;
internal class TrueTypeFontParser
/// <summary>
/// Parses TrueType fonts.
/// </summary>
public static class TrueTypeFontParser
{
public TrueTypeFont Parse(TrueTypeDataBytes data)
/// <summary>
/// Parse the font from the input data.
/// </summary>
public static TrueTypeFont Parse(TrueTypeDataBytes data)
{
var version = data.Read32Fixed();
int numberOfTables = data.ReadUnsignedShort();
@@ -122,7 +128,7 @@
return new TrueTypeFont(version, tables, builder.Build());
}
public NameTable GetNameTable(TrueTypeDataBytes data)
internal static NameTable GetNameTable(TrueTypeDataBytes data)
{
if (data == null)
{

View File

@@ -2,10 +2,19 @@
{
using System.Collections.Generic;
internal class TrueTypeSubsetEncoding
/// <summary>
/// A new encoding to create for the subsetted TrueType file.
/// </summary>
public class TrueTypeSubsetEncoding
{
/// <summary>
/// The characters to include in the subset in order where index is the character code.
/// </summary>
public IReadOnlyList<char> Characters { get; }
/// <summary>
/// Create a new <see cref="TrueTypeSubsetEncoding"/>.
/// </summary>
public TrueTypeSubsetEncoding(IReadOnlyList<char> characters)
{
Characters = characters;

View File

@@ -9,7 +9,10 @@
using Tables.CMapSubTables;
using TrueType;
internal static class TrueTypeSubsetter
/// <summary>
/// Generate a subset of a TrueType font file containing only the required glyphs.
/// </summary>
public static class TrueTypeSubsetter
{
private const ushort IndexToLocLong = 1;
@@ -51,9 +54,10 @@
};
private static readonly byte[] PaddingBytes = {0, 0, 0, 0};
private static readonly TrueTypeFontParser Parser = new TrueTypeFontParser();
/// <summary>
/// Generate a subset of the input font containing only the data required for the glyphs specified in the encoding.
/// </summary>
public static byte[] Subset(byte[] fontBytes, TrueTypeSubsetEncoding newEncoding)
{
if (fontBytes == null)
@@ -66,7 +70,7 @@
throw new ArgumentNullException(nameof(newEncoding));
}
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontBytes)));
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(fontBytes));
var indexMapping = GetIndexMapping(font, newEncoding);
@@ -298,14 +302,29 @@
}
}
/// <summary>
/// Mapping from a glyph index in the old file to the new (subset) glyph index.
/// </summary>
public struct OldToNewGlyphIndex
{
/// <summary>
/// Glyph index in the old input file.
/// </summary>
public ushort OldIndex { get; }
/// <summary>
/// Glyph index in the new subset file.
/// </summary>
public byte NewIndex { get; }
/// <summary>
/// The character represented by this mapping.
/// </summary>
public char Represents { get; }
/// <summary>
/// Create a new <see cref="OldToNewGlyphIndex"/>.
/// </summary>
public OldToNewGlyphIndex(ushort oldIndex, ushort newIndex, char represents)
{
OldIndex = oldIndex;
@@ -313,6 +332,7 @@
Represents = represents;
}
/// <inheritdoc />
public override string ToString()
{
return $"{Represents}: From {OldIndex} To {NewIndex}.";

View File

@@ -6,23 +6,43 @@
using CMapSubTables;
using Core;
internal class CMapTable : ITrueTypeTable, IWriteable
/// <inheritdoc cref="ITrueTypeTable"/>.
/// <summary>
/// The cmap table maps character codes to glyph indices.
/// The choice of encoding for a particular font is dependent on the conventions used by the intended platform.
/// The cmap table can contain multiple encoding tables for use on different platforms, one for each supported encoding scheme.
/// </summary>
public class CMapTable : ITrueTypeTable, IWriteable
{
public IReadOnlyList<ICMapSubTable> SubTables { get; }
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Cmap;
public int Version { get; }
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
public CMapTable(int version, TrueTypeHeaderTable directoryTable, IReadOnlyList<ICMapSubTable> subTables)
/// <summary>
/// Version number (0).
/// </summary>
public ushort Version { get; }
/// <summary>
/// The sub-tables, one for each supported encoding scheme and platform.
/// </summary>
public IReadOnlyList<ICMapSubTable> SubTables { get; }
/// <summary>
/// Create a new <see cref="CMapTable"/>.
/// </summary>
public CMapTable(ushort version, TrueTypeHeaderTable directoryTable, IReadOnlyList<ICMapSubTable> subTables)
{
SubTables = subTables;
Version = version;
DirectoryTable = directoryTable;
}
/// <summary>
/// Get the glyph index for the corresponding character code.
/// </summary>
public bool TryGetGlyphIndex(int characterCode, out int glyphIndex)
{
glyphIndex = 0;
@@ -78,6 +98,7 @@
return false;
}
/// <inheritdoc />
public void Write(Stream stream)
{
var startPosition = stream.Position;

View File

@@ -6,14 +6,17 @@
using Glyphs;
using Parser;
/// <inheritdoc />
/// <summary>
/// The 'glyf' table contains the data that defines the appearance of the glyphs in the font.
/// This includes specification of the points that describe the contours that make up a glyph outline and the instructions that grid-fit that glyph.
/// </summary>
internal class GlyphDataTable : ITrueTypeTable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Glyf;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
public IReadOnlyList<IGlyphDescription> Glyphs { get; }

View File

@@ -3,34 +3,67 @@
using System;
using Core;
/// <inheritdoc />
/// <summary>
/// The 'head' table contains global information about the font.
/// It contains things like as the font version number, the creation and modification dates, revision number and basic typographic data that applies to the font as a whole.
/// </summary>
internal class HeaderTable : ITrueTypeTable
public class HeaderTable : ITrueTypeTable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Head;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
/// <summary>
/// Version number.
/// </summary>
public float Version { get; }
/// <summary>
/// Revision.
/// </summary>
public float Revision { get; }
public long CheckSumAdjustment { get; }
/// <summary>
/// Checksum adjustment is used to derive the checksum of the entire TrueType file.
/// </summary>
public uint CheckSumAdjustment { get; }
public long MagicNumber { get; }
/// <summary>
/// 0x5F0F3CF5.
/// </summary>
public uint MagicNumber { get; }
/// <summary>
/// Flags.
/// </summary>
public ushort Flags { get; }
/// <summary>
/// Units per em.
/// </summary>
public ushort UnitsPerEm { get; }
/// <summary>
/// Created date.
/// </summary>
public DateTime Created { get; }
/// <summary>
/// Modified date.
/// </summary>
public DateTime Modified { get; }
/// <summary>
/// Minimum rectangle which contains all glyphs.
/// </summary>
public PdfRectangle Bounds { get; }
/// <summary>
/// MacStyle flags.
/// </summary>
public HeaderMacStyle MacStyle { get; }
/// <summary>
@@ -38,27 +71,33 @@
/// </summary>
public ushort LowestRecommendedPpem { get; }
/// <summary>
/// Font direction hint.
/// </summary>
public FontDirection FontDirectionHint { get; }
/// <summary>
/// 0 for short offsets, 1 for long.
/// </summary>
public short IndexToLocFormat { get; }
public IndexToLocationTable.EntryFormat IndexToLocFormat { get; }
/// <summary>
/// 0 for current format.
/// </summary>
public short GlyphDataFormat { get; }
public HeaderTable(TrueTypeHeaderTable directoryTable, float version, float revision, long checkSumAdjustment,
long magicNumber, ushort flags, ushort unitsPerEm,
/// <summary>
/// Create a new <see cref="HeaderTable"/>.
/// </summary>
public HeaderTable(TrueTypeHeaderTable directoryTable, float version, float revision, uint checkSumAdjustment,
uint magicNumber, ushort flags, ushort unitsPerEm,
DateTime created, DateTime modified,
short xMin, short yMin,
short xMax, short yMax,
ushort macStyle,
ushort lowestRecommendedPpem,
short fontDirectionHint,
short indexToLocFormat,
short fontDirectionHint,
IndexToLocationTable.EntryFormat indexToLocFormat,
short glyphDataFormat)
{
DirectoryTable = directoryTable;
@@ -78,6 +117,9 @@
GlyphDataFormat = glyphDataFormat;
}
/// <summary>
/// Read the header table from the data stream.
/// </summary>
public static HeaderTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table)
{
data.Seek(table.Offset);
@@ -126,7 +168,7 @@
var macStyle = data.ReadUnsignedShort();
var lowestRecPpem = data.ReadUnsignedShort();
var fontDirectionHint = data.ReadSignedShort();
var indexToLocFormat = data.ReadSignedShort();
var indexToLocFormat = (IndexToLocationTable.EntryFormat)data.ReadSignedShort();
var glyphDataFormat = data.ReadSignedShort();
return new HeaderTable(table, version, fontRevision, checkSumAdjustment,
@@ -135,26 +177,67 @@
fontDirectionHint, indexToLocFormat, glyphDataFormat);
}
public enum FontDirection
/// <summary>
/// Values of the font direction hint.
/// </summary>
public enum FontDirection : short
{
/// <summary>
/// Strongly right to left with neutrals.
/// </summary>
StronglyRightToLeftWithNeutrals = -2,
/// <summary>
/// Strongly right to left.
/// </summary>
StronglyRightToLeft = -1,
/// <summary>
/// Full mixed directional glyphs.
/// </summary>
FullyMixedDirectional = 0,
/// <summary>
/// Strongly left to right.
/// </summary>
StronglyLeftToRight = 1,
/// <summary>
/// Strongly left to right with neutrals.
/// </summary>
StronglyLeftToRightWithNeutrals = 2
}
/// <summary>
/// Values of the Mac Style flag in the header table.
/// </summary>
[Flags]
internal enum HeaderMacStyle : ushort
public enum HeaderMacStyle : ushort
{
None = 0,
/// <summary>
/// Bold.
/// </summary>
Bold = 1 << 0,
/// <summary>
/// Italic.
/// </summary>
Italic = 1 << 1,
/// <summary>
/// Underline.
/// </summary>
Underline = 1 << 2,
/// <summary>
/// Outline.
/// </summary>
Outline = 1 << 3,
/// <summary>
/// Shadow.
/// </summary>
Shadow = 1 << 4,
/// <summary>
/// Condensed (narrow).
/// </summary>
Condensed = 1 << 5,
Extended = 1 << 6,
/// <summary>
/// Extended.
/// </summary>
Extended = 1 << 6
}
}
}

View File

@@ -1,13 +1,16 @@
namespace UglyToad.PdfPig.Fonts.TrueType.Tables
{
/// <inheritdoc />
/// <summary>
/// The 'hhea' table contains information needed to layout fonts whose characters are written horizontally, that is, either left to right or right to left.
/// This table contains information that is general to the font as a whole.
/// </summary>
internal class HorizontalHeaderTable : ITrueTypeTable
public class HorizontalHeaderTable : ITrueTypeTable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Hhea;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
/// <summary>
@@ -80,6 +83,9 @@
/// </summary>
public ushort NumberOfHeaderMetrics { get; }
/// <summary>
/// Create a new <see cref="HorizontalHeaderTable"/>.
/// </summary>
public HorizontalHeaderTable(TrueTypeHeaderTable directoryTable, int majorVersion, int minorVersion, short ascent, short descent,
short lineGap, ushort advanceWidthMaximum,
short minimumLeftSideBearing, short minimumRightSideBearing,

View File

@@ -4,20 +4,41 @@
using System.Collections.Generic;
using Names;
internal class NameTable : ITrueTypeTable
/// <inheritdoc />
/// <summary>
/// A name table allows multilingual strings to be associated with the TrueType font.
/// </summary>
public class NameTable : ITrueTypeTable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Name;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
/// <summary>
/// Font name.
/// </summary>
public string FontName { get; }
/// <summary>
/// Font family name.
/// </summary>
public string FontFamilyName { get; }
/// <summary>
/// Font sub-family name.
/// </summary>
public string FontSubFamilyName { get; }
/// <summary>
/// The name records contained in this name table.
/// </summary>
public IReadOnlyList<TrueTypeNameRecord> NameRecords { get; }
/// <summary>
/// Creaye a new <see cref="NameTable"/>.
/// </summary>
public NameTable(TrueTypeHeaderTable directoryTable,
string fontName,
string fontFamilyName,

View File

@@ -7,18 +7,36 @@
/// <summary>
/// Version 0 was defined in TrueType revision 1.5 and includes fields not in the Apple specification.
/// </summary>
internal class Os2RevisedVersion0Table : Os2Table
public class Os2RevisedVersion0Table : Os2Table
{
/// <summary>
/// Typographic ascender.
/// </summary>
public short TypographicAscender { get; }
/// <summary>
/// Typographic descender.
/// </summary>
public short TypographicDescender { get; }
/// <summary>
/// Typographic line gap.
/// </summary>
public short TypographicLineGap { get; }
/// <summary>
/// The Windows ascender metric. This should be used to specify the height above the baseline for a clipping region.
/// </summary>
public ushort WindowsAscent { get; }
/// <summary>
/// The Windows descender metric. This should be used to specify the vertical extent below the baseline for a clipping region.
/// </summary>
public ushort WindowsDescent { get; }
/// <summary>
/// Create a new <see cref="Os2RevisedVersion0Table"/>.
/// </summary>
public Os2RevisedVersion0Table(TrueTypeHeaderTable directoryTable, ushort version, short xAverageCharacterWidth, ushort weightClass,
ushort widthClass,
ushort typeFlags,
@@ -71,6 +89,7 @@
WindowsDescent = windowsDescent;
}
/// <inheritdoc />
public override void Write(Stream stream)
{
base.Write(stream);

View File

@@ -5,13 +5,16 @@
using System.Linq;
using Core;
/// <inheritdoc cref="ITrueTypeTable"/>.
/// <summary>
/// The most basic format of the OS/2 table, excluding the fields not included in the Apple version of the specification.
/// </summary>
internal class Os2Table : ITrueTypeTable, IWriteable
public class Os2Table : ITrueTypeTable, IWriteable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Os2;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
/// <summary>
@@ -178,6 +181,7 @@
LastCharacterIndex = lastCharacterIndex;
}
/// <inheritdoc />
public virtual void Write(Stream stream)
{
stream.WriteUShort(Version);

View File

@@ -7,7 +7,7 @@
/// <summary>
/// Version 1 was defined in TrueType revision 1.66. Version 1 has two additional fields beyond those in version 0.
/// </summary>
internal class Os2Version1Table : Os2RevisedVersion0Table
public class Os2Version1Table : Os2RevisedVersion0Table
{
/// <summary>
/// This field is used to specify the code pages encompassed by the font file in the 'cmap' subtable for the Microsoft platform(3), Unicode BMP encoding (1).
@@ -19,6 +19,9 @@
/// </summary>
public uint CodePage2 { get; }
/// <summary>
/// Create a new <see cref="Os2Version1Table"/>.
/// </summary>
public Os2Version1Table(TrueTypeHeaderTable directoryTable, ushort version, short xAverageCharacterWidth, ushort weightClass, ushort widthClass,
ushort typeFlags,
short ySubscriptXSize,
@@ -54,6 +57,7 @@
CodePage2 = codePage2;
}
/// <inheritdoc />
public override void Write(Stream stream)
{
base.Write(stream);

View File

@@ -8,7 +8,7 @@
/// Version 4 was defined in OpenType 1.5. Version 4 has the same fields as in version 2 and version 3.
/// Although new fields were not added beyond those in version 2 and 3, the specification of certain fields was revised.
/// </summary>
internal class Os2Version2To4OpenTypeTable : Os2Version1Table
public class Os2Version2To4OpenTypeTable : Os2Version1Table
{
/// <summary>
/// This metric specifies the distance between the baseline and the approximate height of non-ascending lowercase letters.
@@ -90,6 +90,7 @@
MaximumContext = maximumContext;
}
/// <inheritdoc />
public override void Write(Stream stream)
{
base.Write(stream);

View File

@@ -8,7 +8,7 @@
/// Version 5 was defined in OpenType 1.7.
/// Version 5 has two additional fields beyond those in versions 2 - 4.
/// </summary>
internal class Os2Version5OpenTypeTable : Os2Version2To4OpenTypeTable
public class Os2Version5OpenTypeTable : Os2Version2To4OpenTypeTable
{
/// <summary>
/// This value is the lower value of the size range for which this font has been designed.
@@ -74,6 +74,7 @@
UpperOpticalPointSize = upperOpticalPointSize;
}
/// <inheritdoc />
public override void Write(Stream stream)
{
base.Write(stream);

View File

@@ -1,16 +1,20 @@
namespace UglyToad.PdfPig.Fonts.TrueType.Tables
{
using System;
using System.Collections.Generic;
using System.Text;
/// <inheritdoc />
/// <summary>
/// This table contains information for TrueType fonts on PostScript printers.
/// This includes data for the FontInfo dictionary and the PostScript glyph names.
/// </summary>
internal class PostScriptTable : ITrueTypeTable
public class PostScriptTable : ITrueTypeTable
{
/// <inheritdoc />
public string Tag => TrueTypeHeaderTable.Post;
/// <inheritdoc />
public TrueTypeHeaderTable DirectoryTable { get; }
/// <summary>
@@ -19,12 +23,12 @@
/// Format 2.5 is a space optimised subset of the standard Mac glyph set.<br/>
/// Format 3 enables a special font type which provides no PostScript information.<br/>
/// </summary>
public decimal FormatType { get; }
public float Format { get; }
/// <summary>
/// Angle in counter-clockwise degrees from vertical. 0 for upright text, negative for right-leaning text.
/// </summary>
public decimal ItalicAngle { get; }
public float ItalicAngle { get; }
/// <summary>
/// Suggested values for the underline position with negative values below the baseline.
@@ -40,34 +44,49 @@
/// 0 if the font is proportionally spaced, non-zero for monospace or other
/// non-proportional spacing.
/// </summary>
public long IsFixedPitch { get; }
public uint IsFixedPitch { get; }
/// <summary>
/// Minimum memory usage when the TrueType font is downloaded.
/// </summary>
public long MinimumMemoryType42 { get; }
public uint MinimumMemoryType42 { get; }
/// <summary>
/// Maximum memory usage when the TrueType font is downloaded.
/// </summary>
public long MaximumMemoryType42 { get; }
public uint MaximumMemoryType42 { get; }
/// <summary>
/// Minimum memory usage when the TrueType font is downloaded as a Type 1 font.
/// </summary>
public long MinimumMemoryType1 { get; }
public uint MinimumMemoryType1 { get; }
/// <summary>
/// Maximum memory usage when the TrueType font is downloaded as a Type 1 font.
/// </summary>
public long MaximumMemoryType1 { get; }
public uint MaximumMemoryType1 { get; }
public string[] GlyphNames { get; }
/// <summary>
/// PostScript names of the glyphs.
/// </summary>
public IReadOnlyList<string> GlyphNames { get; }
public PostScriptTable(TrueTypeHeaderTable directoryTable, decimal formatType, decimal italicAngle, short underlinePosition, short underlineThickness, long isFixedPitch, long minimumMemoryType42, long maximumMemoryType42, long minimumMemoryType1, long maximumMemoryType1, string[] glyphNames)
/// <summary>
/// Create a new <see cref="PostScriptTable"/>.
/// </summary>
public PostScriptTable(TrueTypeHeaderTable directoryTable, float format,
float italicAngle,
short underlinePosition,
short underlineThickness,
uint isFixedPitch,
uint minimumMemoryType42,
uint maximumMemoryType42,
uint minimumMemoryType1,
uint maximumMemoryType1,
string[] glyphNames)
{
DirectoryTable = directoryTable;
FormatType = formatType;
Format = format;
ItalicAngle = italicAngle;
UnderlinePosition = underlinePosition;
UnderlineThickness = underlineThickness;
@@ -79,7 +98,7 @@
GlyphNames = glyphNames ?? throw new ArgumentNullException(nameof(glyphNames));
}
public static PostScriptTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, BasicMaximumProfileTable maximumProfileTable)
internal static PostScriptTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, BasicMaximumProfileTable maximumProfileTable)
{
data.Seek(table.Offset);
var formatType = data.Read32Fixed();
@@ -94,7 +113,7 @@
var glyphNames = GetGlyphNamesByFormat(data, maximumProfileTable, formatType);
return new PostScriptTable(table, (decimal)formatType, (decimal)italicAngle,
return new PostScriptTable(table, formatType, italicAngle,
underlinePosition, underlineThickness, isFixedPitch,
minMemType42, maxMemType42, mimMemType1,
maxMemType1, glyphNames);

View File

@@ -24,7 +24,7 @@
/// <summary>
/// The actual table data parsed for this TrueType font.
/// </summary>
internal TableRegister TableRegister { get; }
public TableRegister TableRegister { get; }
/// <summary>
/// The name of the font according to the font's name table.

View File

@@ -7,6 +7,8 @@
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Debug|netstandard2.0|AnyCPU'">
<DocumentationFile>obj\Debug\netstandard2.0\UglyToad.PdfPig.Fonts.xml</DocumentationFile>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<WarningsAsErrors />
</PropertyGroup>
<ItemGroup>

View File

@@ -2,7 +2,7 @@
{
using System;
using System.Collections.Generic;
using PdfPig.Geometry;
using PdfPig.Core;
internal class PointComparer : IEqualityComparer<PdfPoint>
{

View File

@@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exceptions;
using Core;
using Parser.Parts;
using Tokenization.Scanner;
using Tokens;

View File

@@ -3,6 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using Content;
using Core;
using Geometry;
using Tokenization.Scanner;
using Tokens;

View File

@@ -2,7 +2,7 @@
{
using System;
using System.Collections.Generic;
using Exceptions;
using Core;
using Graphics.Colors;
using Parser.Parts;
using PdfFonts;

View File

@@ -2,7 +2,7 @@
{
using System;
using System.IO;
using Util;
using PdfPig.Core;
internal static class OperationWriteHelper
{

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>
@@ -10,7 +10,6 @@
/// </summary>
public class AppendEndControlPointBezierCurve : IGraphicsStateOperation
{
/// <summary>
/// The symbol for this operation in a stream.
/// </summary>

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <remarks>

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.PathConstruction
{
using System.IO;
using Geometry;
using PdfPig.Core;
/// <inheritdoc />
/// <summary>

View File

@@ -1,8 +1,7 @@
namespace UglyToad.PdfPig.Graphics.Operations.TextShowing
{
using System.IO;
using IO;
using Util;
using PdfPig.Core;
using Util.JetBrains.Annotations;
/// <inheritdoc />

View File

@@ -4,7 +4,6 @@ namespace UglyToad.PdfPig.Graphics
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Exceptions;
using Operations;
using Operations.ClippingPaths;
using Operations.Compatibility;
@@ -17,6 +16,7 @@ namespace UglyToad.PdfPig.Graphics
using Operations.TextPositioning;
using Operations.TextShowing;
using Operations.TextState;
using PdfPig.Core;
using Tokens;
internal class ReflectionGraphicsStateOperationFactory : IGraphicsStateOperationFactory

View File

@@ -2,10 +2,10 @@
{
using Content;
using Destinations;
using Exceptions;
using Logging;
using Parser.Parts;
using System.Collections.Generic;
using Core;
using Tokenization.Scanner;
using Tokens;
using Util;

View File

@@ -3,11 +3,10 @@
using System;
using System.Collections.Generic;
using Content;
using Exceptions;
using Core;
using Parts;
using Tokenization.Scanner;
using Tokens;
using Util;
internal static class CatalogFactory
{

View File

@@ -3,7 +3,7 @@
using System.Collections.Generic;
using System.Linq;
using CrossReference;
using Exceptions;
using Core;
using Parts.CrossReference;
using Tokenization;
using Tokenization.Scanner;

View File

@@ -2,7 +2,7 @@
{
using System;
using Content;
using Exceptions;
using Core;
using Logging;
using Tokenization.Scanner;
using Tokens;

View File

@@ -4,11 +4,10 @@
using System.Collections.Generic;
using Annotations;
using Content;
using Exceptions;
using Core;
using Filters;
using Geometry;
using Graphics;
using IO;
using Logging;
using Parts;
using Tokenization.Scanner;

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Parser.Parts.CrossReference
{
using System;
using Exceptions;
using Core;
using Tokens;
using Util;

View File

@@ -1,7 +1,7 @@
namespace UglyToad.PdfPig.Parser.Parts.CrossReference
{
using System.Collections.Generic;
using Exceptions;
using Core;
using Filters;
using PdfPig.CrossReference;
using Tokens;

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.Parser.Parts
{
using Exceptions;
using Core;
using Tokenization.Scanner;
using Tokens;

View File

@@ -2,7 +2,7 @@
{
using System;
using System.Collections.Generic;
using Exceptions;
using Core;
using Tokenization.Scanner;
using Tokens;

View File

@@ -9,9 +9,9 @@
using Core;
using CrossReference;
using Encryption;
using Exceptions;
using FileStructure;
using Filters;
using Fonts.SystemFonts;
using Graphics;
using Logging;
using Outline;
@@ -23,7 +23,6 @@
using PdfFonts.Parser;
using PdfFonts.Parser.Handlers;
using PdfFonts.Parser.Parts;
using PdfFonts.SystemFonts;
using PdfFonts.Type1.Parser;
using Tokenization.Scanner;
using Tokens;
@@ -115,7 +114,6 @@
crossReferenceTable = crossReferenceParser.Parse(inputBytes, isLenientParsing, crossReferenceOffset, pdfScanner, scanner);
var trueTypeFontParser = new TrueTypeFontParser();
var fontDescriptorFactory = new FontDescriptorFactory();
var compactFontFormatParser = new CompactFontFormatParser(new CompactFontFormatIndividualFontParser(new CompactFontFormatTopLevelDictionaryReader(),
new CompactFontFormatPrivateDictionaryReader()));
@@ -130,12 +128,12 @@
pdfScanner.UpdateEncryptionHandler(encryptionHandler);
var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, trueTypeFontParser, compactFontFormatParser, filterProvider);
var cidFontFactory = new CidFontFactory(pdfScanner, fontDescriptorFactory, compactFontFormatParser, filterProvider);
var encodingReader = new EncodingReader(pdfScanner);
var fontFactory = new FontFactory(log, new Type0FontHandler(cidFontFactory,
filterProvider, pdfScanner),
new TrueTypeFontHandler(log, pdfScanner, filterProvider, fontDescriptorFactory, trueTypeFontParser, encodingReader, new SystemFontFinder(new TrueTypeFontParser())),
new TrueTypeFontHandler(log, pdfScanner, filterProvider, fontDescriptorFactory, encodingReader, new SystemFontFinder()),
new Type1FontHandler(pdfScanner, filterProvider, fontDescriptorFactory, encodingReader,
new Type1FontParser(new Type1EncryptedPortionParser()), compactFontFormatParser),
new Type3FontHandler(pdfScanner, filterProvider, encodingReader));

View File

@@ -0,0 +1,17 @@
namespace UglyToad.PdfPig.PdfFonts
{
using Core;
internal class CharacterBoundingBox
{
public PdfRectangle GlyphBounds { get; }
public double Width { get; }
public CharacterBoundingBox(PdfRectangle bounds, double width)
{
GlyphBounds = bounds;
Width = width;
}
}
}

View File

@@ -4,7 +4,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Util;
using Core;
/// <summary>
/// A mutable class used when parsing and generating a <see cref="CMap"/>.

View File

@@ -1,12 +1,13 @@
namespace UglyToad.PdfPig.PdfFonts.Encodings
{
using System;
using Fonts.AdobeFontMetrics;
internal class AdobeFontMetricsEncoding : Encoding
{
public override string EncodingName { get; } = "AFM";
public AdobeFontMetricsEncoding(FontMetrics metrics)
public AdobeFontMetricsEncoding(AdobeFontMetrics metrics)
{
if (metrics == null)
{

View File

@@ -3,20 +3,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using SystemFonts;
using Cmap;
using Core;
using Encodings;
using Exceptions;
using Filters;
using IO;
using Fonts;
using Fonts.Standard14Fonts;
using Fonts.SystemFonts;
using Fonts.TrueType;
using Fonts.TrueType.Parser;
using Logging;
using Parts;
using PdfPig.Parser.Parts;
using Simple;
using Tokenization.Scanner;
using Tokens;
using TrueType;
using TrueType.Parser;
using Util;
internal class TrueTypeFontHandler : IFontHandler
@@ -25,20 +26,17 @@
private readonly IPdfTokenScanner pdfScanner;
private readonly IFilterProvider filterProvider;
private readonly FontDescriptorFactory fontDescriptorFactory;
private readonly TrueTypeFontParser trueTypeFontParser;
private readonly IEncodingReader encodingReader;
private readonly ISystemFontFinder systemFontFinder;
public TrueTypeFontHandler(ILog log, IPdfTokenScanner pdfScanner, IFilterProvider filterProvider,
FontDescriptorFactory fontDescriptorFactory,
TrueTypeFontParser trueTypeFontParser,
IEncodingReader encodingReader,
ISystemFontFinder systemFontFinder)
{
this.log = log;
this.filterProvider = filterProvider;
this.fontDescriptorFactory = fontDescriptorFactory;
this.trueTypeFontParser = trueTypeFontParser;
this.encodingReader = encodingReader;
this.systemFontFinder = systemFontFinder;
this.pdfScanner = pdfScanner;
@@ -127,7 +125,7 @@
if (font.TableRegister.CMapTable.TryGetGlyphIndex(i, out var index))
{
string glyphName;
if (index >= 0 && index < postscript.GlyphNames.Length)
if (index >= 0 && index < postscript.GlyphNames.Count)
{
glyphName = postscript.GlyphNames[index];
}
@@ -146,13 +144,14 @@
return new TrueTypeSimpleFont(name, descriptor, toUnicodeCMap, encoding, font, firstCharacter, widths);
}
private TrueTypeFontProgram ParseTrueTypeFont(FontDescriptor descriptor)
private TrueTypeFont ParseTrueTypeFont(FontDescriptor descriptor)
{
if (descriptor.FontFile == null)
{
try
{
return systemFontFinder.GetTrueTypeFont(descriptor.FontName.Data);
var ttf = systemFontFinder.GetTrueTypeFont(descriptor.FontName.Data);
return ttf;
}
catch (Exception ex)
{
@@ -175,7 +174,7 @@
var fontFile = fontFileStream.Decode(filterProvider);
var font = trueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile)));
return font;
}

View File

@@ -4,9 +4,9 @@
using CidFonts;
using Cmap;
using Composite;
using Exceptions;
using Core;
using Filters;
using IO;
using Fonts;
using Parts;
using PdfPig.Parser.Parts;
using Tokenization.Scanner;

View File

@@ -7,6 +7,7 @@
using Encodings;
using Filters;
using Fonts;
using Fonts.Standard14Fonts;
using Parts;
using PdfPig.Parser.Parts;
using Simple;
@@ -14,7 +15,6 @@
using Tokens;
using Type1;
using Type1.Parser;
using Fonts;
internal class Type1FontHandler : IFontHandler
{

View File

@@ -3,10 +3,8 @@
using Cmap;
using Core;
using Encodings;
using Exceptions;
using Filters;
using Geometry;
using IO;
using Fonts;
using PdfPig.Parser.Parts;
using Simple;
using Tokenization.Scanner;

View File

@@ -5,32 +5,30 @@
using CidFonts;
using CompactFontFormat;
using Core;
using Exceptions;
using Filters;
using Fonts;
using Fonts.TrueType;
using Fonts.TrueType.Parser;
using Geometry;
using PdfPig.Parser.Parts;
using Tokenization.Scanner;
using Tokens;
using TrueType;
using Util;
internal class CidFontFactory
{
private readonly FontDescriptorFactory descriptorFactory;
private readonly TrueTypeFontParser trueTypeFontParser;
private readonly CompactFontFormatParser compactFontFormatParser;
private readonly IFilterProvider filterProvider;
private readonly IPdfTokenScanner pdfScanner;
public CidFontFactory(IPdfTokenScanner pdfScanner, FontDescriptorFactory descriptorFactory,
TrueTypeFontParser trueTypeFontParser,
public CidFontFactory(IPdfTokenScanner pdfScanner, FontDescriptorFactory descriptorFactory,
CompactFontFormatParser compactFontFormatParser,
IFilterProvider filterProvider)
{
this.pdfScanner = pdfScanner;
this.descriptorFactory = descriptorFactory;
this.trueTypeFontParser = trueTypeFontParser;
this.compactFontFormatParser = compactFontFormatParser;
this.filterProvider = filterProvider;
}
@@ -117,7 +115,8 @@
{
case DescriptorFontFile.FontFileType.TrueType:
var input = new TrueTypeDataBytes(new ByteArrayInputBytes(fontFile));
return trueTypeFontParser.Parse(input);
var ttf = TrueTypeFontParser.Parse(input);
return new PdfCidTrueTypeFont(ttf);
case DescriptorFontFile.FontFileType.FromSubtype:
{
if (!DirectObjectFinder.TryGet(descriptor.FontFile.ObjectKey, pdfScanner, out StreamToken str))

View File

@@ -6,10 +6,8 @@
using Composite;
using Core;
using Encodings;
using Geometry;
using IO;
using Fonts.TrueType;
using Tokens;
using TrueType;
using Util.JetBrains.Annotations;
internal class TrueTypeSimpleFont : IFont
@@ -26,7 +24,7 @@
[CanBeNull] private readonly Encoding encoding;
[CanBeNull] private readonly TrueTypeFontProgram fontProgram;
[CanBeNull] private readonly TrueTypeFont font;
private readonly int firstCharacter;
@@ -43,13 +41,13 @@
FontDescriptor descriptor,
[CanBeNull] CMap toUnicodeCMap,
[CanBeNull] Encoding encoding,
[CanBeNull] TrueTypeFontProgram fontProgram,
[CanBeNull] TrueTypeFont font,
int firstCharacter,
double[] widths)
{
this.descriptor = descriptor;
this.encoding = encoding;
this.fontProgram = fontProgram;
this.font = font;
this.firstCharacter = firstCharacter;
this.widths = widths;
@@ -142,9 +140,9 @@
fromFont = false;
width = widths[index];
}
else if (fontProgram != null)
else if (font != null)
{
if (!fontProgram.TryGetBoundingAdvancedWidth(characterCode, out width))
if (!font.TryGetAdvanceWidth(characterCode, out width))
{
width = boundingBoxPreTransform;
}
@@ -156,11 +154,11 @@
if (fromFont)
{
width = fontMatrix.Transform(new PdfVector(width, 0)).X;
width = fontMatrix.Transform(new PdfPoint(width, 0)).X;
}
else
{
width = DefaultTransformation.Transform(new PdfVector(width, 0)).X;
width = DefaultTransformation.Transform(new PdfPoint(width, 0)).X;
}
var result = new CharacterBoundingBox(boundingBox, width);
@@ -174,9 +172,9 @@
{
var scale = 1000.0;
if (fontProgram?.TableRegister.HeaderTable != null)
if (font?.TableRegister.HeaderTable != null)
{
scale = fontProgram.GetFontMatrixMultiplier();
scale = font.GetUnitsPerEm();
}
return TransformationMatrix.FromValues(1 / scale, 0, 0, 1 / scale, 0, 0);
@@ -186,17 +184,17 @@
{
fromFont = true;
if (fontProgram == null)
if (font == null)
{
return descriptor.BoundingBox;
}
if (fontProgram.TryGetBoundingBox(characterCode, CharacterCodeToGlyphId, out var bounds))
if (font.TryGetBoundingBox(characterCode, CharacterCodeToGlyphId, out var bounds))
{
return bounds;
}
if (fontProgram.TryGetBoundingAdvancedWidth(characterCode, out var width))
if (font.TryGetAdvanceWidth(characterCode, out var width))
{
return new PdfRectangle(0, 0, width, 0);
}
@@ -214,7 +212,7 @@
}
if (descriptor == null || !unicodeValuesCache.TryGetValue(characterCode, out var unicode)
|| fontProgram.TableRegister.CMapTable == null
|| font.TableRegister.CMapTable == null
|| encoding == null
|| !encoding.CodeToNameMap.TryGetValue(characterCode, out var name)
|| name == null)
@@ -229,63 +227,63 @@
var glyphId = 0;
if (HasFlag(descriptor.Flags, FontDescriptorFlags.Symbolic) && fontProgram.WindowsSymbolCMap != null)
if (HasFlag(descriptor.Flags, FontDescriptorFlags.Symbolic) && font.WindowsSymbolCMap != null)
{
const int startRangeF000 = 0xF000;
const int startRangeF100 = 0xF100;
const int startRangeF200 = 0xF200;
// (3, 0) - (Windows, Symbol)
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode);
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode);
if (glyphId == 0 && characterCode >= 0 && characterCode <= 0xFF)
{
// CMap may use one of the following code ranges, so that we have to add the high byte to get the mapped value.
// F000 - F0FF
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF000);
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF000);
if (glyphId == 0)
{
// F100 - F1FF
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF100);
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF100);
}
if (glyphId == 0)
{
// F200 - F2FF
glyphId = fontProgram.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF200);
glyphId = font.WindowsSymbolCMap.CharacterCodeToGlyphIndex(characterCode + startRangeF200);
}
}
// Handle fonts incorrectly set to symbolic.
if (glyphId == 0 && fontProgram.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
if (glyphId == 0 && font.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
{
glyphId = fontProgram.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
}
}
else
{
// (3, 1) - (Windows, Unicode)
if (fontProgram.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
if (font.WindowsUnicodeCMap != null && !string.IsNullOrEmpty(unicode))
{
glyphId = fontProgram.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
glyphId = font.WindowsUnicodeCMap.CharacterCodeToGlyphIndex(unicode[0]);
}
if (glyphId == 0
&& fontProgram.MacRomanCMap != null
&& font.MacRomanCMap != null
&& MacOsRomanEncoding.Instance.NameToCodeMap.TryGetValue(name, out var macCode))
{
// (1, 0) - (Macintosh, Roman)
glyphId = fontProgram.MacRomanCMap.CharacterCodeToGlyphIndex(macCode);
glyphId = font.MacRomanCMap.CharacterCodeToGlyphIndex(macCode);
}
if (glyphId == 0 && fontProgram.TableRegister.PostScriptTable != null)
if (glyphId == 0 && font.TableRegister.PostScriptTable != null)
{
for (var i = 0; i < fontProgram.TableRegister.PostScriptTable.GlyphNames.Length; i++)
for (var i = 0; i < font.TableRegister.PostScriptTable.GlyphNames.Count; i++)
{
var glyphName = fontProgram.TableRegister.PostScriptTable.GlyphNames[i];
var glyphName = font.TableRegister.PostScriptTable.GlyphNames[i];
if (string.Equals(glyphName, name, StringComparison.OrdinalIgnoreCase))
{

View File

@@ -4,9 +4,9 @@
using System.Collections.Generic;
using Core;
using Encodings;
using IO;
using Fonts.AdobeFontMetrics;
using Fonts.TrueType;
using Tokens;
using TrueType;
/// <summary>
/// Some TrueType fonts use both the Standard 14 descriptor and the TrueType font from disk.
@@ -16,16 +16,16 @@
private static readonly TransformationMatrix DefaultTransformation =
TransformationMatrix.FromValues(1 / 1000.0, 0, 0, 1 / 1000.0, 0, 0);
private readonly FontMetrics fontMetrics;
private readonly AdobeFontMetrics fontMetrics;
private readonly Encoding encoding;
private readonly TrueTypeFontProgram font;
private readonly TrueTypeFont font;
private readonly MetricOverrides overrides;
public NameToken Name { get; }
public bool IsVertical { get; } = false;
public TrueTypeStandard14FallbackSimpleFont(NameToken name, FontMetrics fontMetrics, Encoding encoding, TrueTypeFontProgram font,
public TrueTypeStandard14FallbackSimpleFont(NameToken name, AdobeFontMetrics fontMetrics, Encoding encoding, TrueTypeFont font,
MetricOverrides overrides)
{
this.fontMetrics = fontMetrics;
@@ -90,7 +90,7 @@
if (overrides?.TryGetWidth(characterCode, out width) != true)
{
width = fontMatrix.TransformX(metrics.WidthX);
width = fontMatrix.TransformX(metrics.Width.X);
}
else
{
@@ -106,7 +106,7 @@
{
if (font?.TableRegister.HeaderTable != null)
{
var scale = (double)font.GetFontMatrixMultiplier();
var scale = (double)font.GetUnitsPerEm();
return TransformationMatrix.FromValues(1 / scale, 0, 0, 1 / scale, 0, 0);
}

View File

@@ -4,8 +4,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
using System;
using Core;
using Encodings;
using Geometry;
using IO;
using Fonts.AdobeFontMetrics;
using Tokens;
/// <summary>
@@ -13,7 +12,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
/// </summary>
internal class Type1Standard14Font: IFont
{
private readonly FontMetrics standardFontMetrics;
private readonly AdobeFontMetrics standardFontMetrics;
private readonly Encoding encoding;
public NameToken Name { get; }
@@ -21,7 +20,7 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
private readonly TransformationMatrix fontMatrix = TransformationMatrix.FromValues(0.001, 0, 0, 0.001, 0, 0);
public Type1Standard14Font(FontMetrics standardFontMetrics, Encoding overrideEncoding = null)
public Type1Standard14Font(AdobeFontMetrics standardFontMetrics, Encoding overrideEncoding = null)
{
this.standardFontMetrics = standardFontMetrics ?? throw new ArgumentNullException(nameof(standardFontMetrics));
encoding = overrideEncoding ?? new AdobeFontMetricsEncoding(standardFontMetrics);
@@ -65,18 +64,21 @@ namespace UglyToad.PdfPig.PdfFonts.Simple
{
return new PdfRectangle(0, 0, 250, 0);
}
var x = metrics.Width.X;
var y = metrics.Width.Y;
if (metrics.WidthX == 0 && metrics.BoundingBox.Width > 0)
if (metrics.Width.X == 0 && metrics.BoundingBox.Width > 0)
{
metrics.WidthX = metrics.BoundingBox.Width;
x = metrics.BoundingBox.Width;
}
if (metrics.WidthY == 0 && metrics.BoundingBox.Height > 0)
if (metrics.Width.Y == 0 && metrics.BoundingBox.Height > 0)
{
metrics.WidthY = metrics.BoundingBox.Height;
y = metrics.BoundingBox.Height;
}
return new PdfRectangle(0, 0, metrics.WidthX, metrics.WidthY);
return new PdfRectangle(0, 0, x, y);
}
public TransformationMatrix GetFontMatrix()

View File

@@ -4,9 +4,7 @@
using Composite;
using Core;
using Encodings;
using Exceptions;
using Geometry;
using IO;
using Fonts;
using Tokens;
internal class Type3Font : IFont
@@ -69,7 +67,7 @@
characterBoundingBox = fontMatrix.Transform(characterBoundingBox);
var width = fontMatrix.Transform(new PdfVector(widths[characterCode - firstChar], 0)).X;
var width = fontMatrix.Transform(new PdfPoint(widths[characterCode - firstChar], 0)).X;
return new CharacterBoundingBox(characterBoundingBox, width);
}

View File

@@ -5,11 +5,11 @@
using Core;
using Fonts.TrueType;
internal class TrueTypeFontProgram : ICidFontProgram
internal class PdfCidTrueTypeFont : ICidFontProgram
{
private readonly TrueTypeFont font;
public TrueTypeFontProgram(TrueTypeFont font)
public PdfCidTrueTypeFont(TrueTypeFont font)
{
this.font = font ?? throw new ArgumentNullException(nameof(font));
}

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.Arithmetic
{
using Geometry;
using Core;
/// <summary>
/// Sets the current point to (x, y) in absolute character space coordinates without performing a charstring moveto command.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Horizontal line-to command.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Relative move to for horizontal dimension only.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Horizontal vertical curve to command. Draws a Bézier curve when the first Bézier tangent is horizontal and the second Bézier tangent is vertical.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Relative line-to command. Creates a line moving a distance relative to the current point.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Relative move to command. starts a new subpath of the current path in the same manner as moveto.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Relative rcurveto. Whereas the arguments to the rcurveto operator in the PostScript language are all relative to the current

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Vertical-line to command.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Vertical move to. Moves relative to the current point.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.PathConstruction
{
using Geometry;
using Core;
/// <summary>
/// Vertical-horizontal curveto.

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.StartFinishOutline
{
using Geometry;
using Core;
/// <summary>
/// The name hsbw stands for horizontal sidebearing and width;

View File

@@ -1,6 +1,6 @@
namespace UglyToad.PdfPig.PdfFonts.Type1.CharStrings.Commands.StartFinishOutline
{
using Geometry;
using Core;
/// <summary>
/// Sets left sidebearing and the character width vector.

View File

@@ -2,10 +2,8 @@
{
using System;
using System.Collections.Generic;
using System.Linq;
using CharStrings;
using IO;
using PdfPig.Parser.Parts;
using Core;
using Tokens;
internal class Type1EncryptedPortionParser

View File

@@ -3,7 +3,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Exceptions;
using Core;
using Parser.Parts;
using Tokenization.Scanner;
using Util.JetBrains.Annotations;

View File

@@ -30,13 +30,11 @@
var filterProvider = new MemoryFilterProvider(new DecodeParameterResolver(logger), new PngPredictor(), logger);
var cmapParser = new CMapParser();
var afmParser = new AdobeFontMetricsParser();
var container = new Container();
container.Register(trailerParser);
container.Register(filterProvider);
container.Register(cmapParser);
container.Register(afmParser);
container.Register(logger);
return container;

View File

@@ -4,19 +4,19 @@
using System.Collections.Generic;
using System.IO;
using Core;
using PdfFonts;
using PdfFonts.Encodings;
using PdfPig.Fonts.AdobeFontMetrics;
using Tokens;
internal class Standard14WritingFont : IWritingFont
{
private readonly FontMetrics metrics;
private readonly AdobeFontMetrics metrics;
public bool HasWidths { get; } = false;
public string Name => metrics.FontName;
public Standard14WritingFont(FontMetrics metrics)
public Standard14WritingFont(AdobeFontMetrics metrics)
{
this.metrics = metrics;
}
@@ -31,7 +31,7 @@
}
boundingBox = new PdfRectangle(characterMetric.BoundingBox.Left, characterMetric.BoundingBox.Bottom,
characterMetric.BoundingBox.Left + characterMetric.WidthX, characterMetric.BoundingBox.Top);
characterMetric.BoundingBox.Left + characterMetric.Width.X, characterMetric.BoundingBox.Top);
return true;
}

View File

@@ -9,6 +9,8 @@
using Tokens;
using PdfPig.Fonts;
using PdfPig.Fonts.TrueType;
using PdfPig.Fonts.TrueType.Subsetting;
using PdfPig.Fonts.TrueType.Tables;
internal class TrueTypeWritingFont : IWritingFont
{
@@ -69,7 +71,7 @@
// TODO: get flags TrueTypeEmbedder.java
{ NameToken.Flags, new NumericToken((int)FontDescriptorFlags.Symbolic) },
{ NameToken.FontBbox, GetBoundingBox(bbox, scaling) },
{ NameToken.ItalicAngle, new NumericToken(postscript.ItalicAngle) },
{ NameToken.ItalicAngle, new NumericToken((decimal)postscript.ItalicAngle) },
{ NameToken.Ascent, new NumericToken(Math.Round(hhead.Ascent * scaling, 2)) },
{ NameToken.Descent, new NumericToken(Math.Round(hhead.Descent * scaling, 2)) },
{ NameToken.CapHeight, new NumericToken(90) },

View File

@@ -9,7 +9,8 @@
using Fonts;
using PdfPig.Fonts.TrueType;
using Graphics.Operations;
using PdfFonts;
using PdfPig.Fonts.Standard14Fonts;
using PdfPig.Fonts.TrueType.Parser;
using Tokens;
using Util.JetBrains.Annotations;
@@ -18,8 +19,6 @@
/// </summary>
public class PdfDocumentBuilder
{
private static readonly TrueTypeFontParser Parser = new TrueTypeFontParser();
private readonly Dictionary<int, PdfPageBuilder> pages = new Dictionary<int, PdfPageBuilder>();
private readonly Dictionary<Guid, FontStored> fonts = new Dictionary<Guid, FontStored>();
@@ -67,7 +66,7 @@
return false;
}
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
if (font.TableRegister.CMapTable == null)
{
@@ -105,7 +104,7 @@
{
try
{
var font = Parser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
var font = TrueTypeFontParser.Parse(new TrueTypeDataBytes(new ByteArrayInputBytes(fontFileBytes)));
var id = Guid.NewGuid();
var i = fonts.Count;
var added = new AddedFont(id, NameToken.Create($"F{i}"));

View File

@@ -4,15 +4,13 @@
using System.Collections.Generic;
using System.Linq;
using Content;
using Exceptions;
using Core;
using Filters;
using Geometry;
using Graphics;
using Graphics.Colors;
using Graphics.Core;
using Tokenization.Scanner;
using Tokens;
using Util;
internal static class XObjectFactory
{