SVG icon indicating copy to clipboard operation
SVG copied to clipboard

Private font incorrectly displays italic style

Open huigy opened this issue 3 years ago • 2 comments

Description

I am using SVG.NET to convert SVG to PNG images, while some parts of the text need to use our private font file: Jyeoohai.ttf and jyeoohai-italic.ttf. I use svgfontManager.privateFontPathList.add (fonts) to load the above two font files, the resulting image text of normal form is correct, but the italic text is invalid. If I install the font file on Windows, the font styles are correct even without calling svgfontManager.privateFontPathList.add. However, software is going to be deployed to dozens of servers , so I don't want to install fonts on each one. Can SVG.NET dynamically load these character files?

Example data

<svg xmlns="http://www.w3.org/2000/svg">
  <text y="20" x="5" font-size="32px"
      font-style="normal" style="font-family: Jyeoohai">
    Normal font style
  </text>

  <text y="55" x="5" font-size="32px"
      font-style="italic" style="font-family: Jyeoohai">
    Italic font style
  </text>
</svg>

Used Versions

SVG version 3.3.0.0

huigy avatar Sep 28 '21 05:09 huigy

Can you show what do you mean by "the italic text is invalid"? I guess it is not possible to upload your private font...

mrbean-bremen avatar Oct 01 '21 19:10 mrbean-bremen

I used Open Sans to check how PrivateFontCollection behaves.

If font name is the same, font added earlier will be applied.

  1. OpenSans-Regular.ttf <- Applies as Open Sans
  2. OpenSans-Italic.ttf

@huigy I have never created font files, is it possible to combine all styles into one file ? What is structure of your font files ?

Also what I didn't understand was that when I added only OpenSans-Regular.ttf, all styles became true in the code below.

foreach (var family in privateFontCollection.Families)
{
    System.Diagnostics.Debug.WriteLine(family.Name); // "Open Sans"
    System.Diagnostics.Debug.WriteLine(" Bold is " + family.IsStyleAvailable(FontStyle.Bold)); // true
    System.Diagnostics.Debug.WriteLine(" Italic is " + family.IsStyleAvailable(FontStyle.Italic)); // true
    System.Diagnostics.Debug.WriteLine(" Underline is " + family.IsStyleAvailable(FontStyle.Underline)); // true
}

H1Gdev avatar Oct 04 '21 01:10 H1Gdev