×

Discussion Board

Page 1 of 3 123 LastLast
Results 1 to 15 of 44

Thread: Custom font

  1. #1
    Regular Contributor
    Join Date
    Apr 2006
    Posts
    63

    Custom font

    Hi,


    Is there a way of packaging a custom font with you're application?

    Is there a repository of fonts free of charge you can use?

    How to best guarantee that the font displayed on the canvas remains the same across devices?


    Thanks.

  2. #2
    Nokia Developer Champion
    Join Date
    Apr 2003
    Location
    USA, CA
    Posts
    7,192

    Re: Custom font

    You cannot package a font with your app and there is no guarantee that the font looks the same from device to device (unless you draw the characters yourself or use bitmaps)

    Hartti

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    26

    Re: Custom font

    Martin,
    You can use Custom fonts. Custom font can be implemented easily in J2ME. You have to get a png image(you can get from any graphical designer)which contains all the characters and special symbols required for your application. And, to get the width and height of each characters from the designer. I recomment you strongly to use custom fonts, so that you will get the same font(look & feel) across all devices. If you want further information, provide me your email address, I will send you source file and custom font png images describing custom font implementation.

  4. #4
    Registered User
    Join Date
    Jan 2008
    Posts
    1

    Re: Custom font

    hi i want to implement custome fonts in j2me you can send me eg source code at wondwosen_desalegn@yahoo.com

  5. #5
    Registered User
    Join Date
    Jan 2008
    Location
    Pune, India
    Posts
    4

    Re: Custom font

    Hi guys,

    Easiest way to use custom fonts in j2me applications is by using j2me Polish. We just need to save a Bitmap file (.bmf) into the resource folder & mention it in the style-sheet.

    There are tools available which can convert true-type font files (.ttf) - commonly found in Windows Font folder - to the required .bmf format.

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Re: Custom font

    Can you also send the source code to implement custom font to: dowlu@yahoo.com ?

    Regards,

    Naveen

  7. #7
    Registered User
    Join Date
    Jan 2008
    Posts
    3

    Re: Custom font

    Can you also send the source code to implement custom font to: dowlu@yahoo.com ?

    Regards,

    Naveen

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    1

    Re: Custom font

    i would also appreciate it if you could send me eg source code or
    source file and custom font png images describing custom font implementation to picmes@yahoo.com
    thanks

  9. #9
    Regular Contributor
    Join Date
    Dec 2008
    Posts
    124

    Re: Custom font

    Please i also need that too. Send it to my E-mail: chaoraksa@yahoo.com.

    Thanks in advanced.

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

    Custom fonts: step by step

    1: Draw Your Font

    Lay the characters out in a grid. Don't put them in one long, thin strip, as some devices have problems with images that have one, very large dimension.

    To simplify things, each cell of the grid is the same size.

    Your image should look something like:

    Code:
    1234567890!" '
    *()-.,:/ABCDEF
    GHIJKLMNOPQRST
    UVWXYZabcdefgh
    ijklmnopqrstuv
    wxyzАБВГДЕЁЖЗИ
    ЙКЛМНОПРСТУФХЦ
    ЧШЩЪЫЬЭЮЯабвгд
    еёжзийклмнопрс
    туфхцчшщъыьэюя
    Make sure the background is transparent. Use 8-bit PNG format for best compatibility across devices.

    Note that I've left a space (between the " and ' on the top row). You can have separate code later to handle the space as a special condition, but this is easier.

    2: Defining the Font Parameters
    A string holds a list of characters, in the order that they appear in the image. Use unicode escapes for non-ASCII characters, or someone in another country (with a different character encoding) will get different results.

    This information should really be loaded from some kind of font definition file, but for this example, they'll go in the code.

    Code:
    private static int CELL_WIDTH = 12;
    private static int CELL_HEIGHT = 16;
    
    private static String sequence = "1234567890!\" '*()-.,:/"
            + "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
            + "abcdefghijklmnopqrstuvwxyz"
            + "\u0410\u0411\u0412\u0413\u0414\u0415\u0401\u0416"
            + "\u0417\u0418\u0419\u041A\u041B\u041C\u041D\u041E"
            + "\u041F\u0420\u0421\u0422\u0423\u0424\u0425\u0426"
            + "\u0427\u0428\u0429\u042A\u042B\u042C\u042D\u042E"
            + "\u042F\u0430\u0431\u0432\u0433\u0434\u0435\u0451"
            + "\u0436\u0437\u0438\u0439\u043A\u043B\u043C\u043D"
            + "\u043E\u043F\u0440\u0441\u0442\u0443\u0444\u0445"
            + "\u0446\u0447\u0448\u0449\u044A\u044B\u044C\u044D\u044E\u044F";
    
    private static Image fontImage;
    private static int width;
    private static int height;
    private static int charsPerRow;
    
    public static void inialise(String fontname) throws IOException {
        fontImage = Image.createImage(fontname);
        width = fontimage.getWidth();
        height = fontimage.getHeight();
        charsPerRow = width / CELL_WIDTH;
    }
    3. Drawing a Character

    Using setClip(), you can draw any character you like.

    I've made this code throw an exception if the characters is not in the font, so you know quickly if you have a missing character. For a production build, you might prefer to draw some place-holder character instead.

    Code:
    /** @return width of the character */
    private static int drawChar(Graphics g, char ch, int x, int y) {
        // find the position in the font
        int i = sequence.indexOf(ch);
        if (i == -1) {
            throw new IllegalArgumentException("unsupported character");
        }
    
        // find that character in the image
        int cx = (i % charsPerRow) * CELL_WIDTH;
        int cy = (i / charsPerRow) * CELL_HEIGHT;
    
        // draw it
        g.setClip(x, y, CELL_WIDTH, CELL_HEIGHT);
        g.drawImage(fontimage, x - cx, y - cy, Graphics.TOP | Graphics.LEFT);
    
        return CELL_WIDTH;
    }
    4. Drawing a String

    Once you can draw a character, you can draw a string.

    Code:
    private static void drawString(Graphics g, String s, int x, int y) {
        // this is faster than using s.charAt()
        char[] chs = s.toCharArray();
        for (int i = 0; i < chs.length; i++) {
            x += drawChar(g, chs[i], x, y);
        }
    }
    5. Improvements

    This, of course, will only handle a fixed-width font. Support a proportional-width font is just a matter of adding an array of character widths. The last line of drawChar() then becomes:

    Code:
    return characterWidth[i];
    This implementation also changes the current clip region, which is different behaviour from the API implementation of Graphics.drawString().

    Saving the clip region is a simple matter of:

    Code:
    int clipX = g.getClipX();
    int clipY = g.getClipY();
    int clipW = g.getClipWidth();
    int clipH = g.getClipHeight();
    And restoring it:

    Code:
    g.setClip(clipX, clipY, clipW, clipH);

  11. #11
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Custom font

    wow,
    great how-to graham...
    except of j2mepolish also lwuit supports the creation and usage of different fonts, in case someone wants to use a 3rd party gui-package/tool...

  12. #12
    Regular Contributor
    Join Date
    Oct 2008
    Location
    port said
    Posts
    59

    Re: Custom font

    can any body tell me how to use the j2mepolish use the .bmf file to write the a font and how to tell j2mepolish the font name as its attribute is style,size and face which one as each one have fixed number of attribute
    Last edited by helwg1130; 2009-02-15 at 09:46.
    3oMaR

  13. #13
    Regular Contributor
    Join Date
    Oct 2008
    Location
    port said
    Posts
    59

    Re: Custom font

    i want the tool that convert ttf to bmf
    3oMaR

  14. #14
    Nokia Developer Champion
    Join Date
    Apr 2007
    Posts
    2,708

    Re: Custom font

    i want a ferrari !!!

    are we gonna make the I want/expect something topic ? might be fun, people come with the strangest things

    anyhow, I guess u'd like to have such an utility and u are asking us (in a polite manner) if we know anything about it...
    well i managed to find this :

    http://lmgtfy.com/?q=ttf+to+bmf

    (tip : try to use that incredible tool !!!! it's pretty secret that (i think they call it) searching-machine or something.. or engine to search.. whatever)

    then at the end of the page u get ur result :
    "Use the font-editor situated in the ${polish.home}/bin folder to create bitmap fonts (*.bmf) out of any true type fonts."

  15. #15
    Registered User
    Join Date
    Mar 2003
    Posts
    36

    Re: Custom font

    Any thoughts about whether it is legal to distribute fonts in a png file within a jar file?

Page 1 of 3 123 LastLast

Similar Threads

  1. I m trying to develop the custom Font application plz help
    By HidayathKhan in forum Symbian C++
    Replies: 9
    Last Post: 2011-03-11, 14:16
  2. Custom Font Problem please help!!
    By HidayathKhan in forum Symbian C++
    Replies: 6
    Last Post: 2009-04-06, 08:01
  3. custom font for my app changes all applications font
    By rafeeqpv in forum Symbian C++
    Replies: 0
    Last Post: 2007-08-08, 15:37
  4. custom font problem
    By allyfeng in forum Symbian C++
    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
  •