From 61aba133e6de5197cdf490696ae7aba5f56273fd Mon Sep 17 00:00:00 2001 From: David Capello Date: Wed, 25 Sep 2024 15:54:01 -0300 Subject: [PATCH] Add ShaperFeatures param to draw_text() functions We've moved the ShaperFeatures struct from TextBlob to text namespace. Related to: https://github.com/aseprite/aseprite/issues/4679 --- examples/text_shape.cpp | 2 +- text/draw_text.h | 4 +++- text/draw_text_shaper.cpp | 7 ++++--- text/fwd.h | 4 ++++ text/shaper_features.h | 20 ++++++++++++++++++++ text/skia_text_blob.h | 2 +- text/skia_text_blob_shaper.cpp | 2 +- text/text.h | 1 + text/text_blob.h | 7 +------ text/text_blob_shaper.cpp | 2 +- 10 files changed, 37 insertions(+), 14 deletions(-) create mode 100644 text/shaper_features.h diff --git a/examples/text_shape.cpp b/examples/text_shape.cpp index 448425ad9..c1fbcb7ce 100644 --- a/examples/text_shape.cpp +++ b/examples/text_shape.cpp @@ -65,7 +65,7 @@ struct TextEdit { void makeBlob(FontMgrRef& fontMgr, FontRef& font) { // Create a blob without ligatures (to edit char by char) BoxBuilder handler; - TextBlob::ShaperFeatures features; + ShaperFeatures features; features.ligatures = false; blob = TextBlob::MakeWithShaper(fontMgr, font, text, &handler, features); boxes = handler.boxes(); diff --git a/text/draw_text.h b/text/draw_text.h index 242567a4e..6ac46398b 100644 --- a/text/draw_text.h +++ b/text/draw_text.h @@ -17,6 +17,7 @@ #include "text/font.h" #include "text/font_mgr.h" #include "text/fwd.h" +#include "text/shaper_features.h" namespace os { class Surface; @@ -62,7 +63,8 @@ namespace text { const std::string& text, gfx::Color fg, gfx::Color bg, int x, int y, - DrawTextDelegate* delegate); + DrawTextDelegate* delegate = nullptr, + ShaperFeatures features = {}); void draw_text( os::Surface* surface, diff --git a/text/draw_text_shaper.cpp b/text/draw_text_shaper.cpp index af683491e..8616f7f0e 100644 --- a/text/draw_text_shaper.cpp +++ b/text/draw_text_shaper.cpp @@ -162,16 +162,17 @@ gfx::Rect draw_text(os::Surface* surface, const std::string& text, gfx::Color fg, gfx::Color bg, int x, int y, - DrawTextDelegate* delegate) + DrawTextDelegate* delegate, + ShaperFeatures features) { TextBlobRef blob; if (delegate) { AdapterBuilder handler(surface, text, fg, bg, gfx::PointF(x, y), delegate); - blob = TextBlob::MakeWithShaper(fontMgr, font, text, &handler); + blob = TextBlob::MakeWithShaper(fontMgr, font, text, &handler, features); } else { - blob = TextBlob::MakeWithShaper(fontMgr, font, text); + blob = TextBlob::MakeWithShaper(fontMgr, font, text, nullptr, features); if (surface && blob) { // Paint background if (gfx::geta(bg) > 0) { diff --git a/text/fwd.h b/text/fwd.h index ffc6b95af..e9baec377 100644 --- a/text/fwd.h +++ b/text/fwd.h @@ -17,6 +17,8 @@ namespace text { using codepoint_t = base::codepoint_t; using glyph_t = base::glyph_t; + class DrawTextDelegate; + class Font; using FontRef = base::Ref; @@ -31,6 +33,8 @@ namespace text { class FontStyleSet; using FontStyleSetRef = base::Ref; + struct ShaperFeatures; + class TextBlob; using TextBlobRef = base::Ref; diff --git a/text/shaper_features.h b/text/shaper_features.h new file mode 100644 index 000000000..49cfc2d1a --- /dev/null +++ b/text/shaper_features.h @@ -0,0 +1,20 @@ +// LAF Text Library +// Copyright (c) 2024 Igara Studio S.A. +// +// This file is released under the terms of the MIT license. +// Read LICENSE.txt for more information. + +#ifndef LAF_TEXT_SHAPER_FEATURES_H_INCLUDED +#define LAF_TEXT_SHAPER_FEATURES_H_INCLUDED +#pragma once + +namespace text { + +struct ShaperFeatures { + bool ligatures = true; + ShaperFeatures() { } +}; + +} // namespace text + +#endif diff --git a/text/skia_text_blob.h b/text/skia_text_blob.h index 7bd179fc1..7f8aec673 100644 --- a/text/skia_text_blob.h +++ b/text/skia_text_blob.h @@ -33,7 +33,7 @@ class SkiaTextBlob : public TextBlob { const FontRef& font, const std::string& text, TextBlob::RunHandler* handler, - const TextBlob::ShaperFeatures features); + const ShaperFeatures features); private: sk_sp m_skTextBlob; diff --git a/text/skia_text_blob_shaper.cpp b/text/skia_text_blob_shaper.cpp index cc7c72204..e547d4c7b 100644 --- a/text/skia_text_blob_shaper.cpp +++ b/text/skia_text_blob_shaper.cpp @@ -127,7 +127,7 @@ TextBlobRef SkiaTextBlob::MakeWithShaper( const FontRef& font, const std::string& text, TextBlob::RunHandler* handler, - const TextBlob::ShaperFeatures features) + const ShaperFeatures features) { ASSERT(font); ASSERT(font->type() == FontType::Native); diff --git a/text/text.h b/text/text.h index 7e6622b4b..dce0f8ee0 100644 --- a/text/text.h +++ b/text/text.h @@ -14,6 +14,7 @@ #include "text/font_mgr.h" #include "text/font_style.h" #include "text/font_style_set.h" +#include "text/shaper_features.h" #include "text/text_blob.h" #include "text/typeface.h" diff --git a/text/text_blob.h b/text/text_blob.h index 12a45e18c..0acfb046e 100644 --- a/text/text_blob.h +++ b/text/text_blob.h @@ -11,7 +11,7 @@ #include "gfx/point.h" #include "gfx/rect.h" #include "text/fwd.h" -#include "text/text_blob.h" +#include "text/shaper_features.h" #include #include @@ -57,11 +57,6 @@ namespace text { gfx::RectF getGlyphBounds(size_t i) const; }; - struct ShaperFeatures { - bool ligatures = true; - ShaperFeatures() { } - }; - class RunHandler { public: virtual ~RunHandler() = default; diff --git a/text/text_blob_shaper.cpp b/text/text_blob_shaper.cpp index 60adecb65..f44244d16 100644 --- a/text/text_blob_shaper.cpp +++ b/text/text_blob_shaper.cpp @@ -24,7 +24,7 @@ TextBlobRef TextBlob::MakeWithShaper( const FontRef& font, const std::string& text, TextBlob::RunHandler* handler, - const TextBlob::ShaperFeatures features) + const ShaperFeatures features) { ASSERT(font); switch (font->type()) {