Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do draw italic text on Android canvas?

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)

like image 395
Swarnendu Paul Avatar asked Jul 26 '13 10:07

Swarnendu Paul


People also ask

How do you italicize in canvas?

Format Text To bold text, tap the Bold icon [3]. To italicize text, tap the Italics icon [4]. To underline text, tap the Underline icon [5]. To stop using bold, italics, or underline formatting, tap the Bold, Italics, or Underline icon again.

How to make font italic Android?

Double tap the text you want to format. Tap Format, then choose a formatting option like bolding, italics, or changing the font color.

How do I make my font bold on Android?

android:textStyle attribute is the first and one of the best way to make the text in TextView bold. just use “bold”. If you want to use bold and italic. Use pipeline symbol “|” .


2 Answers

You can use that method :

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

It's working for me.

like image 140
TN888 Avatar answered Sep 30 '22 08:09

TN888


Use this:

paint.setTextSkewX(-0.25f);
like image 28
Gaurav Kumar Avatar answered Sep 30 '22 06:09

Gaurav Kumar