Merge branch 'hex-color-parse' into 'master'

Hex color parse

Closes #2931

See merge request GNOME/gtk!2356
This commit is contained in:
Matthias Clasen 2020-08-05 11:46:55 +00:00
commit 8870ec5e7b
4 changed files with 21 additions and 7 deletions

View File

@ -72,6 +72,7 @@ fedora-x86_64:
variables: variables:
EXTRA_MESON_FLAGS: "--buildtype=debug --default-library=both" EXTRA_MESON_FLAGS: "--buildtype=debug --default-library=both"
script: script:
- meson subprojects update
- meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS} - meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS}
-Dprofiler=true -Dprofiler=true
_build _build
@ -87,6 +88,7 @@ release-build:
variables: variables:
EXTRA_MESON_FLAGS: "--buildtype=release" EXTRA_MESON_FLAGS: "--buildtype=release"
script: script:
- meson subprojects update
- meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS} - meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS}
_build _build
- ninja -C _build - ninja -C _build
@ -99,6 +101,7 @@ installed-tests:
variables: variables:
EXTRA_MESON_FLAGS: "--prefix=/usr --libdir=/usr/lib64 -Dinstall-tests=true" EXTRA_MESON_FLAGS: "--prefix=/usr --libdir=/usr/lib64 -Dinstall-tests=true"
script: script:
- meson subprojects update
- meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS} - meson ${COMMON_MESON_FLAGS} ${EXTRA_MESON_FLAGS} ${BACKEND_FLAGS} ${FEATURE_FLAGS}
_build _build
- ninja -C _build - ninja -C _build

View File

@ -170,19 +170,21 @@ parse_rgb_value (const char *str,
* - A standard name (Taken from the X11 rgb.txt file). * - A standard name (Taken from the X11 rgb.txt file).
* - A hexadecimal value in the form \#rgb, \#rrggbb, * - A hexadecimal value in the form \#rgb, \#rrggbb,
* \#rrrgggbbb or \#rrrrggggbbbb * \#rrrgggbbb or \#rrrrggggbbbb
* - A hexadecimal value in the form \#rgba, \#rrggbbaa,
* or \#rrrrggggbbbbaaaa
* - A RGB color in the form rgb(r,g,b) (In this case the color will * - A RGB color in the form rgb(r,g,b) (In this case the color will
* have full opacity) * have full opacity)
* - A RGBA color in the form rgba(r,g,b,a) * - A RGBA color in the form rgba(r,g,b,a)
* *
* Where r, g, b and a are respectively the red, green, blue and * Where r, g, b and a are respectively the red, green, blue and
* alpha color values. In the last two cases, r, g, and b are either integers * alpha color values. In the last two cases, r, g, and b are either
* in the range 0 to 255 or percentage values in the range 0% to 100%, and * integers in the range 0 to 255 or percentage values in the range 0% to
* a is a floating point value in the range 0 to 1. * 100%, and a is a floating point value in the range 0 to 1.
* *
* Returns: %TRUE if the parsing succeeded * Returns: %TRUE if the parsing succeeded
*/ */
gboolean gboolean
gdk_rgba_parse (GdkRGBA *rgba, gdk_rgba_parse (GdkRGBA *rgba,
const char *spec) const char *spec)
{ {
gboolean has_alpha; gboolean has_alpha;
@ -207,18 +209,19 @@ gdk_rgba_parse (GdkRGBA *rgba,
else else
{ {
PangoColor pango_color; PangoColor pango_color;
guint16 alpha;
/* Resort on PangoColor for rgb.txt color /* Resort on PangoColor for rgb.txt color
* map and '#' prefixed colors * map and '#' prefixed colors
*/ */
if (pango_color_parse (&pango_color, str)) if (pango_color_parse_with_alpha (&pango_color, &alpha, str))
{ {
if (rgba) if (rgba)
{ {
rgba->red = pango_color.red / 65535.; rgba->red = pango_color.red / 65535.;
rgba->green = pango_color.green / 65535.; rgba->green = pango_color.green / 65535.;
rgba->blue = pango_color.blue / 65535.; rgba->blue = pango_color.blue / 65535.;
rgba->alpha = 1; rgba->alpha = alpha / 65535.;
} }
return TRUE; return TRUE;

View File

@ -27,7 +27,7 @@ else
endif endif
glib_req = '>= @0@.@1@.@2@'.format(glib_major_req, glib_minor_req, glib_micro_req) glib_req = '>= @0@.@1@.@2@'.format(glib_major_req, glib_minor_req, glib_micro_req)
pango_req = '>= 1.45.0' pango_req = '>= 1.45.5'
fribidi_req = '>= 0.19.7' fribidi_req = '>= 0.19.7'
cairo_req = '>= 1.14.0' cairo_req = '>= 1.14.0'
gdk_pixbuf_req = '>= 2.30.0' gdk_pixbuf_req = '>= 2.30.0'

View File

@ -57,6 +57,14 @@ test_color_parse (void)
res = gdk_rgba_parse (&color, "rgb(0,0,0)"); res = gdk_rgba_parse (&color, "rgb(0,0,0)");
g_assert (res); g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected)); g_assert (gdk_rgba_equal (&color, &expected));
expected.red = 0.0;
expected.green = 0x8080 / 65535.;
expected.blue = 1.0;
expected.alpha = 0x8888 / 65535.;
res = gdk_rgba_parse (&color, "#0080ff88");
g_assert (res);
g_assert (gdk_rgba_equal (&color, &expected));
} }
static void static void