private Glyph GetGlyph(char character) { Glyph glyph; if (!glyphs.TryGetValue(character, out glyph)) { // if we have a loaded ttf try to create the glyph data if (_ofTypeface != null) { var storage = new VertexStorage(); var translator = new VertexSourceGlyphTranslator(storage); var glyphIndex = _ofTypeface.LookupIndex(character); var ttfGlyph = _ofTypeface.GetGlyphByIndex(glyphIndex); // Typography.OpenFont.IGlyphReaderExtensions.Read(translator, ttfGlyph.GlyphPoints, ttfGlyph.EndPoints); // glyph = new Glyph(); glyph.unicode = character; glyph.horiz_adv_x = _ofTypeface.GetHAdvanceWidthFromGlyphIndex(glyphIndex); glyphs.Add(character, glyph); // Wrap glyph data with ClosedLoopGlyphData to ensure all loops are correctly closed glyph.glyphData = new ClosedLoopGlyphData(storage); } } return(glyph); }
void RunSampleF(PixelFarm.Drawing.Painter p) { //version 4: p.Clear(PixelFarm.Drawing.Color.White); p.UseSubPixelLcdEffect = this.EnableSubPix; //-------------------------- p.StrokeColor = PixelFarm.Drawing.Color.Black; p.StrokeWidth = 2.0f; p.DrawLine(2, 0, 10, 15); int lineLen = 10; int x = 30; int y = 30; p.FillColor = PixelFarm.Drawing.Color.Black; VertexStorePool pool = new VertexStorePool(); using (System.IO.FileStream fs = new System.IO.FileStream("c:\\Windows\\Fonts\\tahoma.ttf", System.IO.FileMode.Open, System.IO.FileAccess.Read)) { Typography.OpenFont.OpenFontReader reader = new Typography.OpenFont.OpenFontReader(); Typography.OpenFont.Typeface typeface = reader.Read(fs); var builder = new Typography.Contours.GlyphPathBuilder(typeface); builder.BuildFromGlyphIndex((ushort)typeface.LookupIndex('C'), 16); PixelFarm.Drawing.Fonts.GlyphTranslatorToVxs tovxs = new Drawing.Fonts.GlyphTranslatorToVxs(); builder.ReadShapes(tovxs); VertexStore vxs = new VertexStore(); tovxs.WriteOutput(vxs); p.Fill(vxs); } p.FillRect(0, 0, 20, 20); }
internal IVertexSource GetGlyphForCharacter(char character) { if (_ofTypeface != null) { // TODO: MAKE SURE THIS IS OFF!!!!!!! It is un-needed and only for debugging //glyphs.Clear(); } // TODO: check for multi character glyphs (we don't currently support them in the reader). Glyph glyph = null; if (!glyphs.TryGetValue(character, out glyph)) { // if we have a loaded ttf try to create the glyph data if (_ofTypeface != null) { var storage = new VertexStorage(); var translator = new VertexSourceGlyphTranslator(storage); var glyphIndex = _ofTypeface.LookupIndex(character); var ttfGlyph = _ofTypeface.GetGlyphByIndex(glyphIndex); // Typography.OpenFont.IGlyphReaderExtensions.Read(translator, ttfGlyph.GlyphPoints, ttfGlyph.EndPoints); // glyph = new Glyph(); glyph.unicode = character; glyph.horiz_adv_x = _ofTypeface.GetHAdvanceWidthFromGlyphIndex(glyphIndex); glyphs.Add(character, glyph); // Wrap glyph data with ClosedLoopGlyphData to ensure all loops are correctly closed glyph.glyphData = new ClosedLoopGlyphData(storage); } } return(glyph?.glyphData); }