RE: Pango tab stops



> -----Original Message-----
> From: Behdad Esfahbod 
> Sent: Wednesday, April 08, 2009 3:30 PM
> 
> On 04/01/2009 07:27 PM, Ian Puleston wrote:
> > Hi,
> 
> Hi Ian,
> 
> 
> > I want to use a PangoTabArray to pass tab stop settings to a print
> function
> > along with text to be sent to a printer. The idea is that the caller
> passes
> > the pre-set PangoTabArray, and the print function then calls
> > pango_layout_set_tabs to add it to the PangoLayout created via
> > gtk_print_context_create_pango_layout.
> >
> > But there seems to be a problem with setting the tabs correctly for
> the
> > resolution (dpi) of the printer. With a PangoTabArray the tabs are
> specified
> > in either pixels or Pango units, and to use either to set tag stops
> at fixed
> > distances requires knowledge of the resolution of the device, but the
> code
> > requesting the print cannot know that (the user has not even selected
> a
> > printer yet).
> 
> No it doesn't.  The cairo PS/PDF/SVG surfaces use Postscript points as
> their
> device "pixel".  That is, for positioning purposes, 72dpi is all you
> care
> about.  The actual resolution of the printer printing them is
> irrelevant.
> 
> Makes sense?
> 
> behdad


OK, sorry for the delay but I've now had a chance to try this and it doesn't seem to work as you say (or more likely I'm still doing something wrong). I set the tabs like this:

#define PANGO_CAIRO_INCHES(n) (n * 72 * PANGO_SCALE)

tabArray = pango_tab_array_new(5, FALSE);
pango_tab_array_set_tab(tabArray, 0, PANGO_TAB_LEFT, PANGO_CAIRO_INCHES(0.1));
pango_tab_array_set_tab(tabArray, 1, PANGO_TAB_LEFT, PANGO_CAIRO_INCHES(0.5));
pango_tab_array_set_tab(tabArray, 2, PANGO_TAB_LEFT, PANGO_CAIRO_INCHES(3.3));
pango_tab_array_set_tab(tabArray, 3, PANGO_TAB_LEFT, PANGO_CAIRO_INCHES(4.2));
pango_tab_array_set_tab(tabArray, 4, PANGO_TAB_LEFT, PANGO_CAIRO_INCHES(6.0));

And I set those tabs in the layout of the print context like this:
layout = gtk_print_context_create_pango_layout(context);
...
pango_layout_set_tabs(layout, (PangoTabArray*)pElem->data);

Then in the "draw-page" signal handler of the print operation I print lines from that layout one at a time like this:

cr = gtk_print_context_get_cairo_context(context);
layoutLine = pango_layout_get_line_readonly(layout, lineCnt);
pango_layout_line_get_extents(layoutLine, &inkRect, &logRect);
textHeight = (gdouble)logRect.height / PANGO_SCALE;
cairo_move_to(cr, currPos_x, currPos_y + textHeight);
pango_cairo_show_layout_line(cr, layoutLine);
currPos_y += textHeight;


So to test it I simply tried printing "\t|\t|\t|\t|\t|\n" to see where the tabs are at. Printing to a PDF (a 300dpi device) they cover about 1.5 inches total (should be 6 inches with the above tab stops), printing to an actual 600dpi printer they cover about 1 inch total.

I was previously setting the tabs in pixels (passing TRUE as the 2nd argument to pango_tab_array_new) and assuming a 300dpi device, and then inside the print function reading them, scaling them up and resaving them for the 600dpi printer, and although it was rather clumsy the positions came out correct.

So any idea what might be incorrect in the above code?

Ian




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]