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
[Problem] User cannot select a font for ShapeString creation. Only a font file #9458
Comments
Relate forum post: Apart from the issue mentioned in the forum post, there is the problem that a single TTF file can contain multiple font definitions. ShapeString is only able to use the first defined font from such a file. |
We definitely need to convert the font file selection field to a proper font selector. Maybe the code they use could be extracted and reimplemented? |
Why not just https://doc.qt.io/qt-5/qfontdialog.html ?
|
It will retun a QFont but there is no way to obtain the actual file path from a QFont... |
Which is a problem only if you consider you need the path. 😃 |
We need it at the moment, because that's what FreeType needs. Of course one could think to replace it, but we'd need something else that can give us bspline contours here: https://github.com/FreeCAD/FreeCAD/blob/master/src/Mod/Part/App/FT2FC.cpp |
I don't know if something like this is possible with QRawFont or QGlyphRun 😕 |
Put two selectors in the UI. One that uses QFontDialog and searches for best match file in C:/Windows/Fonts, /usr/share/fonts or [osx standard file location] (note, you can't necessarily get the ttf file from the font name/QFont/QFontInfo, so we need a guessing algo). This becomes the general use case for most users. The second one uses a QFileDialog and lets the user select a file in non-standard locations or that has an un-guessable name. |
that's not a bad idea at all, actually |
Maybe locations can be obtained using |
not sure it's helpful, but I've been looking around at other projects which are C++ Qt and deal with fonts, Calligra Words imports and makes calls to fontconfig in their Character Style code |
QRawFont can give a QPainterPath which is very similar to a FreeType FT_Outline. |
What about something like this:
|
I made this PR #10335 some time ago, using Qt to find fontpaths. I haven't tested it on Mac or Windows, but seems good enough. For font path retrieval, we can either move forward with this solution or make another solution. Some notes I have taken while doing extensive research on Qt font handling:
|
I think most, if not all, GUI apps that use fonts rely on having fonts "installed" on the system and will only consider those. Only GIMP I think allows to provide custom font paths... Maybe we could live with it? |
fontconfig is available on *nix, Win and Mac. It takes care of finding the fonts (and the files containing the fonts). This would be the ideal solution (I think). The other choice would be some sort of home made font finder that checks the normal locations for fonts on the current platform. Not sure that either solution will handle the case where a desired font lives in some obscure directory. |
I would surely live with only using installed fonts. If external are needed, they could just be installed onto the system.
Fontconfig is not built-in on Windows as with Linux, so it would be an additional dependency. What about the Qt that I propose in my draft PR, would that be good enough? |
PR#10335 looks like it generates a list of font location directories, so it is a step in the right direction, but we ultimately need a map of font name to font file. Not sure if fontconfig would be faster. |
I would go forward with this PR. It seems to me the best solution overall. |
AFAIK, (please double check), then Qt uses fontconfig.
True... we could test how long loading into FreeType would take... But then, should we store all the fonts in a data structure and retrieve then upon usage (so we don't load the same font twice), or should we only load into FreeType to retrieve the name, and then destroy the FreeType object? I guess the last option would be the best with the amount of usage fonts have? Okay, maybe this is just pointless micro-improvements. A second attempt by someone else could also be to try use hax getting the Qt database of FreeType load-ins. IIRC, it's something with QFontDatabasePrivate... but the load-in function bounces around a lot and multiple times, I somehow got into a wrong route, with the save function being a void function - this might have been due to being a parent class for child classes specific for OS (I encountered child specific classes for OS multiple times). |
FWIW Some remarks: The Fem and Plot module already have a dependency on Matplotlib. Qt and matplotlib find a different number of fonts:
A Qt font has style information:
Matplotlib's font_manager can find files based on style information:
Version:
|
Mario52 has created a nice macro that may provide inspiration: |
Related forum topic: |
Is there an existing issue for this?
Version
0.21 (Development)
Full version info
Subproject(s) affected?
Draft
Problem description
When creating a ShapeString, the user is expected to select a font file. This requires browsing the file sytem to find the font files and then picking one.
The UI should allow the user to pick a font using a typical font selection widget that displays the fonts.
Anything else?
https://forum.freecad.org/viewtopic.php?t=77718
Code of Conduct
The text was updated successfully, but these errors were encountered: