Exemplo n.º 1
0
        public static GDIFont GetOrCreateFont(Dictionary <string, GDIFont> gdiFonts, string fontFamily, float fontSize, RPLFormat.FontWeights fontWeight, RPLFormat.FontStyles fontStyle, RPLFormat.TextDecorations textDecoration)
        {
            string  key     = GDIFont.GetKey(fontFamily, fontSize, fontWeight, fontStyle, textDecoration);
            GDIFont gDIFont = default(GDIFont);

            if (gdiFonts.TryGetValue(key, out gDIFont))
            {
                return(gDIFont);
            }
            bool flag        = SharedRenderer.IsWeightBold(fontWeight);
            bool flag2       = fontStyle == RPLFormat.FontStyles.Italic;
            bool underLine   = false;
            bool lineThrough = false;

            switch (textDecoration)
            {
            case RPLFormat.TextDecorations.Underline:
                underLine = true;
                break;

            case RPLFormat.TextDecorations.LineThrough:
                lineThrough = true;
                break;
            }
            Font font = null;

            try
            {
                font    = FontCache.CreateGdiPlusFont(fontFamily, fontSize, ref flag, ref flag2, lineThrough, underLine);
                gDIFont = new GDIFont(key, font, fontSize);
                gdiFonts.Add(key, gDIFont);
                return(gDIFont);
            }
            catch
            {
                if (font != null && !gdiFonts.ContainsKey(key))
                {
                    font.Dispose();
                    font = null;
                }
                throw;
            }
        }
Exemplo n.º 2
0
        private static string GetKey(string fontFamily, float fontSize, RPLFormat.FontWeights fontWeight, RPLFormat.FontStyles fontStyle, RPLFormat.TextDecorations textDecoration)
        {
            StringBuilder stringBuilder = new StringBuilder("FO");

            stringBuilder.Append(fontFamily);
            stringBuilder.Append(fontSize.ToString(CultureInfo.InvariantCulture));
            if (SharedRenderer.IsWeightBold(fontWeight))
            {
                stringBuilder.Append('b');
            }
            else
            {
                stringBuilder.Append('n');
            }
            if (fontStyle == RPLFormat.FontStyles.Italic)
            {
                stringBuilder.Append('i');
            }
            else
            {
                stringBuilder.Append('n');
            }
            switch (textDecoration)
            {
            case RPLFormat.TextDecorations.Underline:
                stringBuilder.Append('u');
                break;

            case RPLFormat.TextDecorations.LineThrough:
                stringBuilder.Append('s');
                break;

            default:
                stringBuilder.Append('n');
                break;
            }
            return(stringBuilder.ToString());
        }