/** Return the advances for the text. These will be vertical advances if
* isVerticalText() returns true.
*
* @param text the text
* @param byteLength number of bytes to of text
* @param widths If not null, returns the array of advances for
* the glyphs. If not NULL, must be at least a large
* as the number of unichars in the specified text.
* @param bounds If not null, returns the bounds for each of
* character, relative to (0, 0)
* @return the number of unichars in the specified text.
*/
int getTextWidths(const void* text, size_t byteLength, SkScalar widths[],
SkRect bounds[] = NULL) const;
可以获得给定字符串每个字符的宽度,保存于widths参数中。
使用:
textCount = strlen(text);
float widths[textCount];
paint->getTextWidths(text, textCount, widths, NULL);
还有这种:
textCount = wcslen(wtext);
textCount2 = textCount*4;
float widths[textCount2];
paint->getTextWidths(wtext, textCount2, widths, NULL);
//宽度值保存于widths中的前textCount位