Browse Source

Text: added support for fake italic (oblique)

Marcin Ziąbek 2 years ago
parent
commit
9f44d287f6
1 changed files with 12 additions and 1 deletions
  1. 12 1
      Source/QuestPDF/Drawing/FontManager.cs

+ 12 - 1
Source/QuestPDF/Drawing/FontManager.cs

@@ -140,12 +140,15 @@ namespace QuestPDF.Drawing
 
             static SKPaint Convert(TextStyle style)
             {
+                var targetTypeface = GetTypeface(style);
+                
                 return new SKPaint
                 {
                     Color = SKColor.Parse(style.Color),
-                    Typeface = GetTypeface(style),
+                    Typeface = targetTypeface,
                     TextSize = (style.Size ?? 12) * GetTextScale(style),
                     IsAntialias = true,
+                    TextSkewX = GetTextSkew(style, targetTypeface),
                 };
             }
 
@@ -194,6 +197,14 @@ namespace QuestPDF.Drawing
                     _ => throw new ArgumentOutOfRangeException()
                 };
             }
+
+            static float GetTextSkew(TextStyle originalTextStyle, SKTypeface targetTypeface)
+            {
+                // requested italic text but got typeface that is not italic
+                var useObliqueText = originalTextStyle.IsItalic == true && !targetTypeface.IsItalic;
+                
+                return useObliqueText ? -0.25f : 0;
+            }
         }
 
         internal static SKFontMetrics ToFontMetrics(this TextStyle style)