Cast rgb() formatted css colors to hex for DOCX [SCI-7796]

This commit is contained in:
Martin Artnik 2023-01-19 15:50:59 +01:00
parent 58be66a06c
commit 0304daef7d

View file

@ -202,8 +202,8 @@ module Reports
if key == 'text-align'
result[:align] = value.to_sym
elsif key == 'color' && Reports::Utils.calculate_color_hsp(value) < 190
result[:color] = value.delete('#')
elsif key == 'color' && Reports::Utils.calculate_color_hsp("##{normalized_hex_color(value)}") < 190
result[:color] = normalized_hex_color(value)
elsif key == 'text-decoration' && value == 'underline'
result[:underline] = true
end
@ -269,5 +269,11 @@ module Reports
def text_formatting_element(element)
{ type: element.name, value: element.text }
end
def normalized_hex_color(color)
return color.delete('#') if color.start_with?('#')
color.scan(/\d+/).map(&:to_i).map { |c| c.to_s(16).rjust(2, '0').upcase }.join
end
end
end