Exemple #1
0
 public Gdi32Font(string faceName, FontSizeUnit fontSizeUnit, float size, int weight, byte italic, byte underline, byte strikeOut, byte charSet, Gdi32FontQuality fontQuality)
     : this(ToFontCacheKey(faceName, fontSizeUnit, size, new Gdi32FontStyleInfo(weight, italic, underline, strikeOut), charSet, fontQuality))
 {
 }
Exemple #2
0
 public Gdi32Font(string faceName, FontSizeUnit fontSizeUnit, float size, Gdi32FontStyleInfo fontStyle, byte charSet, Gdi32FontQuality fontQuality)
     : this(ToFontCacheKey(faceName, fontSizeUnit, size, fontStyle, charSet, fontQuality))
 {
 }
        public static Gdi32Font GetPoolingFont(string faceName, FontSizeUnit fontSizeUnit, float size, Gdi32FontStyleInfo fontStyle, byte charSet, Gdi32FontQuality fontQuality)
        {
            lock (FontCache)
            {
                var key = Gdi32Font.ToFontCacheKey(faceName, fontSizeUnit, size, fontStyle, charSet, fontQuality);

                var font = new Gdi32Font(key);

                for (var node = FontCache.First; node != null; node = node.Next)
                {
                    if (node.Value.Key == key)
                    {
                        if (FontCache.First != node)
                        {
                            FontCache.Remove(node);
                            FontCache.AddFirst(node);
                        }

                        return(font);
                    }
                }

                FontCache.AddFirst(new FontCacheEntry(key, font));

                while (FontCache.Count > 20)
                {
                    var lastNode = FontCache.Last;
                    lastNode.Value.Font.Dispose();
                    FontCache.Remove(lastNode);
                }

                return(font);
            }
        }
Exemple #4
0
        internal static FontCacheKey ToFontCacheKey(string faceName, FontSizeUnit fontSizeUnit, float size, Gdi32FontStyleInfo fontStyle, byte charSet, Gdi32FontQuality fontQuality)
        {
            int height;

            switch (fontSizeUnit)
            {
            case FontSizeUnit.Pixel:
                height = (int)Math.Ceiling(size);
                break;

            case FontSizeUnit.DpiScaledPoint:
                throw new NotSupportedException();

            //height = (int)Math.Ceiling((double)((float)WindowsGraphicsCacheManager.MeasurementGraphics.DeviceContext.DpiY * size / 72f));
            //break;
            case FontSizeUnit.NonDpiScaledPoint:
                height = (int)Math.Ceiling(96.0 * size / 72.0);
                break;

            default:
                throw new ArgumentException(nameof(FontSizeUnit));
            }

            return(new FontCacheKey(faceName, height, fontStyle, charSet, fontQuality));
        }
 public static Gdi32Font GetPoolingFont(string faceName, FontSizeUnit fontSizeUnit, float size, int weight, byte italic, byte underline, byte strikeOut, byte charSet, Gdi32FontQuality fontQuality)
 {
     return(GetPoolingFont(faceName, fontSizeUnit, size, new Gdi32FontStyleInfo(weight, italic, underline, strikeOut), charSet, fontQuality));
 }