[aseprite] 188/250: Add support for multiple font paths
Tobias Hansen
thansen at moszumanska.debian.org
Sun Dec 20 15:27:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
thansen pushed a commit to branch master
in repository aseprite.
commit 5e239a0768de3351bbc7e9815285e0eff9115574
Author: David Capello <davidcapello at gmail.com>
Date: Fri Oct 16 17:00:10 2015 -0300
Add support for multiple font paths
---
src/app/ui/font_popup.cpp | 57 ++++++++++++++++++++++++++++++-----------------
src/app/ui/font_popup.h | 5 -----
2 files changed, 36 insertions(+), 26 deletions(-)
diff --git a/src/app/ui/font_popup.cpp b/src/app/ui/font_popup.cpp
index 868aefd..57557c8 100644
--- a/src/app/ui/font_popup.cpp
+++ b/src/app/ui/font_popup.cpp
@@ -45,9 +45,13 @@ using namespace ui;
class FontItem : public ListItem {
public:
- FontItem(std::string& fontsDir, const std::string& fn)
- : ListItem(fn)
- , m_fontsDir(fontsDir) {
+ FontItem(const std::string& fn)
+ : ListItem(base::get_file_title(fn))
+ , m_filename(fn) {
+ }
+
+ const std::string& filename() const {
+ return m_filename;
}
private:
@@ -88,17 +92,13 @@ private:
if (!getParent())
return;
- ASSERT(getParent());
- ASSERT(getParent()->type() == kListBoxWidget);
-
- std::string filename = base::join_path(m_fontsDir, getText());
app::skin::SkinTheme* theme = app::skin::SkinTheme::instance();
gfx::Color color = theme->colors.text();
try {
m_image.reset(
render_text(
- filename, 16,
+ m_filename, 16,
getText(),
doc::rgba(gfx::getr(color),
gfx::getg(color),
@@ -114,8 +114,8 @@ private:
}
private:
- std::string& m_fontsDir;
base::UniquePtr<doc::Image> m_image;
+ std::string m_filename;
};
FontPopup::FontPopup()
@@ -133,28 +133,44 @@ FontPopup::FontPopup()
m_popup->view()->attachToView(&m_listBox);
+ std::vector<std::string> fontDirs;
#if _WIN32
{
std::vector<wchar_t> buf(MAX_PATH);
HRESULT hr = SHGetFolderPath(NULL, CSIDL_FONTS, NULL,
SHGFP_TYPE_DEFAULT, &buf[0]);
if (hr == S_OK) {
- m_fontsDir = base::to_utf8(&buf[0]);
+ fontDirs.push_back(base::to_utf8(&buf[0]));
}
}
#elif __APPLE__
{
- m_fontsDir = "/Library/Fonts";
+ fontDirs.push_back("/System/Library/Fonts/");
+ fontDirs.push_back("/Library/Fonts");
+ fontDirs.push_back("~/Library/Fonts");
}
#endif
- if (!m_fontsDir.empty()) {
- auto files = base::list_files(m_fontsDir);
- std::sort(files.begin(), files.end());
- for (auto& file : files) {
- if (base::string_to_lower(base::get_file_extension(file)) == "ttf")
- m_listBox.addChild(new FontItem(m_fontsDir, file));
- }
+ // Create a list of fullpaths to every font found in all font
+ // directories (fontDirs)
+ std::vector<std::string> files;
+ for (const auto& fontDir : fontDirs) {
+ auto fontDirFiles = base::list_files(fontDir);
+ for (const auto& file : fontDirFiles)
+ files.push_back(base::join_path(fontDir, file));
+ }
+
+ // 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;
+ });
+
+ // Create one FontItem for each font
+ for (auto& file : files) {
+ if (base::string_to_lower(base::get_file_extension(file)) == "ttf")
+ m_listBox.addChild(new FontItem(file));
}
if (m_listBox.getChildren().empty())
@@ -181,12 +197,11 @@ void FontPopup::onChangeFont()
void FontPopup::onLoadFont()
{
- Widget* child = m_listBox.getSelectedChild();
+ FontItem* child = dynamic_cast<FontItem*>(m_listBox.getSelectedChild());
if (!child)
return;
- std::string filename = base::join_path(m_fontsDir,
- child->getText());
+ std::string filename = child->filename();
if (base::is_file(filename))
Load(filename); // Fire Load signal
diff --git a/src/app/ui/font_popup.h b/src/app/ui/font_popup.h
index 3b710e5..b1d9031 100644
--- a/src/app/ui/font_popup.h
+++ b/src/app/ui/font_popup.h
@@ -29,10 +29,6 @@ namespace app {
void showPopup(const gfx::Rect& bounds);
- const std::string& fontsDir() const {
- return m_fontsDir;
- }
-
Signal1<void, const std::string&> Load;
protected:
@@ -42,7 +38,6 @@ namespace app {
private:
gen::FontPopup* m_popup;
ui::ListBox m_listBox;
- std::string m_fontsDir;
};
} // namespace app
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git
More information about the Pkg-games-commits
mailing list