diff options
author | Hal Canary <halcanary@google.com> | 2018-07-25 16:52:48 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-31 20:11:19 +0000 |
commit | f107a2fd014cd39c489060f2cd1b99cd49c7d0be (patch) | |
tree | 5c324821344901869203bbe055be8d3f69f696cb /src/core/SkFindAndPlaceGlyph.h | |
parent | 1935aa3d27cd4ed4aef2dc04360f247a541d4b00 (diff) |
SkUTF
Create new header and namespace, `SkUTF` where we are putting all of our
robust, well documented UTF-8, UTF-16, and UTF-32 functions:
`SkUTF::{Count,Next,To}UTF{8,16,32}()`.
SkUTF.h and SkUTF.cpp do not depend on the rest of Skia and are suitable
for re-use in other modules.
Some of the old UTF-{8,16} functions still live in SkUtils.h; their use
will be phased out in future CLs.
Also added more unit testing and cleaned up old tests.
Removed functions that were unused outside of tests or used only once.
Change-Id: Iaa59b8705abccf9c4ba082f855da368a0bad8380
Reviewed-on: https://skia-review.googlesource.com/143306
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'src/core/SkFindAndPlaceGlyph.h')
-rw-r--r-- | src/core/SkFindAndPlaceGlyph.h | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/core/SkFindAndPlaceGlyph.h b/src/core/SkFindAndPlaceGlyph.h index f602e8d931..74fa516910 100644 --- a/src/core/SkFindAndPlaceGlyph.h +++ b/src/core/SkFindAndPlaceGlyph.h @@ -147,7 +147,7 @@ private: private: SkUnichar nextUnichar(const char** text, const char* stop) override { - return SkUTF8_NextUnichar(text, stop); + return SkUTF::NextUTF8(text, stop); } }; @@ -157,7 +157,7 @@ private: private: SkUnichar nextUnichar(const char** text, const char* stop) override { - return SkUTF16_NextUnichar((const uint16_t**)text, (const uint16_t*)stop); + return SkUTF::NextUTF16((const uint16_t**)text, (const uint16_t*)stop); } }; @@ -167,10 +167,7 @@ private: private: SkUnichar nextUnichar(const char** text, const char* stop) override { - const int32_t* ptr = *(const int32_t**)text; - SkUnichar uni = *ptr++; - *text = (const char*)ptr; - return uni; + return SkUTF::NextUTF32((const int32_t**)text, (const int32_t*)stop); } }; @@ -181,19 +178,24 @@ private: SkASSERT(cache != nullptr); } - const SkGlyph& lookupGlyph(const char** text, const char*) override { - return fCache->getGlyphIDMetrics(nextGlyphId(text)); + const SkGlyph& lookupGlyph(const char** text, const char* stop) override { + return fCache->getGlyphIDMetrics(nextGlyphId(text, stop)); } - const SkGlyph& lookupGlyphXY(const char** text, const char*, + const SkGlyph& lookupGlyphXY(const char** text, const char* stop, SkFixed x, SkFixed y) override { - return fCache->getGlyphIDMetrics(nextGlyphId(text), x, y); + return fCache->getGlyphIDMetrics(nextGlyphId(text, stop), x, y); } private: - uint16_t nextGlyphId(const char** text) { + uint16_t nextGlyphId(const char** text, const char* stop) { SkASSERT(text != nullptr); const uint16_t* ptr = *(const uint16_t**)text; + SkASSERT(ptr); + if (ptr + 1 > (const uint16_t*)stop) { + *text = stop; + return 0; + } uint16_t glyphID = *ptr; ptr += 1; *text = (const char*)ptr; |