How can we use open source font in the code?

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

How can we use open source font in the code?

Postby shaamu786 » Thu Oct 15, 2009 11:54 am

hello guys I want to use ttf font (other than default) in my code. Can anyone suggest me how to use the font of our choice? please tell me if someone have any idea.
xgw
shaamu786
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Sep 01, 2009 7:17 am
Location: Delhi

Top

Postby pcm2a » Mon Oct 19, 2009 1:25 pm

You can do exactly what you are asking! Make a new folder where res and src are called assets with a subfolder called fonts. Place your .ttf in there.

Code: Select all
        Paint fontPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
        Typeface fontFace = Typeface.createFromAsset(getContext().getAssets(), "fonts/Digitek.ttf");
        fontPaint.setTypeface(fontFace);

        private void drawFontText(Canvas canvas, String text, int size, int color, int x, int y)
        {
           fontPaint.setTextSize(size);
           fontPaint.setColor(color);
           canvas.drawText(text, x, y, fontPaint);
        }
pcm2a
Developer
Developer
 
Posts: 27
Joined: Tue Aug 11, 2009 4:54 pm

Postby shaamu786 » Tue Oct 20, 2009 6:12 am

Thanks dear, actually i did't place the font file in asset folder that's why I was not able to get the desired result. But now my app is working fine.


one more problem, is there any API in Android to draw the srting(like help) on canvas so that when the width of screen completes the text will come to the next line without breaking the word.

For example in given text the word "BATTLES" is breaking when it comes to the next line

"GAME DESCRIPTION:
FIGHT THE GREATEST SUBMARINE BATT
LES OF THE MILLENNIUM."


So text will be like given below here the word "BATTLES" is not breaking.

"GAME DESCRIPTION:
FIGHT THE GREATEST SUBMARINE
BATTLES OF THE MILLENNIUM."



So if someone have any suggestion please tell me.
xgw
shaamu786
Junior Developer
Junior Developer
 
Posts: 16
Joined: Tue Sep 01, 2009 7:17 am
Location: Delhi

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 17 guests