• TouchGFX之二进制翻译


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

    配置文本转换器

    安装二进制翻译

    1. FrontendApplication.hpp
    2. #include
    3. #include
    4. #include
    5. #include
    6. #include
    7. #include
    8. #include
    9. uint8_t fontdata[10000];
    10. FileDataReader reader;
    11. FontCache fontCache;
    12. CachedFont cachedFont; //Cached Font object
    13. //read the translation into this global array
    14. uint8_t translation[10000];
    15. LOCATION_PRAGMA_NOLOAD("TouchGFX_Cache")
    16. uint16_t Cache[1024 * 604] LOCATION_ATTRIBUTE_NOLOAD("TouchGFX_Cache");
    17. FrontendApplication::FrontendApplication(Model& m, FrontendHeap& heap)
    18. : FrontendApplicationBase(m, heap)
    19. {
    20. #ifdef SIMULATOR
    21. const uint32_t cacheSize = 0x300000; //3 MB, as example
    22. uint16_t* const cacheStartAddr = (uint16_t*)malloc(cacheSize);
    23. Bitmap::setCache(cacheStartAddr, cacheSize, 4);
    24. #else
    25. Bitmap::setCache(Cache, sizeof(Cache));
    26. #endif
    27. //read the translation from a file, or change array to a pointer that points
    28. //to the translation data in internal or addressable external flash
    29. FILE* file = fopen("generated/texts/binary/LanguageGb.bin", "rb");
    30. if (file)
    31. {
    32. //read data from file
    33. fread(translation, 1, 10000, file);
    34. fclose(file);
    35. //replace empty translation with the binary data
    36. Texts::setTranslation(GB, translation);
    37. //always change language to get TouchGFX changed from the
    38. //empty translation compiled in to the binary translation
    39. Texts::setLanguage(GB);
    40. }
    41. //setup the font cache with buffer and size; and file reader object
    42. fontCache.setMemory(fontdata, sizeof(fontdata));
    43. fontCache.setReader(&reader);
    44. TypedText text = TypedText(T___SINGLEUSE_2OJQ);
    45. fontCache.initializeCachedFont(text, &cachedFont);
    46. //replace the linked in font in TouchGFX with cachedFont
    47. TypedTextDatabase::setFont(Typography::DEFAULT, &cachedFont);
    48. Unicode::UnicodeChar* str = const_cast(text.getText());
    49. fontCache.cacheString(text, str);
    50. }

    运行模拟器

  • 相关阅读:
    CentOS 8,凛冬将至
    ios ipa包上传需要什么工具
    【java基础系列】14- Java的内部类与常用类
    LAMP(Linux+Apache+MySQL+PHP)环境介绍、配置、搭建
    Unity实现UI的边缘检测和拖拽拉伸功能
    《Neo4J 权威指南》知识点总结
    sqlmap dolog外带数据
    创建Redis 企业软件数据库
    Linux:文件IO
    mybatis踩坑
  • 原文地址:https://blog.csdn.net/lushoumin/article/details/133428699