Paint getFontMetrics - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Paint getFontMetrics method.

This code example shows how to use the following methods:getFontMetrics, getTextBounds, setColor, setTextSize
		mLabel = string;
 
		mWidth = drawable.getIntrinsicWidth();
		mHeight = drawable.getIntrinsicHeight();
 
		mTextPaint = new Paint( Paint.ANTI_ALIAS_FLAG | Paint.SUBPIXEL_TEXT_FLAG | Paint.DEV_KERN_TEXT_FLAG | Paint.HINTING_ON );
		mTextPaint.setColor( Color.WHITE );
		mBounds = new Rect();
		mMetrics = new FontMetrics();
 
		onTextBoundsChanged(); 
	} 
 
	public void setTitle( final String value ) {
		mLabel = value;
		invalidateSelf(); 
		onTextBoundsChanged(); 
	} 
 
	public final String getTitle() {

8
CodeRank
This code example shows how to use the following methods:getFontMetrics, measureText, setTextSize, setTypeface
This code example shows how to use the following methods:getFontMetrics, getTextBounds, setColor, setTextSize, setTypeface
        createFont(text, typeface, fontSize);
    } 
 
    protected Bitmap createFontImage(String text, Typeface typeface, int fontSize) {
 
        paint.setTextSize(fontSize);
        paint.setTypeface(typeface);
        paint.getTextBounds(text, 0, text.length(), bounds);
 
        FontMetrics fontMetrics = paint.getFontMetrics();
 
        final int IMAGE_WIDTH = Math.max(1, bounds.width());
        final int IMAGE_HEIGHT = (int) Math.max(//
                Math.abs(fontMetrics.ascent) + Math.abs(fontMetrics.descent),
                // 
                (Math.abs(fontMetrics.top) + Math.abs(fontMetrics.bottom)));
        Bitmap bitmap = Bitmap.createBitmap(IMAGE_WIDTH, IMAGE_HEIGHT, Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        Graphics graphics = new Graphics();
        graphics.setCanvas(canvas);

7
CodeRank
This code example shows how to use the following methods:getFontMetrics, getFontMetricsInt, getTextSize, setTextSize, setTextSkewX
		return (int)measureText;
	} 
 
	 
	public void initPaint( Paint p ) {
		p.setTypeface( this.typeface );
		p.setUnderlineText(isUnderlined());
		if (isItalic()) { 
			p.setTextSkewX(-0.25f);
		} else { 
			p.setTextSkewX(0f);			
		} 
		p.setTextSize( this.height );
 
		FontMetricsInt fontMetricsInt = p.getFontMetricsInt();
		this.descent =  fontMetricsInt.descent;
		this.baselinePosition = (int) (p.getTextSize() - p.getFontMetrics().descent) + 1;
	} 
 
	/** 

6
CodeRank
This code example shows how to use the following methods:getFontMetrics, measureText, setAntiAlias, setColor, setTextSize
		// 追加された文字列がnullの場合は、適当な文字列に変更 
		if (text == null) {
			text = "no-data";
		} 
		 
		paint.setTextSize(fontSize);
		paint.setColor(Color.argb(255, r, g, b));
		paint.setAntiAlias(true);
		 
		FontMetrics fontMetrics = paint.getFontMetrics();
		 
		int width = (int) paint.measureText(text);
		int height = (int) (fontSize + fontMetrics.bottom);
		/* 
		if (width > brSize) { 
			int maxWidth = brSize; 
			int brPoint = Integer.MAX_VALUE; 
			int currentIndex = 0; 
			while (brPoint != 0) { 
				String mesureString = text.substring(currentIndex); 
6
CodeRank
This code example shows how to use the following methods:getFontMetrics, getTextSize, measureText, setTextSize
        } 
    } 
     
    @Override 
    public float drawTextAt(String text, float x, float y, float h, int align) {
        final Paint.FontMetrics fm = mBrush.getFontMetrics();
        float lineHeight = Math.abs(fm.descent) + Math.abs(fm.ascent);
         
        if (Math.abs(lineHeight - h) > 1e-2f) {
            mBrush.setTextSize(h * mBrush.getTextSize() / lineHeight);
        } 
         
        float w = mBrush.measureText(text);
        x -= (align == 2) ? w : ((align == 1) ? w / 2 : 0);
        mCanvas.drawText(text, x, y - fm.top, mBrush);
         
        return w;
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getFontMetrics, setColor, setTextAlign, setTextSize
        textBackgroundPaint.setColor(Color.WHITE);
        canvas.drawRect(txtBackgroundRect, textBackgroundPaint);  
         
        //Draw text with picture time 
        int textsize = 12;
        Paint textPaint = new Paint( Paint.ANTI_ALIAS_FLAG);  
        textPaint.setTextSize( textsize );  
        textPaint.setColor( Color.BLACK);  
        textPaint.setTextAlign(Paint.Align.CENTER);
        FontMetrics fontMetrics = textPaint.getFontMetrics();  
           
        //Y�����ǣ�(�и�-�����߶�)/2+�����߶� 
        int fontHeight = getFontHeight(textsize);
        float centerBaseY = (mainBmpHeight-5) + ((15-fontHeight)/2 - fontMetrics.top);
        float centerBaseX = mainBmpWidth/2;
         
        canvas.drawText( text, centerBaseX, centerBaseY, textPaint); 
   
        //Unlock canvas 
        canvas.restore();
6
CodeRank
This code example shows how to use the following methods:getFontMetrics, getTextSize, measureText, setAntiAlias, setColor
	private Resources res;
	 
	public Text(Context context, String text, Align alignment) {
		super(alignment);	
		res = context.getResources();
		this.paint = new Paint();
 
		Resources res = context.getResources();
		paint.setColor(res.getColor(android.R.color.primary_text_dark));
		paint.setTextSize(24);
		paint.setAntiAlias(true);
		paint.setSubpixelText(true);
		 
		this.text = text;
		 
		initSprite(); 
		 
		updateTexture = false;
		visibility = VISIBLE;
	} 

6
CodeRank
This code example shows how to use the following methods:getFontMetrics, setAlpha, setAntiAlias, setTextAlign, setTextSize
 
        private static void drawIntoBitmap(Bitmap bm) {
            float x = bm.getWidth();
            float y = bm.getHeight();
            Canvas c = new Canvas(bm);
            Paint paint = new Paint();
            paint.setAntiAlias(true);
 
            paint.setAlpha(0x80);
            c.drawCircle(x/2, y/2, x/2, paint);
 
            paint.setAlpha(0x30);
            paint.setXfermode(
           		new PorterDuffXfermode(PorterDuff.Mode.SRC));
            paint.setTextSize(60);
            paint.setTextAlign(Paint.Align.CENTER);
            Paint.FontMetrics fm = paint.getFontMetrics();
            c.drawText("程式設計", x/2, (y-fm.ascent)/2, paint);
        } 
 

6
CodeRank
This code example shows how to use the following methods:getFontMetrics, setTypeface
		setMeasuredDimension(width, height);
	} 
 
	@Override 
	protected int getSuggestedMinimumHeight() { 
		paint.setTypeface(Typeface.DEFAULT_BOLD);
		return (int) (-paint.getFontMetrics().top + paint.getFontMetrics().bottom)
				+ getPaddingTop() + getPaddingBottom();
	} 
 
	public void onPageScrolled(final int position, final float positionOffset,
			final int positionOffsetPixels) {
		pageOffset = position + positionOffset;
		invalidate();
	} 
 
	public void onPageSelected(final int position) {
		pagePosition = position;
		invalidate();
	} 
6
CodeRank

Related Paint getFontMetrics Questions & Answers:

getFontMetrics Method Overview
Return the font's recommended interline spacing, given the Paint's settings for typeface, textSize, etc.
See Code Examples for other Android Paint Methods: