×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Problem representing 'carriage return' when a class inherits from Canvas

    Hi all,

    Well, maybe my doubt could not sounds so serious... but the point is that I don't have problems when using, for example, a Form. I mean, if I create a String like:

    public class FormText extends Form {

    [...]
    StringItem text = new StringItem(null,"text part 1" + '\n' + "text part 2" + '\n' + "text part 3");
    append text;
    [...]

    }

    i have no problems, and return is represented correctly. But if I use Canvas instead, it doesn't work:

    public class CanvasText extends Canvas{

    [...]
    String text = "text part 1" + '\n' + "text part 2" + '\n' + "text part 3";
    [...]
    protected void paint(Graphics g){
    g.setFont(Font.getFont(Font.FACE_PROPORTIONAL,Font.STYLE_BOLD,Font.SIZE_MEDIUM));
    g.drawString(text,x,y,Graphics.TOP|Graphics.LEFT);
    }
    }

    I would be grateful if any of you could let me know how to represent 'carriage return' when using a String attribute in a Canvas class like this one.
    Regards.

  2. #2
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Re: Problem representing 'carriage return' when a class inherits from Canvas

    Ok, I've realized that my question doesn't make any sense... is not a matter of writing characters, but 'painting'.
    Anyway, I have already implemented an equivalent solution to this problem by myself...
    Regards!

  3. #3
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: Problem representing 'carriage return' when a class inherits from Canvas

    Welcome to Forum Nokia!

    Yes, I'm afraid Graphics.drawString() does not necessarily process characters like \n and \r correctly. If you want text on multiple lines, you need to paint each line separately. Remember that different devices have different screen and font sizes, so a word-wrapping method might be useful...

    Graham.

  4. #4
    Registered User
    Join Date
    Apr 2011
    Posts
    3

    Re: Problem representing 'carriage return' when a class inherits from Canvas

    Hello again!

    Yes, that's what I did... I've implemented a method to paint each line separately, looking after the font width to decide how many words to paint each line.

    Thank you for your answer, Graham.
    Regards.

Similar Threads

  1. Carriage return
    By sharan182 in forum Symbian
    Replies: 3
    Last Post: 2008-04-11, 14:02
  2. Carriage Return character
    By nile_mail in forum Symbian
    Replies: 0
    Last Post: 2006-12-27, 09:23
  3. Carriage return in file writing
    By bernie31 in forum Symbian
    Replies: 1
    Last Post: 2006-02-13, 12:49
  4. Regarding carriage return
    By devesh_symbian in forum Symbian
    Replies: 3
    Last Post: 2005-12-01, 12:01
  5. How to make a carriage return?
    By chrishawaii in forum Symbian
    Replies: 4
    Last Post: 2005-06-01, 09:25

Posting Permissions

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