aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Wagner <bungeman@google.com>2022-03-16 23:39:21 -0400
committerSkCQ <skcq-be@skia-corp.google.com.iam.gserviceaccount.com>2022-03-24 15:30:12 +0000
commita357a11f7456651320f57599f44cee8e49a57104 (patch)
tree2d8aa1d6ad07bbec7e8c76688266b8bffc293450
parente28fcd1782772d2f04acca9184b3f5327cd22781 (diff)
downloadskia-a357a11f7456651320f57599f44cee8e49a57104.tar.gz
Simplify FreeType glyph paths with overlap.
With variable fonts overlapping glyph contours are now normal. However, these do not stroke well. Simpify the glyph paths which are marked as overlapping. Bug: b/225044541 Change-Id: I9687e28c9274cd189f4ae8e059d8d40dd802ec41 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/521637 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Ben Wagner <bungeman@google.com> (cherry picked from commit b3275e1fd64cbbf57a1e9a2ecb2db0812cfba4dc) Reviewed-on: https://skia-review.googlesource.com/c/skia/+/523937 Auto-Submit: Ben Wagner <bungeman@google.com> Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Derek Sollenberger <djsollen@google.com>
-rw-r--r--gm/stroketext.cpp30
-rw-r--r--resources/fonts/Variable.ttfbin11548 -> 12812 bytes
-rw-r--r--src/ports/SkFontHost_FreeType_common.cpp14
3 files changed, 41 insertions, 3 deletions
diff --git a/gm/stroketext.cpp b/gm/stroketext.cpp
index 4c2baa11f4..98e670a9ff 100644
--- a/gm/stroketext.cpp
+++ b/gm/stroketext.cpp
@@ -10,6 +10,8 @@
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkFont.h"
+#include "include/core/SkFontArguments.h"
+#include "include/core/SkFontMgr.h"
#include "include/core/SkFontTypes.h"
#include "include/core/SkImageInfo.h"
#include "include/core/SkPaint.h"
@@ -95,10 +97,24 @@ DEF_SIMPLE_GM(stroketext, canvas, 1200, 480) {
draw_text_set(canvas, paint, font);
}
-DEF_SIMPLE_GM_CAN_FAIL(stroketext_native, canvas, msg, 650, 320) {
+DEF_SIMPLE_GM_CAN_FAIL(stroketext_native, canvas, msg, 650, 420) {
sk_sp<SkTypeface> ttf = MakeResourceAsTypeface("fonts/Stroking.ttf");
sk_sp<SkTypeface> otf = MakeResourceAsTypeface("fonts/Stroking.otf");
- if (!ttf && !otf) {
+
+ sk_sp<SkTypeface> overlap = []() -> sk_sp<SkTypeface>{
+ std::unique_ptr<SkStreamAsset> variableStream(GetResourceAsStream("fonts/Variable.ttf"));
+ if (!variableStream) {
+ return nullptr;
+ }
+ const SkFontArguments::VariationPosition::Coordinate position[] = {
+ { SkSetFourByteTag('w','g','h','t'), 721.0f },
+ };
+ SkFontArguments params;
+ params.setVariationDesignPosition({position, SK_ARRAY_COUNT(position)});
+ return SkFontMgr::RefDefault()->makeFromStream(std::move(variableStream), params);
+ }();
+
+ if (!ttf && !otf && !overlap) {
msg->append("No support for ttf or otf.");
return skiagm::DrawResult::kSkip;
}
@@ -140,5 +156,15 @@ DEF_SIMPLE_GM_CAN_FAIL(stroketext_native, canvas, msg, 650, 320) {
canvas->drawString("○◉ ⁰¹³ᶠ", 10, 300, font, p);
}
+ if (overlap) {
+ /* Variable.ttf is structured like:
+ U+74 t (glyf outline has overlap flag)
+ U+167 ŧ (glyf outline does not have overlap flag)
+ */
+ SkFont font(overlap, 100);
+ p.setStrokeWidth(1);
+ canvas->drawString("tŧ", 10, 400, font, p);
+ }
+
return skiagm::DrawResult::kOk;
}
diff --git a/resources/fonts/Variable.ttf b/resources/fonts/Variable.ttf
index be5cf90130..f852390699 100644
--- a/resources/fonts/Variable.ttf
+++ b/resources/fonts/Variable.ttf
Binary files differ
diff --git a/src/ports/SkFontHost_FreeType_common.cpp b/src/ports/SkFontHost_FreeType_common.cpp
index c85fc77c13..da64ed8d2c 100644
--- a/src/ports/SkFontHost_FreeType_common.cpp
+++ b/src/ports/SkFontHost_FreeType_common.cpp
@@ -13,6 +13,7 @@
#include "include/core/SkPath.h"
#include "include/core/SkPictureRecorder.h"
#include "include/effects/SkGradientShader.h"
+#include "include/pathops/SkPathOps.h"
#include "include/private/SkColorData.h"
#include "include/private/SkTo.h"
#include "src/core/SkFDot6.h"
@@ -49,6 +50,11 @@
#endif
#endif
+// FT_OUTLINE_OVERLAP was added in FreeType 2.10.3
+#ifndef FT_OUTLINE_OVERLAP
+# define FT_OUTLINE_OVERLAP 0x40
+#endif
+
// FT_LOAD_COLOR and the corresponding FT_Pixel_Mode::FT_PIXEL_MODE_BGRA
// were introduced in FreeType 2.5.0.
// The following may be removed once FreeType 2.5.0 is required to build.
@@ -1728,7 +1734,13 @@ bool generateFacePathCOLRv1(FT_Face face, SkGlyphID glyphID, SkPath* path) {
} // namespace
bool SkScalerContext_FreeType_Base::generateGlyphPath(FT_Face face, SkPath* path) {
- return generateGlyphPathStatic(face, path);
+ if (!generateGlyphPathStatic(face, path)) {
+ return false;
+ }
+ if (face->glyph->outline.flags & FT_OUTLINE_OVERLAP) {
+ Simplify(*path, path);
+ }
+ return true;
}
bool SkScalerContext_FreeType_Base::generateFacePath(FT_Face face,