X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=draw.c;h=79518a04c98e340ac2c0014320892d687e09a97f;hb=985cec56a6e655776b35dfeaf338f748808651da;hp=0edf2308977afd7acf427eaa9b5b38fce02d0cbc;hpb=b0e28f41f49991d8a9873d33d1abe02aa4606ae6;p=xboard.git diff --git a/draw.c b/draw.c index 0edf230..79518a0 100644 --- a/draw.c +++ b/draw.c @@ -255,7 +255,7 @@ ExposeRedraw (Option *graph, int x, int y, int w, int h) cairo_destroy(cr); } -static int modV[2], modH[2], transparency[2]; +static int modV[2], modH[2]; static void CreatePNGBoard (char *s, int kind) @@ -375,6 +375,38 @@ LoadSVG (char *dir, int color, int piece, int retry) return NULL; } +static void Wint(FILE *f, int n) +{ // write 32-bit int, lsb first + fprintf(f, "%c%c%c%c", n&255, n>>8&255, n>>16&255, n>>24&255); +} + +static void +SaveWindowsBitmap(ChessSquare piece, int color, int *data, int stride, int w, int h, int bpp) +{ + int i, v, line = (w*bpp + 3)>>2, size = line*4*h; + char buf[100]; + FILE *f; + snprintf(buf, 100, "bmaps/piece%d_%d%c.bmp", piece, w, color ? 's': 'o'); + if(piece >= appData.bmpSave && piece != WhiteKing) return; + f = fopen(buf, "wb"); + if(!f) return; + fprintf(f, "BM"); + Wint(f, size+54); Wint(f, 0); Wint(f, 54); Wint(f, 40); // file size, reserved, image offset, header size + Wint(f, w); Wint(f, h); Wint(f, 8*bpp << 16 | 1); // width, height, planes & bits/pix + Wint(f, 0); // compression + Wint(f, size); Wint(f, 3780); Wint(f, 3780); Wint(f, 0); Wint(f, 0); // image size, pix/m (H and V), color-table size (2x) + for(v=h-1; v>=0; v--) { + for(i=0; i>16&255, g=pix>>8&255, b=pix&255, a=pix>>24&255; + r = r*a/255; b = b*a/255; g = g*a/255; + if(bpp == 4) fprintf(f, "%c%c%c%c", b, g, r, a); else fprintf(f, "%c%c%c", b, g, r); + } + i *= bpp; while(i++ < line*4) fprintf(f, "%c", 0); // padding + } + fclose(f); + if(appData.bmpSave && piece == WhiteKing && color) exit(0); +} + static void ScaleOnePiece (int color, int piece, char *pieceDir) { @@ -431,6 +463,7 @@ ScaleOnePiece (int color, int piece, char *pieceDir) int i, j, p; sscanf(color ? appData.blackPieceColor+1 : appData.whitePieceColor+1, "%x", &p); // replacement color cairo_surface_flush(cs); + SaveWindowsBitmap(piece, color, buf, stride, squareSize, squareSize, 4); for(i=0; i= BlackPawn) piece = BLACK_TO_WHITE piece; p = appData.inscriptions; - n = piece; + if(*p > '0' && *p < '3') nr = *p++ - '0'; // nr of kanji per piece + n = piece; i = 0; while(piece > WhitePawn) { if(*p == '/') p++, piece = n - WhitePBishop; // secondary series if(*p++ == NULLCHAR) { @@ -899,12 +933,19 @@ InscribeKanji (cairo_surface_t *canvas, ChessSquare piece, int x, int y) } q = p - 1; while((*p & 0xC0) == 0x80) p++; // skip UTF-8 continuation bytes - piece--; + if(*q != '.' && ++i < nr) continue; // yet more kanji for the current piece + piece--; i = 0; } - strncpy(buf, p, 10); - for(q=buf; (*++q & 0xC0) == 0x80;); + strncpy(buf, p, 20); + for(q=buf; (*++q & 0xC0) == 0x80;); // skip first unicode + if(nr > 1) { + p = q; + while((*++p & 0xC0) == 0x80) {} // skip second unicode + *p = NULLCHAR; size = 30; i = 16; + DrawUnicode(canvas, q, x, y, PieceToChar(n), flip, size, -10); + } else i = 4; *q = NULLCHAR; - DrawUnicode(canvas, buf, x, y, PieceToChar(n), flip); + DrawUnicode(canvas, buf, x, y, PieceToChar(n), flip, size, i); } void