win32::printer and text formatting

D

diavolo-verde

Hello,

I use Win32::printer for my prints. I print just simple text, i.e.

$rowHeight = $dc->Write($description, $x, $y);
$x += 45;
$rowHeight = $dc->Write($arrivalDate, $x, $y);
$x += 20;
$rowHeight = $dc->Write($price, $x, $y);
$y += $rowHeight;

I'd like to print the currency right formatted:
204,00
12,10

I didn't undersand very much the win32::printer manual on CPAN. Would
anyone give me an example how to do it?

Thanks,

Davide
 
B

Ben Morrow

Quoth "[email protected] said:
Hello,

I use Win32::printer for my prints. I print just simple text, i.e.

$rowHeight = $dc->Write($description, $x, $y);
$x += 45;
$rowHeight = $dc->Write($arrivalDate, $x, $y);
$x += 20;
$rowHeight = $dc->Write($price, $x, $y);
$y += $rowHeight;

I'd like to print the currency right formatted:
204,00
12,10

I didn't undersand very much the win32::printer manual on CPAN. Would
anyone give me an example how to do it?

You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
or possibly there is a CPAN module to make this easier (the POSIX locale
interface is rather smelly).

Ben
 
D

diavolo-verde

Ben Morrow ha scritto:
You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
or possibly there is a CPAN module to make this easier (the POSIX locale
interface is rather smelly).

Thanks Ben, I don't understand. I thought I could use
win32::printer::write or write2 with their options:

# String mode (SM):
$height = $dc->Write($text, $x, $y, [$format, [$just_width]]);
($width, $height) = $dc->Write($text, $x, $y, [$format,
[$just_width]]);

# Draw mode (DM):
$height = $dc->Write($text, $x, $y, $width, $height, [$format,
[$tab_stop]]);
($width, $height, $length, $text) = $dc->Write($text, $x, $y, $width,
$height, [$format, [$tab_stop]]);

but I can't figure out how to use them. How sprintf could help me
printing on printer device?

Thanks,

Davide
 
B

Ben Morrow

Quoth "[email protected] said:
Ben Morrow ha scritto:
You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
or possibly there is a CPAN module to make this easier (the POSIX locale
interface is rather smelly).

Thanks Ben, I don't understand. I thought I could use
win32::printer::write or write2 with their options:

# String mode (SM):
$height = $dc->Write($text, $x, $y, [$format, [$just_width]]);
($width, $height) = $dc->Write($text, $x, $y, [$format,
[$just_width]]);

# Draw mode (DM):
$height = $dc->Write($text, $x, $y, $width, $height, [$format,
[$tab_stop]]);
($width, $height, $length, $text) = $dc->Write($text, $x, $y, $width,
$height, [$format, [$tab_stop]]);

but I can't figure out how to use them.

Maybe you can; I don't know that module.
How sprintf could help me printing on printer device?

You format the number into a string and then print that. Having looked a
little further, I'd probably use Number::Format:

use Number::Format;

my $NF = Number::Format->new(
-thousands_sep => '.',
-decimal_point => ',',
);

my $formatted_price = $NF->format_picture(204, '###,##');

then print $formatted-price however you would have before.

Ben
 
D

Dr.Ruud

Ben Morrow schreef:

diavolo, I guess you mean Win32::printer. Case matters.
Its manual is indeed not so clear and has large parts that would be
better presented in compact tables.

You need to use either sprintf or POSIX::localeconv or I18N::Langinfo;
or possibly there is a CPAN module to make this easier (the POSIX
locale interface is rather smelly).

That way would fail for a header in a proportional font.


The Write method has a "format" parameter:

($width, $height) = $dc->Write($price, $x, $y, RIGHT);


diavolo, see the documentation about the reference point.
 
D

diavolo-verde

Dr.Ruud ha scritto:
The Write method has a "format" parameter:

($width, $height) = $dc->Write($price, $x, $y, RIGHT);


diavolo, see the documentation about the reference point.

thanks, RIGHT is my friend, I'm getting what I wanted :).

BR,

Davide
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top