1
1
module Prawn ::SVG
2
2
class Properties
3
- Config = Struct . new ( :default , :inheritable? , :valid_values , :attr , :ivar )
3
+ Config = Struct . new ( :default , :inheritable? , :valid_values , :attr , :ivar , :id )
4
4
5
5
EM = 16
6
6
FONT_SIZES = {
@@ -49,6 +49,7 @@ class Properties
49
49
50
50
PROPERTIES . each do |name , value |
51
51
value . attr = name . gsub ( '-' , '_' )
52
+ value . id = value . attr . to_sym
52
53
value . ivar = "@#{ value . attr } "
53
54
end
54
55
@@ -57,9 +58,11 @@ class Properties
57
58
ATTR_NAMES = PROPERTIES . keys . map { |name | name . gsub ( '-' , '_' ) }
58
59
59
60
attr_accessor ( *ATTR_NAMES )
61
+ attr_reader :important_ids
60
62
61
63
def initialize
62
64
@numeric_font_size = EM
65
+ @important_ids = [ ]
63
66
end
64
67
65
68
def load_default_stylesheet
@@ -70,10 +73,11 @@ def load_default_stylesheet
70
73
self
71
74
end
72
75
73
- def set ( name , value )
76
+ def set ( name , value , important : false )
74
77
name = name . to_s . downcase
75
78
if ( config = PROPERTIES [ name ] )
76
- if ( value = parse_value ( config , value . strip ) )
79
+ if ( value = parse_value ( config , value . strip ) ) && ( important || !@important_ids . include? ( config . id ) )
80
+ @important_ids << config . id if important
77
81
instance_variable_set ( config . ivar , value )
78
82
end
79
83
elsif name == 'font'
@@ -99,14 +103,15 @@ def compute_properties(other)
99
103
PROPERTY_CONFIGS . each do |config |
100
104
value = other . send ( config . attr )
101
105
102
- if value && value != 'inherit'
106
+ if value && value != 'inherit' && ( ! @important_ids . include? ( config . id ) || other . important_ids . include? ( config . id ) )
103
107
instance_variable_set ( config . ivar , value )
104
108
105
109
elsif value . nil? && !config . inheritable?
106
110
instance_variable_set ( config . ivar , config . default )
107
111
end
108
112
end
109
113
114
+ @important_ids += other . important_ids
110
115
@numeric_font_size = calculate_numeric_font_size
111
116
nil
112
117
end
0 commit comments