×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    59

    Using a custom font questions

    I want to use a custom font in my J2ME applications, i want to change text size and color. Any suggestions on how i can do that ? I've tried J2ME Polish but i can't change text size, and i can only color it blue.

    Please help, thanks in advance.

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

    Re: Using a custom font questions

    Generally, custom fonts are derived from bitmap images, so cannot be resized. You would need to supply separate font images for each size you require.

    (You could build your own custom font mechanism, based on a technology like SVG, but that could be a lot of work, it might be very slow, and it would restrict the number of devices you could support.)

    As for changing colour, essentially the same is true. Either you supply images of the font in each colour you want, or you find a way to change the colour of the image at runtime. Changing colour can be achieved using getRGB() and createRBGImage() to convert an Image object to an int[] and back (changing the colour values in the int[]) (but note that this works only on MIDP-2 and is often memory-hungry), or by dynamically altering the PNG data from which the image is created (loading the PNG into a byte[], then editing the data in the palette chunk). The latter process requires an in-depth knowledge of the PNG file format.

    Graham.

  3. #3
    Regular Contributor
    Join Date
    Dec 2009
    Posts
    59

    Re: Using a custom font questions

    So unless i build my own mechanism, or use different bitmaps (with different font sizes) it's impossible to resize my text ? How can i create an application with text that looks the same on any screen size ?

    Thanks for the reply.

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

    Re: Using a custom font questions

    I'd suggest you make fonts in a number of sizes (say, four). This should cope with the major groups of screen sizes. Minor variations in screen size need to be handled with text wrapping, scrolling, paging, etc.

    Graham.

  5. #5
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: Using a custom font questions

    Hey guys,

    As for changing colour, essentially the same is true. Either you supply images of the font in each colour you want, or you find a way to change the colour of the image at runtime. Changing colour can be achieved using getRGB() and createRBGImage() to convert an Image object to an int[] and back (changing the colour values in the int[]) (but note that this works only on MIDP-2 and is often memory-hungry), or by dynamically altering the PNG data from which the image is created (loading the PNG into a byte[], then editing the data in the palette chunk). The latter process requires an in-depth knowledge of the PNG file format.
    hey, I was planning on having the color change by the value of the font, for example,I predetermine that the default color of the fonts in the png file would be black, black value is 0 but fully transparent pixel value would be different, so if I would like to change the color of the font I just run over the int[] of the image and change the values of the defined color of the font to the color of my choosing and save that value as int, this way I can manage colors with out too much complex code... this should work at least in theory, Graham once told me about some phones that give problem creating images with transparent pixels using the int[].

    and by the way, it is a great deal of work, I got 40% done so far, I still didn't wrote the coloring effect to my font I just designed it, although I wrote an abstract Effect object that does whatever with the font.

    hope this helps.
    Thanks,
    Adam Zehavi.

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

    Re: Using a custom font questions

    Quote Originally Posted by TacB0sS View Post
    some phones that give problem creating images with transparent pixels using the int[].
    Oh yes, I forgot about that!

    If I remember, this affects some Series 60s, and... I think creating an image is fine, but getRGB() ignores the alpha channel, delivering an array of all opaque pixels. My colleague's solution was to ensure that all the transparent pixels in the original image have a distinctive RGB value (we like 0xff00ff) and then add the transparency back in before calling createRGBImage().

    If you're willing to learn the in's and out's of the PNG format, then using a palette-format PNG and altering the palette is a more reliable process, as well as being faster and lighter on memory. There is more programming effort, as you'll need to locate the correct chunk of data in the PNG, and re-calculate its CRC or createImage() will reject the modified data as invalid. You'll also need good enough PNG tools (and to know how to use them!) that you can create PNGs in the exact format you want.

    Graham.

  7. #7
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: Using a custom font questions

    do you have any idea what is the technical reason for this behavior?
    Thanks,
    Adam Zehavi.

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

    Re: Using a custom font questions

    For the "getRGB() losing alpha" problem? Just a bug.

  9. #9
    Regular Contributor
    Join Date
    Jun 2009
    Location
    Tel-Aviv Israel
    Posts
    410

    Re: Using a custom font questions

    yes that makes sense of course, the question is what does this bug do to the int[], how would I get my int value? the same just alpha value would be fully opaque?

    does this happens only to fully transparent pixel?
    does this happens because the device (I assume) converts the pixels alpha values to its defined levels?
    is this bug registered can I view its details somewhere?

    I'm trying to determine the cause to maybe prevent this from happening and work my way around this.
    Thanks,
    Adam Zehavi.

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

    Re: Using a custom font questions

    All the alpha values came out as 0xff (fully opaque). We didn't explore this enough to find out if it affected partially alpha values, as it cropped up when porting and the game we were porting didn't use alpha blending. My colleague's fix would not have worked for alpha values other than 0x00 and 0xff - that would have been much more difficult problem to fix.

    It's very hard to get official bug lists, even from Nokia (Nokia are much better than most manufacturers at confirming "issues"). One of the significant costs in porting is the effort of finding all these issues and devising workarounds.

    Graham.

Similar Threads

  1. Custom Font Problem please help!!
    By HidayathKhan in forum Symbian
    Replies: 6
    Last Post: 2009-04-06, 08:01
  2. Using the font from setting list in custom listbox
    By alav in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-11-05, 17:17
  3. Replies: 0
    Last Post: 2007-08-08, 15:37
  4. custom font problem
    By allyfeng in forum Symbian
    Replies: 8
    Last Post: 2005-05-03, 15:08
  5. Replies: 3
    Last Post: 2005-01-13, 02:53

Posting Permissions

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