Fl_Printer margin

19 views
Skip to first unread message

Jano Crema

unread,
Jun 2, 2017, 5:09:52 PM6/2/17
to fltk.general
How can I remove margin using Fl_Printer
void imprimir()
{
    Fl_Printer printer;
    printer.start_job(1);
    printer.start_page();
    printer.margins(0,0,0,0);
    fl_draw("BOI DA CARA PRETA", 0, 0);
    printer.end_page();
    printer.end_job();

}
d791cb4e-54fb-424d-9fb6-e79952c51ae3.jpg

Greg Ercolano

unread,
Jun 2, 2017, 5:32:39 PM6/2/17
to fltkg...@googlegroups.com
On 06/02/17 13:10, Jano Crema wrote:
> void imprimir()
> {
> Fl_Printer printer;
> printer.start_job(1);
> printer.start_page();
> printer.margins(0,0,0,0);
> fl_draw("BOI DA CARA PRETA", 0, 0);
> printer.end_page();
> printer.end_job();
> }


I've never used Fl_Printer myself, but I tried your program
(on linux) and found I needed to add above fl_draw() settings
for fl_font() and fl_color().

Your margins() call does nothing because all four values are NULL;
those are supposed to be pointers to integers that receive the current
margin offsets, if I read the docs correctly. It does not /set/ the margins.

So what you probably want is:

#include <FL/Fl_Printer.H>
#include <FL/fl_draw.H>

void imprimir()
{
Fl_Printer printer;
printer.start_job(1);
printer.start_page();
int L,T,R,B; // ADDED
printer.margins(&L,&T,&R,&B); // CHANGED
printf("%d %d %d %d\n", L,T,R,B); // ADDED (prints what the margins are)
fl_color(FL_BLACK); // ADDED
fl_font(FL_HELVETICA, 20); // ADDED
fl_draw("TEST ABCDEF", -L, 0); // CHANGED: 0,0 -> -L,0
printer.end_page();
printer.end_job();
}

int main() {
imprimir();
}

The important changes are (a) getting the margins into L/T/R/B,
and then using the value for the left margin (L) as a negative offset
in fl_draw() to compensate for the margin offset (see -L in fl_draw())

That worked for me; it put the text as close to the left physical
printing area as possible.

There may be a way to use the translate method to effectively
do the same thing to all calls, making 0,0 the actual top/left of
the physical printing area -- I didn't try it.

Greg Ercolano

unread,
Jun 2, 2017, 5:40:04 PM6/2/17
to fltkg...@googlegroups.com
On 06/02/17 14:32, Greg Ercolano wrote:
> int L,T,R,B; // ADDED
> printer.margins(&L,&T,&R,&B); // CHANGED
> printf("%d %d %d %d\n", L,T,R,B); // ADDED (prints what the margins are)

I should add; in my case L/T/R/B was 18 18 18 18,
so the margins were all set to 18 in from the edges.

So when calling fl_draw("some text",-L,0), the use of -L
effectively was fl_draw("some text",-18,0),
which reversed the 18 offset, drawing flush left.

Or at least, that's my understanding.

If there is a way to /change/ the margins(), I'm not sure
what method that is, if it's possible. I imagine the margins
are set as part of the printer setup, but I'm not sure.

Manolo

unread,
Jun 3, 2017, 3:04:14 AM6/3/17
to fltk.general
The margins originate from what happens with printers under MSWindows
and MacOS where the system determines that the printable area of the
paper is not the full paper surface.
Under Linux, the margins have been set to 18 points which gives an effect very
similar to the system-imposed margins on the other OSes.

As Greg mentionned, you may draw at a negative x coordinate, or call
Fl_Printer::origin(int x, int y) to move the graphics origin left,
but there may be some areas of the paper the printer won't reach, and they may
change when changing printer.
Reply all
Reply to author
Forward
0 new messages