转换工具下载

  • 链接:
    工具下载
    提取码:kzlc

华为鸿蒙字体

字体下载

打开工具生成外部汉字bin文件,这里选择鸿蒙黑体HarmonyOS_Sans_SC_Black.ttf

加入所有汉字及ascii字符

转换生成MyFont.c和MyFont.bin两个文件,将MyFont.c文件加入到工程中,实现__user_font_getdata的文件读取驱动

static uint8_t __g_font_buf[364];//如bin文件存在SPI FLASH可使用此buffstatic uint8_t *__user_font_getdata(int offset, int size){//如字模保存在SPI FLASH, SPIFLASH_Read(__g_font_buf,offset,size);//如字模已加载到SDRAM,直接返回偏移地址即可如:return (uint8_t*)(sdram_fontddr+offset);lv_fs_file_t file;lv_fs_res_t result;result = lv_fs_open(&file, "P:/test/myFont.bin", LV_FS_MODE_RD);if (result != LV_FS_RES_OK)return NULL;lv_fs_seek(&file, offset);uint32_t len;lv_fs_read(&file, __g_font_buf, size, &len);lv_fs_close(&file);return __g_font_buf;
}

lvgl文件系统驱动匹配

/*** @file lv_tutorial_images.h**//** -------------------------------------------------------------------------------------------* Learn how to use images stored internally (in a variable) or externally (e.g. on an SD card)*-------------------------------------------------------------------------------------------*** The basic object to display images is 'lv_img'. The displayed image is called 'image source'.** IMAGE SOURCES* -----------------** 1. IMAGE CONVETED TO C ARRAY*  With the online image converter tool you can convert your images into C arrays:*  https://littlevgl.com/image-to-c-array**  If you have the converted file:*    - Copy the result C file into your project*    - Declare the image variable with 'LV_IMG_DECLARE(image_name);'*    - Set it for an image object: 'lv_img_set_src(img1, &image_name);'**  In this case you don't need to think about color format because*  all color formats are included in the C file and the currently active*  (according to 'LV_COLOR_DEPTH' in 'lv_conf.h') will be enabled.** 2. IMAGE FROM FILE*  With the above mentioned online image converter tool you can convert images to binary files too.*  Now you should choose the right color format.*  The result of the conversion should be a *.bin file which can be copied to any external device (e.g. SD card)**  To read this file you need to provide some functions for LittlevGL. You will see it in the example below.**  To set a file for an image object use: 'lv_img_set_src(img, "S:path/to/image.bin")'** 3. IMAGE FROM SYMBOL FONT*  The symbol fonts are letters however they look like small images.*  To set symbols for an image object use: 'lv_img_set_src(img, LV_SYMBOL_CLOSE)'** TRANSPARENCY* ---------------** The images have 2 features related to pixel level transparency:** 1. CHROMA KEYING*  The LV_COLOR_TRANSP (lv_conf.h) pixels will be transparent.*  This feature can be enabled individually in the images in the online image converter tool.*  Because Chroma keying can only show/hide a pixel edges on the image might be jagged.*  On the other hand it dosn't mean extra memory usage.** 2. ALHPA BYTE*  It will add an extra byte to every pixel to show its opacity.*  This feature also can be enabled in the online converter tool.*  In case of 8 and 16 bit images it means extra 8 bit for every pixel.*  The 24 bit images are stored on 32 bit independently from Alpha byte settings.*  Alpha byte results very smooth edges and high quality images.*//**********************      INCLUDES*********************/
#include "lv_tutorial_images.h"
#if LV_USE_TUTORIALS#include "lvgl/lvgl.h"
#include <stdio.h>
#include <errno.h>/**********************      DEFINES*********************/
#define PC_FILES    1       /*If you are on PC you can add PC file function to 'lv_fs'*//***********************      TYPEDEFS**********************/
typedef  FILE * pc_file_t;/***********************  STATIC PROTOTYPES**********************/
#if PC_FILES && LV_USE_FILESYSTEM
/*Interface functions to standard C file functions (only the required ones to image handling)*/
static lv_fs_res_t pcfs_open(lv_fs_drv_t * drv, void * file_p, const char * fn, lv_fs_mode_t mode);
static lv_fs_res_t pcfs_close(lv_fs_drv_t * drv, void * file_p);
static lv_fs_res_t pcfs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br);
static lv_fs_res_t pcfs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos);
static lv_fs_res_t pcfs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p);
static lv_fs_res_t pcfs_size(struct _lv_fs_drv_t* drv, void* file_p, uint32_t* size_p);
static lv_fs_res_t pcfs_write(struct _lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw);
#endif/***********************  STATIC VARIABLES**********************/
/*Declare the "source code image" which is stored in the flash*/
LV_IMG_DECLARE(red_flower)
LV_IMG_DECLARE(red_rose_16);
LV_IMG_DECLARE(flower_icon_alpha);/***********************      MACROS**********************//***********************   GLOBAL FUNCTIONS**********************/void init_fs_config(void)
{lv_fs_drv_t pcfs_drv;                         /*A driver descriptor*/memset(&pcfs_drv, 0, sizeof(lv_fs_drv_t));    /*Initialization*/pcfs_drv.file_size = sizeof(pc_file_t);       /*Set up fields...*/pcfs_drv.letter = 'P';pcfs_drv.write_cb = pcfs_write;pcfs_drv.open_cb = pcfs_open;pcfs_drv.close_cb = pcfs_close;pcfs_drv.read_cb = pcfs_read;pcfs_drv.seek_cb = pcfs_seek;pcfs_drv.tell_cb = pcfs_tell;pcfs_drv.size_cb = pcfs_size;lv_fs_drv_register(&pcfs_drv);
}
/*** Create images from variable and file*/
void lv_tutorial_image(void)
{lv_obj_t * scr = lv_disp_get_scr_act(NULL);     /*Get the current screen*//************************** IMAGE FROM SOURCE CODE*************************/
#if 0lv_obj_t * img_var = lv_img_create(scr, NULL); /*Crate an image object*/lv_img_set_src(img_var, &red_flower);  /*Set the created file as image (a red flower)*/lv_obj_set_pos(img_var, 10, 10);      /*Set the positions*/lv_obj_set_drag(img_var, true);img_var = lv_img_create(scr, NULL); /*Crate an image object*/lv_img_set_src(img_var, &red_rose_16);  /*Set the created file as image (a red rose)*/lv_obj_set_pos(img_var, 10, 100);      /*Set the positions*/lv_obj_set_drag(img_var, true);static lv_style_t style_red;lv_style_copy(&style_red, &lv_style_plain);style_red.image.color = LV_COLOR_RED;img_var = lv_img_create(scr, NULL); /*Crate an image object*/lv_img_set_src(img_var, &flower_icon_alpha);  /*Set the created file as image (a red flower icon)*/lv_img_set_style(img_var, LV_IMG_STYLE_MAIN, &style_red);lv_obj_set_pos(img_var, 10, 200);      /*Set the positions*/lv_obj_set_drag(img_var, true);
#endif
#if PC_FILES && LV_USE_FILESYSTEM/*************************** IMAGE FROM BINARY FILE**************************//* Add a simple drive to open images from PC*/lv_fs_drv_t pcfs_drv;                         /*A driver descriptor*/memset(&pcfs_drv, 0, sizeof(lv_fs_drv_t));    /*Initialization*/pcfs_drv.file_size = sizeof(pc_file_t);       /*Set up fields...*/pcfs_drv.letter = 'P';pcfs_drv.open_cb = pcfs_open;pcfs_drv.close_cb = pcfs_close;pcfs_drv.read_cb = pcfs_read;pcfs_drv.seek_cb = pcfs_seek;pcfs_drv.tell_cb = pcfs_tell;pcfs_drv.size_cb = pcfs_size;lv_fs_drv_register(&pcfs_drv);//    lv_obj_t * img_bin = lv_img_create(scr, NULL); /*Create an image object*//* Set the image's file according to the current color depth* a blue flower picture*/
#if LV_COLOR_DEPTH == 8lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/blue_flower_8.bin");
#elif LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 0//lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/blue_flower_16.bin");
#elif LV_COLOR_DEPTH == 16 && LV_COLOR_16_SWAP == 1//  lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/blue_flower_16_swap.bin");
#elif LV_COLOR_DEPTH == 32//   lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/blue_flower_32.bin");
#endif//  lv_obj_set_pos(img_bin, 150, 10);     /*Align next to the source image*///   lv_obj_set_drag(img_bin, true);lv_obj_t* img_bin = lv_img_create(scr, NULL); /*Crate an image object*/// lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/blue_rose_16.bin");  /*Set the created file as image (a red rose)*/lv_img_set_src(img_bin, "P:/watch1.bin");lv_obj_set_pos(img_bin, 0, 0);      /*Set the positions*/lv_obj_set_drag(img_bin, true);//   static lv_style_t style_blue;//  lv_style_copy(&style_blue, &lv_style_plain);//  style_blue.image.color = LV_COLOR_BLUE;
////  img_bin = lv_img_create(scr, NULL); /*Crate an image object*///   lv_img_set_src(img_bin, "P:/lv_examples/lv_tutorial/6_images/flower_icon_alpha.bin");  /*Set the created file as image (a red flower icon)*///   lv_img_set_style(img_bin, LV_IMG_STYLE_MAIN, &style_blue);//   lv_obj_set_pos(img_bin, 150, 200);      /*Set the positions*///  lv_obj_set_drag(img_bin, true);
#endif// lv_obj_t * img_symbol = lv_img_create(scr, NULL);//   lv_img_set_src(img_symbol, LV_SYMBOL_OK);//  lv_obj_set_drag(img_symbol, true);//  lv_obj_set_pos(img_symbol, 300, 10);      /*Set the positions*/
}/***********************   STATIC FUNCTIONS**********************/#if PC_FILES && LV_USE_FILESYSTEM
/*** Open a file from the PC* @param drv pointer to the current driver* @param file_p pointer to a FILE* variable* @param fn name of the file.* @param mode element of 'fs_mode_t' enum or its 'OR' connection (e.g. FS_MODE_WR | FS_MODE_RD)* @return LV_FS_RES_OK: no error, the file is opened*         any error from lv_fs_res_t enum*/
static lv_fs_res_t pcfs_open(lv_fs_drv_t * drv, void * file_p, const char * fn, lv_fs_mode_t mode)
{(void) drv; /*Unused*/errno = 0;const char * flags = "";if(mode == LV_FS_MODE_WR) flags = "wb";else if(mode == LV_FS_MODE_RD) flags = "rb";else if(mode == (LV_FS_MODE_WR | LV_FS_MODE_RD)) flags = "a+";/*Make the path relative to the current directory (the projects root folder)*/char buf[256];sprintf(buf, "./%s", fn);pc_file_t f = fopen(buf, flags);if(f == NULL) return LV_FS_RES_UNKNOWN;else {fseek(f, 0, SEEK_SET);/* 'file_p' is pointer to a file descriptor and* we need to store our file descriptor here*/pc_file_t * fp = file_p;        /*Just avoid the confusing casings*/*fp = f;}return LV_FS_RES_OK;
}static lv_fs_res_t pcfs_write(struct _lv_fs_drv_t* drv, void* file_p, const void* buf, uint32_t btw, uint32_t* bw)
{(void)drv; /*Unused*/pc_file_t* fp = file_p;        /*Just avoid the confusing casings*/*bw = (uint32_t)fwrite(buf, 1, btw, *fp);return LV_FS_RES_OK;
}/*** Close an opened file* @param drv pointer to the current driver* @param file_p pointer to a FILE* variable. (opened with lv_ufs_open)* @return LV_FS_RES_OK: no error, the file is read*         any error from lv__fs_res_t enum*/
static lv_fs_res_t pcfs_close(lv_fs_drv_t * drv, void * file_p)
{(void) drv; /*Unused*/pc_file_t * fp = file_p;        /*Just avoid the confusing casings*/fclose(*fp);return LV_FS_RES_OK;
}/*** Read data from an opened file* @param drv pointer to the current driver* @param file_p pointer to a FILE variable.* @param buf pointer to a memory block where to store the read data* @param btr number of Bytes To Read* @param br the real number of read bytes (Byte Read)* @return LV_FS_RES_OK: no error, the file is read*         any error from lv__fs_res_t enum*/
static lv_fs_res_t pcfs_read(lv_fs_drv_t * drv, void * file_p, void * buf, uint32_t btr, uint32_t * br)
{(void) drv; /*Unused*/pc_file_t * fp = file_p;        /*Just avoid the confusing casings*/*br = (uint32_t)fread(buf, 1, btr, *fp);return LV_FS_RES_OK;
}/*** Set the read write pointer. Also expand the file size if necessary.* @param drv pointer to the current driver* @param file_p pointer to a FILE* variable. (opened with lv_ufs_open )* @param pos the new position of read write pointer* @return LV_FS_RES_OK: no error, the file is read*         any error from lv__fs_res_t enum*/
static lv_fs_res_t pcfs_seek(lv_fs_drv_t * drv, void * file_p, uint32_t pos)
{(void) drv; /*Unused*/pc_file_t * fp = file_p;        /*Just avoid the confusing casings*/fseek(*fp, pos, SEEK_SET);return LV_FS_RES_OK;
}/*** Give the position of the read write pointer* @param drv pointer to the current driver* @param file_p pointer to a FILE* variable.* @param pos_p pointer to to store the result* @return LV_FS_RES_OK: no error, the file is read*         any error from lv__fs_res_t enum*/
static lv_fs_res_t pcfs_tell(lv_fs_drv_t * drv, void * file_p, uint32_t * pos_p)
{(void) drv; /*Unused*/pc_file_t * fp = file_p;        /*Just avoid the confusing casings*/*pos_p = ftell(*fp);return LV_FS_RES_OK;
}static lv_fs_res_t pcfs_size(struct _lv_fs_drv_t* drv, void* file_p, uint32_t* size_p)
{(void)drv; /*Unused*/pc_file_t* fp = file_p;        /*Just avoid the confusing casings*/fseek(*fp, 0L, SEEK_END);*size_p = ftell(*fp);fseek(*fp, 0L, SEEK_SET);return LV_FS_RES_OK;
}#endif#endif /*LV_USE_TUTORIALS*/

鸿蒙字体展示

#pragma execution_character_set("utf-8")
LV_FONT_DECLARE(myFont)
int main(int argc, char** argv)
{/*Initialize LittlevGL*/lv_init();init_fs_config();/*Initialize the HAL for LittlevGL*/hal_init();lv_obj_t* scr = lv_scr_act();lv_obj_t* cont = lv_cont_create(scr, NULL);lv_obj_set_size(cont, LV_HOR_RES_MAX, LV_VER_RES_MAX);lv_obj_t* label = lv_label_create(cont, NULL);lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0);lv_obj_set_auto_realign(label, true);lv_obj_set_style_local_text_font(label, LV_LABEL_PART_MAIN,  \LV_STATE_DEFAULT, &myFont);lv_obj_set_style_local_text_color(label, LV_LABEL_PART_MAIN,   \LV_STATE_DEFAULT, LV_COLOR_MAKE(0XFF,0X00,0XFF));lv_label_set_text(label, "华为鸿蒙字体!\r\nHuawei Hongmeng font!");while (1) {/* Periodically call the lv_task handler.* It could be done in a timer interrupt or an OS task too.*/lv_task_handler();Sleep(10);       /*Just to let the system breathe */}return 0;
}

运行效果图

LVGL使用华为鸿蒙字体相关推荐

  1. 给电脑换上鸿蒙字体吧~

    前言 之前出过很多期系统美化的文章,换主题.图标.动态壁纸之类的 但美化的尽头是默认,应该也有不少朋友不太喜欢花里胡哨的东西 那如何仅通过很小的改动就能让整个系统有焕然一新的感觉呢? 答案应该是更换字 ...

  2. 手机怎么进ph_明日发布,华为鸿蒙OS2.0手机版特色功能曝光

    阅读本文前,请您先点击上面的蓝色字体,再点击"关注",这样您就可以免费收到最新内容了.每天都有分享,完全是免费订阅,请放心关注. 声明:本文转载自网络,如有侵权,请在后台留言联系我 ...

  3. 三、华为鸿蒙HarmonyOS应用开发HUAWEI DevEco Studio实现页面跳转

    在上一节二.华为鸿蒙开发DevEco Studio运行第一个Hello Word工程 基础上进行下面步骤. 在Java UI框架中,提供了两种编写布局的方式:在XML中声明UI布局和在代码中创建布局. ...

  4. 华为鸿蒙2.0 pc,华为鸿蒙工具下载-华为鸿蒙v2.0正式电脑下载 - 91单机网

    华为鸿蒙作为定制化的系统这两天应该霸屏了各个新闻专栏当中,作为华为自己的系统并且涉及到了方方面面,从手机到各类智能设备将全部的普及这个智能系统,并且在5G的加持之下真正的让万物进行互联,而不但仅之时智 ...

  5. 华为鸿蒙os设置界面,华为鸿蒙OS系统界面疑似曝光 运行性能提升超60%

    01华为鸿蒙OS系统界面疑曝光 近日,网上曝光了疑似华为鸿蒙OS操作系统的截图照片.据截图信息显示,此次"鸿蒙"OS操作系统的界面,不论在功能排列.状态栏,还是字体布局.按键配色等 ...

  6. 华为鸿蒙源码有多少,华为鸿蒙源码下载-华为鸿蒙下载v2.0 正式版-西西软件下载...

    华为鸿蒙作为定制化的系统这两天应该霸屏了各个新闻专栏当中,作为华为自己的系统并且涉及到了方方面面,从手机到各种智能设备将全部的普及这个智能系统,并且在5G的加持之下真正的让万物进行互联,而不仅仅之时智 ...

  7. 鸿蒙系统操作界面布局,华为鸿蒙操作系统大曝光

    描述 华为鸿蒙操作系统大曝光 5月21日,华为消费者业务CEO余承东透露,面向下一代技术而设计的华为操作系统"鸿蒙",最早将于今秋面市. 而就在前天,环球时报(Global Tim ...

  8. 乐视pro3应用鸿蒙OS,完美兼容、无广告,初体验华为鸿蒙系统,鸿蒙OS明显优于iOS?...

    原标题:完美兼容.无广告,初体验华为鸿蒙系统,鸿蒙OS明显优于iOS? 周末的时间体验了一下最近比较热门的华为鸿蒙系统,说说感受,第一感觉就是原来的APP都能用,没有闪退等现象,电量消耗和以前基本一样 ...

  9. 华为鸿蒙系统界面_实锤爆小米宣传图抄袭。华为鸿蒙系统界面设计爆光?

    设计行业新闻 1 实锤爆小米宣传图抄袭 首席内幕官:小米西班牙宣传图被指抄袭,这个色彩和构图第一眼看上去几乎是一样的.但借鉴一位小米员工的说法,借鉴跟抄袭的界限有点模糊,这种就算告了也没什么用,色彩形 ...

  10. 吊打安卓?华为鸿蒙“全家桶”最全测评来了!

    鸿蒙系统发布快三个月来吧,这款打自诞生起就背负千万人期待的系统到底是什么样子?和安卓又有哪些差别?能给华为以及我们普通用户生活带来怎样的改变? 今天老王不讲鸿蒙OS技术,就单从手机.平板.电脑.硬件这 ...

最新文章

  1. Python 在编程语言中是什么地位?为什么很多大学不教 Python?
  2. 深度学习在高德的探索与实践
  3. netstat 命令(Linux)
  4. python数据分析实况_机器学习竞赛分享:通用的团队竞技类的数据分析挖掘方法...
  5. spring项目概念-IOCDI
  6. 视频容器格式与编码格式简介
  7. Shell_Oracle Erp和其他系统Interface资料传输通过Shell进行控制(案例)
  8. iScroll4下表单元素聚焦及键盘的异常问题
  9. 构建最基础的Spring项目及所需要的jar包
  10. 信息化建设规划制定的难点及关键点分析
  11. win8 oracle 卸载,大神细说win8系统卸载oracle的法子
  12. cboard企业版源码_Cboard 搭建和初步试用文档
  13. 说明波特率和比特率的关系---再谈一下编码的关系
  14. 微软bi报表服务器,升级 Power BI 报表服务器
  15. 【转】Jsp自定义标签详解
  16. ubuntu下安装goldendict及离线词库
  17. php 超炫 页面,dedecms织梦后台模板,超炫界面风格
  18. 什么是App推广技术?
  19. 乐器php毕业论文,打击乐器在音乐课堂教学中的应用
  20. 银河土星_不要购买三星银河笔记20

热门文章

  1. 把图片url 伪静态 php,php使动态URL标签链接转成伪静态
  2. Window平台编译log4cpp使用方法记录 (一)
  3. 毕设项目 - 基于SSM的企业公寓宿舍后勤管理系统(含源码+论文)
  4. 微电子电路——一位全加器
  5. Java之父评价C语言之父,Java之父评价C语言之父:C语言撑起了一切
  6. openvpen最新安卓中文版_ins下载官方安卓最新版-ins下载安卓版中文版下载v2.5.46 手机版-西西软件下载...
  7. Silverlight 2应用程序中XAP文件揭秘
  8. grub启动主题美化
  9. 吉林大学计算机游戏程序设计,吉林大学在2018年大学生程序设计竞赛中夺得佳绩...
  10. 朱松纯:AI 需由“心”驱动,实现“心”与“理”的动态平衡