Tk font size
Le
perlgenome
Bonjour,
Je cherche à obtenir les informations du font d'un Widget, comment
faire car je rencontre des comportements spéciaux ?
La taille récupérer via ma méthode est toujours inférieur de 4, 5, =
8,
etc pixels par rapport à la vraie taille comme le montre l'exemple ci-
dessous.
Avez vous une idée ?
Une autre façon serait de parser le font mais comment le faire
proprement. Car il est possible de créer un font de plusieurs façon :
- soit en ecrivant -font => "Arial 8 normal" ou "{Arial} 8 normal" ou
Arial 8 , voir même en utilisant la méthode fontCreate.
Exemple :
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new(
-background => 'white',
);
my $bb = $mw->Button(
-text => 'bouton',
-font => 'Arial 8 normal',
)->pack;
for my $size ( qw/ 12 14 16 18 20 22 24 26 28 30/ ) {
$mw->update;
$bb->configure( -font => "Arial $size normal" );
my %font_data = $bb->fontActual( $bb->cget( -font ) );
print "==> Size : $size";
map { print "$_ : $font_data{$_}"; } sort keys %font_data;
print "=";
}
MainLoop();
Ce code me donne ce résultat :
==> Size : 12
-family : Arial
-overstrike : 0
-size : -16
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 14
-family : Arial
-overstrike : 0
-size : -19
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 16
-family : Arial
-overstrike : 0
-size : -21
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 18
-family : Arial
-overstrike : 0
-size : -24
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 20
-family : Arial
-overstrike : 0
-size : -27
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 22
-family : Arial
-overstrike : 0
-size : -29
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 24
-family : Arial
-overstrike : 0
-size : -32
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 26
-family : Arial
-overstrike : 0
-size : -35
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 28
-family : Arial
-overstrike : 0
-size : -37
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 30
-family : Arial
-overstrike : 0
-size : -40
-slant : roman
-underline : 0
-weight : normal
=
Merci
Djibril
Je cherche à obtenir les informations du font d'un Widget, comment
faire car je rencontre des comportements spéciaux ?
La taille récupérer via ma méthode est toujours inférieur de 4, 5, =
8,
etc pixels par rapport à la vraie taille comme le montre l'exemple ci-
dessous.
Avez vous une idée ?
Une autre façon serait de parser le font mais comment le faire
proprement. Car il est possible de créer un font de plusieurs façon :
- soit en ecrivant -font => "Arial 8 normal" ou "{Arial} 8 normal" ou
Arial 8 , voir même en utilisant la méthode fontCreate.
Exemple :
#!/usr/bin/perl
use strict;
use warnings;
use Tk;
my $mw = MainWindow->new(
-background => 'white',
);
my $bb = $mw->Button(
-text => 'bouton',
-font => 'Arial 8 normal',
)->pack;
for my $size ( qw/ 12 14 16 18 20 22 24 26 28 30/ ) {
$mw->update;
$bb->configure( -font => "Arial $size normal" );
my %font_data = $bb->fontActual( $bb->cget( -font ) );
print "==> Size : $size";
map { print "$_ : $font_data{$_}"; } sort keys %font_data;
print "=";
}
MainLoop();
Ce code me donne ce résultat :
==> Size : 12
-family : Arial
-overstrike : 0
-size : -16
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 14
-family : Arial
-overstrike : 0
-size : -19
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 16
-family : Arial
-overstrike : 0
-size : -21
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 18
-family : Arial
-overstrike : 0
-size : -24
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 20
-family : Arial
-overstrike : 0
-size : -27
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 22
-family : Arial
-overstrike : 0
-size : -29
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 24
-family : Arial
-overstrike : 0
-size : -32
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 26
-family : Arial
-overstrike : 0
-size : -35
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 28
-family : Arial
-overstrike : 0
-size : -37
-slant : roman
-underline : 0
-weight : normal
=
==> Size : 30
-family : Arial
-overstrike : 0
-size : -40
-slant : roman
-underline : 0
-weight : normal
=
Merci
Djibril

Poser une question


perlgenome
[...]
[...]
Pourquoi utiliser fontActual ?
Petit extrait de la doc '804delta.pod' :
The fontActual method now returns the pixel value instead of the
point value for -size. Pixel values are expressed as negative
numbers.
Le -16 est donc en pixel alors que le 12 est en point typographique.
--
Paul Gaborit - Perl en français -
Merci pour ta réponse Paul.
En fait, j'avais besoin de jouer avec les font afin de simuler
l'option -compound pour mon module Tk pour la création de bouton avec
couleurs dégradées.
Mais j'ai finalement trouvé une autre méthode beaucoup plus propre et
efficace.
Djibril