diff --git a/QuestPDF/Drawing/FontManager.cs b/QuestPDF/Drawing/FontManager.cs index 2efd877..fe37924 100644 --- a/QuestPDF/Drawing/FontManager.cs +++ b/QuestPDF/Drawing/FontManager.cs @@ -17,6 +17,7 @@ namespace QuestPDF.Drawing private static ConcurrentDictionary FontPaints = new(); private static ConcurrentDictionary ColorPaints = new(); private static ConcurrentDictionary ShaperFonts = new(); + private static ConcurrentDictionary Fonts = new(); private static ConcurrentDictionary TextShapers = new(); private static void RegisterFontType(SKData fontData, string? customName = null) @@ -154,5 +155,10 @@ namespace QuestPDF.Drawing { return TextShapers.GetOrAdd(style.PaintKey, _ => new TextShaper(style)); } + + internal static SKFont FoFont(this TextStyle style) + { + return Fonts.GetOrAdd(style.PaintKey, _ => style.ToPaint().ToFont()); + } } } \ No newline at end of file diff --git a/QuestPDF/Drawing/TextShaper.cs b/QuestPDF/Drawing/TextShaper.cs index 3a76cb0..c0d18c8 100644 --- a/QuestPDF/Drawing/TextShaper.cs +++ b/QuestPDF/Drawing/TextShaper.cs @@ -53,7 +53,7 @@ namespace QuestPDF.Drawing yOffset += glyphPositions[i].YAdvance * scaleY; } - return new TextShapingResult(Paint, glyphs); + return new TextShapingResult(glyphs); } void PopulateBufferWithText(Buffer buffer, string text) @@ -89,12 +89,10 @@ namespace QuestPDF.Drawing internal class TextShapingResult { - private SKPaint Paint { get; } public ShapedGlyph[] Glyphs { get; } - public TextShapingResult(SKPaint paint, ShapedGlyph[] glyphs) + public TextShapingResult(ShapedGlyph[] glyphs) { - Paint = paint; Glyphs = glyphs; } @@ -124,14 +122,14 @@ namespace QuestPDF.Drawing return end.Position.X - start.Position.X + end.Width; } - public DrawTextCommand? PositionText(int startIndex, int endIndex) + public DrawTextCommand? PositionText(int startIndex, int endIndex, TextStyle textStyle) { if (Glyphs.Length == 0) return null; using var skTextBlobBuilder = new SKTextBlobBuilder(); - var positionedRunBuffer = skTextBlobBuilder.AllocatePositionedRun(Paint.ToFont(), endIndex - startIndex + 1); + var positionedRunBuffer = skTextBlobBuilder.AllocatePositionedRun(textStyle.FoFont(), endIndex - startIndex + 1); var glyphSpan = positionedRunBuffer.GetGlyphSpan(); var positionSpan = positionedRunBuffer.GetPositionSpan(); diff --git a/QuestPDF/Elements/Text/Items/TextBlockSpan.cs b/QuestPDF/Elements/Text/Items/TextBlockSpan.cs index d730b10..3ea667f 100644 --- a/QuestPDF/Elements/Text/Items/TextBlockSpan.cs +++ b/QuestPDF/Elements/Text/Items/TextBlockSpan.cs @@ -139,7 +139,7 @@ namespace QuestPDF.Elements.Text.Items var glyphOffsetY = GetGlyphOffset(); - var textDrawingCommand = TextShapingResult.PositionText(request.StartIndex, request.EndIndex); + var textDrawingCommand = TextShapingResult.PositionText(request.StartIndex, request.EndIndex, Style); request.Canvas.DrawRectangle(new Position(0, request.TotalAscent), new Size(request.TextSize.Width, request.TextSize.Height), Style.BackgroundColor);