#include <unistd.h>
#include <memory.h>
#include <pdflib.h>
+#include <math.h>
+#include "../os.h"
+#include "../jpeg.h"
#include "../types.h"
#include "../mem.h"
#include "../gfxdevice.h"
internal_t*i = (internal_t*)dev->internal;
if(!i->tempfile) {
- i->tempfile = strdup("tmp.pdf");
+ i->tempfile = strdup(mktempname(0));
PDF_open_file(i->p, i->tempfile);
PDF_set_parameter(i->p, "usercoordinates", "true");
PDF_set_parameter(i->p, "topdown", "true");
if(mkline(line, i->p))
PDF_clip(i->p);
else
- ; // TODO: not sure about this
+ ; // TODO: strictly speaking, an empty clip clears everything
}
void pdf_endclip(gfxdevice_t*dev)
{
internal_t*i = (internal_t*)dev->internal;
- //PDFLIB_API int PDFLIB_CALL
- //PDF_load_image(i->pPDF *p, const char *imagetype, const char *filename, int len, const char *optlist);
+ double l1 = sqrt(matrix->m00*matrix->m00+matrix->m01*matrix->m01)*img->width;
+ double l2 = sqrt(matrix->m10*matrix->m10+matrix->m11*matrix->m11)*img->height;
+ double r = atan2(matrix->m01, matrix->m00);
+
+ /* fit_image needs the lower left corner of the image */
+ double x = matrix->tx + matrix->m10*img->height;
+ double y = matrix->ty + matrix->m11*img->height;
+
+ char*tempfile = mktempname(0);
+ char options[80];
+ sprintf(options, "boxsize {%f %f} fitmethod meet rotate %f", l1, l2, r*180/M_PI);
+ gfximage_save_jpeg(img, tempfile, 99);
+ int imgid = PDF_load_image(i->p, "jpeg", tempfile, 0, "");
+ PDF_fit_image(i->p, imgid, x, y, options);
}
void pdf_fillgradient(gfxdevice_t*dev, gfxline_t*line, gfxgradient_t*gradient, gfxgradienttype_t type, gfxmatrix_t*matrix)
#include <assert.h>
#include "gfxtools.h"
#include "gfxfont.h"
+#include "jpeg.h"
typedef struct _linedraw_internal
{
}
}
+void gfximage_save_jpeg(gfximage_t*img, char*filename, int quality)
+{
+ unsigned char*data = malloc(img->width*img->height*3);
+ int t;
+ int size = img->width*img->height;
+ int s = 0;
+ for(t=0;t<size;t++) {
+ data[s+0] = img->data[t].r;
+ data[s+1] = img->data[t].g;
+ data[s+2] = img->data[t].b;
+ s+=3;
+ }
+ jpeg_save(data, img->width, img->height, quality, filename);
+}
+
char gfxfontlist_hasfont(gfxfontlist_t*list, gfxfont_t*font);
void gfxfontlist_free(gfxfontlist_t*list, char deletefonts);
+void gfximage_save_jpeg(gfximage_t*img, char*filename, int quality);
+
gfxbbox_t* gfxline_isrectangle(gfxline_t*_l);
gfxline_t*gfxline_makerectangle(double x1, double y1, double x2, double y2);
pixel_at(97,164).should_be_the_same_as pixel_at(208,256)
area_at(215,80,333,156).should_be_plain_colored
area_at(46,126,180,158).should_not_be_plain_colored
+ area_at(38,118,170,152).should_contain_text 'Hello World'
end
end
font = PDF_load_font(p, "Helvetica", "host", "")
PDF_setfont(p, font, 6.0)
-PDF_set_text_pos(p, 40, 100);PDF_show(p, "|")
+PDF_set_text_pos(p, 40, 100);PDF_show(p, "'")
PDF_set_text_pos(p, 80, 100);PDF_show(p, "i")
PDF_set_text_pos(p, 120, 100);PDF_show(p, "l")
PDF_set_text_pos(p, 160, 100);PDF_show(p, "-")
"(#{@x},#{@y})"
end
end
+
+$tempfiles = []
+Kernel.at_exit do
+ $tempfiles.each do |file|
+ `rm -f #{file}`
+ end
+end
+
class DocFile
def initialize(filename, page)
@filename = filename
def convert()
return if @swfname
@swfname = @filename.gsub(/.pdf$/i,"")+".swf"
+ $tempfiles += [@swfname]
`pdfinfo #{@filename}` =~ /Page size:\s*([0-9]+) x ([0-9]+) pts/
width,height = $1,$2
dpi = (72.0 * 612 / width.to_i).to_i
raise ConversionFailed.new(output,@pngname) unless File.exists?(@pngname)
@img = Magick::Image.read(@pngname).first
ensure
- `rm -f #{@swfname}`
`rm -f #{@pngname}`
end
end
def get_text(x1,y1,x2,y2)
self.convert()
- puts "swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}"
- puts `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`
- `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`
+ #puts "swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}"
+ #puts `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`
+ `swfstrings -x #{x1} -y #{y1} -W #{x2-x1} -H #{y2-y1} #{@swfname}`.chomp
end
def get_area(x1,y1,x2,y2)
self.render()