home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC Shareware 1999 March
/
PCShareware-3-99.iso
/
IMPLE
/
DJGPP.RAR
/
DJGPP2
/
XLIB-SR0.ZIP
/
SRC
/
XLIBEMU
/
DRAWTEXT.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-02-10
|
5KB
|
219 lines
/* $Id: drawtext.c 1.3 1994/02/11 00:47:09 ulrich Exp $ */
/*
* drawtext.c
*
* X library text drawing functions.
*/
#include "Xlibemu.h"
GrTextOption _TextOpt = {
(GrFont *) 0,
1, 1,
0, 0,
GR_TEXT_RIGHT,
GR_ALIGN_LEFT,
GR_ALIGN_BASELINE,
GR_BYTE_TEXT
};
extern unsigned long _GXfunctionToGrOPER[];
#define GrCOLOR 0xffff
void
GxPatternString (char *text, int length, int x, int y, GrTextOption *opt, GrPattern *pat)
{
int x1, y1, x2, y2;
int ww, hh;
int width, height;
int fgcolor, bgcolor;
int y_orig, x_orig;
GrContext *cxt, cxt_save;
GrFont *f = opt->txo_font;
x_orig = x;
y_orig = y;
/* code from GrDrawString() */
if((f == NULL) ||
(_GrGetTextSize(text,length,&width,&height,opt) == FALSE) ||
(width == 0) ||
(height == 0))
return;
if((ww = width) < 0) { ww = (-ww); x += (ww - 1); }
if((hh = height) < 0) { hh = (-hh); y += (hh - 1); }
switch(opt->txo_xalign) {
case GR_ALIGN_RIGHT:
x -= (ww - 1);
break;
case GR_ALIGN_CENTER:
x -= (ww >> 1);
break;
}
switch(opt->txo_yalign) {
case GR_ALIGN_BASELINE:
if(opt->txo_direct == GR_TEXT_DEFAULT) y -= f->fnt_baseline;
break;
case GR_ALIGN_BOTTOM:
y -= (hh - 1);
break;
case GR_ALIGN_CENTER:
y -= (hh >> 1);
break;
}
x2 = (x1 = x) + width + ((width > 0) ? (-1) : 1);
y2 = (y1 = y) + height + ((height > 0) ? (-1) : 1);
/* end code GrDrawString() */
GrSaveContext (&cxt_save);
cxt = GrCreateContext (width, 2 * height, NULL, NULL);
GrSetContext (cxt);
GrBitBlt (cxt, 0, 0, &cxt_save, x1, y1, x2, y2, GrWRITE);
GrBitBlt (cxt, 0, height, &cxt_save, x1, y1, x2, y2, GrWRITE);
fgcolor = pat->gp_bmp_fgcolor;
bgcolor = pat->gp_bmp_bgcolor;
pat->gp_bmp_fgcolor = 0;
pat->gp_bmp_bgcolor = GrNOCOLOR;
GrPatternFilledBox (0, 0, width - 1, height - 1, pat);
GrDrawString (text, length, x_orig - x1, y_orig - y1, opt);
pat->gp_bmp_fgcolor = GrNOCOLOR;
pat->gp_bmp_bgcolor = 0;
GrPatternFilledBox (0, height, width - 1, 2 * height - 1, pat);
GrBitBlt (&cxt_save, x1, y1, cxt, 0, 0, width - 1, height - 1, GrWRITE);
GrBitBlt (&cxt_save, x1, y1, cxt, 0, height, width - 1, 2 * height - 1, GrOR);
GrDestroyContext (cxt);
GrSetContext (&cxt_save);
pat->gp_bmp_fgcolor = fgcolor;
pat->gp_bmp_bgcolor = bgcolor;
}
int
XDrawString(
Display* display,
Drawable d,
GC gc,
int x,
int y,
_Xconst char* string,
int length)
{
int oper;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
_TextOpt.txo_font = gc->values.font;
_TextOpt.txo_bgcolor.v = GrNOCOLOR;
oper = _GXfunctionToGrOPER[gc->values.function];
_TextOpt.txo_fgcolor.v = oper | gc->values.foreground;
switch (gc->values.fill_style) {
case FillSolid:
_WDrawRegion (GrDrawString, (long) string, length, x, y, (long) &_TextOpt);
break;
case FillStippled:
case FillOpaqueStippled:
GxPatternString (string, length, x, y, &_TextOpt, gc->values.stipple->pattern);
break;
}
return 1;
}
int
XDrawImageString(
Display* display,
Drawable d,
GC gc,
int x,
int y,
_Xconst char* string,
int length)
{
int oper;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
/*
* XLib documentation says to ignore fill-style and function
*/
_TextOpt.txo_font = gc->values.font;
_TextOpt.txo_fgcolor.v = gc->values.foreground;
_TextOpt.txo_bgcolor.v = gc->values.background;
_WDrawRegion (GrDrawString, (long) string, length, x, y, (long) &_TextOpt);
return 1;
}
int
XDrawString16(
Display* display,
Drawable d,
GC gc,
int x,
int y,
_Xconst XChar2b* string,
int length)
{
return 0;
}
int
XDrawText(
Display* display,
Drawable d,
GC gc,
int x,
int y,
XTextItem* items,
int nitems)
{
int i;
XFontStruct *fs;
if (_WDrawContext (d, gc) == 0)
return 0;
FlushGC(display, gc);
fs = XQueryFont (display, (XID) gc->values.font);
for (i = 0; i < nitems; i++) {
if (items->nchars > 0 && items->chars) {
if (items->font != None) {
XSetFont (display, gc, items->font);
fs = XQueryFont (display, (XID) gc->values.font);
}
x += items->delta;
XDrawString (display, d, gc, x, y,
items->chars, items->nchars);
x += XTextWidth (fs, items->chars, items->nchars);
}
items++;
}
return 1;
}
int
XDrawText16(
Display* display,
Drawable d,
GC gc,
int x,
int y,
XTextItem16* items,
int nitems
)
{
FlushGC(display, gc);
return 0;
}