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);
        }
示例#2
0
        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 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);
        }
示例#4
0
        public static GlyphLoader Load(BinaryReader reader)
        {
            short contoursCount = reader.ReadInt16();
            var   bounds        = Bounds.Load(reader);

            if (contoursCount >= 0)
            {
                return(SimpleGlyphLoader.LoadSimpleGlyph(reader, contoursCount, bounds));
            }
            else
            {
                return(CompositeGlyphLoader.LoadCompositeGlyph(reader, bounds));
            }
        }