lutaml 0.11.9 → 0.11.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/docs.yml +87 -0
  3. data/.github/workflows/links.yml +113 -0
  4. data/.github/workflows/rake.yml +52 -0
  5. data/.github/workflows/release.yml +83 -0
  6. data/.gitignore +29 -0
  7. data/CLAUDE.md +27 -0
  8. data/Gemfile +2 -2
  9. data/docs/.github/workflows/docs.yml +66 -0
  10. data/docs/.github/workflows/links.yml +78 -0
  11. data/docs/CONTINUATION_PLAN.md +168 -0
  12. data/docs/Gemfile +13 -0
  13. data/docs/MIGRATION_GUIDE.md +202 -0
  14. data/docs/README.md +252 -0
  15. data/docs/REFACTOR_PLAN.md +214 -0
  16. data/docs/_config.yml +144 -0
  17. data/docs/_guides/cli-usage.adoc +43 -0
  18. data/docs/_guides/diagram-generation.adoc +316 -0
  19. data/docs/_guides/index.adoc +136 -0
  20. data/docs/_guides/parsing/express-parsing.adoc +42 -0
  21. data/docs/_guides/parsing/index.adoc +78 -0
  22. data/docs/_guides/parsing/qea-parsing.adoc +47 -0
  23. data/docs/_guides/parsing/xmi-parsing.adoc +40 -0
  24. data/docs/_guides/repository-management.adoc +44 -0
  25. data/docs/_guides/sysml-modeling.adoc +37 -0
  26. data/docs/_guides/uml-modeling.adoc +115 -0
  27. data/docs/_pages/concepts/diagram-generation.adoc +337 -0
  28. data/docs/_pages/concepts/lur-format.adoc +711 -0
  29. data/docs/_pages/concepts/qea-parsing.adoc +418 -0
  30. data/docs/_pages/concepts/uml-models.adoc +43 -0
  31. data/docs/_pages/core/architecture.adoc +329 -0
  32. data/docs/_pages/core/installation.adoc +321 -0
  33. data/docs/_pages/core/overview.adoc +197 -0
  34. data/docs/_pages/index.adoc +49 -0
  35. data/docs/_pages/uml-syntax.adoc +1011 -0
  36. data/docs/_references/api/parsers.adoc +61 -0
  37. data/docs/_references/api/presenters.adoc +43 -0
  38. data/docs/_references/api/repository.adoc +67 -0
  39. data/docs/_references/cli/commands.adoc +72 -0
  40. data/docs/_references/configuration/diagram-styles.adoc +716 -0
  41. data/docs/_references/configuration/index.adoc +53 -0
  42. data/docs/_references/configuration/package-metadata.adoc +416 -0
  43. data/docs/_references/formats/index.adoc +43 -0
  44. data/docs/_references/formats/lur-format.adoc +39 -0
  45. data/docs/_references/formats/lutaml-syntax.adoc +379 -0
  46. data/docs/_references/formats/qea-structure.adoc +1364 -0
  47. data/docs/_references/index.adoc +198 -0
  48. data/docs/_tutorials/documentation-site.adoc +47 -0
  49. data/docs/_tutorials/first-lur-package.adoc +45 -0
  50. data/docs/_tutorials/generating-diagrams.adoc +42 -0
  51. data/docs/_tutorials/getting-started.adoc +45 -0
  52. data/docs/_tutorials/index.adoc +100 -0
  53. data/docs/_tutorials/querying-models.adoc +44 -0
  54. data/docs/examples/build_package.rb +12 -0
  55. data/docs/examples/build_site.rb +12 -0
  56. data/docs/examples/city_model.rb +21 -0
  57. data/docs/examples/present_class.rb +10 -0
  58. data/docs/examples/query_model.rb +12 -0
  59. data/docs/examples/render_diagram.rb +11 -0
  60. data/docs/index.adoc +64 -0
  61. data/docs/lml-models-and-instances-syntax.adoc +931 -0
  62. data/docs/lml.adoc +210 -0
  63. data/docs/lychee.toml +50 -0
  64. data/lib/lutaml/version.rb +1 -1
  65. data/lib/lutaml.rb +6 -1
  66. data/lutaml.gemspec +8 -6
  67. metadata +75 -131
  68. data/exe/lutaml-lml +0 -6
  69. data/exe/lutaml-lml-lsp +0 -11
  70. data/lib/lutaml/lml/association_label_resolver.rb +0 -52
  71. data/lib/lutaml/lml/cli.rb +0 -506
  72. data/lib/lutaml/lml/data_processor/attribute_processing.rb +0 -133
  73. data/lib/lutaml/lml/data_processor/collection_processing.rb +0 -37
  74. data/lib/lutaml/lml/data_processor/instance_processing.rb +0 -77
  75. data/lib/lutaml/lml/data_processor/value_declaration_processing.rb +0 -70
  76. data/lib/lutaml/lml/data_processor/value_processing.rb +0 -103
  77. data/lib/lutaml/lml/data_processor/view_processing.rb +0 -26
  78. data/lib/lutaml/lml/data_processor.rb +0 -59
  79. data/lib/lutaml/lml/diagnostic.rb +0 -149
  80. data/lib/lutaml/lml/document_builder.rb +0 -481
  81. data/lib/lutaml/lml/entity_types.rb +0 -30
  82. data/lib/lutaml/lml/executor/adapter_helpers.rb +0 -45
  83. data/lib/lutaml/lml/executor/condition_evaluator.rb +0 -169
  84. data/lib/lutaml/lml/executor/csv_adapter.rb +0 -88
  85. data/lib/lutaml/lml/executor/format_adapter.rb +0 -54
  86. data/lib/lutaml/lml/executor/xml_adapter.rb +0 -102
  87. data/lib/lutaml/lml/executor.rb +0 -96
  88. data/lib/lutaml/lml/format/adapter/document.rb +0 -11
  89. data/lib/lutaml/lml/format/adapter/mapping.rb +0 -31
  90. data/lib/lutaml/lml/format/adapter/standard_adapter.rb +0 -162
  91. data/lib/lutaml/lml/format/adapter/transform.rb +0 -11
  92. data/lib/lutaml/lml/format.rb +0 -29
  93. data/lib/lutaml/lml/formatter/base.rb +0 -79
  94. data/lib/lutaml/lml/formatter/canonical.rb +0 -736
  95. data/lib/lutaml/lml/formatter/elk.rb +0 -45
  96. data/lib/lutaml/lml/formatter/svg_pdf/path_parser.rb +0 -134
  97. data/lib/lutaml/lml/formatter/svg_pdf.rb +0 -285
  98. data/lib/lutaml/lml/formatter.rb +0 -11
  99. data/lib/lutaml/lml/grammar/lml.artifact.json +0 -14993
  100. data/lib/lutaml/lml/grammar/lml.parg +0 -389
  101. data/lib/lutaml/lml/grammar.rb +0 -60
  102. data/lib/lutaml/lml/has_attributes.rb +0 -14
  103. data/lib/lutaml/lml/import_resolver.rb +0 -96
  104. data/lib/lutaml/lml/layout/elk_engine.rb +0 -15
  105. data/lib/lutaml/lml/layout/elk_graph_builder.rb +0 -129
  106. data/lib/lutaml/lml/layout/elk_svg_markers.rb +0 -45
  107. data/lib/lutaml/lml/layout/elk_svg_renderer.rb +0 -119
  108. data/lib/lutaml/lml/layout/engine.rb +0 -17
  109. data/lib/lutaml/lml/layout.rb +0 -12
  110. data/lib/lutaml/lml/literal_value.rb +0 -32
  111. data/lib/lutaml/lml/lsp/conversions.rb +0 -78
  112. data/lib/lutaml/lml/lsp/keywords.rb +0 -43
  113. data/lib/lutaml/lml/lsp/server.rb +0 -378
  114. data/lib/lutaml/lml/lsp/store.rb +0 -68
  115. data/lib/lutaml/lml/lsp/transport.rb +0 -53
  116. data/lib/lutaml/lml/lsp.rb +0 -16
  117. data/lib/lutaml/lml/model_compiler/enums.rb +0 -172
  118. data/lib/lutaml/lml/model_compiler/hydration.rb +0 -123
  119. data/lib/lutaml/lml/model_compiler/serialization_mappings.rb +0 -188
  120. data/lib/lutaml/lml/model_compiler/string_formats.rb +0 -42
  121. data/lib/lutaml/lml/model_compiler/validation.rb +0 -65
  122. data/lib/lutaml/lml/model_compiler.rb +0 -323
  123. data/lib/lutaml/lml/models/action.rb +0 -10
  124. data/lib/lutaml/lml/models/association.rb +0 -29
  125. data/lib/lutaml/lml/models/cardinality.rb +0 -10
  126. data/lib/lutaml/lml/models/collection.rb +0 -11
  127. data/lib/lutaml/lml/models/constraint.rb +0 -23
  128. data/lib/lutaml/lml/models/data_type.rb +0 -41
  129. data/lib/lutaml/lml/models/derived_field.rb +0 -14
  130. data/lib/lutaml/lml/models/diagram.rb +0 -20
  131. data/lib/lutaml/lml/models/document.rb +0 -84
  132. data/lib/lutaml/lml/models/enum.rb +0 -38
  133. data/lib/lutaml/lml/models/fidelity.rb +0 -10
  134. data/lib/lutaml/lml/models/group.rb +0 -11
  135. data/lib/lutaml/lml/models/instance.rb +0 -26
  136. data/lib/lutaml/lml/models/instance_collection.rb +0 -16
  137. data/lib/lutaml/lml/models/instances_export.rb +0 -10
  138. data/lib/lutaml/lml/models/instances_import.rb +0 -11
  139. data/lib/lutaml/lml/models/mapping.rb +0 -15
  140. data/lib/lutaml/lml/models/mapping_rule.rb +0 -16
  141. data/lib/lutaml/lml/models/member_field.rb +0 -14
  142. data/lib/lutaml/lml/models/namespace.rb +0 -16
  143. data/lib/lutaml/lml/models/operation.rb +0 -26
  144. data/lib/lutaml/lml/models/operation_parameter.rb +0 -12
  145. data/lib/lutaml/lml/models/package.rb +0 -26
  146. data/lib/lutaml/lml/models/primitive_type.rb +0 -33
  147. data/lib/lutaml/lml/models/reference.rb +0 -23
  148. data/lib/lutaml/lml/models/serialization_mapping.rb +0 -19
  149. data/lib/lutaml/lml/models/string_format.rb +0 -16
  150. data/lib/lutaml/lml/models/top_element_attribute.rb +0 -116
  151. data/lib/lutaml/lml/models/uml_class.rb +0 -85
  152. data/lib/lutaml/lml/models/value.rb +0 -15
  153. data/lib/lutaml/lml/models/view_filter.rb +0 -11
  154. data/lib/lutaml/lml/models/view_import.rb +0 -11
  155. data/lib/lutaml/lml/parser.rb +0 -19
  156. data/lib/lutaml/lml/pipeline.rb +0 -73
  157. data/lib/lutaml/lml/positioned.rb +0 -13
  158. data/lib/lutaml/lml/preprocessor.rb +0 -130
  159. data/lib/lutaml/lml/quoting.rb +0 -60
  160. data/lib/lutaml/lml/source.rb +0 -49
  161. data/lib/lutaml/lml/source_position.rb +0 -20
  162. data/lib/lutaml/lml/symbol_index.rb +0 -200
  163. data/lib/lutaml/lml/transform.rb +0 -119
  164. data/lib/lutaml/lml/types/text_type.rb +0 -28
  165. data/lib/lutaml/lml/types.rb +0 -10
  166. data/lib/lutaml/lml/validator.rb +0 -458
  167. data/lib/lutaml/lml/version.rb +0 -10
  168. data/lib/lutaml/lml/view_resolution.rb +0 -32
  169. data/lib/lutaml/lml/view_resolver.rb +0 -48
  170. data/lib/lutaml/lml/yaml_parser.rb +0 -17
  171. data/lib/lutaml/lml.rb +0 -130
@@ -1,45 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Formatter
5
- # ELK-layout diagram formatter: builds an Elkrb::Graph from the
6
- # document, lays it out in-process (no external tools) and emits SVG,
7
- # PS/EPS/EMF through vectory, or PDF through the pdfrb-backed
8
- # SvgPdf renderer.
9
- class Elk
10
- VALID_TYPES = %i[svg ps eps emf pdf].freeze
11
-
12
- attr_reader :type
13
-
14
- def initialize(_attributes = {})
15
- @type = :svg
16
- end
17
-
18
- def type=(value)
19
- @type = value.to_sym
20
- return if VALID_TYPES.include?(@type)
21
-
22
- raise ArgumentError,
23
- "unsupported output type #{@type.inspect} (valid: #{VALID_TYPES.join(', ')})"
24
- end
25
-
26
- def format(document)
27
- graph = Lutaml::Layout::ElkGraphBuilder.new.build(document)
28
- svg = Lutaml::Layout::ElkEngine.new(input: graph).render(:svg)
29
- @type == :svg ? svg : convert(svg)
30
- end
31
-
32
- private
33
-
34
- def convert(svg)
35
- return SvgPdf.new(svg).render if @type == :pdf
36
-
37
- require 'vectory'
38
- Vectory::Svg.new(svg).public_send(:"to_#{@type}").content
39
- rescue LoadError
40
- raise Error, 'The vectory gem is required for PS/EPS/EMF output: ' \
41
- 'add `gem "vectory"` to your Gemfile'
42
- end
43
- end
44
- end
45
- end
@@ -1,134 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Formatter
5
- class SvgPdf
6
- # Minimal SVG path data parser: absolute and relative M/m, L/l,
7
- # H/h, V/v, C/c, Z/z — enough for ELK geometry and arrow shapes.
8
- class PathParser
9
- Point = Struct.new(:x, :y)
10
- Line = Struct.new(:point) do
11
- def last_point
12
- point
13
- end
14
- end
15
- Curve = Struct.new(:c1, :c2, :point) do
16
- def last_point
17
- point
18
- end
19
- end
20
- Close = Struct.new(:last_point)
21
-
22
- attr_reader :subpaths
23
-
24
- def initialize(d, dx, dy)
25
- @dx = dx
26
- @dy = dy
27
- parse(d)
28
- end
29
-
30
- private
31
-
32
- def parse(d)
33
- tokens = d.scan(/[MmLlHhVvCcZz]|-?\d*\.?\d+(?:[eE][-+]?\d+)?/)
34
- current = Point.new(0.0, 0.0)
35
- start = current
36
- @subpaths = [[]]
37
- i = 0
38
- while i < tokens.size
39
- cmd = tokens[i]
40
- i += 1
41
- case cmd
42
- when 'Z', 'z'
43
- @subpaths.last << Close.new(start)
44
- current = start.dup
45
- when 'M', 'm'
46
- current, start = move_to(tokens, i, current, cmd == 'm')
47
- i += 2
48
- @subpaths << [] if cmd == 'm'
49
- when 'L', 'l'
50
- current = line_to(tokens, i, current, cmd == 'l')
51
- i += 2
52
- when 'H', 'h'
53
- current = h_line(tokens, i, current, cmd == 'h')
54
- i += 1
55
- when 'V', 'v'
56
- current = v_line(tokens, i, current, cmd == 'v')
57
- i += 1
58
- when 'C', 'c'
59
- current = curve_to(tokens, i, current, cmd == 'c')
60
- i += 6
61
- end
62
- end
63
- finish
64
- end
65
-
66
- def move_to(tokens, i, current, relative)
67
- x = num(tokens, i)
68
- y = num(tokens, i + 1)
69
- point = relative ? Point.new(current.x + x, current.y + y) : Point.new(x, y)
70
- [point, point.dup]
71
- end
72
-
73
- def line_to(tokens, i, current, relative)
74
- x = num(tokens, i)
75
- y = num(tokens, i + 1)
76
- point = relative ? Point.new(current.x + x, current.y + y) : Point.new(x, y)
77
- @subpaths.last << Line.new(point.dup)
78
- point
79
- end
80
-
81
- def h_line(tokens, i, current, relative)
82
- x = num(tokens, i) + (relative ? current.x : 0)
83
- point = Point.new(x, current.y)
84
- @subpaths.last << Line.new(point.dup)
85
- point
86
- end
87
-
88
- def v_line(tokens, i, current, relative)
89
- y = num(tokens, i) + (relative ? current.y : 0)
90
- point = Point.new(current.x, y)
91
- @subpaths.last << Line.new(point.dup)
92
- point
93
- end
94
-
95
- def curve_to(tokens, i, current, relative)
96
- c1 = Point.new(num(tokens, i), num(tokens, i + 1))
97
- c2 = Point.new(num(tokens, i + 2), num(tokens, i + 3))
98
- to = Point.new(num(tokens, i + 4), num(tokens, i + 5))
99
- if relative
100
- c1 = Point.new(c1.x + current.x, c1.y + current.y)
101
- c2 = Point.new(c2.x + current.x, c2.y + current.y)
102
- to = Point.new(to.x + current.x, to.y + current.y)
103
- end
104
- @subpaths.last << Curve.new(c1, c2, to)
105
- to
106
- end
107
-
108
- def num(tokens, i)
109
- tokens[i].to_f
110
- end
111
-
112
- def finish
113
- @subpaths.map { |segments| segments.map { |s| offset(s) } }
114
- .reject(&:empty?)
115
- end
116
-
117
- def offset(segment)
118
- case segment
119
- when Line
120
- Line.new(shift(segment.point))
121
- when Curve
122
- Curve.new(shift(segment.c1), shift(segment.c2), shift(segment.point))
123
- else
124
- segment
125
- end
126
- end
127
-
128
- def shift(point)
129
- Point.new(point.x + @dx, point.y + @dy)
130
- end
131
- end
132
- end
133
- end
134
- end
@@ -1,285 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- module Formatter
5
- # SVG-to-PDF renderer for ELK-layout diagrams (issue #53). Parses the
6
- # ELK SVG output and re-emits it through pdfrb's Canvas: base-14
7
- # standard fonts for text (metrics ship inside pdfrb, no external
8
- # font resources), stroke/fill operators for shapes, and arrow
9
- # markers drawn manually at polyline ends (SVG marker geometry is
10
- # resolved from the document's <defs> and inlined with rotation).
11
- class SvgPdf
12
- autoload :PathParser, 'lutaml/lml/formatter/svg_pdf/path_parser'
13
-
14
- FONT_VARIANTS = {
15
- 'Helvetica' => { bold: :Helvetica_Bold, normal: :Helvetica },
16
- 'Courier' => { bold: :Courier_Bold, normal: :Courier },
17
- 'Times' => { bold: :Times_Bold, normal: :Times_Roman }
18
- }.freeze
19
- ROUNDING = 0.5523
20
-
21
- def initialize(svg)
22
- @svg = svg
23
- end
24
-
25
- def render
26
- require 'pdfrb'
27
- doc = Pdfrb::Document.new
28
- page = doc.pages.add
29
- @canvas = page.canvas
30
- root = Moxml.parse(@svg).root
31
- @width, @height = page_dimensions(root)
32
- @canvas.line_width = 1
33
- @markers = {}
34
- @marker_parents = {}
35
- collect_markers(root, nil)
36
- walk(root, 0.0, 0.0)
37
- io = StringIO.new
38
- doc.write(io: io)
39
- io.string.b
40
- end
41
-
42
- private
43
-
44
- def page_dimensions(root)
45
- [float_attr(root, 'width', 612.0), float_attr(root, 'height', 792.0)]
46
- end
47
-
48
- def float_attr(node, name, fallback)
49
- node.attribute(name)&.value&.to_f || fallback
50
- end
51
-
52
- def collect_markers(node, _parent)
53
- node.children.each do |child|
54
- if child.name == 'marker'
55
- shape = child.children.find { |c| %w[path polygon polyline].include?(c.name) }
56
- if shape
57
- @markers[child.attribute('id')&.value] = shape
58
- @marker_parents[shape] = child
59
- end
60
- end
61
- collect_markers(child, node)
62
- end
63
- end
64
-
65
- # Depth-first walk applying cumulative translate(x,y).
66
- def walk(node, dx, dy)
67
- node.children.each do |child|
68
- # Whitespace between elements arrives as text nodes under
69
- # some moxml adapters; only elements carry geometry.
70
- next unless child.element?
71
-
72
- cdx, cdy = translate_of(child)
73
- case child.name
74
- when 'g'
75
- walk(child, dx + cdx, dy + cdy)
76
- when 'rect'
77
- draw_rect(child, dx + cdx, dy + cdy)
78
- when 'polyline'
79
- draw_polyline(child, dx, dy)
80
- when 'polygon'
81
- draw_polygon(child, dx, dy)
82
- when 'line'
83
- draw_line(child, dx, dy)
84
- when 'path'
85
- draw_path(child, dx + cdx, dy + cdy)
86
- when 'text'
87
- draw_text(child, dx + cdx, dy + cdy)
88
- end
89
- end
90
- end
91
-
92
- def translate_of(node)
93
- t = node.attribute('transform')&.value.to_s
94
- m = t.match(/translate\(\s*([-\d.]+)[,\s]+([-\d.]+)\s*\)/)
95
- m ? [m[1].to_f, m[2].to_f] : [0.0, 0.0]
96
- end
97
-
98
- # SVG user space is y-down; PDF is y-up.
99
- def pt(x, y)
100
- [x, @height - y]
101
- end
102
-
103
- def draw_rect(node, dx, dy)
104
- x = float_attr(node, 'x', 0.0) + dx
105
- y = float_attr(node, 'y', 0.0) + dy
106
- w = float_attr(node, 'width', 0.0)
107
- h = float_attr(node, 'height', 0.0)
108
- rx = float_attr(node, 'rx', 0.0)
109
- set_fill(node)
110
- set_stroke(node)
111
- if rx.positive?
112
- rounded_path(x, y, w, h, rx)
113
- else
114
- @canvas.rectangle(*pt(x, y), w, h)
115
- end
116
- paint(node)
117
- end
118
-
119
- def rounded_path(x, y, w, h, r)
120
- r = [r, w / 2.0, h / 2.0].min
121
- k = ROUNDING * r
122
- _, y2 = pt(x + w, y + h)
123
- top_left, = pt(x, y)
124
- @canvas.move_to(*pt(x + r, y))
125
- @canvas.line_to(*pt(x + w - r, y))
126
- @canvas.curve_to(x + w - r + k, y, x + w, y + r - k, x + w, y + r)
127
- @canvas.line_to(x + w, y + h - r)
128
- @canvas.curve_to(x + w, y + h - r + k, x + w - r + k, y + h, x + w - r, y2)
129
- @canvas.line_to(x + r, y2)
130
- @canvas.curve_to(x + r - k, y + h, x, y + h - r + k, x, y + h - r)
131
- @canvas.line_to(x, y + r)
132
- @canvas.curve_to(x, y + r - k, x + r - k, y, x + r, top_left)
133
- end
134
-
135
- def draw_polyline(node, dx, dy)
136
- points = point_list(node, dx, dy)
137
- return if points.empty?
138
-
139
- set_stroke(node)
140
- @canvas.line_width = float_attr(node, 'stroke-width', 1.0)
141
- @canvas.polyline(points.map { |x, y| pt(x, y) })
142
- @canvas.stroke
143
- draw_marker(node, points)
144
- end
145
-
146
- def draw_polygon(node, dx, dy)
147
- points = point_list(node, dx, dy)
148
- return if points.empty?
149
-
150
- set_fill(node)
151
- set_stroke(node)
152
- @canvas.polygon(points.map { |x, y| pt(x, y) })
153
- paint(node)
154
- end
155
-
156
- def draw_line(node, dx, dy)
157
- x1 = float_attr(node, 'x1', 0.0) + dx
158
- y1 = float_attr(node, 'y1', 0.0) + dy
159
- x2 = float_attr(node, 'x2', 0.0) + dx
160
- y2 = float_attr(node, 'y2', 0.0) + dy
161
- set_stroke(node)
162
- @canvas.line(*pt(x1, y1), *pt(x2, y2))
163
- end
164
-
165
- def point_list(node, dx, dy)
166
- node.attribute('points')&.value.to_s.scan(/(-?[\d.]+)[,\s]+(-?[\d.]+)/)
167
- .map { |x, y| [x.to_f + dx, y.to_f + dy] }
168
- end
169
-
170
- def draw_path(node, dx, dy)
171
- subpaths = PathParser.new(node.attribute('d')&.value.to_s, dx, dy).subpaths
172
- set_fill(node)
173
- set_stroke(node)
174
- subpaths.each do |segments|
175
- first = segments.first
176
- next unless first
177
-
178
- @canvas.move_to(*pt(*first.last_point))
179
- segments.each do |segment|
180
- case segment
181
- when PathParser::Line
182
- @canvas.line_to(*pt(*segment.point))
183
- when PathParser::Curve
184
- c1 = pt(*segment.c1)
185
- c2 = pt(*segment.c2)
186
- to = pt(*segment.point)
187
- @canvas.curve_to(*c1, *c2, *to)
188
- when PathParser::Close
189
- @canvas.close_path
190
- end
191
- end
192
- paint(node)
193
- end
194
- end
195
-
196
- def draw_marker(node, points)
197
- ref = node.attribute('marker-end')&.value.to_s[/url\(#([^)]+)\)/, 1]
198
- shape = @markers[ref]
199
- return unless shape && points.size >= 2
200
-
201
- (x1, y1), (x2, y2) = points[-2, 2]
202
- angle = Math.atan2(y2 - y1, x2 - x1)
203
- cos = Math.cos(angle)
204
- sin = Math.sin(angle)
205
- marker = @marker_parents[shape]
206
- ref_x = float_attr(marker, 'refX', 0.0)
207
- ref_y = float_attr(marker, 'refY', 0.0)
208
- set_fill(shape)
209
- set_stroke(shape)
210
- trace_marker(shape, x2, y2, cos, sin, ref_x, ref_y)
211
- paint(shape)
212
- end
213
-
214
- # Trace the marker's shape geometry translated to (x2,y2) with the
215
- # marker origin at (refX,refY), rotated by the edge direction.
216
- def trace_marker(shape, ox, oy, cos, sin, ref_x, ref_y)
217
- transform = lambda { |x, y|
218
- lx = x - ref_x
219
- ly = y - ref_y
220
- [ox + lx * cos - ly * sin, oy + lx * sin + ly * cos]
221
- }
222
- d = shape.name == 'path' ? shape.attribute('d')&.value.to_s : nil
223
- segments = d ? PathParser.new(d, 0.0, 0.0).subpaths.first : nil
224
- return unless segments&.any?
225
-
226
- first = segments.first.last_point
227
- @canvas.move_to(*pt(*transform.call(*first)))
228
- segments.each do |segment|
229
- case segment
230
- when PathParser::Line
231
- @canvas.line_to(*pt(*transform.call(*segment.point)))
232
- when PathParser::Curve
233
- @canvas.curve_to(*pt(*transform.call(*segment.c1)),
234
- *pt(*transform.call(*segment.c2)),
235
- *pt(*transform.call(*segment.point)))
236
- when PathParser::Close
237
- @canvas.close_path
238
- end
239
- end
240
- end
241
-
242
- def draw_text(node, dx, dy)
243
- x = float_attr(node, 'x', 0.0) + dx
244
- y = float_attr(node, 'y', 0.0) + dy
245
- size = float_attr(node, 'font-size', 12.0)
246
- @canvas.text(node.text.to_s, at: pt(x, y),
247
- font: font_for(node), size: size)
248
- end
249
-
250
- def font_for(node)
251
- family = node.attribute('font-family')&.value.to_s
252
- base = FONT_VARIANTS.keys.find { |k| family.include?(k) } || 'Helvetica'
253
- bold = node.attribute('font-weight')&.value.to_s =~ /bold/i
254
- FONT_VARIANTS[base][bold ? :bold : :normal]
255
- end
256
-
257
- def set_fill(node)
258
- @fill_color = color_attr(node, 'fill')
259
- @canvas.fill_color(@fill_color) if @fill_color
260
- end
261
-
262
- def set_stroke(node)
263
- @stroke_color = color_attr(node, 'stroke')
264
- @canvas.stroke_color(@stroke_color) if @stroke_color
265
- end
266
-
267
- def paint(node)
268
- fill = color_attr(node, 'fill')
269
- stroke = color_attr(node, 'stroke')
270
- if fill && fill != 'none' && stroke && stroke != 'none'
271
- @canvas.fill_stroke
272
- elsif fill && fill != 'none'
273
- @canvas.fill
274
- else
275
- @canvas.stroke
276
- end
277
- end
278
-
279
- def color_attr(node, name)
280
- value = node.attribute(name)&.value.to_s
281
- value =~ /\A#/ ? value : nil
282
- end
283
- end
284
- end
285
- end
@@ -1,11 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Lutaml
4
- # Output formatters: diagram renderers and the canonical LML emitter.
5
- module Formatter
6
- autoload :Base, "lutaml/lml/formatter/base"
7
- autoload :Elk, "lutaml/lml/formatter/elk"
8
- autoload :SvgPdf, "lutaml/lml/formatter/svg_pdf"
9
- autoload :Canonical, "lutaml/lml/formatter/canonical"
10
- end
11
- end