简体   繁体   中英

How can I correctly write text on a path with Codename One

I want to write texts on paths with Codename One the text are street names and more in map. the whole project it's really big and It couldn't be attached. I write another example to show my problem. I draw a rectangle on graphics and I draw a text in it and before drawing i rotate the graphics. but when you give a little big theta for rotating the whole text and rectangle have distance(the text wasn't draw in rectangle). what is this problem?

Code:

public class MyApplication {

    private Form current;
    Form frm;

    public void init(Object context) {
        // Pro users - uncomment this code to get crash reports sent to you automatically
        /*Display.getInstance().addEdtErrorHandler(new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                evt.consume();
                Log.p("Exception in AppName version " + Display.getInstance().getProperty("AppVersion", "Unknown"));
                Log.p("OS " + Display.getInstance().getPlatformName());
                Log.p("Error " + evt.getSource());
                Log.p("Current Form " + Display.getInstance().getCurrent().getName());
                Log.e((Throwable)evt.getSource());
                Log.sendLog();
            }
        });*/
    }

    public void start() {
        if(current != null){
            current.setLayout(new BoxLayout(BoxLayout.Y_AXIS));
            current.show();
            return;
        }
        new StateMachine("/theme");
        createDraw();

    }

    public void stop() {
        current = Display.getInstance().getCurrent();
    }

    public void destroy() {
    }

    private void createDraw() {
        frm = new Form("Rect");
        frm.setLayout(new LayeredLayout());
        frm.setUIID("Form");
        Container cont = new Container(new FlowLayout(Component.RIGHT));
        cont.setUIID("Container");
        Label lbl = new Label();
        lbl.setPreferredSize(new Dimension(1280, 720));
        lbl.setUIID("Label");
        cont.setPreferredSize(new Dimension(1280, 720));
        cont.setShouldCalcPreferredSize(true);
        Image img = Image.createImage(1280, 720);
        Image img2 = Image.createImage(1280, 720);
        Graphics g = img.getGraphics();
        g.setColor(0xff0000);


        Font font =  Font.createSystemFont( Font.FACE_MONOSPACE, Font.SIZE_MEDIUM, Font.SIZE_LARGE);
        g.setFont(font);

        Transform transform = g.getTransform();
        g.rotate(1.5f, 100, 100);
        g.drawRect(100, 100, 200, 22);
        g.drawLine(100, 111, 300, 111);
        g.setColor(0x111111);
        g.drawString("HHHHHHHHHHHHHHHHHH", 100, 100);
        g.setTransform(transform);

        img2.getGraphics().drawImage(img, 0, 0);
        lbl.setIcon(img2);
        frm.addComponent(lbl);

        frm.show();
    }
}

If you rotate with 1.5

g.rotate(1.5f, 100, 100);

在此处输入图片说明

If you rotate with .3

g.rotate(.3f, 100, 100);

在此处输入图片说明

Thanks in advance.

Looking at your code I think you got some calculations wrong, eg just checking this in the simulator on the iPhone3gs skin this almost works:

iPhone 3GS图片

Then on the iPad skin it looks like this:

iPad模拟器

Both of these use the exact same underlying Codename One code.

You seem to be using two mutable images instead of overriding paint or using a painter which isn't good policy as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM