Пример #1
0
        private Glyph GetGlyph(char character)
        {
            Glyph glyph;

            lock (glyphs)
            {
                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.GetGlyphIndex(character);
                        var ttfGlyph   = _ofTypeface.GetGlyph(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);
        }
Пример #2
0
        void RunSampleF(PixelFarm.Drawing.Painter p)
        {
            //version 4:
            p.Clear(PixelFarm.Drawing.Color.White);
            p.UseLcdEffectSubPixelRendering = 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;


            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.OpenFont.Contours.GlyphOutlineBuilder(typeface);
                builder.BuildFromGlyphIndex((ushort)typeface.GetGlyphIndex('C'), 24);

                var tovxs = new Typography.OpenFont.Contours.GlyphTranslatorToVxs();
                builder.ReadShapes(tovxs);

                using (Tools.BorrowVxs(out var vxs))
                {
                    tovxs.WriteOutput(vxs);
                    p.Fill(vxs);
                }
            }
            // p.FillRect(0, 0, 20, 20);
        }