Hi again, I'm not sure exactly what you are trying to do, but the thought just occured to me, that if you really want scalable text, you might be better off using Tk::Zinc. It will let you scale
text (which most other Toolkits don't allow). Now the example below is very simplistic, BUT you could work out an automatic sizing sub, where if you are given the pixel dimensions of the entire box, you could keep scaling the text, and checking it's bbox values, until it just fit into the display box. This is all frought with difficulties, like some fonts look ugly when scaled, etc. Anyways, left-click will zoom, right-click will shrink.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
use Tk::Zinc;
my $mw = MainWindow->new();
$mw->geometry($mw->screenwidth . 'x' .
$mw->screenheight . '+0+20');
$mw->title("Text Scale Test");
my $zinc = $mw->Zinc(
-height => $mw->screenheight,
-width => $mw->screenwidth,
-backcolor => 'black',
-relief => 'raised'
)->pack();
$zinc->fontCreate(
"fonta",
-family => 'arial',
-size => -30,
-weight => 'bold'
);
my $text = $zinc->add('text',1,
-position => [$mw->screenwidth/2 , 75 ],
-text => 'foobar foobaz',
-composescale => 1,
-anchor => 'center',
-color => 'hotpink',
-font => 'fonta',
);
$mw->bind( '<ButtonPress-1>', sub { &move } );
$mw->bind( '<ButtonPress-3>', sub { &move1; } );
#my $id = $mw->repeat(75, sub{ &move } );
MainLoop;
sub move {
# $zinc->translate($text,0, 1);
$zinc->scale( $text, 1.1, 1.1);
}
sub move1 {
# $zinc->translate($text,0, 1);
$zinc->scale( $text, .9, .9);
}
__END__
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.