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