I am trying to display a svg image scaled to the width of the display. It is displayed fine in emulator but not in the phone (nokia 5800) -- I see just a white box. If I remove a 'viewBox' attribute, the image gets displayed but not scaled to the width.
Image:
And the CustomItem:Code:<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG Tiny 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11-tiny-flat.dtd"> <svg xmlns:svg="http://www.w3.org/2000/svg" xmlns="http://www.w3.org/2000/svg" version="1.1" baseProfile="tiny" width="200" height="200" viewBox="0 0 200 200"> <g stroke="#EEDA72" stroke-width="2" transform="translate(100 100)" > <circle id="outerCircle" r="95" fill="#E59816" stroke-width="3" /> <circle id="innerCircle" r="80" fill="#FFFCA0" /> <line id="hourHand" x1="0" y1="0" x2="0" y2="0" stroke="black" /> <line id="partsHand" x1="0" y1="0" x2="0" y2="0" stroke="black" /> </g> </svg>
If you need to see more code, I will give you a link to the git-repository.Code:package org.slavicariansoft.mobile.ui; import java.io.IOException; import java.io.InputStream; import javax.microedition.lcdui.Canvas; import javax.microedition.lcdui.CustomItem; import javax.microedition.lcdui.Graphics; import javax.microedition.m2g.ExternalResourceHandler; import javax.microedition.m2g.SVGAnimator; import javax.microedition.m2g.SVGImage; import javax.microedition.m2g.ScalableGraphics; /** * @author Anton Kuzmin */ public class SVGImageItem extends CustomItem { private ScalableGraphics scalableGraphics; private SVGImage image; private SVGAnimator animator; private Canvas canvas; public SVGImageItem(String label, InputStream inputStream, ExternalResourceHandler externalResHandler) { super(label); try { this.scalableGraphics = ScalableGraphics.createInstance(); this.image = (SVGImage) SVGImage.createImage(inputStream, externalResHandler); this.animator = SVGAnimator.createAnimator(image); this.animator.setTimeIncrement(0.01F); this.animator.play(); this.canvas = (Canvas) animator.getTargetComponent(); } catch (IOException e) { throw new RuntimeException("Caused by " + e.getClass() + ": " + e.getMessage() + "\n" + "microedition.m2g.version:" + System.getProperty("microedition.m2g.version") + "\n" + "microedition.m2g.svg.baseProfile:" + System.getProperty("microedition.m2g.svg.baseProfile") + "\n" + "microedition.m2g.svg.version:" + System.getProperty("microedition.m2g.svg.version")); } } public SVGAnimator getAnimator() { return animator; } public void updateAnimation(Runnable runnable, boolean invokedNow) { try { if (invokedNow) { animator.invokeAndWait(runnable); } else { animator.invokeLater(runnable); } } catch (InterruptedException ex) { ex.printStackTrace(); // XXX find out what to do; // throw new RuntimeException("Interrupted!"); } repaint(); } public SVGImage getImage() { return image; } protected int getMinContentWidth() { return 0; } protected int getMinContentHeight() { return 0; } protected int getPrefContentWidth(int height) { return height; } protected int getPrefContentHeight(int width) { return width; } protected void paint(Graphics g, int w, int h) { this.scalableGraphics.bindTarget(g); this.image.setViewportHeight(h); this.image.setViewportWidth(w); this.scalableGraphics.render(0, 0, this.image); this.scalableGraphics.releaseTarget(); } }

Reply With Quote

