Re: New to gnome-print, but stumbled on something I find odd



On Tue, 2003-12-09 at 12:29, Aaron Ballman wrote:
> >To explain what is happening: the  value with key
> >GNOME_PRINT_KEY_PAPER_WIDTH may in fact contain a string such as 8in or
> >8cm. When you are asking for a double you get 8 independent from the
> >unit. When the user changes the preferred unit that does not change the
> >values stored since if the user changes back you want the exact value
> >the user entered not just some approximation.
> 
> Thanks for the explanation, this makes perfect sense to me.  :-)  I 
> am still running into a stumbling block though.
> 
> So I made a GnomePrintUnit using new and I call 
> gnome_print_config_get_length on what I'm interested in, but I guess 
> I am stuck trying to figure out a decent way to convert this unit 
> into Points.  It looks like (from reading the header file, since 
> that's the only documentation I've really found on the topic) there 
> should be a way to convert from one unit type to another.  I can do 
> the conversion myself by hand, but why reinvent the wheel?  ;-)
> 
> Here is the code I am using currently (val is a const guchar * and 
> mCurrentConfig is a valid GnomePrintConfig object):
> 
> gdouble first = 0.0;
> GnomePrintUnit *unit = new GnomePrintUnit;
> 
> // Get the double value that we want along with the units it is expressed in
> gnome_print_config_get_length( mCurrentConfig, val, &first, &unit );
> 
> 
> Here's where I get stuck.  Do I need to look at unit->abbr and 
> compare it to "mm", "in", etc and then do the conversion by hand.  Or 
> is there some trick I can do by using unit->unittobase to convert 
> automatically from one type to another?  Ideally, I just want all my 
> return values in pixels (so it'd be resolution-dependant), but I can 
> live with them all being in Points as well.
> 
> Any suggestions would be very appreciated.  Also, if you know of a 
> decent place for documentation that google hasn't yielded me yet, 
> that would help me out immensely.  Thanks!

The best way to learn about gnome-print is to look at the gnumeric or
gedit code. Just an excerpt from gnumeric print.c:

	/* Precompute information */
	gnome_print_job_get_page_size_from_config (pj->pi->print_config,
						      &width, &height);

This gives you your page size in points. Of course in new code you
should be using gnome_print_config_get_page_size instead.

That will take care of all your conversions. Don't worry about
resolution because you don't know whetehr that is in fact a whole page
or whether we are printing 2-up so that you are really having everything
reduced by a factor of 2. (That's why the units aren't really points but
gnomeprintpoints.)

Andreas


-- 
Andreas J. Guelzow <aguelzow taliesin ca>
Taliesin

Attachment: signature.asc
Description: This is a digitally signed message part



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