File Coverage

blib/lib/PDF/TextBlock/Font.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 1 1 100.0
total 38 39 97.4


line stmt bran cond sub pod time code
1             package PDF::TextBlock::Font;
2              
3 6     6   42 use strict;
  6         9  
  6         178  
4 6     6   49 use warnings;
  6         9  
  6         150  
5 6     6   29 use Class::Accessor::Fast;
  6         9  
  6         32  
6              
7 6     6   169 use base qw( Class::Accessor::Fast );
  6         18  
  6         649  
8             __PACKAGE__->mk_accessors(qw( pdf font fillcolor size ));
9              
10 6     6   41 use constant mm => 25.4 / 72;
  6         12  
  6         536  
11 6     6   118 use constant in => 1 / 72;
  6         13  
  6         334  
12 6     6   48 use constant pt => 1;
  6         14  
  6         1163  
13              
14             our $VERSION = '0.04';
15              
16             =head1 NAME
17              
18             PDF::TextBlock::Font - A font object to override the defaults PDF::TextBlock uses
19              
20             =head1 SYNOPSIS
21              
22             TODO add from t/*
23              
24             =head1 DESCRIPTION
25              
26             You can hand PDF::TextBlock objects from this class whenever you want to override
27             the font defaults.
28              
29             =head1 METHODS
30              
31             =head2 apply_defaults
32              
33             Applies defaults for you wherever you didn't explicitly set a different value.
34              
35             =cut
36              
37             sub apply_defaults {
38 34     34 1 110 my ($self) = @_;
39 34 50       800 die "pdf attribute (your PDF::API object) required" unless $self->pdf;
40 34         863 my %defaults = (
41             # font is a PDF::API2::Resource::Font::CoreFont
42             font => $self->pdf->corefont( 'Helvetica', -encoding => 'latin1' ),
43             fillcolor => 'black',
44             size => 10 / pt,
45             );
46 34         1003573 foreach my $att (keys %defaults) {
47 102 100       3879 $self->$att($defaults{$att}) unless defined $self->$att;
48             }
49              
50             #my %fonts = (
51             # Helvetica => {
52             # Bold => $pdf->corefont( 'Helvetica-Bold', -encoding => 'latin1' ),
53             # Roman => $pdf->corefont( 'Helvetica', -encoding => 'latin1' ),
54             # Italic => $pdf->corefont( 'Helvetica-Oblique', -encoding => 'latin1' ),
55             # },
56             # Gotham => {
57             # Bold => $pdf->ttfont('Gotham-Bold.ttf', -encode => 'latin1'),
58             # Roman => $pdf->ttfont('Gotham-Light.otf', -encode => 'latin1'),
59             # },
60             #);
61             }
62              
63              
64             =head1 AUTHOR
65              
66             Jay Hannah, C<< >>
67              
68             =head1 BUGS / SUPPORT
69              
70             See PDF::TextBlock.
71              
72             =head1 COPYRIGHT & LICENSE
73              
74             Copyright 2009-2013 Jay Hannah, all rights reserved.
75              
76             This program is free software; you can redistribute it and/or modify it
77             under the same terms as Perl itself.
78              
79             =cut
80              
81             1; # End of PDF::TextBlock::Font