How do draw italic text on Android canvas?
Asked Answered
C

2

16

In my app I am drawing text on Android Canvas;

Now to support underline and bold I am taking help of paint object;

 Paint paint = new Paint();   

 paint.setUnderlineText(true); 
 paint.setFakeBoldText(true);

 paint.setColor(color);
 paint.setTextSize (font_size);
 canvas_obj.drawText(text,x,y,paint);

With this code I am getting bold and underlined text;

I also like to make it italic,

I am developing app for android 2.2 onwards.

how to do it?

Edit:

I am setting Typeface object created with an external font file to support external font; For Italic I am using following code

paint.setTypeface(Typeface.create(external_font_type_face,Typeface.ITALIC));

This also not working, Tested on Samsung Galaxy Ace (android 2.2)

Clapboard answered 26/7, 2013 at 10:16 Comment(0)
C
31

You can use that method :

paint.setTypeface(Typeface.create(Typeface.DEFAULT, Typeface.ITALIC));

It's working for me.

Caryopsis answered 26/7, 2013 at 10:21 Comment(4)
I am already using a Typeface object( created with an external font file, ) in paint ; I am developing app for android 2.2 onwardsClapboard
@Swarnendu Typeface has been implemented in Android 1.5Caryopsis
@ Ty221 Unfortunately it is not working, setting typeface to paint object is replacing previously set typrface object to the paint object(which was set to support external font ); so neither I am getting the external font support nor italic text with default font.. :-(Clapboard
I don't know other way (Google also don't know)Caryopsis
P
2

Use this:

paint.setTextSkewX(-0.25f);
Prothallus answered 8/12, 2017 at 9:58 Comment(1)
While this code snippet may solve the question, including an explanation really helps to improve the quality of your post. Remember that you are answering the question for readers in the future, and those people might not know the reasons for your code suggestion.Payer

© 2022 - 2024 — McMap. All rights reserved.