From 249fdd69a26163440d75de9f234f54fcca393e61 Mon Sep 17 00:00:00 2001 From: stefan schippers Date: Mon, 16 Jan 2023 12:21:35 +0100 Subject: [PATCH] temporary fix for building xschem. Some warnings due to rev >c89 to be fixed, and proper detection of libjpeg must be added --- scconfig/hooks.c | 38 +++++++ src/Makefile.in | 4 +- src/cairo_jpg.c | 109 +++++++++---------- src/draw.c | 20 ++-- src/psprint.c | 267 ++++++++++++++++++++++++----------------------- src/xinit.c | 4 +- src/xschem.h | 3 +- 7 files changed, 245 insertions(+), 200 deletions(-) diff --git a/scconfig/hooks.c b/scconfig/hooks.c index 6b465884..e46729b6 100644 --- a/scconfig/hooks.c +++ b/scconfig/hooks.c @@ -9,6 +9,44 @@ #define version "2.0.1" +int find_sul_pcre(const char *name, int logdepth, int fatal) +{ + const char *test_c = + NL "#include " + NL "#include " + NL "#include " + NL "int main()" + NL "{" + NL " const char *err;" + NL " int erro, ret;" + NL " pcre *p = pcre_compile(\"fo+b\", 0, &err, &erro, NULL);" + NL " ret = pcre_exec(p, NULL, \"hi foobar\", 9, 0, 0, &erro, 1);" + NL " if (ret == 0)" + NL " puts(\"OK\");" + NL " return 0;" + NL "}" + NL; + + const char *node = "libs/sul/pcre"; + + if (require("cc/cc", logdepth, fatal)) + return 1; + + report("Checking for pcre... "); + + if (try_icl_pkg_config(logdepth, "libs/sul/pcre", test_c, NULL, "libpcre", NULL)) + return 0; + + if (try_icl(logdepth, node, test_c, NULL, "-I/usr/include/pcre", "-lpcre")) + return 0; + + if (try_icl(logdepth, node, test_c, NULL, "-I/usr/include/pcre", "-lpcre3")) + return 0; + + return try_fail(logdepth, node); +} + + static void help(void) { printf("./configure: configure xschem.\n"); diff --git a/src/Makefile.in b/src/Makefile.in index 11dc9c55..a3be5184 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -5,7 +5,7 @@ put /local/src { select.c font.c editprop.c save.c paste.c token.c psprint.c node_hash.c hilight.c options.c vhdl_netlist.c svgdraw.c spice_netlist.c tedax_netlist.c verilog_netlist.c parselabel.c expandlabel.c - in_memory_undo.c + in_memory_undo.c cairo_jpg.c } # list all files that need to be installed in "$(XSHAREDIR)" @@ -40,7 +40,7 @@ rawtovcd: rawtovcd.o $(CC) -o rawtovcd rawtovcd.o -lm xschem: $(OBJ) - $(CC) -o xschem $(OBJ) $(LDFLAGS) + $(CC) -o xschem $(OBJ) $(LDFLAGS) -ljpeg parselabel.c: parselabel.l expandlabel.h flex -l -oparselabel.c parselabel.l diff --git a/src/cairo_jpg.c b/src/cairo_jpg.c index 64afac54..82ff3406 100644 --- a/src/cairo_jpg.c +++ b/src/cairo_jpg.c @@ -57,8 +57,9 @@ /*! Macro to activate main() function. This is only used for testing. Comment * it out (#undef) if you link this file to your own program. */ -//#define CAIRO_JPEG_MAIN -// + +/* #define CAIRO_JPEG_MAIN */ + /*! Define this to use an alternate implementation of * cairo_image_surface_create_from_jpeg() which fstat(3)s the file before * reading (see below). For huge files this /may/ be slightly faster. @@ -107,7 +108,7 @@ static void pix_conv(unsigned char *dst, int dw, const unsigned char *src, int s { int si, di; - // safety check + /* safety check */ if (dw < 3 || sw < 3 || dst == NULL || src == NULL) return; @@ -119,7 +120,7 @@ static void pix_conv(unsigned char *dst, int dw, const unsigned char *src, int s dst[di + 1] = src[si + 1]; dst[di + 0] = src[si + 2]; #else - // FIXME: This is untested, it may be wrong. + /* FIXME: This is untested, it may be wrong. */ dst[di - 3] = src[si - 3]; dst[di - 2] = src[si - 2]; dst[di - 1] = src[si - 1]; @@ -157,49 +158,49 @@ cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsig JSAMPROW row_pointer[1]; cairo_surface_t *other = NULL; - // check valid input format (must be IMAGE_SURFACE && (ARGB32 || RGB24)) + /* check valid input format (must be IMAGE_SURFACE && (ARGB32 || RGB24)) */ if (cairo_surface_get_type(sfc) != CAIRO_SURFACE_TYPE_IMAGE || (cairo_image_surface_get_format(sfc) != CAIRO_FORMAT_ARGB32 && cairo_image_surface_get_format(sfc) != CAIRO_FORMAT_RGB24)) { - // create a similar surface with a proper format if supplied input format - // does not fulfill the requirements + /* create a similar surface with a proper format if supplied input format */ + /* does not fulfill the requirements */ double x1, y1, x2, y2; other = sfc; cairo_t *ctx = cairo_create(other); - // get extents of original surface + /* get extents of original surface */ cairo_clip_extents(ctx, &x1, &y1, &x2, &y2); cairo_destroy(ctx); - // create new image surface + /* create new image surface */ sfc = cairo_surface_create_similar_image(other, CAIRO_FORMAT_RGB24, x2 - x1, y2 - y1); if (cairo_surface_status(sfc) != CAIRO_STATUS_SUCCESS) return CAIRO_STATUS_INVALID_FORMAT; - // paint original surface to new surface + /* paint original surface to new surface */ ctx = cairo_create(sfc); cairo_set_source_surface(ctx, other, 0, 0); cairo_paint(ctx); cairo_destroy(ctx); } - // finish queued drawing operations + /* finish queued drawing operations */ cairo_surface_flush(sfc); - // init jpeg compression structures + /* init jpeg compression structures */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_compress(&cinfo); - // set compression parameters + /* set compression parameters */ jpeg_mem_dest(&cinfo, data, len); cinfo.image_width = cairo_image_surface_get_width(sfc); cinfo.image_height = cairo_image_surface_get_height(sfc); #ifdef LIBJPEG_TURBO_VERSION #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ - //cinfo.in_color_space = JCS_EXT_BGRX; + /* cinfo.in_color_space = JCS_EXT_BGRX; */ cinfo.in_color_space = cairo_image_surface_get_format(sfc) == CAIRO_FORMAT_ARGB32 ? JCS_EXT_BGRA : JCS_EXT_BGRX; #else - //cinfo.in_color_space = JCS_EXT_XRGB; + /* cinfo.in_color_space = JCS_EXT_XRGB; */ cinfo.in_color_space = cairo_image_surface_get_format(sfc) == CAIRO_FORMAT_ARGB32 ? JCS_EXT_ARGB : JCS_EXT_XRGB; #endif cinfo.input_components = 4; @@ -210,10 +211,10 @@ cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsig jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE); - // start compressor + /* start compressor */ jpeg_start_compress(&cinfo, TRUE); - // loop over all lines and compress + /* loop over all lines and compress */ while (cinfo.next_scanline < cinfo.image_height) { #ifdef LIBJPEG_TURBO_VERSION @@ -221,7 +222,7 @@ cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsig * cairo_image_surface_get_stride(sfc)); #else unsigned char* row_buf = malloc(3 * cinfo.image_width); - //unsigned char row_buf[3 * cinfo.image_width]; + /* unsigned char row_buf[3 * cinfo.image_width]; */ pix_conv(row_buf, 3, cairo_image_surface_get_data(sfc) + (cinfo.next_scanline * cairo_image_surface_get_stride(sfc)), 4, cinfo.image_width); row_pointer[0] = row_buf; @@ -229,11 +230,11 @@ cairo_status_t cairo_image_surface_write_to_jpeg_mem(cairo_surface_t *sfc, unsig (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); } - // finalize and close everything + /* finalize and close everything */ jpeg_finish_compress(&cinfo); jpeg_destroy_compress(&cinfo); - // destroy temporary image surface (if available) + /* destroy temporary image surface (if available) */ if (other != NULL) cairo_surface_destroy(sfc); @@ -270,14 +271,14 @@ cairo_status_t cairo_image_surface_write_to_jpeg_stream(cairo_surface_t *sfc, ca unsigned char *data = NULL; size_t len = 0; - // create JPEG data in memory from surface + /* create JPEG data in memory from surface */ if ((e = cairo_image_surface_write_to_jpeg_mem(sfc, &data, &len, quality)) != CAIRO_STATUS_SUCCESS) return e; - // write whole memory block with stream function + /* write whole memory block with stream function */ e = write_func(closure, data, len); - // free JPEG memory again and return the return value + /* free JPEG memory again and return the return value */ free(data); return e; @@ -301,14 +302,14 @@ cairo_status_t cairo_image_surface_write_to_jpeg(cairo_surface_t *sfc, const cha cairo_status_t e; int outfile; - // Open/create new file + /* Open/create new file */ if ((outfile = open(filename, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)) == -1) return CAIRO_STATUS_DEVICE_ERROR; - // write surface to file + /* write surface to file */ e = cairo_image_surface_write_to_jpeg_stream(sfc, cj_write, (void*)(intptr_t) outfile, quality); - // close file again and return + /* close file again and return */ close(outfile); return e; } @@ -330,7 +331,7 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_mem(void *data, size_t len JSAMPROW row_pointer[1]; cairo_surface_t *sfc; - // initialize jpeg decompression structures + /* initialize jpeg decompression structures */ cinfo.err = jpeg_std_error(&jerr); jpeg_create_decompress(&cinfo); jpeg_mem_src(&cinfo, data, len); @@ -346,10 +347,10 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_mem(void *data, size_t len cinfo.out_color_space = JCS_RGB; #endif - // start decompressor + /* start decompressor */ (void) jpeg_start_decompress(&cinfo); - // create Cairo image surface + /* create Cairo image surface */ sfc = cairo_image_surface_create(CAIRO_FORMAT_RGB24, cinfo.output_width, cinfo.output_height); if (cairo_surface_status(sfc) != CAIRO_STATUS_SUCCESS) { @@ -357,7 +358,7 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_mem(void *data, size_t len return sfc; } - // loop over all scanlines and fill Cairo image surface + /* loop over all scanlines and fill Cairo image surface */ while (cinfo.output_scanline < cinfo.output_height) { unsigned char *row_address = cairo_image_surface_get_data(sfc) + @@ -369,12 +370,12 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_mem(void *data, size_t len #endif } - // finish and close everything + /* finish and close everything */ cairo_surface_mark_dirty(sfc); (void) jpeg_finish_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); - // set jpeg mime data + /* set jpeg mime data */ cairo_surface_set_mime_data(sfc, CAIRO_MIME_TYPE_JPEG, data, len, free, data); return sfc; @@ -403,39 +404,39 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg_stream(cairo_read_func_t r ssize_t len, rlen; int eof = 0; - // read all data into memory buffer in blocks of CAIRO_JPEG_IO_BLOCK_SIZE + /* read all data into memory buffer in blocks of CAIRO_JPEG_IO_BLOCK_SIZE */ for (len = 0, data = NULL; !eof; len += rlen) { - // grow memory buffer and check for error + /* grow memory buffer and check for error */ if ((tmp = realloc(data, len + CAIRO_JPEG_IO_BLOCK_SIZE)) == NULL) break; data = tmp; - // read bytes into buffer and check for error + /* read bytes into buffer and check for error */ rlen = read_func(closure, data + len, CAIRO_JPEG_IO_BLOCK_SIZE); #ifdef USE_CAIRO_READ_FUNC_LEN_T - // check for error + /* check for error */ if (rlen == -1) break; - // check if EOF occured + /* check if EOF occured */ if (rlen < CAIRO_JPEG_IO_BLOCK_SIZE) eof++; #else - // check for error + /* check for error */ if (rlen == CAIRO_STATUS_READ_ERROR) eof++; #endif } - // check for error in read loop + /* check for error in read loop */ if (!eof) { free(data); return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); } - // call jpeg decompression and return surface + /* call jpeg decompression and return surface */ sfc = cairo_image_surface_create_from_jpeg_mem(data, len); if (cairo_surface_status(sfc) != CAIRO_STATUS_SUCCESS) free(data); @@ -462,19 +463,19 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg(const char *filename) int infile; struct stat stat; - // open input file + /* open input file */ if ((infile = open(filename, O_RDONLY)) == -1) return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); - // get stat structure for file size + /* get stat structure for file size */ if (fstat(infile, &stat) == -1) return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); - // allocate memory + /* allocate memory */ if ((data = malloc(stat.st_size)) == NULL) return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); - // read data + /* read data */ int s = read(infile, data, stat.st_size); if ( s < stat.st_size) return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); @@ -520,11 +521,11 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg(const char *filename) cairo_surface_t *sfc; int infile; - // open input file + /* open input file */ if ((infile = open(filename, O_RDONLY)) == -1) return cairo_image_surface_create(CAIRO_FORMAT_INVALID, 0, 0); - // call stream loading function + /* call stream loading function */ sfc = cairo_image_surface_create_from_jpeg_stream(cj_read, (void*)(intptr_t) infile); close(infile); @@ -540,7 +541,7 @@ cairo_surface_t *cairo_image_surface_create_from_jpeg(const char *filename) int strrcasecmp(const char *s1, const char *s2) { - int off = (int) strlen(s1) - (int) strlen(s2); // typecast size_t to int because size_t typically is unsigned + int off = (int) strlen(s1) - (int) strlen(s2); /* typecast size_t to int because size_t typically is unsigned */ return strcasecmp(s1 + (off < 0 ? 0 : off), s2); } @@ -558,15 +559,15 @@ int main(int argc, char **argv) return 1; } - // test input file type and read file + /* test input file type and read file */ if (!strrcasecmp(argv[1], ".png")) { - // read PNG file + /* read PNG file */ sfc = cairo_image_surface_create_from_png(argv[1]); } else if (!strrcasecmp(argv[1], ".jpg")) { - // read JPEG file + /* read JPEG file */ sfc = cairo_image_surface_create_from_jpeg(argv[1]); } else @@ -575,22 +576,22 @@ int main(int argc, char **argv) return 1; } - // check surface status + /* check surface status */ if (cairo_surface_status(sfc) != CAIRO_STATUS_SUCCESS) { fprintf(stderr, "error loading image: %s", cairo_status_to_string(cairo_surface_status(sfc))); return 2; } - // test output file type and write file + /* test output file type and write file */ if (!strrcasecmp(argv[2], ".png")) { - // write PNG file + /* write PNG file */ cairo_surface_write_to_png(sfc, argv[2]); } else if (!strrcasecmp(argv[2], ".jpg")) { - // write JPEG file + /* write JPEG file */ cairo_image_surface_write_to_jpeg(sfc, argv[2], 90); } else diff --git a/src/draw.c b/src/draw.c index 7ee44951..8b2ba0fc 100644 --- a/src/draw.c +++ b/src/draw.c @@ -981,7 +981,7 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub if(xctx->draw_pixmap) XDrawLine(display, xctx->save_pixmap, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); if(dash) { - XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); } #if !defined(__unix__) && defined(HAS_CAIRO) check_cairo_drawline(ct, c, x1, y1, x2, y2, dash); @@ -1002,14 +1002,14 @@ void drawline(int c, int what, double linex1, double liney1, double linex2, doub XSetDashes(display, xctx->gc[c], 0, dash_arr, 1); XSetLineAttributes (display, xctx->gc[c], INT_BUS_WIDTH(xctx->lw), xDashType, xCap, xJoin); } else { - XSetLineAttributes (display, xctx->gc[c], INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound, JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_BUS_WIDTH(xctx->lw), LineSolid, LINECAP, LINEJOIN); } if(xctx->draw_window) XDrawLine(display, xctx->window, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); if(xctx->draw_pixmap) XDrawLine(display, xctx->save_pixmap, xctx->gc[c], (int)x1, (int)y1, (int)x2, (int)y2); #if !defined(__unix__) && defined(HAS_CAIRO) check_cairo_drawline(ct, c, x1, y1, x2, y2, dash); #endif - XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw), LineSolid, LINECAP , LINEJOIN); } } else if((what & END) && i) @@ -1087,10 +1087,10 @@ void drawtempline(GC gc, int what, double linex1,double liney1,double linex2,dou y2=Y_TO_SCREEN(liney2); if( clip(&x1,&y1,&x2,&y2) ) { - XSetLineAttributes (display, gc, INT_BUS_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc, INT_BUS_WIDTH(xctx->lw), LineSolid, LINECAP , LINEJOIN); XDrawLine(display, xctx->window, gc, (int)x1, (int)y1, (int)x2, (int)y2); - XSetLineAttributes (display, gc, INT_WIDTH(xctx->lw), LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, gc, INT_WIDTH(xctx->lw), LineSolid, LINECAP , LINEJOIN); } } @@ -1346,7 +1346,7 @@ void drawarc(int c, int what, double x, double y, double r, double a, double b, } } if(dash) { - XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, LINECAP , LINEJOIN); } } } @@ -1534,7 +1534,7 @@ void drawpolygon(int c, int what, double *x, double *y, int points, int poly_fil } } if(dash) { - XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, LINECAP , LINEJOIN); } my_free(722, &p); } @@ -1595,7 +1595,7 @@ void drawrect(int c, int what, double rectx1,double recty1,double rectx2,double (unsigned int)y2 - (unsigned int)y1); } if(dash) { - XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gc[c], INT_WIDTH(xctx->lw) ,LineSolid, LINECAP, LINEJOIN); } } } @@ -1862,11 +1862,11 @@ static void set_thick_waves(int what, int wcnt, int wave_col, Graph_ctx *gr) if(what) { if(gr->hilight_wave == wcnt) XSetLineAttributes (display, xctx->gc[wave_col], - 3 * INT_WIDTH(xctx->lw) ,LineSolid, CapRound , JoinRound); + 3 * INT_WIDTH(xctx->lw) ,LineSolid, LINECAP , LINEJOIN); } else { if(gr->hilight_wave == wcnt) XSetLineAttributes (display, xctx->gc[wave_col], - (int)(xctx->lw) ,LineSolid, CapRound , JoinRound); + (int)(xctx->lw) ,LineSolid, LINECAP , LINEJOIN); } } diff --git a/src/psprint.c b/src/psprint.c index f8313c0f..4e8e5259 100644 --- a/src/psprint.c +++ b/src/psprint.c @@ -100,77 +100,78 @@ static char ps_font_family[80] = "Helvetica"; /* Courier Times Helvetica Symbol typedef struct { - unsigned char* buffer; - size_t pos; - size_t size; + unsigned char* buffer; + size_t pos; + size_t size; } png_to_byte_closure_t; cairo_status_t png_reader(void* in_closure, unsigned char* out_data, unsigned int length) { - png_to_byte_closure_t* closure = (png_to_byte_closure_t*)in_closure; - if (!closure->buffer) return CAIRO_STATUS_READ_ERROR; - memcpy(out_data, closure->buffer + closure->pos, length); - closure->pos += length; - return CAIRO_STATUS_SUCCESS; + png_to_byte_closure_t* closure = (png_to_byte_closure_t*)in_closure; + if (!closure->buffer) return CAIRO_STATUS_READ_ERROR; + memcpy(out_data, closure->buffer + closure->pos, length); + closure->pos += length; + return CAIRO_STATUS_SUCCESS; } char* bin2hex(const unsigned char* bin, size_t len) { - char* out; - size_t i; + char* out; + size_t i; - if (bin == NULL || len == 0) - return NULL; + if (bin == NULL || len == 0) + return NULL; - out = malloc(len * 2 + 1); - for (i = 0; i < len; i++) { - out[i * 2] = "0123456789abcdef"[bin[i] >> 4]; - out[i * 2 + 1] = "0123456789abcdef"[bin[i] & 0x0F]; - } - out[len * 2] = '\0'; + out = malloc(len * 2 + 1); + for (i = 0; i < len; i++) { + out[i * 2] = "0123456789abcdef"[bin[i] >> 4]; + out[i * 2 + 1] = "0123456789abcdef"[bin[i] & 0x0F]; + } + out[len * 2] = '\0'; - return out; + return out; } void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2) { - size_t data_size; - png_to_byte_closure_t closure; - char* filter = NULL; - my_strdup(1484, &filter, get_tok_value(r->prop_ptr, "filter", 0)); - unsigned char* image_data64_ptr = get_tok_value(r->prop_ptr, "image_data", 0); + int i; + size_t data_size; + png_to_byte_closure_t closure; + char* filter = NULL; + my_strdup(1484, &filter, get_tok_value(r->prop_ptr, "filter", 0)); + unsigned char* image_data64_ptr = get_tok_value(r->prop_ptr, "image_data", 0); - if (filter) { - size_t filtersize = 0; - char* filterdata = NULL; - closure.buffer = NULL; - filterdata = (char*)base64_decode(image_data64_ptr, strlen(image_data64_ptr), &filtersize); - filter_data(filterdata, filtersize, (char**)&closure.buffer, &data_size, filter); - my_free(1488, &filterdata); - } - else { - closure.buffer = base64_decode(image_data64_ptr, strlen(image_data64_ptr), &data_size); - } - closure.pos = 0; - closure.size = data_size; /* should not be necessary */ - cairo_surface_t* surface = cairo_image_surface_create_from_png_stream(png_reader, &closure); + if (filter) { + size_t filtersize = 0; + char* filterdata = NULL; + closure.buffer = NULL; + filterdata = (char*)base64_decode(image_data64_ptr, strlen(image_data64_ptr), &filtersize); + filter_data(filterdata, filtersize, (char**)&closure.buffer, &data_size, filter); + my_free(1488, &filterdata); + } + else { + closure.buffer = base64_decode(image_data64_ptr, strlen(image_data64_ptr), &data_size); + } + closure.pos = 0; + closure.size = data_size; /* should not be necessary */ + cairo_surface_t* surface = cairo_image_surface_create_from_png_stream(png_reader, &closure); - int png_size_x = cairo_image_surface_get_width(surface); - int png_size_y = cairo_image_surface_get_height(surface); + int png_size_x = cairo_image_surface_get_width(surface); + int png_size_y = cairo_image_surface_get_height(surface); - cairo_surface_flush(surface); - unsigned char* png_data = cairo_image_surface_get_data(surface); + cairo_surface_flush(surface); + unsigned char* png_data = cairo_image_surface_get_data(surface); - unsigned char* invertImage = get_tok_value(r->prop_ptr, "InvertOnExport", 0); - unsigned char BG_r = 0xFF, BG_g = 0xFF, BG_b = 0xFF; - for (int i = 0; i < (png_size_x * png_size_y * 4); i += 4) - { + unsigned char* invertImage = get_tok_value(r->prop_ptr, "InvertOnExport", 0); + unsigned char BG_r = 0xFF, BG_g = 0xFF, BG_b = 0xFF; + for (i = 0; i < (png_size_x * png_size_y * 4); i += 4) + { - unsigned char png_r = png_data[i + 0]; - unsigned char png_g = png_data[i + 1]; - unsigned char png_b = png_data[i + 2]; - unsigned char png_a = png_data[i + 3]; + unsigned char png_r = png_data[i + 0]; + unsigned char png_g = png_data[i + 1]; + unsigned char png_b = png_data[i + 2]; + unsigned char png_a = png_data[i + 3]; if(invertImage[0]=='1') { @@ -185,43 +186,43 @@ void ps_drawPNG(xRect* r, double x1, double y1, double x2, double y2) png_data[i + 2] = png_b + (unsigned char)((double)BG_b * ((double)(0xFF - png_a)) / ((double)(0xFF))); png_data[i + 3] = 0xFF; } - - } - cairo_surface_mark_dirty(surface); + + } + cairo_surface_mark_dirty(surface); static char str[PATH_MAX]; my_snprintf(str, S(str), "%s%s", tclgetvar("XSCHEM_TMP_DIR"), "/temp.jpg"); - cairo_image_surface_write_to_jpeg(surface, str, 100); - unsigned char* jpgData; - FILE* fp; - fp = fopen(str, "rb"); /* Open the file for reading */ - fseek(fp, 0L, SEEK_END); - int fileSize = ftell(fp); - rewind(fp); - jpgData = malloc(fileSize); - fread(jpgData, sizeof(jpgData[0]), fileSize, fp); - fclose(fp); + cairo_image_surface_write_to_jpeg(surface, str, 100); + unsigned char* jpgData; + FILE* fp; + fp = fopen(str, "rb"); /* Open the file for reading */ + fseek(fp, 0L, SEEK_END); + int fileSize = ftell(fp); + rewind(fp); + jpgData = malloc(fileSize); + fread(jpgData, sizeof(jpgData[0]), fileSize, fp); + fclose(fp); - unsigned char* hexEncodedJPG = bin2hex(jpgData, fileSize); + unsigned char* hexEncodedJPG = bin2hex(jpgData, fileSize); - fprintf(fd, "gsave\n"); - fprintf(fd, "%g %g translate\n", X_TO_PS(x1), Y_TO_PS(y1)); - fprintf(fd, "%g %g scale\n", X_TO_PS(x2) - X_TO_PS(x1), Y_TO_PS(y2) - Y_TO_PS(y1)); - fprintf(fd, "%d\n", png_size_x); - fprintf(fd, "%d\n", png_size_y); - fprintf(fd, "8\n"); - fprintf(fd, "[%d 0 0 %d 0 0]\n", png_size_x, png_size_y); - fprintf(fd, "(%s)\n", hexEncodedJPG); - fprintf(fd, "/ASCIIHexDecode\n"); - fprintf(fd, "filter\n"); - fprintf(fd, "0 dict\n"); - fprintf(fd, "/DCTDecode\n"); - fprintf(fd, "filter\n"); - fprintf(fd, "false\n"); - fprintf(fd, "3\n"); - fprintf(fd, "colorimage\n"); - fprintf(fd, "grestore\n"); + fprintf(fd, "gsave\n"); + fprintf(fd, "%g %g translate\n", X_TO_PS(x1), Y_TO_PS(y1)); + fprintf(fd, "%g %g scale\n", X_TO_PS(x2) - X_TO_PS(x1), Y_TO_PS(y2) - Y_TO_PS(y1)); + fprintf(fd, "%d\n", png_size_x); + fprintf(fd, "%d\n", png_size_y); + fprintf(fd, "8\n"); + fprintf(fd, "[%d 0 0 %d 0 0]\n", png_size_x, png_size_y); + fprintf(fd, "(%s)\n", hexEncodedJPG); + fprintf(fd, "/ASCIIHexDecode\n"); + fprintf(fd, "filter\n"); + fprintf(fd, "0 dict\n"); + fprintf(fd, "/DCTDecode\n"); + fprintf(fd, "filter\n"); + fprintf(fd, "false\n"); + fprintf(fd, "3\n"); + fprintf(fd, "colorimage\n"); + fprintf(fd, "grestore\n"); - free(hexEncodedJPG); free(jpgData); + free(hexEncodedJPG); free(jpgData); } @@ -287,53 +288,53 @@ void ps_embedded_graph(xRect* r, double rx1, double ry1, double rx2, double ry2) closure.size = 0; closure.pos = 0; - static char str[PATH_MAX]; + static char str[PATH_MAX]; my_snprintf(str, S(str), "%s%s", tclgetvar("XSCHEM_TMP_DIR"), "/temp.jpg"); - cairo_image_surface_write_to_jpeg(png_sfc, str, 100); + cairo_image_surface_write_to_jpeg(png_sfc, str, 100); - unsigned char* jpgData; - FILE* fp; - fp = fopen(str, "rb"); - fseek(fp, 0L, SEEK_END); - int fileSize = ftell(fp); - rewind(fp); - jpgData = malloc(fileSize); - fread(jpgData, sizeof(jpgData[0]), fileSize, fp); - fclose(fp); + unsigned char* jpgData; + FILE* fp; + fp = fopen(str, "rb"); + fseek(fp, 0L, SEEK_END); + int fileSize = ftell(fp); + rewind(fp); + jpgData = malloc(fileSize); + fread(jpgData, sizeof(jpgData[0]), fileSize, fp); + fclose(fp); - unsigned char* hexEncodedJPG = bin2hex(jpgData, fileSize); + unsigned char* hexEncodedJPG = bin2hex(jpgData, fileSize); - cairo_surface_destroy(png_sfc); - xctx->draw_pixmap = 1; - xctx->draw_window = save_draw_window; - xctx->do_copy_area = 1; - tclsetboolvar("draw_grid", save_draw_grid); - save_restore_zoom(0); - resetwin(1, 1, 1, 0, 0); - change_linewidth(-1.); + cairo_surface_destroy(png_sfc); + xctx->draw_pixmap = 1; + xctx->draw_window = save_draw_window; + xctx->do_copy_area = 1; + tclsetboolvar("draw_grid", save_draw_grid); + save_restore_zoom(0); + resetwin(1, 1, 1, 0, 0); + change_linewidth(-1.); tclsetboolvar("dark_colorscheme", d_c); build_colors(0, 0); draw(); - fprintf(fd, "gsave\n"); - fprintf(fd, "%f %f translate\n", X_TO_PS(rx1), Y_TO_PS(ry1)); - fprintf(fd, "%f %f scale\n", X_TO_PS(rx2) - X_TO_PS(rx1), Y_TO_PS(ry2) - Y_TO_PS(ry1)); - fprintf(fd, "%d\n", rwi); - fprintf(fd, "%d\n", rhi); - fprintf(fd, "8\n"); - fprintf(fd, "[%d 0 0 %d 0 0]\n", rwi, rhi); - fprintf(fd, "(%s)\n", hexEncodedJPG); - fprintf(fd, "/ASCIIHexDecode\n"); - fprintf(fd, "filter\n"); - fprintf(fd, "0 dict\n"); - fprintf(fd, "/DCTDecode\n"); - fprintf(fd, "filter\n"); - fprintf(fd, "false\n"); - fprintf(fd, "3\n"); - fprintf(fd, "colorimage\n"); - fprintf(fd, "grestore\n"); + fprintf(fd, "gsave\n"); + fprintf(fd, "%f %f translate\n", X_TO_PS(rx1), Y_TO_PS(ry1)); + fprintf(fd, "%f %f scale\n", X_TO_PS(rx2) - X_TO_PS(rx1), Y_TO_PS(ry2) - Y_TO_PS(ry1)); + fprintf(fd, "%d\n", rwi); + fprintf(fd, "%d\n", rhi); + fprintf(fd, "8\n"); + fprintf(fd, "[%d 0 0 %d 0 0]\n", rwi, rhi); + fprintf(fd, "(%s)\n", hexEncodedJPG); + fprintf(fd, "/ASCIIHexDecode\n"); + fprintf(fd, "filter\n"); + fprintf(fd, "0 dict\n"); + fprintf(fd, "/DCTDecode\n"); + fprintf(fd, "filter\n"); + fprintf(fd, "false\n"); + fprintf(fd, "3\n"); + fprintf(fd, "colorimage\n"); + fprintf(fd, "grestore\n"); - free(hexEncodedJPG); free(jpgData); + free(hexEncodedJPG); free(jpgData); #endif } static void set_lw(void) @@ -842,7 +843,7 @@ static void ps_draw_symbol(int n,int layer, int what, short tmp_flip, short rot, ROTATION(rot, flip, 0.0,0.0,rect.x1,rect.y1,x1,y1); ROTATION(rot, flip, 0.0,0.0,rect.x2,rect.y2,x2,y2); RECTORDER(x1,y1,x2,y2); - if (rect.flags & 1024)//image + if (rect.flags & 1024) /* image */ { ps_drawPNG(&rect, x0 + x1, y0 + y1, x0 + x2, y0 + y2); continue; @@ -924,8 +925,7 @@ static void fill_ps_colors() } - - +#define A4 void create_ps(char **psfile, int what) { double dx, dy, scale, scaley; @@ -933,9 +933,14 @@ void create_ps(char **psfile, int what) static int numpages = 0; double margin=10; /* in postscript points, (1/72)". No need to add margin as xschem zoom full already has margins.*/ - /* Legal: 612 792 */ - double pagex=792;/* a4, in postscript points, (1/72)" */ - double pagey=612;/* a4, in postscript points, (1/72)" */ + /* Legal: 612 792, A4: 842 595 */ + #ifdef A4 + double pagex=842;/* a4, in postscript points, (1/72)" */ + double pagey=595;/* a4, in postscript points, (1/72)" */ + #else + double pagex=792;/* Legal, in postscript points, (1/72)" */ + double pagey=612;/* Legal, in postscript points, (1/72)" */ + #endif xRect boundbox; int c,i, textlayer; int old_grid; @@ -1113,13 +1118,13 @@ void create_ps(char **psfile, int what) } if (c == GRIDLAYER && (xctx->rect[c][i].flags & 1024)) { /* image */ xRect* r = &xctx->rect[c][i]; - //PNG Code Here + /* PNG Code Here */ ps_drawPNG(r, r->x1, r->y1, r->x2, r->y2); } - if (c == GRIDLAYER && (xctx->rect[c][i].flags & 1)) { /* graph */ - xRect* r = &xctx->rect[c][i]; - ps_embedded_graph(r, r->x1, r->y1, r->x2, r->y2); - } + if (c == GRIDLAYER && (xctx->rect[c][i].flags & 1)) { /* graph */ + xRect* r = &xctx->rect[c][i]; + ps_embedded_graph(r, r->x1, r->y1, r->x2, r->y2); + } } for(i=0;iarcs[c];i++) { diff --git a/src/xinit.c b/src/xinit.c index b10b1f35..b81c6c21 100644 --- a/src/xinit.c +++ b/src/xinit.c @@ -1726,9 +1726,9 @@ void change_linewidth(double w) linew = INT_WIDTH(xctx->lw); dbg(1, "Line width = %d\n", linew); for(i=0;igc[i], linew, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gc[i], linew, LineSolid, LINECAP , LINEJOIN); } - XSetLineAttributes (display, xctx->gctiled, linew, LineSolid, CapRound , JoinRound); + XSetLineAttributes (display, xctx->gctiled, linew, LineSolid, LINECAP , LINEJOIN); } if(!xctx->only_probes) { xctx->areax1 = -2*INT_WIDTH(xctx->lw); diff --git a/src/xschem.h b/src/xschem.h index d86f00b2..b5098626 100644 --- a/src/xschem.h +++ b/src/xschem.h @@ -378,7 +378,8 @@ do { \ #define DIG_NWAVES 0.1 /* inverse number: by default 10 digital traces per graph */ #define DIG_SPACE 0.07 /* trace extends from 0 to DIG_SPACE, so we have DIG_WAVES-DIG_SPACE * spacing between traces */ - +#define LINECAP CapRound /* CapNotLast, CapButt, CapRound, or CapProjecting */ +#define LINEJOIN JoinRound /* JoinMiter, JoinRound, or JoinBevel */ typedef struct { unsigned short type;