add containsText() api

git-svn-id: http://skia.googlecode.com/svn/trunk@487 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@android.com 2010-02-05 17:12:32 +00:00
parent bc7d2fb5be
commit a5dcaf6fd8
2 changed files with 59 additions and 0 deletions

View File

@ -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.

View File

@ -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) {