go-text / typesetting

High quality text shaping in pure Go.
Other
100 stars 10 forks source link

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

Closed akiyosi closed 9 months ago

akiyosi commented 9 months ago

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

benoitkugler commented 9 months ago

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 commented 9 months ago

@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 commented 9 months ago

@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 :

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

akiyosi commented 9 months ago

@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().

akiyosi commented 9 months ago

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

whereswaldon commented 9 months ago

@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 commented 9 months ago

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