Update to new laf draw_text() API

As the new text::draw_text() can draw text with "native" (Skia) fonts,
we have to pass the font manager (text::FontMgr) to it, which is in
SkiaTheme. So we've added a new abstract fontMgr() member function to
ui::Theme to get the active font manager.
This commit is contained in:
David Capello 2024-03-07 19:23:38 -03:00
parent 4cfb3cfa3f
commit ab18cd986c
7 changed files with 31 additions and 20 deletions

2
laf

@ -1 +1 @@
Subproject commit 3bea53125ccafce878d17fcf8d9d192ad69fafb4
Subproject commit 1b5834cd52340f14408112b746c8c46a581c3488

View File

@ -33,14 +33,19 @@ namespace script {
void GraphicsContext::fillText(const std::string& text, int x, int y)
{
text::draw_text(m_surface.get(), m_font,
text, m_paint.color(), 0, x, y, nullptr);
if (auto theme = skin::SkinTheme::instance()) {
text::draw_text(m_surface.get(), theme->fontMgr(), m_font,
text, m_paint.color(), 0, x, y, nullptr);
}
}
gfx::Size GraphicsContext::measureText(const std::string& text) const
{
return text::draw_text(nullptr, m_font, text,
0, 0, 0, 0, nullptr).size();
if (auto theme = skin::SkinTheme::instance()) {
return text::draw_text(nullptr, theme->fontMgr(), m_font, text,
0, 0, 0, 0, nullptr).size();
}
return gfx::Size();
}
void GraphicsContext::drawImage(const doc::Image* img, int x, int y)

View File

@ -1172,7 +1172,7 @@ public:
const gfx::Rect& textBounds() const { return m_textBounds; }
void preProcessChar(const int index,
const int codepoint,
const base::codepoint_t codepoint,
gfx::Color& fg,
gfx::Color& bg,
const gfx::Rect& charBounds) override {

View File

@ -48,8 +48,8 @@ namespace app {
// This is the GUI theme used by Aseprite (which use images from
// data/skins directory).
class SkinTheme : public ui::Theme
, public app::gen::ThemeFile<SkinTheme> {
class SkinTheme final : public ui::Theme
, public app::gen::ThemeFile<SkinTheme> {
public:
static const char* kThemesFolderName;
@ -63,7 +63,7 @@ namespace app {
int preferredScreenScaling() { return m_preferredScreenScaling; }
int preferredUIScaling() { return m_preferredUIScaling; }
text::FontMgrRef fontMgr() const { return m_fontMgr; }
text::FontMgrRef fontMgr() const override { return m_fontMgr; }
text::Font* getDefaultFont() const override { return m_defaultFont.get(); }
text::Font* getWidgetFont(const ui::Widget* widget) const override;
text::Font* getMiniFont() const { return m_miniFont.get(); }

View File

@ -894,7 +894,7 @@ public:
const Entry::CharBoxes& boxes() const { return m_boxes; }
void preProcessChar(const int index,
const int codepoint,
const base::codepoint_t codepoint,
gfx::Color& fg,
gfx::Color& bg,
const gfx::Rect& charBounds) override {
@ -926,7 +926,9 @@ void Entry::recalcCharBoxes(const std::string& text)
{
int lastTextIndex = int(text.size());
CalcBoxesTextDelegate delegate(lastTextIndex);
text::draw_text(nullptr, base::AddRef(font()), text,
text::draw_text(nullptr,
theme()->fontMgr(),
base::AddRef(font()), text,
gfx::ColorNone, gfx::ColorNone, 0, 0, &delegate);
m_boxes = delegate.boxes();

View File

@ -1,5 +1,5 @@
// Aseprite UI Library
// Copyright (C) 2019-2022 Igara Studio S.A.
// Copyright (C) 2019-2024 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -352,7 +352,8 @@ void Graphics::drawText(const std::string& str,
os::SurfaceLock lock(m_surface.get());
gfx::Rect textBounds =
text::draw_text(m_surface.get(), m_font, str, fg, bg, pt.x, pt.y, delegate);
text::draw_text(m_surface.get(), get_theme()->fontMgr(),
m_font, str, fg, bg, pt.x, pt.y, delegate);
dirty(gfx::Rect(pt.x, pt.y, textBounds.w, textBounds.h));
}
@ -373,7 +374,7 @@ public:
gfx::Rect bounds() const { return m_bounds; }
void preProcessChar(const int index,
const int codepoint,
const base::codepoint_t codepoint,
gfx::Color& fg,
gfx::Color& bg,
const gfx::Rect& charBounds) override {
@ -431,8 +432,8 @@ void Graphics::drawUIText(const std::string& str, gfx::Color fg, gfx::Color bg,
int y = m_dy+pt.y;
DrawUITextDelegate delegate(m_surface.get(), m_font.get(), mnemonic);
text::draw_text(m_surface.get(), m_font, str,
fg, bg, x, y, &delegate);
text::draw_text(m_surface.get(), get_theme()->fontMgr(),
m_font, str, fg, bg, x, y, &delegate);
dirty(delegate.bounds());
}
@ -455,9 +456,10 @@ int Graphics::measureUITextLength(const std::string& str,
text::Font* font)
{
DrawUITextDelegate delegate(nullptr, font, 0);
text::draw_text(nullptr, base::AddRef(font), str,
gfx::ColorNone, gfx::ColorNone, 0, 0,
&delegate);
text::draw_text(nullptr, get_theme()->fontMgr(),
base::AddRef(font), str,
gfx::ColorNone, gfx::ColorNone,
0, 0, &delegate);
return delegate.bounds().w;
}

View File

@ -13,10 +13,11 @@
#include "gfx/color.h"
#include "gfx/rect.h"
#include "gfx/size.h"
#include "text/fwd.h"
#include "ui/base.h"
#include "ui/cursor_type.h"
#include "ui/style.h"
#include "ui/scale.h"
#include "ui/style.h"
namespace gfx {
class Region;
@ -62,6 +63,7 @@ namespace ui {
Theme();
virtual ~Theme();
virtual text::FontMgrRef fontMgr() const = 0;
virtual text::Font* getDefaultFont() const = 0;
virtual text::Font* getWidgetFont(const Widget* widget) const = 0;