Module: Idml::Render::ParagraphRules

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

Overview

Emits paragraph-level rules (RuleAbove / RuleBelow) on a pdfrb canvas. Centralizes the IDML → PDF mapping for the paragraph rule attributes carried by StyleResolver::Paragraph.

Each rule is a horizontal stroke above (RuleAbove) or below (RuleBelow) the paragraph block. The rule's weight, color, tint, offset, and indent come from the PSR's RuleAbove* / RuleBelow* attributes; defaults approximate InDesign behavior when an attribute is missing.

Used by TextFrameRenderer so paragraph rules live in one place (DRY).

Constant Summary collapse

DEFAULT_LINE_WEIGHT =
0.5
DEFAULT_TINT =
1.0
DEFAULT_OFFSET =
0.0

Class Method Summary collapse

Class Method Details

.emit_border(canvas, paragraph, context, top_y, bottom_y, frame_left, frame_right) ⇒ Object

Emits the paragraph's border: per-side strokes around the paragraph block, each side with its own line weight, drawn at the block rect expanded by the border offsets.



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/idml/render/paragraph_rules.rb', line 118

def self.emit_border(canvas, paragraph, context, top_y, bottom_y,
                     frame_left, frame_right)
  return unless paragraph.paragraph_border_on
  return unless top_y > bottom_y

  tint_value = decoration_tint(paragraph.paragraph_border_tint)
  return unless tint_value

  color = resolve_color(paragraph.paragraph_border_color,
                        tint_value, context)
  return unless color

  left, right, top, bottom = decoration_rect(
    paragraph, top_y, bottom_y, frame_left, frame_right,
    left_offset: paragraph.paragraph_border_left_offset,
    right_offset: paragraph.paragraph_border_right_offset,
    top_offset: paragraph.paragraph_border_top_offset,
    bottom_offset: paragraph.paragraph_border_bottom_offset
  )
  apply_rule_color(canvas, paragraph.paragraph_border_color,
                   tint_value, context)
  stroke_border_sides(canvas, paragraph, left, right, top, bottom)
end

.emit_rule_above(canvas, paragraph, context, top_y, frame_left, frame_right) ⇒ Object

Emits RuleAbove if paragraph.rule_above is true. The rule sits above the paragraph's first line. top_y is the y of the paragraph's top edge (before SpaceBefore is applied); frame_left / frame_right are the column's text bounds.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/idml/render/paragraph_rules.rb', line 26

def self.emit_rule_above(canvas, paragraph, context, top_y,
                         frame_left, frame_right)
  return unless paragraph.rule_above

  emit_rule(canvas, paragraph, context, top_y, frame_left,
            frame_right,
            weight: paragraph.rule_above_line_weight,
            color: paragraph.rule_above_color,
            tint: paragraph.rule_above_tint,
            offset: paragraph.rule_above_offset,
            left_indent: paragraph.rule_above_left_indent,
            right_indent: paragraph.rule_above_right_indent,
            width_mode: paragraph.rule_above_width,
            position: :above)
end

.emit_rule_below(canvas, paragraph, context, bottom_y, frame_left, frame_right) ⇒ Object

Emits RuleBelow if paragraph.rule_below is true. The rule sits below the paragraph's last line. bottom_y is the y of the paragraph's bottom edge (after SpaceAfter is applied).



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/idml/render/paragraph_rules.rb', line 45

def self.emit_rule_below(canvas, paragraph, context, bottom_y,
                         frame_left, frame_right)
  return unless paragraph.rule_below

  emit_rule(canvas, paragraph, context, bottom_y, frame_left,
            frame_right,
            weight: paragraph.rule_below_line_weight,
            color: paragraph.rule_below_color,
            tint: paragraph.rule_below_tint,
            offset: paragraph.rule_below_offset,
            left_indent: paragraph.rule_below_left_indent,
            right_indent: paragraph.rule_below_right_indent,
            width_mode: paragraph.rule_below_width,
            position: :below)
end

.emit_shading(canvas, paragraph, context, top_y, bottom_y, frame_left, frame_right) ⇒ Object

Emits the paragraph's shading: a fill rect behind the paragraph block (top_y..bottom_y within the column). The ParagraphShading* offsets expand the rect outward; tint scales the color. Color comes from Properties > ParagraphShadingColor (black when absent, per InDesign's default shading color).



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/idml/render/paragraph_rules.rb', line 91

def self.emit_shading(canvas, paragraph, context, top_y, bottom_y,
                      frame_left, frame_right)
  return unless paragraph.paragraph_shading_on
  return unless top_y > bottom_y

  tint_value = decoration_tint(paragraph.paragraph_shading_tint)
  return unless tint_value

  color = resolve_color(paragraph.paragraph_shading_color,
                        tint_value, context)
  return unless color

  left, right, top, bottom = decoration_rect(
    paragraph, top_y, bottom_y, frame_left, frame_right,
    left_offset: paragraph.paragraph_shading_left_offset,
    right_offset: paragraph.paragraph_shading_right_offset,
    top_offset: paragraph.paragraph_shading_top_offset,
    bottom_offset: paragraph.paragraph_shading_bottom_offset
  )
  canvas.fill_color(color)
  canvas.rectangle(left, bottom, right - left, top - bottom)
  canvas.fill
end