Debian Codegraph @

xt/font_attrs.t

raw
1 #!/usr/bin/perl -w
2 # -*- perl -*-
3
4 # Test case from https://rt.cpan.org/Ticket/Display.html?id=42043
5 # Fails if XFT=1 is activated.
6 # Not in normal test suite, because result depends on fonts installed on system.
7
8 use strict;
9
10 use Getopt::Long;
11
12 use Tk;
13 use Tk::Config;
14 use Tk::Font;
15
16 BEGIN {
17 if (!eval q{
18 use Test::More;
19 1;
20 }) {
21 print "1..0 # skip no Test::More module\n";
22 exit;
23 }
24 }
25
26 my $Xft = $Tk::Config::xlib =~ /-lXft\b/;
27 if (!$Xft) {
28 plan skip_all => 'Hardcoded font values work only for XFT=1';
29 exit 0;
30 }
31
32 plan tests => 5;
33
34 my $do_display;
35 GetOptions("display" => \$do_display)
36 or die "usage: $0 [-display]";
37
38 my $mw = MainWindow->new;
39
40 {
41 # The empty array does not work at all for XFT=0
42 my $label = $mw->Label(-text=>"small font, no bold",-font=>[])->pack;
43 my %fa = $label->cget(-font)->actual;
44 is_deeply(\%fa, { -weight => 'normal',
45 -underline => 0,
46 -family => 'Bitstream Vera Sans',
47 -slant => 'roman',
48 -size => -14,
49 -overstrike => 0,
50 }, 'Unchanged font size, normal weight');
51 }
52
53 {
54 my $label = $mw->Label(-text=>"small font, bold",-font=>[-weight=>'bold'])->pack;
55 my %fa = $label->cget(-font)->actual;
56 is_deeply(\%fa, { -weight => 'bold',
57 -underline => 0,
58 -family => 'Bitstream Vera Sans',
59 -slant => 'roman',
60 -size => -14,
61 -overstrike => 0,
62 }, 'Unchanged font size, bold');
63 }
64
65 {
66 my $label = $mw->Label(-text=>"32-point, bold",-font=>[-size=>'32', -weight=>'bold'])->pack;
67 my %fa = $label->cget(-font)->actual;
68 is_deeply(\%fa, { -weight => 'bold',
69 -underline => 0,
70 -family => 'Bitstream Vera Sans',
71 -slant => 'roman',
72 -size => -38,
73 -overstrike => 0,
74 }, '32 point size, bold');
75 }
76
77 {
78 my $label = $mw->Label(-text=>"32-point, bold, string spec",-font=>'{sans serif} 32 bold')->pack;
79 my %fa = $label->cget(-font)->actual;
80 is_deeply(\%fa, { -weight => 'bold',
81 -underline => 0,
82 -family => 'Bitstream Vera Sans',
83 -slant => 'roman',
84 -size => -38,
85 -overstrike => 0,
86 }, '32 point size, bold');
87 }
88
89 {
90 my $label = $mw->Label(-text=>"32-point, no bold",-font=>[-size=>'32'])->pack;
91 my %fa = $label->cget(-font)->actual;
92 is_deeply(\%fa, { -weight => 'normal',
93 -underline => 0,
94 -family => 'Bitstream Vera Sans',
95 -slant => 'roman',
96 -size => -38,
97 -overstrike => 0,
98 }, '32 point size, normal weight');
99 }
100
101 if ($do_display) {
102 my $button = $mw->Button(-text => "Quit",
103 -command => sub { exit })
104 ->pack();
105 MainLoop;
106 }
107
108 __END__