nanogui@linuxhacker.org
/*
* Draw ascii text using COREFONT type font.
*/
void
corefont drawtext(PMWFONT pfont, PSD psd, MWCOORD x, MWCOORD y,
const void *text, int cc, int flags)
{
const unsigned char *str = text;
MWCOORD width; /* width of text area */
MWCOORD height; /* height of text area */
MWCOORD base; /* baseline of text*/
MWCOORD startx, starty;
/* bitmap for characters */
MWIMAGEBITS bitmap[MAX CHAR HEIGHT*MAX CHAR WIDTH/MWIMAGE BITSPERIMAGE];
pfont->fontprocs->GetTextSize(pfont, str, cc, &width, &height, &base);
if(flags & MWTF BASELINE)
y -= base;
else if(flags & MWTF BOTTOM)
y -= (height - 1);
startx = x;
starty = y + base;
switch (GdClipArea(psd, x, y, x + width - 1, y + height - 1)) {
case CLIP VISIBLE:
/*
* For size considerations, there's no low-level text
* draw, so we've got to draw all text
* with per-point clipping for the time being
if (gr usebg)
psd->FillRect(psd, x, y, x + width - 1, y + height - 1,
gr background);
psd->DrawText(psd, x, y, str, cc, gr foreground, pfont);
GdFixCursor(psd);
return;
*/
break;
case CLIP INVISIBLE:
return;
}
/* Get the bitmap for each character individually, and then display
* them using clipping for each one.
*/
while (--cc >= 0 && x < psd->xvirtres) {
unsigned int ch = *str++;
+#if HAVE BIG5 SUPPORT
+ /* chinese big5 decoding*/
+ if (ch >= 0xA1 && ch <= 0xF9 && cc >= 1 &&
+ ((*str >= 0x40 && *str <= 0x7E) ||
+ (*str >= 0xA1 && *str <= 0xFE)) ) {
+ ch = (ch << 8) | *str++;
+ --cc;
+ }
+#endif
#if HAVE GB2312 SUPPORT
/* chinese gb2312 decoding*/
if (ch >= 0xA1 && ch < 0xF8 && cc >= 1 &&
*str >= 0xA1 && *str < 0xFF) {
ch = (ch << 8) | *str++;
--cc;
}
#endif
pfont->fontprocs->GetTextBits(pfont, ch, bitmap, &width,
&height, &base);
/* note: change to bitmap*/
GdBitmap(psd, x, y, width, height, bitmap);
x += width;
}
if (pfont->fontattr & MWTF UNDERLINE)
GdLine(psd, startx, starty, x, starty, FALSE);
GdFixCursor(psd);
}
/*
* Draw ascii text using COREFONT type
font.
*/
void
corefont drawtext(PMWFONT pfont, PSD psd, MWCOORD
x, MWCOORD y,
const void *text, int cc, int flags)
{
const
unsigned char *str =
text;
MWCOORD width; /* width of text area
*/
MWCOORD height; /* height of text area
*/
MWCOORD base; /* baseline of
text*/
MWCOORD startx,
starty;
/* bitmap for characters
*/
MWIMAGEBITS
bitmap[MAX CHAR HEIGHT*MAX CHAR WIDTH/MWIMAGE BITSPERIMAGE];
pfont->fontprocs->GetTextSize(pfont, str, cc,
&width, &height, &base);
if(flags &
MWTF BASELINE)
y -= base;
else if(flags &
MWTF BOTTOM)
y -= (height - 1);
startx =
x;
starty = y + base;
switch (GdClipArea(psd, x, y, x + width - 1, y + height
- 1)) {
case CLIP VISIBLE:
/*
* For size
considerations, there's no low-level text
* draw, so we've got
to draw all text
* with per-point clipping for the time
being
if (gr usebg)
psd->FillRect(psd, x,
y, x + width - 1, y + height -
1,
gr background);
psd->DrawText(psd,
x, y, str, cc, gr foreground,
pfont);
GdFixCursor(psd);
return;
*/
break;
case
CLIP INVISIBLE:
return;
}
/* Get the bitmap for each character individually, and
then display
* them using clipping for each one.
*/
while (--cc >= 0 && x < psd->xvirtres)
{
unsigned int ch = *str++;
+#if
HAVE BIG5 SUPPORT
+ /* chinese big5 decoding*/
+ if
(ch >= 0xA1 && ch <= 0xF9 && cc >= 1
&&
+ ((*str >= 0x40 && *str <= 0x7E)
||
+ (*str >= 0xA1 && *str <= 0xFE)) )
{
+ ch = (ch << 8) |
*str++;
+ --cc;
+ }
+#endif
#if
HAVE GB2312 SUPPORT
/* chinese gb2312
decoding*/
if (ch >= 0xA1 && ch < 0xF8 &&
cc >= 1 &&
*str >= 0xA1 && *str <
0xFF) {
ch = (ch << 8) |
*str++;
--cc;
}
#endif
pfont->fontprocs->GetTextBits(pfont,
ch, bitmap, &width,
&height,
&base);
/* note: change to
bitmap*/
GdBitmap(psd, x, y, width, height,
bitmap);
x += width;
}
if (pfont->fontattr &
MWTF UNDERLINE)
GdLine(psd, startx, starty, x, starty,
FALSE);
GdFixCursor(psd);
}
["application/x-zip-compressed" not shown]