数码相框——2、3、3 在LCD上显示一个矢量字体

把上次的example.c 交叉编译(arm-linux-gcc)会出现很多错误,因为freetype还没交叉编译。
在PC运行freetype的编译过程:

tar -xjf freetype-2.4.10.tar.bz2
./configure make
sudo make install

我们要在开发板上显示文字,则要交叉编译freetype

1、freetype的交叉编译过程:

tar -xjf freetype-2.4.10.tar.bz2 

解压后,打开freetype-2.4.10,可以查看下:

vim docs/INSITALL.CROSS

 26  2. Configuration
 27   ----------------
 28
 29     2.1. Building and target system
 30
 31       To configure for  cross-build, the options `--host=<system>' and
 32       `--build=<system>' must be passed to configure.  For example, if
 33       your building  system is FreeBSD/i386  and the target  system is
 34       Linux/MIPS, say
 35
 36         ./configure \
 37           --build=i386-unknown-freebsd \
 38           --host=mips-ip22-linuxelf \
 39           [other options]

由此可知,配置的时候加上“–host=arm-linux” ,表示是在arm开发板下Linux上使用

但是默认是安装在/usr/local下,如文档所示,我们需要–prefix 指定目录:

 58     2.2. The prefix to install FreeType2
 59
 60       Setting `--prefix=<prefix>'  properly is important.   The prefix
 61       to install FreeType2 is  written into the freetype-config script
 62       and freetype2.pc configuration file.
 63
 64       If  the built  FreeType  2 library  is  used as  a  part of  the
 65       cross-building system,  the prefix  is expected to  be different
 66       from the self-building  system.  For example, configuration with
 67       `--prefix=/usr/local'  installs binaries  into  the system  wide
 68       `/usr/local'  directory  which  then  can't be  executed.   This
 69       causes confusion in configuration  of all applications which use
 70       FreeType2.   Instead,  use a  prefix to install  the cross-build
 71       into     a     separate     system    tree,     for     example,
 72       `--prefix=/usr/local/mips-ip22-linux/'.
 73
 74       On the other  hand, if the built FreeType2 is used  as a part of
 75       the target system, the prefix to install should reflect the file
 76       system structure of the target system.

查看环境变量:(为了查看交叉编译工具链在哪个目录)

echo $PATH

头文件:
在这里插入图片描述
库文件:
在这里插入图片描述

总结交叉编译的文件路径:
//编译出来的头文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
//编译出来的库文件应该放入:
/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib

头文件和库文件的路径不一样,
头文件目录 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr
库文件目录 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/
一般来说是一样的,
如果是一样的:“–prefix=/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr” 就可以了
但是这里不一样,就不能–prefix指定

因此我们先配置和编译,等下在手动放上面总结出的目录里:

./configure --host=arm-linux
make

如文档所示,安装后的东西放在指定临时目录的命令如下:

 94   4. Installation
 95   ---------------
 96
 97     Saying
 98
 99       make install
100
101     as usual to install FreeType2 into the directory tree specified by
102     the argument of the `--prefix' option.
103
104     As noted in section 2.2,  FreeType2  is sometimes configured to be
105     installed  into the  system directory  of the  target  system, and
106     should  not be installed  in the  cross-building system.   In such
107     cases, the  make variable `DESTDIR'  is useful to change  the root
108     directory in the installation.  For example, after
109
110       make DESTDIR=/mnt/target_system_root/ install
111
112     the built FreeType2 library files are installed into the directory
113     `/mnt/target_system_root/<prefix_in_configure>/lib'.

于是我们把安装的东西先放到一个临时文件夹里,看下是什么东西

make DESTDIR=$PWD/tmp install  //PWD是当前目录

我们手动放到将库文件和头文件放到编译环境里:
在这里插入图片描述

把tmp/usr/local/lib/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib :

sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/armv4t/lib -d -rf   
cp *so* /work/nfs_root/fs_mini_mdev_new/lib -d //放进开发板里

-d代表原来是链接文件复制过去还是链接文件

把tmp/usr/local/include/* 复制到 /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include :

sudo cp * /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include -rf

我们试着再次编译example,出现错误:

In file included from example1.c:11:
/usr/local/arm/4.3.2/bin/../arm-none-linux-gnueabi/libc/usr/include/ft2build.h:56:38: error: freetype/config/ftheader.h: No such file or directory

去freetype/config/目录里没有找到ftheader.h
为什么呢?

book@www.100ask.org:/usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include$ ls freetype2/freetype/config/ftheader.h

由此可见我们多了freetype2文件夹,
怎么解决?
像之前一样编译的时候加上 -I参数:
-I /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include/freetype2/
为了方便,我们直接把freetype目录移出来:

cd /usr/local/arm/4.3.2/arm-none-linux-gnueabi/libc/usr/include
mv freetype2/freetype .

编译:

arm-linux-gcc -finput-charset=GBK -fexec-charset=GBK -o show_font show_font.c -lfreetype -lm 

2、修改example.c
运行example.c在控制台上就可以看到结果。
但是我们想在LCD上显示,因此结合show_font.c和example.c。

补充知识:bitmap里的成员:
rows,即位图中的水平线数

width,位图的水平象素数

pitch, 它的绝对值是位图每行占的字节数,根据位图向量方向,可以是正值或是负值
buffer,一个指向位图象素缓冲的无类型指针

在这里插入图片描述

3、 运行

运行后我们发现show_font.c是GBK码于是我们加上以下命令将GBK转换位UTF-8

-finput-charset=GBK 表示源文件的编码方式,默认以UTF-8来解析
-fexec-charset=GBK 表示可执行程序里的字节以什么编码方式来表示

在这里插入图片描述
但是还是无法转换。

我们查看下charset:

man gcc
/charset

在这里插入图片描述
这里说,charset可以转换成被iconv所支持的字符集
于是我们查看下 iconv是怎么用的:

iconv --hel

在这里插入图片描述
我们查看下show_font.c 为何无法从GBK转换为UTF-8:

iconv -f GBK -t UTF-8 show_font.c

在这里插入图片描述
说明运行到这里的时候无法转换

我们把这里的字符删了:
在这里插入图片描述
4、 变换角度
在这里插入图片描述
我们把argv[2] 输入角度,
用strtoul()函数转换为ul类型

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值