- 1月 09 週日 201121:53
邊框字
- 1月 01 週六 201119:35
bdf點陣字(二)
上一個方法,由於bdf檔是即時讀取,所以效能較差。
所以我利用bdf2c產生字型的font.h和font.c檔案
之後只要
#include "font.h"
所以我利用bdf2c產生字型的font.h和font.c檔案
之後只要
#include "font.h"
- 1月 01 週六 201116:37
bdf點陣字
bdf font是文字格式的點陣字型我是將unifont(unicode bdf font),掃成我定義的bitmap格式
1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1111111 1111 11111111111 1 1 1 11111 1
1 1 1 1 1111111 1 1 1 1 1 1
1 1 1 1 1 11 1 1 111 1 1 111
1 1 1 1 1 1 1 1 1 1 1 11111 1
11111111 111111 1111111111 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1111 1 1 1111
1 1 1 1 1 1 1 1111111111 1 11111 1
1111111 1 1 1 1 1 1 1
1 1 1 111111111111111 1 1 1 111111111111111
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 11 1 11
1 1 1 1 1 1 1 1 11 1 11
1 1 1 1 1 1 11 1
- 12月 31 週五 201016:45
利用Qt轉出bitmap點陣字
一般轉點陣字都是用win api
不過我來寫一個Qt的方式
觀念是一樣的
先將字畫出來,在擷取下來,轉成點陣圖
所以我的作法是
不過我來寫一個Qt的方式
觀念是一樣的
先將字畫出來,在擷取下來,轉成點陣圖
所以我的作法是
- 12月 31 週五 201016:07
利用freetype轉出bitmap點陣字
rasters是利用freetype將特定字型文字轉成bitmap字串。
bool rasters(const wchar_t texts[], Bitmap *bitmap)
{
if(texts[0] == '\0') {
return true;
}
FT_Library library;
if (FT_Init_FreeType(&library)) {
return false;
}
FT_Face face;
if(FT_New_Face(library, "C:/WINDOWS/Fonts/MINGLIU.TTC", 0, &face)) {
FT_Done_FreeType(library);
return false;
}
int pixalWidth = 36;
int pixalHeight = 36;
if(FT_Set_Pixel_Sizes(face, pixalWidth, pixalHeight)) {
FT_Done_Face(face);
FT_Done_FreeType(library);
return false;
}
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
for(int i=0; i<wcslen(texts); i++) {
unsigned int ucode = texts[i];
FT_UInt glyph_index = FT_Get_Char_Index(face, ucode);
if(!glyph_index) {
continue;
}
if (FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT)) {
continue;
}
if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP) {
if (FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO)) {
continue;
}
}
Bitmap font = { face->glyph->bitmap_left,
face->glyph->bitmap_top - face->glyph->bitmap.rows,
face->glyph->bitmap.width,
face->glyph->bitmap.rows,
face->glyph->bitmap.pitch,
face->glyph->bitmap.buffer
};
combinetext(bitmap, &font);
}
FT_Done_Face(face);
FT_Done_FreeType(library);
return true;
}
bool rasters(const wchar_t texts[], Bitmap *bitmap)
{
if(texts[0] == '\0') {
return true;
}
FT_Library library;
if (FT_Init_FreeType(&library)) {
return false;
}
FT_Face face;
if(FT_New_Face(library, "C:/WINDOWS/Fonts/MINGLIU.TTC", 0, &face)) {
FT_Done_FreeType(library);
return false;
}
int pixalWidth = 36;
int pixalHeight = 36;
if(FT_Set_Pixel_Sizes(face, pixalWidth, pixalHeight)) {
FT_Done_Face(face);
FT_Done_FreeType(library);
return false;
}
FT_Select_Charmap(face, FT_ENCODING_UNICODE);
for(int i=0; i<wcslen(texts); i++) {
unsigned int ucode = texts[i];
FT_UInt glyph_index = FT_Get_Char_Index(face, ucode);
if(!glyph_index) {
continue;
}
if (FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT)) {
continue;
}
if (face->glyph->format != FT_GLYPH_FORMAT_BITMAP) {
if (FT_Render_Glyph(face->glyph, FT_RENDER_MODE_MONO)) {
continue;
}
}
Bitmap font = { face->glyph->bitmap_left,
face->glyph->bitmap_top - face->glyph->bitmap.rows,
face->glyph->bitmap.width,
face->glyph->bitmap.rows,
face->glyph->bitmap.pitch,
face->glyph->bitmap.buffer
};
combinetext(bitmap, &font);
}
FT_Done_Face(face);
FT_Done_FreeType(library);
return true;
}
- 12月 31 週五 201016:06
將二個bitmap合成一個bitmap(印出bitmap字串)
之前有寫一個印出bitmap字的程式
現在將這個功能擴充成印出bitmap字串
void combinetext(Bitmap *bitmap, Bitmap *font)
{
int x1 = bitmap->x;
int y1 = bitmap->y;
unsigned int width1 = bitmap->width;
unsigned int height1 = bitmap->height;
unsigned int pitch1 = bitmap->pitch;
unsigned char* data1 = bitmap->data;
int x2 = x1 + width1 + font->x;
int y2 = font->y;
unsigned int width2 = font->width;
unsigned int height2 = font->height;
unsigned int pitch2 = font->pitch;
unsigned char* data2 = font->data;
int x3 = x1;
if(x1 > x2) {
x3 = x2;
}
unsigned int width3 = width1 + font->x + width2;
int y3 = y1;
unsigned int height3 = height1;
if(y1 > y2) {
y3 = y2;
height3 += (y1 - y2);
}
if(y1+height1 < y2+height2) {
height3 += (y2+height2) - (y1+height1);
}
unsigned int pitch3 = width3/8;
if(width3 % 8 != 0) {
pitch3 += 1;
}
int size3 = pitch3 * height3;
unsigned char *data3 = calloc(size3, sizeof(unsigned char));
int shiftX1 = 0;
int shiftY1 = (height3+y3) - (height1+y1);
for(int j=0; j<height1; j++) {
int nj = j+shiftY1;
for(int i=0; i<pitch1; i++) {
int n = shiftX1/8+i+nj*pitch3;
unsigned char data = data1[i+j*pitch1];
int shift = shiftX1%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
int shiftX2 = x2-x3;
int shiftY2 = (height3+y3) - (height2+y2);
for(int j=0; j<height2; j++) {
int nj = j+shiftY2;
for(int i=0; i<pitch2; i++) {
int n = shiftX2/8+i+nj*pitch3;
unsigned char data = data2[i+j*pitch2];
int shift = shiftX2%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
free(bitmap->data);
bitmap->x = x3;
bitmap->y = y3;
bitmap->width = width3;
bitmap->height = height3;
bitmap->pitch = pitch3;
bitmap->data = data3;
}
現在將這個功能擴充成印出bitmap字串
void combinetext(Bitmap *bitmap, Bitmap *font)
{
int x1 = bitmap->x;
int y1 = bitmap->y;
unsigned int width1 = bitmap->width;
unsigned int height1 = bitmap->height;
unsigned int pitch1 = bitmap->pitch;
unsigned char* data1 = bitmap->data;
int x2 = x1 + width1 + font->x;
int y2 = font->y;
unsigned int width2 = font->width;
unsigned int height2 = font->height;
unsigned int pitch2 = font->pitch;
unsigned char* data2 = font->data;
int x3 = x1;
if(x1 > x2) {
x3 = x2;
}
unsigned int width3 = width1 + font->x + width2;
int y3 = y1;
unsigned int height3 = height1;
if(y1 > y2) {
y3 = y2;
height3 += (y1 - y2);
}
if(y1+height1 < y2+height2) {
height3 += (y2+height2) - (y1+height1);
}
unsigned int pitch3 = width3/8;
if(width3 % 8 != 0) {
pitch3 += 1;
}
int size3 = pitch3 * height3;
unsigned char *data3 = calloc(size3, sizeof(unsigned char));
int shiftX1 = 0;
int shiftY1 = (height3+y3) - (height1+y1);
for(int j=0; j<height1; j++) {
int nj = j+shiftY1;
for(int i=0; i<pitch1; i++) {
int n = shiftX1/8+i+nj*pitch3;
unsigned char data = data1[i+j*pitch1];
int shift = shiftX1%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
int shiftX2 = x2-x3;
int shiftY2 = (height3+y3) - (height2+y2);
for(int j=0; j<height2; j++) {
int nj = j+shiftY2;
for(int i=0; i<pitch2; i++) {
int n = shiftX2/8+i+nj*pitch3;
unsigned char data = data2[i+j*pitch2];
int shift = shiftX2%8;
if(shift == 0) {
data3[n] |= data;
} else {
data3[n] |= (0x7f & data>>shift);
data3[n+1] |= data<<(8-shift);
}
}
}
free(bitmap->data);
bitmap->x = x3;
bitmap->y = y3;
bitmap->width = width3;
bitmap->height = height3;
bitmap->pitch = pitch3;
bitmap->data = data3;
}
- 6月 23 週三 201011:52
print bitmap font array
先定義一下bitmap格式方便之後處裡typedef struct Bitmap_ {int x;
int y;
unsigned int width;
unsigned int height;
unsigned int pitch;
unsigned char* data;
} Bitmap;
1
上星期突然有個想法,為何不能印出邊框字呢