Chromium Code Reviews| Index: tools/SkShaper.cpp |
| diff --git a/tools/SkShaper.cpp b/tools/SkShaper.cpp |
| index 44dd8fc7f1bbf0e72c47ffd2c469885ca045d144..93778762c1298e199858788b549dd603cc52adc2 100644 |
| --- a/tools/SkShaper.cpp |
| +++ b/tools/SkShaper.cpp |
| @@ -4,14 +4,15 @@ |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| */ |
| - |
| -#include <hb-ot.h> |
| - |
| #include "SkShaper.h" |
| #include "SkStream.h" |
| #include "SkTextBlob.h" |
| #include "SkTypeface.h" |
| +#ifdef SK_ENABLE_HARFBUZZ |
|
bungeman-skia
2016/08/02 21:38:36
I know it's a bit more work, but these two impleme
hal.canary
2016/08/02 23:00:45
Done.
|
| + |
| +#include <hb-ot.h> |
| + |
| static const int FONT_SIZE_SCALE = 512; |
| namespace { |
| @@ -116,11 +117,56 @@ SkScalar SkShaper::shape(SkTextBlobBuilder* builder, |
| for (unsigned i = 0; i < len; i++) { |
| runBuffer.glyphs[i] = info[i].codepoint; |
| reinterpret_cast<SkPoint*>(runBuffer.pos)[i] = |
| - SkPoint::Make(x + pos[i].x_offset * textSizeX, |
| - y - pos[i].y_offset * textSizeY); |
| + SkPoint::Make(SkDoubleToScalar(x + pos[i].x_offset * textSizeX), |
| + SkDoubleToScalar(y - pos[i].y_offset * textSizeY)); |
| x += pos[i].x_advance * textSizeX; |
| y += pos[i].y_advance * textSizeY; |
| } |
| hb_buffer_clear_contents(buffer); |
| return (SkScalar)x; |
| } |
| + |
| +#else // !SK_ENABLE_HARFBUZZ |
| + |
| +struct SkShaper::Impl { |
| + sk_sp<SkTypeface> fTypeface; |
| +}; |
| + |
| +SkShaper::SkShaper(sk_sp<SkTypeface> tf) : fImpl(new Impl) { |
| + fImpl->fTypeface = tf ? std::move(tf) : SkTypeface::MakeDefault(); |
| +} |
| + |
| +SkShaper::~SkShaper() {} |
| + |
| +bool SkShaper::good() const { return true; } |
| + |
| +SkScalar SkShaper::shape(SkTextBlobBuilder* builder, |
| + const SkPaint& srcPaint, |
| + const char* utf8text, |
| + size_t textBytes, |
| + SkPoint point) const { |
| + SkPaint paint(srcPaint); |
| + paint.setTypeface(fImpl->fTypeface); |
| + paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| + int glyphCount = paint.countText(utf8text, textBytes); |
| + if (glyphCount <= 0) { |
| + return 0; |
| + } |
| + SkRect bounds; |
| + (void)paint.measureText(utf8text, textBytes, &bounds); |
| + paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
| + const SkTextBlobBuilder::RunBuffer& runBuffer = builder->allocRunPosH( |
| + paint, glyphCount, point.y(), &bounds); |
| + paint.setTextEncoding(SkPaint::kUTF8_TextEncoding); |
| + (void)paint.textToGlyphs(utf8text, textBytes, runBuffer.glyphs); |
| + (void)paint.getTextWidths(utf8text, textBytes, runBuffer.pos); |
| + SkScalar x = point.x(); |
| + for (int i = 0; i < glyphCount; ++i) { |
| + SkScalar w = runBuffer.pos[i]; |
| + runBuffer.pos[i] = x; |
| + x += w; |
| + } |
| + return (SkScalar)x; |
| +} |
| + |
| +#endif // !SK_ENABLE_HARFBUZZ |