TouchGFX之二进制翻译

正常情况下,文本翻译文件会被编译到应用中。 二进制翻译使应用程序不含文本翻译,该文件可编程到闪存中或存储在SD卡等存储设备上。 在处理大量翻译文件时,为应用开发者带来了更大灵活性。

配置文本转换器

安装二进制翻译

FrontendApplication.hpp

#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[10000];
FileDataReader reader;
FontCache fontCache;
CachedFont cachedFont;  //Cached Font object
//read the translation into this global array
uint8_t translation[10000];

LOCATION_PRAGMA_NOLOAD("TouchGFX_Cache")
uint16_t Cache[1024 * 604] LOCATION_ATTRIBUTE_NOLOAD("TouchGFX_Cache");

FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
    : FrontendApplicationBase(m, heap)
{
#ifdef SIMULATOR
    const uint32_t cacheSize = 0x300000; //3 MB, as example
    uint16_t* const cacheStartAddr = (uint16_t*)malloc(cacheSize);
    Bitmap::setCache(cacheStartAddr, cacheSize, 4);
#else
    Bitmap::setCache(Cache, sizeof(Cache));
#endif
	
	//read the translation from a file, or change array to a pointer that points
	//to the translation data in internal or addressable external flash
	FILE* file = fopen("generated/texts/binary/LanguageGb.bin", "rb");
	if (file)
	{
			//read data from file
			fread(translation, 1, 10000, file);
			fclose(file);

			//replace empty translation with the binary data
			Texts::setTranslation(GB, translation);

			//always change language to get TouchGFX changed from the
			//empty translation compiled in to the binary translation
			Texts::setLanguage(GB);
	}
	
	//setup the font cache with buffer and size; and file reader object
	fontCache.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 cachedFont
	TypedTextDatabase::setFont(Typography::DEFAULT, &cachedFont);
	
	Unicode::UnicodeChar* str = const_cast<Unicode::UnicodeChar*>(text.getText());
	fontCache.cacheString(text, str);
}

运行模拟器

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值