mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-30 01:54:21 +01:00
[vector] Emit shorthand hex colors when possible
This commit is contained in:
1 parent
236d080d9f
commit
a8e59bc6fb
2 files changed
+30
-6
No files matched your search
@@ -268,14 +268,26 @@ hb_svg_append_color (hb_vector_t<char> *buf,
|
||||
hb_color_t color,
|
||||
bool with_alpha)
|
||||
{
|
||||
static const char hex[] = "0123456789ABCDEF";
|
||||
unsigned r = hb_color_get_red (color);
|
||||
unsigned g = hb_color_get_green (color);
|
||||
unsigned b = hb_color_get_blue (color);
|
||||
unsigned a = hb_color_get_alpha (color);
|
||||
hb_svg_append_c (buf, '#');
|
||||
hb_svg_append_hex_byte (buf, r);
|
||||
hb_svg_append_hex_byte (buf, g);
|
||||
hb_svg_append_hex_byte (buf, b);
|
||||
if (((r >> 4) == (r & 0xF)) &&
|
||||
((g >> 4) == (g & 0xF)) &&
|
||||
((b >> 4) == (b & 0xF)))
|
||||
{
|
||||
hb_svg_append_c (buf, hex[r & 0xF]);
|
||||
hb_svg_append_c (buf, hex[g & 0xF]);
|
||||
hb_svg_append_c (buf, hex[b & 0xF]);
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_svg_append_hex_byte (buf, r);
|
||||
hb_svg_append_hex_byte (buf, g);
|
||||
hb_svg_append_hex_byte (buf, b);
|
||||
}
|
||||
if (with_alpha && a != 255)
|
||||
{
|
||||
hb_svg_append_str (buf, "\" fill-opacity=\"");
|
||||
|
||||
@@ -254,14 +254,26 @@ hb_svg_append_color (hb_vector_t<char> *buf,
|
||||
hb_color_t color,
|
||||
bool with_alpha)
|
||||
{
|
||||
static const char hex[] = "0123456789ABCDEF";
|
||||
unsigned r = hb_color_get_red (color);
|
||||
unsigned g = hb_color_get_green (color);
|
||||
unsigned b = hb_color_get_blue (color);
|
||||
unsigned a = hb_color_get_alpha (color);
|
||||
hb_svg_append_c (buf, '#');
|
||||
hb_svg_append_hex_byte (buf, r);
|
||||
hb_svg_append_hex_byte (buf, g);
|
||||
hb_svg_append_hex_byte (buf, b);
|
||||
if (((r >> 4) == (r & 0xF)) &&
|
||||
((g >> 4) == (g & 0xF)) &&
|
||||
((b >> 4) == (b & 0xF)))
|
||||
{
|
||||
hb_svg_append_c (buf, hex[r & 0xF]);
|
||||
hb_svg_append_c (buf, hex[g & 0xF]);
|
||||
hb_svg_append_c (buf, hex[b & 0xF]);
|
||||
}
|
||||
else
|
||||
{
|
||||
hb_svg_append_hex_byte (buf, r);
|
||||
hb_svg_append_hex_byte (buf, g);
|
||||
hb_svg_append_hex_byte (buf, b);
|
||||
}
|
||||
if (with_alpha && a != 255)
|
||||
{
|
||||
hb_svg_append_str (buf, "\" fill-opacity=\"");
|
||||
|
||||
Reference in new issue
Block a user