| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | #! perl | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 6 |  |  | 6 |  | 40 | use strict; | 
|  | 6 |  |  |  |  | 10 |  | 
|  | 6 |  |  |  |  | 149 |  | 
| 4 | 6 |  |  | 6 |  | 24 | use warnings; | 
|  | 6 |  |  |  |  | 9 |  | 
|  | 6 |  |  |  |  | 124 |  | 
| 5 | 6 |  |  | 6 |  | 22 | use utf8; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 45 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | package Text::Layout::FontDescriptor; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 6 |  |  | 6 |  | 178 | use Carp; | 
|  | 6 |  |  |  |  | 11 |  | 
|  | 6 |  |  |  |  | 3530 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | our $VERSION = "0.029"; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | =head1 NAME | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | Text::Layout::FontDescriptor - font description for Text::Layout | 
| 18 |  |  |  |  |  |  |  | 
| 19 |  |  |  |  |  |  | =head1 SYNOPSIS | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | Font descriptors are used internally by Text::Layout and | 
| 22 |  |  |  |  |  |  | Text::Layout::FontConfig. | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | =head1 METHODS | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | =over | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =item new( [ %atts ] ) | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | Creates a new FontDescriptor object. | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | Attributes: | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | =over | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =item family | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | =item style | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =item weight | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | The Family, style, and weight of this font. There are mandatory. For | 
| 45 |  |  |  |  |  |  | defaults, use an empty string. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | =item size | 
| 48 |  |  |  |  |  |  |  | 
| 49 |  |  |  |  |  |  | Optional, font size. | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =item font | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | The actual font data. | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =item loader | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | A code reference to call to actually create/load the font if necessary. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | Loading will store the font data in the C property. | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | =back | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =back | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =cut | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub new { | 
| 68 | 21 |  |  | 21 | 1 | 162 | my ( $pkg, %atts ) = @_; | 
| 69 | 21 |  |  |  |  | 204 | my $self = bless { style => "", | 
| 70 |  |  |  |  |  |  | weight => "", | 
| 71 |  |  |  |  |  |  | %atts } => $pkg; | 
| 72 |  |  |  |  |  |  |  | 
| 73 | 21 |  |  |  |  | 135 | return $self; | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =over | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | =item get_font | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | Returns the actual font data for the font this descriptor describes. | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | If necessary, the backend will be called to create/load the font. | 
| 83 |  |  |  |  |  |  |  | 
| 84 |  |  |  |  |  |  | =back | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | =cut | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | sub get_font { | 
| 89 | 5 |  |  | 5 | 1 | 359 | my ( $self, $context ) = @_; | 
| 90 | 5 |  | 66 |  |  | 27 | $self->{font} ||= do { | 
| 91 | 2 | 50 |  |  |  | 9 | croak("Forgot to pass a layout context to get_font?") | 
| 92 |  |  |  |  |  |  | unless UNIVERSAL::isa( $context, 'Text::Layout' ); | 
| 93 | 2 |  |  |  |  | 11 | $context->load_font( $self->{loader_data}, $self ); | 
| 94 |  |  |  |  |  |  | }; | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | =over | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | =item get_family | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | =item get_style | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | =item get_weight | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | Accessors to the font family, style, and weight. | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | Readonly. | 
| 108 |  |  |  |  |  |  |  | 
| 109 |  |  |  |  |  |  | =back | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | =cut | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | sub get_family { | 
| 114 | 0 |  |  | 0 | 1 | 0 | my ( $self ) = @_; | 
| 115 | 0 |  |  |  |  | 0 | $self->{family}; | 
| 116 |  |  |  |  |  |  | } | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | sub get_style { | 
| 119 | 0 |  |  | 0 | 1 | 0 | my ( $self ) = @_; | 
| 120 | 0 |  |  |  |  | 0 | $self->{style}; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | sub get_weight { | 
| 124 | 0 |  |  | 0 | 1 | 0 | my ( $self ) = @_; | 
| 125 | 0 |  |  |  |  | 0 | $self->{weight}; | 
| 126 |  |  |  |  |  |  | } | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | =over | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | =item set_size | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | =item get_size | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | Sets/gets the size property of the font. | 
| 135 |  |  |  |  |  |  |  | 
| 136 |  |  |  |  |  |  | =back | 
| 137 |  |  |  |  |  |  |  | 
| 138 |  |  |  |  |  |  | =cut | 
| 139 |  |  |  |  |  |  |  | 
| 140 |  |  |  |  |  |  | sub set_size { | 
| 141 | 5 |  |  | 5 | 1 | 12 | my ( $self, $size ) = @_; | 
| 142 | 5 |  |  |  |  | 12 | $self->{size} = $size; | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | sub get_size { | 
| 146 | 2 |  |  | 2 | 1 | 3 | my ( $self ) = @_; | 
| 147 | 2 |  |  |  |  | 9 | $self->{size}; | 
| 148 |  |  |  |  |  |  | } | 
| 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 | 1 |  |  | 1 | 0 | 3 | my ( $self ) = @_; | 
| 179 | 1 |  |  |  |  | 5 | $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 | 3 |  |  | 3 | 0 | 7 | my ( $self ) = @_; | 
| 191 | 3 |  |  |  |  | 13 | $self->{interline}; | 
| 192 |  |  |  |  |  |  | } | 
| 193 |  |  |  |  |  |  |  | 
| 194 |  |  |  |  |  |  | =over | 
| 195 |  |  |  |  |  |  |  | 
| 196 |  |  |  |  |  |  | =item to_string | 
| 197 |  |  |  |  |  |  |  | 
| 198 |  |  |  |  |  |  | Returns a Pango-style font string, C. | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | =back | 
| 201 |  |  |  |  |  |  |  | 
| 202 |  |  |  |  |  |  | =cut | 
| 203 |  |  |  |  |  |  |  | 
| 204 |  |  |  |  |  |  | sub to_string { | 
| 205 | 53 |  |  | 53 | 1 | 86 | my ( $self ) = @_; | 
| 206 | 53 |  |  |  |  | 97 | my $desc = ucfirst( $self->{family} ); | 
| 207 |  |  |  |  |  |  | $desc .= ucfirst( $self->{style} ) | 
| 208 | 53 | 100 | 66 |  |  | 258 | if $self->{style} && $self->{style} ne "normal"; | 
| 209 |  |  |  |  |  |  | $desc .= " " . ucfirst( $self->{weight} ) | 
| 210 | 53 | 100 | 66 |  |  | 159 | if $self->{weight} && $self->{weight} ne "normal"; | 
| 211 | 53 | 100 |  |  |  | 94 | $desc .= " " . $self->{size} if $self->{size}; | 
| 212 | 53 |  |  |  |  | 296 | return $desc; | 
| 213 |  |  |  |  |  |  | } | 
| 214 |  |  |  |  |  |  |  | 
| 215 | 6 |  |  | 6 |  | 4111 | use overload '""' => \&to_string; | 
|  | 6 |  |  |  |  | 3403 |  | 
|  | 6 |  |  |  |  | 52 |  | 
| 216 |  |  |  |  |  |  |  | 
| 217 |  |  |  |  |  |  | =head1 SEE ALSO | 
| 218 |  |  |  |  |  |  |  | 
| 219 |  |  |  |  |  |  | L, L. | 
| 220 |  |  |  |  |  |  |  | 
| 221 |  |  |  |  |  |  | =head1 AUTHOR | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | Johan Vromans, C<<  >> | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | =head1 SUPPORT | 
| 226 |  |  |  |  |  |  |  | 
| 227 |  |  |  |  |  |  | This module is part of L. | 
| 228 |  |  |  |  |  |  |  | 
| 229 |  |  |  |  |  |  | Development takes place on GitHub: | 
| 230 |  |  |  |  |  |  | L. | 
| 231 |  |  |  |  |  |  |  | 
| 232 |  |  |  |  |  |  | You can find documentation for this module with the perldoc command. | 
| 233 |  |  |  |  |  |  |  | 
| 234 |  |  |  |  |  |  | perldoc Text::Layout::FontDescriptor | 
| 235 |  |  |  |  |  |  |  | 
| 236 |  |  |  |  |  |  | Please report any bugs or feature requests using the issue tracker for Text::Layout on GitHub. | 
| 237 |  |  |  |  |  |  |  | 
| 238 |  |  |  |  |  |  | =head1 LICENSE | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | See L. | 
| 241 |  |  |  |  |  |  |  | 
| 242 |  |  |  |  |  |  | =cut | 
| 243 |  |  |  |  |  |  |  | 
| 244 |  |  |  |  |  |  | 1; |