コード例 #1
0
        private int GetFontStyle(SvgTextContentElement element)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            int    style      = (int)FontStyle.Regular;
            string fontWeight = element.GetPropertyValue("font-weight");

            if (fontWeight == "bold" || fontWeight == "bolder" || fontWeight == "600" || fontWeight == "700" || fontWeight == "800" || fontWeight == "900")
            {
                style = style | (int)FontStyle.Bold;
            }

            if (string.Equals(element.GetPropertyValue("font-style"), "italic", comparer))
            {
                style = style | (int)FontStyle.Italic;
            }

            string textDeco = element.GetPropertyValue("text-decoration");

            if (string.Equals(textDeco, "line-through", comparer))
            {
                style = style | (int)FontStyle.Strikeout;
            }
            else if (string.Equals(textDeco, "underline", comparer))
            {
                style = style | (int)FontStyle.Underline;
            }
            return(style);
        }
コード例 #2
0
ファイル: GdiTextRendering.cs プロジェクト: naver/protonow
        private int GetGDIFontStyle(SvgTextContentElement element)
        {
            int    style      = (int)FontStyle.Regular;
            string fontWeight = element.GetPropertyValue("font-weight");

            if (fontWeight == "bold" || fontWeight == "bolder" || fontWeight == "600" || fontWeight == "700" || fontWeight == "800" || fontWeight == "900")
            {
                style = style | (int)FontStyle.Bold;
            }

            if (element.GetPropertyValue("font-style") == "italic")
            {
                style = style | (int)FontStyle.Italic;
            }

            string textDeco = element.GetPropertyValue("text-decoration");

            if (textDeco == "line-through")
            {
                style = style | (int)FontStyle.Strikeout;
            }
            else if (textDeco == "underline")
            {
                style = style | (int)FontStyle.Underline;
            }
            return(style);
        }
コード例 #3
0
        private StringFormat GetStringFormat(SvgTextContentElement element)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            StringFormat sf = new StringFormat();

            bool doAlign = true;

            if (element is SvgTSpanElement || element is SvgTRefElement)
            {
                SvgTextPositioningElement posElement = (SvgTextPositioningElement)element;
                if (posElement.X.AnimVal.NumberOfItems == 0)
                {
                    doAlign = false;
                }
            }

            if (doAlign)
            {
                string anchor = element.GetPropertyValue("text-anchor");
                if (string.Equals(anchor, "middle", comparer))
                {
                    sf.Alignment = StringAlignment.Center;
                }
                if (string.Equals(anchor, "end", comparer))
                {
                    sf.Alignment = StringAlignment.Far;
                }
            }

            string dir = element.GetPropertyValue("direction");

            if (string.Equals(dir, "rtl", comparer))
            {
                if (sf.Alignment == StringAlignment.Far)
                {
                    sf.Alignment = StringAlignment.Near;
                }
                else if (sf.Alignment == StringAlignment.Near)
                {
                    sf.Alignment = StringAlignment.Far;
                }
                sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            }

            dir = element.GetPropertyValue("writing-mode");
            if (string.Equals(dir, "tb", comparer))
            {
                sf.FormatFlags = sf.FormatFlags | StringFormatFlags.DirectionVertical;
            }

            sf.FormatFlags = sf.FormatFlags | StringFormatFlags.MeasureTrailingSpaces;

            return(sf);
        }
コード例 #4
0
ファイル: GdiTextRendering.cs プロジェクト: naver/protonow
        private float GetComputedFontSize(SvgTextContentElement element)
        {
            string str      = element.GetPropertyValue("font-size");
            float  fontSize = 12;

            if (str.EndsWith("%"))
            {
                // percentage of inherited value
            }
            else if (new Regex(@"^\d").IsMatch(str))
            {
                // svg length
                fontSize = (float)new SvgLength(element, "font-size",
                                                SvgLengthDirection.Viewport, str, "10px").Value;
            }
            else if (str == "larger")
            {
            }
            else if (str == "smaller")
            {
            }
            else
            {
                // check for absolute value
            }

            return(fontSize);
        }
コード例 #5
0
        protected FontStyle GetTextFontStyle(SvgTextContentElement element)
        {
            string fontStyle = element.GetPropertyValue("font-style");

            if (string.IsNullOrWhiteSpace(fontStyle))
            {
                return(FontStyles.Normal);
            }

            var comparer = StringComparison.OrdinalIgnoreCase;

            if (string.Equals(fontStyle, "normal", comparer))
            {
                return(FontStyles.Normal);
            }
            if (string.Equals(fontStyle, "italic", comparer))
            {
                return(FontStyles.Italic);
            }
            if (string.Equals(fontStyle, "oblique", comparer))
            {
                return(FontStyles.Oblique);
            }

            return(FontStyles.Normal);
        }
コード例 #6
0
        protected TextDecorationCollection GetTextDecoration(SvgTextContentElement element)
        {
            var comparer = StringComparison.OrdinalIgnoreCase;

            string textDeco = element.GetPropertyValue("text-decoration");

            if (string.IsNullOrWhiteSpace(textDeco))
            {
                return(null);
            }
            if (string.Equals(textDeco, "line-through", comparer))
            {
                return(TextDecorations.Strikethrough);
            }
            if (string.Equals(textDeco, "underline", comparer))
            {
                return(TextDecorations.Underline);
            }
            if (string.Equals(textDeco, "overline", comparer))
            {
                return(TextDecorations.OverLine);
            }

            return(null);
        }
コード例 #7
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static FlowDirection GetTextDirection(SvgTextContentElement element)
        {
            string dir           = element.GetPropertyValue("direction");
            bool   isRightToLeft = (dir == "rtl");

            return(isRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight);
        }
コード例 #8
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static double GetComputedFontSize(SvgTextContentElement element)
        {
            string str      = element.GetPropertyValue("font-size");
            double fontSize = 12;

            if (str.EndsWith("%", StringComparison.Ordinal))
            {
                // percentage of inherited value
            }
            else if (_decimalNumber.IsMatch(str))
            {
                // svg length
                fontSize = new SvgLength(element, "font-size",
                                         SvgLengthDirection.Viewport, str, "10px").Value;
            }
            else if (str == "larger")
            {
            }
            else if (str == "smaller")
            {
            }
            else
            {
                // check for absolute value
            }

            return(fontSize);
        }
コード例 #9
0
        protected FontFamily GetTextFontFamily(SvgTextContentElement element)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            var        systemFontFamilies = Fonts.SystemFontFamilies;
            FontFamily family;

            var comparer = StringComparison.OrdinalIgnoreCase;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });

                    if (string.Equals(fontName, "serif", comparer))
                    {
                        family = WpfDrawingSettings.GenericSerif;
                    }
                    else if (string.Equals(fontName, "sans-serif", comparer))
                    {
                        family = WpfDrawingSettings.GenericSansSerif;
                    }
                    else if (string.Equals(fontName, "monospace", comparer))
                    {
                        family = WpfDrawingSettings.GenericMonospace;
                    }
                    else
                    {
                        var funcFamily = new Func <FontFamily, bool>(ff => string.Equals(ff.Source, fontName, comparer));
                        family = systemFontFamilies.FirstOrDefault(funcFamily);
                        if (family != null)
                        {
                            _actualFontName = fontName;
                        }
                    }
                    if (family != null)
                    {
                        return(family);
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            // No known font-family was found => default to "Arial Unicode MS"
            return(WpfDrawingSettings.DefaultFontFamily);
        }
コード例 #10
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static FontWeight GetTextFontWeight(SvgTextContentElement element)
        {
            string fontWeight = element.GetPropertyValue("font-weight");

            if (string.IsNullOrWhiteSpace(fontWeight))
            {
                return(FontWeights.Normal);
            }

            switch (fontWeight)
            {
            case CssConstants.ValNormal:
                return(FontWeights.Normal);

            case "bold":
                return(FontWeights.Bold);

            case "100":
                return(FontWeights.Thin);

            case "200":
                return(FontWeights.ExtraLight);

            case "300":
                return(FontWeights.Light);

            case "400":
                return(FontWeights.Normal);

            case "500":
                return(FontWeights.Medium);

            case "600":
                return(FontWeights.SemiBold);

            case "700":
                return(FontWeights.Bold);

            case "800":
                return(FontWeights.ExtraBold);

            case "900":
                return(FontWeights.Black);

            case "950":
                return(FontWeights.UltraBlack);
            }

            return(FontWeights.Normal);
        }
コード例 #11
0
        public static double GetComputedFontSize(SvgTextContentElement element)
        {
            string str      = element.GetPropertyValue(CssConstants.PropFontSize);
            double fontSize = 12;

            if (_decimalNumber.IsMatch(str))
            {
                // svg length
                var fontLength = new SvgLength(element, CssConstants.PropFontSize, SvgLengthDirection.Viewport, str, "10px");
                fontSize = fontLength.Value;
            }

            return(fontSize);
        }
コード例 #12
0
        public static double GetComputedFontSize(SvgTextContentElement element)
        {
            string str      = element.GetPropertyValue("font-size");
            double fontSize = 12;

            if (_decimalNumber.IsMatch(str))
            {
                // svg length
                fontSize = new SvgLength(element, "font-size",
                                         SvgLengthDirection.Viewport, str, "10px").Value;
            }

            return(fontSize);
        }
コード例 #13
0
        private float GetComputedFontSize(SvgTextContentElement element)
        {
            string str      = element.GetPropertyValue("font-size");
            float  fontSize = 12;

            if (_decimalNumber.IsMatch(str))
            {
                // svg length
                var fontLength = new SvgLength(element, "font-size", SvgLengthDirection.Viewport, str, "10px");
                fontSize = (float)fontLength.Value;
            }

            return(fontSize);
        }
コード例 #14
0
        public static string TrimText(SvgTextContentElement element, string val)
        {
            if (element.XmlSpace != "preserve")
            {
                val = val.Replace("\n", string.Empty);
            }
            val = _tabNewline.Replace(val, " ");

            var textTransform = element.GetPropertyValue("text-transform");

            if (!string.IsNullOrWhiteSpace(textTransform))
            {
                switch (textTransform)
                {
                case "capitalize":
                    val = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(val);
                    break;

                case "uppercase":
                    val = val.ToUpper(CultureInfo.CurrentCulture);
                    break;

                case "lowercase":
                    val = val.ToLower(CultureInfo.CurrentCulture);
                    break;

                case "full-width":
                case "full-size-kana":
                case "none":
                default:
                    break;
                }
            }

            //if (element.XmlSpace == "preserve" || element.XmlSpace == "default")
            if (element.XmlSpace == "preserve")
            {
                return(val);
            }
            if (element.XmlSpace == "default")
            {
                return(_multipleSpaces.Replace(val, " "));
                //return val;
            }
            return(val.Trim());
        }
コード例 #15
0
        protected FontFamily GetTextFontFamily(SvgTextContentElement element, double fontSize)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            FontFamily family;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });

                    if (String.Equals(fontName, "serif", StringComparison.OrdinalIgnoreCase))
                    {
                        family = WpfDrawingSettings.GenericSerif;
                    }
                    else if (String.Equals(fontName, "sans-serif", StringComparison.OrdinalIgnoreCase))
                    {
                        family = WpfDrawingSettings.GenericSansSerif;
                    }
                    else if (String.Equals(fontName, "monospace", StringComparison.OrdinalIgnoreCase))
                    {
                        family = WpfDrawingSettings.GenericMonospace;
                    }
                    else
                    {
                        family          = new FontFamily(fontName);
                        _actualFontName = fontName;
                    }

                    return(family);
                }
                catch
                {
                }
            }

            // no known font-family was found => default to Arial
            return(WpfDrawingSettings.DefaultFontFamily);
        }
コード例 #16
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static double GetComputedLineHeight(SvgTextContentElement element)
        {
            string str        = element.GetPropertyValue("line-height");
            double lineHeight = 13;

            if (str.EndsWith("%", StringComparison.Ordinal))
            {
                // percentage of inherited value
            }
            else if (_decimalNumber.IsMatch(str))
            {
                // svg length
                lineHeight = new SvgLength(element, "line-height",
                                           SvgLengthDirection.Viewport, str, "13px").Value;
            }

            return(lineHeight);
        }
コード例 #17
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static TextDecorationCollection GetTextDecoration(SvgTextContentElement element)
        {
            string textDeco = element.GetPropertyValue("text-decoration");

            if (textDeco == "line-through")
            {
                return(TextDecorations.Strikethrough);
            }
            if (textDeco == "underline")
            {
                return(TextDecorations.Underline);
            }
            if (textDeco == "overline")
            {
                return(TextDecorations.OverLine);
            }

            return(null);
        }
コード例 #18
0
        private FontFamily GetGDIFontFamily(SvgTextContentElement element, float fontSize)
        {
            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            FontFamily family;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });

                    if (fontName == "serif")
                    {
                        family = FontFamily.GenericSerif;
                    }
                    else if (fontName == "sans-serif")
                    {
                        family = FontFamily.GenericSansSerif;
                    }
                    else if (fontName == "monospace")
                    {
                        family = FontFamily.GenericMonospace;
                    }
                    else
                    {
                        family = new FontFamily(fontName);              // Font(,fontSize).FontFamily;
                    }
                    return(family);
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            // no known font-family was found => default to arial
            return(new FontFamily("Arial"));
        }
コード例 #19
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static FontFamily GetTextFontFamily(SvgTextContentElement element)
        {
            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });

                    if (string.Equals(fontName, "serif", StringComparison.OrdinalIgnoreCase))
                    {
                        fontName = GenericSerifFontFamily;
                    }
                    else if (string.Equals(fontName, "sans-serif", StringComparison.OrdinalIgnoreCase))
                    {
                        fontName = GenericSansSerifFontFamily;
                    }
                    else if (string.Equals(fontName, "monospace", StringComparison.OrdinalIgnoreCase))
                    {
                        fontName = GenericMonospaceFontFamily;
                    }

                    if (!string.IsNullOrWhiteSpace(fontName))
                    {
                        return(new FontFamily(fontName));
                    }
                }
                catch (Exception ex)
                {
                    Trace.WriteLine(ex);
                }
            }

            // no known font-family was found => default to Arial
            return(new FontFamily(DefaultFontFamily));
        }
コード例 #20
0
        protected FontStretch GetTextFontStretch(SvgTextContentElement element)
        {
            string fontStretch = element.GetPropertyValue("font-stretch");

            if (String.IsNullOrEmpty(fontStretch))
            {
                return(FontStretches.Normal);
            }

            switch (fontStretch)
            {
            case "normal":
                return(FontStretches.Normal);

            case "ultra-condensed":
                return(FontStretches.UltraCondensed);

            case "extra-condensed":
                return(FontStretches.ExtraCondensed);

            case "condensed":
                return(FontStretches.Condensed);

            case "semi-condensed":
                return(FontStretches.SemiCondensed);

            case "semi-expanded":
                return(FontStretches.SemiExpanded);

            case "expanded":
                return(FontStretches.Expanded);

            case "extra-expanded":
                return(FontStretches.ExtraExpanded);

            case "ultra-expanded":
                return(FontStretches.UltraExpanded);
            }

            return(FontStretches.Normal);
        }
コード例 #21
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static FontStretch GetTextFontStretch(SvgTextContentElement element)
        {
            string fontStretch = element.GetPropertyValue("font-stretch");

            if (string.IsNullOrWhiteSpace(fontStretch))
            {
                return(FontStretches.Normal);
            }

            switch (fontStretch)
            {
            case CssConstants.ValNormal:
                return(FontStretches.Normal);

            case "ultra-condensed":
                return(FontStretches.UltraCondensed);

            case "extra-condensed":
                return(FontStretches.ExtraCondensed);

            case "condensed":
                return(FontStretches.Condensed);

            case "semi-condensed":
                return(FontStretches.SemiCondensed);

            case "semi-expanded":
                return(FontStretches.SemiExpanded);

            case "expanded":
                return(FontStretches.Expanded);

            case "extra-expanded":
                return(FontStretches.ExtraExpanded);

            case "ultra-expanded":
                return(FontStretches.UltraExpanded);
            }

            return(FontStretches.Normal);
        }
コード例 #22
0
        protected FontStyle GetTextFontStyle(SvgTextContentElement element)
        {
            string fontStyle = element.GetPropertyValue("font-style");

            if (String.IsNullOrEmpty(fontStyle))
            {
                return(FontStyles.Normal);
            }

            if (fontStyle == "normal")
            {
                return(FontStyles.Normal);
            }
            if (fontStyle == "italic")
            {
                return(FontStyles.Italic);
            }
            if (fontStyle == "oblique")
            {
                return(FontStyles.Oblique);
            }

            return(FontStyles.Normal);
        }
コード例 #23
0
ファイル: WpfShapeHelper.cs プロジェクト: zellus/SharpVectors
        private static FontStyle GetTextFontStyle(SvgTextContentElement element)
        {
            string fontStyle = element.GetPropertyValue("font-style");

            if (string.IsNullOrWhiteSpace(fontStyle))
            {
                return(FontStyles.Normal);
            }

            if (fontStyle == CssConstants.ValNormal)
            {
                return(FontStyles.Normal);
            }
            if (fontStyle == "italic")
            {
                return(FontStyles.Italic);
            }
            if (fontStyle == "oblique")
            {
                return(FontStyles.Oblique);
            }

            return(FontStyles.Normal);
        }
コード例 #24
0
 protected FontStyle GetTextFontStyle(SvgTextContentElement element)
 {
     return(this.GetTextFontStyle(element.GetPropertyValue("font-style")));
 }
コード例 #25
0
        public override void RenderText(SvgTextContentElement element,
                                        ref Point ctp, string text, double rotate, WpfTextPlacement placement)
        {
            if (string.IsNullOrWhiteSpace(text))
            {
                return;
            }

            int    vertOrientation = -1;
            int    horzOrientation = -1;
            string orientationText = element.GetPropertyValue("glyph-orientation-vertical");

            if (!string.IsNullOrWhiteSpace(orientationText))
            {
                double orientationValue = 0;
                if (double.TryParse(orientationText, out orientationValue))
                {
                    vertOrientation = (int)orientationValue;
                }
            }
            orientationText = element.GetPropertyValue("glyph-orientation-horizontal");
            if (!string.IsNullOrWhiteSpace(orientationText))
            {
                double orientationValue = 0;
                if (double.TryParse(orientationText, out orientationValue))
                {
                    horzOrientation = (int)orientationValue;
                }
            }

            Point startPoint = ctp;
            IList <WpfTextRun> textRunList = WpfTextRun.BreakWords(text,
                                                                   vertOrientation, horzOrientation);

            for (int tr = 0; tr < textRunList.Count; tr++)
            {
                // For unknown reasons, FormattedText will split a text like "-70%" into two parts "-"
                // and "70%". We provide a shift to account for the split...
                double baselineShiftX = 0;
                double baselineShiftY = 0;

                WpfTextRun textRun = textRunList[tr];

                DrawingGroup verticalGroup = new DrawingGroup();

                DrawingContext verticalContext = verticalGroup.Open();
                DrawingContext currentContext  = _drawContext;

                _drawContext = verticalContext;

                this.DrawSingleLineText(element, ref ctp, textRun, rotate, placement);

                verticalContext.Close();

                _drawContext = currentContext;

                if (verticalGroup.Children.Count == 1)
                {
                    DrawingGroup textGroup = verticalGroup.Children[0] as DrawingGroup;
                    if (textGroup != null)
                    {
                        verticalGroup = textGroup;
                    }
                }

                string runText   = textRun.Text;
                int    charCount = runText.Length;

                double            totalHeight = 0;
                DrawingCollection drawings    = verticalGroup.Children;
                int itemCount = drawings != null ? drawings.Count : 0;
                for (int i = 0; i < itemCount; i++)
                {
                    Drawing      textDrawing = drawings[i];
                    DrawingGroup textGroup   = textDrawing as DrawingGroup;

                    if (vertOrientation == -1)
                    {
                        if (textGroup != null)
                        {
                            for (int j = 0; j < textGroup.Children.Count; j++)
                            {
                                GlyphRunDrawing glyphDrawing = textGroup.Children[j] as GlyphRunDrawing;
                                if (glyphDrawing != null)
                                {
                                    if (textRun.IsLatin)
                                    {
                                        GlyphRun glyphRun = glyphDrawing.GlyphRun;

                                        IList <ushort> glyphIndices = glyphRun.GlyphIndices;
                                        IDictionary <ushort, double> allGlyphWeights = glyphRun.GlyphTypeface.AdvanceWidths;
                                        double lastAdvanceWeight =
                                            allGlyphWeights[glyphIndices[glyphIndices.Count - 1]] * glyphRun.FontRenderingEmSize;

                                        totalHeight += glyphRun.ComputeAlignmentBox().Width + lastAdvanceWeight / 2d;
                                    }
                                    else
                                    {
                                        totalHeight += ChangeGlyphOrientation(glyphDrawing,
                                                                              baselineShiftX, baselineShiftY, false);
                                    }
                                }
                            }
                        }
                        else
                        {
                            GlyphRunDrawing glyphDrawing = textDrawing as GlyphRunDrawing;
                            if (glyphDrawing != null)
                            {
                                if (textRun.IsLatin)
                                {
                                    GlyphRun glyphRun = glyphDrawing.GlyphRun;

                                    IList <UInt16> glyphIndices = glyphRun.GlyphIndices;
                                    IDictionary <ushort, double> allGlyphWeights = glyphRun.GlyphTypeface.AdvanceWidths;
                                    double lastAdvanceWeight =
                                        allGlyphWeights[glyphIndices[glyphIndices.Count - 1]] * glyphRun.FontRenderingEmSize;

                                    totalHeight += glyphRun.ComputeAlignmentBox().Width + lastAdvanceWeight / 2d;
                                }
                                else
                                {
                                    totalHeight += ChangeGlyphOrientation(glyphDrawing,
                                                                          baselineShiftX, baselineShiftY, false);
                                }
                            }
                        }
                    }
                    else if (vertOrientation == 0)
                    {
                        if (textGroup != null)
                        {
                            for (int j = 0; j < textGroup.Children.Count; j++)
                            {
                                GlyphRunDrawing glyphDrawing = textGroup.Children[j] as GlyphRunDrawing;
                                if (glyphDrawing != null)
                                {
                                    baselineShiftX = ChangeGlyphOrientation(glyphDrawing,
                                                                            baselineShiftX, baselineShiftY, textRun.IsLatin);
                                    totalHeight += baselineShiftX;
                                }
                            }
                        }
                        else
                        {
                            GlyphRunDrawing glyphDrawing = textDrawing as GlyphRunDrawing;
                            if (textDrawing != null)
                            {
                                totalHeight += ChangeGlyphOrientation(glyphDrawing,
                                                                      baselineShiftX, baselineShiftY, textRun.IsLatin);
                            }
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }

                if (!this.IsMeasuring)
                {
                    _drawContext.DrawDrawing(verticalGroup);
                }

                if (tr < textRunList.Count)
                {
                    ctp.X         = startPoint.X;
                    ctp.Y         = startPoint.Y + totalHeight;
                    startPoint.Y += totalHeight;
                }
            }
        }
コード例 #26
0
        protected WpfFontFamilyInfo GetTextFontFamilyInfo(SvgTextContentElement element)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            FontStyle   fontStyle   = GetTextFontStyle(element);
            FontWeight  fontWeight  = GetTextFontWeight(element);
            FontStretch fontStretch = GetTextFontStretch(element);

            var comparer = StringComparison.OrdinalIgnoreCase;

            var docElement = element.OwnerDocument;

            ISet <string>  svgFontFamilies = docElement.SvgFontFamilies;
            IList <string> svgFontNames    = null;

            if (svgFontFamilies != null && svgFontFamilies.Count != 0)
            {
                svgFontNames = new List <string>();
            }
            var systemFontFamilies = Fonts.SystemFontFamilies;

            FontFamily family = null;

            WpfFontFamilyType familyType = WpfFontFamilyType.None;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });
                    if ((svgFontFamilies != null && svgFontFamilies.Count != 0) && svgFontFamilies.Contains(fontName))
                    {
                        svgFontNames.Add(fontName);
                        continue;
                    }

                    if (string.Equals(fontName, "serif", comparer))
                    {
                        family     = WpfDrawingSettings.GenericSerif;
                        familyType = WpfFontFamilyType.Generic;
                    }
                    else if (string.Equals(fontName, "sans-serif", comparer))
                    {
                        family     = WpfDrawingSettings.GenericSansSerif;
                        familyType = WpfFontFamilyType.Generic;
                    }
                    else if (string.Equals(fontName, "monospace", comparer))
                    {
                        family     = WpfDrawingSettings.GenericMonospace;
                        familyType = WpfFontFamilyType.Generic;
                    }
                    else
                    {
                        var funcFamily = new Func <FontFamily, bool>(ff => string.Equals(ff.Source, fontName, comparer));
                        family = systemFontFamilies.FirstOrDefault(funcFamily);
                        if (family != null)
                        {
                            _actualFontName = fontName;
                            familyType      = WpfFontFamilyType.System;
                        }
                    }

                    if (family != null)
                    {
                        return(new WpfFontFamilyInfo(familyType, _actualFontName, family,
                                                     fontWeight, fontStyle, fontStretch));
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            //// If set, use the SVG-Font...NOT READY YET
            //if (svgFontNames != null && svgFontNames.Count != 0)
            //{
            //    IList<SvgFontElement> svgFonts = docElement.GetFonts(svgFontNames);
            //    if (svgFonts != null && svgFonts.Count != 0)
            //    {
            //        // For a single match...
            //        if (svgFonts.Count == 1)
            //        {
            //            return new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
            //                fontWeight, fontStyle, fontStretch);
            //        }

            //        // For multiple matches, we will test the variants...
            //        string fontVariant = element.GetPropertyValue("font-variant");
            //        if (string.IsNullOrWhiteSpace(fontVariant))
            //        {
            //            // Not found, return the first match...
            //            return new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
            //                fontWeight, fontStyle, fontStretch);
            //        }

            //        foreach (var svgFont in svgFonts)
            //        {
            //            var fontFace = svgFont.FontFace;
            //            if (fontFace == null)
            //            {
            //                continue;
            //            }
            //            if (fontVariant.Equals(fontFace.FontVariant, comparer))
            //            {
            //                return new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
            //                    fontWeight, fontStyle, fontStretch);
            //            }
            //        }
            //    }
            //}

            // No known font-family was found => default to "Arial Unicode MS"
            return(new WpfFontFamilyInfo(familyType, _actualFontName,
                                         WpfDrawingSettings.DefaultFontFamily, fontWeight, fontStyle, fontStretch));
        }
コード例 #27
0
        protected WpfFontFamilyInfo GetTextFontFamilyInfo(SvgTextContentElement element)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontFamily.Split(new char[1] {
                ','
            });

            FontStyle   fontStyle   = GetTextFontStyle(element);
            FontWeight  fontWeight  = GetTextFontWeight(element);
            FontStretch fontStretch = GetTextFontStretch(element);

            var comparer   = StringComparison.OrdinalIgnoreCase;
            var docElement = element.OwnerDocument;

            ISet <string> svgFontFamilies = docElement.SvgFontFamilies;
            IDictionary <string, string> styledFontIds = docElement.StyledFontIds;

            IList <string> svgFontNames = null;

            if (svgFontFamilies != null && svgFontFamilies.Count != 0)
            {
                svgFontNames = new List <string>();
            }
            //var systemFontFamilies = Fonts.SystemFontFamilies;

            var wpfSettings         = _context.Settings;
            var fontFamilyNames     = wpfSettings.FontFamilyNames;
            var privateFontFamilies = wpfSettings.HasFontFamilies;

            FontFamily family = null;
            // using separate pointer to give less priority to generic font names
            FontFamily genericFamily = null;

            WpfFontFamilyType familyType = WpfFontFamilyType.None;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });
                    if (svgFontFamilies != null && svgFontFamilies.Count != 0)
                    {
                        if (svgFontFamilies.Contains(fontName))
                        {
                            svgFontNames.Add(fontName);
                            continue;
                        }
                        if (styledFontIds.ContainsKey(fontName))
                        {
                            string mappedFontName = styledFontIds[fontName];
                            if (svgFontFamilies.Contains(mappedFontName))
                            {
                                svgFontNames.Add(mappedFontName);
                                continue;
                            }
                        }
                    }

                    if (string.Equals(fontName, "serif", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericSerif;
                    }
                    else if (string.Equals(fontName, "sans-serif", comparer) ||
                             string.Equals(fontName, "sans serif", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericSansSerif;
                    }
                    else if (string.Equals(fontName, "monospace", comparer))
                    {
                        genericFamily = WpfDrawingSettings.GenericMonospace;
                    }
                    else if (styledFontIds.ContainsKey(fontName))
                    {
                        string mappedFontName = styledFontIds[fontName];
                        family = LookupFontFamily(mappedFontName, fontFamilyNames);
                        if (family != null)
                        {
                            _actualFontName = mappedFontName;
                            familyType      = WpfFontFamilyType.System;
                        }
                    }
                    else
                    {
                        // Try looking up fonts in the system font registry...
                        family = LookupFontFamily(fontName, fontFamilyNames);
                        if (family != null)
                        {
                            _actualFontName = fontName;
                            familyType      = WpfFontFamilyType.System;
                        }

                        // If not found, look through private fonts if available..
                        if (family == null && privateFontFamilies)
                        {
                            family = wpfSettings.LookupFontFamily(fontName);
                            if (family != null)
                            {
                                _actualFontName = fontName;
                                familyType      = WpfFontFamilyType.Private;
                            }
                        }
                    }

                    if (family != null)
                    {
                        return(new WpfFontFamilyInfo(familyType, _actualFontName, family,
                                                     fontWeight, fontStyle, fontStretch));
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            // If set, use the SVG-Font...
            if (svgFontNames != null && svgFontNames.Count != 0)
            {
                FontFamily altFamily = (genericFamily != null) ? genericFamily : WpfDrawingSettings.DefaultFontFamily;

                IList <SvgFontElement> svgFonts = docElement.GetFonts(svgFontNames);
                if (svgFonts != null && svgFonts.Count != 0)
                {
                    string fontVariant = element.GetPropertyValue("font-variant");

                    // For a single match...
                    if (svgFonts.Count == 1)
                    {
                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }

                    // For the defined font style...
                    if (fontStyle != FontStyles.Normal)
                    {
                        // Then it is either oblique or italic
                        SvgFontElement closeFont   = null;
                        SvgFontElement closestFont = null;
                        bool           isItalic    = fontStyle.Equals(FontStyles.Italic);
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            var typefaceStyle = GetTextFontStyle(fontFace.FontStyle);
                            if (fontStyle.Equals(typefaceStyle))
                            {
                                closeFont = svgFont;
                                if (closestFont == null)
                                {
                                    closestFont = svgFont;
                                }
                                var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                                if (fontVariant.Equals(fontFace.FontVariant, comparer))
                                {
                                    closestFont = svgFont;
                                    if (fontWeight.Equals(typefaceWeight))
                                    {
                                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                                   fontWeight, fontStyle, fontStretch);

                                        fontFamilyInfo.Variant = fontVariant;
                                        // For rendering that do not support the SVG Fonts...
                                        fontFamilyInfo.Family = altFamily;
                                        return(fontFamilyInfo);
                                    }
                                }
                            }
                            if (closeFont == null)
                            {
                                if (isItalic && typefaceStyle == FontStyles.Oblique)
                                {
                                    closeFont = svgFont;
                                }
                                if (!isItalic && typefaceStyle == FontStyles.Italic)
                                {
                                    closeFont = svgFont;
                                }
                            }
                        }
                        if (closestFont != null)
                        {
                            closeFont = closestFont;
                        }

                        if (closeFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(closeFont.FontFamily, closeFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                    }

                    SvgFontElement variantFont = null;
                    // For multiple matches, we will test the variants...
                    if (!string.IsNullOrWhiteSpace(fontVariant))
                    {
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            if (fontVariant.Equals(fontFace.FontVariant, comparer))
                            {
                                variantFont = svgFont;
                                // Check for more perfect match...
                                var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                                var typefaceStyle  = GetTextFontStyle(fontFace.FontStyle);
                                if (fontStyle.Equals(typefaceStyle) && fontWeight.Equals(typefaceWeight))
                                {
                                    var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                               fontWeight, fontStyle, fontStretch);

                                    fontFamilyInfo.Variant = fontVariant;
                                    // For rendering that do not support the SVG Fonts...
                                    fontFamilyInfo.Family = altFamily;
                                    return(fontFamilyInfo);
                                }
                            }
                        }

                        //if (variantFont != null)
                        //{
                        //    // If there was a matching variant but either style or weight not matched...
                        //    var fontFamilyInfo = new WpfFontFamilyInfo(variantFont.FontFamily, variantFont,
                        //        fontWeight, fontStyle, fontStretch);

                        //    fontFamilyInfo.Variant = fontVariant;
                        //    // For rendering that do not support the SVG Fonts...
                        //    fontFamilyInfo.Family = altFamily;
                        //    return fontFamilyInfo;
                        //}
                    }

                    // For the defined font weights...
                    if (fontWeight != FontWeights.Normal && fontWeight != FontWeights.Regular)
                    {
                        int            weightValue    = fontWeight.ToOpenTypeWeight();
                        int            selectedValue  = int.MaxValue;
                        SvgFontElement sameWeightFont = null;
                        SvgFontElement closestFont    = null;
                        foreach (var svgFont in svgFonts)
                        {
                            var fontFace = svgFont.FontFace;
                            if (fontFace == null)
                            {
                                continue;
                            }
                            var typefaceWeight = GetTextFontWeight(fontFace.FontWeight);
                            if (fontWeight.Equals(typefaceWeight))
                            {
                                sameWeightFont = svgFont;
                                var typefaceStyle = GetTextFontStyle(fontFace.FontStyle);
                                if (fontStyle.Equals(typefaceStyle))
                                {
                                    var fontFamilyInfo = new WpfFontFamilyInfo(svgFont.FontFamily, svgFont,
                                                                               fontWeight, fontStyle, fontStretch);

                                    fontFamilyInfo.Variant = fontVariant;
                                    // For rendering that do not support the SVG Fonts...
                                    fontFamilyInfo.Family = altFamily;
                                    return(fontFamilyInfo);
                                }
                            }

                            int weightDiff = Math.Abs(weightValue - typefaceWeight.ToOpenTypeWeight());
                            if (weightDiff < selectedValue)
                            {
                                closestFont   = svgFont;
                                selectedValue = weightDiff;
                            }
                        }

                        // If the weights matched, but not the style
                        if (sameWeightFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(sameWeightFont.FontFamily, sameWeightFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                        if (closestFont != null)
                        {
                            var fontFamilyInfo = new WpfFontFamilyInfo(closestFont.FontFamily, closestFont,
                                                                       fontWeight, fontStyle, fontStretch);

                            fontFamilyInfo.Variant = fontVariant;
                            // For rendering that do not support the SVG Fonts...
                            fontFamilyInfo.Family = altFamily;
                            return(fontFamilyInfo);
                        }
                    }

                    if (variantFont != null)
                    {
                        // If there was a matching variant but either style or weight not matched...
                        var fontFamilyInfo = new WpfFontFamilyInfo(variantFont.FontFamily, variantFont,
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }
                    else // If the variant is not found, return the first match...
                    {
                        var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                                                                   fontWeight, fontStyle, fontStretch);

                        fontFamilyInfo.Variant = fontVariant;
                        // For rendering that do not support the SVG Fonts...
                        fontFamilyInfo.Family = altFamily;
                        return(fontFamilyInfo);
                    }

                    //// For multiple matches, we will test the variants...
                    //if (string.IsNullOrWhiteSpace(fontVariant))
                    //{
                    //    // Not found, return the first match...
                    //    var fontFamilyInfo = new WpfFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
                    //        fontWeight, fontStyle, fontStretch);

                    //    fontFamilyInfo.Variant = fontVariant;
                    //    // For rendering that do not support the SVG Fonts...
                    //    fontFamilyInfo.Family = altFamily;
                    //    return fontFamilyInfo;
                    //}
                }
            }

            if (genericFamily != null)
            {
                return(new WpfFontFamilyInfo(WpfFontFamilyType.Generic, _actualFontName, genericFamily,
                                             fontWeight, fontStyle, fontStretch));
            }

            // No known font-family was found => default to "Arial"
            return(new WpfFontFamilyInfo(familyType, _actualFontName,
                                         WpfDrawingSettings.DefaultFontFamily, fontWeight, fontStyle, fontStretch));
        }
コード例 #28
0
        protected WpfTextStringFormat GetTextStringFormat(SvgTextContentElement element)
        {
            WpfTextStringFormat sf = WpfTextStringFormat.Default;

            bool doAlign = true;

            if (element is SvgTSpanElement || element is SvgTRefElement)
            {
                SvgTextPositioningElement posElement = (SvgTextPositioningElement)element;
                if (posElement.X.AnimVal.NumberOfItems == 0)
                {
                    doAlign = false;
                }
            }

            var comparer = StringComparison.OrdinalIgnoreCase;

            string dir           = element.GetPropertyValue("direction");
            bool   isRightToLeft = string.Equals(dir, "rtl", comparer);

            sf.Direction = isRightToLeft ? FlowDirection.RightToLeft : FlowDirection.LeftToRight;

            if (doAlign)
            {
                string anchor = element.GetPropertyValue("text-anchor");

                if (isRightToLeft)
                {
                    if (string.Equals(anchor, "middle", comparer))
                    {
                        sf.Anchor = WpfTextAnchor.Middle;
                    }
                    else if (string.Equals(anchor, "end", comparer))
                    {
                        sf.Anchor = WpfTextAnchor.Start;
                    }
                    else
                    {
                        sf.Anchor = WpfTextAnchor.End;
                    }
                }
                else
                {
                    if (string.Equals(anchor, "middle", comparer))
                    {
                        sf.Anchor = WpfTextAnchor.Middle;
                    }
                    else if (string.Equals(anchor, "end", comparer))
                    {
                        sf.Anchor = WpfTextAnchor.End;
                    }
                }
            }
            else
            {
                SvgTextElement textElement = element.ParentNode as SvgTextElement;
                if (textElement != null)
                {
                    string anchor = textElement.GetPropertyValue("text-anchor");
                    if (isRightToLeft)
                    {
                        if (string.Equals(anchor, "middle", comparer))
                        {
                            sf.Anchor = WpfTextAnchor.Middle;
                        }
                        else if (string.Equals(anchor, "end", comparer))
                        {
                            sf.Anchor = WpfTextAnchor.Start;
                        }
                        else
                        {
                            sf.Anchor = WpfTextAnchor.End;
                        }
                    }
                    else
                    {
                        if (string.Equals(anchor, "middle", comparer))
                        {
                            sf.Anchor = WpfTextAnchor.Middle;
                        }
                        else if (string.Equals(anchor, "end", comparer))
                        {
                            sf.Anchor = WpfTextAnchor.End;
                        }
                    }
                }
            }

            //if (isRightToLeft)
            //{
            //    if (sf.Alignment == TextAlignment.Right)
            //        sf.Alignment = TextAlignment.Left;
            //    else if (sf.Alignment == TextAlignment.Left)
            //        sf.Alignment = TextAlignment.Right;

            //    //sf.FormatFlags = StringFormatFlags.DirectionRightToLeft;
            //}

            //dir = element.GetPropertyValue("writing-mode");
            //if (dir == "tb")
            //{
            //    sf.FormatFlags = sf.FormatFlags | StringFormatFlags.DirectionVertical;
            //}

            //sf.FormatFlags = sf.FormatFlags | StringFormatFlags.MeasureTrailingSpaces;

            return(sf);
        }
コード例 #29
0
        protected FontWeight GetTextFontWeight(SvgTextContentElement element)
        {
            string fontWeight = element.GetPropertyValue("font-weight");

            if (string.IsNullOrWhiteSpace(fontWeight))
            {
                return(FontWeights.Normal);
            }

            switch (fontWeight)
            {
            case "normal":
                return(FontWeights.Normal);

            case "bold":
                return(FontWeights.Bold);

            case "100":
                return(FontWeights.Thin);

            case "200":
                return(FontWeights.ExtraLight);

            case "300":
                return(FontWeights.Light);

            case "400":
                return(FontWeights.Normal);

            case "500":
                return(FontWeights.Medium);

            case "600":
                return(FontWeights.SemiBold);

            case "700":
                return(FontWeights.Bold);

            case "800":
                return(FontWeights.ExtraBold);

            case "900":
                return(FontWeights.Black);

            case "950":
                return(FontWeights.UltraBlack);
            }

            if (string.Equals(fontWeight, "bolder", StringComparison.OrdinalIgnoreCase))
            {
                SvgTransformableElement parentElement = element.ParentNode as SvgTransformableElement;
                if (parentElement != null)
                {
                    fontWeight = parentElement.GetPropertyValue("font-weight");
                    if (!string.IsNullOrWhiteSpace(fontWeight))
                    {
                        return(this.GetBolderFontWeight(fontWeight));
                    }
                }
                return(FontWeights.ExtraBold);
            }
            if (string.Equals(fontWeight, "lighter", StringComparison.OrdinalIgnoreCase))
            {
                SvgTransformableElement parentElement = element.ParentNode as SvgTransformableElement;
                if (parentElement != null)
                {
                    fontWeight = parentElement.GetPropertyValue("font-weight");
                    if (!string.IsNullOrWhiteSpace(fontWeight))
                    {
                        return(this.GetLighterFontWeight(fontWeight));
                    }
                }
                return(FontWeights.Light);
            }

            return(FontWeights.Normal);
        }
コード例 #30
0
        private GdiFontFamilyInfo GetTextFontFamilyInfo(SvgTextContentElement element)
        {
            _actualFontName = null;

            string fontFamily = element.GetPropertyValue("font-family");

            string[] fontNames = fontNames = fontFamily.Split(new char[1] {
                ','
            });

            GdiFontStyles    fontStyle   = GetTextFontStyle(element);
            GdiFontWeights   fontWeight  = GetTextFontWeight(element);
            GdiFontStretches fontStretch = GetTextFontStretch(element);

            var comparer = StringComparison.OrdinalIgnoreCase;

            var docElement = element.OwnerDocument;

            ISet <string> svgFontFamilies = docElement.SvgFontFamilies;
            IDictionary <string, string> styledFontIds = docElement.StyledFontIds;

            IList <string> svgFontNames = null;

            if (svgFontFamilies != null && svgFontFamilies.Count != 0)
            {
                svgFontNames = new List <string>();
            }
            var systemFontFamilies = FontFamily.Families;

            FontFamily family = null;
            // using separate pointer to give less priority to generic font names
            FontFamily genericFamily = null;

            GdiFontFamilyType familyType = GdiFontFamilyType.None;

            foreach (string fn in fontNames)
            {
                try
                {
                    string fontName = fn.Trim(new char[] { ' ', '\'', '"' });
                    if (svgFontFamilies != null && svgFontFamilies.Count != 0)
                    {
                        if (svgFontFamilies.Contains(fontName))
                        {
                            svgFontNames.Add(fontName);
                            continue;
                        }
                        if (styledFontIds.ContainsKey(fontName))
                        {
                            string mappedFontName = styledFontIds[fontName];
                            if (svgFontFamilies.Contains(mappedFontName))
                            {
                                svgFontNames.Add(mappedFontName);
                                continue;
                            }
                        }
                    }

                    if (string.Equals(fontName, "serif", comparer))
                    {
                        genericFamily = GdiRenderingSettings.GenericSerif;
                    }
                    else if (string.Equals(fontName, "sans-serif", comparer) ||
                             string.Equals(fontName, "sans serif", comparer))
                    {
                        genericFamily = GdiRenderingSettings.GenericSansSerif;
                    }
                    else if (string.Equals(fontName, "monospace", comparer))
                    {
                        genericFamily = GdiRenderingSettings.GenericMonospace;
                    }
                    else if (styledFontIds.ContainsKey(fontName))
                    {
                        string mappedFontName = styledFontIds[fontName];
                        var    funcFamily     = new Func <FontFamily, bool>(ff => string.Equals(ff.Name, mappedFontName, comparer));
                        family = systemFontFamilies.FirstOrDefault(funcFamily);
                        if (family != null)
                        {
                            _actualFontName = mappedFontName;
                            familyType      = GdiFontFamilyType.System;
                        }
                    }
                    else
                    {
                        string normalizedFontName;
                        var    funcFamily = new Func <FontFamily, bool>(ff => string.Equals(ff.Name, fontName, comparer));
                        family = systemFontFamilies.FirstOrDefault(funcFamily);
                        if (family != null)
                        {
                            _actualFontName = fontName;
                            familyType      = GdiFontFamilyType.System;
                        }
                        else if (fontName.IndexOf('-') > 0)
                        {
                            normalizedFontName = fontName.Replace("-", " ");
                            funcFamily         = new Func <FontFamily, bool>(ff => string.Equals(ff.Name,
                                                                                                 normalizedFontName, comparer));
                            family = systemFontFamilies.FirstOrDefault(funcFamily);
                            if (family != null)
                            {
                                _actualFontName = normalizedFontName;
                                familyType      = GdiFontFamilyType.System;
                            }
                        }
                        else if (SplitByCaps(fontName, out normalizedFontName))
                        {
                            funcFamily = new Func <FontFamily, bool>(ff => string.Equals(ff.Name,
                                                                                         normalizedFontName, comparer));
                            family = systemFontFamilies.FirstOrDefault(funcFamily);
                            if (family != null)
                            {
                                _actualFontName = normalizedFontName;
                                familyType      = GdiFontFamilyType.System;
                            }
                        }
                    }

                    if (family != null)
                    {
                        return(new GdiFontFamilyInfo(familyType, _actualFontName, family,
                                                     fontWeight, fontStyle, fontStretch));
                    }
                }
                catch (Exception ex)
                {
                    Trace.TraceError(ex.ToString());
                }
            }

            //// If set, use the SVG-Font...Not Ready Yet!!!
            //if (svgFontNames != null && svgFontNames.Count != 0)
            //{
            //    IList<SvgFontElement> svgFonts = docElement.GetFonts(svgFontNames);
            //    if (svgFonts != null && svgFonts.Count != 0)
            //    {
            //        string fontVariant = element.GetPropertyValue("font-variant");

            //        // For a single match...
            //        if (svgFonts.Count == 1)
            //        {
            //            var fontFamilyInfo = new GdiFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
            //                fontWeight, fontStyle, fontStretch);

            //            fontFamilyInfo.Variant = fontVariant;
            //            return fontFamilyInfo;
            //        }

            //        // For multiple matches, we will test the variants...
            //        if (string.IsNullOrWhiteSpace(fontVariant))
            //        {
            //            // Not found, return the first match...
            //            var fontFamilyInfo = new GdiFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
            //                fontWeight, fontStyle, fontStretch);

            //            fontFamilyInfo.Variant = fontVariant;
            //            return fontFamilyInfo;
            //        }

            //        foreach (var svgFont in svgFonts)
            //        {
            //            var fontFace = svgFont.FontFace;
            //            if (fontFace == null)
            //            {
            //                continue;
            //            }
            //            if (fontVariant.Equals(fontFace.FontVariant, comparer))
            //            {
            //                var fontFamilyInfo = new GdiFontFamilyInfo(svgFont.FontFamily, svgFont,
            //                    fontWeight, fontStyle, fontStretch);

            //                fontFamilyInfo.Variant = fontVariant;
            //                return fontFamilyInfo;
            //            }
            //        }

            //        // If the variant is not found, return the first match...
            //        {
            //            var fontFamilyInfo = new GdiFontFamilyInfo(svgFonts[0].FontFamily, svgFonts[0],
            //                fontWeight, fontStyle, fontStretch);

            //            fontFamilyInfo.Variant = fontVariant;
            //            return fontFamilyInfo;
            //        }
            //    }
            //}

            if (genericFamily != null)
            {
                return(new GdiFontFamilyInfo(GdiFontFamilyType.Generic, _actualFontName, genericFamily,
                                             fontWeight, fontStyle, fontStretch));
            }

            // No known font-family was found => default to "Arial"
            return(new GdiFontFamilyInfo(familyType, _actualFontName,
                                         GdiRenderingSettings.DefaultFontFamily, fontWeight, fontStyle, fontStretch));
        }