Skip to content

Commit

Permalink
Add ShaperFeatures param to draw_text() functions
Browse files Browse the repository at this point in the history
We've moved the ShaperFeatures struct from TextBlob to text namespace.

Related to: aseprite/aseprite#4679
  • Loading branch information
dacap committed Sep 25, 2024
1 parent f8c9221 commit 61aba13
Show file tree
Hide file tree
Showing 10 changed files with 37 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/text_shape.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion text/draw_text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
7 changes: 4 additions & 3 deletions text/draw_text_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions text/fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Font>;

Expand All @@ -31,6 +33,8 @@ namespace text {
class FontStyleSet;
using FontStyleSetRef = base::Ref<FontStyleSet>;

struct ShaperFeatures;

class TextBlob;
using TextBlobRef = base::Ref<TextBlob>;

Expand Down
20 changes: 20 additions & 0 deletions text/shaper_features.h
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion text/skia_text_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<SkTextBlob> m_skTextBlob;
Expand Down
2 changes: 1 addition & 1 deletion text/skia_text_blob_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions text/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
7 changes: 1 addition & 6 deletions text/text_blob.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <functional>
#include <string>
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion text/text_blob_shaper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 61aba13

Please sign in to comment.