templatize drawString

Bug: skia:
Change-Id: Icd1104bfb88e324458d89e40633ddc01f131c4e9
Reviewed-on: https://skia-review.googlesource.com/c/189165
Commit-Queue: Mike Reed <reed@google.com>
Auto-Submit: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
This commit is contained in:
Mike Reed 2019-02-04 11:22:54 -05:00 committed by Skia Commit-Bot
parent 950dfd7cc2
commit 9d895824c6
2 changed files with 33 additions and 54 deletions

View File

@ -1823,17 +1823,8 @@ public:
/** Draws text, with origin at (x, y), using clip, SkMatrix, SkFont font,
and SkPaint paint.
When encoding is SkTextEncoding::kUTF8, SkTextEncoding::kUTF16, or
SkTextEncoding::kUTF32, this function uses the default
character-to-glyph mapping from the SkTypeface in font. It does not
perform typeface fallback for characters not found in the SkTypeface.
It does not perform kerning or other complex shaping; glyphs are
positioned based on their default advances.
Text meaning depends on SkTextEncoding.
Text size is affected by SkMatrix and SkFont text size. Default text
size is 12 point.
Does not perform typeface fallback for characters not found in the SkTypeface.
Glyphs are positioned based on their default advances.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By
@ -1852,64 +1843,51 @@ public:
/** Experimental.
Draws null terminated string, with origin at (x, y), using clip, SkMatrix,
SkFont font, and SkPaint paint.
Helper for drawSimpleText that takes a string class.
Assumes string is encoded as UTF-8.
This function uses the default character-to-glyph mapping from the
SkTypeface in font. It does not perform typeface fallback for
characters not found in the SkTypeface. It does not perform kerning;
glyphs are positioned based on their default advances.
String str is encoded as UTF-8.
Text size is affected by SkMatrix and font text size. Default text
size is 12 point.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By
default, draws filled black glyphs.
@param str character code points drawn,
ending with a char value of zero
@param str string of character code points
@param x start of string on x-axis
@param y start of string on y-axis
@param font typeface, text size and so, used to describe the text
@param paint blend, color, and so on, used to draw
*/
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont& font,
const SkPaint& paint) {
this->drawSimpleText(str, strlen(str), kUTF8_SkTextEncoding, x, y, font, paint);
template <typename T> void drawString(const T& str, SkScalar x, SkScalar y, const SkFont& font,
const SkPaint& paint) {
this->drawSimpleText(str.data(), str.size(), kUTF8_SkTextEncoding, x, y, font, paint);
}
/** Experimental.
Helper for drawSimpleText that takes array of chars, treated as cstring (null-terminated).
Assumes text is encoded as UTF-8.
Draws SkString, with origin at (x, y), using clip, SkMatrix, SkFont font,
and SkPaint paint.
This function uses the default character-to-glyph mapping from the
SkTypeface in font. It does not perform typeface fallback for
characters not found in the SkTypeface. It does not perform kerning;
glyphs are positioned based on their default advances.
SkString str is encoded as UTF-8.
Text size is affected by SkMatrix and SkFont text size. Default text
size is 12 point.
All elements of paint: SkPathEffect, SkMaskFilter, SkShader,
SkColorFilter, SkImageFilter, and SkDrawLooper; apply to text. By
default, draws filled black glyphs.
@param str character code points drawn,
ending with a char value of zero
@param str string of character code points
@param x start of string on x-axis
@param y start of string on y-axis
@param font typeface, text size and so, used to describe the text
@param paint blend, color, and so on, used to draw
*/
void drawString(const SkString& str, SkScalar x, SkScalar y, const SkFont& font,
*/
template <size_t N> void drawString(const char (&cstr)[N], SkScalar x, SkScalar y,
const SkFont& font, const SkPaint& paint) {
// Even though we know the allocated size of the array, we cannot assume that the caller
// wants to use all of it, hence the call to strlen() and the dox mentioning that we
// require the string to be null-terminated.
this->drawSimpleText(cstr, strlen(cstr), kUTF8_SkTextEncoding, x, y, font, paint);
}
/** Experimental.
Helper for drawSimpleText that takes char*, treated as cstring (null-terminated)
Assumes text is encoded as UTF-8.
@param str string of character code points
@param x start of string on x-axis
@param y start of string on y-axis
@param font typeface, text size and so, used to describe the text
@param paint blend, color, and so on, used to draw
*/
void drawString(const char cstr[], SkScalar x, SkScalar y, const SkFont& font,
const SkPaint& paint) {
this->drawSimpleText(str.c_str(), str.size(), kUTF8_SkTextEncoding, x, y, font, paint);
this->drawSimpleText(cstr, strlen(cstr), kUTF8_SkTextEncoding, x, y, font, paint);
}
/** Draws SkTextBlob blob at (x, y), using clip, SkMatrix, and SkPaint paint.

View File

@ -132,6 +132,7 @@ public:
bool isEmpty() const { return 0 == fRec->fLength; }
size_t size() const { return (size_t) fRec->fLength; }
const char* data() const { return fRec->data(); }
const char* c_str() const { return fRec->data(); }
char operator[](size_t n) const { return this->c_str()[n]; }