当前位置:网站首页>Transplantation of freetype Library
Transplantation of freetype Library
2022-07-03 07:59:00 【A chicken without learning】
freetype The migration of Libraries
freetype Depend on libpng, and libpng Depend on zlib, So we need to migrate three libraries in this migration , Each migration operation is similar , But the order cannot be reversed
1. transplant zlib library
1.1 download zlib library
Download address : zlib Official website
1.2 take zlib Move to linux Virtual machine , And extract the , Unzip and enter the directory
1. tar -xzf zlib-1.2.11.tar.gz
2. cd zlib-l.2.11/
1.3 Use configure To configure the makefile
1. export CC=arm-linux-gnueabihf-gcc # Your compiler , Mine may be different from yours
2. ./configure --prefix=/home/hxd/tools/zlib # prefix Used to specify the location of library installation
1.4 Use make && make install Installation Library
1. make
2. make install
After successful installation , You will get three directories under the installation directory you just set , Namely include/, lib/, share/
1.5 What will be obtained include/ Copy all files in the directory to the default search header directory of your compilation tool chain , What will be obtained lib/ Copy all the files in the directory to the directory of the default search library files of your compilation tool chain ( The purpose of this is that you don't need to add the path manually when compiling in the future , So this step can also be omitted )
1. echo "main(){}" | arm-linux-gnueabihf-gcc -E -v - # This command can view the default search path of the compilation tool , Choose the right one by yourself
- include route , I chose the path of my cross tool chain /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-DA3ud1CH-1656498779106)(D:\Myblog\blogimages\image-20220627213644947.png)]](/img/7e/6d87cd72dd7530d4b144f6ec7a1505.png)
cp -rfd /home/hxd/tools/zlib/include/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include # add -d The purpose of is to copy the linked file in this way , Save space
- lib route , I chose the path of my cross tool chain /usr/lib/gcc-cross/arm-linux-gnueabihf/9
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-HuaiIXRU-1656498779108)(D:\Myblog\blogimages\image-20220627213842124.png)]](/img/ee/b75475ba5c68e3c517e80f251b466f.png)
cp -rf /home/hxd/tools/zlib/lib/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/
1.6 Will be compiled zlib Migrate the library to the development board
Only need to lib/ Copy all files in the directory to the development board /usr/lib/ or /lib/ Next
1. First the zlib Folder copy nfs Under the directory of , Then the development board mounts the nfs
2. rm -rf /usr/lib/libz* /lib/libz* # If the library existed before , May interfere with each other , So delete the previous Library
3. cp -rfd /mnt/zlib/lib/* /usr/lib
2. transplant libpng library
2.1 download libpng library
Download address : Official website
2.2 take libpng Move to linux Virtual machine , And extract the , Unzip and enter the directory
1. tar -xJf libpng-1.6.37.tar.xz
2. cd libpng-l.6.37
2.3 perform ./configure
if It was done before 1.5 operation
1. ./configure --host=arm-linux-gnueabihf --prefix=/home/hxd/tools/libpng
else
1. export CFLAGS="$CFLAGS -I/home/hxd/tools/zlib/include" # With your zlib Installation path
2. export CPPFLAGS="$CPPFLAGS -I/home/hxd/tools/zlib/include"
3. export LDFLAGS="$LDFLAGS -L/home/hxd/tools/zlib/lib"
4. ./configure --host=arm-linux-gnueabihf --prefix=/home/hxd/tools/libpng
2.4 install
make && make install
2.5 Configure into the compilation chain , Convenient for later compilation ( Specific path 1.5 There's an explanation ), Also need to freetype2 All files in the directory are moved to freetype2 At the same directory
1. cp -rfd /home/hxd/tools/libpng/include/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include # add -d The purpose of is to copy the linked file in this way , Save space
2. cp -rf /home/hxd/tools/libpng/lib/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/
3. cp -rf /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include/freetype2/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include/
2.6 Migrate to development board
Need to put lib/ Copy all files in the directory to the development board /usr/lib/ or /lib/ Next
1. First the libpng Folder copy nfs Under the directory of , Then the development board mounts the nfs
2. rm -rf /usr/lib/libpng* /lib/libpng* # If the library existed before , May interfere with each other , So delete the previous Library
3. cp -rfd /mnt/libpng/lib/* /usr/lib
3. transplant freetype library
3.1 download
Download address : Official website
3.2 Move to linux Virtual machine , After decompressing , Enter this directory
1. tar -xJf freetype-2.10.2.tar.xz
2. cd freetype-2.10.2
3.3 Use configure To configure makefile
if Ahead 1.5 and 2.5 They are equipped with
1. ./configure --prefix=/home/hxd/tools/freetype --host=arm-linux-gnueabihf
elif No configuration in front
1. export CFLAGS="$CFLAGS -I/home/hxd/tools/zlib/include -I/home/hxd/tools/libpng/include" # With your zlib and libpng Installation path
2. export CPPFLAGS="$CPPFLAGS -I/home/hxd/tools/zlib/include -I/home/hxd/tools/libpng/include"
3. export LDFLAGS="$LDFLAGS -L/home/hxd/tools/zlib/lib -L/home/hxd/tools/libpng/lib"
4. ./configure --prefix=/home/hxd/tools/freetype --host=arm-linux-gnueabihf
3.4 install
make && make install
3.5 Configure it into the cross compilation tool chain , Convenient for later compilation ( Specific path 1.5 There's an explanation )
1. cp -rfd /home/hxd/tools/freetype/include/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/include # add -d The purpose of is to copy the linked file in this way , Save space
2. cp -rf /home/hxd/tools/freetype/lib/* /usr/lib/gcc-cross/arm-linux-gnueabihf/9/
3.6 Migrate to the development board
1. First the libpng Folder copy nfs Under the directory of , Then the development board mounts the nfs
2. rm -rf /usr/lib/libfreetype* /lib/libfreetype* # If the library existed before , May interfere with each other , So delete the previous Library
3. cp -rfd /mnt/libpng/lib/* /usr/lib
4. Use
4.1 If not configured 1.5,2.5,3.5
Compile the example :
arm-linux-gnueabihf-gcc test.c -o test -lz -lm -lpng -freetype -I/home/hxd/tools/freetype/include/freetype2 -L/home/hxd/tools/freetype/lib -L/home/hxd/tools/zlib/lib -L/home/hxd/tools/libpng/lib
4.2 If the
Compile the example :
arm-linux-gnueabihf-gcc test.c -o test -lz -lm -lpng -freetype
5. example ( Code from Weige )
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <linux/fb.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <wchar.h>
#include <sys/ioctl.h>
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H
int fd_fb;
struct fb_var_screeninfo var; /* Current var */
struct fb_fix_screeninfo fix; /* Current fix */
int screen_size;
unsigned char *fbmem;
unsigned int line_width;
unsigned int pixel_width;
/* color : 0x00RRGGBB */
void lcd_put_pixel(int x, int y, unsigned int color)
{
unsigned char *pen_8 = fbmem+y*line_width+x*pixel_width;
unsigned short *pen_16;
unsigned int *pen_32;
unsigned int red, green, blue;
pen_16 = (unsigned short *)pen_8;
pen_32 = (unsigned int *)pen_8;
switch (var.bits_per_pixel)
{
case 8:
{
*pen_8 = color;
break;
}
case 16:
{
/* 565 */
red = (color >> 16) & 0xff;
green = (color >> 8) & 0xff;
blue = (color >> 0) & 0xff;
color = ((red >> 3) << 11) | ((green >> 2) << 5) | (blue >> 3);
*pen_16 = color;
break;
}
case 32:
{
*pen_32 = color;
break;
}
default:
{
printf("can't surport %dbpp\n", var.bits_per_pixel);
break;
}
}
}
/********************************************************************** * The name of the function : draw_bitmap * Function description : according to bitmap Bitmap , stay LCD Display Chinese characters at the specified position * Input parameters : x coordinate ,y coordinate , Bitmap pointer * Output parameters : nothing * return return value : nothing * modification date Version number Modifier Modify the content * ----------------------------------------------- * 2020/05/12 V1.0 zh(angenao) establish ***********************************************************************/
void
draw_bitmap( FT_Bitmap* bitmap,
FT_Int x,
FT_Int y,
unsigned int color)
{
FT_Int i, j, p, q;
FT_Int x_max = x + bitmap->width;
FT_Int y_max = y + bitmap->rows;
//printf("x = %d, y = %d\n", x, y);
for ( j = y, q = 0; j < y_max; j++, q++ )
{
for ( i = x, p = 0; i < x_max; i++, p++ )
{
if ( i < 0 || j < 0 ||
i >= var.xres || j >= var.yres )
continue;
//image[j][i] |= bitmap->buffer[q * bitmap->width + p];
if (bitmap->buffer[q * bitmap->width + p]) lcd_put_pixel(i, j, color);
}
}
}
int compute_string_bbox(FT_Face face, wchar_t *wstr, FT_BBox *abbox)
{
int i;
int error;
FT_BBox bbox;
FT_BBox glyph_bbox;
FT_Vector pen;
FT_Glyph glyph;
FT_GlyphSlot slot = face->glyph;
/* initialization */
bbox.xMin = bbox.yMin = 32000;
bbox.xMax = bbox.yMax = -32000;
/* Specify the origin as (0, 0) */
pen.x = 0;
pen.y = 0;
/* Calculate the of each character bounding box */
/* First translate, Again load char, You can get its outer frame */
for (i = 0; i < wcslen(wstr); i++)
{
/* transformation :transformation */
FT_Set_Transform(face, 0, &pen);
/* Load bitmap : load glyph image into the slot (erase previous one) */
error = FT_Load_Char(face, wstr[i], FT_LOAD_RENDER);
if (error)
{
printf("FT_Load_Char error\n");
return -1;
}
/* Take out glyph */
error = FT_Get_Glyph(face->glyph, &glyph);
if (error)
{
printf("FT_Get_Glyph error!\n");
return -1;
}
/* from glyph Get the outer frame : bbox */
FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &glyph_bbox);
/* Update the outline */
if ( glyph_bbox.xMin < bbox.xMin )
bbox.xMin = glyph_bbox.xMin;
if ( glyph_bbox.yMin < bbox.yMin )
bbox.yMin = glyph_bbox.yMin;
if ( glyph_bbox.xMax > bbox.xMax )
bbox.xMax = glyph_bbox.xMax;
if ( glyph_bbox.yMax > bbox.yMax )
bbox.yMax = glyph_bbox.yMax;
/* Calculate the origin of the next character : increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
/* return string bbox */
*abbox = bbox;
}
int display_string(FT_Face face, wchar_t *wstr, int lcd_x, int lcd_y, unsigned int color, int angle)
{
int i;
int error;
FT_BBox bbox;
FT_Vector pen;
FT_Glyph glyph;
FT_GlyphSlot slot = face->glyph;
FT_Matrix matrix;
/* hold LCD Convert coordinates to Cartesian coordinates */
int x = lcd_x;
int y = var.yres - lcd_y;
/* Calculation frame */
compute_string_bbox(face, wstr, &bbox);
/* Push back the origin */
pen.x = (x - bbox.xMin) * 64; /* Company : 1/64 Pixels */
pen.y = (y - bbox.yMax) * 64; /* Company : 1/64 Pixels */
/* Rotation Angle */
/* set up matrix */
matrix.xx = (FT_Fixed)( cos( angle ) * 0x10000L );
matrix.xy = (FT_Fixed)(-sin( angle ) * 0x10000L );
matrix.yx = (FT_Fixed)( sin( angle ) * 0x10000L );
matrix.yy = (FT_Fixed)( cos( angle ) * 0x10000L );
/* Process each character */
for (i = 0; i < wcslen(wstr); i++)
{
/* transformation :transformation */
FT_Set_Transform(face, &matrix, &pen);
/* Load bitmap : load glyph image into the slot (erase previous one) */
error = FT_Load_Char(face, wstr[i], FT_LOAD_RENDER);
if (error)
{
printf("FT_Load_Char error\n");
return -1;
}
/* stay LCD Draw on : Use LCD coordinate */
draw_bitmap( &slot->bitmap,
slot->bitmap_left,
var.yres - slot->bitmap_top, color);
/* Calculate the origin of the next character : increment pen position */
pen.x += slot->advance.x;
pen.y += slot->advance.y;
}
return 0;
}
int main(int argc, char **argv)
{
wchar_t *wstr = L" Hello world !Hello World!";
FT_Library library;
FT_Face face;
int error;
FT_BBox bbox;
int font_size = 24;
int angle = 0;
int lcd_x, lcd_y;
if (argc < 4)
{
printf("Usage : %s <font_file> <lcd_x> <lcd_y> [font_size] [angle]\n", argv[0]);
return -1;
}
lcd_x = strtoul(argv[2], NULL, 0);
lcd_y = strtoul(argv[3], NULL, 0);
if (argc == 5)
font_size = strtoul(argv[4], NULL, 0);
if (argc == 6)
{
font_size = strtoul(argv[4], NULL, 0);
angle = atoi(argv[5]);
}
fd_fb = open("/dev/fb0", O_RDWR);
if (fd_fb < 0)
{
printf("can't open /dev/fb0\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_VSCREENINFO, &var))
{
printf("can't get var\n");
return -1;
}
if (ioctl(fd_fb, FBIOGET_FSCREENINFO, &fix))
{
printf("can't get fix\n");
return -1;
}
line_width = var.xres * var.bits_per_pixel / 8;
pixel_width = var.bits_per_pixel / 8;
screen_size = var.xres * var.yres * var.bits_per_pixel / 8;
fbmem = (unsigned char *)mmap(NULL , screen_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd_fb, 0);
if (fbmem == (unsigned char *)-1)
{
printf("can't mmap\n");
return -1;
}
/* Clear the screen : All set to black */
memset(fbmem, 0, screen_size);
error = FT_Init_FreeType( &library ); /* initialize library */
error = FT_New_Face( library, argv[1], 0, &face ); /* create face object */
FT_Set_Pixel_Sizes(face, font_size, 0);
printf("font_size: %d\n", font_size);
display_string(face, L" Hello world !Hello World!", lcd_x, lcd_y, 0x112233, angle);
display_string(face, L" Hello world !Hello World!", lcd_x, lcd_y+font_size, 0x222233, angle);
display_string(face, L" Hello world !Hello World!", lcd_x, lcd_y+font_size*2, 0x332233, angle);
display_string(face, L" Hello world !Hello World!", lcd_x, lcd_y+font_size*3, 0x442233, angle);
return 0;
}
边栏推荐
- Generate video using clipout in viz engine
- the installer has encountered an unexpected error installing this package
- I want to do large screen data visualization application feature analysis
- WorldView卫星遥感影像数据/米级分辨率遥感影像
- An intern's journey to cnosdb
- 华为交换机:配置telnet和ssh、web访问
- 华为交换机Console密码重置、设备初始化、默认密码
- Technology dry goods | Roberta of the migration of mindspore NLP model - emotion analysis task
- Go language - loop statement
- Huawei switches are configured with SSH login remote management switches
猜你喜欢

The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.

IP production stream is so close to me

*p++、*++p、++*p、(*p)++

Pat class a 1030 travel plan

PostGIS space function

C language learning notes (mind map)

【LeetCode】2. Valid parentheses · valid parentheses

I want to do large screen data visualization application feature analysis

My touch screen production "brief history" 1

An article for you to understand - Manchester code
随机推荐
Harmonyos third training notes
华为交换机基础配置(telnet/ssh登录)
[cocos creator] get the resource UUID
[MySQL 13] if you change your password for the first time after installing mysql, you can skip MySQL password verification to log in
链式长取值
The difference between hdmi2.1 and hdmi2.0 and the conversion of PD signals.
What is a data type? What is the use of data types?
[end of 2021] National Meteorological Short Video (Kwai, Tiktok) influence list in December
PostGIS space function
the installer has encountered an unexpected error installing this package
Pat class a 1031 Hello world for u
PHP微信抢红包的算法
Enter three times and guess a number
Iterm2 setting
Lua framwrok framework starts
haproxy+keepalived集群搭建02
tslib库的移植
Professor Zhang Yang of the University of Michigan is employed as a visiting professor of Shanghai Jiaotong University, China (picture)
[untitled]
How to clear the console password for s7700 device