expose SkFont as public way to use TextBlobBuilder
Step 1 of many to (eventually) use SkFont to make blobs, and not paint.
Bug: skia:2664
Change-Id: Iaa0682f9d947e18afa96b448519f2f60ffe104cc
Reviewed-on: https://skia-review.googlesource.com/c/165521
Auto-Submit: Mike Reed <reed@google.com>
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Mike Reed <reed@google.com>
diff --git a/include/core/SkTextBlob.h b/include/core/SkTextBlob.h
index f789a6a..36a3671 100644
--- a/include/core/SkTextBlob.h
+++ b/include/core/SkTextBlob.h
@@ -19,12 +19,15 @@
#define SkTextBlob_DEFINED
#include "../private/SkTemplates.h"
+#include "SkFont.h"
#include "SkPaint.h"
#include "SkString.h"
#include "SkRefCnt.h"
#include <atomic>
+#define SK_SUPPORT_LEGACY_TEXTBLOBBUILD_WITH_PAINT
+
struct SkSerialProcs;
struct SkDeserialProcs;
@@ -50,41 +53,41 @@
*/
uint32_t uniqueID() const { return fUniqueID; }
- /** Creates SkTextBlob with a single run. text meaning depends on SkPaint::TextEncoding;
- by default, text is encoded as UTF-8.
+ /** Creates SkTextBlob with a single run.
- paint contains attributes used to define the run text:
+ font contains attributes used to define the run text:
SkTypeface, SkPaint text size, SkPaint text scale x,
- SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
- SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
- and SkPaint subpixel text.
+ SkFont text skew x, SkPaint::Align, SkFont::Hinting, anti-alias, SkFont fake bold,
+ SkFont font embedded bitmaps, SkFont full hinting spacing, LCD text, SkFont linear text,
+ and SkFont subpixel text.
@param text character code points or glyphs drawn
@param byteLength byte length of text array
- @param paint text size, typeface, text scale, and so on, used to draw
+ @param font text size, typeface, text scale, and so on, used to draw
@return SkTextBlob constructed from one run
*/
- static sk_sp<SkTextBlob> MakeFromText(
- const void* text, size_t byteLength, const SkPaint& paint);
+ static sk_sp<SkTextBlob> MakeFromText(const void* text, size_t byteLength, const SkFont& font,
+ SkPaint::TextEncoding = SkPaint::kUTF8_TextEncoding);
/** Creates SkTextBlob with a single run. string meaning depends on SkPaint::TextEncoding;
by default, string is encoded as UTF-8.
- paint contains SkPaint::FontMetrics used to define the run text:
+ font contains attributes used to define the run text:
SkTypeface, SkPaint text size, SkPaint text scale x,
- SkPaint text skew x, SkPaint::Align, SkPaint::Hinting, anti-alias, SkPaint fake bold,
- SkPaint font embedded bitmaps, SkPaint full hinting spacing, LCD text, SkPaint linear text,
- and SkPaint subpixel text.
+ SkFont text skew x, SkPaint::Align, SkFont::Hinting, anti-alias, SkFont fake bold,
+ SkFont font embedded bitmaps, SkFont full hinting spacing, LCD text, SkFont linear text,
+ and SkFont subpixel text.
@param string character code points or glyphs drawn
- @param paint text size, typeface, text scale, and so on, used to draw
+ @param font text size, typeface, text scale, and so on, used to draw
@return SkTextBlob constructed from one run
*/
- static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkPaint& paint) {
+ static sk_sp<SkTextBlob> MakeFromString(const char* string, const SkFont& font,
+ SkPaint::TextEncoding encoding = SkPaint::kUTF8_TextEncoding) {
if (!string) {
return nullptr;
}
- return MakeFromText(string, strlen(string), paint);
+ return MakeFromText(string, strlen(string), font, encoding);
}
/** Writes data to allow later reconstruction of SkTextBlob. memory points to storage
@@ -220,6 +223,7 @@
uint32_t* clusters; //!< reserved for future use
};
+#ifdef SK_SUPPORT_LEGACY_TEXTBLOBBUILD_WITH_PAINT
/** Returns run with storage for glyphs. Caller must write count glyphs to
RunBuffer.glyphs() before next call to FontBlobBuilder.
@@ -308,6 +312,14 @@
const SkRect* bounds = nullptr) {
return this->allocRunTextPos(font, count, 0, SkString(), bounds);
}
+#endif
+
+ const RunBuffer& allocRun(const SkFont& font, int count, SkScalar x, SkScalar y,
+ const SkRect* bounds = nullptr);
+ const RunBuffer& allocRunPosH(const SkFont& font, int count, SkScalar y,
+ const SkRect* bounds = nullptr);
+ const RunBuffer& allocRunPos(const SkFont& font, int count,
+ const SkRect* bounds = nullptr);
private:
const RunBuffer& allocRunText(const SkPaint& font,