aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUILD.gn21
-rw-r--r--samplecode/SampleTextBox.cpp37
2 files changed, 24 insertions, 34 deletions
diff --git a/BUILD.gn b/BUILD.gn
index aef276c48a..b214a25546 100644
--- a/BUILD.gn
+++ b/BUILD.gn
@@ -1499,7 +1499,6 @@ if (skia_enable_tools) {
":experimental_svg_model",
":flags",
":gm",
- ":skshaper",
":tool_utils",
":views",
":xml",
@@ -1610,21 +1609,15 @@ if (skia_enable_tools) {
}
}
- test_lib("skshaper") {
- public_include_dirs = [ "tools/shape" ]
- deps = [
- ":skia",
- ]
- # TODO(halcanary): Build ICU on iOS.
- if (is_ios || target_cpu == "wasm") {
- sources = [
- "tools/shape/SkShaper_primitive.cpp",
- ]
- } else {
+ # TODO(halcanary): Build ICU on iOS.
+ if (!is_ios && target_cpu != "wasm") {
+ test_app("sktexttopdf-hb") {
sources = [
"tools/shape/SkShaper_harfbuzz.cpp",
+ "tools/shape/using_skia_and_harfbuzz.cpp",
]
- deps += [
+ deps = [
+ ":skia",
"//third_party/harfbuzz",
"//third_party/icu",
]
@@ -1632,11 +1625,11 @@ if (skia_enable_tools) {
}
test_app("sktexttopdf") {
sources = [
+ "tools/shape/SkShaper_primitive.cpp",
"tools/shape/using_skia_and_harfbuzz.cpp",
]
deps = [
":skia",
- ":skshaper",
]
}
diff --git a/samplecode/SampleTextBox.cpp b/samplecode/SampleTextBox.cpp
index 3c1e9eb878..c5fe4cfcd2 100644
--- a/samplecode/SampleTextBox.cpp
+++ b/samplecode/SampleTextBox.cpp
@@ -5,26 +5,24 @@
* found in the LICENSE file.
*/
#include "SampleCode.h"
-
+#include "SkView.h"
#include "SkBlurMaskFilter.h"
#include "SkCanvas.h"
-#include "SkColorFilter.h"
-#include "SkColorPriv.h"
#include "SkColorShader.h"
#include "SkGradientShader.h"
#include "SkGraphics.h"
-#include "SkOSFile.h"
#include "SkPath.h"
#include "SkRandom.h"
#include "SkRegion.h"
#include "SkShader.h"
-#include "SkShaper.h"
-#include "SkStream.h"
-#include "SkTextBlob.h"
+#include "SkUtils.h"
+#include "SkColorPriv.h"
+#include "SkColorFilter.h"
#include "SkTime.h"
#include "SkTypeface.h"
-#include "SkUtils.h"
-#include "SkView.h"
+#include "SkTextBox.h"
+#include "SkOSFile.h"
+#include "SkStream.h"
extern void skia_set_text_gamma(float blackGamma, float whiteGamma);
@@ -59,7 +57,7 @@ public:
protected:
// overrides from SkEventSink
- bool onQuery(SkEvent* evt) override {
+ virtual bool onQuery(SkEvent* evt) {
if (SampleCode::TitleQ(*evt)) {
SampleCode::TitleR(evt, "TextBox");
return true;
@@ -72,28 +70,27 @@ protected:
canvas->clipRect(SkRect::MakeWH(w, h));
canvas->drawColor(bg);
-
- SkShaper shaper(nullptr);
-
SkScalar margin = 20;
+ SkTextBox tbox;
+ tbox.setMode(SkTextBox::kLineBreak_Mode);
+ tbox.setBox(margin, margin,
+ w - margin, h - margin);
+ tbox.setSpacing(SkIntToScalar(3)/3, 0);
SkPaint paint;
paint.setAntiAlias(true);
paint.setLCDRenderText(true);
paint.setColor(fg);
+ tbox.setText(gText, strlen(gText), paint);
for (int i = 9; i < 24; i += 2) {
- SkTextBlobBuilder builder;
paint.setTextSize(SkIntToScalar(i));
- SkPoint end = shaper.shape(&builder, paint, gText, strlen(gText), true,
- { margin, margin }, w - margin);
- canvas->drawTextBlob(builder.make(), 0, 0, paint);
-
- canvas->translate(0, end.y());
+ tbox.draw(canvas);
+ canvas->translate(0, tbox.getTextHeight() + paint.getFontSpacing());
}
}
- void onDrawContent(SkCanvas* canvas) override {
+ virtual void onDrawContent(SkCanvas* canvas) {
SkScalar width = this->width() / 3;
drawTest(canvas, width, this->height(), SK_ColorBLACK, SK_ColorWHITE);
canvas->translate(width, 0);