diff --git a/pdf/creator/const.go b/pdf/creator/const.go index d75e7b26..3668a909 100644 --- a/pdf/creator/const.go +++ b/pdf/creator/const.go @@ -41,6 +41,39 @@ const ( TextAlignmentJustify ) +// TextRenderingMode determines whether showing text shall cause glyph +// outlines to be stroked, filled, used as a clipping boundary, or some +// combination of the three. +// See section 9.3 "Text State Parameters and Operators" and +// Table 106 (pp. 254-255 PDF32000_2008). +type TextRenderingMode int + +const ( + // TextRenderingModeFill (default) - Fill text. + TextRenderingModeFill TextRenderingMode = iota + + // TextRenderingModeStroke - Stroke text. + TextRenderingModeStroke + + // TextRenderingModeFillStroke - Fill, then stroke text. + TextRenderingModeFillStroke + + // TextRenderingModeInvisible - Neither fill nor stroke text (invisible). + TextRenderingModeInvisible + + // TextRenderingModeFillClip - Fill text and add to path for clipping. + TextRenderingModeFillClip + + // TextRenderingModeStrokeClip - Stroke text and add to path for clipping. + TextRenderingModeStrokeClip + + // TextRenderingModeFillStrokeClip - Fill, then stroke text and add to path for clipping. + TextRenderingModeFillStrokeClip + + // TextRenderingModeClip - Add text to path for clipping. + TextRenderingModeClip +) + // Relative and absolute positioning types. type positioning int diff --git a/pdf/creator/styled_paragraph.go b/pdf/creator/styled_paragraph.go index 045348f2..79a54269 100644 --- a/pdf/creator/styled_paragraph.go +++ b/pdf/creator/styled_paragraph.go @@ -656,6 +656,9 @@ func drawStyledParagraphOnBlock(blk *Block, p *StyledParagraph, ctx DrawContext) fontName := defaultFontName fontSize := defaultFontSize + // Set chunk rendering mode. + cc.Add_Tr(int64(style.RenderingMode)) + if p.alignment != TextAlignmentJustify || isLastLine { spaceMetrics, found := style.Font.GetRuneMetrics(' ') if !found { @@ -744,6 +747,9 @@ func drawStyledParagraphOnBlock(blk *Block, p *StyledParagraph, ctx DrawContext) } currX += chunkWidth + + // Reset rendering mode. + cc.Add_Tr(int64(TextRenderingModeFill)) } currY -= height diff --git a/pdf/creator/text_style.go b/pdf/creator/text_style.go index 96a21c7f..916fcd94 100644 --- a/pdf/creator/text_style.go +++ b/pdf/creator/text_style.go @@ -19,6 +19,9 @@ type TextStyle struct { // The size of the font. FontSize float64 + + // The rendering mode. + RenderingMode TextRenderingMode } // newTextStyle creates a new text style object using the specified font.