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;
}
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);
}
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; // 返回文本所在行的行高
}
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();
}
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;
}
Aggregations