mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-09-19 10:47:56 +08:00
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:
@@ -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);
|
||||
}
|
||||
}
|
@@ -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)
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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)
|
||||
{
|
||||
|
@@ -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;
|
||||
|
@@ -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}.";
|
||||
|
@@ -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;
|
||||
|
@@ -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; }
|
||||
|
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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,
|
||||
|
@@ -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,
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
@@ -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.
|
||||
|
@@ -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>
|
||||
|
Reference in New Issue
Block a user