List of usage examples for android.graphics Paint setTextSize
public void setTextSize(float textSize)
From source file:Main.java
public static void calculateOKTextSize(Paint paint, float stripeWidth, String[] text, float maxAllowedTextSize) { float minTextSize = 1000; for (int i = 0; i < text.length; ++i) { float currSize = setTextSizeForWidth(paint, stripeWidth, text[i]); if (currSize < minTextSize) minTextSize = currSize;//from w w w. j av a 2s.c o m } if (minTextSize > maxAllowedTextSize) paint.setTextSize(maxAllowedTextSize); else paint.setTextSize(minTextSize); }
From source file:cc.softwarefactory.lokki.android.utilities.Utils.java
public static Bitmap getDefaultAvatarInitials(Context context, String text) { Log.e(TAG, "getDefaultAvatarInitials"); String initials = getInitials(text); Paint paint = new Paint(); paint.setStyle(Paint.Style.FILL); paint.setColor(Color.WHITE);//from w w w .j a v a 2 s .c o m paint.setTextSize(36); paint.setStrokeWidth(4); paint.setTextAlign(Paint.Align.CENTER); Bitmap bm = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bm); canvas.drawColor(context.getResources().getColor(R.color.material_blue_300)); int distanceFromBaseline = (int) ((paint.descent() + paint.ascent()) / 2); int xPos = (canvas.getWidth() / 2); int yPos = (canvas.getHeight() / 2) - distanceFromBaseline; canvas.drawText(initials, xPos, yPos, paint); return bm; }
From source file:com.viewpagerindicator.TabMovablePageIndicator.java
public static int getTextWidth(String str, float fontSize, Typeface typeface) { if (str == null || str.equals("")) { return 0; }// ww w . j av a 2 s.c om Paint pFont = new Paint(); Rect rect = new Rect(); pFont.setTextSize(fontSize); pFont.setTypeface(typeface); pFont.getTextBounds(str, 0, str.length(), rect); return rect.width(); }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static Paint newPaint(String fontName, int fontSize, int alignment) { Paint paint = new Paint(); paint.setColor(Color.WHITE);// www. ja v a 2 s . c o m paint.setTextSize(fontSize); paint.setAntiAlias(true); /* * Set type face for paint, now it support .ttf file. */ if (fontName.endsWith(".ttf")) { try { //Typeface typeFace = Typeface.createFromAsset(context.getAssets(), fontName); Typeface typeFace = Cocos2dxTypefaces.get(context, fontName); paint.setTypeface(typeFace); } catch (Exception e) { Log.e("Cocos2dxBitmap", "error to create ttf type face: " + fontName); /* * The file may not find, use system font */ paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL)); } } else { paint.setTypeface(Typeface.create(fontName, Typeface.NORMAL)); } int hAlignment = alignment & 0x0F; switch (hAlignment) { case HALIGNCENTER: paint.setTextAlign(Align.CENTER); break; case HALIGNLEFT: paint.setTextAlign(Align.LEFT); break; case HALIGNRIGHT: paint.setTextAlign(Align.RIGHT); break; default: paint.setTextAlign(Align.LEFT); break; } return paint; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);//from w ww.ja v a 2 s. c om paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:eu.iescities.pilot.rovereto.roveretoexplorer.map.MapManager.java
private static Bitmap writeOnStoryMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);/*w w w. ja v a 2 s .c om*/ paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2 - ((paint.descent() + paint.ascent()) / 2); canvas.drawText(text, x, y, paint); return bitmap; }
From source file:eu.trentorise.smartcampus.trentinofamiglia.map.MapManager.java
private static Bitmap writeOnMarker(Context mContext, int drawableId, String text) { float scale = mContext.getResources().getDisplayMetrics().density; Bitmap bitmap = BitmapFactory.decodeResource(mContext.getResources(), drawableId) .copy(Bitmap.Config.ARGB_8888, true); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setTextAlign(Align.CENTER);//from www . ja v a2 s.co m paint.setTextSize(scale * 14); paint.setAntiAlias(true); paint.setARGB(255, 255, 255, 255); Canvas canvas = new Canvas(bitmap); Rect bounds = new Rect(); paint.getTextBounds(text, 0, text.length(), bounds); float x = bitmap.getWidth() / 2; float y = bitmap.getHeight() / 2 - 5; canvas.drawText(text, x, y, paint); return bitmap; }
From source file:org.cocos2dx.lib.Cocos2dxBitmap.java
private static int getFontSizeAccordingHeight(int height) { Paint paint = new Paint(); Rect bounds = new Rect(); paint.setTypeface(Typeface.DEFAULT); int incr_text_size = 1; boolean found_desired_size = false; while (!found_desired_size) { paint.setTextSize(incr_text_size); String text = "SghMNy"; paint.getTextBounds(text, 0, text.length(), bounds); incr_text_size++;//from w w w . j a va2s . co m if (height - bounds.height() <= 2) { found_desired_size = true; } Log.d("font size", "incr size:" + incr_text_size); } return incr_text_size; }
From source file:com.kmagic.solitaire.DrawMaster.java
/** * Get paint for text use// w ww . j av a 2s. c o m * @return red paint object */ public static Paint getTextPaint(final float fontSize, final Paint.Align align) { Paint paint = getPaint(); paint.setTextSize(fontSize); paint.setTypeface(Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD)); paint.setTextAlign(align); return (paint); }
From source file:info.papdt.blacklight.support.Utility.java
public static int getFontHeight(Context context, float fontSize) { // Convert Dp To Px float px = context.getResources().getDisplayMetrics().density * fontSize + 0.5f; // Use Paint to get font height Paint p = new Paint(); p.setTextSize(px); FontMetrics fm = p.getFontMetrics(); return (int) Math.ceil(fm.descent - fm.ascent); }