Exemplo n.º 1
0
        public void LoadFontMetadata()
        {
            FontDescription description = FontDescription.LoadDescription(TestFonts.SimpleFontFileData());

            Assert.Equal("SixLaborsSampleAB regular", description.FontName);
            Assert.Equal("Regular", description.FontSubFamilyName);
        }
Exemplo n.º 2
0
        public void LoadGlyph()
        {
            Font font = new FontCollection().Install(TestFonts.SimpleFontFileData()).CreateFont(12);

            // Get letter A
            Glyph g        = font.GetGlyph(41);
            var   instance = g.Instance;

            Assert.Equal(20, instance.ControlPoints.Length);
            Assert.Equal(20, instance.OnCurves.Length);
        }
Exemplo n.º 3
0
        public void LayoutWithLocation(string text, float x, float y, float expectedX, float expectedY)
        {
            FontCollection c    = new FontCollection();
            Font           font = c.Install(TestFonts.SimpleFontFileData()).CreateFont(12);

            int scaleFactor   = 72 * font.EmSize; // 72 * emSize means 1 point = 1px
            var glyphRenderer = new GlyphRenderer();
            var renderer      = new TextRenderer(glyphRenderer);

            renderer.RenderText(text, new RendererOptions(new Font(font, 1), 72 * font.EmSize, new PointF(x, y)));

            Assert.Equal(new PointF(expectedX, expectedY), glyphRenderer.GlyphRects[0].Location);
        }
Exemplo n.º 4
0
        public void LoadFont()
        {
            IFontInstance font = FontInstance.LoadFont(TestFonts.SimpleFontFileData());

            Assert.Equal("SixLaborsSampleAB regular", font.Description.FontName);
            Assert.Equal("Regular", font.Description.FontSubFamilyName);

            GlyphInstance glyph = font.GetGlyph('a');
            var           r     = new GlyphRenderer();

            glyph.RenderTo(r, 12, System.Numerics.Vector2.Zero, new System.Numerics.Vector2(72), 0);
            // the test font only has characters .notdef, 'a' & 'b' defined
            Assert.Equal(6, r.ControlPoints.Distinct().Count());
        }
Exemplo n.º 5
0
        public void MeasureTextWithKerning(string text, float height, float width, bool enableKerning)
        {
            var  c    = new FontCollection();
            Font font = c.Install(TestFonts.SimpleFontFileData()).CreateFont(12);

            int           scaleFactor = 72 * font.EmSize; // 72 * emSize means 1 point = 1px
            FontRectangle size        = TextMeasurer.MeasureBounds(text, new RendererOptions(new Font(font, 1), 72 * font.EmSize)
            {
                ApplyKerning = enableKerning
            });

            Assert.Equal(height, size.Height, 4);
            Assert.Equal(width, size.Width, 4);
        }
        public void LoadFont()
        {
            Font font = new FontCollection().Add(TestFonts.SimpleFontFileData()).CreateFont(12);

            Assert.Equal("SixLaborsSampleAB regular", font.FontMetrics.Description.FontNameInvariantCulture);
            Assert.Equal("Regular", font.FontMetrics.Description.FontSubFamilyNameInvariantCulture);

            GlyphMetrics glyph = font.FontMetrics.GetGlyphMetrics(new CodePoint('a'), ColorFontSupport.None).First();
            var          r     = new GlyphRenderer();

            glyph.RenderTo(r, font.Size, System.Numerics.Vector2.Zero, new TextOptions(font));

            // the test font only has characters .notdef, 'a' & 'b' defined
            Assert.Equal(6, r.ControlPoints.Distinct().Count());
        }