1 package LaTeX::TikZ::Formatter;
8 LaTeX::TikZ::Formatter - LaTeX::TikZ formatter object.
16 our $VERSION = '0.01';
20 use LaTeX::TikZ::Tools;
23 use Any::Moose 'Util::TypeConstraints';
27 isa => enum([ qw/cm pt/ ]),
55 does => 'Maybe[LaTeX::TikZ::Point]',
60 no warnings 'recursion';
62 Sub::Name::subname('find_mods' => sub {
63 my ($set, $layers, $others) = @_;
65 if ($set->isa('LaTeX::TikZ::Set::Mod')) {
67 if ($_->isa('LaTeX::TikZ::Mod::Layer')) {
75 my @subsets = $set->isa('LaTeX::TikZ::Set::Sequence')
77 : $set->isa('LaTeX::TikZ::Set::Path')
81 $find_mods->($_, $layers, $others) for @subsets;
88 my $seq = LaTeX::TikZ::Set::Sequence->new(
92 my (@layers, @other_mods);
93 $find_mods->($seq, \@layers, \@other_mods);
95 my $o = $tikz->origin;
96 $seq = $seq->translate($o) if defined $o;
99 my $h = $tikz->height;
101 if (defined $w and defined $h) {
102 $seq->clip(Tikz->rectangle(Tikz->point(0) => [ $w, $h ]));
103 $_ = $tikz->len($_) for $w, $h;
104 $canvas = ",papersize={$w,$h},body={$w,$h}";
108 "\\usepackage[pdftex,hcentering,vcentering$canvas]{geometry}",
109 "\\usepackage{tikz}",
110 "\\usetikzlibrary{patterns}",
115 push @decls, LaTeX::TikZ::Mod::Layer->declare(@layers);
118 push @decls, $_->declare($tikz);
122 "\\begin{tikzpicture}",
123 $seq->draw($tikz)->instantiate,
124 "\\end{tikzpicture}",
127 return \@header, \@decls, \@content;
131 my ($tikz, $len) = @_;
133 $len = 0 if LaTeX::TikZ::Tools::numeq($len, 0);
135 sprintf $tikz->format . $tikz->unit, $len * $tikz->scale;
141 $a = ($a * 180) / CORE::atan2(0, -1);
142 $a += 360 if LaTeX::TikZ::Tools::numcmp($a, 0) < 0;
145 sprintf $tikz->format, POSIX::ceil($a);
149 my ($tikz, $name, $pos) = @_;
151 my $scale = sprintf '%0.2f', $tikz->scale / 5;
153 "node[scale=$scale,$pos] {\$$name\$}";
157 my ($tikz, $width) = @_;
159 # width=1 is 0.4 points for a scale of 2.5
160 0.8 * $width * ($tikz->scale / 5);
163 __PACKAGE__->meta->make_immutable;
167 Vincent Pit, C<< <perl at profvince.com> >>, L<http://www.profvince.com>.
169 You can contact me by mail or on C<irc.perl.org> (vincent).
173 Please report any bugs or feature requests to C<bug-latex-tikz at rt.cpan.org>, or through the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LaTeX-TikZ>.
174 I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
178 You can find documentation for this module with the perldoc command.
182 =head1 COPYRIGHT & LICENSE
184 Copyright 2010 Vincent Pit, all rights reserved.
186 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
190 1; # End of LaTeX::TikZ::Formatter