예제 #1
0
파일: SvgDocument.cs 프로젝트: carbon/SVG
 private void Draw(ISvgRenderer renderer, ISvgBoundable boundable)
 {
     using (FontManager = new SvgFontManager())
     {
         renderer.SetBoundable(boundable);
         Render(renderer);
         FontManager = null;
     }
 }
예제 #2
0
        public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc)
        {
            // Split font family list on "," and then trim start and end spaces and quotes.
            var        fontParts = (fontFamilyList ?? string.Empty).Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' }));
            FontFamily family;
            IEnumerable <SvgFontFace> sFaces;

            // Find a the first font that exists in the list of installed font families.
            //styles from IE get sent through as lowercase.
            foreach (var f in fontParts)
            {
                if (doc != null && doc.FontDefns().TryGetValue(f, out sFaces))
                {
                    return(sFaces);
                }
                family = SvgFontManager.FindFont(f);
                if (family != null)
                {
                    return(family);
                }
#if !NETSTANDARD20
                family = PrivateFonts.Families.FirstOrDefault(ff => string.Equals(ff.Name, f, StringComparison.OrdinalIgnoreCase));
                if (family != null)
                {
                    return(family);
                }
#endif
                switch (f.ToLower())
                {
                case "serif":
                    return(System.Drawing.FontFamily.GenericSerif);

                case "sans-serif":
                    return(System.Drawing.FontFamily.GenericSansSerif);

                case "monospace":
                    return(System.Drawing.FontFamily.GenericMonospace);
                }
            }

            // No valid font family found from the list requested.
            return(System.Drawing.FontFamily.GenericSansSerif);
        }
예제 #3
0
        private IFontDefn GetFont(ISvgRenderer renderer, SvgElement owner, SvgFontManager fontManager)
        {
            var visual = owner?.Parents.OfType <SvgVisualElement>().FirstOrDefault();

            return(visual?.GetFont(renderer, fontManager));
        }
예제 #4
0
        /// <summary>
        /// Get the font information based on data stored with the text object or inherited from the parent.
        /// </summary>
        /// <returns></returns>
        internal IFontDefn GetFont(ISvgRenderer renderer, SvgFontManager fontManager)
        {
            // Get the font-size
            float fontSize;
            var   fontSizeUnit = this.FontSize;

            if (fontSizeUnit == SvgUnit.None || fontSizeUnit == SvgUnit.Empty)
            {
                fontSize = new SvgUnit(SvgUnitType.Em, 1.0f);
            }
            else
            {
                fontSize = fontSizeUnit.ToDeviceValue(renderer, UnitRenderingType.Vertical, this);
            }

            var family = ValidateFontFamily(this.FontFamily, this.OwnerDocument, fontManager ?? this.OwnerDocument.FontManager);
            var sFaces = family as IEnumerable <SvgFontFace>;
            var ppi    = this.OwnerDocument?.Ppi ?? SvgDocument.PointsPerInch;

            if (sFaces == null)
            {
                var fontStyle = System.Drawing.FontStyle.Regular;

                // Get the font-weight
                switch (this.FontWeight)
                {
                case SvgFontWeight.Bold:
                case SvgFontWeight.W600:
                case SvgFontWeight.W700:
                case SvgFontWeight.W800:
                case SvgFontWeight.W900:
                    fontStyle |= System.Drawing.FontStyle.Bold;
                    break;

                case SvgFontWeight.Bolder:
                    switch (Parent?.FontWeight ?? SvgFontWeight.Normal)
                    {
                    case SvgFontWeight.W100:
                    case SvgFontWeight.W200:
                    case SvgFontWeight.W300:
                        break;

                    default:
                        fontStyle |= System.Drawing.FontStyle.Bold;
                        break;
                    }
                    break;

                case SvgFontWeight.Lighter:
                    switch (Parent?.FontWeight ?? SvgFontWeight.Normal)
                    {
                    case SvgFontWeight.W800:
                    case SvgFontWeight.W900:
                        fontStyle |= System.Drawing.FontStyle.Bold;
                        break;
                    }
                    break;
                }

                // Get the font-style
                switch (this.FontStyle)
                {
                case SvgFontStyle.Italic:
                case SvgFontStyle.Oblique:
                    fontStyle |= System.Drawing.FontStyle.Italic;
                    break;
                }

                // Get the text-decoration
                var textDecoration = this.TextDecoration;
                if (!textDecoration.HasFlag(SvgTextDecoration.None))
                {
                    if (textDecoration.HasFlag(SvgTextDecoration.LineThrough))
                    {
                        fontStyle |= System.Drawing.FontStyle.Strikeout;
                    }
                    if (textDecoration.HasFlag(SvgTextDecoration.Underline))
                    {
                        fontStyle |= System.Drawing.FontStyle.Underline;
                    }
                }

                var ff = family as FontFamily;
                if (!ff.IsStyleAvailable(fontStyle))
                {
                    // Do Something
                }

                // Get the font-family
                return(new GdiFontDefn(new Font(ff, fontSize, fontStyle, GraphicsUnit.Pixel), ppi));
            }
            else
            {
                var font = sFaces.First().Parent as SvgFont;
                if (font == null)
                {
                    var uri = sFaces.First().Descendants().OfType <SvgFontFaceUri>().First().ReferencedElement;
                    font = OwnerDocument.IdManager.GetElementById(uri) as SvgFont;
                }
                return(new SvgFontDefn(font, fontSize, ppi));
            }
        }
예제 #5
0
        public static object ValidateFontFamily(string fontFamilyList, SvgDocument doc, SvgFontManager fontManager)
        {
            // Split font family list on "," and then trim start and end spaces and quotes.
            var fontParts = (fontFamilyList ?? string.Empty).Split(new[] { ',' }).Select(fontName => fontName.Trim(new[] { '"', ' ', '\'' }));

            // Find a the first font that exists in the list of installed font families.
            // styles from IE get sent through as lowercase.
            foreach (var f in fontParts)
            {
                IEnumerable <SvgFontFace> fontFaces;
                if (doc != null && doc.FontDefns().TryGetValue(f, out fontFaces))
                {
                    return(fontFaces);
                }

                var family = fontManager.FindFont(f);
                if (family != null)
                {
                    return(family);
                }
            }

            // No valid font family found from the list requested.
            return(System.Drawing.FontFamily.GenericSansSerif);
        }