Discussion:
FLTK 1.3 printing (printer)
Richard Sanders
2011-08-07 21:16:08 UTC
Permalink
I need to print a page that is has more text lines than the window (or
screen).

I am not having a problem printing things. I am wondering if anyone
has experience printing a multi page document who would share their
insites (rather than me re inventing thew wheel).
Matthias Melcher
2011-08-07 22:46:37 UTC
Permalink
It's really simple. Just open the device, giving it the number of pages you want to print. Then start the page, the set the scale to some value that gives you enough room to fit everything on your page.

Now simply call the FLTK drawing command, just like you would inside someWidget::draw(). Then end the page and print the next one.

Finally, close the device.

// print pages
Fl_Printer * p = new Fl_Printer();
if (!p->start_job(num_windows)) {
// Print each page...
for (page = 0; page<n; page++) {
int width, heightl
p->start_page();
p->printable_rect(&width, &height);

// draw a headline
fltk3::font(fltk3::HELVETICA_BOLD, 12);
fltk3::color(0, 0, 0);
fltk3::draw("It's really simple.", width/2, 32);

// set the scale, if needed (default is 72dpi)
p->scale(scale, scale);
// print more

p->end_page();
}
p->end_job();
}
delete p;
Post by Richard Sanders
I need to print a page that is has more text lines than the window (or
screen).
I am not having a problem printing things. I am wondering if anyone
has experience printing a multi page document who would share their
insites (rather than me re inventing thew wheel).
_______________________________________________
fltk mailing list
http://lists.easysw.com/mailman/listinfo/fltk
Richard Sanders
2011-08-07 23:28:11 UTC
Permalink
It's really simple. Just open the device, giving it the number of pages =
you want to print. Then start the page, the set the scale to some value =
that gives you enough room to fit everything on your page.
Now simply call the FLTK drawing command, just like you would inside =
someWidget::draw(). Then end the page and print the next one.
Finally, close the device.
// print pages
Fl_Printer * p =3D new Fl_Printer();
if (!p->start_job(num_windows)) {
// Print each page...
for (page =3D 0; page<n; page++) {
int width, heightl
p->start_page();
p->printable_rect(&width, &height);
=20
// draw a headline
fltk3::font(fltk3::HELVETICA_BOLD, 12);
fltk3::color(0, 0, 0);
fltk3::draw("It's really simple.", width/2, 32);
// set the scale, if needed (default is 72dpi)
p->scale(scale, scale);
// print more
p->end_page();
}
p->end_job();
}
delete p;
Post by Richard Sanders
I need to print a page that is has more text lines than the window (or
screen).
=20
I am not having a problem printing things. I am wondering if anyone
has experience printing a multi page document who would share their
incites (rather than me re inventing thew wheel).=20
=20
_______________________________________________
fltk mailing list
http://lists.easysw.com/mailman/listinfo/fltk
Thanks, I was wondering about drawing text to the printer rather than on a widget.
Matthias Melcher
2011-08-07 23:38:57 UTC
Permalink
Post by Richard Sanders
Thanks, I was wondering about drawing text to the printer rather than on a widget.
Thanks to the unified Device system, the printer is just another rendering area. All drawing should be the same, no matter if sent ot the screen or paper.
Edzard Egberts
2011-08-08 06:04:45 UTC
Permalink
Post by Matthias Melcher
// set the scale, if needed (default is 72dpi)
p->scale(scale, scale);
I think, scaling doesn't belong to resolution, doesn't it?
My scaling example:

int ww= pWindow->w();
int wh= pWindow->h();
int pw, ph;
if (!p->start_job(1))
{
p->start_page();
if (!p->printable_rect(&pw, &ph))
{
int left, top, right, bottom;
p->margins (&left, &top, &right, &bottom);
pw-= 2* left;
ph-= 2* top;
left*= 2;
top*= 2;
float sw= float(pw)/float(ww);
float sh= float(ph)/float(wh);
if (sw > sh) sw= sh;
p->scale(sw);
p->print_widget(pWindow, left, top);
}
p->end_page();
p->end_job();
}
Matthias Melcher
2011-08-08 16:24:23 UTC
Permalink
Post by Edzard Egberts
Post by Matthias Melcher
// set the scale, if needed (default is 72dpi)
p->scale(scale, scale);
I think, scaling doesn't belong to resolution, doesn't it?
It's all interconnected. The default printing scale is 72 unit per inch. If your paper is 8" high, you get 8x72 (576) vertical coordinates ("pixels", in case your dot matrix printer has 72 dpi).

If you scale down the drawing, you get more pixels per inch, and more pixels in total on the same size paper.

Pixels here don't mean much of course, because PostScript is mostly vector oriented... .

Is that what you meant?
Edzard Egberts
2011-08-09 06:08:06 UTC
Permalink
Post by Matthias Melcher
Post by Edzard Egberts
// set the scale, if needed (default is 72dpi) p->scale(scale,
scale);
I think, scaling doesn't belong to resolution, doesn't it?
It's all interconnected. The default printing scale is 72 unit per
inch. If your paper is 8" high, you get 8x72 (576) vertical
coordinates ("pixels", in case your dot matrix printer has 72 dpi).
If you scale down the drawing, you get more pixels per inch, and more
pixels in total on the same size paper.
Pixels here don't mean much of course, because PostScript is mostly
vector oriented... .
Is that what you meant?
Yes, now I understand better. I considered scaling as some kind of
scaled blitting to a map with constant resolution - the same way things
are handled on screen. Handling it by printers resolution is a very
interesting way I never thought of, but I see the advantages. :o)
Loading...