Module: Idml::TextEngine::Measurement

Defined in:
lib/idml/text_engine/measurement.rb

Overview

Height measurement for paragraphs — shape + wrap each run and sum the line count × leading. Used where a paragraph's full extent must be known before its lines are laid out (paragraph shading/border rects).

Constant Summary collapse

DEFAULT_POINT_SIZE =
12.0

Class Method Summary collapse

Class Method Details

.paragraph_height(paragraph, font, wrap_width) ⇒ Object

Returns the paragraph's rendered height at wrap_width: every run's wrapped line count × leading, plus paragraph SpaceBefore / SpaceAfter.



15
16
17
18
19
20
21
22
23
24
# File 'lib/idml/text_engine/measurement.rb', line 15

def self.paragraph_height(paragraph, font, wrap_width)
  lines_height = paragraph.runs.sum do |run|
    size = run.point_size || DEFAULT_POINT_SIZE
    lines = wrapped_lines(run, font, wrap_width, size)
    lines.length *
      TextEngine::VerticalLayout.leading_for(paragraph.auto_leading,
                                             size)
  end
  lines_height + space_before_after(paragraph)
end