Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move font_paths files from aseprite to laf #123

Closed

Conversation

martincapello
Copy link
Member

Moves the font_path* files from Aseprite source into LAF's "os" namespace. I did this work because when I was trying to find the cause of aseprite/aseprite#4795 I wanted to create an isolated simple app showing just a window with a menu using the aseprite ui, without using any aseprite code. And these files were one of the reasons that made it impossible to do it, hence they had to be moved.

Copy link
Collaborator

@aseprite-bot aseprite-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions


namespace os {

std::string find_font(const std::string& firstDir, const std::string& filename)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::string" is directly included [misc-include-cleaner]

os/font_path.cpp:6:

- #ifdef HAVE_CONFIG_H
+ #include <string>
+ #ifdef HAVE_CONFIG_H

if (base::is_file(fn))
return fn;

base::paths fontDirs;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "base::paths" is directly included [misc-include-cleaner]

os/font_path.cpp:6:

- #ifdef HAVE_CONFIG_H
+ #include "base/paths.h"
+ #ifdef HAVE_CONFIG_H

#endif

#include "os/font_path.h"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header font_path.h is not used directly [misc-include-cleaner]

Suggested change

#include "base/string.h"

#include <cctype>
#include <shlobj.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'shlobj.h' file not found [clang-diagnostic-error]

#include <shlobj.h>
         ^


namespace app {

void get_font_dirs(base::paths& fontDirs)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "base::paths" is directly included [misc-include-cleaner]

os/win/font_path_win.cpp:6:

- #ifdef HAVE_CONFIG_H
+ #include "base/paths.h"
+ #ifdef HAVE_CONFIG_H

#endif

#include "os/font_path.h"

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: included header font_path.h is not used directly [misc-include-cleaner]

Suggested change


namespace app {

base::paths g_cache;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "base::paths" is directly included [misc-include-cleaner]

os/x11/font_path_unix.cpp:6:

- #ifdef HAVE_CONFIG_H
+ #include "base/paths.h"
+ #ifdef HAVE_CONFIG_H

return;
}

std::queue<std::string> q;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::string" is directly included [misc-include-cleaner]

os/x11/font_path_unix.cpp:6:

- #ifdef HAVE_CONFIG_H
+ #include <string>
+ #ifdef HAVE_CONFIG_H

q.push("/usr/share/fonts");

while (!q.empty()) {
std::string fontDir = q.front();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'fontDir' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string fontDir = q.front();
std::string const fontDir = q.front();

fontDirs.push_back(fontDir);

for (const auto& file : base::list_files(fontDir, base::ItemType::Directories)) {
std::string fullpath = base::join_path(fontDir, file);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable 'fullpath' of type 'std::string' (aka 'basic_string') can be declared 'const' [misc-const-correctness]

Suggested change
std::string fullpath = base::join_path(fontDir, file);
std::string const fullpath = base::join_path(fontDir, file);

@dacap
Copy link
Member

dacap commented Dec 26, 2024

Just in case, any font/text related refactor should go to beta, because there is a new laf-text library and the main branch is deprecated for this kind of stuff. Probably this can be done in the beta branch, but I'm not sure if it's needed there (you should try to do the example app with the beta branch).

@dacap dacap assigned martincapello and unassigned dacap Dec 26, 2024
@martincapello
Copy link
Member Author

I actually needed to use the main branch because the fix is planned for the next release of the main branch. But sure, these changes can go in beta branch. I will first see if they are still needed for beta.

@martincapello martincapello changed the base branch from main to beta December 26, 2024 18:19
@martincapello martincapello changed the base branch from beta to main December 26, 2024 18:20
@martincapello
Copy link
Member Author

Seems that in beta, in lines:

https://github.com/aseprite/aseprite/blob/7fb8cfc8fab97c9e4caa3a437501e4dfc4be47f3/src/app/ui/skin/skin_theme.cpp#L215-L217

      fontFilename = app::find_font(xmlDir, platformFileStr);
    if (fileStr && fontFilename.empty())
      fontFilename = app::find_font(xmlDir, fileStr);

The app::find_font() function is still being used as in the main branch. Which means that if I want to create an example with a custom Theme using just the ui module I cannot use the find_font function because it is part of Aseprite. So, I believe that the refactor still applies for beta. Will create a new PR.

@dacap
Copy link
Member

dacap commented Dec 26, 2024

Probably we can move the find_font() function to the ui-lib in that case.

In other case, we could refactor the functionality to something inside FontMgr implementation.

@dacap
Copy link
Member

dacap commented Dec 26, 2024

Sorry, but in case you want to use a custom font using the ui module, I think the current FontMgr can solve that:

virtual FontRef loadTrueTypeFont(const char* filename, float size);
or listing the font faces of the system.

@martincapello
Copy link
Member Author

Okay, so, does the current FontMgr have a function that returns all the system directories that are used to look for font files?

@martincapello
Copy link
Member Author

Or a function to get all the font files available on the system?

@dacap
Copy link
Member

dacap commented Dec 26, 2024

Or a function to get all the font files available on the system?

Yes, check the listfonts example, the FontMgr is the new API to get all system font/load a specific TTF font (e.g. the Text tool / font selector are using this new API).

We want to deprecate and finally remove the app::find_font() in a future.

@martincapello
Copy link
Member Author

We want to deprecate and finally remove the app::find_font() in a future.

I see, then does this means that we will change how the fonts.xml works in Aseprite? So, instead of naming the font file, we would just name the family name?

@martincapello
Copy link
Member Author

I'm closing this because it doesn't make sense any more, since the function will be deprecated. However, I'm still curious about the future of the processing of fonts.xml.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants