public void LoadSingleGlyphWithInt8Offset_signed_byte() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16((ushort)CompositeFlags.ArgsAreXYValues); // signed byte writer.WriteUInt16(1); // glyph id writer.WriteInt8(sbyte.MinValue + 1); // dx writer.WriteInt8(sbyte.MinValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.ControlPoints); Assert.Equal(new Vector2(sbyte.MinValue + 1 + 20, sbyte.MinValue + 2 + 21), point); }
public void LoadSingleGlyphWithUInt8Offset_unsigned_byte() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16(0); // 8bit unsigned writer.WriteUInt16(1); // glyph id writer.WriteUInt8(sbyte.MaxValue + 1); // dx writer.WriteUInt8(sbyte.MaxValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>()) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray()); Assert.Equal(new Vector2(sbyte.MaxValue + 1 + 20, sbyte.MaxValue + 2 + 21), point); }
public void LoadSingleGlyphWithInt16Offset_signed_short() { var writer = new BigEndianBinaryWriter(); writer.WriteUInt16((ushort)(CompositeGlyphFlags.Args1And2AreWords /* 16bit */ | CompositeGlyphFlags.ArgsAreXYValues /* signed */)); // flags writer.WriteUInt16(1); // glyph id writer.WriteInt16(short.MinValue + 1); // dx writer.WriteInt16(short.MinValue + 2); // dy writer.GetReader(); var bounds = new Bounds(0, 0, 100, 100); var glyph = CompositeGlyphLoader.LoadCompositeGlyph(writer.GetReader(), in bounds); var tbl = new GlyphTable(new[] { new SimpleGlyphLoader(bounds), // padding new SimpleGlyphLoader(new short[] { 20 }, new short[] { 21 }, new[] { true }, new ushort[] { 1 }, bounds, Array.Empty <byte>()) }); GlyphVector finalGlyph = glyph.CreateGlyph(tbl); Vector2 point = Assert.Single(finalGlyph.GetOutline().ControlPoints.ToArray()); Assert.Equal(new Vector2(short.MinValue + 1 + 20, short.MinValue + 2 + 21), point); }
public void LoadFormat1() { var writer = new BigEndianBinaryWriter(); writer.WriteNameTable( new Dictionary <KnownNameIds, string> { { KnownNameIds.CopyrightNotice, "copyright" }, { KnownNameIds.FullFontName, "fullname" }, { KnownNameIds.FontFamilyName, "family" }, { KnownNameIds.FontSubfamilyName, "subfamily" }, { KnownNameIds.UniqueFontID, "id" }, { (KnownNameIds)90, "other1" }, { (KnownNameIds)91, "other2" } }, new List <string> { "lang1", "lang2" }); var table = NameTable.Load(writer.GetReader()); Assert.Equal("fullname", table.FontName(CultureInfo.InvariantCulture)); Assert.Equal("family", table.FontFamilyName(CultureInfo.InvariantCulture)); Assert.Equal("subfamily", table.FontSubFamilyName(CultureInfo.InvariantCulture)); Assert.Equal("id", table.Id(CultureInfo.InvariantCulture)); Assert.Equal("copyright", table.GetNameById(CultureInfo.InvariantCulture, KnownNameIds.CopyrightNotice)); Assert.Equal("other1", table.GetNameById(CultureInfo.InvariantCulture, 90)); Assert.Equal("other2", table.GetNameById(CultureInfo.InvariantCulture, 91)); }
public void LoadFormat0() { var writer = new BigEndianBinaryWriter(); // int subtableCount = 1; writer.WriteCMapSubTable( new Format0SubTable( 0, PlatformIDs.Windows, 2, new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 })); BigEndianBinaryReader reader = writer.GetReader(); ushort format = reader.ReadUInt16(); // read format before we pass along as that's what the cmap table does Assert.Equal(0, format); Format0SubTable table = Format0SubTable.Load( new[] { new EncodingRecord(PlatformIDs.Windows, 2, 0) }, reader).Single(); Assert.Equal(0, table.Language); Assert.Equal(PlatformIDs.Windows, table.Platform); Assert.Equal(2, table.Encoding); Assert.Equal(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 }, table.GlyphIds); }
public void LoadHead() { var writer = new BigEndianBinaryWriter(); writer.WriteHeadTable(new HeadTable( HeadTable.HeadFlags.None, HeadTable.HeadMacStyle.Italic | HeadTable.HeadMacStyle.Bold, 1024, new DateTime(2017, 02, 06, 07, 47, 00), new DateTime(2017, 02, 07, 07, 47, 00), new Bounds(0, 0, 1024, 1022), 0, HeadTable.IndexLocationFormats.Offset16)); var head = HeadTable.Load(writer.GetReader()); Assert.Equal(HeadTable.HeadFlags.None, head.Flags); Assert.Equal(HeadTable.HeadMacStyle.Italic | HeadTable.HeadMacStyle.Bold, head.MacStyle); Assert.Equal(1024, head.UnitsPerEm); Assert.Equal(new DateTime(2017, 02, 06, 07, 47, 00), head.Created); Assert.Equal(new DateTime(2017, 02, 07, 07, 47, 00), head.Modified); Assert.Equal(0, head.Bounds.Min.X); Assert.Equal(0, head.Bounds.Min.Y); Assert.Equal(1024, head.Bounds.Max.X); Assert.Equal(1022, head.Bounds.Max.Y); Assert.Equal(0, head.LowestRecPPEM); Assert.Equal(HeadTable.IndexLocationFormats.Offset16, head.IndexLocationFormat); }
public void LoadFormat4() { var writer = new BigEndianBinaryWriter(); // int subtableCount = 1; writer.WriteCMapSubTable( new Format4SubTable( 0, PlatformIDs.Windows, 2, new[] { new Format4SubTable.Segment(0, 1, 2, 3, 4) }, new ushort[] { 1, 2, 3, 4, 5, 6, 7, 8 })); BigEndianBinaryReader reader = writer.GetReader(); ushort format = reader.ReadUInt16(); // read format before we pass along as that's what the cmap table does Assert.Equal(4, format); Format4SubTable table = Format4SubTable.Load( new[] { new EncodingRecord(PlatformIDs.Windows, 2, 0) }, reader).Single(); Assert.Equal(0, table.Language); Assert.Equal(PlatformIDs.Windows, table.Platform); Assert.Equal(2, table.Encoding); Assert.Equal(new ushort[] { 1, 2, 3, 4, 5, 6, 7, 8 }, table.GlyphIds); Assert.Single(table.Segments); Format4SubTable.Segment seg = table.Segments[0]; Assert.Equal(0, seg.Index); Assert.Equal(1, seg.End); Assert.Equal(2, seg.Start); Assert.Equal(3, seg.Delta); Assert.Equal(4, seg.Offset); }
public void ReadAllValues(string tag, uint checksum, uint offset, uint length) { var writer = new BigEndianBinaryWriter(); writer.WriteTableHeader(tag, checksum, offset, length); var header = TableHeader.Read(writer.GetReader()); Assert.Equal(checksum, header.CheckSum); Assert.Equal(length, header.Length); Assert.Equal(offset, header.Offset); Assert.Equal(tag, header.Tag); }
public void LoadFormat0() { var writer = new BigEndianBinaryWriter(); writer.WriteCMapTable(new[] { new Format0SubTable(0, PlatformIDs.Windows, 9, new byte[] { 0, 1, 2 }) }); var table = CMapTable.Load(writer.GetReader()); Assert.Single(table.Tables.Where(x => x != null)); Format0SubTable[] format0Tables = table.Tables.OfType <Format0SubTable>().ToArray(); Assert.Single(format0Tables); }
public void LoadVerticalHeadTable() { var writer = new BigEndianBinaryWriter(); writer.WriteVerticalHeadTable(new VerticalHeadTable(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)); var tbl = VerticalHeadTable.Load(writer.GetReader()); Assert.Equal(1, tbl.Ascender); Assert.Equal(2, tbl.Descender); Assert.Equal(3, tbl.LineGap); Assert.Equal(4, tbl.AdvanceHeightMax); Assert.Equal(5, tbl.MinTopSideBearing); Assert.Equal(6, tbl.MinBottomSideBearing); Assert.Equal(7, tbl.YMaxExtent); Assert.Equal(8, tbl.CaretSlopeRise); Assert.Equal(9, tbl.CaretSlopeRun); Assert.Equal(10, tbl.CaretOffset); Assert.Equal(11, tbl.NumberOfVMetrics); }
public void LoadHorizontalHeadTable() { var writer = new BigEndianBinaryWriter(); writer.WriteHorizontalHeadTable(new HorizontalHeadTable(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)); var tbl = HorizontalHeadTable.Load(writer.GetReader()); Assert.Equal(1, tbl.Ascender); Assert.Equal(2, tbl.Descender); Assert.Equal(3, tbl.LineGap); Assert.Equal(4, tbl.AdvanceWidthMax); Assert.Equal(5, tbl.MinLeftSideBearing); Assert.Equal(6, tbl.MinRightSideBearing); Assert.Equal(7, tbl.XMaxExtent); Assert.Equal(8, tbl.CaretSlopeRise); Assert.Equal(9, tbl.CaretSlopeRun); Assert.Equal(10, tbl.CaretOffset); Assert.Equal(11, tbl.NumberOfHMetrics); }