Example #1
0
        public void LoadFontMetadata()
        {
            var description = FontDescription.LoadDescription(TestFonts.SimpleFontFileData());

            Assert.Equal("SixLaborsSampleAB regular", description.FontNameInvariantCulture);
            Assert.Equal("Regular", description.FontSubFamilyNameInvariantCulture);
        }
Example #2
0
        public void LoadFontMetadataWoff()
        {
            FontDescription description = FontDescription.LoadDescription(TestFonts.SimpleFontFileWoffData());

            Assert.Equal("SixLaborsSampleAB regular", description.FontName);
            Assert.Equal("Regular", description.FontSubFamilyName);
        }
        public void LoadFontMetadata_WithWoff2Format()
        {
            var description = FontDescription.LoadDescription(TestFonts.OpensSansWoff2Data());

            Assert.Equal("Open Sans Regular", description.FontNameInvariantCulture);
            Assert.Equal("Regular", description.FontSubFamilyNameInvariantCulture);
        }
        public void GlyphsCount_WithWoffFormat_EqualsTtf()
        {
            var        fontReaderWoff = new FontReader(TestFonts.OpensSansWoff1Data());
            GlyphTable glyphsWoff     = fontReaderWoff.GetTable <GlyphTable>();
            var        fontReaderTtf  = new FontReader(TestFonts.OpenSansTtfData());
            GlyphTable glyphsTtf      = fontReaderTtf.GetTable <GlyphTable>();

            Assert.Equal(glyphsTtf.GlyphCount, glyphsWoff.GlyphCount);
        }
        public void ReadFont_WithWoffFormat_EqualsTtf()
        {
            var fontReaderTtf  = new FontReader(TestFonts.OpenSansTtfData());
            var fontReaderWoff = new FontReader(TestFonts.OpensSansWoff1Data());

            Assert.Equal(fontReaderTtf.Headers.Count, fontReaderWoff.Headers.Count);
            foreach (string key in fontReaderTtf.Headers.Keys)
            {
                Assert.True(fontReaderWoff.Headers.ContainsKey(key));
            }
        }
Example #6
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);
        }
Example #7
0
        public void RenderColrGlyph()
        {
            Font font = new FontCollection().Install(TestFonts.TwemojiMozillaData()).CreateFont(12);

            // Get letter Grinning Face emoji
            var instance = font.Instance as FontInstance;

            Assert.True(instance.TryGetGlyphIndex(this.AsCodePoint("😀"), out ushort idx));
            Assert.True(instance.TryGetColoredVectors(idx, out GlyphInstance[] vectors));

            Assert.Equal(3, vectors.Length);
        }
Example #8
0
        public void AddViaStreamReturnsDescription()
        {
            var sut = new FontCollection();

            using Stream s = TestFonts.CarterOneFileData();
            FontFamily family = sut.Add(s, out FontDescription description);

            Assert.NotNull(description);
            Assert.Equal("Carter One", description.FontFamilyInvariantCulture);
            Assert.Equal("Regular", description.FontSubFamilyNameInvariantCulture);
            Assert.Equal(FontStyle.Regular, description.Style);
        }
Example #9
0
        public void InstallViaStreamhReturnsDecription()
        {
            var sut = new FontCollection();
            var collectionFromPath = sut.InstallCollection(TestFonts.SSimpleTrueTypeCollectionData(), out var descriptions);

            Assert.Equal(2, collectionFromPath.Count());
            var openSans = Assert.Single(collectionFromPath, x => x.Name == "Open Sans");
            var abFont   = Assert.Single(collectionFromPath, x => x.Name == "SixLaborsSampleAB");

            Assert.Equal(2, descriptions.Count());
            var openSansDescription = Assert.Single(descriptions, x => x.FontName == "Open Sans");
            var abFontDescription   = Assert.Single(descriptions, x => x.FontName == "SixLaborsSampleAB regular");
        }
Example #10
0
        public void RenderColrGlyphTextRenderer()
        {
            Font font = new FontCollection().Install(TestFonts.TwemojiMozillaData()).CreateFont(12);

            var renderer = new ColorGlyphRenderer();

            TextRenderer.RenderTextTo(renderer, "😀", new RendererOptions(font)
            {
                ColorFontSupport = ColorFontSupport.MicrosoftColrFormat
            });

            Assert.Equal(3, renderer.Colors.Count);
        }
        public void LoadFont_WithWoff2Format()
        {
            Font font = new FontCollection().Add(TestFonts.OpensSansWoff2Data()).CreateFont(12);

            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));

            Assert.Equal(37, r.ControlPoints.Count);
            Assert.Single(r.GlyphKeys);
            Assert.Single(r.GlyphRects);
        }
Example #12
0
        public void InstallViaStreamReturnsDecription()
        {
            FontCollection sut = new FontCollection();

            using (System.IO.Stream s = TestFonts.CarterOneFileData())
            {
                FontFamily family = sut.Install(s, out FontDescription description);
                Assert.NotNull(description);
                Assert.Equal("Carter One", description.FontFamily);
                Assert.Equal("Regular", description.FontSubFamilyName);
                Assert.Equal(FontStyle.Regular, description.Style);
            }
        }
Example #13
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);
        }
        public void AddViaStreamReturnsDescription()
        {
            var suit = new FontCollection();
            IEnumerable <FontFamily> collectionFromPath = suit.AddCollection(TestFonts.SSimpleTrueTypeCollectionData(), out IEnumerable <FontDescription> descriptions);

            Assert.Equal(2, collectionFromPath.Count());
            FontFamily openSans = Assert.Single(collectionFromPath, x => x.Name == "Open Sans");
            FontFamily abFont   = Assert.Single(collectionFromPath, x => x.Name == "SixLaborsSampleAB");

            Assert.Equal(2, descriptions.Count());
            FontDescription openSansDescription = Assert.Single(descriptions, x => x.FontNameInvariantCulture == "Open Sans");
            FontDescription abFontDescription   = Assert.Single(descriptions, x => x.FontNameInvariantCulture == "SixLaborsSampleAB regular");
        }
Example #15
0
        public void LoadFontWoff()
        {
            IFontInstance font = FontInstance.LoadFont(TestFonts.SimpleFontFileWoffData());

            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());
        }
Example #16
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 LoadFontWoff()
        {
            Font font = new FontCollection().Add(TestFonts.SimpleFontFileWoffData()).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, 12, System.Numerics.Vector2.Zero, new TextOptions(font));

            // the test font only has characters .notdef, 'a' & 'b' defined
            Assert.Equal(6, r.ControlPoints.Distinct().Count());
        }
        public void FontClassNoPath_SetProperties()
        {
            var collection = new FontCollection();

            using Stream stream = TestFonts.CarterOneFileData();
            FontFamily family = collection.Add(stream);
            var        font   = new Font(family, 12);

            Assert.Equal("Carter One", font.Name);
            Assert.Equal(12, font.Size);
            Assert.Equal(FontStyle.Regular, font.RequestedStyle);
            Assert.False(font.IsBold);
            Assert.False(font.IsItalic);
            Assert.False(font.TryGetPath(out string path));
            Assert.Null(path);
        }
        public void Issue21_LoopDetectedLoadingGlyphs()
        {
            Font font = new FontCollection().Add(TestFonts.CarterOneFileData()).CreateFont(12);

            font.FontMetrics.GetGlyphMetrics(new CodePoint('\0'), ColorFontSupport.None).First();
        }
Example #20
0
        public void Issue21_LoopDetectedLoadingGlyphs()
        {
            Font font = new FontCollection().Install(TestFonts.CarterOneFileData()).CreateFont(12);

            GlyphInstance g = font.Instance.GetGlyph('\0');
        }