FreeType字形指标缓存多个字体大小 [英] FreeType Glyph Metrics Caching of multiple Font sizes

查看:563
本文介绍了FreeType字形指标缓存多个字体大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个项目,可以将产品信息呈现到给定的模板(自定义XML格式)上,然后以自定义二进制LCD格式进行呈现并将其转换(简化的步骤)

I have a project that renders product information onto a given template (custom XML format), then renders and converts it in a custom binary LCD format (steps simplified)

我们的客户现在需要自动调整文字容器. (客户提供了一个特定大小的框,并且各种字符串必须自动调整大小适合该容器

Our customers now want auto-fitting text container. (customer gives a box of specific size and all kinds of strings have to get auto-resized to fit into that container

为此,我必须计算多种字体大小(例如100pt不适合,99pt不适合,98pt不适合...,...,65pt适合)的字符串宽度(自由类型:每个字符/字形)! )

For that I have to calculate the width of the string (freetype: each char/glyph) for multiple font-sizes (e.g. 100pt doesnt fit, 99pt doesnt fit, 98pt doesnt..., ..., 65pt fits!)

问题在于,每个自动适配元素的freetype需要花费大量时间(〜20-30 ms),而整个应用程序只能使用〜100ms的时间. (因此,当客户再添加5个自动调整元素时,已经保证超过100毫秒)

The Problem is that freetype takes a lot of time (~20-30 ms) for each auto-fit element and I have only ~100ms for my whole application to use. (so when customer adds 5 more autofit elements it's already guaranteed to exceed ~100 ms)

一个自制的字体缓存生成器,它获取字体文件并计算从1pt到100pt的字体大小的每个unicode字符的宽度.然后它从这样的数据中生成C源代码:

A selfmade font-cache-generator which takes a font-file and calculates the widths of each unicode-character for font-sizes from 1pt to 100pt. Then it generates C source code out of the data like this:

//
#define  COUNT_SIZES  100    // Font-Size 1-100
#define  COUNT_CHARS  65536  // Full Unicode Table
int char_sizes[COUNT_SIZES][COUNT_CHARS] = 
{
   {1,1,2,2,3,1,1,2,2,3,1,2,2,1,2,2,3,1,2,.......// 65536
   {2,2,3,3,4,2,1,3,3,4,2,3,3,2,3,3,4,2,3,.......// 65536
   {2,3,4,3,5,2,2,4,4,5,2,4,4,2,4,3,5,3,3,.......// 65536
   // ...
   // 100 font sizes
};

在动态库(.so)中编译的文件大小为25 MB,"dlload"大约需要50ms,"dlsym"大约需要10ms(WAAAAAAY太多!)

That compiled in a dynamic lib (.so) is 25 MB in size and takes ~50ms to "dlload" and ~10ms to "dlsym" (WAAAAAAY too much!)

以同样的方式,但是只有ASCII表(因此65536中只有128个)可以编译成58 KB的.so文件,"dlload"大约需要500µs,"dlsym"大约需要100µs(非常好!)

The same way but only ASCII table (so only 128 of 65536) compiles into a 58 KB .so file and takes ~500µs for "dlload" and ~100µs for "dlsym" (very nice!)

我的下一个尝试是将font-cache-generator集成到我的项目中,并且仅缓存特定客户所需的字形(欧洲的客户需要约500个字形,亚洲的一个(例如繁体中文)则需要2500个字形) (仅是示例,不确定,甚至可能还需要)

My next attempt would be to integrate the font-cache-generator into my project and cache only the glyphs I need for the specific customer (customer in europe needs ~500 glyphs, one in asia (e.g. traditional chinese) needs ~2500 (only examples, not exactly sure, maybe even more needed)

但是在我进行艰苦的旅程(:()之前,我想问你是否知道一种更好的方法?一个图书馆/项目可以做到这一点?

But before I take on that hard-work journey (:() I wanted to ask you if you know a better way of doing it? A library/project that does just that?

我不敢相信这是不可能的,否则浏览器如何显示lorem ipsum而不加载秒数? :D

I cannot believe that it's not possible, how should a browser show lorem ipsum without loading seconds otherwise? :D

关于如何解决此性能问题的任何想法?

Any idea on how to solve this performance issue?

关于数据缓存的任何信息性链接都可以极快地访问缓存(大约< 1ms)?

Any informative link on data caching with extremly fast access to cache (somewhat <1ms)?

  • Unix (Ubuntu 16.04) 64位
  • x86 AND arm 体系结构存在!
  • Unix (Ubuntu 16.04) 64bit
  • x86 AND arm architectures exist!

推荐答案

我发现了使用这些库的一种可能方法:

I found one possible way using these libraries:

  • ICU (用于unicode)
  • 自由类型(用于字形)
  • Harfbuzz (用于布局)
  • ICU (for unicode)
  • Freetype (for the Glyphs)
  • Harfbuzz (for layout)

Github项目: Harfbuzz-ICU-Freetype

Github Project: Harfbuzz-ICU-Freetype

宽松的构建说明:

  • CMakeLists.txt option(WITH_XX "DESCRIPT." ON/OFF)
  • 中的搜索选项
  • 使用-D启用CMake选项:cmake -DWITH_ZLIB=ON -DWITH_Harfbuzz=ON ..
  • mkdir build && cd build && cmake [option [option [...]]] ..
  • make -j $count_of_cpu_cores && sudo make install
  • Search options in CMakeLists.txt option(WITH_XX "DESCRIPT." ON/OFF)
  • Enable CMake options with -D: cmake -DWITH_ZLIB=ON -DWITH_Harfbuzz=ON ..
  • mkdir build && cd build && cmake [option [option [...]]] ..
  • make -j $count_of_cpu_cores && sudo make install

Google上的一些 Harfbuzz布局教程/指南

Google for some Harfbuzz Layout tutorials / guides

这篇关于FreeType字形指标缓存多个字体大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆