1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
Description: Use deterministic values for gradients
Previously, Prawn used #hash for gradients. Unfortunately, this uses
#object_id internally and prevent Prawn to create PDF using gradients
in a reproducible manner.
.
We now instead use an internal Hash with an incremental index starting
at 1.
Author: Jérémy Bobbio <lunar@debian.org>
Forwarded: https://github.com/prawnpdf/prawn/pull/844
Last-Update: 2019-01-07
--- a/lib/prawn/graphics/patterns.rb
+++ b/lib/prawn/graphics/patterns.rb
@@ -78,7 +78,7 @@
def gradient_registry_key(gradient, opts)
_x1, _y1, x2, y2, transformation = gradient_coordinates(gradient, opts)
- if gradient[1].is_a?(Array) # axial
+ key = if gradient[1].is_a?(Array) # axial
[
transformation,
x2, y2,
@@ -92,7 +92,16 @@
gradient[3],
gradient[4], gradient[5]
]
- end.hash
+ end
+ unless @gradient_key_registry
+ @gradient_key_registry ||= {}
+ @gradient_key_index = 1
+ end
+ unless @gradient_key_registry.include?(key)
+ @gradient_key_registry[key] = @gradient_key_index
+ @gradient_key_index += 1
+ end
+ @gradient_key_registry[key]
end
def gradient_registry
|