1

When I am drawing Text with custom font(basically icon ex: WINGDING.ttf) using drawText is showing simple text as provided.

Steps I followed: 1. Added font file to Assets folder 2. Set paint with the added font 3. drawing text with the paint

To draw text I used the corresponding English character

canvas.drawText("p",0,1, x, y, myPaint);

This displays as p on app

TN.
  • 18,874
  • 30
  • 99
  • 157
user1287553
  • 23
  • 1
  • 4

2 Answers2

2

use this way if you have assets/fonts:

    private Paint    myPaint= new Paint(Paint.ANTI_ALIAS_FLAG);  
    private Typeface mFace; 
    mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/WINGDING.ttf");  
    myPaint.setTextSize(32);
    myPaint.setTypeface(mFace);
    canvas.drawText("test test",0,1, x, y, myPaint);
  //canvas.drawText("test test", 10, 200, myPaint);

example:

private static class MyView extends View   
    {  
private Paint    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  
private Typeface mFace;  
public MyView(Context context)   
{  
super(context);   
mFace = Typeface.createFromAsset(getContext().getAssets(),"fonts/WINGDING.ttf");  
mPaint.setTextSize(32);  
}  
 @Override protected void onDraw(Canvas canvas)   
{   
mPaint.setTypeface(mFace);  
canvas.drawText("p p p p", 10, 200, mPaint);  
}  
} 
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
  • I tried following code as per your comment but getting same result: class MyView extends View { Paint myPaint; public MyView(Context context) { super(context); Typeface face=Typeface.createFromAsset(getResources().getAssets(), "fonts/WINGDING.ttf"); myPaint=new Paint(Paint.ANTI_ALIAS_FLAG); myPaint.setTypeface(face); myPaint.setTextSize(30); myPaint.setColor(Color.WHITE); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); canvas.drawText("p", 50, 50, myPaint); } } – user1287553 Apr 28 '12 at 05:15
  • still same result: text "p p p p" corresponds to some font icon in WINGDING font but it is displaying p p p p – user1287553 Apr 28 '12 at 05:56
  • code is right try by using any other font instead of WINGDING – ρяσѕρєя K Apr 28 '12 at 06:00
  • 1
    I tried following fonts: WAKER___.TTF -> works, WEBDINGS.TTF -> did not work, WINGDING.ttf -> did not work one difference is there in these fonts WAKER___.TTF should display p as p but WEBDINGS.TTF & WINGDING.ttf should display p as icon text – user1287553 Apr 28 '12 at 06:08
  • 1
    my problem is WEBDINGS.TTF should display text icon, means corresponding text for characters(ex: p) but it displays same character as it is. i.e instead of using the custom font(WEBDINGS.TTF) it is using default font while displaying Typeface always works for me if not using icon fonts – user1287553 Apr 28 '12 at 06:18
0

I found this SO post that linked this font converter, http://www.freefontconverter.com.

I took my .ttf font that would not render and converted it to .ttf again (so .ttf to .ttf) and now it works! I hope this helps!

Community
  • 1
  • 1
Shadoninja
  • 1,276
  • 1
  • 12
  • 22