idml 0.2.4 → 0.2.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 820fb71d72a5017eb34973c4a6fdd67ee5bcd7d10a11391c40dbeed7b7d7af7f
4
- data.tar.gz: 4f451cec97a6c9aa653bb2d443630fc1a27d1c4b4f1d9514f5d84ece917f9c6d
3
+ metadata.gz: 2d870be70e870df44bf1b0fcd658e5d5cc04b877e00d195f40666027c4a64b12
4
+ data.tar.gz: f3b5e9f8ea4e3eb181f66795746a090d4994c5ce7ea32cbf210b8366c9d801fa
5
5
  SHA512:
6
- metadata.gz: e87bcf39867cc0a98a791edb97c47fdadc8739a8fe23dd33cae0c86dcfb402e1f0acf217cbfe28c49c4c501e58089c2b7418a94fa5568b8979ab24676c9dd3a9
7
- data.tar.gz: 9d09a038c13d8d18e4b81012ef791a59ce54a64b7a91cb1d0a93364f1651576477f6db07a0a103e94aad7204b54f9b3e7ce7e2d202c81c76e31daf0f92d564a7
6
+ metadata.gz: 2bbbd17c0ef7958732c45ffc848f4e0ad89ac27406f79f42af769d49ce9f5dc88584b5e7b45e462a77d85c663b383113c11b8cd824942320de7baa57bf3ec77d
7
+ data.tar.gz: b6e86c5e3d233aa80ea12302db92781dac9d08e6cc55c28aa83858bc73b18875f78f7bebdf67e077c9c7fa462d617e8401763b421cf45a9c7e21d0663516eb8a
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- idml (0.2.4)
4
+ idml (0.2.5)
5
5
  bigdecimal
6
6
  fontisan
7
7
  lutaml-model (~> 0.8.18)
@@ -198,7 +198,7 @@ CHECKSUMS
198
198
  ffi (1.17.4-x86_64-linux-gnu) sha256=9d3db14c2eae074b382fa9c083fe95aec6e0a1451da249eab096c34002bc752d
199
199
  ffi (1.17.4-x86_64-linux-musl) sha256=3fdf9888483de005f8ef8d1cf2d3b20d86626af206cbf780f6a6a12439a9c49e
200
200
  fontisan (0.4.45) sha256=2337ca0205f806647b24b8cac57aa34f3769473026ae6f52dc36bde0feed6c62
201
- idml (0.2.4)
201
+ idml (0.2.5)
202
202
  json (2.21.2) sha256=1f1d3b7cf2b3ba1a69beca0bb6db13d5438b80bff3cd54cdaaa620b9b07c1c6a
203
203
  language_server-protocol (3.17.0.6) sha256=5ef2c0c138f8267e1bc631d3328347d354f96724b0af22f2c79516120443b7f0
204
204
  lint_roller (1.1.0) sha256=2c0c845b632a7d172cb849cc90c1bce937a28c5c8ccccb50dfd46a485003cc87
@@ -0,0 +1,24 @@
1
+ # TODO PDF 66: Real PDF gradient shadings via pdfrb 0.4.0
2
+
3
+ ## Status: DONE
4
+
5
+ ## What was implemented
6
+
7
+ RectangleRenderer now uses pdfrb's `Shadings#add_axial` +
8
+ `Canvas#fill_shading` for gradient fills instead of the discrete
9
+ 32-rectangle approximation. Produces mathematically smooth gradients
10
+ with zero banding.
11
+
12
+ When FillColor is a Gradient reference:
13
+ 1. Look up the Gradient element from Resources/Graphic.xml
14
+ 2. Resolve each GradientStop's color via ColorResolver
15
+ 3. Create a pdfrb axial shading: `add_axial(from:, to:, stops:)`
16
+ 4. Draw the rectangle path and fill with the shading
17
+
18
+ ## Acceptance criteria
19
+
20
+ - [x] RectangleRenderer detects Gradient/* fill colors
21
+ - [x] Creates pdfrb axial shading with resolved color stops
22
+ - [x] Uses canvas.fill_shading instead of discrete rectangles
23
+ - [x] Falls back to solid color for non-gradient fills
24
+ - [x] All tests pass
@@ -29,6 +29,11 @@ module Idml
29
29
  return unless rect.fill_color
30
30
  return if rect.fill_color == "Color/None"
31
31
 
32
+ if GradientResolver.gradient?(rect.fill_color)
33
+ render_gradient_fill(canvas, rect, context, box)
34
+ return
35
+ end
36
+
32
37
  color = context.color_resolver&.resolve(rect.fill_color)
33
38
  return unless color
34
39
 
@@ -38,6 +43,44 @@ module Idml
38
43
  end
39
44
  private_class_method :render_fill
40
45
 
46
+ def self.render_gradient_fill(canvas, rect, context, box)
47
+ stops = gradient_stops_for(rect, context)
48
+ return unless stops&.length&.>=(2)
49
+
50
+ shading = canvas.document.shadings.add_axial(
51
+ from: [box[:x], box[:y] + box[:height]],
52
+ to: [box[:x] + box[:width], box[:y]],
53
+ stops: stops,
54
+ )
55
+ canvas.rectangle(box[:x], box[:y], box[:width], box[:height])
56
+ canvas.fill_shading(shading)
57
+ end
58
+ private_class_method :render_gradient_fill
59
+
60
+ def self.gradient_stops_for(rect, context)
61
+ graphic = context.package&.graphic
62
+ return nil unless graphic
63
+
64
+ gradient = graphic.gradient.find do |g|
65
+ g.self_attr == rect.fill_color
66
+ end
67
+ return nil unless gradient
68
+ return nil unless gradient.gradient_stop.length >= 2
69
+
70
+ gradient_stops(gradient, context)
71
+ end
72
+ private_class_method :gradient_stops_for
73
+
74
+ def self.gradient_stops(gradient, context)
75
+ gradient.gradient_stop.filter_map do |stop|
76
+ color = context.color_resolver&.resolve(stop.stop_color)
77
+ next unless color
78
+
79
+ [stop.location || 0.0, ColorHelper.to_canvas(color)]
80
+ end
81
+ end
82
+ private_class_method :gradient_stops
83
+
41
84
  def self.render_stroke(canvas, rect, context, box)
42
85
  return unless strokeable?(rect)
43
86
 
data/lib/idml/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Idml
4
- VERSION = "0.2.4"
4
+ VERSION = "0.2.5"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idml
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ribose
@@ -206,6 +206,7 @@ files:
206
206
  - TODO.pdf/63-replace-fontmetrics-with-pdfrb.md
207
207
  - TODO.pdf/64-pipeline-cli-optimizations.md
208
208
  - TODO.pdf/65-pdfrb-019-integration.md
209
+ - TODO.pdf/66-gradient-shadings-pdfrb.md
209
210
  - TODO.pdf/README.md
210
211
  - exe/idml
211
212
  - idml.gemspec