[Item 2.3.4] 1_ eBook Lesson, 1 / 2_ display line / two lines of text on the LCD vectors

Host: VMWare - Ubuntu-16.04.2-x64-100ask
Development Board: Mini2440--256M of NandFlash, the NorFlash 2M, 64M the SDRAM, the LCD-TD35;
    bootlorder: U-boot1.16, Kernel: 4.3.2;
Compiler: arm-linux-gcc-4.3.2


 

2.3.4 _1_ displayed on the LCD display one line of text vector

The source base 02th_arm / 02th_arm / 02th_lcd / show_font.c the modification, renamed show_lines.c:
a vector font retention operation, remove the remaining independent code;.

Second, the problems and solutions
Source:
#include ...

fd_fb int;
static unsigned char * fbmem; start address / * fb of * /
static struct fb_var_screeninfo var;
static struct fb_fix_screeninfo FIX;
/ *
* Color: 0 x00RRGGBB
* /
static unsigned Short convert32to16 (int Color)
{
int Red, Green, Blue;
Red = (Color >> 16) & 0xFF;
Green = (Color >>. 8) & 0xFF;
Blue = (Color >> 0) & 0xFF;
return ((Red >>. 3) <<. 11) | (( >> 2 Green) <<. 5) | (Blue >>. 3); // Color: 565
}
/ * stippled
* Color: 32bit, 0 x00RRGGBB
* Ultimately, the data is filled in the frame buffer, and then scanned to the LCD display screen;
* /
static void fb_put_pixel (int X, Y int, unsigned int Color)
{
unsigned char * pen_8;
unsigned Short * pen_16;
unsigned int *pen_32;
unsigned char *pixel_base = fbmem + (var.xres*y + x)*var.bits_per_pixel/8;
switch(var.bits_per_pixel)
{
case 8:
pen_8 = (unsigned char *)pixel_base;
*pen_8 = color;
break;
case 16:
pen_16 = (unsigned short *)pixel_base;
*pen_16 = convert32to16(color);
break;
case 32:
pen_32 = (unsigned int *)pixel_base;
*pen_32 = color;
break;
default:
printf("can't surpport %dbpp\n", var.bits_per_pixel);
break;
}
}
/* 绘制字符位图 */
void draw_bitmap(FT_Bitmap * bitmap, FT_Int x, FT_Int y)
{
FT_Int i, j;
for(j = y; j < y + bitmap->rows; j++)
for(i = x; i < x + bitmap->width; i++)
{
if(i < 0 || j < 0 || i >= var.xres || j >= var.yres)
continue;
fb_put_pixel(i, j, bitmap->buffer[(j - y)*bitmap->width + (i - x)]);
}
}
int main(int argc, char **argv)
{
FT_Library library; // typedef struct FT_LibraryRec_ *FT_Library;
// typedef struct FT_LibraryRec_{ ... } FT_LibraryRec;
FT_Face face; // typedef struct FT_FaceRec_* FT_Face;
// typedef struct FT_FaceRec_
{...
FT_GlyphSlot glyph; ... //typedef struct FT_GlyphSlotRec_* FT_GlyphSlot;
//同下面的变量slot的类型一样;
} FT_FaceRec;

Slot FT_GlyphSlot; typedef struct // * FT_GlyphSlotRec_ FT_GlyphSlot;
// FT_GlyphSlotRec_ typedef struct
{...
FT_Library Library;
a FT_Face face;
FT_Glyph_Metrics metrics;
FT_Vector Advance; // The following variables of the same type as the pen;
// Vector:. N-vector, vector.
// advance: n progress, progress; adj advance; advance; vanguard...
The format FT_Glyph_Format;
FT_Bitmap Bitmap;
FT_Int of bitmap_left;
FT_Int bitmap_top;
...
} the FT_GlyphSlotRec;


FT_Vector PEN; / * unconverted starting point * /
typedef struct FT_Vector_
{
FT_Pos X; // typedef Signed Long FT_Pos;
FT_Pos Y;
} FT_Vector;
Matrix a simple FT_Matrix; / * Transformation Matrix * /
int error;
int I;
wchar_t wstr1 [] = L "network asked one hundred GIF";
wchar_t wstr2 [] = L "www.100ask.org";
/ * a, the LCD initialization * /
/ * II vector font display * /
error = FT_Init_FreeType (& Library) ; / * initialize Freetype libraries * /
IF (error) {. . . }
Error = the FT_New_Face (Library, the argv [. 1], 0, & face); / * open a font file * /
IF (error) {. . . }

Slot as face- => Glyph; // pointer variable slot which is stored
FT_Set_Pixel_Sizes (face, 24, 0) ; / * Font Size: 24x24 pixels * /

/ * determine the starting point coordinate:
* lcd_x = 0;
* = lcd_y 24;
* Cartesian coordinate system:
* = lcd_x X = 0;
* Y = var.yres - lcd_y = var.yres - 24;
* /
pen.x * 64 = 0;
pen.y = (var.yres - 24 ) * 64;

for (I = 0; I <wcslen (wstr1); I ++)
{
FT_Set_Transform (face, 0, & PEN); / * set the conversion parameters: rotation 0 * /

/ * The glyph code value loaded into the slot * /
/ * when the load is the glyph into the slot as face-> glyph * /
error = FT_Load_Char (face, chinese_str [I], the bit flag FT_LOAD_RENDER);
IF (error)
{
the printf ( " . FT_Load_Char error \ n-");
return -1;
}
draw_bitmap (& slot-> Bitmap,
slot-> of bitmap_left,
var.yres - slot-> bitmap_top);
/ * increase the pen position * /
pen.x + = slot- > advance.x;
}
return 0;
}
problem 1: for each replacement pen in position, and not for a variable slot () loop for explicit reassigned, but why can
pen.x + = slot-> advance .x;
pen.y + = slot-> advance.y;
increase the position of the pen?
A: = slot as face-> Glyph;
1. slot pointer variable is a pointer type structure: struct FT_GlyphSlotRec_ *;
2. face pointer variable is a pointer type structure: struct FT_FaceRec_ *;
3. The pointer variable face-> glyph pointer type member is a structure: struct FT_GlyphSlotRec_ *; and with the same type of slot;
before for () loop, slot-shaped structure pointer is given face-> glyph members


Question 2: Slot slot inside the data is automatically loaded it?
Conjecture and Corollary 1: pen.x + = slot-> advance.x ; pen position can be increased, demonstrating advance.x / y is the current vector
font chinese_str [i] of size (unit: pixels), and therefore among the storage slot is the moment vector font chinese_str [i]
of the glyph. Not variable and the slot for () loop is vector font chinese_str [i] re-assignment of explicit glyph,
but may be changed by the position of the pen slot-> advance.x / y, so inference data into the slot inside automatic loading.

Conjecture and Corollary 2: into the slot is a function of the data inside FT_Load_Char () automatically loaded.
/ * Load is the character wstr [i] of the glyph into the slot face-> glyph, then the new next time for () loop
glyph * characters into the slot, the slot will be overwritten.
*
* Note 1: The out glyph-> index to character wstr [i] of glyph loaded from the inside face.
* FT_LOAD_DEFAULT: no conversion to a bitmap, only exactly one of vector data, i.e., data glyph,
* depicted later time and then converted to a bitmap, it saves time.
* /
Error = of FT_Load_Glyph (face, glyph-> index, FT_LOAD_DEFAULT for the);
and a function of error = FT_Load_Char (face, wstr1 [ i], FT_LOAD_RENDER); / * load glyph to slot * / The encoded values
of the function corresponding to FT_Get_Char_Index () integrated three functions FT_Load_Glyph (), FT_Render_Glyph ().
Thus, into the slot in which the data should function FT_Load_Char () automatically loaded.


【注释】
1.FT_EXPORT( FT_Error ) FT_Set_Pixel_Sizes( FT_Face face, FT_UInt pixel_width, FT_UInt pixel_height );
//typedef unsigned int FT_UInt;

2.FT_EXPORT (FT_Error) FT_Load_Char (a FT_Face face, FT_ULong char_code, FT_Int32 The load_flags);
// typedef unsigned Long FT_ULong;
// typedef Signed XXX FT_Int32;
[A] Function
Analysis: an LCD in accordance with the frame buffer data from the LCD fb from left to right, from top to bottom scan understood, it is understood fb_put_pixel (x, y, color) ) of the parametric coordinate (x, y) coordinates are LCD.
Thus, draw_bitmap parameters (x, y) in the function (bitmap, x, y) coordinates are LCD, and top-left pixel coordinate origin do font.
And because draw_bitmap (& slot-> bitmap, slot- > bitmap_left, var.yres - slot-> bitmap_top), so:
slot-> bitmap_left font = x_LCD_ the top left corner, var.yres - slot-> bitmap_top = y_LCD_ upper left fonts angle.
So, slot-> bitmap_top = var.yres - y_LCD_ font = y_ upper left corner of the Cartesian coordinates _ fonts upper left corner.

 


Third, the compiler and the operating panel
a. From the left displays several lines of text
$ -finput ARM-Linux-GCC-charset = GBK -lm -o show_lines show_lines.c -lfreetype
# 32000000 NFS 192.168.0.106:/work/nfs_root/ uImage_lcd_3th; bootm 32000000
# 32000000 nfs 192.168.0.101:/work/nfs_root/uImage_lcd_3th; bootm 32000000


GB input code set is a code, but the memory array string chinese_str [] is stored inside the wide-character type,
the type of wide-character Unicode code that is inside.
If the source code is written in UTF-8, can not necessary to add -finput-charset = GBK parameter SourceInsight3 but
does not support the UTF-8 encoding (). Simplified Chinese mainland default GB code.

 

ARM-Linux-gcc $ -finput-charset = GBK -o show_lines_1 show_lines_1.c -lfreetype -lm
$ sudo cp show_lines_1 /work/nfs_root/fs_mini_mdev_new/driver_test3/2.3freetype/02th_arm/
# ./show_lines_1 ../../ simsun.ttc
// the LCD display: ask a hundred net gif

 

================================================== =====
------------------------------------
section 2.3.4 _2_ display two vector text line
1, print boxes?
Glyph FT_Glyph; / * A handle to Image The Glyph * /
FT_BBox BBOX; / * vector contains xMin each character, yMin; xMax, yMax; * /

for(i = 0; i < wcslen(wstr1); i++)
{
error = FT_Get_Glyph( face->glyph, &glyph );
if ( error )
{
printf("FT_Get_Glyph error!\n");
return -1;
}

FT_Glyph_Get_CBox( glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox );

}

补充:
typedef struct FT_BBox_
{
FT_Pos xMin, yMin;
FT_Pos xMax, yMax;

} FT_BBox;
<StructEntryTable> * /
/ * FT_BBox * /
/ * * /
/ * <the Description> * /
/ * A Structure Used to HOLD AN Outline apos the bounding Box, IE, The * /
/ * coordinates of ITS Extrema in The Horizontal vertical * and /
. / * directions
/ * translation: save contour bounding box structure, i.e., its extrema coordinates in the horizontal and vertical directions for.
/ * Outline: Overview; outline; Show ... contour; ... outline shape; outline; contour; sketch;
/ * the bounding: border;
modify the source code:
int line_box_ymin = 10000; // Cartesian coordinate system;
int = line_box_ymax 0; // Cartesian coordinate system;

pen.x * 64 = 0;
pen.y = (var.yres - (line_box_ymax - line_box_ymin + 24)) * 64;

for(i = 0; i < wcslen(wstr1); i++)
{
error = FT_Get_Glyph( face->glyph, &glyph );
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;
}


 

Guess you like

Origin www.cnblogs.com/xiaohujian/p/11318226.html