public void Clear(Typeface typeface) { if (_totalBmpCache.TryGetValue(typeface, out TypefaceGlyphBitmapCache found)) { found.Clear(); _totalBmpCache.Remove(typeface); } if (_currentTypeface == typeface) { _currentTypeface = null; _bmpCache = null; } }
public void SetCurrentTypeface(Typeface typeface, float sizeInPts) { if (_currentTypeface == typeface && _currentSizeInPts == sizeInPts) { return; } _currentSizeInPts = sizeInPts; _currentTypeface = typeface; if (_totalBmpCache.TryGetValue(typeface, out _bmpCache)) { _bmpCache.SetFontSize(_currentSizeInPts); return; } //TODO: you can scale down to proper img size //or create a single texture atlas. //if not create a new one _bmpCache = new TypefaceGlyphBitmapCache(typeface); _bmpCache.SetFontSize(_currentSizeInPts); return; //if (!delayCreateBmp) //{ // 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); // _bitmapList.RegisterBitmap(i, glyphBitmap); // } // } //} }
/// <summary> /// clear all cache bitmap /// </summary> public void Clear() { if (_currentTypeface == null) { return; } _currentTypeface = null; foreach (TypefaceGlyphBitmapCache bmplist in _totalBmpCache.Values) { bmplist.Dispose(); } _totalBmpCache.Clear(); // _bmpCache?.Dispose(); _bmpCache = null; }