DEFS element unique names

A discussion forum for JFreeSVG (a fast, lightweight, SVG generator for the Java platform).

DEFS element unique names

Postby DavidThi808 » Sun Aug 14, 2016 3:03 pm

The documentation says:
when an HTML page contains multiple SVG elements, the items within the DEFS element for each SVG element must have IDs that are unique across all SVG elements in the page. We auto-populate the defsKeyPrefix attribute to help ensure that unique IDs are generated.


Is the best (or ok) way to handle this to call setDefsKeyPrefix() with a different string for every SVGGraphics2D we create?

thanks - dave
DavidThi808
 
Posts: 106
Joined: Fri May 27, 2005 7:44 pm
Location: Boulder, CO

Re: DEFS element unique names

Postby david.gilbert » Tue Aug 16, 2016 10:39 pm

If you do nothing, the prefix will be unique because it is initialised with:

Code: Select all
this.defsKeyPrefix = String.valueOf(System.nanoTime());


However, this generates a fairly long prefix...if you can manually set shorter prefixes but still guarantee the uniqueness of the keys then you'll save some space in the generated SVG.
David Gilbert
JFreeChart Project Leader

:idea: Read my blog
:idea: Ask your company to buy the JFreeChart Developer Guide
:idea: Check out other products sold by my company Object Refinery Limited
david.gilbert
JFreeChart Project Leader
 
Posts: 11595
Joined: Fri Mar 14, 2003 10:29 am


Return to JFreeSVG

Who is online

Users browsing this forum: No registered users and 1 guest