Method: HexaPDF::Content::Canvas#text_rendering_mode
- Defined in:
- lib/hexapdf/content/canvas.rb
#text_rendering_mode(m = nil, &bk) ⇒ Object Also known as: text_rendering_mode=
:call-seq:
canvas.text_rendering_mode => current_text_rendering_mode
canvas.text_rendering_mode(mode) => canvas
canvas.text_rendering_mode(mode) { block } => canvas
The text rendering mode determines if and how glyphs are rendered.
The mode parameter can be one of the following (also see TextRenderingMode):
- :fill or 0
-
The text is filled (default)
- :stroke or 1
-
The text is stroked.
- :fill_stroke or 2
-
The test is filled, then stroked.
- :invisible or 3
-
The text is neither filled nor stroked.
- :fill_clip or 4
-
The text is filled and added to the clipping path.
- :stroke_clip or 5
-
The text is stroked and added to the clipping path.
- :fill_stroke_clip or 6
-
The text is filled, then stroked and added to the clipping path.
- :clip or 7
-
The text is added to the clipping path.
either be a valid integer or one of the symbols :fill, :stroke,
Note that the return value is always a normalized text rendering mode value.
Returns the current text rendering mode value (see GraphicsState#text_rendering_mode) when no argument is given. Otherwise sets the text rendering mode using the mode argument and returns self. The setter version can also be called in the text_rendering_mode= form.
If the mode and a block are provided, the changed text rendering mode is only active during the block by saving and restoring the graphics state.
Examples:
#>pdf
canvas.text_rendering_mode(:fill)
canvas.text_rendering_mode # => #<NamedValue @name=:fill, @value = 0>
canvas.text_rendering_mode = :stroke # => #<NamedValue @name=:stroke, @value = 1>
canvas.text_rendering_mode(3) do
canvas.text_rendering_mode # => #<NamedValue @name=:invisible, @value = 3>
end
canvas.text_rendering_mode # => #<NamedValue @name=:stroke, @value = 1>
# visual example
canvas.font("Helvetica", size: 25)
canvas.stroke_color("green")
[:fill, :stroke, :fill_stroke, :invisible].each_with_index do |trm, index|
canvas.text_rendering_mode = trm
canvas.text("#{trm} text.", at: [20, 150 - 30 * index])
end
See: PDF2.0 s9.3.6, GraphicsState::TextRenderingMode
2020 2021 2022 |
# File 'lib/hexapdf/content/canvas.rb', line 2020 def text_rendering_mode(m = nil, &bk) gs_getter_setter(:text_rendering_mode, :Tr, m && TextRenderingMode.normalize(m), &bk) end |