RazrFalcon / ttf-parser

A high-level, safe, zero-allocation TrueType font parser.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:

  1. Implement a functionality that enables the extraction of basic font information solely from font files.
  2. Ensure this interface can collect required font metadata without the necessity of loading the complete font file.
  3. 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.
  4. Utilize the gathered meta information to enable the on-demand loading of a glyph, constituting a further request.
  5. 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 Faces 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.

You don't have to read the file. Just memory map it. See how fontdb works.

As was mentioned in #82 this is impossible to implement. You have to either use memmap or write your own parser.

I'll explore how fontdb operates to see if there are methods that can be adapted. Thank you for your suggestion.