字库font使用

news/2024/10/17 12:22:27/

windows字体位置        C:\Windows\Fonts

linux字体位置  /usr/share/fonts/DroidSansFallback.ttf

库文件libfont.a

链接:https://pan.baidu.com/s/1BYamH8s_v54IlSrvQe21hg?pwd=mft7
提取码:mft7

font.h

#ifndef __font_h__
#define __font_h__#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include<unistd.h>#define color u32
#define getColor(a, b, c, d) (a|b<<8|c<<16|d<<24)typedef unsigned char u8;
typedef unsigned short u16;
typedef unsigned int u32;
typedef unsigned long long u64;typedef char s8;
typedef short s16;
typedef int s32;
typedef long long s64;typedef struct stbtt_fontinfo
{void           * userdata;unsigned char  * data;              // pointer to .ttf fileint              fontstart;         // offset of start of fontint numGlyphs;                     // number of glyphs, needed for range checkingint loca,head,glyf,hhea,hmtx,kern; // table locations as offset from start of .ttfint index_map;                     // a cmap mapping for our chosen character encodingint indexToLocFormat;              // format needed to map from glyph index to glyph
} stbtt_fontinfo;typedef struct{u32 height;u32 width;u32 byteperpixel;u8 *map;
}bitmap;typedef struct{stbtt_fontinfo *info;u8 *buffer;float scale;
}font;//lcd设备结构体
struct LcdDevice
{int fd;unsigned int *mp; //保存映射首地址};//1.初始化字库 
font *fontLoad(char *fontPath);//2.设置字体的大小 
void fontSetSize(font *f, s32 pixels);//3.设置字体输出框的大小//byteperpixel 4
bitmap *createBitmap(u32 width, u32 height, u32 byteperpixel);//可以指定输出框的颜色
bitmap *createBitmapWithInit(u32 width, u32 height, u32 byteperpixel, color c);//4.把字体输出到输出框中 //maxWidth 0 任意长,宽度就是画布宽度减去起始位置
void fontPrint(font *f, bitmap *screen, s32 x, s32 y, char *text, color c, s32 maxWidth);//5.把输出框的所有信息显示到LCD屏幕中 
void show_font_to_lcd(unsigned int *p,int px,int py,bitmap *bm);// 关闭字体库
void fontUnload(font *f);// 关闭bitmap
void destroyBitmap(bitmap *bm);#endif

main.c

#include "font.h"int (*lcd)[800];
//映射
void init_lcd()
{int fd = open("/dev/fb0",O_RDWR);if(fd<0){puts("open lcd fail");return;}lcd = mmap(NULL,800*480*4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);if(lcd!=MAP_FAILED)puts("映射成功");close(fd);
}
//清屏 
void clear(int (*lcd)[800],int color)
{for(int y=0;y<480;y++){for(int x=0;x<800;x++){lcd[y][x] = color;}}
}
int main()
{    //初始化LCD init_lcd();clear(lcd,0);//1.加载字库font *f = fontLoad("/usr/share/fonts/DroidSansFallback.ttf");if(f == NULL)puts("加载失败");//2.设置字体的大小 8-72fontSetSize(f,72);//3.设置字体输出框的大小bitmap *bm = createBitmap(200,100, 4);//4.把字体输出到输出框中fontPrint(f,bm, 10,10, "hello",0xff000000, 0);//颜色RGBA//不定长超过画布则不显示//5.把输出框的所有信息显示到LCD屏幕中 show_font_to_lcd((unsigned int *)lcd,0,0,bm);// 关闭bitmapdestroyBitmap(bm);// 关闭字体库,不需要频繁关闭//fontUnload(f);//解除映射munmap(lcd,800*480*4);return 0;
}
//arm-linux-gcc main.c -o main -L./ -lm -lfont


http://www.ppmy.cn/news/248386.html

相关文章

CSS font-family字体大合集

以下为font-family常用合集以及一部分文字效果&#xff1a; windows常见内置中文字体 宋体 SimSun 黑体 SimHei 微软雅黑 Microsoft YaHei 微软正黑体 Microsoft JhengHei 新宋体 NSimSun 新细明体 PMingLiU 细明体 MingLiU 标楷体 DFKai-SB 仿宋 FangSong 楷体 Kai…

黑客学习-xss漏洞总结

1、什么是xss 先来看案例 在一个输入框中&#xff0c;输入js代码&#xff0c;存放alter()其弹窗,结果可以看到&#xff0c;代码成功执行。这个就是xss漏洞 XSS攻击全称跨站脚本攻击&#xff0c;是一种在Web应用中常见的安全漏洞&#xff0c;它允许用户将恶意代码植入到Web页面…

TTF字体包瘦身

需求 客户要求首页使用字体,分别为中文和英文格式 首页是基于H5的一个公众号 问题 客户给的字体较大,有两个格式的,分别是中文和英文的.单个都超过了10M, 如果未压缩,因为在首页,访问的次数多,会造成服务器资源紧张, 准备工作 下载好完整版客户提供的的.ttf文件。 下载好…

CSS字体样式属性调试

恶魔 不能# CSS字体样式属性调试 1.font-size font-size属性用于设置字号 p { font-size:20px;2.font-family font-family用于设置字体 p { font-family:"Mirsoft YaHei"&#xff1b; }网页中常用字体有宋体&#xff0c;微软雅黑&#xff0c;黑体等 可以同时指定…

【数据结构】常见排序算法——常见排序介绍、选择排序(直接选择排序、堆排序)交换排序(冒泡排序)

文章目录 1.常见排序2.选择排序2.1直接选择排序2.2堆排序 3.交换排序3.1冒泡排序 1.常见排序 2.选择排序 选择排序是一种简单但不高效的排序算法&#xff0c;其基本思想是从待排序的数据中选择最小&#xff08;或最大&#xff09;的元素放到已排序的数据末尾。具体操作步骤如下…

Netty的bytebuf详解

ByteBuf ByteBuf是对nio中ByteBuffer的增强。主要的增强点就是ByteBuf它可以动态调整容量大小&#xff0c;当要存储的数据超过了当前容量的上限就会进行扩容&#xff0c;扩容的上限是多少&#xff1f;扩容机制是什么&#xff1f;请跟着本文往下看。对了&#xff0c;还有一个增强…

Linux命令su、sudo、sudo su、sudo -i使用和区别

sudo 与 su 两个命令的最大区别是&#xff1a; sudo 命令需要输入当前用户的密码&#xff0c;su 命令需要输入 root 用户的密码。另外一个区别是其默认行为&#xff0c;sudo 命令只允许使用提升的权限运行单个命令&#xff0c;而 su 命令会启动一个新的 shell&#xff0c;同时…

FPGA DAC AD9764调试

AD9764 时钟频率125M 14位数据位 数值电压/V8192016384-30313653.3-227302 实测8267 电压近似为0