Add TextStyle text rendering mode property

This commit is contained in:
Adrian-George Bostan 2019-01-30 20:10:51 +02:00
parent 3121645d50
commit b86acf161f
3 changed files with 42 additions and 0 deletions

View File

@ -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

View File

@ -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

View File

@ -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.