2015-10-16 05:16:16 +08:00
|
|
|
// Aseprite
|
2024-03-06 05:50:24 +08:00
|
|
|
// Copyright (C) 2020-2024 Igara Studio S.A.
|
2018-02-21 21:39:30 +08:00
|
|
|
// Copyright (C) 2001-2018 David Capello
|
2015-10-16 05:16:16 +08:00
|
|
|
//
|
2016-08-27 04:02:58 +08:00
|
|
|
// This program is distributed under the terms of
|
|
|
|
// the End-User License Agreement for Aseprite.
|
2015-10-16 05:16:16 +08:00
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "app/ui/font_popup.h"
|
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
#include "app/app.h"
|
2024-03-25 22:59:25 +08:00
|
|
|
#include "app/file_selector.h"
|
|
|
|
#include "app/font_info.h"
|
2017-02-25 04:56:57 +08:00
|
|
|
#include "app/font_path.h"
|
2022-01-07 17:02:38 +08:00
|
|
|
#include "app/i18n/strings.h"
|
2017-03-16 01:24:42 +08:00
|
|
|
#include "app/match_words.h"
|
2024-10-29 20:48:23 +08:00
|
|
|
#include "app/recent_files.h"
|
2024-03-25 22:59:25 +08:00
|
|
|
#include "app/ui/separator_in_view.h"
|
|
|
|
#include "app/ui/skin/font_data.h"
|
2015-10-16 05:16:16 +08:00
|
|
|
#include "app/ui/skin/skin_theme.h"
|
2020-06-10 06:56:25 +08:00
|
|
|
#include "app/util/conversion_to_surface.h"
|
2024-03-25 22:59:25 +08:00
|
|
|
#include "app/util/render_text.h"
|
2015-10-16 05:16:16 +08:00
|
|
|
#include "base/fs.h"
|
|
|
|
#include "base/string.h"
|
|
|
|
#include "doc/image.h"
|
2015-11-04 23:17:30 +08:00
|
|
|
#include "doc/image_ref.h"
|
2018-08-09 23:58:43 +08:00
|
|
|
#include "os/surface.h"
|
|
|
|
#include "os/system.h"
|
2024-03-25 22:59:25 +08:00
|
|
|
#include "text/text.h"
|
2015-10-16 05:16:16 +08:00
|
|
|
#include "ui/box.h"
|
|
|
|
#include "ui/button.h"
|
2021-03-20 05:57:56 +08:00
|
|
|
#include "ui/fit_bounds.h"
|
2018-06-09 02:52:10 +08:00
|
|
|
#include "ui/graphics.h"
|
|
|
|
#include "ui/listitem.h"
|
2024-03-25 22:59:25 +08:00
|
|
|
#include "ui/message.h"
|
2018-06-09 02:52:10 +08:00
|
|
|
#include "ui/paint_event.h"
|
2015-12-04 08:50:05 +08:00
|
|
|
#include "ui/size_hint_event.h"
|
2015-10-16 05:16:16 +08:00
|
|
|
#include "ui/theme.h"
|
|
|
|
#include "ui/view.h"
|
|
|
|
|
|
|
|
#include "font_popup.xml.h"
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2020-04-08 23:03:32 +08:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include <windows.h>
|
|
|
|
#undef max
|
2015-10-16 05:16:16 +08:00
|
|
|
#endif
|
|
|
|
|
2020-04-08 23:03:32 +08:00
|
|
|
#include <algorithm>
|
2015-11-04 23:17:30 +08:00
|
|
|
#include <map>
|
2015-10-20 03:41:14 +08:00
|
|
|
|
2015-10-16 05:16:16 +08:00
|
|
|
namespace app {
|
|
|
|
|
|
|
|
using namespace ui;
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
static std::map<std::string, os::SurfaceRef> g_thumbnails;
|
2015-11-04 23:17:30 +08:00
|
|
|
|
2015-10-16 05:16:16 +08:00
|
|
|
class FontItem : public ListItem {
|
|
|
|
public:
|
2024-03-25 22:59:25 +08:00
|
|
|
struct ByName {};
|
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
explicit FontItem(const FontInfo& fontInfo)
|
|
|
|
: ListItem(fontInfo.humanString())
|
|
|
|
, m_fontInfo(fontInfo)
|
|
|
|
{
|
|
|
|
getCachedThumbnail();
|
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
FontItem(const std::string& name, ByName)
|
|
|
|
: ListItem(name)
|
|
|
|
, m_fontInfo(FontInfo::Type::Name,
|
|
|
|
name,
|
2024-04-16 05:52:36 +08:00
|
|
|
FontInfo::kDefaultSize,
|
2024-09-26 03:37:41 +08:00
|
|
|
text::FontStyle(),
|
|
|
|
FontInfo::Flags::Antialias)
|
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
getCachedThumbnail();
|
|
|
|
}
|
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
explicit FontItem(const std::string& fn)
|
2015-10-17 04:00:10 +08:00
|
|
|
: ListItem(base::get_file_title(fn))
|
2024-03-25 22:59:25 +08:00
|
|
|
, m_fontInfo(FontInfo::Type::File,
|
|
|
|
fn,
|
2024-04-16 05:52:36 +08:00
|
|
|
FontInfo::kDefaultSize,
|
2024-09-26 03:37:41 +08:00
|
|
|
text::FontStyle(),
|
|
|
|
FontInfo::Flags::Antialias)
|
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
getCachedThumbnail();
|
|
|
|
}
|
|
|
|
|
|
|
|
FontItem(const std::string& name, const text::FontStyle& style, const text::FontStyleSetRef& set)
|
|
|
|
: ListItem(name)
|
|
|
|
, m_fontInfo(FontInfo::Type::System,
|
|
|
|
name,
|
2024-09-26 03:37:41 +08:00
|
|
|
FontInfo::kDefaultSize,
|
|
|
|
style,
|
|
|
|
FontInfo::Flags::Antialias)
|
2024-04-16 05:52:36 +08:00
|
|
|
, m_set(set)
|
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
getCachedThumbnail();
|
2015-10-17 04:00:10 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
FontInfo fontInfo() const { return m_fontInfo; }
|
2015-10-16 05:16:16 +08:00
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
obs::signal<void()> ThumbnailGenerated;
|
|
|
|
|
2015-10-16 05:16:16 +08:00
|
|
|
private:
|
2024-03-25 22:59:25 +08:00
|
|
|
void getCachedThumbnail() { m_thumbnail = g_thumbnails[m_fontInfo.thumbnailId()]; }
|
|
|
|
|
2015-10-16 05:16:16 +08:00
|
|
|
void onPaint(PaintEvent& ev) override
|
|
|
|
{
|
2015-10-17 05:52:52 +08:00
|
|
|
ListItem::onPaint(ev);
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
generateThumbnail();
|
2015-10-16 05:16:16 +08:00
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
if (m_thumbnail) {
|
2024-11-22 06:00:57 +08:00
|
|
|
const auto* theme = app::skin::SkinTheme::get(this);
|
2024-03-25 22:59:25 +08:00
|
|
|
Graphics* g = ev.graphics();
|
2024-11-22 06:00:57 +08:00
|
|
|
g->drawColoredRgbaSurface(m_thumbnail.get(), theme->colors.text(), textWidth() + 4, 0);
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-12-04 08:50:05 +08:00
|
|
|
void onSizeHint(SizeHintEvent& ev) override
|
|
|
|
{
|
|
|
|
ListItem::onSizeHint(ev);
|
2024-03-25 22:59:25 +08:00
|
|
|
if (m_thumbnail) {
|
2015-12-04 08:50:05 +08:00
|
|
|
gfx::Size sz = ev.sizeHint();
|
2024-03-25 22:59:25 +08:00
|
|
|
ev.setSizeHint(sz.w + 4 + m_thumbnail->width(), std::max(sz.h, m_thumbnail->height()));
|
2015-10-17 05:52:52 +08:00
|
|
|
}
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
void generateThumbnail()
|
|
|
|
{
|
|
|
|
if (m_thumbnail)
|
2015-10-16 05:16:16 +08:00
|
|
|
return;
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
const auto* theme = app::skin::SkinTheme::get(this);
|
2015-10-16 05:16:16 +08:00
|
|
|
|
|
|
|
try {
|
2024-10-29 20:48:23 +08:00
|
|
|
const FontInfo fontInfoDefSize(m_fontInfo,
|
|
|
|
FontInfo::kDefaultSize,
|
|
|
|
text::FontStyle(),
|
|
|
|
FontInfo::Flags::Antialias);
|
|
|
|
|
2024-11-22 06:00:57 +08:00
|
|
|
doc::ImageRef image = render_text(fontInfoDefSize, text(), gfx::rgba(0, 0, 0));
|
2024-03-25 22:59:25 +08:00
|
|
|
if (!image)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Convert the doc::Image into a os::Surface
|
|
|
|
m_thumbnail = os::System::instance()->makeRgbaSurface(image->width(), image->height());
|
|
|
|
convert_image_to_surface(image.get(),
|
|
|
|
nullptr,
|
|
|
|
m_thumbnail.get(),
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
image->width(),
|
|
|
|
image->height());
|
2015-11-04 23:17:30 +08:00
|
|
|
|
|
|
|
// Save the thumbnail for future FontPopups
|
2024-03-25 22:59:25 +08:00
|
|
|
g_thumbnails[m_fontInfo.thumbnailId()] = m_thumbnail;
|
|
|
|
|
|
|
|
ThumbnailGenerated();
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
2015-10-30 03:18:51 +08:00
|
|
|
catch (const std::exception&) {
|
2015-10-17 05:52:52 +08:00
|
|
|
// Ignore errors
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
void onSelect(bool selected) override
|
|
|
|
{
|
|
|
|
if (!selected || m_thumbnail)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ListBox* listbox = static_cast<ListBox*>(parent());
|
|
|
|
if (!listbox)
|
|
|
|
return;
|
|
|
|
|
|
|
|
generateThumbnail();
|
|
|
|
listbox->makeChildVisible(this);
|
|
|
|
}
|
|
|
|
|
2015-10-16 05:16:16 +08:00
|
|
|
private:
|
2024-03-25 22:59:25 +08:00
|
|
|
os::SurfaceRef m_thumbnail;
|
|
|
|
FontInfo m_fontInfo;
|
2024-04-16 05:52:36 +08:00
|
|
|
text::FontStyleSetRef m_set;
|
2015-10-16 05:16:16 +08:00
|
|
|
};
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
bool FontPopup::FontListBox::onProcessMessage(ui::Message* msg)
|
|
|
|
{
|
|
|
|
const bool result = ui::ListBox::onProcessMessage(msg);
|
|
|
|
|
|
|
|
// When we release the mouse button we close the popup, i.e. like
|
|
|
|
// selecting an item from a combo box.
|
|
|
|
if (msg->type() == ui::kMouseUpMessage) {
|
|
|
|
if (auto* win = this->window()) {
|
|
|
|
win->closeWindow(nullptr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-10-23 01:32:33 +08:00
|
|
|
bool FontPopup::FontListBox::onAcceptKeyInput()
|
|
|
|
{
|
|
|
|
// Always accept a kKeyDownMessage so we can get Up/Down keyboard
|
|
|
|
// messages from the FontEntry field (when the user is editing the
|
|
|
|
// font name).
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
FontPopup::FontPopup(const FontInfo& fontInfo)
|
|
|
|
: PopupWindow(std::string(),
|
2015-12-06 02:56:32 +08:00
|
|
|
ClickBehavior::CloseOnClickInOtherWindow,
|
|
|
|
EnterBehavior::DoNothingOnEnter)
|
2015-10-16 05:16:16 +08:00
|
|
|
, m_popup(new gen::FontPopup())
|
2024-03-25 22:59:25 +08:00
|
|
|
, m_timer(100)
|
2015-10-16 05:16:16 +08:00
|
|
|
{
|
|
|
|
setAutoRemap(false);
|
|
|
|
setBorder(gfx::Border(4 * guiscale()));
|
|
|
|
|
|
|
|
addChild(m_popup);
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
m_timer.Tick.connect([this] { onTickRelayout(); });
|
2020-07-04 08:51:46 +08:00
|
|
|
m_popup->loadFont()->Click.connect([this] { onLoadFont(); });
|
2015-10-20 02:32:44 +08:00
|
|
|
m_listBox.setFocusMagnet(true);
|
2024-03-25 22:59:25 +08:00
|
|
|
m_listBox.Change.connect([this] {
|
|
|
|
if (m_listBox.hasFocus() || m_listBox.hasCapture()) {
|
|
|
|
onFontChange();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
m_listBox.DoubleClickItem.connect([this] { onFontChange(); });
|
2015-10-16 05:16:16 +08:00
|
|
|
|
|
|
|
m_popup->view()->attachToView(&m_listBox);
|
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
// Pinned fonts
|
|
|
|
m_pinnedSeparator = new SeparatorInView(Strings::font_popup_pinned_fonts());
|
|
|
|
m_listBox.addChild(m_pinnedSeparator);
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
// Default fonts
|
2024-10-29 20:48:23 +08:00
|
|
|
bool first = true;
|
2024-03-25 22:59:25 +08:00
|
|
|
for (auto kv : skin::SkinTheme::get(this)->getWellKnownFonts()) {
|
|
|
|
if (!kv.second->filename().empty()) {
|
2024-10-29 20:48:23 +08:00
|
|
|
if (first) {
|
2024-03-25 22:59:25 +08:00
|
|
|
m_listBox.addChild(new SeparatorInView(Strings::font_popup_theme_fonts()));
|
2024-10-29 20:48:23 +08:00
|
|
|
first = false;
|
2024-03-25 22:59:25 +08:00
|
|
|
}
|
|
|
|
m_listBox.addChild(new FontItem(kv.first, FontItem::ByName()));
|
2015-10-20 03:41:14 +08:00
|
|
|
}
|
2015-10-17 04:00:10 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Create one FontItem for each font
|
2024-03-25 22:59:25 +08:00
|
|
|
m_listBox.addChild(new SeparatorInView(Strings::font_popup_system_fonts()));
|
|
|
|
bool empty = true;
|
|
|
|
|
|
|
|
// Get system fonts from laf-text module
|
|
|
|
const text::FontMgrRef fontMgr = theme()->fontMgr();
|
|
|
|
const int n = fontMgr->countFamilies();
|
|
|
|
if (n > 0) {
|
|
|
|
for (int i = 0; i < n; ++i) {
|
|
|
|
std::string name = fontMgr->familyName(i);
|
|
|
|
text::FontStyleSetRef set = fontMgr->familyStyleSet(i);
|
|
|
|
if (set && set->count() > 0) {
|
2024-04-16 05:52:36 +08:00
|
|
|
// Match the typeface with the default FontStyle (Normal
|
|
|
|
// weight, Upright slant, etc.)
|
|
|
|
auto typeface = set->matchStyle(text::FontStyle());
|
|
|
|
if (typeface) {
|
2024-04-16 06:02:07 +08:00
|
|
|
auto* item = new FontItem(name, typeface->fontStyle(), set);
|
2024-04-16 05:52:36 +08:00
|
|
|
item->ThumbnailGenerated.connect([this] { onThumbnailGenerated(); });
|
|
|
|
m_listBox.addChild(item);
|
|
|
|
empty = false;
|
2024-03-27 03:00:39 +08:00
|
|
|
}
|
2024-03-25 22:59:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Get fonts listing .ttf files TODO we should be able to remove
|
|
|
|
// this code in the future (probably after DirectWrite API is always
|
|
|
|
// available).
|
|
|
|
else {
|
|
|
|
base::paths fontDirs;
|
|
|
|
get_font_dirs(fontDirs);
|
|
|
|
|
|
|
|
// Create a list of fullpaths to every font found in all font
|
|
|
|
// directories (fontDirs)
|
|
|
|
base::paths files;
|
|
|
|
for (const auto& fontDir : fontDirs) {
|
2024-09-24 01:21:01 +08:00
|
|
|
for (const auto& file : base::list_files(fontDir, base::ItemType::Files)) {
|
|
|
|
files.push_back(base::join_path(fontDir, file));
|
2024-03-25 22:59:25 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sort all files by "file title"
|
|
|
|
std::sort(files.begin(), files.end(), [](const std::string& a, const std::string& b) {
|
|
|
|
return base::utf8_icmp(base::get_file_title(a), base::get_file_title(b)) < 0;
|
|
|
|
});
|
|
|
|
|
|
|
|
for (auto& file : files) {
|
|
|
|
std::string ext = base::string_to_lower(base::get_file_extension(file));
|
|
|
|
if (ext == "ttf" || ext == "ttc" || ext == "otf" || ext == "dfont") {
|
|
|
|
m_listBox.addChild(new FontItem(file));
|
|
|
|
empty = false;
|
|
|
|
}
|
|
|
|
}
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
if (empty)
|
2022-01-07 17:02:38 +08:00
|
|
|
m_listBox.addChild(new ListItem(Strings::font_popup_empty_fonts()));
|
2024-03-25 22:59:25 +08:00
|
|
|
|
|
|
|
for (auto* child : m_listBox.children()) {
|
|
|
|
if (auto* childItem = dynamic_cast<FontItem*>(child)) {
|
|
|
|
if (childItem->fontInfo().title() == childItem->text()) {
|
|
|
|
m_listBox.selectChild(childItem);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FontPopup::~FontPopup()
|
|
|
|
{
|
|
|
|
m_timer.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontPopup::setSearchText(const std::string& searchText)
|
|
|
|
{
|
|
|
|
FontItem* firstItem = nullptr;
|
|
|
|
|
|
|
|
const MatchWords match(searchText);
|
|
|
|
for (auto* child : m_listBox.children()) {
|
|
|
|
auto* childItem = dynamic_cast<FontItem*>(child);
|
|
|
|
if (!childItem)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
const bool visible = match(childItem->text());
|
|
|
|
if (visible && !firstItem)
|
|
|
|
firstItem = childItem;
|
|
|
|
childItem->setVisible(visible);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_listBox.selectChild(firstItem);
|
|
|
|
layout();
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
2021-03-20 05:57:56 +08:00
|
|
|
void FontPopup::showPopup(Display* display, const gfx::Rect& buttonBounds)
|
2015-10-16 05:16:16 +08:00
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
m_listBox.selectChild(nullptr);
|
2015-10-16 05:16:16 +08:00
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
recreatePinnedItems();
|
|
|
|
|
2021-03-20 05:57:56 +08:00
|
|
|
ui::fit_bounds(
|
|
|
|
display,
|
|
|
|
this,
|
2024-06-12 09:31:13 +08:00
|
|
|
gfx::Rect(buttonBounds.x, buttonBounds.y2(), buttonBounds.w * 2, buttonBounds.h),
|
2021-03-20 05:57:56 +08:00
|
|
|
[](const gfx::Rect& workarea,
|
|
|
|
gfx::Rect& bounds,
|
|
|
|
std::function<gfx::Rect(Widget*)> getWidgetBounds) { bounds.h = workarea.y2() - bounds.y; });
|
2015-10-16 05:16:16 +08:00
|
|
|
|
|
|
|
openWindow();
|
|
|
|
}
|
|
|
|
|
2024-10-29 20:48:23 +08:00
|
|
|
void FontPopup::recreatePinnedItems()
|
|
|
|
{
|
|
|
|
// Update list of pinned fonts
|
|
|
|
if (m_pinnedSeparator) {
|
|
|
|
// Delete pinned elements
|
|
|
|
while (true) {
|
|
|
|
Widget* next = m_pinnedSeparator->nextSibling();
|
|
|
|
if (!next || next->type() == kSeparatorWidget)
|
|
|
|
break;
|
|
|
|
delete next;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Recreate pinned elements
|
|
|
|
auto& pinnedFonts = App::instance()->recentFiles()->pinnedFonts();
|
|
|
|
int i = 1;
|
|
|
|
for (const auto& fontInfoStr : pinnedFonts) {
|
|
|
|
m_listBox.insertChild(i++, new FontItem(base::convert_to<FontInfo>(fontInfoStr)));
|
|
|
|
}
|
|
|
|
m_pinnedSeparator->setVisible(!pinnedFonts.empty());
|
2024-11-22 05:11:01 +08:00
|
|
|
layout();
|
2024-10-29 20:48:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
FontInfo FontPopup::selectedFont()
|
2017-03-16 01:24:42 +08:00
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
const FontItem* child = dynamic_cast<FontItem*>(m_listBox.getSelectedChild());
|
|
|
|
if (child)
|
|
|
|
return child->fontInfo();
|
|
|
|
return FontInfo();
|
2017-03-16 01:24:42 +08:00
|
|
|
}
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
void FontPopup::onFontChange()
|
2015-10-16 05:16:16 +08:00
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
const FontInfo fontInfo = selectedFont();
|
|
|
|
if (fontInfo.isValid())
|
2024-10-23 01:32:33 +08:00
|
|
|
FontChange(fontInfo);
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void FontPopup::onLoadFont()
|
|
|
|
{
|
2024-03-25 22:59:25 +08:00
|
|
|
std::string currentFile;
|
|
|
|
const FontInfo fontInfo = selectedFont();
|
|
|
|
if (fontInfo.isValid() && fontInfo.type() == FontInfo::Type::File)
|
|
|
|
currentFile = fontInfo.name();
|
|
|
|
|
|
|
|
base::paths exts = { "ttf", "ttc", "otf", "dfont" };
|
|
|
|
base::paths face;
|
|
|
|
if (!show_file_selector(Strings::font_popup_select_truetype_fonts(),
|
|
|
|
currentFile,
|
|
|
|
exts,
|
|
|
|
FileSelectorType::Open,
|
|
|
|
face))
|
2015-10-16 05:16:16 +08:00
|
|
|
return;
|
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
ASSERT(!face.empty());
|
2024-10-23 01:32:33 +08:00
|
|
|
FontChange(FontInfo(FontInfo::Type::File, face.front()));
|
2024-03-25 22:59:25 +08:00
|
|
|
}
|
2015-10-16 05:16:16 +08:00
|
|
|
|
2024-03-25 22:59:25 +08:00
|
|
|
void FontPopup::onThumbnailGenerated()
|
|
|
|
{
|
|
|
|
m_timer.start();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FontPopup::onTickRelayout()
|
|
|
|
{
|
|
|
|
m_popup->view()->updateView();
|
|
|
|
m_timer.stop();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool FontPopup::onProcessMessage(ui::Message* msg)
|
|
|
|
{
|
|
|
|
switch (msg->type()) {
|
|
|
|
case kKeyDownMessage: {
|
|
|
|
const auto* keymsg = static_cast<const KeyMessage*>(msg);
|
|
|
|
|
|
|
|
// Pressing Esc or Enter will just close the popup.
|
|
|
|
if (keymsg->scancode() == kKeyEsc || keymsg->scancode() == kKeyEnter ||
|
|
|
|
keymsg->scancode() == kKeyEnterPad) {
|
|
|
|
EscKey();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ui::PopupWindow::onProcessMessage(msg);
|
2015-10-16 05:16:16 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace app
|