Make TextLine::fEllipsis unique_ptr.

Clarify and simplify ownership of the ellipsis.

Change-Id: I3f4567d2a16b51ecc6406d872019c4665c49fe50
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/290536
Reviewed-by: Julia Lavrova <jlavrova@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
Ben Wagner 2020-05-18 10:52:23 -04:00 committed by Skia Commit-Bot
parent e73e2fc356
commit 0b13ceceaa
2 changed files with 13 additions and 9 deletions

View File

@ -489,7 +489,7 @@ void TextLine::createEllipsis(SkScalar maxWidth, const SkString& ellipsis, bool)
auto attachEllipsis = [&](const Cluster* cluster){
// Shape the ellipsis
Run* run = shapeEllipsis(ellipsis, cluster->run());
std::unique_ptr<Run> run = shapeEllipsis(ellipsis, cluster->run());
run->fClusterStart = cluster->textRange().start;
run->setMaster(fMaster);
@ -500,7 +500,7 @@ void TextLine::createEllipsis(SkScalar maxWidth, const SkString& ellipsis, bool)
return false;
}
fEllipsis = std::make_shared<Run>(*run);
fEllipsis = std::move(run);
fEllipsis->shift(width, 0);
fAdvance.fX = width;
return true;
@ -517,13 +517,14 @@ void TextLine::createEllipsis(SkScalar maxWidth, const SkString& ellipsis, bool)
}
}
Run* TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
std::unique_ptr<Run> TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
class ShapeHandler final : public SkShaper::RunHandler {
public:
ShapeHandler(SkScalar lineHeight, const SkString& ellipsis)
: fRun(nullptr), fLineHeight(lineHeight), fEllipsis(ellipsis) {}
Run* run() { return fRun; }
Run* run() & { return fRun.get(); }
std::unique_ptr<Run> run() && { return std::move(fRun); }
private:
void beginLine() override {}
@ -533,7 +534,8 @@ Run* TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
void commitRunInfo() override {}
Buffer runBuffer(const RunInfo& info) override {
fRun = new Run(nullptr, info, 0, fLineHeight, 0, 0);
SkASSERT(!fRun);
fRun = std::unique_ptr<Run>(new Run(nullptr, info, 0, fLineHeight, 0, 0));
return fRun->newRunBuffer();
}
@ -546,7 +548,7 @@ Run* TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
void commitLine() override {}
Run* fRun;
std::unique_ptr<Run> fRun;
SkScalar fLineHeight;
SkString fEllipsis;
};
@ -558,7 +560,7 @@ Run* TextLine::shapeEllipsis(const SkString& ellipsis, Run* run) {
std::numeric_limits<SkScalar>::max(), &handler);
handler.run()->fTextRange = TextRange(0, ellipsis.size());
handler.run()->fMaster = fMaster;
return handler.run();
return std::move(handler).run();
}
TextLine::ClipContext TextLine::measureTextInsideOneRun(TextRange textRange,

View File

@ -11,6 +11,8 @@
#include "modules/skparagraph/src/Run.h"
#include "src/core/SkSpan.h"
#include <memory>
namespace skia {
namespace textlayout {
@ -108,7 +110,7 @@ public:
private:
Run* shapeEllipsis(const SkString& ellipsis, Run* run);
std::unique_ptr<Run> shapeEllipsis(const SkString& ellipsis, Run* run);
void justify(SkScalar maxWidth);
void paintText(SkCanvas* canvas, TextRange textRange, const TextStyle& style, const ClipContext& context) const;
@ -130,7 +132,7 @@ private:
SkVector fOffset; // Text position
SkScalar fShift; // Let right
SkScalar fWidthWithSpaces;
std::shared_ptr<Run> fEllipsis; // In case the line ends with the ellipsis
std::unique_ptr<Run> fEllipsis; // In case the line ends with the ellipsis
InternalLineMetrics fSizes; // Line metrics as a max of all run metrics and struts
InternalLineMetrics fMaxRunMetrics; // No struts - need it for GetRectForRange(max height)
bool fHasBackground;