summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 4c0c5f0)
raw | patch | inline | side by side (parent: 4c0c5f0)
author | pjrm <pjrm@users.sourceforge.net> | |
Mon, 13 Mar 2006 02:56:37 +0000 (02:56 +0000) | ||
committer | pjrm <pjrm@users.sourceforge.net> | |
Mon, 13 Mar 2006 02:56:37 +0000 (02:56 +0000) |
(sp_svg_write_color): Require buflen >= 8. (All existing callers already conform.)
doc: Remove out-of-date (and incorrect: cannot have space in `rgb(' for CSS colors) todo comment.
noop: SP_SVG_NUMCOLORS is used in only one place; replace it with inline G_N_ELEMENTS(...).
doc: Remove out-of-date (and incorrect: cannot have space in `rgb(' for CSS colors) todo comment.
noop: SP_SVG_NUMCOLORS is used in only one place; replace it with inline G_N_ELEMENTS(...).
src/svg/svg-color.cpp | patch | blob | history |
diff --git a/src/svg/svg-color.cpp b/src/svg/svg-color.cpp
index 5a7602e4ffee8e5d6fc1ec1dff3c0ecaa32d69f4..613d97c0b4e46cda317bcb2d0ac44919ce42dc40 100644 (file)
--- a/src/svg/svg-color.cpp
+++ b/src/svg/svg-color.cpp
#endif
#include <math.h>
+#include <glib/gmessages.h>
#include <glib/gstrfuncs.h>
#include <glib/ghash.h>
#include <glib/gutils.h>
{ 0x9ACD32, "yellowgreen" }
};
-#define SP_SVG_NUMCOLORS (sizeof(sp_svg_color_named) / sizeof(sp_svg_color_named[0]))
-
static GHashTable *sp_svg_create_color_hash();
guint32
gchar c[32];
guint32 val = 0;
- /*
- * todo: handle the rgb (r, g, b) and rgb ( r%, g%, b%), syntax
- * defined in http://www.w3.org/TR/REC-CSS2/syndata.html#color-units
- */
-
if (str == NULL) return def;
while ((*str <= ' ') && *str) str++;
if (!*str) return def;
return (val << 8);
}
+/**
+ * \pre buflen \>= 8.
+ */
gint
-sp_svg_write_color(gchar *buf, gint buflen, guint32 color)
+sp_svg_write_color(gchar *buf, unsigned const buflen, guint32 const color)
{
+ g_assert(8 <= buflen);
return g_snprintf(buf, buflen, "#%06x", color >> 8);
}
{
GHashTable *colors = g_hash_table_new(g_str_hash, g_str_equal);
- for (unsigned i = 0 ; i < SP_SVG_NUMCOLORS ; i++) {
+ for (unsigned i = 0 ; i < G_N_ELEMENTS(sp_svg_color_named) ; i++) {
g_hash_table_insert(colors,
(gpointer)(sp_svg_color_named[i].name),
(gpointer)(&sp_svg_color_named[i].rgb));