Module: HexaPDF::Content::TextRenderingMode

Defined in:
lib/hexapdf/content/graphics_state.rb

Overview

Defines all available text rendering modes as constants. Each text rendering mode is an instance of NamedValue. For use with e.g. Canvas#text_rendering_mode.

See: PDF2.0 s9.3.6

Constant Summary collapse

FILL =

Fill text.

Specify as 0 or :fill.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.text_rendering_mode(:fill)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
NamedValue.new(:fill, 0)
STROKE =

Stroke text.

Specify as 1 or :stroke.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.stroke_color("hp-blue").line_width(0.5)
canvas.text_rendering_mode(:stroke)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
NamedValue.new(:stroke, 1)
FILL_STROKE =

Fill, then stroke text.

Specify as 2 or :fill_stroke.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.stroke_color("hp-blue").line_width(0.5)
canvas.text_rendering_mode(:fill_stroke)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
NamedValue.new(:fill_stroke, 2)
INVISIBLE =

Neither fill nor stroke text (invisible).

Specify as 3 or :invisible.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.text_rendering_mode(:invisible)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
canvas.stroke_color("hp-blue").line_width(20).line(30, 20, 30, 80).stroke
NamedValue.new(:invisible, 3)
FILL_CLIP =

Fill text and add to path for clipping.

Specify as 4 or :fill_clip.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.text_rendering_mode(:fill_clip)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
canvas.stroke_color("hp-orange").line_width(20).line(30, 20, 30, 80).stroke
NamedValue.new(:fill_clip, 4)
STROKE_CLIP =

Stroke text and add to path for clipping.

Specify as 5 or :stroke_clip.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.stroke_color("hp-blue").line_width(0.5)
canvas.text_rendering_mode(:stroke_clip)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
canvas.stroke_color("hp-orange").line_width(20).line(30, 20, 30, 80).stroke
NamedValue.new(:stroke_clip, 5)
FILL_STROKE_CLIP =

Fill, then stroke text and add to path for clipping.

Specify as 6 or :fill_stroke_clip.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.stroke_color("hp-blue").line_width(0.5)
canvas.text_rendering_mode(:fill_stroke_clip)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
canvas.stroke_color("hp-orange").line_width(20).line(30, 20, 30, 80).stroke
NamedValue.new(:fill_stroke_clip, 6)
CLIP =

Add text to path for clipping.

Specify as 7 or :clip.

#>pdf-small-hide
canvas.font("Helvetica", size: 13)
canvas.stroke_color("hp-blue").line_width(0.5)
canvas.text_rendering_mode(:clip)
canvas.text("#{canvas.text_rendering_mode.name}", at: [10, 50])
canvas.stroke_color("hp-orange").line_width(20).line(30, 20, 30, 80).stroke
NamedValue.new(:clip, 7)

Class Method Summary collapse

Class Method Details

.normalize(style) ⇒ Object

Returns the argument normalized to a valid text rendering mode, i.e. a NamedValue instance.

  • 0 or :fill can be used for the FILL mode.

  • 1 or :stroke can be used for the STROKE mode.

  • 2 or :fill_stroke can be used for the FILL_STROKE mode.

  • 3 or :invisible can be used for the INVISIBLE mode.

  • 4 or :fill_clip can be used for the FILL_CLIP mode.

  • 5 or :stroke_clip can be used for the STROKE_CLIP mode.

  • 6 or :fill_stroke_clip can be used for the FILL_STROKE_CLIP mode.

  • 7 or :clip can be used for the CLIP mode.

  • Otherwise an error is raised.



326
327
328
329
330
331
332
333
334
335
336
337
338
339
# File 'lib/hexapdf/content/graphics_state.rb', line 326

def self.normalize(style)
  case style
  when :fill, 0 then FILL
  when :stroke, 1 then STROKE
  when :fill_stroke, 2 then FILL_STROKE
  when :invisible, 3 then INVISIBLE
  when :fill_clip, 4 then FILL_CLIP
  when :stroke_clip, 5 then STROKE_CLIP
  when :fill_stroke_clip, 6 then FILL_STROKE_CLIP
  when :clip, 7 then CLIP
  else
    raise ArgumentError, "Unknown text rendering mode: #{style}"
  end
end