summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-03-31 16:55:49 +0200
committerManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com>2024-04-30 10:22:47 +0200
commit9472ff546cc0b4150d4dec89b48b3e4814b421f6 (patch)
treebd4bd14b59b13a41decf50a207c7e1770bcabd6e /test
parentb402b6a8397f9fc13157813d39d505ea9ead00f0 (diff)
Implement and document new class Fl_PDF_File_Surface
Diffstat (limited to 'test')
-rw-r--r--test/device.cxx61
1 files changed, 24 insertions, 37 deletions
diff --git a/test/device.cxx b/test/device.cxx
index e039397b6..67e29d239 100644
--- a/test/device.cxx
+++ b/test/device.cxx
@@ -30,6 +30,7 @@
#include <FL/Fl_Image_Surface.H>
#include <FL/Fl_Native_File_Chooser.H>
#include <FL/Fl_SVG_File_Surface.H>
+#include <FL/Fl_PDF_File_Surface.H>
#include "pixmaps/porsche.xpm"
#include "pixmaps/sorceress.xbm"
@@ -523,59 +524,45 @@ void copy(Fl_Widget *, void *data) {
Fl_Surface_Device::pop_current();
}
- if (strcmp(operation, "Fl_Printer") == 0 || strcmp(operation, "Fl_PostScript_File_Device") == 0) {
+ if (strcmp(operation, "Fl_Printer") == 0 || strcmp(operation, "Fl_PostScript_File_Device") == 0
+ || strcmp(operation, "Fl_PDF_File_Surface") == 0) {
Fl_Paged_Device *p;
int err;
char *err_message = NULL;
if (strcmp(operation, "Fl_Printer") == 0) {
p = new Fl_Printer();
err = p->begin_job(1, NULL, NULL, &err_message);
- }
- else {
+ } else if (strcmp(operation, "Fl_PDF_File_Surface") == 0) {
+ p = new Fl_PDF_File_Surface();
+ err = ((Fl_PDF_File_Surface*)p)->begin_job("FLTK.pdf", &err_message);
+ } else {
p = new Fl_PostScript_File_Device();
err = ((Fl_PostScript_File_Device*)p)->start_job(1);
}
if (!err) {
p->begin_page();
- if (target->as_window()) {
- int w, h;
- p->printable_rect(&w, &h);
- p->origin(w/2, h/2);
- p->print_window(target->as_window(), -target->w()/2, -target->h()/2);
- }
- else p->print_widget(target);
+ Fl_Window *win = target->as_window();
+ int target_w = win ? win->decorated_w() : target->w();
+ int target_h = win ? win->decorated_h() : target->h();
+ int w, h;
+ p->printable_rect(&w, &h);
+ float s = 1, s_aux = 1;
+ if (target_w > w)
+ s_aux = float(w) / target_w;
+ if (target_h > h)
+ s = float(h) / target_h;
+ if (s_aux < s) s = s_aux;
+ p->scale(s);
+ p->printable_rect(&w, &h);
+ p->origin(w/2, h/2);
+ if (win) p->draw_decorated_window(win, - target_w/2, - target_h/2);
+ else p->draw(target, - target_w/2, - target_h/2);
p->end_page();
p->end_job();
} else if (err > 1 && err_message) {fl_alert("%s", err_message); delete[] err_message;}
delete p;
}
- if (strcmp(operation, "Fl_EPS_File_Surface") == 0) {
- Fl_Native_File_Chooser fnfc;
- fnfc.title("Save a .eps file");
- fnfc.type(Fl_Native_File_Chooser::BROWSE_SAVE_FILE);
- fnfc.filter("EPS\t*.eps\n");
- fnfc.options(Fl_Native_File_Chooser::SAVEAS_CONFIRM | Fl_Native_File_Chooser::USE_FILTER_EXT);
- if (!fnfc.show() ) {
- FILE *eps = fl_fopen(fnfc.filename(), "w");
- if (eps) {
- int ww, wh;
- if (target->as_window()) {
- ww = target->as_window()->decorated_w();
- wh = target->as_window()->decorated_h();
- } else {
- ww = target->w();
- wh = target->h();
- }
- Fl_EPS_File_Surface p(ww, wh, eps);
- if (p.file()) {
- if (target->as_window()) p.draw_decorated_window(target->as_window());
- else p.draw(target);
- }
- }
- }
- }
-
if (strcmp(operation, "Fl_SVG_File_Surface") == 0) {
Fl_Native_File_Chooser fnfc;
fnfc.title("Save a .svg file");
@@ -763,7 +750,7 @@ int main(int argc, char ** argv) {
rb = new Fl_Radio_Round_Button(170,4,150,12, "Fl_Copy_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(5,17,150,12, "Fl_Printer"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(170,17,150,12, "Fl_PostScript_File_Device"); rb->callback(operation_cb, NULL); rb->labelsize(12);
- rb = new Fl_Radio_Round_Button(5,30,150,12, "Fl_EPS_File_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
+ rb = new Fl_Radio_Round_Button(5,30,150,12, "Fl_PDF_File_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(170,30,150,12, "Fl_SVG_File_Surface"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(5,43,150,12, "fl_capture_window()"); rb->callback(operation_cb, NULL); rb->labelsize(12);
rb = new Fl_Radio_Round_Button(170,43,150,12, "Fl_Image_Surface::mask()"); rb->callback(operation_cb, NULL); rb->labelsize(12);