|
@@ -126,35 +126,47 @@ namespace QuestPDF.Elements.Text.Items
|
|
|
{
|
|
{
|
|
|
var fontMetrics = Style.ToFontMetrics();
|
|
var fontMetrics = Style.ToFontMetrics();
|
|
|
|
|
|
|
|
- var glyphOffsetY = GetVerticalGlyphOffsetForStyle(Style);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ var glyphOffset = GetGlyphOffset();
|
|
|
var text = Text.Substring(request.StartIndex, request.EndIndex - request.StartIndex);
|
|
var text = Text.Substring(request.StartIndex, request.EndIndex - request.StartIndex);
|
|
|
|
|
|
|
|
request.Canvas.DrawRectangle(new Position(0, request.TotalAscent), new Size(request.TextSize.Width, request.TextSize.Height), Style.BackgroundColor);
|
|
request.Canvas.DrawRectangle(new Position(0, request.TotalAscent), new Size(request.TextSize.Width, request.TextSize.Height), Style.BackgroundColor);
|
|
|
- request.Canvas.DrawText(text, new Position(0, glyphOffsetY), Style);
|
|
|
|
|
|
|
+ request.Canvas.DrawText(text, new Position(0, glyphOffset), Style);
|
|
|
|
|
|
|
|
// draw underline
|
|
// draw underline
|
|
|
if ((Style.HasUnderline ?? false) && fontMetrics.UnderlinePosition.HasValue)
|
|
if ((Style.HasUnderline ?? false) && fontMetrics.UnderlinePosition.HasValue)
|
|
|
- DrawLine(glyphOffsetY + fontMetrics.UnderlinePosition.Value, fontMetrics.UnderlineThickness ?? 1);
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ var underlineOffset = Style.FontPosition == FontPosition.Superscript ? 0 : glyphOffset;
|
|
|
|
|
+ DrawLine(fontMetrics.UnderlinePosition.Value + underlineOffset, fontMetrics.UnderlineThickness ?? 1);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
// draw stroke
|
|
// draw stroke
|
|
|
if ((Style.HasStrikethrough ?? false) && fontMetrics.StrikeoutPosition.HasValue)
|
|
if ((Style.HasStrikethrough ?? false) && fontMetrics.StrikeoutPosition.HasValue)
|
|
|
- DrawLine(glyphOffsetY + fontMetrics.StrikeoutPosition.Value, fontMetrics.StrikeoutThickness ?? 1);
|
|
|
|
|
-
|
|
|
|
|
|
|
+ {
|
|
|
|
|
+ var strikeoutThickness = fontMetrics.StrikeoutThickness ?? 1;
|
|
|
|
|
+ strikeoutThickness *= Style.FontPosition == FontPosition.Normal ? 1f : 0.625f;
|
|
|
|
|
+
|
|
|
|
|
+ DrawLine(fontMetrics.StrikeoutPosition.Value + glyphOffset, strikeoutThickness);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void DrawLine(float offset, float thickness)
|
|
void DrawLine(float offset, float thickness)
|
|
|
{
|
|
{
|
|
|
- request.Canvas.DrawRectangle(new Position(0, offset - thickness / 2f), new Size(request.TextSize.Width, thickness), Style.Color);
|
|
|
|
|
|
|
+ request.Canvas.DrawRectangle(new Position(0, offset), new Size(request.TextSize.Width, thickness), Style.Color);
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
- private static float GetVerticalGlyphOffsetForStyle(TextStyle style)
|
|
|
|
|
- {
|
|
|
|
|
- if (style.FontPosition == FontPosition.Superscript)
|
|
|
|
|
- return (style.Size ?? 12f) * -0.35f;
|
|
|
|
|
- if (style.FontPosition == FontPosition.Subscript)
|
|
|
|
|
- return (style.Size ?? 12f) * 0.1f;
|
|
|
|
|
|
|
+ float GetGlyphOffset()
|
|
|
|
|
+ {
|
|
|
|
|
+ var fontSize = Style.Size ?? 12f;
|
|
|
|
|
|
|
|
- return 0;
|
|
|
|
|
|
|
+ var offsetFactor = Style.FontPosition switch
|
|
|
|
|
+ {
|
|
|
|
|
+ FontPosition.Normal => 0,
|
|
|
|
|
+ FontPosition.Subscript => 0.1f,
|
|
|
|
|
+ FontPosition.Superscript => -0.35f,
|
|
|
|
|
+ _ => throw new ArgumentOutOfRangeException()
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ return fontSize * offsetFactor;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|