Fix gms placing text in bounds.
In the operation of taking the bounds of (horizontal text) and then drawing the text within those bounds it is necessary to draw the text at the origin of the bounds and not at the left edge of the bounds. Change-Id: I712e1713ca5e0be929b11f526f224141a5310cc2 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/319776 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
8ff24492e2
commit
12857d405c
@ -46,7 +46,6 @@ protected:
|
||||
const char* text = "able was I ere I saw elba";
|
||||
font.setSubpixel(true);
|
||||
font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
|
||||
// If we use SkTextBlob::MakeFromText, we get very different positioning ... why?
|
||||
ToolUtils::add_to_text_blob(&builder, text, font, 0, 0);
|
||||
fBlob = builder.make();
|
||||
}
|
||||
@ -68,7 +67,7 @@ protected:
|
||||
canvas->save();
|
||||
canvas->translate(x, y);
|
||||
canvas->rotate(360.0f / SK_ARRAY_COUNT(colors) * i);
|
||||
canvas->translate(-fBlob->bounds().width() / 2.0f + 0.5f, 0);
|
||||
canvas->translate(-fBlob->bounds().width() / 2.0f - fBlob->bounds().left() + 0.5f, 0);
|
||||
|
||||
SkPaint textPaint;
|
||||
textPaint.setColor(colors[i]);
|
||||
|
@ -95,19 +95,17 @@ protected:
|
||||
fFont.setSize(fPtSizes[i]);
|
||||
|
||||
fFont.measureText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8, &r);
|
||||
// safeRect is set of x,y positions where we can draw the string without hitting
|
||||
// the GM's border.
|
||||
// The set of x,y offsets which place the bounding box inside the GM's border.
|
||||
SkRect safeRect = SkRect::MakeLTRB(-r.fLeft, -r.fTop, w - r.fRight, h - r.fBottom);
|
||||
if (safeRect.isEmpty()) {
|
||||
// If we don't fit then just don't worry about how we get cliped to the device
|
||||
// border.
|
||||
// If the bounds don't fit then allow any offset in the GM's border.
|
||||
safeRect = SkRect::MakeWH(w, h);
|
||||
}
|
||||
fPositions[i].fX = random.nextRangeScalar(safeRect.fLeft, safeRect.fRight);
|
||||
fPositions[i].fY = random.nextRangeScalar(safeRect.fTop, safeRect.fBottom);
|
||||
fOffsets[i].fX = random.nextRangeScalar(safeRect.fLeft, safeRect.fRight);
|
||||
fOffsets[i].fY = random.nextRangeScalar(safeRect.fTop, safeRect.fBottom);
|
||||
|
||||
fClipRects[i] = r;
|
||||
fClipRects[i].offset(fPositions[i].fX, fPositions[i].fY);
|
||||
fClipRects[i].offset(fOffsets[i].fX, fOffsets[i].fY);
|
||||
fClipRects[i].outset(2.f, 2.f);
|
||||
|
||||
if (fEffectiveClip) {
|
||||
@ -124,7 +122,7 @@ protected:
|
||||
|
||||
canvas->save();
|
||||
canvas->clipRect(fClipRects[i]);
|
||||
canvas->translate(fPositions[i].fX, fPositions[i].fY);
|
||||
canvas->translate(fOffsets[i].fX, fOffsets[i].fY);
|
||||
canvas->drawSimpleText(fStrings[i].c_str(), fStrings[i].size(), SkTextEncoding::kUTF8,
|
||||
0, 0, fFont, fPaint);
|
||||
canvas->restore();
|
||||
@ -160,7 +158,7 @@ private:
|
||||
SkColor fColors[kCnt];
|
||||
SkScalar fPtSizes[kCnt];
|
||||
int fTypefaceIndices[kCnt];
|
||||
SkPoint fPositions[kCnt];
|
||||
SkPoint fOffsets[kCnt];
|
||||
SkRect fClipRects[kCnt];
|
||||
|
||||
using INHERITED = skiagm::GM;
|
||||
|
Loading…
Reference in New Issue
Block a user