From: Vincent Pit Date: Thu, 22 Jul 2010 20:54:33 +0000 (+0200) Subject: Make ->render return one body for each argument X-Git-Tag: v0.01~7 X-Git-Url: http://git.vpit.fr/?a=commitdiff_plain;h=ee0f9123624eb8e48675f80303ed436b9a94e348;p=perl%2Fmodules%2FLaTeX-TikZ.git Make ->render return one body for each argument --- diff --git a/lib/LaTeX/TikZ/Formatter.pm b/lib/LaTeX/TikZ/Formatter.pm index 718c3eb..efa7dc6 100644 --- a/lib/LaTeX/TikZ/Formatter.pm +++ b/lib/LaTeX/TikZ/Formatter.pm @@ -117,11 +117,7 @@ my $find_mods = do { my $translate; sub render { - my $tikz = shift; - - my $seq = LaTeX::TikZ::Set::Sequence->new( - kids => \@_, - ); + my ($tikz, @sets) = @_; unless ($translate) { require LaTeX::TikZ::Functor; @@ -144,9 +140,12 @@ sub render { } my $origin = $tikz->origin; - $seq = $seq->$translate($origin) if defined $origin; + if (defined $origin) { + @sets = map $_->$translate($origin), @sets; + } my (@layers, @other_mods); + my $seq = LaTeX::TikZ::Set::Sequence->new(kids => \@sets); $find_mods->($seq, \@layers, \@other_mods); my $w = $tikz->width; @@ -154,11 +153,13 @@ sub render { my $canvas = ''; if (defined $w and defined $h) { require LaTeX::TikZ::Set::Rectangle; - $seq->clip(LaTeX::TikZ::Set::Rectangle->new( - from => 0, - width => $w, - height => $h, - )); + for (@sets) { + $_->clip(LaTeX::TikZ::Set::Rectangle->new( + from => 0, + width => $w, + height => $h, + )); + } $_ = $tikz->len($_) for $w, $h; $canvas = ",papersize={$w,$h},body={$w,$h}"; } @@ -173,13 +174,13 @@ sub render { push @decls, LaTeX::TikZ::Mod::Layer->declare(@layers) if @layers; push @decls, $_->declare($tikz) for @other_mods; - my @content = ( + my @bodies = map [ "\\begin{tikzpicture}", - @{ $seq->draw($tikz) }, + @{ $_->draw($tikz) }, "\\end{tikzpicture}", - ); + ], @sets; - return \@header, \@decls, \@content; + return \@header, \@decls, @bodies; } sub len { diff --git a/t/10-set.t b/t/10-set.t index f8d4dee..190846c 100644 --- a/t/10-set.t +++ b/t/10-set.t @@ -128,7 +128,7 @@ eval { }; is $@, '', 'adding something to a path set doesn\'t croak'; -check [ $path, $path ], 'two identical path sets', <<'RES'; +check Tikz->seq($path, $path), 'two identical path sets', <<'RES'; \draw foo bar baz foo ; \draw foo bar baz foo ; RES diff --git a/t/20-mod.t b/t/20-mod.t index b6db376..50a869e 100644 --- a/t/20-mod.t +++ b/t/20-mod.t @@ -123,7 +123,7 @@ my $baz = eval { }; is $@, '', 'creating another colored raw set doesn\'t croak'; -check [ $foo, $baz ], 'mods folding 1', <<'RES'; +check Tikz->seq($foo, $baz), 'mods folding 1', <<'RES'; \begin{scope} [color=red] \begin{scope} [line width=4.0pt] \draw foo ; @@ -133,7 +133,7 @@ check [ $foo, $baz ], 'mods folding 1', <<'RES'; \end{scope} RES -check [ $baz, $foo ], 'mods folding 2', <<'RES'; +check Tikz->seq($baz, $foo), 'mods folding 2', <<'RES'; \begin{scope} [color=red] \draw baz ; \begin{scope} [line width=4.0pt] @@ -149,7 +149,7 @@ my $qux = eval { }; is $@, '', 'creating another raw set with modded width doesn\'t croak'; -check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES'; +check Tikz->seq($foo, $baz, $qux), 'mods folding 3', <<'RES'; \begin{scope} [color=red] \begin{scope} [line width=4.0pt] \draw foo ; @@ -160,7 +160,7 @@ check [ $foo, $baz, $qux ], 'mods folding 3', <<'RES'; \draw [line width=4.0pt] qux ; RES -check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES'; +check Tikz->seq($foo, $qux, $baz), 'mods folding 4', <<'RES'; \begin{scope} [line width=4.0pt] \begin{scope} [color=red] \draw foo ; @@ -171,7 +171,7 @@ check [ $foo, $qux, $baz ], 'mods folding 4', <<'RES'; \draw [color=red] baz ; RES -check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES'; +check Tikz->seq($baz, $foo, $qux), 'mods folding 5', <<'RES'; \begin{scope} [color=red] \draw baz ; \begin{scope} [line width=4.0pt] @@ -182,7 +182,7 @@ check [ $baz, $foo, $qux ], 'mods folding 5', <<'RES'; \draw [line width=4.0pt] qux ; RES -check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES'; +check Tikz->seq($baz, $qux, $foo), 'mods folding 6', <<'RES'; \draw [color=red] baz ; \draw [line width=4.0pt] qux ; \begin{scope} [color=red,line width=4.0pt] @@ -191,7 +191,7 @@ check [ $baz, $qux, $foo ], 'mods folding 6', <<'RES'; \end{scope} RES -check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES'; +check Tikz->seq($qux, $foo, $baz), 'mods folding 7', <<'RES'; \begin{scope} [line width=4.0pt] \draw qux ; \begin{scope} [color=red] @@ -202,7 +202,7 @@ check [ $qux, $foo, $baz ], 'mods folding 7', <<'RES'; \draw [color=red] baz ; RES -check [ $qux, $baz, $foo ], 'mods folding 8', <<'RES'; +check Tikz->seq($qux, $baz, $foo), 'mods folding 8', <<'RES'; \draw [line width=4.0pt] qux ; \draw [color=red] baz ; \begin{scope} [color=red,line width=4.0pt]