使用freetype庫在LCD顯示多行內容

2021-10-24 04:57:55 字數 3859 閱讀 8635

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#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)

case16:

case32:

default:}

}/* replace this function with something useful. */

void

draw_bitmap

(ft_bitmap* bitmap, ft_int x, ft_int y)

}return;}

intmain

(int argc,

const

char

*ar**)

fd_fb =

open

("/dev/fb0"

, o_rdwr);if

(fd_fb <0)

if(ioctl

(fd_fb, fbioget_vscreeninfo,

&var))if

(ioctl

(fd_fb, fbioget_fscreeninfo,

&fix)

) 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)/* 清屏: 全部設為黑色 */

memset

(fbmem,

0, screen_size)

;/* 初始化向量字型 */

error =

ft_init_freetype

(&library)

;/* initialize library */

/* error handling omitted */

if(error !=0)

error =

ft_new_face

(library, ar**[1]

,0,&face)

;/* create face object */

/* error handling omitted */

if(error !=0)

slot = face->glyph;

error =

ft_set_pixel_sizes

(face,24,

0);if

(error !=0)

/* 確定座標,顯示第一行內容:

* lcd_x = 0

* lcd_y = 24

* 笛卡爾座標系:

* x = lcd_x = 0

* y = var.yres - lcd_y = var.yres - 24

*/pen.x =0*

64;pen.y =

(var.yres -24)

*64;for

(i =

0; i <

wcslen

(wstr1)

; i++

) error =

ft_get_glyph

(face->glyph,

&glyph);if

(error)

ft_glyph_get_cbox

(glyph, ft_glyph_bbox_truncate,

&bbox);if

(line_box_ymin > bbox.ymin)

line_box_ymin = bbox.ymin;

if(line_box_ymax < bbox.ymax)

line_box_ymax = bbox.ymax;

draw_bitmap

(&slot->bitmap, slot->bitmap_left, var.yres - slot->bitmap_top)

;/* increment pen position */

pen.x +

= slot->advance.x;

+= slot->advance.y;

}/* 確定座標,顯示第二行內容:

* lcd_x = 0

* lcd_y = line_box_ymax - line_box_ymin + 24

* 笛卡爾座標系:

freetype 使用小結

freetype是乙個完全開源的 可擴充套件 可定製且可移植的字型引擎,它提供truetype字型驅動的實現統一的介面來訪問多種字型格式檔案,包括點陣字 truetype opentype type1 cid cff windows fon fnt x11 pcf等。freetype函式庫具有以下特...

初探freetype字型庫

文字的顯示依賴於字型字型檔,大致的字型字型檔分為點陣字型檔 筆畫字型檔和輪廓字型檔。點陣字型檔 缺點比較明顯,縮放存在鋸齒,渲染旋轉等操作相對複雜,且效果不理想,先大多用在嵌入式行業 基本拋棄 常見格式有bdf,pcf,fnt,hbf,hzf等。筆畫字型 不討論。輪廓字型 即向量字型,利用字型輪廓及...

freetype的使用及總結

總結 1 首先建立乙個庫 2 根據字型檔案得到face object 3 設定字型大小及第乙個座標值 4 載入face得到字型的glyph及buffer 5 顯示 每次顯示乙個字元都是根據前乙個字元的glyph得到下乙個字元座標的原點值,這樣方便顯示 include include include ...