Custom svg images in GWT ClientBundle (ImageBundle)

I usually use GWT ClientBundle to manage my images in my application like

@Source("icons/info.png")
ImageResource info();

      

Not. I want to switch to .svg graphics, but I haven't found a way to use svg in ClientBundle like SVGResource or something. I know svg is supported in GWT and there are possibilities to insert these graphs inside GWT, but I would like to take advantage of ClientBundle + advantages of svg. Has anyone already solved this problem?

+3


source to share


2 answers


ImageResource

is for bitmaps that the GWT compiler could have optimized in one way or another, and you can ask for their size.

For vector images like SVG, you can simply use DataResource

with annotation @MimeType("image/svg+xml")

.

@Source("icons/info.svg")
@MimeType("image/svg+xml")
DataResource info();

      



Note that you cannot use @sprite

in CssResource

, but you can get the URL of the resource, for example background-image

using @url

.
You also cannot pass the resource to the widget Image

, but then you can just pass it getSafeUri()

.


If you want to use SVG content instead of using it as an image url, you can use TextResource

. You need to pass it as an setInnerHTML

element or setHTML

widget for it to be parsed by the browser.

+12


source


There is LIB-GWT-SVG . It supports the latest GWT (2.7.0) and seems to be mature.

They have implemented SVG integration with UIBinder and added SVGResource which you can link just like ImageResource



@Source(...)
SVGResource bundledResource;

      

+3


source







All Articles