当前位置: 首页 > news >正文

TouchGFX之字体缓存

使用二进制字体需要将整个字体加载到存储器。 在某些情况下,如果字体很大,如大字号中文字体,则这样做可能不可取。

字体缓存使应用能够从外部存储器只能加载显示字符串所需的字母。 这意味着整个字体无需保存到在可寻址闪存或RAM上,而是只需保存在更大的文件系统上。

字体文件阅读器

FileDataReader.hpp#ifndef FILEDATAREADER_HPP
#define FILEDATAREADER_HPP
#include <fonts/FontCache.hpp>
#include <stdio.h>using namespace touchgfx;class FileDataReader : public FontDataReader
{
public:virtual ~FileDataReader() { }virtual void open(){fp = fopen("generated/fonts/bin/Font_verdana_20_4bpp.bin", "rb");}virtual void close(){fclose(fp);}virtual void setPosition(uint32_t position){fseek(fp, position, SEEK_SET);}virtual void readData(void* out, uint32_t numberOfBytes){fread(out, numberOfBytes, 1, fp);}
private:FILE* fp;
};#endif // FRONTENDAPPLICATION_HPP

创建FontCache、存储缓冲区和文件系统阅读器对象,然后安装CachedFont:

#include <gui/common/FrontendApplication.hpp>
#include <BitmapDatabase.hpp>
#include <texts/TextKeysAndLanguages.hpp>
#include <texts/TypedTextDatabase.hpp>
#include <gui/common/FileDataReader.hpp>
#include <fonts/CachedFont.hpp>
#include <fonts/FontCache.hpp>uint8_t fontdata[5120];
FileDataReader reader;
FontCache fontCache;
CachedFont cachedFont;  //Cached Font objectLOCATION_PRAGMA_NOLOAD("TouchGFX_Cache")
uint16_t Cache[1024 * 604] LOCATION_ATTRIBUTE_NOLOAD("TouchGFX_Cache");FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap): FrontendApplicationBase(m, heap)
{
#ifdef SIMULATORconst uint32_t cacheSize = 0x300000; //3 MB, as exampleuint16_t* const cacheStartAddr = (uint16_t*)malloc(cacheSize);Bitmap::setCache(cacheStartAddr, cacheSize, 4);
#elseBitmap::setCache(Cache, sizeof(Cache));
#endif//setup the font cache with buffer and size; and file reader objectfontCache.setMemory(fontdata, sizeof(fontdata));fontCache.setReader(&reader);TypedText text = TypedText(T___SINGLEUSE_2OJQ);fontCache.initializeCachedFont(text, &cachedFont);//replace the linked in font in TouchGFX with cachedFontTypedTextDatabase::setFont(Typography::DEFAULT, &cachedFont);Unicode::UnicodeChar* str = const_cast<Unicode::UnicodeChar*>(text.getText());fontCache.cacheString(text, str);
}

运行模拟器

http://www.lryc.cn/news/178587.html

相关文章:

  • windows系统关闭软件开机自启的常用两种方法
  • 巧用@Conditional注解根据配置文件注入不同的bean对象
  • 论文笔记(整理):轨迹相似度顶会论文中使用的数据集
  • Python实现单例模式
  • spark相关网站
  • ThreeJS-3D教学四-光源
  • Linux 回收内存到底怎么计算anon/file回收比例,只是swappiness这么简单?
  • 软件测试中的测试工具和自动化测试
  • 个人博客系统测试报告
  • 高效搜索,提升编程效率
  • Java编程技巧:文件上传、下载、预览
  • 【蓝桥杯选拔赛真题63】Scratch云朵降雨 少儿编程scratch图形化编程 蓝桥杯选拔赛真题解析
  • 【新版】系统架构设计师 - 软件架构的演化与维护
  • 安卓循环遍历计时器
  • Docker-基本了解
  • Leetcode383. 赎金信
  • overleaf杂谈-Springer文献格式问题
  • No148.精选前端面试题,享受每天的挑战和学习
  • BASH shell脚本篇4——函数
  • VisualStudio配置OpenCV环境
  • C++手写NMS
  • 第9讲:VUE中监听器WATCH使用详解
  • 微信小程序开发基础(一)认识小程序
  • LeetCode 1049. 最后一块石头的重量 II
  • Golang中的类型转换介绍
  • 本人碰到的RN项目的坑
  • EcmaScript标准-导入与导出-js
  • 如何将matlab中的mat矩阵文件在python中读取出来
  • 解释C语言中 6.18f (浮点数常量后缀)
  • Pandas 2.1中的新改进和新功能