Search in sources :

Example 1 with FontMetrics

use of android.graphics.Paint.FontMetrics in project AndroidChromium by JackyAndroid.

the class TextMessageWithLinkAndIconPreference method onCreateView.

@Override
public View onCreateView(ViewGroup parent) {
    View view = super.onCreateView(parent);
    if (mNoBottomSpacing) {
        ApiCompatibilityUtils.setPaddingRelative(view, ApiCompatibilityUtils.getPaddingStart(view), view.getPaddingTop(), ApiCompatibilityUtils.getPaddingEnd(view), 0);
    }
    ((TextView) view.findViewById(android.R.id.summary)).setMovementMethod(LinkMovementMethod.getInstance());
    // The icon is aligned to the top of the text view, which can be higher than the
    // ascender line of the text, and makes it look aligned improperly.
    TextView textView = (TextView) view.findViewById(getTitle() != null ? android.R.id.title : android.R.id.summary);
    FontMetrics metrics = textView.getPaint().getFontMetrics();
    ImageView icon = (ImageView) view.findViewById(android.R.id.icon);
    ApiCompatibilityUtils.setPaddingRelative(icon, 0, (int) java.lang.Math.ceil(metrics.ascent - metrics.top), 0, 0);
    return view;
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View)

Example 2 with FontMetrics

use of android.graphics.Paint.FontMetrics in project Zong by Xenoage.

the class AndroidTextMeasurer method measure.

public static TextMetrics measure(Paint paint, String text) {
    FontMetrics metrics = new FontMetrics();
    paint.getFontMetrics(metrics);
    float ascent = Units.pxToMm(Math.abs(metrics.ascent), 1);
    float descent = Units.pxToMm(metrics.descent, 1);
    float leading = Units.pxToMm(metrics.leading, 1);
    float width = Units.pxToMm(paint.measureText(text), 1);
    return new TextMetrics(ascent, descent, leading, width);
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics) TextMetrics(com.xenoage.utils.font.TextMetrics)

Example 3 with FontMetrics

use of android.graphics.Paint.FontMetrics in project android2 by aqi00.

the class MeasureUtil method getTextHeight.

// 获取指定文本的高度
public static float getTextHeight(String text, float textSize) {
    // 创建一个画笔对象
    Paint paint = new Paint();
    // 设置画笔的文本大小
    paint.setTextSize(textSize);
    // 获取画笔默认字体的度量衡
    FontMetrics fm = paint.getFontMetrics();
    // 返回文本自身的高度
    return fm.descent - fm.ascent;
// return fm.bottom - fm.top + fm.leading;  // 返回文本所在行的行高
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics) Paint(android.graphics.Paint)

Example 4 with FontMetrics

use of android.graphics.Paint.FontMetrics in project DMGameApp by xiaohaibin.

the class ColorTrackView method measureText.

private void measureText() {
    mTextWidth = (int) mPaint.measureText(mText);
    FontMetrics fm = mPaint.getFontMetrics();
    mTextHeight = (int) Math.ceil(fm.descent - fm.top);
    mPaint.getTextBounds(mText, 0, mText.length(), mTextBound);
    mTextHeight = mTextBound.height();
}
Also used : FontMetrics(android.graphics.Paint.FontMetrics)

Example 5 with FontMetrics

use of android.graphics.Paint.FontMetrics in project quran_android by quran.

the class HighlightingImageView method initOverlayParams.

private boolean initOverlayParams(Matrix matrix) {
    if (overlayParams == null || pageBounds == null) {
        return false;
    }
    // Overlay params previously initiated; skip
    if (overlayParams.init) {
        return true;
    }
    int overlayColor = overlayTextColor;
    if (isNightMode) {
        overlayColor = Color.rgb(nightModeTextBrightness, nightModeTextBrightness, nightModeTextBrightness);
    }
    overlayParams.paint.setColor(overlayColor);
    // Use font metrics to calculate the maximum possible height of the text
    FontMetrics fm = overlayParams.paint.getFontMetrics();
    final RectF mappedRect = new RectF();
    matrix.mapRect(mappedRect, pageBounds);
    // Calculate where the text's baseline should be
    // (for top text and bottom text)
    // (p.s. parts of the glyphs will be below the baseline such as a
    // 'y' or 'ي')
    overlayParams.topBaseline = -fm.top;
    overlayParams.bottomBaseline = getHeight() - fm.bottom;
    // Calculate the horizontal margins off the edge of screen
    overlayParams.offsetX = Math.min(mappedRect.left, getWidth() - mappedRect.right);
    overlayParams.init = true;
    return true;
}
Also used : RectF(android.graphics.RectF) FontMetrics(android.graphics.Paint.FontMetrics) Paint(android.graphics.Paint)

Aggregations

FontMetrics (android.graphics.Paint.FontMetrics)8 Paint (android.graphics.Paint)3 TextView (android.widget.TextView)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 RectF (android.graphics.RectF)1 Typeface (android.graphics.Typeface)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 Pixmap (com.badlogic.gdx.graphics.Pixmap)1 TextMetrics (com.xenoage.utils.font.TextMetrics)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FreePaint (var3d.net.center.freefont.FreePaint)1