Ejemplo n.º 1
0
 public DirectoryEntry(string tag, long outputEntryOffset, TrueTypeHeaderTable inputHeader)
 {
     Tag = tag;
     OutputEntryOffset = outputEntryOffset;
     InputHeader       = inputHeader;
     DummyHeader       = TrueTypeHeaderTable.GetEmptyHeaderTable(tag);
 }
Ejemplo n.º 2
0
        public NameTable Parse(TrueTypeHeaderTable header, TrueTypeDataBytes data, TableRegister.Builder register)
        {
            data.Seek(header.Offset);
            // ReSharper disable once UnusedVariable
            var format       = data.ReadUnsignedShort();
            var count        = data.ReadUnsignedShort();
            var stringOffset = data.ReadUnsignedShort();

            var names = new NameRecordBuilder[count];

            for (var i = 0; i < count; i++)
            {
                names[i] = NameRecordBuilder.Read(data);
            }

            var strings = new TrueTypeNameRecord[count];
            var offset  = header.Offset + stringOffset;

            for (var i = 0; i < count; i++)
            {
                strings[i] = GetTrueTypeNameRecord(names[i], data, offset);
            }

            return(new NameTable(header, GetName(4, strings), GetName(1, strings), GetName(2, strings), strings));
        }
Ejemplo n.º 3
0
        public GlyphDataTable(TrueTypeHeaderTable directoryTable, IReadOnlyList <uint> glyphOffsets,
                              PdfRectangle maxGlyphBounds,
                              TrueTypeDataBytes tableBytes)
        {
            this.glyphOffsets   = glyphOffsets;
            this.maxGlyphBounds = maxGlyphBounds;
            this.tableBytes     = tableBytes;
            DirectoryTable      = directoryTable;
            if (tableBytes == null)
            {
                throw new ArgumentNullException(nameof(tableBytes));
            }

            if (glyphOffsets == null)
            {
                throw new ArgumentNullException(nameof(glyphOffsets));
            }

            if (tableBytes.Length != directoryTable.Length)
            {
                throw new ArgumentException($"glyf table data should match length of directory entry. Expected: {directoryTable.Length}. Actual: {tableBytes.Length}.");
            }

            glyphs = new Lazy <IReadOnlyList <IGlyphDescription> >(ReadGlyphs);
        }
Ejemplo n.º 4
0
        public static HorizontalMetricsTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
        {
            var glyphCount  = tableRegister.MaximumProfileTable.NumberOfGlyphs;
            var metricCount = tableRegister.HorizontalHeaderTable.NumberOfHeaderMetrics;

            data.Seek(table.Offset);

            // The number of entries in the left side bearing field per entry is number of glyphs - number of metrics
            var additionalLeftSideBearingLength = glyphCount - metricCount;

            var advancedWidths = new int[metricCount];

            // For bearings over the metric count, the width is the same as the last width in advanced widths.
            var leftSideBearings = new short[glyphCount];

            for (var i = 0; i < metricCount; i++)
            {
                advancedWidths[i]   = data.ReadUnsignedShort();
                leftSideBearings[i] = data.ReadSignedShort();
            }

            for (var i = 0; i < additionalLeftSideBearingLength; i++)
            {
                leftSideBearings[metricCount + i] = data.ReadSignedShort();
            }

            return(new HorizontalMetricsTable(table, advancedWidths, leftSideBearings, metricCount));
        }
Ejemplo n.º 5
0
        public static T Parse <T>(TrueTypeHeaderTable table, TrueTypeDataBytes data, TableRegister.Builder register) where T : ITrueTypeTable
        {
            if (typeof(T) == typeof(CMapTable))
            {
                return((T)(object)CMapTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(HorizontalMetricsTable))
            {
                return((T)(object)HorizontalMetricsTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(NameTable))
            {
                return((T)(object)NameTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(Os2Table))
            {
                return((T)(object)Os2TableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(HorizontalHeaderTable))
            {
                return((T)(object)HorizontalHeaderTableParser.Parse(table, data, register));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Load the index to location (loca) table from the TrueType font. Requires the maximum profile (maxp) and header (head) table
        /// to have been parsed.
        /// </summary>
        internal static IndexToLocationTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
        {
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }

            if (tableRegister == null)
            {
                throw new ArgumentNullException(nameof(tableRegister));
            }

            data.Seek(table.Offset);

            var headerTable         = tableRegister.HeaderTable;
            var maximumProfileTable = tableRegister.MaximumProfileTable;

            if (headerTable == null)
            {
                throw new InvalidFontFormatException("No header (head) table was defined in this font.");
            }

            if (maximumProfileTable == null)
            {
                throw new InvalidFontFormatException("No maximum profile (maxp) table was defined in this font.");
            }

            var format = (EntryFormat)headerTable.IndexToLocFormat;

            var glyphCount = maximumProfileTable.NumberOfGlyphs + 1;

            uint[] offsets;

            switch (format)
            {
            case EntryFormat.Short:
            {
                // The local offset divided by 2 is stored.
                offsets = new uint[glyphCount];
                for (var i = 0; i < glyphCount; i++)
                {
                    offsets[i] = (uint)(data.ReadUnsignedShort() * 2);
                }
                break;
            }

            case EntryFormat.Long:
            {
                // The actual offset is stored.
                offsets = data.ReadUnsignedIntArray(glyphCount);
                break;
            }

            default:
                throw new InvalidOperationException($"The format {format} was invalid for the index to location (loca) table.");
            }


            return(new IndexToLocationTable(table, format, offsets));
        }
Ejemplo n.º 7
0
        public static KerningTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable headerTable)
        {
            data.Seek(headerTable.Offset);

            var version = data.ReadUnsignedShort();

            var numberOfSubtables = data.ReadUnsignedShort();

            var subTables = new KerningSubTable[numberOfSubtables];

            for (var i = 0; i < numberOfSubtables; i++)
            {
                var currentOffset = data.Position;

                var subtableVersion = data.ReadUnsignedShort();
                var subtableLength  = data.ReadUnsignedShort();
                var coverage        = data.ReadUnsignedShort();

                var kernCoverage = (KernCoverage)coverage;
                var format       = ((coverage & 255) >> 8);

                switch (format)
                {
                case 0:
                    subTables[i] = ReadFormat0Table(subtableVersion, data, kernCoverage);
                    break;

                case 2:
                    subTables[i] = ReadFormat2Table(subtableVersion, data, kernCoverage, currentOffset);
                    break;
                }
            }

            return(new KerningTable(subTables));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Create a new <see cref="Os2Version1Table"/>.
 /// </summary>
 public Os2Version1Table(TrueTypeHeaderTable directoryTable, ushort version, short xAverageCharacterWidth, ushort weightClass, ushort widthClass,
                         ushort typeFlags,
                         short ySubscriptXSize,
                         short ySubscriptYSize,
                         short ySubscriptXOffset,
                         short ySubscriptYOffset,
                         short ySuperscriptXSize,
                         short ySuperscriptYSize,
                         short ySuperscriptXOffset,
                         short ySuperscriptYOffset,
                         short yStrikeoutSize,
                         short yStrikeoutPosition,
                         short familyClass,
                         IReadOnlyList <byte> panose,
                         IReadOnlyList <uint> unicodeRanges,
                         string vendorId,
                         ushort fontSelectionFlags,
                         ushort firstCharacterIndex,
                         ushort lastCharacterIndex,
                         short typographicAscender,
                         short typographicDescender,
                         short typographicLineGap,
                         ushort windowsAscent,
                         ushort windowsDescent,
                         uint codePage1,
                         uint codePage2) : base(directoryTable, version, xAverageCharacterWidth, weightClass, widthClass,
                                                typeFlags, ySubscriptXSize, ySubscriptYSize, ySubscriptXOffset, ySubscriptYOffset, ySuperscriptXSize,
                                                ySuperscriptYSize, ySuperscriptXOffset, ySuperscriptYOffset, yStrikeoutSize, yStrikeoutPosition,
                                                familyClass, panose, unicodeRanges, vendorId, fontSelectionFlags, firstCharacterIndex, lastCharacterIndex,
                                                typographicAscender, typographicDescender, typographicLineGap, windowsAscent, windowsDescent)
 {
     CodePage1 = codePage1;
     CodePage2 = codePage2;
 }
Ejemplo n.º 9
0
 /// <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,
                    IndexToLocationTable.EntryFormat indexToLocFormat,
                    short glyphDataFormat)
 {
     DirectoryTable     = directoryTable;
     Version            = version;
     Revision           = revision;
     CheckSumAdjustment = checkSumAdjustment;
     MagicNumber        = magicNumber;
     Flags                 = flags;
     UnitsPerEm            = unitsPerEm;
     Created               = created;
     Modified              = modified;
     Bounds                = new PdfRectangle(xMin, yMin, xMax, yMax);
     MacStyle              = (HeaderMacStyle)macStyle;
     LowestRecommendedPpem = lowestRecommendedPpem;
     FontDirectionHint     = (FontDirection)fontDirectionHint;
     IndexToLocFormat      = indexToLocFormat;
     GlyphDataFormat       = glyphDataFormat;
 }
Ejemplo n.º 10
0
        public static BasicMaximumProfileTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table)
        {
            data.Seek(table.Offset);

            var version        = data.Read32Fixed();
            var numberOfGlyphs = data.ReadUnsignedShort();

            if (Math.Abs(version - 0.5) < float.Epsilon)
            {
                return(new BasicMaximumProfileTable(table, version, numberOfGlyphs));
            }

            var maxPoints            = data.ReadUnsignedShort();
            var maxContours          = data.ReadUnsignedShort();
            var maxCompositePoints   = data.ReadUnsignedShort();
            var maxCompositeContours = data.ReadUnsignedShort();

            var maxZones              = data.ReadUnsignedShort();
            var maxTwilightPoints     = data.ReadUnsignedShort();
            var maxStorage            = data.ReadUnsignedShort();
            var maxFunctionDefs       = data.ReadUnsignedShort();
            var maxInstructionDefs    = data.ReadUnsignedShort();
            var maxStackElements      = data.ReadUnsignedShort();
            var maxSizeOfInstructions = data.ReadUnsignedShort();
            var maxComponentElements  = data.ReadUnsignedShort();
            var maxComponentDepth     = data.ReadUnsignedShort();

            return(new MaximumProfileTable(table, version, numberOfGlyphs, maxPoints,
                                           maxContours, maxCompositePoints, maxCompositeContours, maxZones,
                                           maxTwilightPoints, maxStorage, maxFunctionDefs, maxInstructionDefs,
                                           maxStackElements, maxSizeOfInstructions, maxComponentElements,
                                           maxComponentDepth));
        }
Ejemplo n.º 11
0
 public HeaderTable(TrueTypeHeaderTable directoryTable, decimal version, decimal revision, long checkSumAdjustment,
                    long magicNumber, int flags, int unitsPerEm,
                    DateTime created, DateTime modified,
                    short xMin, short yMin,
                    short xMax, short yMax,
                    int macStyle,
                    int lowestRecommendedPpem,
                    short fontDirectionHint,
                    short indexToLocFormat,
                    short glyphDataFormat)
 {
     DirectoryTable     = directoryTable;
     Version            = version;
     Revision           = revision;
     CheckSumAdjustment = checkSumAdjustment;
     MagicNumber        = magicNumber;
     Flags                 = flags;
     UnitsPerEm            = unitsPerEm;
     Created               = created;
     Modified              = modified;
     XMin                  = xMin;
     YMin                  = yMin;
     XMax                  = xMax;
     YMax                  = yMax;
     MacStyle              = (HeaderMacStyle)macStyle;
     LowestRecommendedPpem = lowestRecommendedPpem;
     FontDirectionHint     = (FontDirection)fontDirectionHint;
     IndexToLocFormat      = indexToLocFormat;
     GlyphDataFormat       = glyphDataFormat;
 }
Ejemplo n.º 12
0
        public HorizontalMetricsTable(TrueTypeHeaderTable directoryTable, int[] advancedWidths, short[] leftSideBearings, int metricCount)
        {
            this.advancedWidths   = advancedWidths;
            this.leftSideBearings = leftSideBearings;
            this.metricCount      = metricCount;

            DirectoryTable = directoryTable;
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Read the header table from the data stream.
        /// </summary>
        public static HeaderTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table)
        {
            data.Seek(table.Offset);
            var version            = data.Read32Fixed();
            var fontRevision       = data.Read32Fixed();
            var checkSumAdjustment = data.ReadUnsignedInt();
            var magicNumber        = data.ReadUnsignedInt();

            if (magicNumber != 0x5F0F3CF5)
            {
                throw new InvalidOperationException("The magic number for this TrueType font was incorrect. Value was: " + magicNumber);
            }

            var flags      = data.ReadUnsignedShort();
            var unitsPerEm = data.ReadUnsignedShort();

            if (unitsPerEm < 16 || unitsPerEm > 16384)
            {
                throw new InvalidOperationException($"The units per em for this TrueType font was incorrect, value should be between 16 and 16384 but found {unitsPerEm} istead.");
            }

            DateTime created;

            try
            {
                created = data.ReadInternationalDate();
            }
            catch (InvalidFontFormatException)
            {
                created = DateTime.MinValue;
            }

            DateTime modified;

            try
            {
                modified = data.ReadInternationalDate();
            }
            catch (InvalidFontFormatException)
            {
                modified = DateTime.MinValue;
            }

            var xMin              = data.ReadSignedShort();
            var yMin              = data.ReadSignedShort();
            var xMax              = data.ReadSignedShort();
            var yMax              = data.ReadSignedShort();
            var macStyle          = data.ReadUnsignedShort();
            var lowestRecPpem     = data.ReadUnsignedShort();
            var fontDirectionHint = data.ReadSignedShort();
            var indexToLocFormat  = (IndexToLocationTable.EntryFormat)data.ReadSignedShort();
            var glyphDataFormat   = data.ReadSignedShort();

            return(new HeaderTable(table, version, fontRevision, checkSumAdjustment,
                                   magicNumber, flags, unitsPerEm, created, modified,
                                   xMin, yMin, xMax, yMax, macStyle, lowestRecPpem,
                                   fontDirectionHint, indexToLocFormat, glyphDataFormat));
        }
Ejemplo n.º 14
0
        public static GlyphDataTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
        {
            data.Seek(table.Offset);

            var indexToLocationTable = tableRegister.IndexToLocationTable;

            var offsets = indexToLocationTable.GlyphOffsets;

            var entryCount = offsets.Length;

            var glyphCount = entryCount - 1;

            var glyphs = new IGlyphDescription[glyphCount];

            var emptyGlyph = Glyph.Empty(tableRegister.HeaderTable.Bounds);

            var compositeLocations = new Dictionary <int, TemporaryCompositeLocation>();

            for (var i = 0; i < glyphCount; i++)
            {
                if (offsets[i] == offsets[i + 1])
                {
                    // empty glyph
                    glyphs[i] = emptyGlyph;
                    continue;
                }

                data.Seek(offsets[i] + table.Offset);

                var contourCount = data.ReadSignedShort();

                var minX = data.ReadSignedShort();
                var minY = data.ReadSignedShort();
                var maxX = data.ReadSignedShort();
                var maxY = data.ReadSignedShort();

                var bounds = new PdfRectangle(minX, minY, maxX, maxY);

                // If the number of contours is greater than or equal zero it's a simple glyph.
                if (contourCount >= 0)
                {
                    glyphs[i] = ReadSimpleGlyph(data, contourCount, bounds);
                }
                else
                {
                    compositeLocations.Add(i, new TemporaryCompositeLocation(data.Position, bounds, contourCount));
                }
            }

            // Build composite glyphs by combining simple and other composite glyphs.
            foreach (var compositeLocation in compositeLocations)
            {
                glyphs[compositeLocation.Key] = ReadCompositeGlyph(data, compositeLocation.Value, compositeLocations, glyphs, emptyGlyph);
            }

            return(new GlyphDataTable(table, glyphs));
        }
Ejemplo n.º 15
0
        public static GlyphDataTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
        {
            data.Seek(table.Offset);

            var bytes = data.ReadByteArray((int)table.Length);

            return(new GlyphDataTable(table, tableRegister.IndexToLocationTable.GlyphOffsets,
                                      tableRegister.HeaderTable.Bounds,
                                      new TrueTypeDataBytes(bytes)));
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Create a new <see cref="HorizontalMetricsTable"/>.
 /// </summary>
 public HorizontalMetricsTable(TrueTypeHeaderTable directoryTable,
                               IReadOnlyList <HorizontalMetric> horizontalMetrics,
                               IReadOnlyList <short> additionalLeftSideBearings)
 {
     DirectoryTable    = directoryTable;
     HorizontalMetrics = horizontalMetrics
                         ?? throw new ArgumentNullException(nameof(horizontalMetrics));
     AdditionalLeftSideBearings = additionalLeftSideBearings
                                  ?? throw new ArgumentNullException(nameof(additionalLeftSideBearings));
 }
Ejemplo n.º 17
0
 public NameTable(TrueTypeHeaderTable directoryTable,
                  string fontName,
                  string fontFamilyName,
                  string fontSubFamilyName,
                  IReadOnlyList <TrueTypeNameRecord> nameRecords)
 {
     DirectoryTable    = directoryTable;
     FontName          = fontName;
     FontFamilyName    = fontFamilyName;
     FontSubFamilyName = fontSubFamilyName;
     NameRecords       = nameRecords;
 }
Ejemplo n.º 18
0
 /// <summary>
 /// Creaye a new <see cref="NameTable"/>.
 /// </summary>
 public NameTable(TrueTypeHeaderTable directoryTable,
                  string fontName,
                  string fontFamilyName,
                  string fontSubFamilyName,
                  IReadOnlyList <TrueTypeNameRecord> nameRecords)
 {
     DirectoryTable    = directoryTable;
     FontName          = fontName;
     FontFamilyName    = fontFamilyName;
     FontSubFamilyName = fontSubFamilyName;
     NameRecords       = nameRecords ?? throw new ArgumentNullException(nameof(nameRecords));
 }
Ejemplo n.º 19
0
 public PostScriptTable(TrueTypeHeaderTable directoryTable, decimal formatType, decimal italicAngle, short underlinePosition, short underlineThickness, long isFixedPitch, long minimumMemoryType42, long maximumMemoryType42, long minimumMemoryType1, long maximumMemoryType1, string[] glyphNames)
 {
     DirectoryTable      = directoryTable;
     FormatType          = formatType;
     ItalicAngle         = italicAngle;
     UnderlinePosition   = underlinePosition;
     UnderlineThickness  = underlineThickness;
     IsFixedPitch        = isFixedPitch;
     MinimumMemoryType42 = minimumMemoryType42;
     MaximumMemoryType42 = maximumMemoryType42;
     MinimumMemoryType1  = minimumMemoryType1;
     MaximumMemoryType1  = maximumMemoryType1;
     GlyphNames          = glyphNames ?? throw new ArgumentNullException(nameof(glyphNames));
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Create a new <see cref="MaximumProfileTable"/>.
 /// </summary>
 public MaximumProfileTable(TrueTypeHeaderTable directoryTable, float version, int numberOfGlyphs, int maximumPoints, int maximumContours, int maximumCompositePoints, int maximumCompositeContours, int maximumZones, int maximumTwilightPoints, int maximumStorage, int maximumFunctionDefinitions, int maximumInstructionDefinitions, int maximumStackElements, int maximumSizeOfInstructions, int maximumComponentElements, int maximumComponentDepth) : base(directoryTable, version, numberOfGlyphs)
 {
     MaximumPoints                 = maximumPoints;
     MaximumContours               = maximumContours;
     MaximumCompositePoints        = maximumCompositePoints;
     MaximumCompositeContours      = maximumCompositeContours;
     MaximumZones                  = maximumZones;
     MaximumTwilightPoints         = maximumTwilightPoints;
     MaximumStorage                = maximumStorage;
     MaximumFunctionDefinitions    = maximumFunctionDefinitions;
     MaximumInstructionDefinitions = maximumInstructionDefinitions;
     MaximumStackElements          = maximumStackElements;
     MaximumSizeOfInstructions     = maximumSizeOfInstructions;
     MaximumComponentElements      = maximumComponentElements;
     MaximumComponentDepth         = maximumComponentDepth;
 }
Ejemplo n.º 21
0
        public HorizontalMetricsTable Parse(TrueTypeHeaderTable header, TrueTypeDataBytes data, TableRegister.Builder register)
        {
            var glyphCount  = register.MaximumProfileTable.NumberOfGlyphs;
            var metricCount = register.HorizontalHeaderTable.NumberOfHeaderMetrics;

            data.Seek(header.Offset);
            var bytesRead = 0;


            var horizontalMetrics = new HorizontalMetric[metricCount];


            for (var i = 0; i < metricCount; i++)
            {
                var width = data.ReadUnsignedShort();
                var lsb   = data.ReadSignedShort();

                horizontalMetrics[i] = new HorizontalMetric(width, lsb);

                bytesRead += 4;
            }

            int numberNonHorizontal = glyphCount - metricCount;

            // handle bad fonts with too many hmetrics
            if (numberNonHorizontal < 0)
            {
                numberNonHorizontal = glyphCount;
            }

            // The number of entries in the left side bearing field per entry is number of glyphs - number of metrics
            // For bearings over the metric count, the width is the same as the last width in advanced widths.
            var additionalLeftSideBearings = new short[numberNonHorizontal];

            for (var i = 0; i < additionalLeftSideBearings.Length; i++)
            {
                if (bytesRead >= header.Length)
                {
                    break;
                }

                additionalLeftSideBearings[i] = data.ReadSignedShort();
                bytesRead += 2;
            }

            return(new HorizontalMetricsTable(header, horizontalMetrics, additionalLeftSideBearings));
        }
Ejemplo n.º 22
0
        public static GlyphDataTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister tableRegister)
        {
            data.Seek(table.Offset);

            var headerTable          = tableRegister.HeaderTable;
            var indexToLocationTable = tableRegister.IndexToLocationTable;

            var offsets = indexToLocationTable.GlyphOffsets;

            var entryCount = offsets.Length;

            var glyphCount = entryCount - 1;

            var glyphs = new IGlyphDescription[glyphCount];

            for (var i = 0; i < glyphCount; i++)
            {
                if (offsets[i] == offsets[i + 1])
                {
                    // empty glyph
                    continue;
                }

                data.Seek(offsets[i] + table.Offset);

                var contourCount = data.ReadSignedShort();

                var minX = data.ReadSignedShort();
                var minY = data.ReadSignedShort();
                var maxX = data.ReadSignedShort();
                var maxY = data.ReadSignedShort();

                var bounds = new PdfRectangle(minX, minY, maxX, maxY);

                // If the number of contours is greater than or equal zero it's a simple glyph.
                if (contourCount >= 0)
                {
                    glyphs[i] = ReadSimpleGlyph(data, contourCount, bounds);
                }
                else
                {
                }
            }

            return(new GlyphDataTable(table, glyphs));
        }
Ejemplo n.º 23
0
 /// <summary>
 /// Create a new <see cref="Os2Version2To4OpenTypeTable"/>.
 /// </summary>
 public Os2Version2To4OpenTypeTable(TrueTypeHeaderTable directoryTable, ushort version,
                                    short xAverageCharacterWidth,
                                    ushort weightClass,
                                    ushort widthClass,
                                    ushort typeFlags,
                                    short ySubscriptXSize,
                                    short ySubscriptYSize,
                                    short ySubscriptXOffset,
                                    short ySubscriptYOffset,
                                    short ySuperscriptXSize,
                                    short ySuperscriptYSize,
                                    short ySuperscriptXOffset,
                                    short ySuperscriptYOffset,
                                    short yStrikeoutSize,
                                    short yStrikeoutPosition,
                                    short familyClass,
                                    IReadOnlyList <byte> panose,
                                    IReadOnlyList <uint> unicodeRanges,
                                    string vendorId,
                                    ushort fontSelectionFlags,
                                    ushort firstCharacterIndex,
                                    ushort lastCharacterIndex,
                                    short typographicAscender,
                                    short typographicDescender,
                                    short typographicLineGap,
                                    ushort windowsAscent,
                                    ushort windowsDescent,
                                    uint codePage1,
                                    uint codePage2,
                                    short xHeight,
                                    short capHeight,
                                    ushort defaultCharacter,
                                    ushort breakCharacter,
                                    ushort maximumContext) : base(directoryTable, version, xAverageCharacterWidth, weightClass, widthClass,
                                                                  typeFlags, ySubscriptXSize, ySubscriptYSize, ySubscriptXOffset, ySubscriptYOffset, ySuperscriptXSize,
                                                                  ySuperscriptYSize, ySuperscriptXOffset, ySuperscriptYOffset, yStrikeoutSize, yStrikeoutPosition,
                                                                  familyClass, panose, unicodeRanges, vendorId, fontSelectionFlags, firstCharacterIndex, lastCharacterIndex,
                                                                  typographicAscender, typographicDescender, typographicLineGap, windowsAscent, windowsDescent,
                                                                  codePage1, codePage2)
 {
     XHeight          = xHeight;
     CapHeight        = capHeight;
     DefaultCharacter = defaultCharacter;
     BreakCharacter   = breakCharacter;
     MaximumContext   = maximumContext;
 }
Ejemplo n.º 24
0
        public HorizontalHeaderTable Parse(TrueTypeHeaderTable header, TrueTypeDataBytes data, TableRegister.Builder register)
        {
            data.Seek(header.Offset);
            var majorVersion = data.ReadUnsignedShort();
            var minorVersion = data.ReadUnsignedShort();

            var ascender  = data.ReadSignedShort();
            var descender = data.ReadSignedShort();
            var lineGap   = data.ReadSignedShort();

            var advancedWidthMax = data.ReadUnsignedShort();

            var minLeftSideBearing  = data.ReadSignedShort();
            var minRightSideBearing = data.ReadSignedShort();
            var xMaxExtent          = data.ReadSignedShort();

            var caretSlopeRise = data.ReadSignedShort();
            var caretSlopeRun  = data.ReadSignedShort();
            var caretOffset    = data.ReadSignedShort();

            // Reserved section
            data.ReadSignedShort();
            data.ReadSignedShort();
            data.ReadSignedShort();
            data.ReadSignedShort();

            var metricDataFormat = data.ReadSignedShort();

            if (metricDataFormat != 0)
            {
                throw new NotSupportedException("The metric data format for a horizontal header table should be 0.");
            }

            var numberOfHeaderMetrics = data.ReadUnsignedShort();

            return(new HorizontalHeaderTable(header, majorVersion, minorVersion, ascender,
                                             descender, lineGap, advancedWidthMax,
                                             minLeftSideBearing,
                                             minRightSideBearing,
                                             xMaxExtent,
                                             caretSlopeRise,
                                             caretSlopeRun,
                                             caretOffset,
                                             metricDataFormat,
                                             numberOfHeaderMetrics));
        }
Ejemplo n.º 25
0
 /// <summary>
 /// Create a new <see cref="Os2Table"/>.
 /// </summary>
 public Os2Table(TrueTypeHeaderTable directoryTable, ushort version, short xAverageCharacterWidth, ushort weightClass,
                 ushort widthClass,
                 ushort typeFlags,
                 short ySubscriptXSize,
                 short ySubscriptYSize,
                 short ySubscriptXOffset,
                 short ySubscriptYOffset,
                 short ySuperscriptXSize,
                 short ySuperscriptYSize,
                 short ySuperscriptXOffset,
                 short ySuperscriptYOffset,
                 short yStrikeoutSize,
                 short yStrikeoutPosition,
                 short familyClass,
                 IReadOnlyList <byte> panose,
                 IReadOnlyList <uint> unicodeRanges,
                 string vendorId,
                 ushort fontSelectionFlags,
                 ushort firstCharacterIndex,
                 ushort lastCharacterIndex)
 {
     DirectoryTable         = directoryTable;
     Version                = version;
     XAverageCharacterWidth = xAverageCharacterWidth;
     WeightClass            = weightClass;
     WidthClass             = widthClass;
     TypeFlags              = typeFlags;
     YSubscriptXSize        = ySubscriptXSize;
     YSubscriptYSize        = ySubscriptYSize;
     YSubscriptXOffset      = ySubscriptXOffset;
     YSubscriptYOffset      = ySubscriptYOffset;
     YSuperscriptXSize      = ySuperscriptXSize;
     YSuperscriptYSize      = ySuperscriptYSize;
     YSuperscriptXOffset    = ySuperscriptXOffset;
     YSuperscriptYOffset    = ySuperscriptYOffset;
     YStrikeoutSize         = yStrikeoutSize;
     YStrikeoutPosition     = yStrikeoutPosition;
     FamilyClass            = familyClass;
     Panose              = panose;
     UnicodeRanges       = unicodeRanges;
     VendorId            = vendorId;
     FontSelectionFlags  = fontSelectionFlags;
     FirstCharacterIndex = firstCharacterIndex;
     LastCharacterIndex  = lastCharacterIndex;
 }
Ejemplo n.º 26
0
 public HorizontalHeaderTable(TrueTypeHeaderTable directoryTable, int majorVersion, int minorVersion, short ascender, short descender, short lineGap, int advanceWidthMaximum, short minimumLeftSideBearing, short minimumRightSideBearing, short xMaxExtent, short caretSlopeRise, short caretSlopeRun, short caretOffset, short metricDataFormat, int numberOfHeaderMetrics)
 {
     DirectoryTable          = directoryTable;
     MajorVersion            = majorVersion;
     MinorVersion            = minorVersion;
     Ascender                = ascender;
     Descender               = descender;
     LineGap                 = lineGap;
     AdvanceWidthMaximum     = advanceWidthMaximum;
     MinimumLeftSideBearing  = minimumLeftSideBearing;
     MinimumRightSideBearing = minimumRightSideBearing;
     XMaxExtent              = xMaxExtent;
     CaretSlopeRise          = caretSlopeRise;
     CaretSlopeRun           = caretSlopeRun;
     CaretOffset             = caretOffset;
     MetricDataFormat        = metricDataFormat;
     NumberOfHeaderMetrics   = numberOfHeaderMetrics;
 }
Ejemplo n.º 27
0
        public static T Parse <T>(TrueTypeHeaderTable table, TrueTypeDataBytes data, TableRegister.Builder register) where T : ITrueTypeTable
        {
            //checksum https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6.html
            uint sum    = 0;
            var  nLongs = (table.Length + 3) / 4;

            data.Seek(table.Offset);
            while (nLongs-- > 0)
            {
                sum += (uint)data.ReadSignedInt();
            }

            if (sum != table.CheckSum)
            {
                Trace.TraceWarning("Table with invalid checksum found in TrueType font file.");
            }

            if (typeof(T) == typeof(CMapTable))
            {
                return((T)(object)CMapTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(HorizontalMetricsTable))
            {
                return((T)(object)HorizontalMetricsTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(NameTable))
            {
                return((T)(object)NameTableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(Os2Table))
            {
                return((T)(object)Os2TableParser.Parse(table, data, register));
            }

            if (typeof(T) == typeof(HorizontalHeaderTable))
            {
                return((T)(object)HorizontalHeaderTableParser.Parse(table, data, register));
            }

            throw new NotImplementedException();
        }
Ejemplo n.º 28
0
        public static PostScriptTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, BasicMaximumProfileTable maximumProfileTable)
        {
            data.Seek(table.Offset);
            var formatType         = data.Read32Fixed();
            var italicAngle        = data.Read32Fixed();
            var underlinePosition  = data.ReadSignedShort();
            var underlineThickness = data.ReadSignedShort();
            var isFixedPitch       = data.ReadUnsignedInt();
            var minMemType42       = data.ReadUnsignedInt();
            var maxMemType42       = data.ReadUnsignedInt();
            var mimMemType1        = data.ReadUnsignedInt();
            var maxMemType1        = data.ReadUnsignedInt();

            var glyphNames = GetGlyphNamesByFormat(data, maximumProfileTable, formatType);

            return(new PostScriptTable(table, (decimal)formatType, (decimal)italicAngle,
                                       underlinePosition, underlineThickness, isFixedPitch,
                                       minMemType42, maxMemType42, mimMemType1,
                                       maxMemType1, glyphNames));
        }
Ejemplo n.º 29
0
        public static IndexToLocationTable Load(TrueTypeDataBytes data, TrueTypeHeaderTable table, TableRegister.Builder tableRegister)
        {
            const short shortFormat = 0;
            const short longFormat  = 1;

            data.Seek(table.Offset);

            var headerTable         = tableRegister.HeaderTable;
            var maximumProfileTable = tableRegister.MaximumProfileTable;

            var format = headerTable.IndexToLocFormat;

            var glyphCount = maximumProfileTable.NumberOfGlyphs + 1;

            var offsets = new long[glyphCount];

            switch (format)
            {
            case shortFormat:
            {         // The local offset divided by 2 is stored.
                for (int i = 0; i < glyphCount; i++)
                {
                    offsets[i] = data.ReadUnsignedShort() * 2;
                }
                break;
            }

            case longFormat:
            {
                // The actual offset is stored.
                data.ReadUnsignedIntArray(offsets, glyphCount);
                break;
            }

            default:
                throw new InvalidOperationException($"The format {format} was invalid for the index to location (loca) table.");
            }


            return(new IndexToLocationTable(table, offsets));
        }
Ejemplo n.º 30
0
 public GlyphDataTable(TrueTypeHeaderTable directoryTable, IReadOnlyList <IGlyphDescription> glyphs)
 {
     DirectoryTable = directoryTable;
     Glyphs         = glyphs ?? throw new ArgumentNullException(nameof(glyphs));
 }