void MyWidget::transform_img_back() { if(image) delete image; image = transform_back(); this->update(); }
void pdf_drawchar(gfxdevice_t*dev, gfxfont_t*font, int glyphnr, gfxcolor_t*color, gfxmatrix_t*matrix) { internal_t*i = (internal_t*)dev->internal; if(!font) return; gfxglyph_t*glyph = &font->glyphs[glyphnr]; char as_shape = 0; if(!type3 && !ttf) {msg("<warning> No type3 enabled. Drawing char %d as shape", glyphnr);as_shape=1;} if(glyphnr>256-32) {msg("<warning> Drawing char %d as shape (not < 224)", glyphnr);as_shape=1;} if(as_shape) { reset_matrix(i); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); gfxline_t*line2 = gfxline_clone(glyph->line); gfxline_transform(line2, matrix); if(mkline(line2, i->p, i->config_xpad, i->config_ypad, 1.0, 1)) { PDF_fill(i->p); } gfxline_free(line2); } else { assert(gfxfontlist_hasfont(i->fontlist, font)); int fontid = (int)(ptroff_t)gfxfontlist_getuserdata(i->fontlist, font->id); gfxmatrix_t m = *matrix; m.m00*=64; m.m01*=64; m.m10*=64; m.m11*=64; if(ttf) { m.m10 = -m.m10; m.m11 = -m.m11; } if(!(fabs(m.m00 - i->m00) < 1e-6 && fabs(m.m01 - i->m01) < 1e-6 && fabs(m.m10 - i->m10) < 1e-6 && fabs(m.m11 - i->m11) < 1e-6)) { set_matrix(i, m.m00, m.m01, m.m10, m.m11); } double tx, ty; transform_back(i, m.tx+i->config_xpad, m.ty+i->config_ypad, &tx, &ty); PDF_setfont(i->p, fontid, ttf?16.0:1.0); PDF_setrgbcolor_fill(i->p, color->r/255.0, color->g/255.0, color->b/255.0); char name[32]; sprintf(name, "%c", glyphnr+32); if(fabs(tx - i->lastx) > 0.001 || ty != i->lasty) { PDF_show_xy2(i->p, name, strlen(name), tx, ty); } else { PDF_show2(i->p, name, strlen(name)); } i->lastx = tx + glyph->advance; i->lasty = ty; } }
void pdf_fillbitmap(gfxdevice_t*dev, gfxline_t*line, gfximage_t*img, gfxmatrix_t*matrix, gfxcxform_t*cxform) { internal_t*i = (internal_t*)dev->internal; int t,size=img->width*img->height; int has_alpha=0; for(t=0;t<size;t++) { if(img->data[t].a!=255) { has_alpha=1; break; } } double w = sqrt(matrix->m00*matrix->m00+matrix->m01*matrix->m01); double h = sqrt(matrix->m10*matrix->m10+matrix->m11*matrix->m11); double l1 = w*img->width; double l2 = h*img->height; double dpi_x = 72.0 / w; double dpi_y = 72.0 / h; double dpi = dpi_x>dpi_y?dpi_x:dpi_y; gfximage_t*rescaled_image = 0; if(i->config_maxdpi && dpi > i->config_maxdpi) { int newwidth = img->width*i->config_maxdpi/dpi; int newheight = img->height*i->config_maxdpi/dpi; rescaled_image = gfximage_rescale(img, newwidth, newheight); msg("<notice> Downscaling %dx%d image (dpi %f, %.0fx%.0f on page) to %dx%d (dpi %d)", img->width, img->height, dpi, l1, l2, newwidth, newheight, i->config_maxdpi); img = rescaled_image; } if(i->config_mindpi && dpi < i->config_mindpi && img->width>1 && img->height>1) { msg("<error> Found image of size %dx%d with dpi %f, minimum allowed dpi is %d", img->width, img->height, dpi, i->config_mindpi); exit(1); } char tempfile[128]; mktempname(tempfile, "jpg"); gfximage_save_jpeg(img, tempfile, 96); int imgid=-1; if(has_alpha) { char tempfile2[128]; mktempname(tempfile2, "jpg"); int t; int size = img->width*img->height; unsigned char*alpha = malloc(size); for(t=0;t<size;t++) { alpha[t] = img->data[t].a; } jpeg_save_gray(alpha, img->width, img->height, 97, tempfile2); free(alpha); int maskid = PDF_load_image(i->p, "jpeg", tempfile2, 0, "mask"); unlink(tempfile2); char masked[80]; if(maskid<0) { msg("<error> Couldn't process mask jpeg of size %dx%d: error code %d", img->width, img->height, maskid); return; } sprintf(masked, "masked %d", maskid); imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, masked); } else { imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, ""); } if(imgid<0) { msg("<error> Couldn't process jpeg of size %dx%d: error code %d, file %s", img->width, img->height, imgid, tempfile); return; } unlink(tempfile); char options[80]; set_matrix(i, matrix->m00, matrix->m01, matrix->m10, matrix->m11); /* an image's (0,0) is at the lower left corner */ double x=matrix->tx + i->config_xpad + matrix->m10*img->height; double y=matrix->ty + i->config_ypad + matrix->m11*img->height; double tx,ty; transform_back(i, x, y, &tx, &ty); PDF_place_image(i->p, imgid, tx, ty, 1.0); PDF_close_image(i->p, imgid); if(rescaled_image) gfximage_free(rescaled_image); }