/// <summary> /// Creates a <see cref="TrippyFontFile"/> holding information for multiple fonts with the same size. /// </summary> /// <remarks>All the fonts have the same character range.</remarks> public static TrippyFontFile CreateFontFile(ReadOnlySpan <string> fontFiles, float size, char firstChar = ' ', char lastChar = '~', Color?backgroundColor = null) { IGlyphSource[] glyphSources = new IGlyphSource[fontFiles.Length]; for (int i = 0; i < glyphSources.Length; i++) { glyphSources[i] = new FontGlyphSource(FontInstance.LoadFont(fontFiles[i]), size, firstChar, lastChar); } return(FontBuilder.CreateFontFile(glyphSources, backgroundColor)); }
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()); }
public SixLaborsFontSource(byte[] data) { FontInstance fontInstance; using (var ms = new MemoryStream(data)) { fontInstance = FontInstance.LoadFont(ms); _source = new FontGlyphSource(fontInstance); } var fh = fontInstance.Ascender - fontInstance.Descender; AscentBase = fontInstance.Ascender / (float)fh; DescentBase = fontInstance.Descender / (float)fh; LineHeightBase = fontInstance.LineHeight / (float)fh; }
/// <summary> /// Creates a <see cref="TrippyFontFile"/> holding information for a single font. /// </summary> public static TrippyFontFile CreateFontFile(Stream fontStream, float size, char firstChar = ' ', char lastChar = '~', Color?backgroundColor = null) { return(FontBuilder.CreateFontFile(new FontGlyphSource(FontInstance.LoadFont(fontStream), size, firstChar, lastChar), backgroundColor)); }