static void doEncodeWORD( WORD *w, void *d ) { data_word_tables *data = d; char *p; if( w->references <= 1 ) { return; } w->index = data->current_base++; data->word_base[ w->index ] = data->current_text; data->keep_base[ w->index ] = w; data->current_text += w->len; for( p = w->name; *p; ++p ) { outputChar( o_msgc, *p ); } fputc( '\n', o_msgc ); }
LayoutText::LayoutText(Text* text) : m_text(text) { int sawNl = 0; unsigned int n = m_text->m_text.size(); const char* raw = m_text->m_text.data(); for (unsigned int i = 0; i < n; ++i) { // \n\n means real line break; otherwise reflow text if (raw[i] == '\n') { if (sawNl) { outputNl(); outputBr(); continue; } else sawNl = 1; } else if (raw[i] == '\f') { outputPageBreak(); continue; } else { sawNl = 0; } outputChar(raw[i]); } flushText(); }
int gvprintf(writeCharFunc writeChar, char *fmt, va_list ap) { int len = 0; while(*fmt) { if (*fmt == '%') { uint8_t size = 2; // default size uint32_t mask = 0xFFFF; char f = 'd'; // default type fmt++; switch(*fmt) { case '1': size = 1; fmt++; break; case '2': size = 2; fmt++; break; case '4': size = 4; fmt++; break; } switch(*fmt) { case '%': outputChar(*fmt); break; case 's': { char *s = va_arg (ap, char *); while(*s) { outputChar(*s++); } } break; case 'S': { char *s = va_arg (ap, char *); char c; while((c = pgm_read_byte(s)) != '\0') { outputChar(c); s++; } } break; case 'c': { unsigned char c = (unsigned char)va_arg (ap, int /*char*/); outputChar(c); } break; case 'u': case 'd': case 'x': case 'b': { uint32_t v; switch (size) { case 1: v = va_arg (ap, int/*uint8_t*/); break; case 2: v = va_arg (ap, int/*uint16_t*/); break; case 4: v = va_arg (ap, uint32_t); break; } if (*fmt == 'x') { len += i2h(writeChar, v, size); } else if (*fmt == 'b') { len += i2b(writeChar, v, size); } else { len += i2d(writeChar, v, size, *fmt == 'd'); } } break; default: outputChar(*fmt); break; } fmt++; } else {
void captureXFont(Display * dpy, Font font, char *xfont, char *name) { int first, last, count; int cnt, len; Pixmap offscreen; Window drawable; XFontStruct *fontinfo; XImage *image; GC xgc; XGCValues values; int width, height; int i, j, k; XCharStruct *charinfo; XChar2b character; GLubyte *bitmapData; int x, y; int spanLength; int charWidth, charHeight, maxSpanLength, pixwidth; int grabList[MAX_GLYPHS_PER_GRAB]; int glyphsPerGrab = MAX_GLYPHS_PER_GRAB; int numToGrab; int rows, pages, byte1, byte2, index; int nullBitmap; drawable = RootWindow(dpy, DefaultScreen(dpy)); fontinfo = XQueryFont(dpy, font); pages = fontinfo->max_char_or_byte2 - fontinfo->min_char_or_byte2 + 1; first = (fontinfo->min_byte1 << 8) + fontinfo->min_char_or_byte2; last = (fontinfo->max_byte1 << 8) + fontinfo->max_char_or_byte2; count = last - first + 1; width = fontinfo->max_bounds.rbearing - fontinfo->min_bounds.lbearing; height = fontinfo->max_bounds.ascent + fontinfo->max_bounds.descent; /* 16-bit fonts have more than one row; indexing into per_char is trickier. */ rows = fontinfo->max_byte1 - fontinfo->min_byte1 + 1; maxSpanLength = (width + 7) / 8; /* For portability reasons we don't use alloca for bitmapData, but we could. */ bitmapData = malloc(height * maxSpanLength); /* Be careful determining the width of the pixmap; the X protocol allows pixmaps of width 2^16-1 (unsigned short size) but drawing coordinates max out at 2^15-1 (signed short size). If the width is too large, we need to limit the glyphs per grab. */ if ((glyphsPerGrab * 8 * maxSpanLength) >= (1 << 15)) { glyphsPerGrab = (1 << 15) / (8 * maxSpanLength); } pixwidth = glyphsPerGrab * 8 * maxSpanLength; offscreen = XCreatePixmap(dpy, drawable, pixwidth, height, 1); values.font = font; values.background = 0; values.foreground = 0; xgc = XCreateGC(dpy, offscreen, GCFont | GCBackground | GCForeground, &values); XFillRectangle(dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); XSetForeground(dpy, xgc, 1); numToGrab = 0; if (fontinfo->per_char == NULL) { charinfo = &(fontinfo->min_bounds); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; spanLength = (charWidth + 7) / 8; } printf("\n/* GENERATED FILE -- DO NOT MODIFY */\n\n"); printf("#include \"glutbitmap.h\"\n\n"); for (i = first; count; i++, count--) { int undefined; if (rows == 1) { undefined = (fontinfo->min_char_or_byte2 > i || fontinfo->max_char_or_byte2 < i); } else { byte2 = i & 0xff; byte1 = i >> 8; undefined = (fontinfo->min_char_or_byte2 > byte2 || fontinfo->max_char_or_byte2 < byte2 || fontinfo->min_byte1 > byte1 || fontinfo->max_byte1 < byte1); } if (undefined) { goto PossiblyDoGrab; } if (fontinfo->per_char != NULL) { if (rows == 1) { index = i - fontinfo->min_char_or_byte2; } else { byte2 = i & 0xff; byte1 = i >> 8; index = (byte1 - fontinfo->min_byte1) * pages + (byte2 - fontinfo->min_char_or_byte2); } charinfo = &(fontinfo->per_char[index]); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; if (charWidth == 0 || charHeight == 0) { if (charinfo->width != 0) { /* Still must move raster pos even if empty character */ outputChar(i, 0, 0, 0, 0, charinfo->width, 0); } goto PossiblyDoGrab; } } grabList[numToGrab] = i; character.byte2 = i & 255; character.byte1 = i >> 8; /* XXX We could use XDrawImageString16 which would also paint the backing rectangle but X server bugs in some scalable font rasterizers makes it more effective to do XFillRectangles to clear the pixmap and then XDrawImage16 for the text. */ XDrawString16(dpy, offscreen, xgc, -charinfo->lbearing + 8 * maxSpanLength * numToGrab, charinfo->ascent, &character, 1); numToGrab++; PossiblyDoGrab: if (numToGrab >= glyphsPerGrab || count == 1) { image = XGetImage(dpy, offscreen, 0, 0, pixwidth, height, 1, XYPixmap); for (j = numToGrab - 1; j >= 0; j--) { if (fontinfo->per_char != NULL) { byte2 = grabList[j] & 0xff; byte1 = grabList[j] >> 8; index = (byte1 - fontinfo->min_byte1) * pages + (byte2 - fontinfo->min_char_or_byte2); charinfo = &(fontinfo->per_char[index]); charWidth = charinfo->rbearing - charinfo->lbearing; charHeight = charinfo->ascent + charinfo->descent; spanLength = (charWidth + 7) / 8; } memset(bitmapData, 0, height * spanLength); for (y = 0; y < charHeight; y++) { for (x = 0; x < charWidth; x++) { if (XGetPixel(image, j * maxSpanLength * 8 + x, charHeight - 1 - y)) { /* Little endian machines (such as DEC Alpha) could benefit from reversing the bit order here and changing the GL_UNPACK_LSB_FIRST parameter in glutBitmapCharacter to GL_TRUE. */ bitmapData[y * spanLength + x / 8] |= (1 << (7 - (x & 7))); } } } if (PRINTABLE(grabList[j])) { printf("/* char: 0x%x '%c' */\n\n", grabList[j], grabList[j]); } else { printf("/* char: 0x%x */\n\n", grabList[j]); } /* Determine if the bitmap is null. */ nullBitmap = 1; len = (charinfo->ascent + charinfo->descent) * ((charinfo->rbearing - charinfo->lbearing + 7) / 8); cnt = 0; while (cnt < len) { for (k = 0; k < 16 && cnt < len; k++, cnt++) { if (bitmapData[cnt] != 0) { nullBitmap = 0; } } } if (!nullBitmap) { printf("static const GLubyte ch%ddata[] = {\n", grabList[j]); len = (charinfo->ascent + charinfo->descent) * ((charinfo->rbearing - charinfo->lbearing + 7) / 8); cnt = 0; while (cnt < len) { for (k = 0; k < 16 && cnt < len; k++, cnt++) { printf("0x%x,", bitmapData[cnt]); } printf("\n"); } printf("};\n\n"); } else { charWidth = 0; charHeight = 0; } outputChar(grabList[j], charWidth, charHeight, -charinfo->lbearing, charinfo->descent, charinfo->width, !nullBitmap); } XDestroyImage(image); numToGrab = 0; if (count > 0) { XSetForeground(dpy, xgc, 0); XFillRectangle(dpy, offscreen, xgc, 0, 0, 8 * maxSpanLength * glyphsPerGrab, height); XSetForeground(dpy, xgc, 1); } }
static void writeMsgTable( void ) { MSGSYM *m; unsigned *msg_base; unsigned current_base; unsigned current_text; unsigned i; WORDREF *r; WORD *w; char *p; current_text = 0; current_base = 0; msg_base = malloc( ( messageCounter + 1 ) * sizeof( unsigned ) ); outputTableName( o_msgc, "uint_8 const", "msg_text" ); for( m = messageSyms; m != NULL; m = m->next ) { msg_base[ current_base++ ] = current_text; fputs( "\n/* ", o_msgc ); outputNumJ( o_msgc, m->index, 4 ); fputc( ' ', o_msgc ); fputs( m->lang_txt[LANG_English], o_msgc ); fputs( " */\n", o_msgc ); for( r = m->words; r != NULL; r = r->next ) { w = r->word; if( w->index == NO_INDEX ) { outputNum( o_msgc, w->len ); fputs( ", ", o_msgc ); for( p = w->name; *p; ++p ) { outputChar( o_msgc, *p ); } fputc( '\n', o_msgc ); current_text += 1 + w->len; } else { if( w->index <= USE_SMALL_ENC ) { fputs( "ENC_BIT | ", o_msgc ); outputNum( o_msgc, w->index ); ++current_text; } else { fputs( "ENC_BIT | LARGE_BIT | ", o_msgc ); outputNum( o_msgc, ( w->index >> 8 ) ); fputs( ", ", o_msgc ); outputNum( o_msgc, ( w->index & 0x0ff ) ); current_text += 2; } fputs( ", /* ", o_msgc ); fputs( w->name, o_msgc ); fputs( " */\n", o_msgc ); } } } fputs( "};\n", o_msgc ); totalBytes += current_text; msg_base[ current_base++ ] = current_text; totalBytes += current_base * sizeof( short ); outputTableName( o_msgc, "unsigned short const", "msg_base" ); for( i = 0; i < current_base; ++i ) { outputNum( o_msgc, msg_base[ i ] ); fputc( ',', o_msgc ); fputc( '\n', o_msgc ); } fputs( "};\n", o_msgc ); if( allGroups != NULL ) { MSGGROUP *g; outputTableName( o_msgc, "unsigned short const", "msg_group_base" ); for( g = allGroups; g != NULL; g = g->next ) { outputNum( o_msgc, g->msgIndex ); fputc( ',', o_msgc ); fputc( '\n', o_msgc ); } assert( messageIndex == 0 ); outputNum( o_msgc, messageCounter ); fputs( ",\n};\n", o_msgc ); fputs( "MSG_SCOPE char const MSG_MEM msg_group_name[][2] = {\n" , o_msgc ); for( g = allGroups; g != NULL; g = g->next ) { char buf[10]; buf[0] = '\''; buf[1] = g->name[0]; buf[2] = '\''; buf[3] = ','; buf[4] = '\''; buf[5] = g->name[1]; buf[6] = '\''; buf[7] = ','; buf[8] = '\n'; buf[9] = '\0'; fputs( buf, o_msgc ); } fputs( "};\n", o_msgc ); fputs( "#define MSGS_GROUPED\n", o_msgc ); } free( msg_base ); }