【问题标题】:Not displayed fonts while converting SVG image转换 SVG 图像时不显示字体
【发布时间】:2017-03-08 18:09:49
【问题描述】:

我正在使用this package 将 svg 图像转换为 png。 我的代码正在运行,看起来像这样:

SvgDocument svgDoc = SvgDocument.FromSvg<SvgDocument>(decoded);

foreach (var item in svgDoc.Children)
{
      SetFonts(item);
}

Bitmap image = svgDoc.Draw();

有一个已知的issue 显示字体,所以我正在尝试使用这种方法:

 public void SetFonts(SvgElement parent)
    {
        if (parent.HasChildren())
        {
            foreach (SvgElement child in parent.Children)
            {
                SetFonts(child);
            }
        }

        try
        {
            SvgText svgText = (SvgText)parent;
            svgText.FontFamily = "Arial";
            svgText.FontSize = 12;
            svgText.Font = "Arial";
        }
        catch
        {
        }
    }

它只找到 by Day 文本字符串,但轴的标题仍然不可见,可能是哪里出了问题?

这个 svg 文件是here

【问题讨论】:

    标签: c# svg png


    【解决方案1】:

    您需要将 CSS 放在 defs 部分。比如:

    <defs>
      <style type="text/css">
        @font-face {
          font-family: Delicious;
          src: url('../fonts/font.woff');
        }
      </style>
    </defs>
    

    【讨论】:

      猜你喜欢
      • 2016-07-30
      • 2012-10-06
      • 2021-01-11
      • 1970-01-01
      • 2020-05-11
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2012-05-08
      相关资源
      最近更新 更多