ea 0.6.34 → 0.6.36

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.
@@ -91,7 +91,7 @@ module Ea
91
91
  end
92
92
 
93
93
  # EA's scale factor varies by point size (GDI quantization):
94
- # Carlito regular fits 1.390 at 7pt but 1.432 at 9pt. Sizes
94
+ # Carlito regular fits 1.390 at 7pt but 1.440 at 9pt. Sizes
95
95
  # without a fitted entry use the style's default (7pt, the
96
96
  # corpus's dominant size).
97
97
  def factor_for(family, size_pt, weight, style)
@@ -59,7 +59,27 @@ module Ea
59
59
  # Element x-extent: logical bounds only (matches EA's canvas
60
60
  # left/right exactly).
61
61
  # Element y-extent: union of logical + image_bounds (image
62
- # extends below bounds for shadow / image padding).
62
+ # extends below bounds for shadow / image padding), plus the
63
+ # "(from Parent)" subtitle extent: EA draws the subtitle 15px
64
+ # below the body and its text descent adds ~4 more, reserving
65
+ # 19px of canvas below subtitle-bearing packages (the +19
66
+ # height family: 05DF5000 Main, Metadata All, package
67
+ # Clients/Suppliers contexts).
68
+ SUBTITLE_CANVAS_EXTRA = 19
69
+
70
+ def subtitle_points
71
+ pts = []
72
+ (diagram.elements || []).each do |e|
73
+ primary = e.bounds || e.image_bounds
74
+ next unless primary
75
+ next unless subtitle_extends_below?(e)
76
+
77
+ pts << [primary.x, primary.y + primary.height +
78
+ SUBTITLE_CANVAS_EXTRA]
79
+ end
80
+ pts
81
+ end
82
+
63
83
  def element_points
64
84
  pts = []
65
85
  (diagram.elements || []).each do |e|
@@ -67,6 +87,10 @@ module Ea
67
87
  if primary
68
88
  pts << [primary.x, primary.y]
69
89
  pts << [primary.x + primary.width, primary.y + primary.height]
90
+ if subtitle_extends_below?(e)
91
+ pts << [primary.x, primary.y + primary.height +
92
+ SUBTITLE_CANVAS_EXTRA]
93
+ end
70
94
  end
71
95
  if e.bounds && e.image_bounds
72
96
  ib = e.image_bounds
@@ -76,6 +100,24 @@ module Ea
76
100
  end
77
101
  pts
78
102
  end
103
+
104
+ # Mirrors Compartment::PackageFromParent's render conditions:
105
+ # the subtitle draws only on ShowForeign diagrams for a
106
+ # placed package whose parent differs from the diagram's
107
+ # package.
108
+ def subtitle_extends_below?(element)
109
+ return false unless model_index
110
+ return false unless diagram.show_foreign
111
+
112
+ pkg = model_index[element.model_element_ref]
113
+ return false unless pkg.is_a?(Ea::Model::Package)
114
+
115
+ parent_id = pkg.parent_id
116
+ return false if parent_id.nil? || parent_id.empty?
117
+ return false if parent_id == diagram.package_id
118
+
119
+ model_index[parent_id].is_a?(Ea::Model::Package)
120
+ end
79
121
  end
80
122
  end
81
123
  end
@@ -42,6 +42,33 @@ module Ea
42
42
  new(min_x: min_x, min_y: min_y, width: width, height: height)
43
43
  end
44
44
 
45
+ # Second-pass canvas over the DRAWN extents captured by the
46
+ # element pass (grown classifiers, autosized packages, plus
47
+ # BoundsCalculator's subtitle reservation). EA sizes the
48
+ # canvas from drawn extents, so diagrams whose lowest/rightmost
49
+ # element grew get a taller/wider canvas than the stored-rect
50
+ # first pass provides.
51
+ def self.from_drawn(diagram, drawn_bounds, model_index: nil)
52
+ base = BoundsCalculator.new(diagram, model_index: model_index)
53
+ pts = []
54
+ drawn_bounds.each_value do |b|
55
+ pts << [b.x, b.y]
56
+ pts << [b.x + b.width, b.y + b.height]
57
+ end
58
+ extra = base.send(:subtitle_points)
59
+ min_x = (pts + extra).map(&:first).min || 0
60
+ min_y = (pts + extra).map(&:last).min || 0
61
+ max_x = (pts + extra).map(&:first).max || 0
62
+ max_y = (pts + extra).map(&:last).max || 0
63
+ return from(diagram, model_index: model_index) if pts.empty?
64
+
65
+ new(min_x: min_x, min_y: min_y,
66
+ width: (max_x - min_x) + BoundsCalculator::INSET_LEFT +
67
+ BoundsCalculator::INSET_RIGHT,
68
+ height: (max_y - min_y) + BoundsCalculator::INSET_TOP +
69
+ BoundsCalculator::INSET_BOTTOM)
70
+ end
71
+
45
72
  def view_box
46
73
  "0 0 #{width} #{height}"
47
74
  end
@@ -21,11 +21,25 @@ module Ea
21
21
 
22
22
  def render
23
23
  canvas = Canvas.from(diagram, model_index: model_index)
24
- layers = LayerSequencer.new(diagram, model_index: model_index,
25
- canvas: canvas, frame: frame,
26
- document: document)
27
- .layers
28
- .reject { |s| s.nil? || s.empty? }
24
+ seq = LayerSequencer.new(diagram, model_index: model_index,
25
+ canvas: canvas, frame: frame,
26
+ document: document)
27
+ seq.layers
28
+ # Second pass over the DRAWN extents: grown classifiers and
29
+ # autosized packages can exceed the stored-rect canvas EA
30
+ # sizes from drawn extents. Skip when the first pass already
31
+ # covers the drawn extents (the common case).
32
+ grown = seq.drawn_bounds
33
+ if grown && grown.values.any? &&
34
+ exceeds?(canvas, grown.values)
35
+ canvas = Canvas.from_drawn(diagram, grown,
36
+ model_index: model_index)
37
+ seq = LayerSequencer.new(diagram, model_index: model_index,
38
+ canvas: canvas, frame: frame,
39
+ document: document)
40
+ seq.layers
41
+ end
42
+ layers = seq.layers.reject { |s| s.nil? || s.empty? }
29
43
  image_layer = emit_images
30
44
  layers << image_layer if image_layer
31
45
 
@@ -55,6 +69,16 @@ module Ea
55
69
  %(<g id="images">\n#{fragments.join("\n")}\n</g>)
56
70
  end
57
71
 
72
+ # True when any drawn bound falls outside the stored-rect
73
+ # canvas content area.
74
+ def exceeds?(canvas, bounds)
75
+ bounds.any? do |b|
76
+ b.x < canvas.min_x || b.y < canvas.min_y ||
77
+ b.x + b.width > canvas.min_x + canvas.width ||
78
+ b.y + b.height > canvas.min_y + canvas.height
79
+ end
80
+ end
81
+
58
82
  def render_image(image)
59
83
  svg = Ea::Image::EmfRenderer.render(image.bytes)
60
84
  return nil unless svg
data/lib/ea/version.rb CHANGED
@@ -4,5 +4,5 @@ module Ea
4
4
  # Gem release version. Extracted to its own file so the
5
5
  # `gem-release` tool's `gem bump` can find and update it via the
6
6
  # standard `lib/<gem>/version.rb` convention.
7
- VERSION = "0.6.34"
7
+ VERSION = "0.6.36"
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ea
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.34
4
+ version: 0.6.36
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose Inc.