X-Git-Url: http://git.vpit.fr/?p=perl%2Fmodules%2FLaTeX-TikZ.git;a=blobdiff_plain;f=lib%2FLaTeX%2FTikZ%2FSet.pm;fp=lib%2FLaTeX%2FTikZ%2FSet.pm;h=e673097ec2f20e7a9349e8cabff8cdef3cfb84c3;hp=4e6eafcab46dc282645010805e07fb4f03734b57;hb=4ec204cfd114d9ce19fd616f093503c971b00a1f;hpb=7f9973057cc57660599aa4a093718cf343a48198 diff --git a/lib/LaTeX/TikZ/Set.pm b/lib/LaTeX/TikZ/Set.pm index 4e6eafc..e673097 100644 --- a/lib/LaTeX/TikZ/Set.pm +++ b/lib/LaTeX/TikZ/Set.pm @@ -15,8 +15,7 @@ Version 0.02 our $VERSION = '0.02'; -use Scope::Guard (); - +use LaTeX::TikZ::Context; use LaTeX::TikZ::Scope; use LaTeX::TikZ::Tools; @@ -49,9 +48,10 @@ This method is required by the interface : =item * -C +C Returns an array reference of TikZ code lines required to effectively draw the current set object, formatted by the L object C<$formatter>. +The current evaluation context is passed as the L object C<$context>. =back @@ -82,63 +82,25 @@ sub mod { $set; } -{ - our %mods; - our $last_mod = 0; - - around 'draw' => sub { - my ($orig, $set, $tikz) = @_; - - local $last_mod = $last_mod; - - # Save a deep copy - my %saved_idx = map { $_ => $#{$mods{$_}} } keys %mods; - my $guard = Scope::Guard->new(sub { - for (keys %mods) { - if (exists $saved_idx{$_}) { - $#{$mods{$_}} = $saved_idx{$_}; - } else { - delete $mods{$_}; - } - } - }); - - my (@mods, $last_layer); -MOD: - for my $mod ($set->mods) { - my $is_layer = $ltml_tc->check($mod); - $last_layer = $mod if $is_layer; - my $tag = $mod->tag; - my $old = $mods{$tag} || []; - for (@$old) { - next MOD if $_->[0]->covers($mod); - } - push @{$mods{$tag}}, [ $mod, $last_mod++, $is_layer ]; - push @mods, $mod; - } - - if ($last_layer) { - # Clips and mods don't propagate through layers. Hence if a layer is set, - # force their reuse. - @mods = $last_layer; - push @mods, map $_->[0], - sort { $a->[1] <=> $b->[1] } - grep !$_->[2], - map @$_, - values %mods; - } - - my $body = $set->$orig($tikz); - - if (@mods) { - $body = LaTeX::TikZ::Scope->new - ->mod(map $_->apply($tikz), @mods) - ->body($body); - } - - $body; - }; -} +around 'draw' => sub { + my ($orig, $set, $tikz, $pcxt) = @_; + + my $cxt = LaTeX::TikZ::Context->new( + parent => $pcxt, + mods => [ $set->mods ], + ); + + my $body = $set->$orig($tikz, $cxt); + + my @mods = $cxt->effective_mods; + if (@mods) { + $body = LaTeX::TikZ::Scope->new + ->mod(map $_->apply($tikz), @mods) + ->body($body); + } + + $body; +}; =head2 C