| 1 | #! perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | package Text::Layout::FontDescriptor; | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 8 | 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<font> property. | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | =back | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =back | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | =cut | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 27 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 27 | my ( $pkg, %atts ) = @_; | |||||||||||||||||||||||||||
| 67 | 27 | my $self = bless { style => "", | |||||||||||||||||||||||||||
| 68 | weight => "", | ||||||||||||||||||||||||||||
| 69 | %atts } => $pkg; | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 27 | 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 | 7 | ▶ | sub get_font { | ||||||||||||||||||||||||||
|
Subroutine
get_font: called CC=3 SCAR=11.3
Pod
documented
| |||||||||||||||||||||||||||||
| 87 | 7 | my ( $self, $context ) = @_; | |||||||||||||||||||||||||||
| 88 | 7 | ▶ | $self->{font} ||= do { | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->{"font"} ||= do {
croak("Forgot to pass a layout context to get_font?") unless UNIVERSAL::isa($context, "Text::Layout");
$context->load_font($self->{"loader_data"}, $self)
}
MC/DC0%0/2
$self->{"font"} ||= do {
croak("Forgot to pass a layout context to get_font?") unless UNIVERSAL::isa($context, "Text::Layout");
$context->load_font($self->{"loader_data"}, $self)
}
$self->{"font"}
do {
croak("Forgot to pass a layout context to get_font?") unless UNIVERSAL::isa($context, "Text::Layout");
$context->load_font($self->{"loader_data"}, $self)
}
Truth table66%2/3
A ||= B
A= $self->{"font"}B= do {
croak("Forgot to pass a layout context to get_font?") unless UNIVERSAL::isa($context, "Text::Layout");
$context->load_font($self->{"loader_data"}, $self)
}
| |||||||||||||||||||||||||||||
| 89 | 3 | ▶ | croak("Forgot to pass a layout context to get_font?") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | unless UNIVERSAL::isa( $context, 'Text::Layout' ); | ||||||||||||||||||||||||||||
| 91 | 3 | $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 | 0 | ▶ | sub get_family { | ||||||||||||||||||||||||||
|
Subroutine
get_family: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 113 | 0 | $self->{family}; | |||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 0 | ▶ | sub get_style { | ||||||||||||||||||||||||||
|
Subroutine
get_style: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 117 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 118 | 0 | $self->{style}; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | sub get_weight { | ||||||||||||||||||||||||||
|
Subroutine
get_weight: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 123 | 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 | 7 | ▶ | sub set_size { | ||||||||||||||||||||||||||
|
Subroutine
set_size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 139 | 7 | my ( $self, $size ) = @_; | |||||||||||||||||||||||||||
| 140 | 7 | $self->{size} = $size; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 2 | ▶ | sub get_size { | ||||||||||||||||||||||||||
|
Subroutine
get_size: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 144 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 145 | 2 | $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 | 0 | ▶ | sub set_direction { | ||||||||||||||||||||||||||
|
Subroutine
set_direction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 161 | 0 | my ( $self, $direction ) = @_; | |||||||||||||||||||||||||||
| 162 | 0 | $self->{direction} = $direction; | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | sub get_direction { | ||||||||||||||||||||||||||
|
Subroutine
get_direction: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 166 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 167 | 0 | $self->{direction}; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | # Not documented -- internal use only. | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | 0 | ▶ | sub set_shaping { | ||||||||||||||||||||||||||
|
Subroutine
set_shaping: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 173 | 0 | my ( $self, $sh ) = @_; | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | $self->{shaping} = $sh // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$sh // 1
MC/DC0%0/1
$sh // 1
$sh
Truth table0%0/2
A
A= $sh
| |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 2 | ▶ | sub get_shaping { | ||||||||||||||||||||||||||
|
Subroutine
get_shaping: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 178 | 2 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 179 | 2 | $self->{shaping}; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | # Not documented -- internal use only. | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | sub set_interline { | ||||||||||||||||||||||||||
|
Subroutine
set_interline: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 185 | 0 | my ( $self, $sh ) = @_; | |||||||||||||||||||||||||||
| 186 | 0 | ▶ | $self->{interline} = $sh // 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
$sh // 1
MC/DC0%0/1
$sh // 1
$sh
Truth table0%0/2
A
A= $sh
| |||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | sub get_interline { | ||||||||||||||||||||||||||
|
Subroutine
get_interline: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 190 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 191 | 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 | 0 | ▶ | sub set_ascender { | ||||||||||||||||||||||||||
|
Subroutine
set_ascender: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 200 | 0 | my ( $self, $asc ) = @_; | |||||||||||||||||||||||||||
| 201 | 0 | $self->{ascender} = $asc; | |||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 4 | ▶ | sub get_ascender { | ||||||||||||||||||||||||||
|
Subroutine
get_ascender: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 205 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 206 | 4 | $self->{ascender}; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub set_descender { | ||||||||||||||||||||||||||
|
Subroutine
set_descender: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 210 | 0 | my ( $self, $desc ) = @_; | |||||||||||||||||||||||||||
| 211 | 0 | $self->{descender} = $desc; | |||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 4 | ▶ | sub get_descender { | ||||||||||||||||||||||||||
|
Subroutine
get_descender: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 215 | 4 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 216 | 4 | $self->{descender}; | |||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||
| 219 | =over | ||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | =item to_string | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | Returns a Pango-style font string, C<Sans Italic 14>. | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =back | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | =cut | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 35 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 230 | 35 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 231 | 35 | my $desc = ucfirst( $self->{family} ); | |||||||||||||||||||||||||||
| 232 | $desc .= ucfirst( $self->{style} ) | ||||||||||||||||||||||||||||
| 233 | 35 | ▶ | if $self->{style} && $self->{style} ne "normal"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"style"} and $self->{"style"} ne "normal"
MC/DC50%1/2
$self->{"style"} and $self->{"style"} ne "normal"
$self->{"style"}
$self->{"style"} ne "normal"
Truth table66%2/3
A and B
A= $self->{"style"}B= $self->{"style"} ne "normal"
| |||||||||||||||||||||||||||||
| 234 | $desc .= " " . ucfirst( $self->{weight} ) | ||||||||||||||||||||||||||||
| 235 | 35 | ▶ | if $self->{weight} && $self->{weight} ne "normal"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"weight"} and $self->{"weight"} ne "normal"
MC/DC50%1/2
$self->{"weight"} and $self->{"weight"} ne "normal"
$self->{"weight"}
$self->{"weight"} ne "normal"
Truth table66%2/3
A and B
A= $self->{"weight"}B= $self->{"weight"} ne "normal"
| |||||||||||||||||||||||||||||
| 236 | 35 | ▶ | $desc .= " " . $self->{size} if $self->{size}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 237 | 35 | return $desc; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | 8 | ▶ | use overload '""' => \&to_string; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | L<Text::Layout::FontConfig>, L<Text::Layout>. | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | Johan Vromans, C<< <JV at CPAN dot org> >> | ||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | This module is part of L<Text::Layout>. | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | Development takes place on GitHub: | ||||||||||||||||||||||||||||
| 255 | L<https://github.com/sciurius/perl-Text-Layout>. | ||||||||||||||||||||||||||||
| 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<Text::Layout>. | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 8 | 1; | |||||||||||||||||||||||||||