You Are Here:

Community: Developer Discussion Boards

#1 Old SVGImage and viewPort: image is not displayed in phon (fine in emulator) - 2009-03-08, 11:24

Join Date: Mar 2009
Posts: 5
thehappycoder
Offline
Registered User
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.
Reply With Quote

#2 Old Re: SVGImage and viewPort: image is not displayed in phon (fine in emulator) - 2009-03-08, 14:45

Join Date: Mar 2009
Posts: 5
thehappycoder
Offline
Registered User
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();
    }
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules

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

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
[Java ME] SVGImage и viewPort: не отображается svg на телефоне (в эмуляторе ОК) thehappycoder Russian Developer Forum - Форум Российских разработчиков 1 2009-03-08 14:47
SVG API / Scalable User Interface - Bug in Emulator thunder7553 Tools and SDK Feedback 0 2006-03-14 09:58

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomhttpE3aE2fE2fdiscussionE2eforumE2enokiaE2ecomE2fforumE2fshowthreadE2ephpE3ftE3d18645X qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE44iscussionQ qdcZtypeQUqfntypeZE44iscussionContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZentertainmentQ qfnZtopicQUqfnTopicZj2meQ qfnZtopicQUqfnTopicZjavaQ qfnZtopicQUqfnTopicZmediaQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE44iscussionQ qfnZtypeQUqfntypeZE44iscussionContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE44iscussionQ qrdfZtypeQUqfntypeZE44iscussionContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ