Fix empty run handling in trivial shaper iterators
When the text run is of zero length the iterator starts at the end. The trivial itereators did not handle this case. Change-Id: Id41304500e33d821874f56ab20085cbc4b2d9b0b Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252857 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com>
This commit is contained in:
parent
91a1ec34bf
commit
0f3a26dd18
@ -75,8 +75,8 @@ private:
|
||||
class TrivialRunIterator : public RunIteratorSubclass {
|
||||
public:
|
||||
static_assert(std::is_base_of<RunIterator, RunIteratorSubclass>::value, "");
|
||||
TrivialRunIterator(size_t utf8Bytes) : fEnd(utf8Bytes), fAtEnd(false) {}
|
||||
void consume() override { fAtEnd = true; }
|
||||
TrivialRunIterator(size_t utf8Bytes) : fEnd(utf8Bytes), fAtEnd(fEnd == 0) {}
|
||||
void consume() override { SkASSERT(!fAtEnd); fAtEnd = true; }
|
||||
size_t endOfCurrentRun() const override { return fAtEnd ? fEnd : 0; }
|
||||
bool atEnd() const override { return fAtEnd; }
|
||||
private:
|
||||
|
@ -59,24 +59,17 @@ struct RunHandler final : public SkShaper::RunHandler {
|
||||
}
|
||||
void commitLine() override {}
|
||||
};
|
||||
} // namespace
|
||||
|
||||
static void cluster_test(skiatest::Reporter* reporter, const char* resource) {
|
||||
void shaper_test(skiatest::Reporter* reporter, const char* name, SkData* data) {
|
||||
auto shaper = SkShaper::Make();
|
||||
if (!shaper) {
|
||||
ERRORF(reporter, "Could not create shaper.");
|
||||
return;
|
||||
}
|
||||
|
||||
auto data = GetResourceAsData(resource);
|
||||
if (!data) {
|
||||
ERRORF(reporter, "Could not get resource %s.", resource);
|
||||
return;
|
||||
}
|
||||
|
||||
constexpr float kWidth = 400;
|
||||
SkFont font(SkTypeface::MakeDefault());
|
||||
RunHandler rh(resource, reporter);
|
||||
RunHandler rh(name, reporter);
|
||||
shaper->shape((const char*)data->data(), data->size(), font, true, kWidth, &rh);
|
||||
|
||||
constexpr SkFourByteTag latn = SkSetFourByteTag('l','a','t','n');
|
||||
@ -88,6 +81,20 @@ static void cluster_test(skiatest::Reporter* reporter, const char* resource) {
|
||||
fontIterator, bidiIterator, scriptIterator, languageIterator, kWidth, &rh);
|
||||
}
|
||||
|
||||
void cluster_test(skiatest::Reporter* reporter, const char* resource) {
|
||||
auto data = GetResourceAsData(resource);
|
||||
if (!data) {
|
||||
ERRORF(reporter, "Could not get resource %s.", resource);
|
||||
return;
|
||||
}
|
||||
|
||||
shaper_test(reporter, resource, data.get());
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
DEF_TEST(Shaper_cluster_empty, r) { shaper_test(r, "empty", SkData::MakeEmpty().get()); }
|
||||
|
||||
#define SHAPER_TEST(X) DEF_TEST(Shaper_cluster_ ## X, r) { cluster_test(r, "text/" #X ".txt"); }
|
||||
SHAPER_TEST(arabic)
|
||||
SHAPER_TEST(armenian)
|
||||
|
Loading…
Reference in New Issue
Block a user