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>
This commit is contained in:
parent
fc06f981e2
commit
2a1848d2aa
@ -13,7 +13,7 @@
|
||||
#include "SkPoint.h"
|
||||
#include "SkTypeface.h"
|
||||
|
||||
class SkPaint;
|
||||
class SkFont;
|
||||
class SkTextBlobBuilder;
|
||||
|
||||
/**
|
||||
@ -29,12 +29,12 @@ public:
|
||||
|
||||
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;
|
||||
|
@ -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 @@ struct ShapedGlyph {
|
||||
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 @@ struct ShapedRun {
|
||||
const char* fUtf8Start;
|
||||
const char* fUtf8End;
|
||||
int fNumGlyphs;
|
||||
SkPaint fPaint;
|
||||
SkFont fPaint;
|
||||
UBiDiLevel fLevel;
|
||||
std::unique_ptr<ShapedGlyph[]> fGlyphs;
|
||||
};
|
||||
@ -416,7 +416,9 @@ static constexpr bool is_LTR(UBiDiLevel level) {
|
||||
|
||||
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 @@ bool SkShaper::good() const {
|
||||
}
|
||||
|
||||
SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
const SkPaint& srcPaint,
|
||||
const SkFont& srcPaint,
|
||||
const char* utf8,
|
||||
size_t utf8Bytes,
|
||||
bool leftToRight,
|
||||
@ -633,15 +635,14 @@ SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
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 @@ SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
|
||||
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);
|
||||
|
@ -33,7 +33,7 @@ unsigned utf8_lead_byte_to_count(const char* ptr) {
|
||||
}
|
||||
|
||||
SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
const SkPaint& srcPaint,
|
||||
const SkFont& srcPaint,
|
||||
const char* utf8text,
|
||||
size_t textBytes,
|
||||
bool leftToRight,
|
||||
@ -41,21 +41,21 @@ SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
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 @@ SkPoint SkShaper::shape(SkTextBlobBuilder* builder,
|
||||
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];
|
||||
|
@ -83,7 +83,8 @@ protected:
|
||||
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);
|
||||
|
||||
|
@ -1922,8 +1922,9 @@ static int lsk_newTextBlob(lua_State* L) {
|
||||
|
||||
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());
|
||||
|
@ -134,12 +134,13 @@ public:
|
||||
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 @@ private:
|
||||
SkCanvas *pageCanvas;
|
||||
SkPaint white_paint;
|
||||
SkPaint glyph_paint;
|
||||
SkFont font;
|
||||
double current_x;
|
||||
double current_y;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user