@@ -127,66 +127,6 @@ void serialize_unicode_ranges(StringBuilder& builder, Vector<Gfx::UnicodeRange>
127127 });
128128}
129129
130- namespace {
131-
132- char nth_digit (u32 value, u8 digit)
133- {
134- // This helper is used to format integers.
135- // nth_digit(745, 1) -> '5'
136- // nth_digit(745, 2) -> '4'
137- // nth_digit(745, 3) -> '7'
138-
139- VERIFY (value < 1000 );
140- VERIFY (digit <= 3 );
141- VERIFY (digit > 0 );
142-
143- while (digit > 1 ) {
144- value /= 10 ;
145- digit--;
146- }
147-
148- return ' 0' + value % 10 ;
149- }
150-
151- Array<char , 4 > format_to_8bit_compatible (u8 value)
152- {
153- // This function formats to the shortest string that roundtrips at 8 bits.
154- // As an example:
155- // 127 / 255 = 0.498 ± 0.001
156- // 128 / 255 = 0.502 ± 0.001
157- // But round(.5 * 255) == 128, so this function returns (note that it's only the fractional part):
158- // 127 -> "498"
159- // 128 -> "5"
160-
161- u32 const three_digits = (value * 1000u + 127 ) / 255 ;
162- u32 const rounded_to_two_digits = (three_digits + 5 ) / 10 * 10 ;
163-
164- if ((rounded_to_two_digits * 255 / 100 + 5 ) / 10 != value)
165- return { nth_digit (three_digits, 3 ), nth_digit (three_digits, 2 ), nth_digit (three_digits, 1 ), ' \0 ' };
166-
167- u32 const rounded_to_one_digit = (three_digits + 50 ) / 100 * 100 ;
168- if ((rounded_to_one_digit * 255 / 100 + 5 ) / 10 != value)
169- return { nth_digit (rounded_to_two_digits, 3 ), nth_digit (rounded_to_two_digits, 2 ), ' \0 ' , ' \0 ' };
170-
171- return { nth_digit (rounded_to_one_digit, 3 ), ' \0 ' , ' \0 ' , ' \0 ' };
172- }
173-
174- }
175-
176- // https://www.w3.org/TR/css-color-4/#serializing-sRGB-values
177- void serialize_a_srgb_value (StringBuilder& builder, Color color)
178- {
179- // The serialized form is derived from the computed value and thus, uses either the rgb() or rgba() form
180- // (depending on whether the alpha is exactly 1, or not), with lowercase letters for the function name.
181- // NOTE: Since we use Gfx::Color, having an "alpha of 1" means its value is 255.
182- if (color.alpha () == 0 )
183- builder.appendff (" rgba({}, {}, {}, 0)" , color.red (), color.green (), color.blue ());
184- else if (color.alpha () == 255 )
185- builder.appendff (" rgb({}, {}, {})" , color.red (), color.green (), color.blue ());
186- else
187- builder.appendff (" rgba({}, {}, {}, 0.{})" , color.red (), color.green (), color.blue (), format_to_8bit_compatible (color.alpha ()).data ());
188- }
189-
190130// https://drafts.csswg.org/cssom/#serialize-a-css-value
191131void serialize_a_number (StringBuilder& builder, double value)
192132{
@@ -218,13 +158,6 @@ String serialize_a_url(StringView url)
218158 return builder.to_string_without_validation ();
219159}
220160
221- String serialize_a_srgb_value (Color color)
222- {
223- StringBuilder builder;
224- serialize_a_srgb_value (builder, color);
225- return builder.to_string_without_validation ();
226- }
227-
228161String serialize_a_number (double value)
229162{
230163 StringBuilder builder;
0 commit comments