Issue about JAVA function drawString()

Hi,
I’m trying to implement some low level functions to realise my JAVA APP on my hareware platform. As the photo showed below, I want to put a string on my screen with calling the JAVA API drawString(), but the string didn’t appear after my fireware ran, could you tell me what the matched C code function is to show the string?

Thank you!

Hi @MJ163,

The draw string will be done on the MicroUI stack, could you check that you can draw where you are trying to draw?

  • Check the Graphic context clip
  • try to draw a fill rect of the full screen to make sure you can draw where you want
  • Try to draw your string at 0, 0

Regards,

Hi @pierre.rivron,

Thank you for your advices, I success to draw a fill rectangle on my screen, but fail to draw a string at (0, 0). What’s the matter? In addition, how to check the graphic context clip?

Regards,

Hi @MJ163,

Is your string drawn on the simulator?

You can check the clip with g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight()

Regards,

Hi @pierre.rivron,

It was correctly showed on the SDK simulator, but wrong on my board.

I checked the 4 java functions you mentioned above, return value in turn is 0, 0, 480 and 272. And what’s the relationship between drawing string and clipping zone?

Regards,

Hi @MJ163,

  • Does this.messages contains only not empty Strings?
  • Which UI pack version are you using?

The clipping zone will forbid drawing outside of it.

Regards,

Hi @pierre.rivron,

  • My string is “Hello”.
  • My UI pack version is MICROUI-2.0.

Additionally, my board is not your recommended, the lcd’s resolution on my board is 1024*600, and the value of g.getClipWidth() and g.getClipHeight() is in turn 1024 and 600.

Regards,

You provided me the MicroUI API version, you can get the UI pack vresion from MicroEJ SDK:

  • Window
  • Preferences
  • MicroEJ
  • Architectures
  • Unfold the architecture you are using for your platform
  • You will see the packs and their versions.

Could you send your java code to support@microej.com ?

Regards,

Hi @pierre.rivron,

My UI pack vresion is 7.2.1.

My java code is sample and showd below:
/*

  • Java
  • Copyright 2016 IS2T. All rights reserved.
  • For demonstration purpose only.
  • IS2T PROPRIETARY. Use is subject to license terms.
    */
    package com.microej.example.hello;

import java.io.IOException;

import ej.microui.MicroUI;
import ej.microui.display.Colors;
import ej.microui.display.Display;
import ej.microui.display.Displayable;
import ej.microui.display.Font;
import ej.microui.display.GraphicsContext;
import ej.microui.display.Image;
import ej.microui.util.EventHandler;

/**

  • Prints the message “Hello World !” an displays MicroEJ splash
    */
    public class HelloWorld extends Displayable implements EventHandler{

    private static final int PADDING_TEXT = 5;
    private static final int PADDING_BETWEEN_IMAGE_AND_TEXT = 30;

    private final String[] messages;

    private Image microejImage;

    public static void main(String[] args) {
    MicroUI.start();
    new HelloWorld().show();
    }

    public HelloWorld() {
    super(Display.getDefaultDisplay());
    messages = new String[] { “Hello” };
    try {
    microejImage = Image.createImage("/images/mej.png");
    }
    catch (IOException e) {
    throw new AssertionError(e);
    }
    }

    @Override
    public void paint(GraphicsContext g) {
    // clean
    g.setColor(Colors.YELLOW);
    int width = getDisplay().getWidth();
    int height = getDisplay().getHeight();
    g.fillRect(0, 0, width, height);

     // compute vertical center
     int y = height / 2;
     int microejImageHeight = microejImage.getHeight();
     y -= (microejImageHeight + PADDING_BETWEEN_IMAGE_AND_TEXT) / 2;
     Font font = Font.getFont(Font.LATIN, 36, Font.STYLE_PLAIN);
     g.setFont(font);
     y -= (messages.length * font.getHeight() + PADDING_TEXT) / 2;
     // draw MicroEJ image
     g.drawImage(microejImage, width / 2, y, GraphicsContext.HCENTER | GraphicsContext.TOP);
     y += microejImageHeight + PADDING_BETWEEN_IMAGE_AND_TEXT;
     // draw each message
    
     g.setColor(Colors.NAVY);
     for (String message : this.messages) {
     	g.drawString(message, width / 2, y, GraphicsContext.HCENTER | GraphicsContext.VCENTER);
     	y += font.getHeight() + PADDING_TEXT;
     }
    

    }

    @Override
    public EventHandler getController() {
    return this;
    }

    @Override
    public boolean handleEvent(int event) {
    return false;
    }
    }

Regards,

Hi @MJ163,

Ok, your Java code is correct.

Could you send your platform to support@microej.com ?

In the meantime, you can try out this code, you should see red rectangle where the text is supposed to be:

	    for (String message : this.messages) {
			g.setColor(0xFF0000);
			int fontHeight = font.getHeight();
			int stringWidth = font.stringWidth(message);
			int x = width / 2 - stringWidth / 2;
			g.fillRect(x, y, stringWidth, fontHeight);
			g.setColor(Colors.NAVY);
			g.drawString(message, x, y, GraphicsContext.TOP | GraphicsContext.LEFT);
			y += fontHeight + PADDING_TEXT;
		}

Hi @pierre.rivron,

Yes, a red rectangle is shown at the location of the string, but no string appears.

I have no permission to send mails to the external mail address.

Thank you for your support sincerely!

Regards,

Hello

Have you linked the font(s) with the MicroEJ application or not ? In another words, do you have implemented the external resources (LLEXT_impl.h) and do you have put the font (*.ejf_raw) file(s) in this external memory ?

If yes, is it possible to link the font(s) with the application and retry your test ? I would like to exclude the “external resources” use case.

Regards,

Hi @MJ163,

I may have another idea, could you send your .ejf file(s) and fonts.list file(s)?
Or could you check that you embed the right characters, if not we would print the first character embedded, if it is an empty character you would end up with your bug.

Regards,

Hi @pierre.rivron,

The content of my fonts.list is “/fonts/english_light.ejf::4”.
My .ejf file is the same as one in your demo example “Hello World”.

And how to check the charcters I embed?

Regards,

Hi @guillaume.balan,

  • There is no LLEXT_impl.h in my C code project .

  • What do you mean of external memory?

Regards,

Ok so it is not an external resource issue.

An external resource is a resource which is not linked with the MicroEJ application. This kind of resources is often located in a SDCard. The LLAPI LLExt_impl.h allows to the MicroEJ application to access them; without explicitly use a file system in the application.

The idea is to be sure about the font used to render the string. Before calling gc.drawString(), you have to set a font calling gc.setFont(). If not set, the default font is used. You can check the font characteristics calling gc.getFont().getDescriptor() just before gc.drawString()