SkShaper: Fix a couple of crashes when fonts aren't found
Change-Id: Id62bb0e0edde25fe90f63547d4dbedada2c09909
Reviewed-on: https://skia-review.googlesource.com/c/166803
Auto-Submit: Hal Canary <halcanary@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/modules/skshaper/src/SkShaper_harfbuzz.cpp b/modules/skshaper/src/SkShaper_harfbuzz.cpp
index 2b20426..0406496 100644
--- a/modules/skshaper/src/SkShaper_harfbuzz.cpp
+++ b/modules/skshaper/src/SkShaper_harfbuzz.cpp
@@ -71,6 +71,9 @@
}
HBFont create_hb_font(SkTypeface* tf) {
+ if (!tf) {
+ return nullptr;
+ }
int index;
HBBlob blob(stream_to_blob(std::unique_ptr<SkStreamAsset>(tf->openStream(&index))));
HBFace face(hb_face_create(blob.get(), (unsigned)index));
@@ -601,6 +604,9 @@
// TODO: language
hb_buffer_guess_segment_properties(buffer);
// TODO: features
+ if (!font->currentHBFont()) {
+ continue;
+ }
hb_shape(font->currentHBFont(), buffer, nullptr, 0);
unsigned len = hb_buffer_get_length(buffer);
if (len == 0) {
diff --git a/site/user/tips.md b/site/user/tips.md
index 78ba5aa..8954cef 100644
--- a/site/user/tips.md
+++ b/site/user/tips.md
@@ -110,8 +110,11 @@
<span id="kerning">Does Skia shape text (kerning)?</span>
---------------------------------------------------------
-No. Skia provides interfaces to draw glyphs, but does not implement a
-text shaper. Skia's client's often use
+Shaping is the process that translates a span of Unicode text into a span of
+positioned glyphs with the apropriate typefaces.
+
+Skia does not shape text. Skia provides interfaces to draw glyphs, but does
+not implement a text shaper. Skia's client's often use
[HarfBuzz](http://www.freedesktop.org/wiki/Software/HarfBuzz/) to
generate the glyphs and their positions, including kerning.