Re: Gnome2::Print
- From: Emmanuele Bassi <bassi-e libero it>
- To: gtk-perl-list gnome org
- Subject: Re: Gnome2::Print
- Date: Mon, 1 Dec 2003 19:50:12 +0100
* Cornel Ghiban <green neomedia ro>:
Ok.. I found the examples/* (they work very well), but I still can't use
Gnome2::Print. Let's say I have a text, net very long - 30 lines for example,
how can I print this text?
If you are pretty sure that the lenght of each line is less than the
page width, you might just cycle through every line of the text and
call:
my $pc = $job->get_context;
$pc->show($a_line);
$pc->moveto(..., ...);
Otherwise, if you do not know the lenght of the lines (you are printing
the contents of a GtkTextBuffer, for instance), you'll have to check if
the next character/word is out of the page boundaries, and act on this
knowledge.
+++
Remember: the minimum height between lines is calculated using:
# $font is a Gnome2::Print::Font object
# height('b') + height('p');
$font_height = $font->get_ascender + $font->get_descender;
Those are values specified by each font.
+++
If you have a buffer consisting of lines, here's some code:
sub render_job
{
my $job = shift;
my $conf = $job->get_config;
my $pc = $job->get_context;
my $buffer = [
"Twinkle Twinkle",
"Little Star",
"Twinkle Twinkle",
"Where You Are",
];
my $font = Gnome2::Print::Font->find_closest("Sans Regular", 16);
# line_space = max_font_size + 20%
my $line_space = ($font->get_descender + $font->get_ascender) * 1.2;
my ($width, $height) = $job->get_page_size;
my $cur_x = 50; # 50px border left
my $cur_y = $height - 100; # 100px border bottom
my $page_n = 1;
# baginpage wants a string, not an integer; this is just
# plain braindead, but fortunately we aren't using C...
$pc->beginpage(sprintf("%d", $page_n++));
$pc->moveto($cur_x, $cur_y);
$pc->setfont($font);
foreach (@$buffer)
{
$pc->show($_);
$cur_y -= $line_space;
# force new page, just to show how does it work.
if ($cur_y < 700)
{
$pc->showpage;
$pc->beginpage(sprintf("%d", $page_n++));
$pc->setfont($font);
$cur_y = $height - 100;
}
$pc->moveto($cur_x, $cur_y);
}
$pc->showpage;
$job->close;
}
[ just use replace the render_job sub inside examples/basic-font.pl to
test it ]
+++
I'll try and come up with a better example that gathers the text froma
TextView widget and prints it.
Regards,
Emmanuele.
--
Emmanuele Bassi (Zefram) [ http://www.emmanuelebassi.net ]
GnuPG Key fingerprint = 4DD0 C90D 4070 F071 5738 08BD 8ECC DB8F A432 0FF4
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]