×

Discussion Board

Results 1 to 2 of 2
  1. #1
    Registered User
    Join Date
    Mar 2009
    Posts
    5

    SVGImage and viewPort: image is not displayed in phon (fine in emulator)

    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:
    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>
    And the CustomItem:
    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();
        }
    
    }
    If you need to see more code, I will give you a link to the git-repository.

  2. #2
    Registered User
    Join Date
    Mar 2009
    Posts
    5

    Re: SVGImage and viewPort: image is not displayed in phon (fine in emulator)

    I found the problem (see commented out line). But I don't know why it happens. Any ideas?

    Code:
    private void updateTime() {
            this.slavicTime = SlavicDateUtil.convert(new Date());
    
            timeItem.setLabel(slavicTime.getHourName());
            timeItem.setText(slavicTime.getHours() + " : " + slavicTime.getParts());
    
            clockFace.update(slavicTime, true);
        }
    
        private void init() {
            ...
            clockFace = new ClockFace(null, clockFaceInputStream, null);
            clockFace.setLayout(Item.LAYOUT_NEWLINE_AFTER);
            clockFace.setPreferredSize(mainForm.getWidth(), mainForm.getWidth());
            mainForm.append(clockFace);
    
            // No blank (with white background) image if this is commented
            // updateTime();
            resumeTimer();
        }
    
        private void resumeTimer() {
            timer = new Timer();
            timer.schedule(new TimerTask() {
                public void run() {
                    System.out.println("Update time!");
                    updateTime();
                }
            }, 0L, 1000L);
        }
    
    ...
    ClockFace.java:
    
        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();
        }

Similar Threads

  1. SVG API / Scalable User Interface - Bug in Emulator
    By thunder7553 in forum Tools and SDK Feedback (Closed)
    Replies: 0
    Last Post: 2006-03-14, 08:58

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×