Call minikin::getBounds instead of using Layout.
The bounding box is not necessary for drawing text, so it is no longer stored in the Layout object. Instead, calculate by minikin::getBounds function. Bug: 169114687 Test: atest PaintTest Test: atest Paint_TextBoundsTest Change-Id: I3f77d2cc3843ac504c7475c7800f2526b403d933
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include <log/log.h>
|
||||
|
||||
#include <minikin/MeasuredText.h>
|
||||
#include <minikin/Measurement.h>
|
||||
#include "Paint.h"
|
||||
#include "SkPathMeasure.h"
|
||||
#include "Typeface.h"
|
||||
@@ -69,6 +70,18 @@ minikin::Layout MinikinUtils::doLayout(const Paint* paint, minikin::Bidi bidiFla
|
||||
}
|
||||
}
|
||||
|
||||
void MinikinUtils::getBounds(const Paint* paint, minikin::Bidi bidiFlags, const Typeface* typeface,
|
||||
const uint16_t* buf, size_t bufSize, minikin::MinikinRect* out) {
|
||||
minikin::MinikinPaint minikinPaint = prepareMinikinPaint(paint, typeface);
|
||||
|
||||
const minikin::U16StringPiece textBuf(buf, bufSize);
|
||||
const minikin::StartHyphenEdit startHyphen = paint->getStartHyphenEdit();
|
||||
const minikin::EndHyphenEdit endHyphen = paint->getEndHyphenEdit();
|
||||
|
||||
minikin::getBounds(textBuf, minikin::Range(0, textBuf.size()), bidiFlags, minikinPaint,
|
||||
startHyphen, endHyphen, out);
|
||||
}
|
||||
|
||||
float MinikinUtils::measureText(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const Typeface* typeface, const uint16_t* buf, size_t start,
|
||||
size_t count, size_t bufSize, float* advances) {
|
||||
|
||||
@@ -48,6 +48,9 @@ public:
|
||||
size_t contextStart, size_t contextCount,
|
||||
minikin::MeasuredText* mt);
|
||||
|
||||
static void getBounds(const Paint* paint, minikin::Bidi bidiFlags, const Typeface* typeface,
|
||||
const uint16_t* buf, size_t bufSize, minikin::MinikinRect* out);
|
||||
|
||||
static float measureText(const Paint* paint, minikin::Bidi bidiFlags,
|
||||
const Typeface* typeface, const uint16_t* buf,
|
||||
size_t start, size_t count, size_t bufSize,
|
||||
|
||||
@@ -356,18 +356,13 @@ namespace PaintGlue {
|
||||
}
|
||||
|
||||
static void doTextBounds(JNIEnv* env, const jchar* text, int count, jobject bounds,
|
||||
const Paint& paint, const Typeface* typeface, jint bidiFlags) {
|
||||
const Paint& paint, const Typeface* typeface, jint bidiFlagsInt) {
|
||||
SkRect r;
|
||||
SkIRect ir;
|
||||
|
||||
minikin::Layout layout = MinikinUtils::doLayout(&paint,
|
||||
static_cast<minikin::Bidi>(bidiFlags), typeface,
|
||||
text, count, // text buffer
|
||||
0, count, // draw range
|
||||
0, count, // context range
|
||||
nullptr);
|
||||
minikin::MinikinRect rect;
|
||||
layout.getBounds(&rect);
|
||||
minikin::Bidi bidiFlags = static_cast<minikin::Bidi>(bidiFlagsInt);
|
||||
MinikinUtils::getBounds(&paint, bidiFlags, typeface, text, count, &rect);
|
||||
r.fLeft = rect.mLeft;
|
||||
r.fTop = rect.mTop;
|
||||
r.fRight = rect.mRight;
|
||||
|
||||
Reference in New Issue
Block a user