1.Requirement
nano-X support GZIP PCF fonts
字型可用firefly
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR11.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR12.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR13.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR14.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR15.pcf.gz
http://cle.linux.org.tw/fonts/FireFly/bitmaps/pcf/fireflyR16.pcf.gz
在PC上產生fonts.dir在加以修改
[gigijoe@localhost fonts]$ ls
fireflyR13.pcf.gz fireflyR16.pcf.gz
[gigijoe@localhost fonts]$ mkfontdir
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-firefly new sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-firefly new sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改成
[gigijoe@localhost fonts]$ cat fonts.dir
2
fireflyR13.pcf.gz -firefly-sung-medium-r-normal--13-120-75-75-p-129-iso10646-1
fireflyR16.pcf.gz -firefly-sung-medium-r-normal--16-150-75-75-p-159-iso10646-1
修改 x11/Font_xlfd.cxx
////////////////////////////////////////////////////////////////
// The predefined fonts that fltk has:
static IFont fonts [] = {
{{"helvetica",0}, "-*-helvetica-medium-r-normal--*", fonts+1, fonts+2},
{{"helvetica",1}, "-*-helvetica-bold-r-normal--*", fonts+1, fonts+3},
{{"helvetica",2}, "-*-helvetica-medium-o-normal--*", fonts+3, fonts+2},
{{"helvetica",3}, "-*-helvetica-bold-o-normal--*", fonts+3, fonts+3},
{{"courier", 0}, "-*-courier-medium-r-normal--*", fonts+5, fonts+6},
{{"courier", 1}, "-*-courier-bold-r-normal--*", fonts+5, fonts+7},
{{"courier", 2}, "-*-courier-medium-o-normal--*", fonts+7, fonts+6},
{{"courier", 3}, "-*-courier-bold-o-normal--*", fonts+7, fonts+7},
{{"times", 0}, "-*-times-medium-r-normal--*", fonts+9, fonts+10},
{{"times", 1}, "-*-times-bold-r-normal--*", fonts+9, fonts+11},
{{"times", 2}, "-*-times-medium-i-normal--*", fonts+11,fonts+10},
{{"times", 3}, "-*-times-bold-i-normal--*", fonts+11,fonts+11},
{{"symbol", 0}, "-*-symbol-*", fonts+12,fonts+12},
{{"lucidatypewriter", 0}, "-*-lucidatypewriter-medium-r-normal-sans-*", fonts+14,fonts+14},
{{"lucidatypewriter", 1}, "-*-lucidatypewriter-bold-r-normal-sans-*", fonts+14,fonts+14},
{{"zapf dingbats", 0}, "-*-*zapf dingbats-*", fonts+15,fonts+15},
{{"sung", 0}, "-*-sung-medium-*-*--*", fonts+16,fonts+16},
};
fltk::Font* const fltk::HELVETICA = &(fonts[0].f);
fltk::Font* const fltk::HELVETICA_BOLD = &(fonts[1].f);
fltk::Font* const fltk::HELVETICA_ITALIC = &(fonts[2].f);
fltk::Font* const fltk::HELVETICA_BOLD_ITALIC = &(fonts[3].f);
fltk::Font* const fltk::COURIER = &(fonts[4].f);
fltk::Font* const fltk::COURIER_BOLD = &(fonts[5].f);
fltk::Font* const fltk::COURIER_ITALIC = &(fonts[6].f);
fltk::Font* const fltk::COURIER_BOLD_ITALIC = &(fonts[7].f);
fltk::Font* const fltk::TIMES = &(fonts[8].f);
fltk::Font* const fltk::TIMES_BOLD = &(fonts[9].f);
fltk::Font* const fltk::TIMES_ITALIC = &(fonts[10].f);
fltk::Font* const fltk::TIMES_BOLD_ITALIC = &(fonts[11].f);
fltk::Font* const fltk::SYMBOL_FONT = &(fonts[12].f);
fltk::Font* const fltk::SCREEN_FONT = &(fonts[13].f);
fltk::Font* const fltk::SCREEN_BOLD_FONT = &(fonts[14].f);
fltk::Font* const fltk::ZAPF_DINGBATS = &(fonts[15].f);
fltk::Font* const fltk::SUNG = &(fonts[16].f);
/*! For back-compatabilty with FLTK1, this turns an integer into one
of the built-in fonts. 0 = HELVETICA. */
fltk::Font* fltk::font(int i) {return &(fonts[i%16].f);}
修改 src/Style.cxx
// Do not change the contents of this ever. The themes depend on getting
// a known state initially. Make sure the documentation below matches the
// default values!
static void revert(Style* s) {
s->parent_ = 0; // this is the topmost style always
s->box_ = DOWN_BOX;
s->buttonbox_ = UP_BOX;
s->glyph_ = Widget::default_glyph;
s->labelfont_ = SUNG;
s->textfont_ = SUNG;
s->labeltype_ = NORMAL_LABEL;
s->color_ = WHITE; // GRAY99?
s->textcolor_ = BLACK;
s->selection_color_ = WINDOWS_BLUE;
s->selection_textcolor_= WHITE;
s->buttoncolor_ = GRAY75;
s->labelcolor_ = BLACK;
s->highlight_color_ = NO_COLOR;
s->highlight_textcolor_= NO_COLOR;
s->labelsize_ = 12;
s->textsize_ = 12;
s->leading_ = 2;
s->scrollbar_width_ = 15;
s->scrollbar_align_ = ALIGN_RIGHT|ALIGN_BOTTOM;
}
修改 fltk/Style.h
struct Font;
extern FL_API Font* const HELVETICA;
extern FL_API Font* const HELVETICA_BOLD;
extern FL_API Font* const HELVETICA_ITALIC;
extern FL_API Font* const HELVETICA_BOLD_ITALIC;
extern FL_API Font* const COURIER;
extern FL_API Font* const COURIER_BOLD;
extern FL_API Font* const COURIER_ITALIC;
extern FL_API Font* const COURIER_BOLD_ITALIC;
extern FL_API Font* const TIMES;
extern FL_API Font* const TIMES_BOLD;
extern FL_API Font* const TIMES_ITALIC;
extern FL_API Font* const TIMES_BOLD_ITALIC;
extern FL_API Font* const SYMBOL_FONT;
extern FL_API Font* const SCREEN_FONT;
extern FL_API Font* const SCREEN_BOLD_FONT;
extern FL_API Font* const ZAPF_DINGBATS;
extern FL_API Font* const SUNG;
patch
轉載
http://tw.myblog.yahoo.com/jw!GdTvlQ.YCR8E9rpahh6eqfZX9g--/article?mid=163&prev=164&next=149&l=f&fid=17
--- microwindows-0.91-old/src/engine/font_pcf.c 2003-06-16 11:20:09.000000000 +0800
+++ microwindows-0.91-new/src/engine/font_pcf.c 2008-01-10 14:28:37.000000000 +0800
@@ -245,6 +245,37 @@
return dwswap(n);
}
+/* read a 16-bit integer MSB16 format*/
+static unsigned short
+readMSB16(FILEP file)
+{
+ unsigned short s;
+
+ FREAD(file, &s, sizeof(s));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((s) << 8) & 0xff00) | (((s) >> 8) & 0x00ff));
+#else
+ return s;
+#endif
+}
+
+/* read a 32-bit integer MSB32 format*/
+static unsigned long
+readMSB32(FILEP file)
+{
+ unsigned long n;
+
+ FREAD(file, &n, sizeof(n));
+#if !MW_CPU_BIG_ENDIAN
+ return ((((n) << 24) & 0xff000000L) | \
+ (((n) << 8) & 0x00ff0000L) | \
+ (((n) >> 8) & 0x0000ff00L) | \
+ (((n) >> 24) & 0x000000ffL) );
+#else
+ return n;
+#endif
+}
+
/* Get the offset of the given field */
static int
pcf_get_offset(int item)
@@ -272,21 +303,26 @@
struct prop_entry *p;
unsigned char *string_buffer, *spos;
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_PROPERTIES)) == -1)
return (-1);
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
- num_props = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_props = read32(file);
p = *prop = (struct prop_entry *) malloc(num_props *
sizeof(struct prop_entry));
for (i = 0; i < num_props; i++) {
- p[i].name = readLSB32(file);
+ p[i].name = read32(file);
p[i].is_string = readINT8(file);
- p[i].value = readLSB32(file);
+ p[i].value = read32(file);
}
/* Pad to 32 bit multiples */
@@ -295,7 +331,7 @@
/* Read the entire set of strings into memory */
- ssize = readLSB32(file);
+ ssize = read32(file);
spos = string_buffer = (unsigned char *) ALLOCA(ssize);
FREAD(file, string_buffer, ssize);
@@ -333,6 +369,7 @@
unsigned long *o;
unsigned char *b;
unsigned long bmsize[GLYPHPADOPTIONS];
+ unsigned long (*read32)(FILEP);
if ((offset = pcf_get_offset(PCF_BITMAPS)) == -1)
return -1;
@@ -340,15 +377,18 @@
format = readLSB32(file);
endian = (format & PCF_BIT_MASK)? PCF_LSB_FIRST: PCF_MSB_FIRST;
-
- num_glyphs = readLSB32(file);
+ if (endian == PCF_LSB_FIRST)
+ read32 = readMSB32;
+ else
+ read32 = readLSB32;
+ num_glyphs = read32(file);
o = *offsets = (unsigned long *)malloc(num_glyphs * sizeof(unsigned long));
for (i=0; i < num_glyphs; ++i)
- o[i] = readLSB32(file);
+ o[i] = read32(file);
for (i=0; i < GLYPHPADOPTIONS; ++i)
- bmsize[i] = readLSB32(file);
+ bmsize[i] = read32(file);
pad = format & PCF_GLYPH_PAD_MASK;
*bits_size = bmsize[pad]? bmsize[pad] : 1;
@@ -358,14 +398,9 @@
FREAD(file, b, *bits_size);
/* convert bitmaps*/
- bit_order_invert(b, *bits_size);
-#if MW_CPU_BIG_ENDIAN
- if (endian == PCF_LSB_FIRST)
- two_byte_swap(b, *bits_size);
-#else
if (endian == PCF_MSB_FIRST)
- two_byte_swap(b, *bits_size);
-#endif
+ bit_order_invert(b, *bits_size);
+ two_byte_swap(b, *bits_size);
return num_glyphs;
}
@@ -376,29 +411,39 @@
long i, size, offset;
unsigned long format;
struct metric_entry *m;
+ unsigned long (*read32)(FILEP);
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_METRICS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK) {
+ read16 = readMSB16;
+ read32 = readMSB32;
+ }
+ else {
+ read16 = readLSB16;
+ read32 = readLSB32;
+ }
if ((format & PCF_FORMAT_MASK) == PCF_DEFAULT_FORMAT) {
- size = readLSB32(file); /* 32 bits - Number of metrics*/
+ size = read32(file); /* 32 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
for (i=0; i < size; i++) {
- m[i].leftBearing = readLSB16(file);
- m[i].rightBearing = readLSB16(file);
- m[i].width = readLSB16(file);
- m[i].ascent = readLSB16(file);
- m[i].descent = readLSB16(file);
- m[i].attributes = readLSB16(file);
+ m[i].leftBearing = read16(file);
+ m[i].rightBearing = read16(file);
+ m[i].width = read16(file);
+ m[i].ascent = read16(file);
+ m[i].descent = read16(file);
+ m[i].attributes = read16(file);
}
} else {
- size = readLSB16(file); /* 16 bits - Number of metrics*/
+ size = read16(file); /* 16 bits - Number of metrics*/
m = *metrics = (struct metric_entry *) malloc(size *
sizeof(struct metric_entry));
@@ -421,30 +466,35 @@
long offset, n;
unsigned long format;
struct encoding_entry *e;
+ unsigned short (*read16)(FILEP);
if ((offset = pcf_get_offset(PCF_BDF_ENCODINGS)) == -1)
return -1;
FSEEK(file, offset, SEEK_SET);
format = readLSB32(file);
+ if (format & PCF_BIT_MASK)
+ read16 = readMSB16;
+ else
+ read16 = readLSB16;
e = *encoding = (struct encoding_entry *)
malloc(sizeof(struct encoding_entry));
- e->min_byte2 = readLSB16(file);
- e->max_byte2 = readLSB16(file);
- e->min_byte1 = readLSB16(file);
- e->max_byte1 = readLSB16(file);
- e->defaultchar = readLSB16(file);
+ e->min_byte2 = read16(file);
+ e->max_byte2 = read16(file);
+ e->min_byte1 = read16(file);
+ e->max_byte1 = read16(file);
+ e->defaultchar = read16(file);
e->count = (e->max_byte2 - e->min_byte2 + 1) *
(e->max_byte1 - e->min_byte1 + 1);
e->map = (unsigned short *) malloc(e->count * sizeof(unsigned short));
DPRINTF("def char %d (%x)\n", e->defaultchar, e->defaultchar);
for (n = 0; n < e->count; ++n) {
- e->map[n] = readLSB16(file);
+ e->map[n] = read16(file);
/*DPRINTF("ncode %x (%c) %x\n", n, n, e->map[n]);*/
}
- DPRINTF("size %d byte1 %d,%d byte2 %d,%d\n", e->count,
+ DPRINTF("size %ld byte1 %d,%d byte2 %d,%d\n", e->count,
e->min_byte1, e->max_byte1, e->min_byte2, e->max_byte2);
return e->count;
}
2.Compile procdure as FLTK
3.修改 test/utf8.cxx
//"-*-fixed-*-*-*--*-*-*-*-*-*-gost19768.74-*,"
"-*-fixed-*-iso10646-1"*/
/*"-*-unifont-*-*-*-*-*-*-*-*-*-*-iso10646-1"*/ <<-- Mark這行
"-*-sung-medium-*-*--*-*-*-*-*-*-iso10646-1" <<-- 加入這行,這樣才會認得firefly字型
#if 0
xchar arabic1[] ={/*8238,*/ 1610, 0x20, 1608, 0x20, 1606, 0x20, 1616, 0x20, 1603, 0x20, 1608, 0x20, 1583, 0};
l = fl_unicode2utf(arabic1, 14, abuf);
abuf[l] = 0;
#endif
strcpy(abuf, "中華電信");
4.run utf8
沒有留言:
張貼留言