diff options
author | Ruben Undheim <ruben.undheim@gmail.com> | 2018-10-20 17:54:32 +0200 |
---|---|---|
committer | Ruben Undheim <ruben.undheim@gmail.com> | 2018-10-20 17:54:32 +0200 |
commit | ca2442640f4394296d9d6b0c42d41d399dbf9667 (patch) | |
tree | 879c0a6065d6982d5a82b35dc3ff67299e2ea7d9 /svg.c | |
parent | 04d5d0ea0f65a434e568fe031f6396caec9b3a8d (diff) |
New upstream version 3.9.73+dfsg.1
Diffstat (limited to 'svg.c')
-rw-r--r-- | svg.c | 100 |
1 files changed, 62 insertions, 38 deletions
@@ -5,6 +5,7 @@ #include <stdio.h> #include <stdlib.h> +#include <stdint.h> #include <string.h> #ifndef XC_WIN32 #include <unistd.h> @@ -53,7 +54,6 @@ extern Display *dpy; extern Pixmap STIPPLE[8]; extern XCWindowData *areawin; extern Globaldata xobjs; -extern int *appcolors; extern colorindex *colorlist; extern int number_colors; extern fontinfo *fonts; @@ -70,18 +70,12 @@ FILE *svgf; void svg_printcolor(int passcolor, char *prefix) { - int i; - if (passcolor != DEFAULTCOLOR) { - for (i = 0; i < number_colors; i++) { - if (colorlist[i].color.pixel == passcolor) break; - } - if (i < number_colors) { - fprintf(svgf, "%s\"#%02x%02x%02x\" ", + if ((passcolor < number_colors) && (passcolor != DEFAULTCOLOR)) { + fprintf(svgf, "%s\"#%02x%02x%02x\" ", prefix, - (colorlist[i].color.red >> 8), - (colorlist[i].color.green >> 8), - (colorlist[i].color.blue >> 8)); - } + (colorlist[passcolor].color.red >> 8), + (colorlist[passcolor].color.green >> 8), + (colorlist[passcolor].color.blue >> 8)); } } @@ -229,13 +223,17 @@ void SVGCreateImages(int page) fname = tmpnam(NULL); ppf = fopen(fname, "w"); if (ppf != NULL) { - fprintf(ppf, "P6 %d %d 255\n", img->image->width, img->image->height); - for (y = 0; y < img->image->height; y++) { - for (x = 0; x < img->image->width; x++) { - pixel.i = XGetPixel(img->image, x, y); - fwrite(&pixel.b[2], 1, 1, ppf); - fwrite(&pixel.b[1], 1, 1, ppf); - fwrite(&pixel.b[0], 1, 1, ppf); + int width, height; + width = xcImageGetWidth(img->image); + height = xcImageGetWidth(img->image); + fprintf(ppf, "P6 %d %d 255\n", width, height); + for (y = 0; y < height; y++) { + for (x = 0; x < width; x++) { + u_char r, g, b; + xcImageGetPixel(img->image, x, y, &r, &g, &b); + fwrite(&r, 1, 1, ppf); + fwrite(&g, 1, 1, ppf); + fwrite(&b, 1, 1, ppf); } } } @@ -274,7 +272,9 @@ void SVGDrawGraphic(graphicptr gp) int i; char outname[128], *pptr; float tscale; - int rotation; + float rotation; + int width = xcImageGetWidth(gp->source); + int height = xcImageGetHeight(gp->source); for (i = 0; i < xobjs.images; i++) { img = xobjs.imagelist + i; @@ -291,20 +291,19 @@ void SVGDrawGraphic(graphicptr gp) UPushCTM(); UPreMultCTM(DCTM, gp->position, gp->scale, gp->rotation); - corner.x = -(gp->source->width >> 1); - corner.y = (gp->source->height >> 1); + corner.x = -(width >> 1); + corner.y = (height >> 1); UTransformbyCTM(DCTM, &corner, &ppt, 1); UPopCTM(); tscale = gp->scale * UTopScale(); rotation = gp->rotation + UTopRotation(); - if (rotation >= 360) rotation -= 360; - else if (rotation < 0) rotation += 360; + if (rotation >= 360.0) rotation -= 360.0; + else if (rotation < 0.0) rotation += 360.0; - fprintf(svgf, "<image transform=\"translate(%d,%d) scale(%g) rotate(%d)\"\n", + fprintf(svgf, "<image transform=\"translate(%d,%d) scale(%g) rotate(%f)\"\n", ppt.x, ppt.y, tscale, rotation); - fprintf(svgf, " width=\"%dpx\" height=\"%dpx\"", - gp->source->width, gp->source->height); + fprintf(svgf, " width=\"%dpx\" height=\"%dpx\"", width, height); fprintf(svgf, " xlink:href=\"%s\">\n", outname); fprintf(svgf, "</image>\n"); } @@ -519,7 +518,7 @@ void SVGDrawObject(objinstptr theinstance, short level, int passcolor, pushlistp case(LABEL): if (level == 0 || TOLABEL(areagen)->pin == False || - (TOLABEL(areagen)->justify & PINVISIBLE)) + (TOLABEL(areagen)->anchor & PINVISIBLE)) SVGDrawString(TOLABEL(areagen), curcolor, theinstance); break; } @@ -546,15 +545,17 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) { stringpart *strptr; char *textptr; - short fstyle, ffont, tmpjust, baseline, deltay; + short fstyle, ffont, tmpanchor, baseline, deltay; int pos, defaultcolor, curcolor, scolor; short oldx, oldfont, oldstyle; int olinerise = 4; float tmpscale = 1.0, natscale = 1.0; XPoint newpoint; TextExtents tmpext; + TextLinesInfo tlinfo; short *tabstops = NULL; short tabno, numtabs = 0, group = 0; + short linenum = 0; int open_text, open_span, open_decor; XPoint *decorations = NULL; short nvals = 0; @@ -618,8 +619,8 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) UPushCTM(); UPreMultCTM(DCTM, drawlabel->position, drawlabel->scale, drawlabel->rotation); - /* check for flip invariance; recompute CTM and justification if necessary */ - tmpjust = flipadjust(drawlabel->justify); + /* check for flip invariance; recompute CTM and anchoring if necessary */ + tmpanchor = flipadjust(drawlabel->anchor); /* Note that the Y-scale is inverted or text comes out upside-down. But we */ /* need to adjust to the Y baseline. */ @@ -631,19 +632,22 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) fprintf(svgf, ">\n"); /* "natural" (unscaled) length */ - tmpext = ULength(drawlabel, localinst, 0, NULL); - - newpoint.x = (tmpjust & NOTLEFT ? - (tmpjust & RIGHT ? -tmpext.maxwidth : -tmpext.maxwidth >> 1) : 0); - newpoint.y = (tmpjust & NOTBOTTOM ? - (tmpjust & TOP ? -tmpext.ascent : -(tmpext.ascent + tmpext.base) >> 1) + tlinfo.dostop = 0; + tlinfo.tbreak = NULL; + tlinfo.padding = NULL; + tmpext = ULength(drawlabel, localinst, &tlinfo); + + newpoint.x = (tmpanchor & NOTLEFT ? + (tmpanchor & RIGHT ? -tmpext.maxwidth : -tmpext.maxwidth >> 1) : 0); + newpoint.y = (tmpanchor & NOTBOTTOM ? + (tmpanchor & TOP ? -tmpext.ascent : -(tmpext.ascent + tmpext.base) >> 1) : -tmpext.base); /* Pinlabels have an additional offset spacing to pad */ /* them from the circuit point to which they attach. */ if (drawlabel->pin) { - pinadjust(tmpjust, &(newpoint.x), &(newpoint.y), 1); + pinadjust(tmpanchor, &(newpoint.x), &(newpoint.y), 1); } oldx = newpoint.x; @@ -653,6 +657,16 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) open_span = 0; open_decor = 0; pos = 0; + + /* Adjust for center or right justification */ + if (tlinfo.padding != NULL) { + if (tmpanchor & JUSTIFYRIGHT) + newpoint.x += tlinfo.padding[linenum]; + else if (tmpanchor & TEXTCENTERED) + newpoint.x += 0.5 * tlinfo.padding[linenum]; + linenum++; + } + for (strptr = drawlabel->string; strptr != NULL; strptr = nextstringpart(strptr, localinst)) { @@ -833,6 +847,15 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) baseline -= BASELINE; newpoint.y = baseline; newpoint.x = oldx; + + if (tlinfo.padding != NULL) { + if (tmpanchor & JUSTIFYRIGHT) + newpoint.x += tlinfo.padding[linenum]; + else if (tmpanchor & TEXTCENTERED) + newpoint.x += 0.5 * tlinfo.padding[linenum]; + linenum++; + } + fprintf(svgf, "<tspan x=\"%d\" y=\"%d\">", newpoint.x, -newpoint.y); open_span++; break; @@ -968,6 +991,7 @@ void SVGDrawString(labelptr drawlabel, int passcolor, objinstptr localinst) UPopCTM(); if (tabstops != NULL) free(tabstops); + if (tlinfo.padding != NULL) free(tlinfo.padding); /* If there were decorations (underlines, overlines), generate them */ |