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

fontscan: add function to return all matched font locations #129

Merged
merged 1 commit into from
Dec 19, 2023

Conversation

akiyosi
Copy link
Contributor

@akiyosi akiyosi commented Dec 17, 2023

I wanted to get all of the font locations that matched a given font family.
This PR adds such a function.

@benoitkugler
Copy link
Contributor

Hi @akiyosi and thank you for this contribution.

Out of curiosity, could you elaborate on why you need such function, and what is the use case you would like to support ?

@akiyosi
Copy link
Contributor Author

akiyosi commented Dec 18, 2023

@benoitkugler
Thanks for your comment.

I am creating a GUI application in Go using Go Qt binding.
The issue I have is that Qt applications are very slow to start up on Windows, so I am trying to speed up the startup process by loading font information directly with Qt's low-level font interface called QRawFont.

The reason for the slow startup of the Qt application on Windows was that it took time to load a large number of installed fonts when building the font database called QFontDatabase. In addition, the process of building the QFontDatabase seemed unavoidable when using QFont, a common interface used by Qt applications to render text.

Further investigation revealed that the QFontDatabase construction process could be avoided by using QRawFont.
However, in order for QRawFont to load a specific font, it requires the file path of that font to be specified directly. I am wondering if go-text/typesetting/fontscan could be used to obtain this font file path. FindSystemFont() returns the first font file path that matches, so I would like to get all the font files that match and combine them to assemble the QRawFont for the Qt I need.

@benoitkugler
Copy link
Contributor

@benoitkugler Thanks for your comment.

I am creating a GUI application in Go using Go Qt binding. The issue I have is that Qt applications are very slow to start up on Windows, so I am trying to speed up the startup process by loading font information directly with Qt's low-level font interface called QRawFont.

The reason for the slow startup of the Qt application on Windows was that it took time to load a large number of installed fonts when building the font database called QFontDatabase. In addition, the process of building the QFontDatabase seemed unavoidable when using QFont, a common interface used by Qt applications to render text.

Further investigation revealed that the QFontDatabase construction process could be avoided by using QRawFont. However, in order for QRawFont to load a specific font, it requires the file path of that font to be specified directly. I am wondering if go-text/typesetting/fontscan could be used to obtain this font file path. FindSystemFont() returns the first font file path that matches, so I would like to get all the font files that match and combine them to assemble the QRawFont for the Qt I need.

That is very interesting, thank you for the details.

I would like to point down two features you won't use with this approach :

  • matching font against an Aspect (italic, bold, stretch)
  • family substitutions, when the system does not have the required font

Is it intentional?
I ask because, if not, it would perhaps be better to surface the results of Fontmap.SetQuery

@akiyosi
Copy link
Contributor Author

akiyosi commented Dec 18, 2023

@benoitkugler
Yes, they are intended.

I am considering a mechanism whereby the application-side logic loads the appropriate font based on the font file filename obtained from MatchedSystemFont().

Copy link
Contributor

@benoitkugler benoitkugler left a comment

Choose a reason for hiding this comment

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

Good addition overall, thank you !
I've added two suggestions for better consistency with the existing FindSystemFont.

fontscan/fontmap.go Outdated Show resolved Hide resolved
fontscan/fontmap.go Outdated Show resolved Hide resolved
@akiyosi akiyosi force-pushed the add-func-to-return-fonts branch from 5a8e365 to e980ef8 Compare December 18, 2023 12:21
@akiyosi
Copy link
Contributor Author

akiyosi commented Dec 18, 2023

@benoitkugler
Thanks for the review! That makes sense 👍
I fixed it.

@whereswaldon
Copy link
Member

@akiyosi Could you post a comment here stating that you understand that by contributing this code to typesetting, you are placing it into the public domain? See our licenses for the specific terms that this code would be subject to.

@akiyosi
Copy link
Contributor Author

akiyosi commented Dec 18, 2023

@whereswaldon
Yes, I understand that the code I have contributed is subject to the license of this repository.

@whereswaldon whereswaldon merged commit cc0073e into go-text:main Dec 19, 2023
10 checks passed
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