FontStyle.Italic seems to be ignored for a font loaded via FontCollection? #177
-
Hello. I'm new to loading fonts from files versus using the Here's a small reproduction: using var canvas = new Image<Rgba32>(300, 100, Rgba32.ParseHex("FFFFFF"));
var collection = new FontCollection();
var fontFamily = collection.Install("Data/Fonts/TF2secondary.ttf");
var regularFont = fontFamily.CreateFont(20, FontStyle.Regular);
var italicFont = fontFamily.CreateFont(20, FontStyle.Italic);
canvas.Mutate(x =>
{
x.DrawText("This text should be regular.", regularFont, Color.Black, new PointF(10, 10));
x.DrawText("This text should be italics.", italicFont, Color.Black, new PointF(10, 50));
});
await using var output = new MemoryStream();
await canvas.SaveAsPngAsync(output); I am able to use italics with this font in something like Word: I'm not sure if this is a limitation of the library, or if Word or other programs which use italics for fonts do some hackery i'm not aware of, or if I'm simply making assumptions that my code is correct when I'm actually missing something or messing something up. Any advice or solutions would be appreciated. The font is TF2 Secondary found on dafont for usage in testing your own repro. *Edit: It seems from your response in this discussion that maybe it has to do with the fact I'm just loading a single font file, and not a supposed "TF2 Secondary Italic" font file? As far as I can tell one doesn't exist, or as least I'm only installing a single .ttf file, so now I'm leaning towards "Word and other programs are doing some hackery to force the font to be italic" being the cause. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Yep. That's exactly what they do. https://graphicdesign.stackexchange.com/a/42413 You could do something similar by passing a |
Beta Was this translation helpful? Give feedback.
Yep. That's exactly what they do. https://graphicdesign.stackexchange.com/a/42413
You could do something similar by passing a
Matrix3x2
via theDrawingOptions
to theDrawText
method. Use theAffineTransformBuilder
to create the skew matrix usingTextMeasurer
to provide the text bounds to generate the transform.