@Override public Rectangle[] getCharacterBoundingBoxes(Text text, TextSpan[] spans) { GlyphMetrics[] metrics = getGlyphMetrics(text, spans); Rectangle[] charBoxes = new Rectangle[metrics.length]; for (int i = 0; i < charBoxes.length; ++i) charBoxes[i] = new Rectangle(metrics[i].boundingBox); return charBoxes; }
float x = x_px2mm(charBox.left); float y = y_px2mm(charBox.top); float width = x_px2mm(charBox.width()); float height = y_px2mm(charBox.height()); float rightSideBearing = getRightSideBearing(label, start, end, charBox);
int fontSize = Math.round(y_mm2px(style.getFontSize())); fontKey = new FontKey(spans[spanIndex].getStyle().getFontFamily(), typefaces[spanIndex].getStyle(), fontSizes[spanIndex]); spanEnd = spans[spanIndex].getEndPosition(); updatePaint(fontSizes, typefaces, spanIndex); GlyphMetrics m = getGlyphMetrics(fontKey, label, start, end); float pos = x_px2mm(posPx); updatePaint(fontSizes, typefaces, 0); int start = text.getGlyphBeginAt(0); int end = text.getGlyphEndAt(0); GlyphMetrics m = getGlyphMetrics(fontKey, label, start, end); charBoxes[0] = new GlyphMetrics(m.boundingBox.x, m.boundingBox.y, m.boundingBox.width, m.boundingBox.height, m.leftSideBearing, m.rightSideBearing);
private final float getRightSideBearing(String label, int start, int end, RectF charBox) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { float advance = paint.getRunAdvance(label, start, end, start, end, false, end); return x_px2mm(advance - charBox.right); } else { return 0; } }
editor.setFontMetricsProvider(new FontMetricsProvider(displayMetrics, typefaceMap));