glx: indent -br -i3 -npcs --no-tabs xfont.c
This commit is contained in:
parent
b57e9f2a74
commit
1bb4658fab
|
@ -49,58 +49,55 @@
|
||||||
int debug_xfonts = 0;
|
int debug_xfonts = 0;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_char_struct (XCharStruct *ch, char *prefix)
|
dump_char_struct(XCharStruct * ch, char *prefix)
|
||||||
{
|
{
|
||||||
printf ("%slbearing = %d, rbearing = %d, width = %d\n",
|
printf("%slbearing = %d, rbearing = %d, width = %d\n",
|
||||||
prefix, ch->lbearing, ch->rbearing, ch->width);
|
prefix, ch->lbearing, ch->rbearing, ch->width);
|
||||||
printf ("%sascent = %d, descent = %d, attributes = %u\n",
|
printf("%sascent = %d, descent = %d, attributes = %u\n",
|
||||||
prefix, ch->ascent, ch->descent, (unsigned int) ch->attributes);
|
prefix, ch->ascent, ch->descent, (unsigned int) ch->attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_font_struct (XFontStruct *font)
|
dump_font_struct(XFontStruct * font)
|
||||||
{
|
{
|
||||||
printf ("ascent = %d, descent = %d\n", font->ascent, font->descent);
|
printf("ascent = %d, descent = %d\n", font->ascent, font->descent);
|
||||||
printf ("char_or_byte2 = (%u,%u)\n",
|
printf("char_or_byte2 = (%u,%u)\n",
|
||||||
font->min_char_or_byte2, font->max_char_or_byte2);
|
font->min_char_or_byte2, font->max_char_or_byte2);
|
||||||
printf ("byte1 = (%u,%u)\n", font->min_byte1, font->max_byte1);
|
printf("byte1 = (%u,%u)\n", font->min_byte1, font->max_byte1);
|
||||||
printf ("all_chars_exist = %s\n", font->all_chars_exist ? "True" :
|
printf("all_chars_exist = %s\n", font->all_chars_exist ? "True" : "False");
|
||||||
"False");
|
printf("default_char = %c (\\%03o)\n",
|
||||||
printf ("default_char = %c (\\%03o)\n",
|
(char) (isprint(font->default_char) ? font->default_char : ' '),
|
||||||
(char) (isprint (font->default_char) ? font->default_char : ' '),
|
|
||||||
font->default_char);
|
font->default_char);
|
||||||
dump_char_struct (&font->min_bounds, "min> ");
|
dump_char_struct(&font->min_bounds, "min> ");
|
||||||
dump_char_struct (&font->max_bounds, "max> ");
|
dump_char_struct(&font->max_bounds, "max> ");
|
||||||
#if 0
|
#if 0
|
||||||
for (c = font->min_char_or_byte2; c <= font->max_char_or_byte2; c++)
|
for (c = font->min_char_or_byte2; c <= font->max_char_or_byte2; c++) {
|
||||||
{
|
|
||||||
char prefix[8];
|
char prefix[8];
|
||||||
sprintf (prefix, "%d> ", c);
|
sprintf(prefix, "%d> ", c);
|
||||||
dump_char_struct (&font->per_char[c], prefix);
|
dump_char_struct(&font->per_char[c], prefix);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
dump_bitmap (unsigned int width, unsigned int height, GLubyte *bitmap)
|
dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap)
|
||||||
{
|
{
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
|
|
||||||
printf (" ");
|
printf(" ");
|
||||||
for (x = 0; x < 8*width; x++)
|
for (x = 0; x < 8 * width; x++)
|
||||||
printf ("%o", 7 - (x % 8));
|
printf("%o", 7 - (x % 8));
|
||||||
putchar ('\n');
|
putchar('\n');
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++) {
|
||||||
{
|
printf("%3o:", y);
|
||||||
printf ("%3o:", y);
|
for (x = 0; x < 8 * width; x++)
|
||||||
for (x = 0; x < 8*width; x++)
|
putchar((bitmap[width * (height - y - 1) + x / 8] & (1 << (7 - (x %
|
||||||
putchar ((bitmap[width*(height - y - 1) + x/8] & (1 << (7 - (x %
|
8))))
|
||||||
8))))
|
|
||||||
? '*' : '.');
|
? '*' : '.');
|
||||||
printf (" ");
|
printf(" ");
|
||||||
for (x = 0; x < width; x++)
|
for (x = 0; x < width; x++)
|
||||||
printf ("0x%02x, ", bitmap[width*(height - y - 1) + x]);
|
printf("0x%02x, ", bitmap[width * (height - y - 1) + x]);
|
||||||
putchar ('\n');
|
putchar('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
@ -133,84 +130,90 @@ dump_bitmap (unsigned int width, unsigned int height, GLubyte *bitmap)
|
||||||
* Generate OpenGL-compatible bitmap.
|
* Generate OpenGL-compatible bitmap.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
fill_bitmap (Display *dpy, Window win, GC gc,
|
fill_bitmap(Display * dpy, Window win, GC gc,
|
||||||
unsigned int width, unsigned int height,
|
unsigned int width, unsigned int height,
|
||||||
int x0, int y0, unsigned int c, GLubyte *bitmap)
|
int x0, int y0, unsigned int c, GLubyte * bitmap)
|
||||||
{
|
{
|
||||||
XImage *image;
|
XImage *image;
|
||||||
unsigned int x, y;
|
unsigned int x, y;
|
||||||
Pixmap pixmap;
|
Pixmap pixmap;
|
||||||
XChar2b char2b;
|
XChar2b char2b;
|
||||||
|
|
||||||
pixmap = XCreatePixmap (dpy, win, 8*width, height, 1);
|
pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1);
|
||||||
XSetForeground(dpy, gc, 0);
|
XSetForeground(dpy, gc, 0);
|
||||||
XFillRectangle (dpy, pixmap, gc, 0, 0, 8*width, height);
|
XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height);
|
||||||
XSetForeground(dpy, gc, 1);
|
XSetForeground(dpy, gc, 1);
|
||||||
|
|
||||||
char2b.byte1 = (c >> 8) & 0xff;
|
char2b.byte1 = (c >> 8) & 0xff;
|
||||||
char2b.byte2 = (c & 0xff);
|
char2b.byte2 = (c & 0xff);
|
||||||
|
|
||||||
XDrawString16 (dpy, pixmap, gc, x0, y0, &char2b, 1);
|
XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1);
|
||||||
|
|
||||||
image = XGetImage (dpy, pixmap, 0, 0, 8*width, height, 1, XYPixmap);
|
image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap);
|
||||||
if (image) {
|
if (image) {
|
||||||
/* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */
|
/* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
for (x = 0; x < 8*width; x++)
|
for (x = 0; x < 8 * width; x++)
|
||||||
if (XGetPixel (image, x, y))
|
if (XGetPixel(image, x, y))
|
||||||
bitmap[width*(height - y - 1) + x/8] |= (1 << (7 - (x % 8)));
|
bitmap[width * (height - y - 1) + x / 8] |=
|
||||||
XDestroyImage (image);
|
(1 << (7 - (x % 8)));
|
||||||
|
XDestroyImage(image);
|
||||||
}
|
}
|
||||||
|
|
||||||
XFreePixmap (dpy, pixmap);
|
XFreePixmap(dpy, pixmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* determine if a given glyph is valid and return the
|
* determine if a given glyph is valid and return the
|
||||||
* corresponding XCharStruct.
|
* corresponding XCharStruct.
|
||||||
*/
|
*/
|
||||||
static XCharStruct *isvalid(XFontStruct *fs, int which)
|
static XCharStruct *
|
||||||
|
isvalid(XFontStruct * fs, int which)
|
||||||
{
|
{
|
||||||
unsigned int rows,pages;
|
unsigned int rows, pages;
|
||||||
int byte1 = 0, byte2 = 0;
|
int byte1 = 0, byte2 = 0;
|
||||||
int i,valid = 1;
|
int i, valid = 1;
|
||||||
|
|
||||||
rows = fs->max_byte1 - fs->min_byte1 + 1;
|
rows = fs->max_byte1 - fs->min_byte1 + 1;
|
||||||
pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
|
pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1;
|
||||||
|
|
||||||
if (rows == 1) {
|
if (rows == 1) {
|
||||||
/* "linear" fonts */
|
/* "linear" fonts */
|
||||||
if ((fs->min_char_or_byte2 > which) ||
|
if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which))
|
||||||
(fs->max_char_or_byte2 < which)) valid = 0;
|
valid = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* "matrix" fonts */
|
/* "matrix" fonts */
|
||||||
byte2 = which & 0xff;
|
byte2 = which & 0xff;
|
||||||
byte1 = which >> 8;
|
byte1 = which >> 8;
|
||||||
if ((fs->min_char_or_byte2 > byte2) ||
|
if ((fs->min_char_or_byte2 > byte2) ||
|
||||||
(fs->max_char_or_byte2 < byte2) ||
|
(fs->max_char_or_byte2 < byte2) ||
|
||||||
(fs->min_byte1 > byte1) ||
|
(fs->min_byte1 > byte1) || (fs->max_byte1 < byte1))
|
||||||
(fs->max_byte1 < byte1)) valid = 0;
|
valid = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (valid) {
|
if (valid) {
|
||||||
if (fs->per_char) {
|
if (fs->per_char) {
|
||||||
if (rows == 1) {
|
if (rows == 1) {
|
||||||
/* "linear" fonts */
|
/* "linear" fonts */
|
||||||
return(fs->per_char + (which-fs->min_char_or_byte2) );
|
return (fs->per_char + (which - fs->min_char_or_byte2));
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
/* "matrix" fonts */
|
/* "matrix" fonts */
|
||||||
i = ((byte1 - fs->min_byte1) * pages) +
|
i = ((byte1 - fs->min_byte1) * pages) +
|
||||||
(byte2 - fs->min_char_or_byte2);
|
(byte2 - fs->min_char_or_byte2);
|
||||||
return(fs->per_char + i);
|
return (fs->per_char + i);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return(&fs->min_bounds);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return(NULL);
|
else {
|
||||||
|
return (&fs->min_bounds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return (NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
_X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
_X_HIDDEN void
|
||||||
|
DRI_glXUseXFont(Font font, int first, int count, int listbase)
|
||||||
{
|
{
|
||||||
GLXContext CC;
|
GLXContext CC;
|
||||||
Display *dpy;
|
Display *dpy;
|
||||||
|
@ -233,9 +236,8 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
dpy = CC->currentDpy;
|
dpy = CC->currentDpy;
|
||||||
win = CC->currentDrawable;
|
win = CC->currentDrawable;
|
||||||
|
|
||||||
fs = XQueryFont (dpy, font);
|
fs = XQueryFont(dpy, font);
|
||||||
if (!fs)
|
if (!fs) {
|
||||||
{
|
|
||||||
__glXSetError(CC, GL_INVALID_VALUE);
|
__glXSetError(CC, GL_INVALID_VALUE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -246,10 +248,9 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
max_bm_width = (max_width + 7) / 8;
|
max_bm_width = (max_width + 7) / 8;
|
||||||
max_bm_height = max_height;
|
max_bm_height = max_height;
|
||||||
|
|
||||||
bm = (GLubyte *) Xmalloc((max_bm_width * max_bm_height) * sizeof
|
bm = (GLubyte *) Xmalloc((max_bm_width * max_bm_height) * sizeof(GLubyte));
|
||||||
(GLubyte));
|
|
||||||
if (!bm) {
|
if (!bm) {
|
||||||
XFreeFontInfo( NULL, fs, 1 );
|
XFreeFontInfo(NULL, fs, 1);
|
||||||
__glXSetError(CC, GL_OUT_OF_MEMORY);
|
__glXSetError(CC, GL_OUT_OF_MEMORY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -264,38 +265,37 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Save the current packing mode for bitmaps. */
|
/* Save the current packing mode for bitmaps. */
|
||||||
glGetIntegerv (GL_UNPACK_SWAP_BYTES, &swapbytes);
|
glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes);
|
||||||
glGetIntegerv (GL_UNPACK_LSB_FIRST, &lsbfirst);
|
glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst);
|
||||||
glGetIntegerv (GL_UNPACK_ROW_LENGTH, &rowlength);
|
glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength);
|
||||||
glGetIntegerv (GL_UNPACK_SKIP_ROWS, &skiprows);
|
glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows);
|
||||||
glGetIntegerv (GL_UNPACK_SKIP_PIXELS, &skippixels);
|
glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels);
|
||||||
glGetIntegerv (GL_UNPACK_ALIGNMENT, &alignment);
|
glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
|
||||||
|
|
||||||
/* Enforce a standard packing mode which is compatible with
|
/* Enforce a standard packing mode which is compatible with
|
||||||
fill_bitmap() from above. This is actually the default mode,
|
fill_bitmap() from above. This is actually the default mode,
|
||||||
except for the (non)alignment. */
|
except for the (non)alignment. */
|
||||||
glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE);
|
glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE);
|
||||||
glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE);
|
glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
|
||||||
glPixelStorei (GL_UNPACK_ROW_LENGTH, 0);
|
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
|
||||||
glPixelStorei (GL_UNPACK_SKIP_ROWS, 0);
|
glPixelStorei(GL_UNPACK_SKIP_ROWS, 0);
|
||||||
glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0);
|
glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0);
|
||||||
glPixelStorei (GL_UNPACK_ALIGNMENT, 1);
|
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||||
|
|
||||||
pixmap = XCreatePixmap (dpy, win, 10, 10, 1);
|
pixmap = XCreatePixmap(dpy, win, 10, 10, 1);
|
||||||
values.foreground = BlackPixel (dpy, DefaultScreen (dpy));
|
values.foreground = BlackPixel(dpy, DefaultScreen(dpy));
|
||||||
values.background = WhitePixel (dpy, DefaultScreen (dpy));
|
values.background = WhitePixel(dpy, DefaultScreen(dpy));
|
||||||
values.font = fs->fid;
|
values.font = fs->fid;
|
||||||
valuemask = GCForeground | GCBackground | GCFont;
|
valuemask = GCForeground | GCBackground | GCFont;
|
||||||
gc = XCreateGC (dpy, pixmap, valuemask, &values);
|
gc = XCreateGC(dpy, pixmap, valuemask, &values);
|
||||||
XFreePixmap (dpy, pixmap);
|
XFreePixmap(dpy, pixmap);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (debug_xfonts)
|
if (debug_xfonts)
|
||||||
dump_font_struct (fs);
|
dump_font_struct(fs);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (i = 0; i < count; i++)
|
for (i = 0; i < count; i++) {
|
||||||
{
|
|
||||||
unsigned int width, height, bm_width, bm_height;
|
unsigned int width, height, bm_width, bm_height;
|
||||||
GLfloat x0, y0, dx, dy;
|
GLfloat x0, y0, dx, dy;
|
||||||
XCharStruct *ch;
|
XCharStruct *ch;
|
||||||
|
@ -309,15 +309,16 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
if (!ch) {
|
if (!ch) {
|
||||||
ch = &fs->max_bounds;
|
ch = &fs->max_bounds;
|
||||||
valid = 0;
|
valid = 0;
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
valid = 1;
|
valid = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (debug_xfonts) {
|
if (debug_xfonts) {
|
||||||
char s[7];
|
char s[7];
|
||||||
sprintf (s, isprint (c) ? "%c> " : "\\%03o> ", c);
|
sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c);
|
||||||
dump_char_struct (ch, s);
|
dump_char_struct(ch, s);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -325,13 +326,13 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
straight from the glXUseXFont(3) manpage. */
|
straight from the glXUseXFont(3) manpage. */
|
||||||
width = ch->rbearing - ch->lbearing;
|
width = ch->rbearing - ch->lbearing;
|
||||||
height = ch->ascent + ch->descent;
|
height = ch->ascent + ch->descent;
|
||||||
x0 = - ch->lbearing;
|
x0 = -ch->lbearing;
|
||||||
y0 = ch->descent - 1;
|
y0 = ch->descent - 1;
|
||||||
dx = ch->width;
|
dx = ch->width;
|
||||||
dy = 0;
|
dy = 0;
|
||||||
|
|
||||||
/* X11's starting point. */
|
/* X11's starting point. */
|
||||||
x = - ch->lbearing;
|
x = -ch->lbearing;
|
||||||
y = ch->ascent;
|
y = ch->ascent;
|
||||||
|
|
||||||
/* Round the width to a multiple of eight. We will use this also
|
/* Round the width to a multiple of eight. We will use this also
|
||||||
|
@ -340,30 +341,30 @@ _X_HIDDEN void DRI_glXUseXFont( Font font, int first, int count, int listbase )
|
||||||
bm_width = (width + 7) / 8;
|
bm_width = (width + 7) / 8;
|
||||||
bm_height = height;
|
bm_height = height;
|
||||||
|
|
||||||
glNewList (list, GL_COMPILE);
|
glNewList(list, GL_COMPILE);
|
||||||
if (valid && (bm_width > 0) && (bm_height > 0)) {
|
if (valid && (bm_width > 0) && (bm_height > 0)) {
|
||||||
|
|
||||||
memset (bm, '\0', bm_width * bm_height);
|
memset(bm, '\0', bm_width * bm_height);
|
||||||
fill_bitmap (dpy, win, gc, bm_width, bm_height, x, y, c, bm);
|
fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm);
|
||||||
|
|
||||||
glBitmap (width, height, x0, y0, dx, dy, bm);
|
glBitmap(width, height, x0, y0, dx, dy, bm);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
if (debug_xfonts) {
|
if (debug_xfonts) {
|
||||||
printf ("width/height = %u/%u\n", width, height);
|
printf("width/height = %u/%u\n", width, height);
|
||||||
printf ("bm_width/bm_height = %u/%u\n", bm_width,
|
printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height);
|
||||||
bm_height);
|
dump_bitmap(bm_width, bm_height, bm);
|
||||||
dump_bitmap (bm_width, bm_height, bm);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
} else {
|
|
||||||
glBitmap (0, 0, 0.0, 0.0, dx, dy, NULL);
|
|
||||||
}
|
}
|
||||||
glEndList ();
|
else {
|
||||||
|
glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL);
|
||||||
|
}
|
||||||
|
glEndList();
|
||||||
}
|
}
|
||||||
|
|
||||||
Xfree(bm);
|
Xfree(bm);
|
||||||
XFreeFontInfo( NULL, fs, 1 );
|
XFreeFontInfo(NULL, fs, 1);
|
||||||
XFreeGC (dpy, gc);
|
XFreeGC(dpy, gc);
|
||||||
|
|
||||||
/* Restore saved packing modes. */
|
/* Restore saved packing modes. */
|
||||||
glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
|
glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes);
|
||||||
|
|
Loading…
Reference in New Issue