summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-10-20 18:11:46 +0200
committerBenjamin Otte <otte@redhat.com>2015-10-22 13:09:10 +0200
commit775178c2d7480895ce1b2bb86477a45e48bd22e4 (patch)
treef00b36f589bbde0800b9909bc266f445bb3a5a96
parent25f271d2e1e5916d0c3f73d20a366873f64fbbc4 (diff)
downloadlibrsvg-775178c2d7480895ce1b2bb86477a45e48bd22e4.tar.gz
defs: Do the right thing for duplicate ids
When an id (illegally) exists twice in an SVG file, all renderers keep the definition that appears first. Do the same in rsvg.
-rw-r--r--rsvg-defs.c3
-rw-r--r--tests/fixtures/reftests/duplicate-id-ref.pngbin0 -> 155 bytes
-rw-r--r--tests/fixtures/reftests/duplicate-id.svg7
3 files changed, 10 insertions, 0 deletions
diff --git a/rsvg-defs.c b/rsvg-defs.c
index 280f87f1..d2c6a06f 100644
--- a/rsvg-defs.c
+++ b/rsvg-defs.c
@@ -135,6 +135,9 @@ rsvg_defs_set (RsvgDefs * defs, const char *name, RsvgNode * val)
void
rsvg_defs_register_name (RsvgDefs * defs, const char *name, RsvgNode * val)
{
+ if (g_hash_table_lookup (defs->hash, name))
+ return;
+
g_hash_table_insert (defs->hash, g_strdup (name), val);
}
diff --git a/tests/fixtures/reftests/duplicate-id-ref.png b/tests/fixtures/reftests/duplicate-id-ref.png
new file mode 100644
index 00000000..162a6587
--- /dev/null
+++ b/tests/fixtures/reftests/duplicate-id-ref.png
Binary files differ
diff --git a/tests/fixtures/reftests/duplicate-id.svg b/tests/fixtures/reftests/duplicate-id.svg
new file mode 100644
index 00000000..c05f3413
--- /dev/null
+++ b/tests/fixtures/reftests/duplicate-id.svg
@@ -0,0 +1,7 @@
+<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="10" height="10">
+ <defs>
+ <rect fill="chartreuse" id="a" width="10" height="10" />
+ <rect fill="tomato" id="a" width="10" height="10" />
+ </defs>
+ <use xlink:href="#a"/>
+</svg>