File Coverage

blib/lib/Graphics/Primitive/Font.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Graphics::Primitive::Font;
2 2     2   41351 use Moose;
  0            
  0            
3             use MooseX::Storage;
4             use Moose::Util::TypeConstraints;
5              
6             with 'MooseX::Clone';
7             with Storage (format => 'JSON', io => 'File');
8              
9             enum 'Graphics::Primitive::Font::AntialiasModes' => [
10             qw(default none gray subpixel)
11             ];
12             enum 'Graphics::Primitive::Font::HintMetrics' => [
13             'default', 'off', 'on'
14             ];
15             enum 'Graphics::Primitive::Font::HintStyles' => [
16             'default', 'none', 'slight', 'medium', 'full'
17             ];
18             enum 'Graphics::Primitive::Font::Slants' => [
19             'normal', 'italic', 'oblique'
20             ];
21             enum 'Graphics::Primitive::Font::SubpixelOrders' => [
22             qw(default rgb bgr vrgb vbgr)
23             ];
24             enum 'Graphics::Primitive::Font::Variants' => [
25             'normal', 'small-caps'
26             ];
27             enum 'Graphics::Primitive::Font::Weights' => [
28             'normal', 'bold'
29             ];
30              
31             has 'antialias_mode' => (
32             is => 'rw',
33             isa => 'Graphics::Primitive::Font::AntialiasModes',
34             default => 'default'
35             );
36             has 'family' => (
37             is => 'rw',
38             isa => 'Str',
39             default => $ENV{GRAPHICS_PRIMITIVE_DEFAULT_FONT} || ($^O eq 'MSWin32'?'Arial':'Sans')
40             );
41             has 'hint_metrics' => (
42             is => 'rw',
43             isa => 'Graphics::Primitive::Font::HintMetrics',
44             default => 'default'
45             );
46             has 'hint_style' => (
47             is => 'rw',
48             isa => 'Graphics::Primitive::Font::HintStyles',
49             default => 'default'
50             );
51             has 'size' => (
52             is => 'rw',
53             isa => 'Num',
54             default => sub { 12 }
55             );
56             has 'slant' => (
57             is => 'rw',
58             isa => 'Graphics::Primitive::Font::Slants',
59             default => 'normal'
60             );
61             has 'subpixel_order' => (
62             is => 'rw',
63             isa => 'Graphics::Primitive::Font::SubpixelOrders',
64             default => 'default'
65             );
66             has 'variant' => (
67             is => 'rw',
68             isa => 'Graphics::Primitive::Font::Variants',
69             default => 'normal'
70             );
71             has 'weight' => (
72             is => 'rw',
73             isa => 'Graphics::Primitive::Font::Weights',
74             default => 'normal'
75             );
76              
77             __PACKAGE__->meta->add_method('face' => __PACKAGE__->can('family'));
78              
79             sub derive {
80             my ($self, $args) = @_;
81              
82             return unless ref($args) eq 'HASH';
83             my $new = $self->clone;
84             foreach my $key (keys %{ $args }) {
85             $new->$key($args->{$key}) if($new->can($key));
86             }
87             return $new;
88             }
89              
90             __PACKAGE__->meta->make_immutable;
91              
92             no Moose;
93             1;
94             __END__
95             =head1 NAME
96              
97             Graphics::Primitive::Font - Text styling
98              
99             =head1 DESCRIPTION
100              
101             Graphics::Primitive::Font represents the various options that are available
102             when rendering text. The options here may or may not have an effect on your
103             rendering. They represent a cross-section of the features provided by
104             various drivers. Setting them should B<not> break anything, but may not
105             have an effect if the driver doesn't understand the option.
106              
107             =head1 SYNOPSIS
108              
109             use Graphics::Primitive::Font;
110              
111             my $font = Graphics::Primitive::Font->new({
112             family => 'Arial',
113             size => 12,
114             slant => 'normal'
115             });
116              
117             =head1 METHODS
118              
119             =head2 Constructor
120              
121             =over 4
122              
123             =back
124              
125             =head1 Attributes
126              
127             =head2 antialias_modes
128              
129             Set the antialiasing mode for this font. Possible values are default, none,
130             gray and subpixel.
131              
132             =head2 family
133              
134             Set this font's family.
135              
136             =head2 hint_metrics
137              
138             Controls whether to hint font metrics. Hinting means quantizing them so that
139             they are integer values in device space. This improves the consistency of
140             letter and line spacing, however it also means that text will be laid out
141             differently at different zoom factors. May not be supported by all drivers.
142              
143             =head2 hint_style
144              
145             Set the the type of hinting to do on font outlines. Hinting is the process of
146             fitting outlines to the pixel grid in order to improve the appearance of the
147             result. Since hinting outlines involves distorting them, it also reduces the
148             faithfulness to the original outline shapes. Not all of the outline hinting
149             styles are supported by all drivers. Options are default, none, slight,
150             medium and full.
151              
152             =head2 size
153              
154             Set/Get the size of this font.
155              
156             =head2 slant
157              
158             Set/Get the slant of this font. Valid values are normal, italic and oblique.
159              
160             =head2 subpixel_order
161              
162             Set the order of color elements within each pixel on the display device when
163             rendering with subpixel antialiasing. Value values are default, rgb, bgr,
164             vrgb and vbgr.
165              
166             =head2 variant
167              
168             Set/Get the variant of this font. Valid values are normal or small-caps.
169              
170             =head2 weight
171              
172             Set/Get the weight of this font. Value valies are normal and bold.
173              
174             =head1 METHODS
175              
176             =head2 new
177              
178             Creates a new Graphics::Primitive::Font.
179              
180             =head2 derive
181              
182             Clone this font but change one or more of it's attributes by passing in a
183             hashref of options:
184              
185             my $new = $font->derive({ attr => $newvalue });
186            
187             The returned font will be identical to the cloned one, save the attributes
188             specified.
189              
190             =head1 AUTHOR
191              
192             Cory Watson, C<< <gphat@cpan.org> >>
193              
194             =head1 COPYRIGHT & LICENSE
195              
196             Copyright 2008-2010 by Cory G Watson.
197              
198             This program is free software; you can redistribute it and/or modify it
199             under the same terms as Perl itself.