diff options
author | 2010-02-05 17:12:32 +0000 | |
---|---|---|
committer | 2010-02-05 17:12:32 +0000 | |
commit | a5dcaf6fd8115fb9c6028ca4e9848b968375abcd (patch) | |
tree | 2e51de8fa63aa7da50599207397508433f53e1bc | |
parent | bc7d2fb5be746f6e0d9bd60c9e181eec20fe31ea (diff) |
add containsText() api
git-svn-id: http://skia.googlecode.com/svn/trunk@487 2bbb7eff-a529-9590-31e7-b0007b416f81
-rw-r--r-- | include/core/SkPaint.h | 9 | ||||
-rw-r--r-- | src/core/SkPaint.cpp | 50 |
2 files changed, 59 insertions, 0 deletions
diff --git a/include/core/SkPaint.h b/include/core/SkPaint.h index 86f174a524..5fef527f65 100644 --- a/include/core/SkPaint.h +++ b/include/core/SkPaint.h @@ -708,6 +708,15 @@ public: int textToGlyphs(const void* text, size_t byteLength, uint16_t glyphs[]) const; + /** Return true if all of the specified text has a corresponding non-zero + glyph ID. If any of the code-points in the text are not supported in + the typeface (i.e. the glyph ID would be zero), then return false. + + If the text encoding for the paint is kGlyph_TextEncoding, then this + returns true if all of the specified glyph IDs are non-zero. + */ + bool containsText(const void* text, size_t byteLength) const; + /** Convert the glyph array into Unichars. Unconvertable glyphs are mapped to zero. Note: this does not look at the text-encoding setting in the paint, only at the typeface. diff --git a/src/core/SkPaint.cpp b/src/core/SkPaint.cpp index c918ff6950..0261ca68d4 100644 --- a/src/core/SkPaint.cpp +++ b/src/core/SkPaint.cpp @@ -381,6 +381,56 @@ int SkPaint::textToGlyphs(const void* textData, size_t byteLength, return gptr - glyphs; } +bool SkPaint::containsText(const void* textData, size_t byteLength) const { + if (0 == byteLength) { + return true; + } + + SkASSERT(textData != NULL); + + // handle this encoding before the setup for the glyphcache + if (this->getTextEncoding() == kGlyphID_TextEncoding) { + const uint16_t* glyphID = static_cast<const uint16_t*>(textData); + size_t count = byteLength >> 1; + for (size_t i = 0; i < count; i++) { + if (0 == glyphID[i]) { + return false; + } + } + return true; + } + + SkAutoGlyphCache autoCache(*this, NULL); + SkGlyphCache* cache = autoCache.getCache(); + + switch (this->getTextEncoding()) { + case SkPaint::kUTF8_TextEncoding: { + const char* text = static_cast<const char*>(textData); + const char* stop = text + byteLength; + while (text < stop) { + if (0 == cache->unicharToGlyph(SkUTF8_NextUnichar(&text))) { + return false; + } + } + break; + } + case SkPaint::kUTF16_TextEncoding: { + const uint16_t* text = static_cast<const uint16_t*>(textData); + const uint16_t* stop = text + (byteLength >> 1); + while (text < stop) { + if (0 == cache->unicharToGlyph(SkUTF16_NextUnichar(&text))) { + return false; + } + } + break; + } + default: + SkASSERT(!"unknown text encoding"); + return false; + } + return true; +} + void SkPaint::glyphsToUnichars(const uint16_t glyphs[], int count, SkUnichar textData[]) const { if (count <= 0) { |