java类android.graphics.Paint.FontMetrics的实例源码

TerminalBridge.java 文件源码 项目:GitHub 阅读 38 收藏 0 点赞 0 评论 0
private int fontSizeCompare(float sizeDp, int cols, int rows, int width, int height) {
    // read new metrics to get exact pixel dimensions
    defaultPaint.setTextSize((int) (sizeDp * this.displayDensity + 0.5f));
    FontMetrics fm = defaultPaint.getFontMetrics();

    float[] widths = new float[1];
    defaultPaint.getTextWidths("X", widths);
    int termWidth = (int) widths[0] * cols;
    int termHeight = (int) Math.ceil(fm.descent - fm.top) * rows;

    Log.d("fontsize", String.format("font size %fdp resulted in %d x %d", sizeDp, termWidth, termHeight));

    // Check to see if it fits in resolution specified.
    if (termWidth > width || termHeight > height)
        return 1;

    if (termWidth == width || termHeight == height)
        return 0;

    return -1;
}
RoundedIconGenerator.java 文件源码 项目:chromium-for-android-56-debug-video 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Constructs the generator and initializes the common members ignoring display density.
 *
 * @param iconWidthPx The width of the generated icon in pixels.
 * @param iconHeightPx The height of the generated icon in pixels.
 * @param cornerRadiusPx The radius of the corners in the icon in pixels.
 * @param backgroundColor Color at which the rounded rectangle should be drawn.
 * @param textSizePx Size at which the text should be drawn in pixels.
 */
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
        int backgroundColor, float textSizePx) {
    mIconWidthPx = iconWidthPx;
    mIconHeightPx = iconHeightPx;
    mCornerRadiusPx = cornerRadiusPx;

    mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextSize(textSizePx);

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;
}
TopicTipView.java 文件源码 项目:LiteSDK 阅读 26 收藏 0 点赞 0 评论 0
private void init(){
    mWidth = (int) getPaint().measureText(getText().toString());
    FontMetrics fm = getPaint().getFontMetrics();
    mFontHeiht = (float)Math.ceil(fm.descent - fm.ascent);
    int horizontalPadding = getHorizontalPaddint();
    int verticalPadding = getVerticalPaddint();
    mPath.reset();
    mPath.moveTo(0, 0);
    mPath.lineTo(mWidth + horizontalPadding, 0);
    mPath.lineTo(mWidth + horizontalPadding, mFontHeiht + verticalPadding);
    mPath.lineTo(25, mFontHeiht + verticalPadding);
    mPath.lineTo(0, mFontHeiht+verticalPadding+25);
    mPath.close();

    mPaint.setAntiAlias(true);
    mPaint.setColor(Color.RED);
    mPaint.setStyle(Style.FILL);

    getPaint().setColor(Color.WHITE);// 不知道什么原因,xml设置无效。暂时先在代码中设置。
}
RoundedIconGenerator.java 文件源码 项目:AndroidChromium 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Constructs the generator and initializes the common members ignoring display density.
 *
 * @param iconWidthPx The width of the generated icon in pixels.
 * @param iconHeightPx The height of the generated icon in pixels.
 * @param cornerRadiusPx The radius of the corners in the icon in pixels.
 * @param backgroundColor Color at which the rounded rectangle should be drawn.
 * @param textSizePx Size at which the text should be drawn in pixels.
 */
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
        int backgroundColor, float textSizePx) {
    mIconWidthPx = iconWidthPx;
    mIconHeightPx = iconHeightPx;
    mCornerRadiusPx = cornerRadiusPx;

    mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextSize(textSizePx);

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;
}
TitleBar.java 文件源码 项目:iOffice 阅读 33 收藏 0 点赞 0 评论 0
public TitleBar(Context context)
{
    super(context);

    BitmapFactory.Options opts = new BitmapFactory.Options();
    opts.inJustDecodeBounds = true;
    BitmapFactory.decodeResource(getResources(),  R.drawable.sys_title_bg_vertical, opts); 
    height = opts.outHeight;        

    setBackgroundResource(R.drawable.sys_title_bg_vertical);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(Color.WHITE);
    paint.setTextSize(24);
    FontMetrics fm = paint.getFontMetrics();

    yPostion = (height - fm.descent + fm.ascent) / 2  -  fm.ascent;

    mBusyIndicator = new ProgressBar(getContext());
    mBusyIndicator.setIndeterminate(true);
    //mBusyIndicator.setBackgroundResource(R.drawable.busy);
    addView(mBusyIndicator);
    mBusyIndicator.setVisibility(GONE);
}
TerminalBridge.java 文件源码 项目:connectbot 阅读 27 收藏 0 点赞 0 评论 0
private int fontSizeCompare(float size, int cols, int rows, int width, int height) {
    // read new metrics to get exact pixel dimensions
    defaultPaint.setTextSize(size);
    FontMetrics fm = defaultPaint.getFontMetrics();

    float[] widths = new float[1];
    defaultPaint.getTextWidths("X", widths);
    int termWidth = (int)widths[0] * cols;
    int termHeight = (int)Math.ceil(fm.descent - fm.top) * rows;

    Log.d("fontsize", String.format("font size %f resulted in %d x %d", size, termWidth, termHeight));

    // Check to see if it fits in resolution specified.
    if (termWidth > width || termHeight > height)
        return 1;

    if (termWidth == width || termHeight == height)
        return 0;

    return -1;
}
AbGraphical.java 文件源码 项目:EntboostIM 阅读 28 收藏 0 点赞 0 评论 0
/**
 * 描述:绘制文本,支持换行.
 *
 * @param canvas the canvas
 * @param text the text
 * @param maxWPix the max w pix
 * @param paint the paint
 * @param left the left
 * @param top the top
 * @return the int
 */
public static int drawText(Canvas canvas,String text,int maxWPix,TextPaint paint,int left,int top) {
if(AbStrUtil.isEmpty(text)){
    return 1;
}
//需要根据文字长度控制换行
   //测量文字的长度
List<String> mStrList  = getDrawRowStr(text,maxWPix,paint);

    FontMetrics fm  = paint.getFontMetrics();
    int hSize = (int)Math.ceil(fm.descent - fm.ascent)+2;

    for(int i=0;i<mStrList.size();i++){
     //计算坐标
     int x = left;
        int y = top+hSize/2+hSize*i;
     String textLine = mStrList.get(i);
        canvas.drawText(textLine,x,y, paint); 

    }
    return mStrList.size();
}
RoundedIconGenerator.java 文件源码 项目:Vafrinn 阅读 28 收藏 0 点赞 0 评论 0
/**
 * Constructs the generator and initializes the common members ignoring display density.
 *
 * @param iconWidthPx The width of the generated icon in pixels.
 * @param iconHeightPx The height of the generated icon in pixels.
 * @param cornerRadiusPx The radius of the corners in the icon in pixels.
 * @param backgroundColor Color at which the rounded rectangle should be drawn.
 * @param textSizePx Size at which the text should be drawn in pixels.
 */
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
        int backgroundColor, float textSizePx) {
    mIconWidthPx = iconWidthPx;
    mIconHeightPx = iconHeightPx;
    mCornerRadiusPx = cornerRadiusPx;

    mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextSize(textSizePx);

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;
}
TopicTipView.java 文件源码 项目:umeng_community_android 阅读 27 收藏 0 点赞 0 评论 0
private void init(){
    mWidth = (int) getPaint().measureText(getText().toString());
    FontMetrics fm = getPaint().getFontMetrics();
    mFontHeiht = (float)Math.ceil(fm.descent - fm.ascent);
    int horizontalPadding = getHorizontalPaddint();
    int verticalPadding = getVerticalPaddint();
    mPath.reset();
    mPath.moveTo(0, 0);
    mPath.lineTo(mWidth + horizontalPadding, 0);
    mPath.lineTo(mWidth + horizontalPadding, mFontHeiht + verticalPadding);
    mPath.lineTo(25, mFontHeiht + verticalPadding);
    mPath.lineTo(0, mFontHeiht+verticalPadding+25);
    mPath.close();

    mPaint.setAntiAlias(true);
    mPaint.setColor(ResFinder.getColor("umeng_comm_topic_tip_bg"));
    mPaint.setStyle(Style.FILL);

    getPaint().setColor(Color.WHITE);// 不知道什么原因,xml设置无效。暂时先在代码中设置。
}
AbTextView.java 文件源码 项目:eshow-android 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Draw text.
 *
 * @param canvas the canvas
 * @param text the text
 * @param maxWPix the max w pix
 * @param paint the paint
 * @return the int
 */
public int drawText(Canvas canvas, String text, int maxWPix,
        TextPaint paint) {
    if (TextUtils.isEmpty(text)) {
        return 1;
    }
    // 需要根据文字长度控制换行
    // 测量文字的长度
    List<String> mStrList = getDrawRowStr(text, maxWPix, paint);

    FontMetrics fm = paint.getFontMetrics();
    int hSize = (int)Math.ceil(fm.descent - fm.ascent);

    for (int i = 0; i < mStrList.size(); i++) {
        // 计算坐标
        float x = leftPadding;
        float y = topPadding+hSize/2+i*(hSize+lineSpacing)+bottomPadding;
        String textLine = mStrList.get(i);
        if(i < maxLines){
            canvas.drawText(textLine, x, y, paint);
        }
    }
    return mStrList.size();
}
TopicTipView.java 文件源码 项目:AndroidGeek 阅读 27 收藏 0 点赞 0 评论 0
private void init(){
    mWidth = (int) getPaint().measureText(getText().toString());
    FontMetrics fm = getPaint().getFontMetrics();
    mFontHeiht = (float)Math.ceil(fm.descent - fm.ascent);
    int horizontalPadding = getHorizontalPaddint();
    int verticalPadding = getVerticalPaddint();
    mPath.reset();
    mPath.moveTo(0, 0);
    mPath.lineTo(mWidth + horizontalPadding, 0);
    mPath.lineTo(mWidth + horizontalPadding, mFontHeiht + verticalPadding);
    mPath.lineTo(25, mFontHeiht + verticalPadding);
    mPath.lineTo(0, mFontHeiht+verticalPadding+25);
    mPath.close();

    mPaint.setAntiAlias(true);
    mPaint.setColor(ResFinder.getColor("umeng_comm_topic_tip_bg"));
    mPaint.setStyle(Style.FILL);

    getPaint().setColor(Color.WHITE);// 不知道什么原因,xml设置无效。暂时先在代码中设置。
}
PieSeries.java 文件源码 项目:Android-SmartChart 阅读 56 收藏 0 点赞 0 评论 0
protected void drawLabel(Canvas canvas, String labelText, List<RectF> prevLabelsBounds, int centerX, int centerY,
            float shortRadius, float longRadius, float currentAngle, float angle, int left, int right, int color,
            Paint paint, boolean line, boolean showMoreLabel)
{

    LabelPoint labelPoint =
                drawLabelHandler(canvas, labelText, prevLabelsBounds, centerX, centerY, shortRadius, longRadius,
                            currentAngle, angle, left, right, color, paint, line);
    String[] texts = labelText.split("/");
    for (int index = 0; index < texts.length; index++)
    {
        canvas.drawText(texts[index], labelPoint.xLabel, labelPoint.yLabel, paint);
        FontMetrics fm = paint.getFontMetrics();
        labelPoint.yLabel = labelPoint.yLabel + Math.round(fm.descent - fm.top) + 2;
    }
    if (line)
    {
        prevLabelsBounds.add(new RectF(labelPoint.xLabel, labelPoint.yLabel, labelPoint.xLabel
                    + labelPoint.widthLabel, labelPoint.yLabel + labelPoint.size));
    }
}
RoundedIconGenerator.java 文件源码 项目:365browser 阅读 27 收藏 0 点赞 0 评论 0
/**
 * Constructs the generator and initializes the common members ignoring display density.
 *
 * @param iconWidthPx The width of the generated icon in pixels.
 * @param iconHeightPx The height of the generated icon in pixels.
 * @param cornerRadiusPx The radius of the corners in the icon in pixels.
 * @param backgroundColor Color at which the rounded rectangle should be drawn.
 * @param textSizePx Size at which the text should be drawn in pixels.
 */
public RoundedIconGenerator(int iconWidthPx, int iconHeightPx, int cornerRadiusPx,
        int backgroundColor, float textSizePx) {
    mIconWidthPx = iconWidthPx;
    mIconHeightPx = iconHeightPx;
    mCornerRadiusPx = cornerRadiusPx;

    mBackgroundRect = new RectF(0, 0, mIconWidthPx, mIconHeightPx);

    mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBackgroundPaint.setColor(backgroundColor);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(Color.WHITE);
    mTextPaint.setFakeBoldText(true);
    mTextPaint.setTextSize(textSizePx);

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;
}
NestHeader.java 文件源码 项目:NestRefreshLayout 阅读 22 收藏 0 点赞 0 评论 0
/**
     * @see android.view.ViewGroup#dispatchDraw(Canvas)
     */
    @Override
    protected void dispatchDraw(Canvas canvas) {
        if (mState == STATE_REFRESHING) {
//
//            float centerX = mArrowImageView.getMeasuredWidth() / 2;
//            float centerY = mArrowImageView.getMeasuredHeight() / 2;
//            Matrix matrix = mArrowImageView.getImageMatrix();
//            mArrowImageView.setScaleType(ScaleType.MATRIX);
//            matrix.postRotate(25, centerX, centerY);
//            mArrowImageView.setImageMatrix(matrix);
        }
        super.dispatchDraw(canvas);
        if (isInEditMode()) {
            return;
        }
        FontMetrics fontMetrics = mPaint.getFontMetrics();
        // 计算文字高度
        float fontHeight = fontMetrics.bottom - fontMetrics.top;
        // 计算文字baseline
        float textBaseY = getHeight() - (getHeight() - fontHeight) / 2 - fontMetrics.bottom;
        canvas.drawText(mstrTitle, getWidth() / 2 + mArrowImageView.getMeasuredWidth(), textBaseY, mPaint);
    }
WheelView.java 文件源码 项目:Unity 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 画左右的Label
 *
 * @param canvas
 */
private void drawLabel(Canvas canvas) {
    canvas.save();
    int vh = getHeight();

    FontMetrics fontMetrics = paint.getFontMetrics();
    // 计算文字高度
    float fontHeight = fontMetrics.bottom - fontMetrics.top;
    // 计算文字baseline
    float y = PADDING + vh - (vh - fontHeight) / 2 - fontMetrics.bottom;

    if (!TextUtils.isEmpty(mRightLabel)) {
        canvas.drawText(mRightLabel, getWidth() - rightLabelLen / 2
                - PADDING, y, labelPaint);
    }
    if (!TextUtils.isEmpty(mLeftLabel)) {
        canvas.drawText(mLeftLabel, PADDING + leftLabelLen / 2, y,
                labelPaint);
    }

    canvas.restore();
}
TasksCompletedView.java 文件源码 项目:lookingforseats-nwpu 阅读 26 收藏 0 点赞 0 评论 0
private void initVariable() {
    mCirclePaint = new Paint();
    mCirclePaint.setAntiAlias(true);
    mCirclePaint.setColor(mCircleColor);
    mCirclePaint.setStyle(Paint.Style.FILL);

    mRingPaint = new Paint();
    mRingPaint.setAntiAlias(true);
    mRingPaint.setColor(mRingColor);
    mRingPaint.setStyle(Paint.Style.STROKE);
    mRingPaint.setStrokeWidth(mStrokeWidth);

    mTextPaint = new Paint();
    mTextPaint.setAntiAlias(true);
    mTextPaint.setStyle(Paint.Style.FILL);
    mTextPaint.setARGB(255, 255, 255, 255);
    mTextPaint.setTextSize(mRadius / 2);

    FontMetrics fm = mTextPaint.getFontMetrics();
    mTxtHeight = (int) Math.ceil(fm.descent - fm.ascent);

}
AbTextView.java 文件源码 项目:androidsummary 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Draw text.
 *
 * @param canvas the canvas
 * @param text the text
 * @param maxWPix the max w pix
 * @param paint the paint
 * @return the int
 */
public int drawText(Canvas canvas, String text, int maxWPix,
        TextPaint paint) {
    if (TextUtils.isEmpty(text)) {
        return 1;
    }
    // 需要根据文字长度控制换行
    // 测量文字的长度
    List<String> mStrList = getDrawRowStr(text, maxWPix, paint);

    FontMetrics fm = paint.getFontMetrics();
    int hSize = (int)Math.ceil(fm.descent - fm.ascent);

    for (int i = 0; i < mStrList.size(); i++) {
        // 计算坐标
        float x = leftPadding;
        float y = topPadding+hSize/2+i*(hSize+lineSpacing)+bottomPadding;
        String textLine = mStrList.get(i);
        if(i < maxLines){
            canvas.drawText(textLine, x, y, paint);
        }
    }
    return mStrList.size();
}
InvestGroupChart.java 文件源码 项目:GomeOnline 阅读 35 收藏 0 点赞 0 评论 0
protected void onDraw(Canvas canvas){
        Paint paint = new Paint();
        paint.setStyle(Style.STROKE);
        paint.setAntiAlias(true);
        paint.setColor(0xffe9e9e9);
        paint.setTextSize(Function.getFitPx(getContext(), 30));
        FontMetrics fm = paint.getFontMetrics();
//      canvas.drawRect(drawRect, paint);
        canvas.drawLine(drawRect.left, drawRect.top, drawRect.right, drawRect.top, paint);
        canvas.drawLine(drawRect.left, drawRect.bottom, drawRect.right, drawRect.bottom, paint);
        float h = (maxValue - minValue) / 2;
        float y = Function.getYCoordinate(drawRect, minValue+h, maxValue, minValue);
        paint.setColor(0xffbbbbbc);
        canvas.drawLine(drawRect.left, y, drawRect.right, y, paint);
        paint.setTextAlign(Align.RIGHT);
        int baseline = (int) (drawRect.top + (drawRect.bottom - drawRect.top - fm.bottom + fm.top) / 2 - fm.top); 
        canvas.drawText("0%", drawRect.left-Function.getFitPx(getContext(), 20), baseline, paint);
        paint.setColor(getContext().getResources().getColor(R.color.font_de3031));          
        canvas.drawText("3.4%", drawRect.left-Function.getFitPx(getContext(), 20), drawRect.top-(fm.top-fm.bottom)/2 + 2, paint);
        paint.setColor(getContext().getResources().getColor(R.color.font_32a632));          
        canvas.drawText("-3.4%", drawRect.left-Function.getFitPx(getContext(), 20), drawRect.bottom, paint);
    }
RLAutoSplitTextView.java 文件源码 项目:Roid-Library 阅读 26 收藏 0 点赞 0 评论 0
@Override
protected void onDraw(Canvas canvas)
{
    Paint mPaint = getPaint();

    //Get font's height & leading:
    FontMetrics fm = mPaint.getFontMetrics();
    float height = fm.descent - fm.ascent + fm.leading;

    float x = 0;
    float y = height;
    String[] textLines = autoSplit(getText().toString(), mPaint, getWidth());
    for (String textLine : textLines)
    {
        canvas.drawText(textLine, x, y, mPaint);
        y += height;
    }
}
TerminalBridge.java 文件源码 项目:GitHub 阅读 30 收藏 0 点赞 0 评论 0
/**
 * Request a different font size. Will make call to parentChanged() to make
 * sure we resize PTY if needed.
 *
 * @param sizeDp Size of font in dp
 */
private final void setFontSize(float sizeDp) {
    if (sizeDp <= 0.0) {
        return;
    }

    final int fontSizePx = (int) (sizeDp * this.displayDensity + 0.5f);

    defaultPaint.setTextSize(fontSizePx);
    fontSizeDp = sizeDp;

    // read new metrics to get exact pixel dimensions
    FontMetrics fm = defaultPaint.getFontMetrics();
    charTop = (int) Math.ceil(fm.top);

    float[] widths = new float[1];
    defaultPaint.getTextWidths("X", widths);
    charWidth = (int) Math.ceil(widths[0]);
    charHeight = (int) Math.ceil(fm.descent - fm.top);

    // refresh any bitmap with new font size
    if (parent != null) {
        parentChanged(parent);
    }

    for (FontSizeChangedListener ofscl : fontSizeChangedListeners) {
        ofscl.onFontSizeChanged(sizeDp);
    }

    host.setFontSize((int) sizeDp);
    manager.hostdb.saveHost(host);

    forcedSize = false;
}
HighlightingImageView.java 文件源码 项目:Quran 阅读 23 收藏 0 点赞 0 评论 0
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;
}
SliderView.java 文件源码 项目:Hotspot-master-devp 阅读 25 收藏 0 点赞 0 评论 0
/**
 * 获取字体的高度
 * @param fontSize
 * @return
 */
private int getFontHeight(float fontSize){  
     Paint paint = new Paint();  
     paint.setTextSize(fontSize);  
     FontMetrics fm = paint.getFontMetrics();  
    return (int) Math.ceil(fm.descent - fm.top) + 2;  
}
TitleBitmapFactory.java 文件源码 项目:chromium-for-android-56-debug-video 阅读 48 收藏 0 点赞 0 评论 0
/**
 * @param context   The current Android's context.
 * @param incognito Whether the title are for incognito mode.
 * @param nullFaviconResourceId A drawable resource id of a default favicon.
 */
public TitleBitmapFactory(Context context, boolean incognito, int nullFaviconResourceId) {
    mNullFaviconResourceId = nullFaviconResourceId;

    Resources res = context.getResources();
    int textColor = ApiCompatibilityUtils.getColor(res, incognito
            ? R.color.compositor_tab_title_bar_text_incognito
            : R.color.compositor_tab_title_bar_text);
    float textSize = res.getDimension(R.dimen.compositor_tab_title_text_size);

    boolean fakeBoldText = res.getBoolean(R.bool.compositor_tab_title_fake_bold_text);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setColor(textColor);

    mTextPaint.setTextSize(textSize);
    mTextPaint.setFakeBoldText(fakeBoldText);
    mTextPaint.density = res.getDisplayMetrics().density;

    FontMetrics textFontMetrics = mTextPaint.getFontMetrics();
    mTextHeight = (float) Math.ceil(textFontMetrics.bottom - textFontMetrics.top);
    mTextYOffset = -textFontMetrics.top;

    mFaviconDimension = res.getDimensionPixelSize(R.dimen.compositor_tab_title_favicon_size);
    mViewHeight = (int) Math.max(mFaviconDimension, mTextHeight);

    int width = res.getDisplayMetrics().widthPixels;
    int height = res.getDisplayMetrics().heightPixels;
    mMaxWidth = (int) (TITLE_WIDTH_PERCENTAGE * Math.max(width, height));

    // Set the favicon dimension here.
    mFaviconDimension = Math.min(mMaxWidth, mFaviconDimension);
}
TextMessageWithLinkAndIconPreference.java 文件源码 项目:chromium-for-android-56-debug-video 阅读 20 收藏 0 点赞 0 评论 0
@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;
}
SimpleTextCacheStuffer.java 文件源码 项目:letv 阅读 24 收藏 0 点赞 0 评论 0
protected Float getCacheHeight(BaseDanmaku danmaku, Paint paint) {
    Float textSize = Float.valueOf(paint.getTextSize());
    Float textHeight = (Float) sTextHeightCache.get(textSize);
    if (textHeight != null) {
        return textHeight;
    }
    FontMetrics fontMetrics = paint.getFontMetrics();
    textHeight = Float.valueOf((fontMetrics.descent - fontMetrics.ascent) + fontMetrics.leading);
    sTextHeightCache.put(textSize, textHeight);
    return textHeight;
}
ScrollTextView.java 文件源码 项目:AndroidTvDemo 阅读 25 收藏 0 点赞 0 评论 0
/**
 * text height
 *
 * @param fontSize fontsize
 * @return fontsize `s height
 */
public int getFontHeight(float fontSize)
{
    Paint paint = new Paint();
    paint.setTextSize(fontSize);
    FontMetrics fm = paint.getFontMetrics();
    return (int)Math.ceil(fm.descent - fm.ascent);
}
ViewUtils.java 文件源码 项目:android-project-gallery 阅读 27 收藏 0 点赞 0 评论 0
/**
 * 返回字体高度
 * 
 * @param textSize
 * @return
 */
public static int getFontHeight(float textSize)
{
    Paint paint = new Paint();
    paint.setTextSize(textSize);
    FontMetrics fm = paint.getFontMetrics();

    return (int) Math.ceil(fm.descent - fm.top) + 2;
}
SingleLineEditText.java 文件源码 项目:android-project-gallery 阅读 22 收藏 0 点赞 0 评论 0
/**
 * 返回字体高度
 * 
 * @param textSize
 * @return
 */
public int getFontHeight(float textSize)
{
    Paint paint = new Paint();
    paint.setTextSize(textSize);
    FontMetrics fm = paint.getFontMetrics();

    return (int) Math.ceil(fm.descent - fm.top) + 2;
}
ViewUtils.java 文件源码 项目:Lunei 阅读 25 收藏 0 点赞 0 评论 0
/**
 * get Font height
 */
public static int getFontHeight(TextView view) {
    Paint paint = new Paint();
    paint.setTextSize(view.getTextSize());
    FontMetrics fm = paint.getFontMetrics();
    return (int) (Math.ceil(fm.descent - fm.ascent));
}
DeviceProfile.java 文件源码 项目:SimplOS 阅读 33 收藏 0 点赞 0 评论 0
private void updateIconSize(float scale, int drawablePadding, Resources res,
                            DisplayMetrics dm) {
    iconSizePx = (int) (Utilities.pxFromDp(inv.iconSize, dm) * scale);
    iconTextSizePx = (int) (Utilities.pxFromSp(inv.iconTextSize, dm) * scale);
    iconDrawablePaddingPx = drawablePadding;
    hotseatIconSizePx = (int) (Utilities.pxFromDp(inv.hotseatIconSize, dm) * scale);

    // Search Bar
    searchBarSpaceWidthPx = Math.min(widthPx,
            res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_max_width));
    searchBarSpaceHeightPx = getSearchBarTopOffset()
            + res.getDimensionPixelSize(R.dimen.dynamic_grid_search_bar_height);

    // Calculate the actual text height
    Paint textPaint = new Paint();
    textPaint.setTextSize(iconTextSizePx);
    FontMetrics fm = textPaint.getFontMetrics();
    cellWidthPx = iconSizePx;
    cellHeightPx = iconSizePx + iconDrawablePaddingPx + (int) Math.ceil(fm.bottom - fm.top);
    final float scaleDps = res.getDimensionPixelSize(R.dimen.dragViewScale);
    dragViewScale = (iconSizePx + scaleDps) / iconSizePx;

    // Hotseat
    hotseatBarHeightPx = iconSizePx + 4 * edgeMarginPx;
    hotseatCellWidthPx = iconSizePx;
    hotseatCellHeightPx = iconSizePx;

    // Folder
    folderCellWidthPx = cellWidthPx + 3 * edgeMarginPx;
    folderCellHeightPx = cellHeightPx + edgeMarginPx;
    folderBackgroundOffset = -edgeMarginPx;
    folderIconSizePx = iconSizePx + 2 * -folderBackgroundOffset;
}


问题


面经


文章

微信
公众号

扫码关注公众号