00001
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifdef HAVE_CONFIG_H
00026 # include <config.h>
00027 #endif
00028
00029 #if defined(HAVE_FREETYPE2) && !defined(__zaurus__)
00030
00031 #include <ft2build.h>
00032 #include FT_FREETYPE_H
00033
00034 #include <string.h>
00035 #include "vgafile.h"
00036
00037
00038
00039
00040
00041 static void Gen_shadow
00042 (
00043 unsigned char *pixels,
00044 int w, int h,
00045 unsigned char fg,
00046 unsigned char shadow
00047 )
00048 {
00049 int r, c;
00050
00051 for (r = 0; r < h; r++)
00052 for (c = 0; c < w; c++)
00053 {
00054 if (pixels[r*w+c] != fg)
00055 continue;
00056 int rr, cc;
00057 for (rr = r - 1; rr <= r + 1; rr++)
00058 {
00059 if (rr < 0 || rr >= h)
00060 continue;
00061 for (cc = c - 1; cc <= c + 1; cc++)
00062 if (cc >= 0 && cc < w &&
00063 pixels[rr*w+cc] != fg)
00064 pixels[rr*w+cc] = shadow;
00065 }
00066 }
00067 }
00068
00069
00070
00071
00072
00073
00074
00075
00076 bool Gen_font_shape
00077 (
00078 Shape *shape,
00079 const char *fontfile,
00080 int nframes,
00081 int pixels_ht,
00082 unsigned char fg,
00083 unsigned char bg,
00084 int shadow
00085 )
00086 {
00087 FT_Library library;
00088 int error = FT_Init_FreeType(&library);
00089 if (error)
00090 return false;
00091 FT_Face face;
00092 error = FT_New_Face(library, fontfile, 0, &face);
00093 if (error)
00094 return false;
00095 error = FT_Set_Pixel_Sizes(face, 0, pixels_ht);
00096
00097 FT_GlyphSlot glyph = face->glyph;
00098 if (error)
00099 return false;
00100 shape->resize(nframes);
00101 for (int chr = 0; chr < nframes; chr++)
00102 {
00103 error = FT_Load_Char(face, chr,
00104 FT_LOAD_RENDER|FT_LOAD_MONOCHROME);
00105 if (error)
00106 {
00107
00108 continue;
00109 }
00110 int w = glyph->bitmap.width, h = glyph->bitmap.rows;
00111 int sw = w, sh = h;
00112 int offset = 0;
00113 if (!sw)
00114 sw = glyph->metrics.horiAdvance/64;
00115 if (!sh)
00116 sh = glyph->metrics.vertAdvance/64;
00117 if (shadow != -1)
00118 {
00119 sw += 2;
00120 sh += 2;
00121 offset = 1;
00122 }
00123
00124 int cnt = sw*sh;
00125 unsigned char *pixels = new unsigned char[cnt];
00126 memset(pixels, bg, cnt);
00127
00128 unsigned char *src = glyph->bitmap.buffer;
00129 unsigned char *dest = pixels + offset*sw;
00130 for (int row = 0; row < h; row++)
00131 {
00132 for (int b = 0; b < w; b++)
00133 if (src[b/8]&(0x80>>(b%8)))
00134 dest[offset + b] = fg;
00135 dest += sw;
00136 src += glyph->bitmap.pitch;
00137 }
00138 if (shadow >= 0)
00139 Gen_shadow(pixels, sw, sh, fg, (unsigned char) shadow);
00140
00141 Shape_frame *frame = new Shape_frame(pixels,
00142 sw, sh, glyph->bitmap_left + offset,
00143 glyph->bitmap_top + offset, true);
00144 delete pixels;
00145 shape->set_frame(frame, chr);
00146 }
00147 FT_Done_FreeType(library);
00148 return true;
00149 }
00150
00151 #endif
00152