mirror of
https://github.com/UglyToad/PdfPig.git
synced 2026-01-18 19:51:24 +08:00
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:
@@ -77,7 +77,9 @@
|
||||
letter.Width,
|
||||
letter.FontSize,
|
||||
fontDetails,
|
||||
letter.Color,
|
||||
letter.RenderingMode,
|
||||
letter.StrokeColor,
|
||||
letter.FillColor,
|
||||
letter.PointSize,
|
||||
letter.TextSequence);
|
||||
|
||||
|
||||
@@ -65,7 +65,9 @@
|
||||
letter.Width,
|
||||
letter.FontSize,
|
||||
letter.Font,
|
||||
letter.Color,
|
||||
letter.RenderingMode,
|
||||
letter.StrokeColor,
|
||||
letter.FillColor,
|
||||
letter.PointSize,
|
||||
letter.TextSequence);
|
||||
}
|
||||
|
||||
@@ -61,12 +61,33 @@
|
||||
/// Details about the font for this letter.
|
||||
/// </summary>
|
||||
public FontDetails Font { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 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 color of the letter.
|
||||
/// 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();
|
||||
|
||||
@@ -292,14 +292,7 @@
|
||||
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,26 +312,16 @@
|
||||
attachTo.Width,
|
||||
attachTo.FontSize,
|
||||
attachTo.Font,
|
||||
attachTo.Color,
|
||||
attachTo.RenderingMode,
|
||||
attachTo.StrokeColor,
|
||||
attachTo.FillColor,
|
||||
attachTo.PointSize,
|
||||
attachTo.TextSequence);
|
||||
}
|
||||
else
|
||||
{
|
||||
letter = new Letter(
|
||||
unicode,
|
||||
transformedGlyphBounds,
|
||||
transformedPdfBounds.BottomLeft,
|
||||
transformedPdfBounds.BottomRight,
|
||||
transformedPdfBounds.Width,
|
||||
fontSize,
|
||||
font.Details,
|
||||
color,
|
||||
pointSize,
|
||||
textSequence);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
// If we did not create a letter for a combined diacritic, create one here.
|
||||
if (letter == null)
|
||||
{
|
||||
letter = new Letter(
|
||||
unicode,
|
||||
@@ -348,7 +331,9 @@
|
||||
transformedPdfBounds.Width,
|
||||
fontSize,
|
||||
font.Details,
|
||||
color,
|
||||
currentState.FontState.TextRenderingMode,
|
||||
currentState.CurrentStrokingColor,
|
||||
currentState.CurrentNonStrokingColor,
|
||||
pointSize,
|
||||
textSequence);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user