From: pjrm Date: Mon, 13 Mar 2006 06:51:37 +0000 (+0000) Subject: (sp_style_write_ipaint): Pretty colour names: use sp_svg_write_color instead of ... X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=847b48e9671acccb61e9ecb6833164ae5ce31380;p=inkscape.git (sp_style_write_ipaint): Pretty colour names: use sp_svg_write_color instead of #rrggbb. style-test.cpp: Update unit tests accordingly. --- diff --git a/src/style-test.cpp b/src/style-test.cpp index 86382b174..54be0040e 100644 --- a/src/style-test.cpp +++ b/src/style-test.cpp @@ -249,7 +249,7 @@ static void color_val(char const prop[], char const *const dummy_vals[]) { assert(dummy_vals == NULL); - char const *const extra_vals[] = {"#0000ff", NULL}; + char const *const extra_vals[] = {"blue", "#234", "#0100ff", NULL}; enum_val(prop, extra_vals); #if 0 char const *color_vals[G_N_ELEMENTS(color_keywords) + G_N_ELEMENTS(extra_vals)]; @@ -540,10 +540,10 @@ test_style() char const *const *tst_fn_arg; bool can_explicitly_inherit; } const props[] = { - {"color", "#000000", "#000000", color_val, NULL, true}, + {"color", "black", "black", color_val, NULL, true}, // initial value "depends on user agent" {"display", "inline", "inline", enum_val, display_vals, true}, - {"fill", "#000000", "black", paint_val, NULL, true}, + {"fill", "black", "black", paint_val, NULL, true}, {"fill-opacity", "1", "1", opacity_val, NULL, true}, {"fill-rule", "nonzero", "nonzero", enum_val, fill_rule_vals, true}, {"font-family", "Bitstream Vera Sans", "Bitstream Vera Sans", font_family_val, NULL, true}, @@ -595,8 +595,8 @@ test_style() "writing-mode:lr-tb;" "text-anchor:start;" "opacity:1;" - "color:#000000;" - "fill:#000000;" + "color:black;" + "fill:black;" "fill-opacity:1;" "fill-rule:nonzero;" "stroke:none;" @@ -687,7 +687,7 @@ test_style() bad[i], bad[i]); UTEST_TEST(tst_name) { gchar *str0_set = merge_then_write_string(style_str, SP_STYLE_FLAG_IFSET); - UTEST_ASSERT(streq(str0_set, "color:#112233")); + UTEST_ASSERT(streq(str0_set, "color:#123")); g_free(str0_set); } g_free(style_str); diff --git a/src/style.cpp b/src/style.cpp index 3baa1678b..3ed6f335f 100644 --- a/src/style.cpp +++ b/src/style.cpp @@ -3325,12 +3325,13 @@ sp_style_write_ipaint(gchar *b, gint const len, gchar const *const key, return g_snprintf(b, len, "%s:currentColor;", key); } else { switch (paint->type) { - case SP_PAINT_TYPE_COLOR: - return g_snprintf(b, len, "%s:#%06x;", key, sp_color_get_rgba32_falpha(&paint->value.color, 0.0) >> 8); - break; + case SP_PAINT_TYPE_COLOR: { + char color_buf[8]; + sp_svg_write_color(color_buf, sizeof(color_buf), sp_color_get_rgba32_ualpha(&paint->value.color, 0)); + return g_snprintf(b, len, "%s:%s;", key, color_buf); + } case SP_PAINT_TYPE_PAINTSERVER: return g_snprintf(b, len, "%s:url(%s);", key, paint->value.paint.uri); - break; default: break; }