Module: Idml::Render::WrapContour

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

Overview

Shape-mode text wrap: builds a PDF-space polygon from a page item's PathGeometry (Bézier segments flattened at a fixed resolution) and measures the horizontal overlap of a text line's band with the polygon, expanded by the wrap offsets. Band coverage uses even-odd ray casting at the band's midline, so compound paths with holes wrap correctly.

Defined Under Namespace

Classes: Shape

Constant Summary collapse

FLATTEN_STEPS =
8

Class Method Summary collapse

Class Method Details

.bounding_box(shape) ⇒ Object

The shape's bounding box: [left, bottom, right, top] in PDF coordinates, flattened across subpaths.



33
34
35
36
37
38
# File 'lib/idml/render/wrap_contour.rb', line 33

def self.bounding_box(shape)
  points = shape.polygons.flatten(1)
  xs = points.map(&:first)
  ys = points.map(&:last)
  [xs.min, ys.min, xs.max, ys.max]
end

.overlap_width(shape, line_y, line_height, frame_x, frame_right) ⇒ Object

Total horizontal overlap of the text line's band with the shape, expanded by the offsets and clipped to the frame. The caller (TextWrapResolver) owns inverse flipping.



135
136
137
138
139
140
141
142
# File 'lib/idml/render/wrap_contour.rb', line 135

def self.overlap_width(shape, line_y, line_height, frame_x,
                       frame_right)
  mid_y = line_y + (line_height / 2.0)
  width = shape.polygons.sum do |polygon|
    polygon_overlap(polygon, mid_y, shape.offset)
  end
  clip_width(width, frame_x, frame_right)
end

.shape(item, pref, page_height) ⇒ Object

Builds the wrap shape for an item's PathGeometry and wrap preference. Returns nil when the item has no geometry.



23
24
25
26
27
28
29
# File 'lib/idml/render/wrap_contour.rb', line 23

def self.shape(item, pref, page_height)
  polygons = polygons_for(item, page_height)
  return nil if polygons.empty?

  Shape.new(polygons: polygons, offset: wrap_offset(pref),
            inverse: pref.inverse, side: pref.text_wrap_side)
end