Request for Addition of an Interface to Extract Basic Font Information from Files to Support Directory Scan of All Fonts for Rendering Unicode Text
giantpand2000 opened this issue · comments
Description:
Currently, ttf-parser requires reading entire font files into memory, which is inefficient for larger font files, especially during directory scans containing multiple fonts.
Scenario:
I have a specific requirement to scan a directory containing multiple font files and gather basic information from these font files. This information will aid in selecting appropriate fonts when rendering Unicode text. Specifically, when dealing with CJK (Chinese, Japanese, Korean) fonts like NotoSansSC-VariableFont_wght.ttf 17.7MB, the current process of loading entire font files into memory is inefficient and time-consuming.
Desired Solution:
I propose adding an interface in ttf-parser that allows the extraction of essential font information from font files without loading the entire file into memory. This enhancement would streamline the process of scanning directories and rendering Unicode text by efficiently collecting the necessary font information without the need to load the complete font file.
Proposed Interface:
- Implement a functionality that enables the extraction of basic font information solely from font files.
- Ensure this interface can collect required font metadata without the necessity of loading the complete font file.
- Provide access to crucial font attributes like font family, weight, style, etc. (and the information for testing if a char has its glyph), for effective font selection while rendering Unicode text.
- Utilize the gathered meta information to enable the on-demand loading of a glyph, constituting a further request.
- Considering the memory-efficient nature of FreeType, exploring the use of FreeType might be a viable alternative as it operates in a similar manner to manage small memory usage.
Importance:
This enhancement significantly boosts efficiency and performance when scanning directories containing multiple font files and rendering Unicode text, particularly when dealing with large CJK font files. It enables streamlined font selection and rendering by retrieving only the essential font information.
Closed Issue Link #82 :
Issue 82 - Allow parsing Face
s from implementations of std::io::Read + std::io::Seek
Acknowledging the verbose nature of this content, this request was formulated with the aid of ChatGPT. Your understanding and consideration are appreciated.
I'll explore how fontdb
operates to see if there are methods that can be adapted. Thank you for your suggestion.