Example #1
0
        /// <summary>
        /// set font size in point unit, this value may be rounded
        /// </summary>
        /// <param name="value"></param>
        public void SetFontSize(float value)
        {
            //check if we have size-specific bmp cache or not
            float actualCacheSize = (float)Math.Round(value, 1);

            if (_size == actualCacheSize)
            {
                return;
            }

            //
            _size = actualCacheSize;

            if (_specificFontSizeGlyphBitmaps == null)
            {
                _specificFontSizeGlyphBitmaps = new Dictionary <float, GlyphBitmapList>();
            }

            if (!_specificFontSizeGlyphBitmaps.TryGetValue(actualCacheSize, out _bitmapList))
            {
                //not found=> create a new one
                _bitmapList = new GlyphBitmapList();


                _specificFontSizeGlyphBitmaps.Add(actualCacheSize, _bitmapList);
            }
        }
Example #2
0
        public void SetCurrentTypeface(Typeface typeface)
        {
            _currentTypeface = typeface;
            if (_cacheGlyphBmpLists.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();
            _cacheGlyphBmpLists.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.GetGlyph(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, "testGlyphBmp_" + i + ".png");
                _bitmapList.RegisterBitmap(glyph.GlyphIndex, glyphBitmap);
            }
        }
Example #3
0
        public void SetCurrentTypeface(Typeface typeface)
        {
            _currentTypeface = typeface;
            if (_cachedBmpList.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();
            _cachedBmpList.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.GetGlyph(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, "testGlyphBmp_" + i + ".png");

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