当前位置: 首页>>代码示例>>Java>>正文


Java Paint.getTextSize方法代码示例

本文整理汇总了Java中android.graphics.Paint.getTextSize方法的典型用法代码示例。如果您正苦于以下问题:Java Paint.getTextSize方法的具体用法?Java Paint.getTextSize怎么用?Java Paint.getTextSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.graphics.Paint的用法示例。


在下文中一共展示了Paint.getTextSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override public void draw(Canvas canvas, CharSequence text, int start, int end,
                           float defaultX, int top, int defaultY, int bottom, Paint paint) {
    float x = 0;
    float y = 0;
    switch (position) {
        case RIGHT_TOP:
            x = canvas.getWidth() - paint.measureText(text, start, end);
            y = paint.getTextSize();
            break;
        case RIGHT_CENTER:
            x = canvas.getWidth() - paint.measureText(text, start, end);
            y = canvas.getHeight() / 2;
            break;
        case RIGHT_BOTTOM:
            x = canvas.getWidth() - paint.measureText(text, start, end);
            y = canvas.getHeight() - paint.getFontMetricsInt().bottom;
            break;
    }
    if (color != -1)
        paint.setColor(color);
    canvas.drawText(text, start, end, x, y, paint);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:23,代码来源:CustomAlignmentSpan.java

示例2: onDrawWeekDayLetters

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Invoked to draw first letters of days in week from the specified <var>top</var> position.
 * <p>
 * Default implementation draws day letters in one row on the specified <var>canvas</var>.
 *
 * @param canvas The canvas on which to draw day letters.
 * @param top    Top position from which to start the drawing. This is the position returned from
 *               {@link #onDrawTitle(Canvas, float, Paint)} method {@code +} {@link #getDayLettersOffsetVertical()}.
 * @param paint  Paint for day letters ready to be used for drawing.
 * @return Updated top position from which following graphic components (day numbers) of this view
 * will be drawn.
 * @see #onDrawDayNumbers(Canvas, float, Paint)
 */
protected float onDrawWeekDayLetters(@NonNull Canvas canvas, float top, @NonNull Paint paint) {
	/**
	 * We will draw 7 columns for each day in week.
	 */
	int dayIndex = mFirstDayOfWeek - 1;
	paint.getTextBounds(Integer.toString(MAX_DAY_IN_MONTH), 0, 2, TEXT_BOUNDS);
	float left = getPaddingLeft() + TEXT_BOUNDS.width() / 2f;
	top += (int) paint.getTextSize();
	for (int i = 0; i < DAYS_IN_WEEK; i++) {
		final String dayLetter = DAY_LETTERS[dayIndex];
		canvas.drawText(dayLetter, 0, 1, left, top, paint);
		left += mSpacingHorizontal;
		if (++dayIndex >= DAYS_IN_WEEK) {
			dayIndex = 0;
		}
	}
	return top;
}
 
开发者ID:universum-studios,项目名称:android_ui,代码行数:32,代码来源:MonthView.java

示例3: calcTextSizeForRect

import android.graphics.Paint; //导入方法依赖的package包/类
private static float calcTextSizeForRect(String _text, Paint _textPaint, RectF _rectBounds) {

        Matrix matrix = new Matrix();
        Rect textBoundsTmp = new Rect();
        //replace ones because for some fonts the 1 takes less space which causes issues
        String text = _text.replace('1', '0');

        //get current mText bounds
        _textPaint.getTextBounds(text, 0, text.length(), textBoundsTmp);

        RectF textBoundsTmpF = new RectF(textBoundsTmp);

        matrix.setRectToRect(textBoundsTmpF, _rectBounds, Matrix.ScaleToFit.CENTER);
        float values[] = new float[9];
        matrix.getValues(values);
        return _textPaint.getTextSize() * values[Matrix.MSCALE_X];
    }
 
开发者ID:VRLoser,项目名称:greendao_expand,代码行数:18,代码来源:CircleProgressView.java

示例4: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
                   @Nullable Paint.FontMetricsInt fm) {

    /* update FontMetricsInt or otherwise span does not get drawn when
       it covers the whole text */
    Paint.FontMetricsInt metrics = paint.getFontMetricsInt();
    if (fm != null) {
        fm.top = metrics.top;
        fm.ascent = metrics.ascent;
        fm.descent = metrics.descent;
        fm.bottom = metrics.bottom;
    }

    return (int) (paint.getTextSize()*1.2);
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:17,代码来源:CustomEmojiHelper.java

示例5: draw1LineTextAnchorMid

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Draw a single line text, x, y is in the middle of the line.
 */
public void draw1LineTextAnchorMid(Canvas canvas, String text, double x, double y,
		Paint paint, com.cyzapps.VisualMFP.Color color, double dTextSize, double dRotateDegree) {
	
	float fRotateDegree = (float)dRotateDegree, fX = (float)x, fY = (float)y;
	if (dRotateDegree != 0)	{
		canvas.rotate(fRotateDegree, fX, fY);
	}
	int nPaintOriginalColor = paint.getColor();
	float fPaintOriginalTxtSize = paint.getTextSize();
	if (color != null)	{
		paint.setColor(color.getARGB());
	}	// otherwise, use paint's color.
	paint.setTextSize((float)dTextSize);
	float fWidth = paint.measureText(text);
	canvas.drawText(text, fX - fWidth/2, fY + (float)dTextSize/2 - paint.descent(), paint);
	paint.setTextSize(fPaintOriginalTxtSize);
	paint.setColor(nPaintOriginalColor);
	if (dRotateDegree != 0) {
		canvas.rotate(-fRotateDegree, fX, fY);
	}
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:25,代码来源:FlatChart.java

示例6: calcTextBounds

import android.graphics.Paint; //导入方法依赖的package包/类
public Rect calcTextBounds(String text, Paint paint, double dTextSize, double dSpaceBtwTxtLines)	{
    float fPaintOriginalTxtSize = paint.getTextSize();
    Align alignOriginal = paint.getTextAlign();
    Rect rectTxtBox = new Rect(); // rectTxtBox gives original text box and returns the actual text box
    if (text == null)	{
    	return rectTxtBox;	// null protection.
    }
    paint.setTextSize((float)dTextSize);
    paint.setTextAlign(Align.LEFT);
    String[] lines = text.split("\n");
    for (int i = 0; i < lines.length; ++i) {
    	int nTxtWidth = (int)Math.ceil(paint.measureText(lines[i]));
        if (i == 0)    {
            rectTxtBox.left = 0;
            rectTxtBox.right = nTxtWidth;	//rect.right;
            rectTxtBox.top = 0;
            rectTxtBox.bottom = (int)Math.ceil(-paint.ascent() + paint.descent());//rect.height();
        } else    {
            rectTxtBox.right = Math.max(rectTxtBox.right, nTxtWidth);
            rectTxtBox.bottom = (int) (rectTxtBox.bottom + (int)Math.ceil(-paint.ascent() + paint.descent()) + dSpaceBtwTxtLines);
        }
    }
    paint.setTextAlign(alignOriginal);
    paint.setTextSize(fPaintOriginalTxtSize);
    return rectTxtBox;
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:27,代码来源:OGLChart.java

示例7: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    mPaint = new Paint(paint);
    mPaint.setTextSize(mTextSize);
    if(mTextSize > paint.getTextSize() && fm != null){
        Paint.FontMetricsInt newFm = mPaint.getFontMetricsInt();
        fm.descent = newFm.descent;
        fm.ascent = newFm.ascent;
        fm.top = newFm.top;
        fm.bottom = newFm.bottom;
    }
    return (int) mPaint.measureText(text, start, end);
}
 
开发者ID:coopese,项目名称:qmui,代码行数:14,代码来源:QMUITextSizeSpan.java

示例8: getCharGeometryCacheKey

import android.graphics.Paint; //导入方法依赖的package包/类
private static int getCharGeometryCacheKey(final char referenceChar, final Paint paint) {
    final int labelSize = (int)paint.getTextSize();
    final Typeface face = paint.getTypeface();
    final int codePointOffset = referenceChar << 15;
    if (face == Typeface.DEFAULT) {
        return codePointOffset + labelSize;
    } else if (face == Typeface.DEFAULT_BOLD) {
        return codePointOffset + labelSize + 0x1000;
    } else if (face == Typeface.MONOSPACE) {
        return codePointOffset + labelSize + 0x2000;
    } else {
        return codePointOffset + labelSize;
    }
}
 
开发者ID:rkkr,项目名称:simple-keyboard,代码行数:15,代码来源:TypefaceUtils.java

示例9: applyCodeTextStyle

import android.graphics.Paint; //导入方法依赖的package包/类
public void applyCodeTextStyle(@NonNull Paint paint) {

        if (codeTextColor != 0) {
            paint.setColor(codeTextColor);
        }

        // custom typeface was set
        if (codeTypeface != null) {

            paint.setTypeface(codeTypeface);

            // please note that we won't be calculating textSize
            // (like we do when no Typeface is provided), if it's some specific typeface
            // we would confuse users about textSize
            if (codeTextSize != 0) {
                paint.setTextSize(codeTextSize);
            }

        } else {
            paint.setTypeface(Typeface.MONOSPACE);
            final float textSize;
            if (codeTextSize != 0) {
                textSize = codeTextSize;
            } else {
                textSize = paint.getTextSize() * CODE_DEF_TEXT_SIZE_RATIO;
            }
            paint.setTextSize(textSize);
        }
    }
 
开发者ID:noties,项目名称:Markwon,代码行数:30,代码来源:SpannableTheme.java

示例10: draw

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public void draw(@NonNull Canvas canvas, CharSequence text, int start, int end, float x,
                 int top, int y, int bottom, @NonNull Paint paint) {
    if (imageDrawable == null) return;
    canvas.save();

    int emojiSize = (int) (paint.getTextSize() * 1.1);
    imageDrawable.setBounds(0, 0, emojiSize, emojiSize);

    int transY = bottom - imageDrawable.getBounds().bottom;
    transY -= paint.getFontMetricsInt().descent/2;
    canvas.translate(x, transY);
    imageDrawable.draw(canvas);
    canvas.restore();
}
 
开发者ID:Vavassor,项目名称:Tusky,代码行数:16,代码来源:CustomEmojiHelper.java

示例11: getCacheHeight

import android.graphics.Paint; //导入方法依赖的package包/类
protected Float getCacheHeight(BaseDanmaku danmaku, Paint paint) {
    Float textSize = paint.getTextSize();
    Float textHeight = sTextHeightCache.get(textSize);
    if (textHeight == null) {
        Paint.FontMetrics fontMetrics = paint.getFontMetrics();
        textHeight = fontMetrics.descent - fontMetrics.ascent + fontMetrics.leading;
        sTextHeightCache.put(textSize, textHeight);
    }
    return textHeight;
}
 
开发者ID:lisnstatic,项目名称:live_master,代码行数:11,代码来源:SimpleTextCacheStuffer.java

示例12: drawText

import android.graphics.Paint; //导入方法依赖的package包/类
/**
 * Draw a multiple lines text.
 */
public void drawText(Canvas canvas, String text, double x, double y,
		Paint paint, com.cyzapps.VisualMFP.Color color, double dTextSize, double dRotateDegree) {
	
	float fRotateDegree = (float)dRotateDegree, fX = (float)x, fY = (float)y;
	if (dRotateDegree != 0)	{
		canvas.rotate(fRotateDegree, fX, fY);
	}
	int nPaintOriginalColor = paint.getColor();
	float fPaintOriginalTxtSize = paint.getTextSize();
	if (color != null)	{
		paint.setColor(color.getARGB());
	}	// otherwise, use paint's color.
	paint.setTextSize((float)dTextSize);
	String[] lines = text.split("\n");
	Rect rect = new Rect();
	int yOff = 0;
	for (int i = 0; i < lines.length; ++i) {
		canvas.drawText(lines[i], fX, fY + paint.getFontMetrics().leading + paint.ascent() + yOff, paint);
		paint.getTextBounds(lines[i], 0, lines[i].length(), rect);
		yOff = (int) (yOff + rect.height() + mdSpaceBtwTxtLines); // space between lines
	}
	paint.setTextSize(fPaintOriginalTxtSize);
	paint.setColor(nPaintOriginalColor);
	if (dRotateDegree != 0) {
		canvas.rotate(-fRotateDegree, fX, fY);
	}
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:31,代码来源:FlatChart.java

示例13: draw

import android.graphics.Paint; //导入方法依赖的package包/类
public void draw(Canvas canvas, double x, double y, double width, double height, Paint paint) {
	drawBackground(canvas, x, y, width, height, paint, null);
	float fPaintOriginalTxtSize = paint.getTextSize();
	paint.setTextSize((float)(width/2));
	draw1LineTextAnchorMid(canvas, mstrChartTitle, x / 2, y + mdSmallSize, paint, null, mdSmallSize, 0);
       drawButtons(canvas, x, y, width, height, paint);
	paint.setTextSize(fPaintOriginalTxtSize);
}
 
开发者ID:woshiwpa,项目名称:SmartMath,代码行数:9,代码来源:FlatChart.java

示例14: loadPages

import android.graphics.Paint; //导入方法依赖的package包/类
public static SparseArray<ArrayList<String>> loadPages(String source, Paint textPaint, int visibleHeight, int visibleWidth, int intervalSize, int paragraphSize) {
    SparseArray<ArrayList<String>> pageArray = new SparseArray<>();
    List<String> lines = new ArrayList<>();
    if (source != null && source.length() > 0) {
        String[] split = source.split("\n");
        //剩余高度
        int rHeight = visibleHeight + intervalSize + paragraphSize;
        for (String paragraph : split) {
            boolean hasContent=false;
            //如果只有换行符,那么就不执行
            if (StringUtils.isBlank(paragraph)) continue;
            //重置段落
            paragraph = StringUtils.halfToFull("  " + paragraph + "\n");
            paragraph = StringUtils.trimBeforeReplace(paragraph, "  ");
            while (paragraph.length() > 0) {


                //测量一行占用的字节数
                int count = textPaint.breakText(paragraph, true, visibleWidth, null);
                String subStr = paragraph.substring(0, count);
                String trim = subStr.trim();
                if (trim.length()>0&&!trim.equals("\n") && !trim.equals("\r\n")&&!StringUtils.isBlank(trim)) {
                    //重置剩余距离
                    rHeight -= (textPaint.getTextSize() + intervalSize);

                    //达到行数要求,创建Page
                    if (rHeight < 0) {
                        //创建Page
                        pageArray.put(pageArray.size(), new ArrayList<>(lines));
                        //重置Lines
                        lines.clear();
                        rHeight = visibleHeight;
                        continue;
                    }
                    //将一行字节,存储到lines中
                    lines.add(subStr);
                    hasContent=true;
                }


                //裁剪
                paragraph = paragraph.substring(count);
            }

            if (lines.size() > 0&&hasContent) {
                rHeight -= paragraphSize;
            }
        }

        if (lines.size() != 0) {
            pageArray.put(pageArray.size(), new ArrayList<>(lines));
            //重置Lines
            lines.clear();

        }
    }
    return pageArray;
}
 
开发者ID:z-chu,项目名称:FriendBook,代码行数:59,代码来源:StringAdapter.java

示例15: getSize

import android.graphics.Paint; //导入方法依赖的package包/类
@Override
public int getSize(Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) {
    int width = (int) paint.measureText(mTableLinkText, 0, mTableLinkText.length());
    mTextSize = paint.getTextSize();
    return width;
}
 
开发者ID:RanKKI,项目名称:PSNine,代码行数:7,代码来源:DrawTableLinkSpan.java


注:本文中的android.graphics.Paint.getTextSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。