Ejemplo n.º 1
0
        public void SetCurrentTypeface(Typeface typeface)
        {
            _currentTypeface = typeface;
            if (_cacheGlyphPathBuilders.TryGetValue(typeface, out _bitmapList))
            {
                return;
            }
            //TODO: you can scale down to proper img size
            //or create a single texture atlas.
            //if not create a new one
            _bitmapList = new GlyphBitmapList();
            _cacheGlyphPathBuilders.Add(typeface, _bitmapList);
            int glyphCount = typeface.GlyphCount;

            System.Text.StringBuilder stbuilder = new System.Text.StringBuilder();
            for (ushort i = 0; i < glyphCount; ++i)
            {
                stbuilder.Length = 0;//reset
                Glyph glyph = typeface.GetGlyphByIndex(i);
                typeface.ReadSvgContent(glyph, stbuilder);
                //create bitmap from svg

                GlyphBitmap glyphBitmap = new GlyphBitmap();
                glyphBitmap.Width  = glyph.MaxX - glyph.MinX;
                glyphBitmap.Height = glyph.MaxY - glyph.MinY;

                if (glyphBitmap.Width == 0 || glyphBitmap.Height == 0)
                {
                    continue;
                }

                glyphBitmap.Bitmap = _svgBmpBuilderFunc(stbuilder);// ParseAndRenderSvg(stbuilder, vgDocHost);
                if (glyphBitmap.Bitmap == null)
                {
                    continue;
                }

                //
                //MemBitmapExtensions.SaveImage(glyphBitmap.Bitmap, "d:\\WImageTest\\testGlyphBmp_" + i + ".png");
                _bitmapList.RegisterBitmap(glyph.GlyphIndex, glyphBitmap);
            }
        }
Ejemplo n.º 2
0
        public void SetCurrentTypeface(Typeface typeface)
        {
            _currentTypeface = typeface;
            if (_cacheGlyphPathBuilders.TryGetValue(typeface, out _bitmapList))
            {
                return;
            }

            //TODO: you can scale down to proper img size
            //or create a single texture atlas.


            //if not create a new one
            _bitmapList = new GlyphBitmapList();
            _cacheGlyphPathBuilders.Add(typeface, _bitmapList);

            int glyphCount = typeface.GlyphCount;

            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                for (ushort i = 0; i < glyphCount; ++i)
                {
                    ms.SetLength(0);

                    Glyph glyph = typeface.GetGlyphByIndex(i);
                    typeface.ReadBitmapContent(glyph, ms);

                    GlyphBitmap glyphBitmap = new GlyphBitmap();
                    glyphBitmap.Width  = glyph.MaxX - glyph.MinX;
                    glyphBitmap.Height = glyph.MaxY - glyph.MinY;

                    //glyphBitmap.Bitmap = ...
                    glyphBitmap.Bitmap = MemBitmap.LoadBitmap(ms);
                    //MemBitmapExtensions.SaveImage(glyphBitmap.Bitmap, "d:\\WImageTest\\testGlyphBmp_" + i + ".png");

                    _bitmapList.RegisterBitmap(glyph.GlyphIndex, glyphBitmap);
                }
            }
        }