File Coverage

blib/lib/Text/Layout/FontDescriptor.pm
Criterion Covered Total %
statement 38 58 65.5
branch 7 8 87.5
condition 6 13 46.1
subroutine 13 23 56.5
pod 10 18 55.5
total 74 120 61.6


line stmt bran cond sub pod time code
1             #! perl
2              
3 8     8   66 use strict;
  8         17  
  8         344  
4 8     8   42 use warnings;
  8         16  
  8         402  
5 8     8   51 use utf8;
  8         69  
  8         55  
6              
7             package Text::Layout::FontDescriptor;
8              
9 8     8   527 use Carp;
  8         14  
  8         8393  
10              
11             our $VERSION = "0.045";
12              
13             =head1 NAME
14              
15             Text::Layout::FontDescriptor - font description for Text::Layout
16              
17             =head1 SYNOPSIS
18              
19             Font descriptors are used internally by Text::Layout and
20             Text::Layout::FontConfig.
21              
22             =cut
23              
24             =head1 METHODS
25              
26             =over
27              
28             =item new( [ %atts ] )
29              
30             Creates a new FontDescriptor object.
31              
32             Attributes:
33              
34             =over
35              
36             =item family
37              
38             =item style
39              
40             =item weight
41              
42             The Family, style, and weight of this font. There are mandatory. For
43             defaults, use an empty string.
44              
45             =item size
46              
47             Optional, font size.
48              
49             =item font
50              
51             The actual font data.
52              
53             =item loader
54              
55             A code reference to call to actually create/load the font if necessary.
56              
57             Loading will store the font data in the C property.
58              
59             =back
60              
61             =back
62              
63             =cut
64              
65             sub new {
66 27     27 1 174 my ( $pkg, %atts ) = @_;
67 27         301 my $self = bless { style => "",
68             weight => "",
69             %atts } => $pkg;
70              
71 27         214 return $self;
72             }
73              
74             =over
75              
76             =item get_font
77              
78             Returns the actual font data for the font this descriptor describes.
79              
80             If necessary, the backend will be called to create/load the font.
81              
82             =back
83              
84             =cut
85              
86             sub get_font {
87 7     7 1 392 my ( $self, $context ) = @_;
88 7   66     40 $self->{font} ||= do {
89 3 50       32 croak("Forgot to pass a layout context to get_font?")
90             unless UNIVERSAL::isa( $context, 'Text::Layout' );
91 3         18 $context->load_font( $self->{loader_data}, $self );
92             };
93             }
94              
95             =over
96              
97             =item get_family
98              
99             =item get_style
100              
101             =item get_weight
102              
103             Accessors to the font family, style, and weight.
104              
105             Readonly.
106              
107             =back
108              
109             =cut
110              
111             sub get_family {
112 0     0 1 0 my ( $self ) = @_;
113 0         0 $self->{family};
114             }
115              
116             sub get_style {
117 0     0 1 0 my ( $self ) = @_;
118 0         0 $self->{style};
119             }
120              
121             sub get_weight {
122 0     0 1 0 my ( $self ) = @_;
123 0         0 $self->{weight};
124             }
125              
126             =over
127              
128             =item set_size
129              
130             =item get_size
131              
132             Sets/gets the size property of the font.
133              
134             =back
135              
136             =cut
137              
138             sub set_size {
139 7     7 1 22 my ( $self, $size ) = @_;
140 7         25 $self->{size} = $size;
141             }
142              
143             sub get_size {
144 2     2 1 4 my ( $self ) = @_;
145 2         9 $self->{size};
146             }
147              
148             =over
149              
150             =item set_direction
151              
152             =item get_direction
153              
154             Sets/gets the direction property of the font.
155              
156             =back
157              
158             =cut
159              
160             sub set_direction {
161 0     0 1 0 my ( $self, $direction ) = @_;
162 0         0 $self->{direction} = $direction;
163             }
164              
165             sub get_direction {
166 0     0 1 0 my ( $self ) = @_;
167 0         0 $self->{direction};
168             }
169              
170             # Not documented -- internal use only.
171              
172             sub set_shaping {
173 0     0 0 0 my ( $self, $sh ) = @_;
174 0   0     0 $self->{shaping} = $sh // 1;
175             }
176              
177             sub get_shaping {
178 2     2 0 5 my ( $self ) = @_;
179 2         13 $self->{shaping};
180             }
181              
182             # Not documented -- internal use only.
183              
184             sub set_interline {
185 0     0 0 0 my ( $self, $sh ) = @_;
186 0   0     0 $self->{interline} = $sh // 1;
187             }
188              
189             sub get_interline {
190 0     0 0 0 my ( $self ) = @_;
191 0         0 $self->{interline};
192             }
193              
194             # Not documented -- internal use only.
195              
196             # Note that the ascender/descender values are filled in at load time,
197             # unless overridden by a set_... call.
198              
199             sub set_ascender {
200 0     0 0 0 my ( $self, $asc ) = @_;
201 0         0 $self->{ascender} = $asc;
202             }
203              
204             sub get_ascender {
205 4     4 0 9 my ( $self ) = @_;
206 4         16 $self->{ascender};
207             }
208              
209             sub set_descender {
210 0     0 0 0 my ( $self, $desc ) = @_;
211 0         0 $self->{descender} = $desc;
212             }
213              
214             sub get_descender {
215 4     4 0 11 my ( $self ) = @_;
216 4         24 $self->{descender};
217             }
218              
219             =over
220              
221             =item to_string
222              
223             Returns a Pango-style font string, C.
224              
225             =back
226              
227             =cut
228              
229             sub to_string {
230 69     69 1 126 my ( $self ) = @_;
231 69         156 my $desc = ucfirst( $self->{family} );
232             $desc .= ucfirst( $self->{style} )
233 69 100 66     290 if $self->{style} && $self->{style} ne "normal";
234             $desc .= " " . ucfirst( $self->{weight} )
235 69 100 66     271 if $self->{weight} && $self->{weight} ne "normal";
236 69 100       128 $desc .= " " . $self->{size} if $self->{size};
237 69         550 return $desc;
238             }
239              
240 8     8   4460 use overload '""' => \&to_string;
  8         13439  
  8         71  
241              
242             =head1 SEE ALSO
243              
244             L, L.
245              
246             =head1 AUTHOR
247              
248             Johan Vromans, C<< >>
249              
250             =head1 SUPPORT
251              
252             This module is part of L.
253              
254             Development takes place on GitHub:
255             L.
256              
257             You can find documentation for this module with the perldoc command.
258              
259             perldoc Text::Layout::FontDescriptor
260              
261             Please report any bugs or feature requests using the issue tracker for Text::Layout on GitHub.
262              
263             =head1 LICENSE
264              
265             See L.
266              
267             =cut
268              
269             1;