Added Letter properties RenderingMode, StrokeColor, FillColor and added those as mandatory

constructor arguments. Kept property Color, which contains either StrokeColor (if rendering mode is Stroke)
or FillColor (for all other rendering modes).
In PdfPageBuilder opted for default text rendering mode "Fill" which seems like a sensible default.
This commit is contained in:
mvantzet
2023-01-13 12:35:25 +01:00
parent 65bc754f5b
commit 06253966e4
5 changed files with 62 additions and 31 deletions

View File

@@ -77,7 +77,9 @@
letter.Width,
letter.FontSize,
fontDetails,
letter.Color,
letter.RenderingMode,
letter.StrokeColor,
letter.FillColor,
letter.PointSize,
letter.TextSequence);

View File

@@ -65,7 +65,9 @@
letter.Width,
letter.FontSize,
letter.Font,
letter.Color,
letter.RenderingMode,
letter.StrokeColor,
letter.FillColor,
letter.PointSize,
letter.TextSequence);
}

View File

@@ -63,10 +63,31 @@
public FontDetails Font { get; }
/// <summary>
/// The color of the letter.
/// Text rendering mode that indicates whether we should draw this letter's strokes,
/// fill, both, neither (in case of hidden text), etc.
/// If it calls for stroking the <see cref="StrokeColor" /> is used.
/// If it calls for filling, the <see cref="FillColor"/> is used.
/// In modes that perform both filling and stroking, the effect is as if each glyph outline were filled and then stroked in separate operations.
/// </summary>
public TextRenderingMode RenderingMode { get; }
/// <summary>
/// The primary color of the letter, which is either the <see cref="StrokeColor"/> in case
/// <see cref="RenderingMode"/> is <see cref="TextRenderingMode.Stroke"/>, or otherwise
/// it is the <see cref="FillColor"/>.
/// </summary>
public IColor Color { get; }
/// <summary>
/// Stroking color
/// </summary>
public IColor StrokeColor { get; }
/// <summary>
/// Non-stroking (fill) color
/// </summary>
public IColor FillColor { get; }
/// <summary>
/// The size of the font in points.
/// </summary>
@@ -86,7 +107,9 @@
double width,
double fontSize,
FontDetails font,
IColor color,
TextRenderingMode renderingMode,
IColor strokeColor,
IColor fillColor,
double pointSize,
int textSequence)
{
@@ -97,7 +120,17 @@
Width = width;
FontSize = fontSize;
Font = font;
Color = color ?? GrayColor.Black;
RenderingMode = renderingMode;
if (renderingMode == TextRenderingMode.Stroke)
{
Color = StrokeColor = strokeColor ?? GrayColor.Black;
FillColor = fillColor;
}
else
{
Color = FillColor = fillColor ?? GrayColor.Black;
StrokeColor = strokeColor;
}
PointSize = pointSize;
TextSequence = textSequence;
TextOrientation = GetTextOrientation();

View File

@@ -292,13 +292,6 @@
var transformedPdfBounds = PerformantRectangleTransformer
.Transform(renderingMatrix, textMatrix, transformationMatrix, new PdfRectangle(0, 0, boundingBox.Width, 0));
// If the text rendering mode calls for filling, the current nonstroking color in the graphics state is used;
// if it calls for stroking, the current stroking color is used.
// In modes that perform both filling and stroking, the effect is as if each glyph outline were filled and then stroked in separate operations.
// TODO: expose color as something more advanced
var color = currentState.FontState.TextRenderingMode != TextRenderingMode.Stroke
? currentState.CurrentNonStrokingColor
: currentState.CurrentStrokingColor;
Letter letter = null;
if (Diacritics.IsInCombiningDiacriticRange(unicode) && bytes.CurrentOffset > 0 && letters.Count > 0)
@@ -319,11 +312,16 @@
attachTo.Width,
attachTo.FontSize,
attachTo.Font,
attachTo.Color,
attachTo.RenderingMode,
attachTo.StrokeColor,
attachTo.FillColor,
attachTo.PointSize,
attachTo.TextSequence);
}
else
}
// If we did not create a letter for a combined diacritic, create one here.
if (letter == null)
{
letter = new Letter(
unicode,
@@ -333,22 +331,9 @@
transformedPdfBounds.Width,
fontSize,
font.Details,
color,
pointSize,
textSequence);
}
}
else
{
letter = new Letter(
unicode,
transformedGlyphBounds,
transformedPdfBounds.BottomLeft,
transformedPdfBounds.BottomRight,
transformedPdfBounds.Width,
fontSize,
font.Details,
color,
currentState.FontState.TextRenderingMode,
currentState.CurrentStrokingColor,
currentState.CurrentNonStrokingColor,
pointSize,
textSequence);
}

View File

@@ -895,7 +895,16 @@
var documentSpace = textMatrix.Transform(renderingMatrix.Transform(fontMatrix.Transform(rect)));
var letter = new Letter(c.ToString(), documentSpace, advanceRect.BottomLeft, advanceRect.BottomRight, width, (double)fontSize, FontDetails.GetDefault(name),
var letter = new Letter(
c.ToString(),
documentSpace,
advanceRect.BottomLeft,
advanceRect.BottomRight,
width,
(double)fontSize,
FontDetails.GetDefault(name),
TextRenderingMode.Fill,
GrayColor.Black,
GrayColor.Black,
(double)fontSize,
textSequence);