Module: Idml::Render::StrokeStyle

Defined in:
lib/idml/render/stroke_style.rb

Overview

Maps IDML stroke-style attributes on a page item to the four pdfrb Canvas setters that control PDF stroke rendering: line_cap=, line_join=, miter_limit=, dash_pattern=.

IDML → PDF enum mapping per PDF 32000-1 §8.4.3:

EndCap        

StrokeDashAndGap is a flat list [d1, g1, d2, g2, ...] — pdfrb accepts the same shape as dash_pattern=[array, phase].

Constant Summary collapse

CAP_MAP =
{
  "ButtEndCap" => 0,
  "RoundEndCap" => 1,
  "ProjectingEndCap" => 2,
}.freeze
JOIN_MAP =
{
  "MiterEndJoin" => 0,
  "RoundEndJoin" => 1,
  "BevelEndJoin" => 2,
}.freeze

Class Method Summary collapse

Class Method Details

.apply(canvas, item) ⇒ Object

Apply stroke-style settings from item to canvas inside a saved graphics state, then yield so the caller can emit the path and call canvas.stroke. The save/restore ensures cap/join/miter/dash settings don't bleed into subsequent strokes on the same page.



49
50
51
52
53
54
55
56
57
# File 'lib/idml/render/stroke_style.rb', line 49

def self.apply(canvas, item)
  canvas.save_graphics_state do
    set_cap(canvas, item.end_cap)
    set_join(canvas, item.end_join)
    set_miter(canvas, item.miter_limit)
    set_dash(canvas, item.stroke_dash_and_gap)
    yield
  end
end

.strokeable?(item) ⇒ Boolean

True when the item has a renderable stroke: a non-None stroke color and a positive stroke weight.

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/idml/render/stroke_style.rb', line 38

def self.strokeable?(item)
  !!(item.stroke_color &&
    item.stroke_color != "Color/None" &&
    item.stroke_weight&.positive?)
end