Class: Ea::Svg::EaEmitter::Element::HeaderRenderer

Inherits:
Object
  • Object
show all
Defined in:
lib/ea/svg/ea_emitter/element/header_renderer.rb

Overview

Emits the header text <g> containing stereotype + class name lines. Lines + styling computed by HeaderLines.

EA centers header text within the element bounds (computing the left edge from text-width approximation since SVG text x= is the start position, not the center).

Class Method Summary collapse

Class Method Details

.render(lines, bounds:, first_y:, family:, size:, size_unit: "pt", fill: "#000000", weight_normal: 400, weight_bold: 700, stroke_in_text: "#000000", width_factor: 0.65, line_offset: 6) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ea/svg/ea_emitter/element/header_renderer.rb', line 14

def self.render(lines, bounds:, first_y:, family:,
                size:, size_unit: "pt",
                fill: "#000000", weight_normal: 400, weight_bold: 700,
                stroke_in_text: "#000000", width_factor: 0.65,
                line_offset: 6)
  line_h = size + line_offset
  text_blocks = lines.each_with_index.map do |(text, style), idx|
    weight = case style
             when :bold, :bold_italic then weight_bold
             else weight_normal
             end
    font_style = (style == :italic || style == :bold_italic) ? "italic" : "normal"
    y = first_y + (idx * line_h)
    centered_x = center_x_for(text, bounds, size, width_factor)
    TextRenderer.new(
      content: text,
      x: centered_x, y: y,
      family: family, size: size, size_unit: size_unit,
      weight: weight, style: font_style, fill: fill,
      stroke_in_text: stroke_in_text, width_factor: width_factor
    ).to_svg
  end
  %(<g style="#{Style::TEXT_GROUP}">\n#{text_blocks.join("\n")}\n</g>)
end