LVGL7.11中使用freetype库加载显示字体

您所在的位置:网站首页 bitmaperror LVGL7.11中使用freetype库加载显示字体

LVGL7.11中使用freetype库加载显示字体

2024-03-17 16:19| 来源: 网络整理| 查看: 265

目录

 

1、使用环境

2、关于freetype库

3、编译freetype-2.10.4

4、下载LVGL官方封装的接口lv_lib_freetype

5、在mian.c中添加测试代码

1、使用环境

硬件环境:宸芯科技的SS202X系列芯片(笔者这里使用的是SS202D)

软件环境:Linux(移植的嵌入式系统)  LVGL7.11

编译器:arm-linux-gnueabihf-gcc

2、关于freetype库

笔者这里使用的是freetype-2.10.4,下载地址:https://download.savannah.gnu.org/releases/freetype/

3、编译freetype-2.10.4

(1)解压freetype-2.10.4

tar -zxvf freetype-2.10.4.tar.gz

解压完成后可以用tree命令看到如下文件目录树

tree freetype-2.10.4 freetype-2.10.4 ├── autogen.sh ├── builds │   ├── amiga │   │   ├── include │   │   │   └── config │   │   │   ├── ftconfig.h │   │   │   └── ftmodule.h │   │   ├── makefile │   │   ├── makefile.os4 │   │   ├── README │   │   ├── smakefile │   │   └── src │   │   └── base │   │   ├── ftdebug.c │   │   └── ftsystem.c │   ├── ansi │   │   ├── ansi-def.mk │   │   └── ansi.mk │   ├── atari │   │   ├── ATARI.H │   │   ├── deflinejoiner.awk │   │   ├── FNames.SIC │   │   ├── FREETYPE.PRJ │   │   ├── gen-purec-patch.sh │   │   └── README.TXT │   ├── beos │   │   ├── beos-def.mk │   │   ├── beos.mk │   │   └── detect.mk │   ├── cmake │   │   ├── FindBrotliDec.cmake │   │   ├── FindHarfBuzz.cmake │   │   ├── iOS.cmake │   │   └── testbuild.sh │   ├── compiler │   │   ├── ansi-cc.mk │   │   ├── bcc-dev.mk │   │   ├── bcc.mk │   │   ├── emx.mk │   │   ├── gcc-dev.mk │   │   ├── gcc.mk │   │   ├── intelc.mk │   │   ├── unix-lcc.mk │   │   ├── visualage.mk │   │   ├── visualc.mk │   │   ├── watcom.mk │   │   └── win-lcc.mk │   ├── detect.mk │   ├── dos │   │   ├── detect.mk │   │   ├── dos-def.mk │   │   ├── dos-emx.mk │   │   ├── dos-gcc.mk │   │   └── dos-wat.mk │   ├── exports.mk │   ├── freetype.mk │   ├── link_dos.mk │   ├── link_std.mk │   ├── mac │   │   ├── ascii2mpw.py │   │   ├── freetype-Info.plist │   │   ├── FreeType.m68k_cfm.make.txt │   │   ├── FreeType.m68k_far.make.txt │   │   ├── FreeType.ppc_carbon.make.txt │   │   ├── FreeType.ppc_classic.make.txt │   │   ├── ftlib.prj.xml │   │   ├── ftmac.c │   │   └── README │   ├── meson │   │   ├── extract_freetype_version.py │   │   ├── extract_libtool_version.py │   │   ├── generate_reference_docs.py │   │   ├── parse_modules_cfg.py │   │   └── process_ftoption_h.py │   ├── modules.mk │   ├── os2 │   │   ├── detect.mk │   │   ├── os2-def.mk │   │   ├── os2-dev.mk │   │   └── os2-gcc.mk │   ├── symbian │   │   ├── bld.inf │   │   └── freetype.mmp │   ├── toplevel.mk │   ├── unix │   │   ├── aclocal.m4 │   │   ├── ax_compare_version.m4 │   │   ├── ax_prog_python_version.m4 │   │   ├── config.guess │   │   ├── config.sub │   │   ├── configure │   │   ├── configure.ac │   │   ├── configure.raw │   │   ├── detect.mk │   │   ├── freetype2.in │   │   ├── freetype2.m4 │   │   ├── freetype-config.in │   │   ├── ftconfig.h.in │   │   ├── ft-munmap.m4 │   │   ├── ftsystem.c │   │   ├── install.mk │   │   ├── install-sh │   │   ├── ltmain.sh │   │   ├── pkg.m4 │   │   ├── unix-cc.in │   │   ├── unixddef.mk │   │   ├── unix-def.in │   │   ├── unix-dev.mk │   │   ├── unix-lcc.mk │   │   └── unix.mk │   ├── vms │   │   ├── ftconfig.h │   │   ├── ftsystem.c │   │   ├── LIBS.OPT_IA64 │   │   ├── _LINK.OPT_IA64 │   │   └── vmslib.dat │   ├── wince │   │   ├── ftdebug.c │   │   ├── vc2005-ce │   │   │   ├── freetype.sln │   │   │   ├── freetype.vcproj │   │   │   └── index.html │   │   └── vc2008-ce │   │   ├── freetype.sln │   │   ├── freetype.vcproj │   │   └── index.html │   └── windows │   ├── detect.mk │   ├── ftdebug.c │   ├── vc2010 │   │   ├── freetype.sln │   │   ├── freetype.user.props │   │   ├── freetype.vcxproj │   │   ├── freetype.vcxproj.filters │   │   └── index.html │   ├── visualc │   │   ├── freetype.dsp │   │   ├── freetype.dsw │   │   ├── freetype.sln │   │   ├── freetype.vcproj │   │   └── index.html │   ├── visualce │   │   ├── freetype.dsp │   │   ├── freetype.dsw │   │   ├── freetype.vcproj │   │   └── index.html │   ├── w32-bccd.mk │   ├── w32-bcc.mk │   ├── w32-dev.mk │   ├── w32-gcc.mk │   ├── w32-icc.mk │   ├── w32-intl.mk │   ├── w32-lcc.mk │   ├── w32-mingw32.mk │   ├── w32-vcc.mk │   ├── w32-wat.mk │   └── win32-def.mk ├── ChangeLog ├── ChangeLog.20 ├── ChangeLog.21 ├── ChangeLog.22 ├── ChangeLog.23 ├── ChangeLog.24 ├── ChangeLog.25 ├── ChangeLog.26 ├── ChangeLog.27 ├── ChangeLog.28 ├── ChangeLog.29 ├── CMakeLists.txt ├── configure ├── devel │   ├── ft2build.h │   └── ftoption.h ├── docs │   ├── CHANGES │   ├── CMAKE │   ├── CUSTOMIZE │   ├── DEBUG │   ├── DOCGUIDE │   ├── formats.txt │   ├── freetype-config.1 │   ├── FTL.TXT │   ├── GPLv2.TXT │   ├── INSTALL │   ├── INSTALL.ANY │   ├── INSTALL.CROSS │   ├── INSTALL.GNU │   ├── INSTALL.MAC │   ├── INSTALL.UNIX │   ├── INSTALL.VMS │   ├── LICENSE.TXT │   ├── MAKEPP │   ├── PROBLEMS │   ├── raster.txt │   ├── README │   ├── reference │   │   ├── 404.html │   │   ├── assets │   │   │   ├── fonts │   │   │   │   ├── font-awesome.css │   │   │   │   ├── material-icons.css │   │   │   │   └── specimen │   │   │   │   ├── FontAwesome.ttf │   │   │   │   ├── FontAwesome.woff │   │   │   │   ├── FontAwesome.woff2 │   │   │   │   ├── MaterialIcons-Regular.ttf │   │   │   │   ├── MaterialIcons-Regular.woff │   │   │   │   └── MaterialIcons-Regular.woff2 │   │   │   ├── images │   │   │   │   ├── favicon.png │   │   │   │   └── icons │   │   │   │   ├── bitbucket.1b09e088.svg │   │   │   │   ├── github.f0b8504a.svg │   │   │   │   └── gitlab.6dd19c00.svg │   │   │   ├── javascripts │   │   │   │   ├── application.c33a9706.js │   │   │   │   ├── lunr │   │   │   │   │   ├── lunr.ar.js │   │   │   │   │   ├── lunr.da.js │   │   │   │   │   ├── lunr.de.js │   │   │   │   │   ├── lunr.du.js │   │   │   │   │   ├── lunr.es.js │   │   │   │   │   ├── lunr.fi.js │   │   │   │   │   ├── lunr.fr.js │   │   │   │   │   ├── lunr.hu.js │   │   │   │   │   ├── lunr.it.js │   │   │   │   │   ├── lunr.ja.js │   │   │   │   │   ├── lunr.jp.js │   │   │   │   │   ├── lunr.multi.js │   │   │   │   │   ├── lunr.nl.js │   │   │   │   │   ├── lunr.no.js │   │   │   │   │   ├── lunr.pt.js │   │   │   │   │   ├── lunr.ro.js │   │   │   │   │   ├── lunr.ru.js │   │   │   │   │   ├── lunr.stemmer.support.js │   │   │   │   │   ├── lunr.sv.js │   │   │   │   │   ├── lunr.th.js │   │   │   │   │   ├── lunr.tr.js │   │   │   │   │   ├── lunr.vi.js │   │   │   │   │   ├── tinyseg.js │   │   │   │   │   └── wordcut.js │   │   │   │   └── modernizr.86422ebf.js │   │   │   └── stylesheets │   │   │   ├── application.adb8469c.css │   │   │   └── application-palette.a8b3c06d.css │   │   ├── ft2-auto_hinter.html │   │   ├── ft2-base_interface.html │   │   ├── ft2-basic_types.html │   │   ├── ft2-bdf_fonts.html │   │   ├── ft2-bitmap_handling.html │   │   ├── ft2-bzip2.html │   │   ├── ft2-cache_subsystem.html │   │   ├── ft2-cff_driver.html │   │   ├── ft2-cid_fonts.html │   │   ├── ft2-color_management.html │   │   ├── ft2-computations.html │   │   ├── ft2-error_code_values.html │   │   ├── ft2-error_enumerations.html │   │   ├── ft2-font_formats.html │   │   ├── ft2-gasp_table.html │   │   ├── ft2-glyph_management.html │   │   ├── ft2-glyph_stroker.html │   │   ├── ft2-glyph_variants.html │   │   ├── ft2-gx_validation.html │   │   ├── ft2-gzip.html │   │   ├── ft2-header_file_macros.html │   │   ├── ft2-header_inclusion.html │   │   ├── ft2-incremental.html │   │   ├── ft2-index.html │   │   ├── ft2-layer_management.html │   │   ├── ft2-lcd_rendering.html │   │   ├── ft2-list_processing.html │   │   ├── ft2-lzw.html │   │   ├── ft2-mac_specific.html │   │   ├── ft2-module_management.html │   │   ├── ft2-multiple_masters.html │   │   ├── ft2-ot_validation.html │   │   ├── ft2-outline_processing.html │   │   ├── ft2-parameter_tags.html │   │   ├── ft2-pcf_driver.html │   │   ├── ft2-pfr_fonts.html │   │   ├── ft2-properties.html │   │   ├── ft2-quick_advance.html │   │   ├── ft2-raster.html │   │   ├── ft2-sfnt_names.html │   │   ├── ft2-sizes_management.html │   │   ├── ft2-system_interface.html │   │   ├── ft2-t1_cid_driver.html │   │   ├── ft2-truetype_engine.html │   │   ├── ft2-truetype_tables.html │   │   ├── ft2-tt_driver.html │   │   ├── ft2-type1_tables.html │   │   ├── ft2-user_allocation.html │   │   ├── ft2-version.html │   │   ├── ft2-winfnt_fonts.html │   │   ├── images │   │   │   └── favico.ico │   │   ├── index.html │   │   ├── javascripts │   │   │   └── extra.js │   │   ├── search │   │   │   └── search_index.json │   │   ├── sitemap.xml │   │   ├── sitemap.xml.gz │   │   └── stylesheets │   │   └── extra.css │   ├── release │   ├── TODO │   └── VERSIONS.TXT ├── include │   ├── freetype │   │   ├── config │   │   │   ├── ftconfig.h │   │   │   ├── ftheader.h │   │   │   ├── ftmodule.h │   │   │   ├── ftoption.h │   │   │   ├── ftstdlib.h │   │   │   ├── integer-types.h │   │   │   ├── mac-support.h │   │   │   └── public-macros.h │   │   ├── freetype.h │   │   ├── ftadvanc.h │   │   ├── ftbbox.h │   │   ├── ftbdf.h │   │   ├── ftbitmap.h │   │   ├── ftbzip2.h │   │   ├── ftcache.h │   │   ├── ftchapters.h │   │   ├── ftcid.h │   │   ├── ftcolor.h │   │   ├── ftdriver.h │   │   ├── fterrdef.h │   │   ├── fterrors.h │   │   ├── ftfntfmt.h │   │   ├── ftgasp.h │   │   ├── ftglyph.h │   │   ├── ftgxval.h │   │   ├── ftgzip.h │   │   ├── ftimage.h │   │   ├── ftincrem.h │   │   ├── ftlcdfil.h │   │   ├── ftlist.h │   │   ├── ftlzw.h │   │   ├── ftmac.h │   │   ├── ftmm.h │   │   ├── ftmodapi.h │   │   ├── ftmoderr.h │   │   ├── ftotval.h │   │   ├── ftoutln.h │   │   ├── ftparams.h │   │   ├── ftpfr.h │   │   ├── ftrender.h │   │   ├── ftsizes.h │   │   ├── ftsnames.h │   │   ├── ftstroke.h │   │   ├── ftsynth.h │   │   ├── ftsystem.h │   │   ├── fttrigon.h │   │   ├── fttypes.h │   │   ├── ftwinfnt.h │   │   ├── internal │   │   │   ├── autohint.h │   │   │   ├── cffotypes.h │   │   │   ├── cfftypes.h │   │   │   ├── compiler-macros.h │   │   │   ├── ftcalc.h │   │   │   ├── ftdebug.h │   │   │   ├── ftdrv.h │   │   │   ├── ftgloadr.h │   │   │   ├── fthash.h │   │   │   ├── ftmemory.h │   │   │   ├── ftobjs.h │   │   │   ├── ftpsprop.h │   │   │   ├── ftrfork.h │   │   │   ├── ftserv.h │   │   │   ├── ftstream.h │   │   │   ├── fttrace.h │   │   │   ├── ftvalid.h │   │   │   ├── psaux.h │   │   │   ├── pshints.h │   │   │   ├── services │   │   │   │   ├── svbdf.h │   │   │   │   ├── svcfftl.h │   │   │   │   ├── svcid.h │   │   │   │   ├── svfntfmt.h │   │   │   │   ├── svgldict.h │   │   │   │   ├── svgxval.h │   │   │   │   ├── svkern.h │   │   │   │   ├── svmetric.h │   │   │   │   ├── svmm.h │   │   │   │   ├── svotval.h │   │   │   │   ├── svpfr.h │   │   │   │   ├── svpostnm.h │   │   │   │   ├── svprop.h │   │   │   │   ├── svpscmap.h │   │   │   │   ├── svpsinfo.h │   │   │   │   ├── svsfnt.h │   │   │   │   ├── svttcmap.h │   │   │   │   ├── svtteng.h │   │   │   │   ├── svttglyf.h │   │   │   │   └── svwinfnt.h │   │   │   ├── sfnt.h │   │   │   ├── t1types.h │   │   │   ├── tttypes.h │   │   │   └── wofftypes.h │   │   ├── t1tables.h │   │   ├── ttnameid.h │   │   ├── tttables.h │   │   └── tttags.h │   └── ft2build.h ├── Makefile ├── meson.build ├── meson_options.txt ├── modules.cfg ├── objs │   └── README ├── README ├── README.git ├── src │   ├── autofit │   │   ├── afangles.c │   │   ├── afangles.h │   │   ├── afblue.c │   │   ├── afblue.cin │   │   ├── afblue.dat │   │   ├── afblue.h │   │   ├── afblue.hin │   │   ├── afcjk.c │   │   ├── afcjk.h │   │   ├── afcover.h │   │   ├── afdummy.c │   │   ├── afdummy.h │   │   ├── aferrors.h │   │   ├── afglobal.c │   │   ├── afglobal.h │   │   ├── afhints.c │   │   ├── afhints.h │   │   ├── afindic.c │   │   ├── afindic.h │   │   ├── aflatin2.c │   │   ├── aflatin2.h │   │   ├── aflatin.c │   │   ├── aflatin.h │   │   ├── afloader.c │   │   ├── afloader.h │   │   ├── afmodule.c │   │   ├── afmodule.h │   │   ├── afranges.c │   │   ├── afranges.h │   │   ├── afscript.h │   │   ├── afshaper.c │   │   ├── afshaper.h │   │   ├── afstyles.h │   │   ├── aftypes.h │   │   ├── afwarp.c │   │   ├── afwarp.h │   │   ├── afwrtsys.h │   │   ├── autofit.c │   │   ├── module.mk │   │   └── rules.mk │   ├── base │   │   ├── ftadvanc.c │   │   ├── ftbase.c │   │   ├── ftbase.h │   │   ├── ftbbox.c │   │   ├── ftbdf.c │   │   ├── ftbitmap.c │   │   ├── ftcalc.c │   │   ├── ftcid.c │   │   ├── ftcolor.c │   │   ├── ftdbgmem.c │   │   ├── ftdebug.c │   │   ├── fterrors.c │   │   ├── ftfntfmt.c │   │   ├── ftfstype.c │   │   ├── ftgasp.c │   │   ├── ftgloadr.c │   │   ├── ftglyph.c │   │   ├── ftgxval.c │   │   ├── fthash.c │   │   ├── ftinit.c │   │   ├── ftlcdfil.c │   │   ├── ftmac.c │   │   ├── ftmm.c │   │   ├── ftobjs.c │   │   ├── ftotval.c │   │   ├── ftoutln.c │   │   ├── ftpatent.c │   │   ├── ftpfr.c │   │   ├── ftpsprop.c │   │   ├── ftrfork.c │   │   ├── ftsnames.c │   │   ├── ftstream.c │   │   ├── ftstroke.c │   │   ├── ftsynth.c │   │   ├── ftsystem.c │   │   ├── fttrigon.c │   │   ├── fttype1.c │   │   ├── ftutil.c │   │   ├── ftver.rc │   │   ├── ftwinfnt.c │   │   ├── md5.c │   │   ├── md5.h │   │   └── rules.mk │   ├── bdf │   │   ├── bdf.c │   │   ├── bdfdrivr.c │   │   ├── bdfdrivr.h │   │   ├── bdferror.h │   │   ├── bdf.h │   │   ├── bdflib.c │   │   ├── module.mk │   │   ├── README │   │   └── rules.mk │   ├── bzip2 │   │   ├── ftbzip2.c │   │   └── rules.mk │   ├── cache │   │   ├── ftcache.c │   │   ├── ftcbasic.c │   │   ├── ftccache.c │   │   ├── ftccache.h │   │   ├── ftccback.h │   │   ├── ftccmap.c │   │   ├── ftcerror.h │   │   ├── ftcglyph.c │   │   ├── ftcglyph.h │   │   ├── ftcimage.c │   │   ├── ftcimage.h │   │   ├── ftcmanag.c │   │   ├── ftcmanag.h │   │   ├── ftcmru.c │   │   ├── ftcmru.h │   │   ├── ftcsbits.c │   │   ├── ftcsbits.h │   │   └── rules.mk │   ├── cff │   │   ├── cff.c │   │   ├── cffcmap.c │   │   ├── cffcmap.h │   │   ├── cffdrivr.c │   │   ├── cffdrivr.h │   │   ├── cfferrs.h │   │   ├── cffgload.c │   │   ├── cffgload.h │   │   ├── cffload.c │   │   ├── cffload.h │   │   ├── cffobjs.c │   │   ├── cffobjs.h │   │   ├── cffparse.c │   │   ├── cffparse.h │   │   ├── cfftoken.h │   │   ├── module.mk │   │   └── rules.mk │   ├── cid │   │   ├── ciderrs.h │   │   ├── cidgload.c │   │   ├── cidgload.h │   │   ├── cidload.c │   │   ├── cidload.h │   │   ├── cidobjs.c │   │   ├── cidobjs.h │   │   ├── cidparse.c │   │   ├── cidparse.h │   │   ├── cidriver.c │   │   ├── cidriver.h │   │   ├── cidtoken.h │   │   ├── module.mk │   │   ├── rules.mk │   │   └── type1cid.c │   ├── gxvalid │   │   ├── gxvalid.c │   │   ├── gxvalid.h │   │   ├── gxvbsln.c │   │   ├── gxvcommn.c │   │   ├── gxvcommn.h │   │   ├── gxverror.h │   │   ├── gxvfeat.c │   │   ├── gxvfeat.h │   │   ├── gxvfgen.c │   │   ├── gxvjust.c │   │   ├── gxvkern.c │   │   ├── gxvlcar.c │   │   ├── gxvmod.c │   │   ├── gxvmod.h │   │   ├── gxvmort0.c │   │   ├── gxvmort1.c │   │   ├── gxvmort2.c │   │   ├── gxvmort4.c │   │   ├── gxvmort5.c │   │   ├── gxvmort.c │   │   ├── gxvmort.h │   │   ├── gxvmorx0.c │   │   ├── gxvmorx1.c │   │   ├── gxvmorx2.c │   │   ├── gxvmorx4.c │   │   ├── gxvmorx5.c │   │   ├── gxvmorx.c │   │   ├── gxvmorx.h │   │   ├── gxvopbd.c │   │   ├── gxvprop.c │   │   ├── gxvtrak.c │   │   ├── module.mk │   │   ├── README │   │   └── rules.mk │   ├── gzip │   │   ├── adler32.c │   │   ├── ftgzip.c │   │   ├── ftzconf.h │   │   ├── infblock.c │   │   ├── infblock.h │   │   ├── infcodes.c │   │   ├── infcodes.h │   │   ├── inffixed.h │   │   ├── inflate.c │   │   ├── inftrees.c │   │   ├── inftrees.h │   │   ├── infutil.c │   │   ├── infutil.h │   │   ├── rules.mk │   │   ├── zlib.h │   │   ├── zutil.c │   │   └── zutil.h │   ├── lzw │   │   ├── ftlzw.c │   │   ├── ftzopen.c │   │   ├── ftzopen.h │   │   └── rules.mk │   ├── otvalid │   │   ├── module.mk │   │   ├── otvalid.c │   │   ├── otvalid.h │   │   ├── otvbase.c │   │   ├── otvcommn.c │   │   ├── otvcommn.h │   │   ├── otverror.h │   │   ├── otvgdef.c │   │   ├── otvgpos.c │   │   ├── otvgpos.h │   │   ├── otvgsub.c │   │   ├── otvjstf.c │   │   ├── otvmath.c │   │   ├── otvmod.c │   │   ├── otvmod.h │   │   └── rules.mk │   ├── pcf │   │   ├── module.mk │   │   ├── pcf.c │   │   ├── pcfdrivr.c │   │   ├── pcfdrivr.h │   │   ├── pcferror.h │   │   ├── pcf.h │   │   ├── pcfread.c │   │   ├── pcfread.h │   │   ├── pcfutil.c │   │   ├── pcfutil.h │   │   ├── README │   │   └── rules.mk │   ├── pfr │   │   ├── module.mk │   │   ├── pfr.c │   │   ├── pfrcmap.c │   │   ├── pfrcmap.h │   │   ├── pfrdrivr.c │   │   ├── pfrdrivr.h │   │   ├── pfrerror.h │   │   ├── pfrgload.c │   │   ├── pfrgload.h │   │   ├── pfrload.c │   │   ├── pfrload.h │   │   ├── pfrobjs.c │   │   ├── pfrobjs.h │   │   ├── pfrsbit.c │   │   ├── pfrsbit.h │   │   ├── pfrtypes.h │   │   └── rules.mk │   ├── psaux │   │   ├── afmparse.c │   │   ├── afmparse.h │   │   ├── cffdecode.c │   │   ├── cffdecode.h │   │   ├── module.mk │   │   ├── psarrst.c │   │   ├── psarrst.h │   │   ├── psaux.c │   │   ├── psauxerr.h │   │   ├── psauxmod.c │   │   ├── psauxmod.h │   │   ├── psblues.c │   │   ├── psblues.h │   │   ├── psconv.c │   │   ├── psconv.h │   │   ├── pserror.c │   │   ├── pserror.h │   │   ├── psfixed.h │   │   ├── psfont.c │   │   ├── psfont.h │   │   ├── psft.c │   │   ├── psft.h │   │   ├── psglue.h │   │   ├── pshints.c │   │   ├── pshints.h │   │   ├── psintrp.c │   │   ├── psintrp.h │   │   ├── psobjs.c │   │   ├── psobjs.h │   │   ├── psread.c │   │   ├── psread.h │   │   ├── psstack.c │   │   ├── psstack.h │   │   ├── pstypes.h │   │   ├── rules.mk │   │   ├── t1cmap.c │   │   ├── t1cmap.h │   │   ├── t1decode.c │   │   └── t1decode.h │   ├── pshinter │   │   ├── module.mk │   │   ├── pshalgo.c │   │   ├── pshalgo.h │   │   ├── pshglob.c │   │   ├── pshglob.h │   │   ├── pshinter.c │   │   ├── pshmod.c │   │   ├── pshmod.h │   │   ├── pshnterr.h │   │   ├── pshrec.c │   │   ├── pshrec.h │   │   └── rules.mk │   ├── psnames │   │   ├── module.mk │   │   ├── psmodule.c │   │   ├── psmodule.h │   │   ├── psnamerr.h │   │   ├── psnames.c │   │   ├── pstables.h │   │   └── rules.mk │   ├── raster │   │   ├── ftmisc.h │   │   ├── ftraster.c │   │   ├── ftraster.h │   │   ├── ftrend1.c │   │   ├── ftrend1.h │   │   ├── module.mk │   │   ├── raster.c │   │   ├── rasterrs.h │   │   └── rules.mk │   ├── sfnt │   │   ├── module.mk │   │   ├── pngshim.c │   │   ├── pngshim.h │   │   ├── rules.mk │   │   ├── sfdriver.c │   │   ├── sfdriver.h │   │   ├── sferrors.h │   │   ├── sfnt.c │   │   ├── sfobjs.c │   │   ├── sfobjs.h │   │   ├── sfwoff2.c │   │   ├── sfwoff2.h │   │   ├── sfwoff.c │   │   ├── sfwoff.h │   │   ├── ttbdf.c │   │   ├── ttbdf.h │   │   ├── ttcmap.c │   │   ├── ttcmapc.h │   │   ├── ttcmap.h │   │   ├── ttcolr.c │   │   ├── ttcolr.h │   │   ├── ttcpal.c │   │   ├── ttcpal.h │   │   ├── ttkern.c │   │   ├── ttkern.h │   │   ├── ttload.c │   │   ├── ttload.h │   │   ├── ttmtx.c │   │   ├── ttmtx.h │   │   ├── ttpost.c │   │   ├── ttpost.h │   │   ├── ttsbit.c │   │   ├── ttsbit.h │   │   ├── woff2tags.c │   │   └── woff2tags.h │   ├── smooth │   │   ├── ftgrays.c │   │   ├── ftgrays.h │   │   ├── ftsmerrs.h │   │   ├── ftsmooth.c │   │   ├── ftsmooth.h │   │   ├── module.mk │   │   ├── rules.mk │   │   └── smooth.c │   ├── tools │   │   ├── afblue.pl │   │   ├── apinames.c │   │   ├── chktrcmp.py │   │   ├── cordic.py │   │   ├── ftrandom │   │   │   ├── ftrandom.c │   │   │   ├── Makefile │   │   │   └── README │   │   ├── glnames.py │   │   ├── make_distribution_archives.py │   │   ├── no-copyright │   │   ├── test_afm.c │   │   ├── test_bbox.c │   │   ├── test_trig.c │   │   ├── update-copyright │   │   └── update-copyright-year │   ├── truetype │   │   ├── module.mk │   │   ├── rules.mk │   │   ├── truetype.c │   │   ├── ttdriver.c │   │   ├── ttdriver.h │   │   ├── tterrors.h │   │   ├── ttgload.c │   │   ├── ttgload.h │   │   ├── ttgxvar.c │   │   ├── ttgxvar.h │   │   ├── ttinterp.c │   │   ├── ttinterp.h │   │   ├── ttobjs.c │   │   ├── ttobjs.h │   │   ├── ttpload.c │   │   ├── ttpload.h │   │   ├── ttsubpix.c │   │   └── ttsubpix.h │   ├── type1 │   │   ├── module.mk │   │   ├── rules.mk │   │   ├── t1afm.c │   │   ├── t1afm.h │   │   ├── t1driver.c │   │   ├── t1driver.h │   │   ├── t1errors.h │   │   ├── t1gload.c │   │   ├── t1gload.h │   │   ├── t1load.c │   │   ├── t1load.h │   │   ├── t1objs.c │   │   ├── t1objs.h │   │   ├── t1parse.c │   │   ├── t1parse.h │   │   ├── t1tokens.h │   │   └── type1.c │   ├── type42 │   │   ├── module.mk │   │   ├── rules.mk │   │   ├── t42drivr.c │   │   ├── t42drivr.h │   │   ├── t42error.h │   │   ├── t42objs.c │   │   ├── t42objs.h │   │   ├── t42parse.c │   │   ├── t42parse.h │   │   ├── t42types.h │   │   └── type42.c │   └── winfonts │   ├── fnterrs.h │   ├── module.mk │   ├── rules.mk │   ├── winfnt.c │   └── winfnt.h ├── version.sed └── vms_make.com 72 directories, 794 files

(2)编译配置

进入目录

cd freetype-2.10.4

配置编译参数

这里指定了编译器为arm-linux-gnueablihf-gcc 安装目录为当前目录下的library,不需要依赖zlib和png库

./configure CC=arm-linux-gnueabihf-gcc --host=arm-linux --prefix=$PWD/library --with-zlib=no --with-png=no make make install

编译完成之后再用tree命令查看安装目录,结构如下:

library/ ├── include │   └── freetype2 │   ├── freetype │   │   ├── config │   │   │   ├── ftconfig.h │   │   │   ├── ftheader.h │   │   │   ├── ftmodule.h │   │   │   ├── ftoption.h │   │   │   ├── ftstdlib.h │   │   │   ├── integer-types.h │   │   │   ├── mac-support.h │   │   │   └── public-macros.h │   │   ├── freetype.h │   │   ├── ftadvanc.h │   │   ├── ftbbox.h │   │   ├── ftbdf.h │   │   ├── ftbitmap.h │   │   ├── ftbzip2.h │   │   ├── ftcache.h │   │   ├── ftchapters.h │   │   ├── ftcid.h │   │   ├── ftcolor.h │   │   ├── ftdriver.h │   │   ├── fterrdef.h │   │   ├── fterrors.h │   │   ├── ftfntfmt.h │   │   ├── ftgasp.h │   │   ├── ftglyph.h │   │   ├── ftgxval.h │   │   ├── ftgzip.h │   │   ├── ftimage.h │   │   ├── ftincrem.h │   │   ├── ftlcdfil.h │   │   ├── ftlist.h │   │   ├── ftlzw.h │   │   ├── ftmac.h │   │   ├── ftmm.h │   │   ├── ftmodapi.h │   │   ├── ftmoderr.h │   │   ├── ftotval.h │   │   ├── ftoutln.h │   │   ├── ftparams.h │   │   ├── ftpfr.h │   │   ├── ftrender.h │   │   ├── ftsizes.h │   │   ├── ftsnames.h │   │   ├── ftstroke.h │   │   ├── ftsynth.h │   │   ├── ftsystem.h │   │   ├── fttrigon.h │   │   ├── fttypes.h │   │   ├── ftwinfnt.h │   │   ├── t1tables.h │   │   ├── ttnameid.h │   │   ├── tttables.h │   │   └── tttags.h │   └── ft2build.h ├── lib │   ├── libfreetype.a │   ├── libfreetype.la │   ├── libfreetype.so -> libfreetype.so.6.17.4 │   ├── libfreetype.so.6 -> libfreetype.so.6.17.4 │   ├── libfreetype.so.6.17.4 │   └── pkgconfig │   └── freetype2.pc └── share └── aclocal └── freetype2.m4 8 directories, 60 files 4、下载LVGL官方封装的接口lv_lib_freetype

下载地址:https://github.com/lvgl/lv_lib_freetype

由于文件较少,下面直接贴上源代码:

/** * @file lv_freetype.h * */ #ifndef _LV_FONT_TTF_H #define _LV_FONT_TTF_H #ifdef __cplusplus extern "C" { #endif /********************* * INCLUDES *********************/ #include "lvgl/lvgl.h" #include "ft2build.h" #include FT_FREETYPE_H #include FT_GLYPH_H #include FT_CACHE_H #include FT_SIZES_H /********************* * DEFINES *********************/ #define LV_USE_FT_CACHE_MANAGER 1 /********************** * TYPEDEFS **********************/ typedef struct { uint16_t cnt; char* name; } lv_face_info_t; typedef struct { uint16_t num; uint16_t cnt; lv_ll_t face_ll; } lv_faces_control_t; typedef enum { FT_FONT_STYLE_NORMAL = 0, FT_FONT_STYLE_ITALIC = 1 font = lv_mem_alloc(sizeof(lv_font_t)); if(dsc->font == NULL) { lv_mem_free(dsc); return false; } lv_face_info_t *face_info = NULL; FT_Face face = face_find_in_list(info); if (face == NULL) { if (face_control.cnt == face_control.num - 1) { LV_LOG_WARN("face full"); goto Fail; } face_info = lv_mem_alloc(sizeof(lv_face_info_t) + strlen(info->name) + 1); if(face_info == NULL) { goto Fail; } FT_Error error = FT_New_Face(library, info->name, 0, &face); if(error){ lv_mem_free(face_info); LV_LOG_WARN("create face error(%d)", error); goto Fail; } face_info->name = ((char *)face_info) + sizeof(lv_face_info_t); strcpy(face_info->name, info->name); face_info->cnt = 1; face->generic.data = face_info; face->generic.finalizer = face_generic_finalizer; face_add_to_list(face); } else { #if LV_USE_FT_CACHE_MANAGER == 0 FT_Size size; FT_Error error = FT_New_Size(face, &size); if (error) { goto Fail; } FT_Activate_Size(size); FT_Reference_Face(face); #else face_info = (lv_face_info_t *)face->generic.data; face_info->cnt++; #endif } FT_Set_Pixel_Sizes(face, 0, info->weight); dsc->face = face; dsc->size = face->size; dsc->weight = info->weight; dsc->style = info->style; lv_font_t *font = dsc->font; font->user_data = dsc; font->get_glyph_dsc = get_glyph_dsc_cb; font->get_glyph_bitmap = get_glyph_bitmap_cb; font->line_height = (dsc->face->size->metrics.height >> 6); font->base_line = -(dsc->face->size->metrics.descender >> 6); font->subpx = LV_FONT_SUBPX_NONE; font->underline_position = dsc->face->underline_position; font->underline_thickness = dsc->face->underline_thickness; font->dsc = NULL; info->font = font; return true; Fail: lv_mem_free(dsc->font); lv_mem_free(dsc); return false; } void lv_ft_font_destroy(lv_font_t* font) { if (font == NULL) { return; } lv_font_fmt_ft_dsc_t * dsc = (lv_font_fmt_ft_dsc_t *)(font->user_data); if (dsc) { #if LV_USE_FT_CACHE_MANAGER == 0 FT_Done_Size(dsc->size); FT_Done_Face(dsc->face); #else lv_face_info_t *face_info = (lv_face_info_t *)dsc->face->generic.data; face_info->cnt--; if(face_info->cnt == 0){ FTC_Manager_RemoveFaceID(cache_manager, (FTC_FaceID)dsc->face); } #endif lv_mem_free(dsc->font); lv_mem_free(dsc); } } /********************** * STATIC FUNCTIONS **********************/ static void face_generic_finalizer(void* object) { FT_Face face = (FT_Face)object; face_remove_from_list(face); if(face->generic.data){ lv_face_info_t *face_info = (lv_face_info_t *)face->generic.data; lv_mem_free(face_info); } LV_LOG_INFO("face finalizer(%p)\n", face); } static FT_Face face_find_in_list(lv_ft_info_t *info) { lv_face_info_t *face_info; FT_Face *pface = _lv_ll_get_head(&face_control.face_ll); while(pface) { face_info = (lv_face_info_t *)(*pface)->generic.data; if (strcmp(face_info->name, info->name) == 0) { return *pface; } pface = _lv_ll_get_next(&face_control.face_ll, pface); } return NULL; } static void face_add_to_list(FT_Face face) { FT_Face *pface; pface = (FT_Face *)_lv_ll_ins_tail(&face_control.face_ll); *pface = face; face_control.cnt++; } static void face_remove_from_list(FT_Face face) { FT_Face *pface = _lv_ll_get_head(&face_control.face_ll); while(pface) { if (*pface == face) { _lv_ll_remove(&face_control.face_ll, pface); lv_mem_free(pface); face_control.cnt--; break; } pface = _lv_ll_get_next(&face_control.face_ll, pface); } } #if LV_USE_FT_CACHE_MANAGER static FT_Error font_face_requester(FTC_FaceID face_id, FT_Library library_is,FT_Pointer req_data,FT_Face* aface) { LV_UNUSED(library_is); LV_UNUSED(req_data); *aface = face_id; return FT_Err_Ok; } static bool get_glyph_dsc_cb_cache(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { LV_UNUSED(unicode_letter_next); if(unicode_letter < 0x20) { dsc_out->adv_w = 0; dsc_out->box_h = 0; dsc_out->box_w = 0; dsc_out->ofs_x = 0; dsc_out->ofs_y = 0; dsc_out->bpp = 0; return true; } lv_font_fmt_ft_dsc_t * dsc = (lv_font_fmt_ft_dsc_t *)(font->user_data); FT_Face face = dsc->face; static FTC_ImageTypeRec desc_sbit_type; desc_sbit_type.face_id = (FTC_FaceID)face; desc_sbit_type.flags = FT_LOAD_RENDER | FT_LOAD_TARGET_NORMAL; desc_sbit_type.height = dsc->weight; desc_sbit_type.width = dsc->weight; FT_UInt charmap_index = FT_Get_Charmap_Index(face->charmap); FT_UInt glyph_index = FTC_CMapCache_Lookup(cmap_cache, (FTC_FaceID)face, charmap_index, unicode_letter); FT_Error error = FTC_SBitCache_Lookup(sbit_cache, &desc_sbit_type, glyph_index, &sbit, NULL); dsc_out->adv_w = sbit->xadvance; dsc_out->box_h = sbit->height; /*Height of the bitmap in [px]*/ dsc_out->box_w = sbit->width; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = sbit->left; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = sbit->top - sbit->height; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 8; /*Bit per pixel: 1/2/4/8*/ return true; } static const uint8_t * get_glyph_bitmap_cb_cache(const lv_font_t * font, uint32_t unicode_letter) { LV_UNUSED(font); LV_UNUSED(unicode_letter); return (const uint8_t *)sbit->buffer; } #else/* LV_USE_FT_CACHE_MANAGER */ static bool get_glyph_dsc_cb_nocache(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { LV_UNUSED(unicode_letter_next); if(unicode_letter < 0x20) { dsc_out->adv_w = 0; dsc_out->box_h = 0; dsc_out->box_w = 0; dsc_out->ofs_x = 0; dsc_out->ofs_y = 0; dsc_out->bpp = 0; return true; } FT_Error error; FT_Face face; lv_font_fmt_ft_dsc_t * dsc = (lv_font_fmt_ft_dsc_t *)(font->user_data); face = dsc->face; FT_UInt glyph_index = FT_Get_Char_Index( face, unicode_letter ); if (face->size != dsc->size) { FT_Activate_Size(dsc->size); } error = FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT ); if (error){ return false; } error = FT_Render_Glyph( face->glyph, FT_RENDER_MODE_NORMAL); if (error){ return false; } dsc_out->adv_w = (face->glyph->metrics.horiAdvance >> 6); dsc_out->box_h = face->glyph->bitmap.rows; /*Height of the bitmap in [px]*/ dsc_out->box_w = face->glyph->bitmap.width; /*Width of the bitmap in [px]*/ dsc_out->ofs_x = face->glyph->bitmap_left; /*X offset of the bitmap in [pf]*/ dsc_out->ofs_y = face->glyph->bitmap_top - face->glyph->bitmap.rows; /*Y offset of the bitmap measured from the as line*/ dsc_out->bpp = 8; /*Bit per pixel: 1/2/4/8*/ return true; } static const uint8_t * get_glyph_bitmap_cb_nocache(const lv_font_t * font, uint32_t unicode_letter) { LV_UNUSED(unicode_letter); lv_font_fmt_ft_dsc_t * dsc = (lv_font_fmt_ft_dsc_t *)(font->user_data); FT_Face face = dsc->face; return (const uint8_t *)(face->glyph->bitmap.buffer); } #endif/* LV_USE_FT_CACHE_MANAGER */ static bool get_glyph_dsc_cb(const lv_font_t * font, lv_font_glyph_dsc_t * dsc_out, uint32_t unicode_letter, uint32_t unicode_letter_next) { #if LV_USE_FT_CACHE_MANAGER return get_glyph_dsc_cb_cache(font, dsc_out, unicode_letter, unicode_letter_next); #else return get_glyph_dsc_cb_nocache(font, dsc_out, unicode_letter, unicode_letter_next); #endif } static const uint8_t * get_glyph_bitmap_cb(const lv_font_t * font, uint32_t unicode_letter) { #if LV_USE_FT_CACHE_MANAGER return get_glyph_bitmap_cb_cache(font, unicode_letter); #else return get_glyph_bitmap_cb_nocache(font, unicode_letter); #endif }

将整个文件夹lv_lib_freetype拷贝到LVGL的工程目录下,由于笔者这里单独建立了一个目录lv_lib,这里将lv_lib_freetype放到了lv_lib目录下

test@test:/home/work/lvgl_v711/Sigmastar202D$ls build.sh lonbon_app lv_drivers lv_examples lv_fs_if lv_lib Makefile module test.png library lv_conf.h lv_drv_conf.h lv_ex_conf.h lvgl main.c MicroHei.ttf README.md test@test:/home/work/lvgl_v711/Sigmastar202D$ ls lv_lib/ lv_lib_bmp lv_lib_freetype lv_lib_png lv_lib_qrcode lv_lib_split_jpg

然后将library目录中的头文件合并到lv_lib_freetype目录下,并在lv_lib_freetype下添加lv_lib_freetype.mk

test@test:/home/work/lvgl_v711/Sigmastar202D$ cd lv_lib/lv_lib_freetype/ test@test:/home/work/lvgl_v711/Sigmastar202D/lv_lib/lv_lib_freetype$ ls freetype ft2build.h lv_freetype.c lv_freetype.h lv_lib_freetype.mk test@test:/home/work/lvgl_v711/Sigmastar202D/lv_lib/lv_lib_freetype$ ls freetype/ config ftbdf.h ftchapters.h fterrdef.h ftglyph.h ftincrem.h ftmac.h ftotval.h ftrender.h ftsynth.h ftwinfnt.h tttags.h freetype.h ftbitmap.h ftcid.h fterrors.h ftgxval.h ftlcdfil.h ftmm.h ftoutln.h ftsizes.h ftsystem.h t1tables.h ftadvanc.h ftbzip2.h ftcolor.h ftfntfmt.h ftgzip.h ftlist.h ftmodapi.h ftparams.h ftsnames.h fttrigon.h ttnameid.h ftbbox.h ftcache.h ftdriver.h ftgasp.h ftimage.h ftlzw.h ftmoderr.h ftpfr.h ftstroke.h fttypes.h tttables.h test@test:/home/work/lvgl_v711/Sigmastar202D/lv_lib/lv_lib_freetype$ # # lv_lib_freetype.mk # LV_LIB_FREETYPE_DIR_NAME ?= lv_lib_freetype CSRCS += lv_freetype.c #添加依赖文件路径 DEPPATH += --dep-path $(LVGL_DIR)/lv_lib/$(LV_LIB_FREETYPE_DIR_NAME) #添加搜索路径 VPATH += :$(LVGL_DIR)/lv_lib/$(LV_LIB_FREETYPE_DIR_NAME) #添加头文件包含路径 CFLAGS += "-I$(LVGL_DIR)/lv_lib/$(LV_LIB_FREETYPE_DIR_NAME)" CFLAGS += "-I$(LVGL_DIR)/lv_lib/$(LV_LIB_FREETYPE_DIR_NAME)/freetype"

然后回到LVGL工程目录,在Makefile文件中添加链接路径和链接库 

include $(LVGL_DIR)/lv_lib/lv_lib_freetype/lv_lib_freetype.mk CFLAGS += -L./library CFLAGS += -lfreetype 5、在mian.c中添加测试代码 void freetype_font_test() { /* init freetype library */ lv_freetype_init(64, 1, 0); /*Create a font*/ lv_ft_info_t ft_info; ft_info.name = "./MicroHei.ttf"; ft_info.weight = 90; ft_info.style = FT_FONT_STYLE_NORMAL; lv_ft_font_init(&ft_info); lv_ft_info_t ft_info1; ft_info1.name = "./MicroHei.ttf"; ft_info1.weight = 40; ft_info1.style = FT_FONT_STYLE_NORMAL; lv_ft_font_init(&ft_info1); /*Create style with the new font*/ static lv_style_t style; lv_style_init(&style); lv_style_set_text_font(&style, LV_STATE_DEFAULT, ft_info.font); static lv_style_t style1; lv_style_init(&style1); lv_style_set_text_font(&style1, LV_STATE_DEFAULT, ft_info1.font); /*Create a label with the new style*/ lv_obj_t * label = lv_label_create(lv_scr_act(), NULL); lv_obj_add_style(label, LV_LABEL_PART_MAIN, &style); lv_label_set_text(label, "Hello world 123456\n你好世界!"); lv_obj_align(label, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); lv_obj_add_style(label1, LV_LABEL_PART_MAIN, &style1); lv_label_set_text(label1, "世界你好"); lv_obj_align(label1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 200); }

修改lv_conf.h将LV_USE_USER_DATA改成1

#define LV_USE_USER_DATA 1 //0

同时将library中的库文件拷到运行目录下的library目录中,运行效果如下:

参考文献:LVGL学习之路——基于lv_lib_freetype库的TTF字体文件动态加载中文字体

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3