×

Discussion Board

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

    Custom font applications ?

    Hi,

    Do you guys know any other applications that can write custom font ? I don't want J2ME Polish, Font4Mobile, Mobile BitMap Fonts because:
    - J2ME Polish: displays a dot under the letter "i"
    - Font4Mobile: font creator won't start, don't know why
    - Mobile BitMap Fonts: creates incomplete letters (missing pixels)

    I know i'm the unluckiest man alive, i've been told this alot.
    And i don't want to create them manually, i tried that, and i find it too difficult.

    Thanks,
    Alex

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

    Re: Custom font applications ?

    I think i'll go for manually.
    I used Graham's tutorial here, and i have some questions:

    private static int CELL_WIDTH = 12;
    private static int CELL_HEIGHT = 16;

    CELL_HEIGHT is the size of the font, like arial 16 ?
    If CELL_WIDTH is the same for every character, then the text will look awful, because characters like "l", "." are smaller (in width) than characters like "@", "M".
    What can i do to solve this ?

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

    Re: Custom font applications ?

    In the example code, characters are placed in a grid. Each character is in a fixed-size rectangle. CELL_WIDTH and CELL_HEIGHT are the size of rectangles. They are needed to locate the correct cell in the grid (the correct character). Both are in pixels.

    Yes, to keep things simple, this example code is suitable only for fixed-pitch fonts, like Courier. However, modifying it for proportionally-spaced fonts is not difficult. Like any good tutor, I leave some work for the student!

    Get some code working with a fixed-pitch font first.

    For proportional fonts, you will need to add a width for each character. It's not complicated, but it involves some effort.

    You can add this by hand:

    Code:
    private static int[] characterWidth = new int[] {
        3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 5, 4, etc.
    };
    The only other modification is at the end of drawChar(), where:

    Code:
    return CELL_WIDTH;
    needs to be replaced with:

    Code:
    return characterWidth[i];
    Ideally, the array of width data would be loaded from a file, and that file would be generated by some tool that scans the font image to find the width of each character image. But you can just code them in by hand.

    Note that for fixed-pitch fonts, the characters need to be centred in each cell, whereas for proportional fonts, the characters should be flush to the left-edge of the cell. For a proportional font, the characters should still be in fixed-size cells. This wastes a bit of memory (because there will be blank space in the image, but makes drawing faster by making the correct character easier to locate in the font image.

    Use a paint program (like Paint Shop Pro) that can overlay a grid on the image you're drawing when you make the font. That will make life much simpler. You need to make sure no pixels fall outside the cell for that character, or other characters will appear with "artifacts" (extra pixels that a shouldn't be there).

    The cell size needs to be large enough! Sounds obvious, but don't forget that (as you say), W, M and @ can be very wide. Also, allow enough space for decenders (g, j, p, q), diacritical marks above capital letters (Â, É, Ñ). Remember also that some languages use marks below characters (such as French ç and Romanian ş and ţ).

    Graham.

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

    Re: Custom font applications ?

    Wow! That really sounds like a lot of work, getting character width for each character in every font size i want to use. I guess it will pay off in the end.

    Thanks Graham.

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

    Re: Custom font applications ?

    Yes, that's why I left it out of the example!

    If you're going to do this a lot, then you need to write a tool to create the width data for you. You can do this in J2SE, loading the image and using the same cell width and height. Use a PixelGrabber to get the pixel data from the image (works like Image.getRGB() in 'ME), and look for the right-most, non-transparent pixel in each cell. From this, you can work out the width of the character in that cell. Write that to a data file (use a DataOutputStream), which you can then include in your JAR, and read in the app with a DataInputStream. Such a project should take around one day to complete.

    Graham.

Similar Threads

  1. So Weird when I add a font file in project
    By SymbianSymbian in forum Symbian
    Replies: 2
    Last Post: 2009-08-10, 03:43
  2. How to get the name of the used font
    By chrishawaii in forum Symbian User Interface
    Replies: 1
    Last Post: 2007-06-22, 06:55
  3. CRichText and Custom fonts
    By hansmeet2 in forum Symbian User Interface
    Replies: 2
    Last Post: 2006-11-15, 17:56
  4. CRichText and Custom Font
    By kmsoomro in forum Symbian
    Replies: 0
    Last Post: 2006-10-07, 19:09
  5. custom font with midp2 application
    By kmsoomro in forum Mobile Java General
    Replies: 1
    Last Post: 2006-02-20, 15:04

Posting Permissions

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