public static Font GetLegacyFont(TextBlock element)
        {
            System.Drawing.FontStyle style = 0;

            FontStyle[] s = new System.Drawing.FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Strikeout, FontStyle.Underline };

            // Find the first default style that will work with this font...
            var family = new System.Drawing.FontFamily(element.FontFamily.Source);

            foreach (FontStyle fs in s)
            {
                if (family.IsStyleAvailable(fs))
                {
                    style = fs;
                    break;
                }
            }

            // Scale the font from 96 DPI to 72 DPI
            double size = PixelsToPoints(element, element.FontSize);

            if (element.FontWeight == System.Windows.FontWeights.Bold)
            {
                style |= System.Drawing.FontStyle.Bold;
            }

            if (element.FontStyle == System.Windows.FontStyles.Italic || element.FontStyle == System.Windows.FontStyles.Oblique)
            {
                style |= System.Drawing.FontStyle.Italic;
            }

            if (element.TextDecorations.Contains(System.Windows.TextDecorations.Underline[0]))
            {
                style |= System.Drawing.FontStyle.Underline;
            }

            if (element.TextDecorations.Contains(System.Windows.TextDecorations.Strikethrough[0]))
            {
                style |= System.Drawing.FontStyle.Strikeout;
            }

            var font = new Font(family, (float)size, style);

            return(font);
        }
Пример #2
0
        public static Font GetLegacyFont(TextBlock element)
        {
            System.Drawing.FontStyle style = 0;

            FontStyle[] s = new System.Drawing.FontStyle[] { FontStyle.Regular, FontStyle.Bold, FontStyle.Italic, FontStyle.Strikeout, FontStyle.Underline};

            // Find the first default style that will work with this font...
            var family = new System.Drawing.FontFamily(element.FontFamily.Source);
            foreach (FontStyle fs in s) {
                if (family.IsStyleAvailable(fs)) {
                    style = fs;
                    break;
                }
            }

            // Scale the font from 96 DPI to 72 DPI
            double size = PixelsToPoints(element, element.FontSize);

            if (element.FontWeight == System.Windows.FontWeights.Bold) {
                style |= System.Drawing.FontStyle.Bold;
            }

            if (element.FontStyle == System.Windows.FontStyles.Italic || element.FontStyle == System.Windows.FontStyles.Oblique) {
                style |= System.Drawing.FontStyle.Italic;
            }

            if (element.TextDecorations.Contains(System.Windows.TextDecorations.Underline[0])) {
                style |= System.Drawing.FontStyle.Underline;
            }

            if (element.TextDecorations.Contains(System.Windows.TextDecorations.Strikethrough[0])) {
                style |= System.Drawing.FontStyle.Strikeout;
            }

            var font = new Font(family, (float) size, style);

            return font;
        }