zentara wrote:

On Thu, 13 Jan 2005 14:20:34 +1100, [EMAIL PROTECTED] (Daniel
Kasak) wrote:



I'm hunting for a method of creating labels under Linux.
I've already looked at everything on freshmeat.net that came up when I searched for 'labels'. None of them cut it.


Requirements:

- Coloured, rotated ( 90 degrees ) text rendering
- Coloured rectangle rendering

That's it. You'd think one of the existing labelling packages would accomodate me so far, right? Nope.

Background:

We have a filing system where each file has a label, which is made up of ( mainly ) coloured numbers ( ie each number gets a different colour *background* ). This last bit ... the coloured background ... is what's stopping me from using any of the existing labelling packages.

So now that I've decided that there isn't anything out there that does what I want, I'm going to have to write something. What should I use?

I've had a brief look at PDF::API2, but I can't even figure out if it does what I want - the documentation is a little nonexistant.
So should I use GD?



I can see a way with Tk and the Tk::Canvas, but it would probably take some work aligning the pages for printout.

My idea would be to create a canvas of the proper page size, and create
properly aligned rectangles on it for each label.


In those rectangles you can create other smaller rectangles and give
them fill colors as needed by your number system, then lay numbers on
top, with another color for the numbered text.  You can also choose your
fonts, and you can be clever in positioning your letters to give the
effect of rotated text.

The canvas can then be exported to postscript, or a jpg with
the WinPhoto module.

For a super simple example:

#!/usr/bin/perl
use Tk;
use strict;
my $w=20;
my $x=0;
my $y=0;

my %nums = (
  0 => ['black','yellow'],
  1 => ['yellow','black'],
  2 => ['white','green'],
  3 => ['green','white'],
  4 => ['grey','red'],
  5 => ['red','grey'],
  6 => ['blue','white'],
  7 => ['white','blue'],
  8 => ['orange','grey45'],
  9 => ['grey45','orange'],
);

my $mw=tkinit;
my $c = $mw->Canvas->pack;

for (0..9) {
my $item=$c->createRectangle($x,$y,$x+20,$y+20,
            -fill=> ${$nums{$_}}[0],
         );

my $text = $c->createText($x+10,$y+10,
          -anchor=>'center',
          -fill => ${$nums{$_}}[1],
          -text => $_
         );

     $x+=20;
}

$mw->Button(
   -text    => "Save",
   -command => [sub {
        $c->update;
        my @capture=();
        my ($x0,$y0,$x1,$y1)=$c->bbox('all');

@capture=('-x'=>$x0,'-y'=>$y0,-height=>$y1-$y0,-width=>$x1-$x0);
        $c -> postscript(-colormode=>'color',
                              -file=>$0.'.ps',
                              -rotate=>0,
                              -width=>800,
                              -height=>500,
                              @capture);

                             }

 ]  )->pack;

MainLoop;



Interesting. I haven't used Tk before ( I'm using Gtk2 ), but that doesn't look too hard. I'll look more into it when I get some time.
Thanks :)


--
Daniel Kasak
IT Developer
NUS Consulting Group
Level 5, 77 Pacific Highway
North Sydney, NSW, Australia 2060
T: (+61) 2 9922-7676 / F: (+61) 2 9922 7989
email: [EMAIL PROTECTED]
website: http://www.nusconsulting.com.au

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>

Reply via email to