SkShaper->SkFont
Change-Id: I6293f08c426650e3d1da8b2f94a81f7b0a65e8a3
Reviewed-on: https://skia-review.googlesource.com/c/172969
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Hal Canary <halcanary@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/modules/skshaper/include/SkShaper.h b/modules/skshaper/include/SkShaper.h
index 190a4d8..92c236c 100644
--- a/modules/skshaper/include/SkShaper.h
+++ b/modules/skshaper/include/SkShaper.h
@@ -13,7 +13,7 @@
#include "SkPoint.h"
#include "SkTypeface.h"
-class SkPaint;
+class SkFont;
class SkTextBlobBuilder;
/**
@@ -29,12 +29,12 @@
bool good() const;
SkPoint shape(SkTextBlobBuilder* dest,
- const SkPaint& srcPaint,
- const char* utf8text,
- size_t textBytes,
- bool leftToRight,
- SkPoint point,
- SkScalar width) const;
+ const SkFont& srcPaint,
+ const char* utf8text,
+ size_t textBytes,
+ bool leftToRight,
+ SkPoint point,
+ SkScalar width) const;
private:
SkShaper(const SkShaper&) = delete;
diff --git a/modules/skshaper/src/SkShaper_harfbuzz.cpp b/modules/skshaper/src/SkShaper_harfbuzz.cpp
index 8c15e33..ced56ee 100644
--- a/modules/skshaper/src/SkShaper_harfbuzz.cpp
+++ b/modules/skshaper/src/SkShaper_harfbuzz.cpp
@@ -10,7 +10,7 @@
#include "SkLoadICU.h"
#include "SkMalloc.h"
#include "SkOnce.h"
-#include "SkPaint.h"
+#include "SkFont.h"
#include "SkPoint.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
@@ -396,7 +396,7 @@
bool fHasVisual;
};
struct ShapedRun {
- ShapedRun(const char* utf8Start, const char* utf8End, int numGlyphs, const SkPaint& paint,
+ ShapedRun(const char* utf8Start, const char* utf8End, int numGlyphs, const SkFont& paint,
UBiDiLevel level, std::unique_ptr<ShapedGlyph[]> glyphs)
: fUtf8Start(utf8Start), fUtf8End(utf8End), fNumGlyphs(numGlyphs), fPaint(paint)
, fLevel(level), fGlyphs(std::move(glyphs))
@@ -405,7 +405,7 @@
const char* fUtf8Start;
const char* fUtf8End;
int fNumGlyphs;
- SkPaint fPaint;
+ SkFont fPaint;
UBiDiLevel fLevel;
std::unique_ptr<ShapedGlyph[]> fGlyphs;
};
@@ -416,7 +416,9 @@
static void append(SkTextBlobBuilder* b, const ShapedRun& run, int start, int end, SkPoint* p) {
unsigned len = end - start;
- auto runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(b, run.fPaint, len,
+ SkPaint tmpPaint;
+ run.fPaint.LEGACY_applyToPaint(&tmpPaint);
+ auto runBuffer = SkTextBlobBuilderPriv::AllocRunTextPos(b, tmpPaint, len,
run.fUtf8End - run.fUtf8Start, SkString());
memcpy(runBuffer.utf8text, run.fUtf8Start, run.fUtf8End - run.fUtf8Start);
@@ -517,7 +519,7 @@
}
SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
- const SkPaint& srcPaint,
+ const SkFont& srcPaint,
const char* utf8,
size_t utf8Bytes,
bool leftToRight,
@@ -633,15 +635,14 @@
return point;
}
- SkPaint paint(srcPaint);
- paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ SkFont paint(srcPaint);
paint.setTypeface(sk_ref_sp(font->currentTypeface()));
ShapedRun& run = runs.emplace_back(utf8Start, utf8End, len, paint, bidi->currentLevel(),
std::unique_ptr<ShapedGlyph[]>(new ShapedGlyph[len]));
int scaleX, scaleY;
hb_font_get_scale(font->currentHBFont(), &scaleX, &scaleY);
- double textSizeY = run.fPaint.getTextSize() / scaleY;
- double textSizeX = run.fPaint.getTextSize() / scaleX * run.fPaint.getTextScaleX();
+ double textSizeY = run.fPaint.getSize() / scaleY;
+ double textSizeX = run.fPaint.getSize() / scaleX * run.fPaint.getScaleX();
for (unsigned i = 0; i < len; i++) {
ShapedGlyph& glyph = run.fGlyphs[i];
glyph.fID = info[i].codepoint;
@@ -731,7 +732,7 @@
if (previousRunIndex != runIndex) {
SkFontMetrics metrics;
- runs[runIndex].fPaint.getFontMetrics(&metrics);
+ runs[runIndex].fPaint.getMetrics(&metrics);
maxAscent = SkTMin(maxAscent, metrics.fAscent);
maxDescent = SkTMax(maxDescent, metrics.fDescent);
maxLeading = SkTMax(maxLeading, metrics.fLeading);
diff --git a/modules/skshaper/src/SkShaper_primitive.cpp b/modules/skshaper/src/SkShaper_primitive.cpp
index 3f45a11..1dd6da6 100644
--- a/modules/skshaper/src/SkShaper_primitive.cpp
+++ b/modules/skshaper/src/SkShaper_primitive.cpp
@@ -33,7 +33,7 @@
}
SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
- const SkPaint& srcPaint,
+ const SkFont& srcPaint,
const char* utf8text,
size_t textBytes,
bool leftToRight,
@@ -41,21 +41,21 @@
SkScalar width) const {
sk_ignore_unused_variable(leftToRight);
- SkPaint paint(srcPaint);
+ SkFont paint(srcPaint);
paint.setTypeface(fImpl->fTypeface);
- paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
- int glyphCount = paint.countText(utf8text, textBytes);
+ int glyphCount = paint.countText(utf8text, textBytes, SkTextEncoding::kUTF8);
if (glyphCount <= 0) {
return point;
}
SkRect bounds;
SkFontMetrics metrics;
- paint.getFontMetrics(&metrics);
+ paint.getMetrics(&metrics);
point.fY -= metrics.fAscent;
- (void)paint.measureText(utf8text, textBytes, &bounds);
- paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding);
+ (void)paint.measureText(utf8text, textBytes, SkTextEncoding::kUTF8, &bounds);
+ SkPaint tmpPaint;
+ paint.LEGACY_applyToPaint(&tmpPaint);
const SkTextBlobBuilder::RunBuffer& runBuffer =
- builder->allocRunTextPosH(paint, glyphCount, point.y(), textBytes, SkString(), &bounds);
+ builder->allocRunTextPosH(tmpPaint, glyphCount, point.y(), textBytes, SkString(), &bounds);
memcpy(runBuffer.utf8text, utf8text, textBytes);
const char* txtPtr = utf8text;
for (int i = 0; i < glyphCount; ++i) {
@@ -64,9 +64,10 @@
txtPtr += utf8_lead_byte_to_count(txtPtr);
SkASSERT(txtPtr <= utf8text + textBytes);
}
- paint.setTextEncoding(SkPaint::kUTF8_TextEncoding);
- (void)paint.textToGlyphs(utf8text, textBytes, runBuffer.glyphs);
- (void)paint.getTextWidths(utf8text, textBytes, runBuffer.pos);
+ (void)paint.textToGlyphs(utf8text, textBytes, SkTextEncoding::kUTF8,
+ runBuffer.glyphs, glyphCount);
+ // replace with getPos()?
+ (void)paint.getWidths(runBuffer.glyphs, glyphCount, runBuffer.pos);
SkScalar x = point.x();
for (int i = 0; i < glyphCount; ++i) {
SkScalar w = runBuffer.pos[i];
diff --git a/samplecode/SampleTextBox.cpp b/samplecode/SampleTextBox.cpp
index 1c698ac..8762391 100644
--- a/samplecode/SampleTextBox.cpp
+++ b/samplecode/SampleTextBox.cpp
@@ -83,7 +83,8 @@
for (int i = 9; i < 24; i += 2) {
SkTextBlobBuilder builder;
paint.setTextSize(SkIntToScalar(i));
- SkPoint end = shaper.shape(&builder, paint, gText, strlen(gText), true,
+ SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
+ SkPoint end = shaper.shape(&builder, font, gText, strlen(gText), true,
{ margin, margin }, w - margin);
canvas->drawTextBlob(builder.make(), 0, 0, paint);
diff --git a/src/utils/SkLua.cpp b/src/utils/SkLua.cpp
index c5a6617..074493c 100644
--- a/src/utils/SkLua.cpp
+++ b/src/utils/SkLua.cpp
@@ -1922,8 +1922,9 @@
SkShaper shaper(nullptr);
+ SkFont font = SkFont::LEGACY_ExtractFromPaint(paint);
SkTextBlobBuilder builder;
- SkPoint end = shaper.shape(&builder, paint, text, strlen(text), true,
+ SkPoint end = shaper.shape(&builder, font, text, strlen(text), true,
{ bounds.left(), bounds.top() }, bounds.width());
push_ref<SkTextBlob>(L, builder.make());
diff --git a/tools/using_skia_and_harfbuzz.cpp b/tools/using_skia_and_harfbuzz.cpp
index f4513c4..ed2b2c7 100644
--- a/tools/using_skia_and_harfbuzz.cpp
+++ b/tools/using_skia_and_harfbuzz.cpp
@@ -134,12 +134,13 @@
glyph_paint.setColor(SK_ColorBLACK);
glyph_paint.setFlags(SkPaint::kAntiAlias_Flag |
SkPaint::kSubpixelText_Flag);
- glyph_paint.setTextSize(SkDoubleToScalar(config->font_size.value));
+ font.setEdging(SkFont::Edging::kSubpixelAntiAlias);
+ font.setSize(SkDoubleToScalar(config->font_size.value));
}
void WriteLine(const SkShaper& shaper, const char *text, size_t textBytes) {
SkTextBlobBuilder textBlobBuilder;
- SkPoint endPoint = shaper.shape(&textBlobBuilder, glyph_paint, text, textBytes, true,
+ SkPoint endPoint = shaper.shape(&textBlobBuilder, font, text, textBytes, true,
SkPoint{0, 0},
config->page_width.value - 2*config->left_margin.value);
sk_sp<const SkTextBlob> blob = textBlobBuilder.make();
@@ -171,6 +172,7 @@
SkCanvas *pageCanvas;
SkPaint white_paint;
SkPaint glyph_paint;
+ SkFont font;
double current_x;
double current_y;
};