]> git.vpit.fr Git - perl/modules/LaTeX-TikZ.git/blobdiff - lib/LaTeX/TikZ/Formatter.pm
Make the formatter autocoerce the origin
[perl/modules/LaTeX-TikZ.git] / lib / LaTeX / TikZ / Formatter.pm
index 64266072622b8dac002b407a7c57fa534e13e358..b9a6e10de4e7aae925e04899cc2411440a0d73ee 100644 (file)
@@ -51,8 +51,9 @@ has 'height' => (
 );
 
 has 'origin' => (
- is   => 'ro',
- does => 'Maybe[LaTeX::TikZ::Point]',
+ is     => 'ro',
+ isa    => 'Maybe[LaTeX::TikZ::Point::Autocoerce]',
+ coerce => 1,
 );
 
 my $find_mods;
@@ -62,13 +63,11 @@ $find_mods = do {
  Sub::Name::subname('find_mods' => sub {
   my ($set, $layers, $others) = @_;
 
-  if ($set->isa('LaTeX::TikZ::Set::Mod')) {
-   for ($set->mods) {
-    if ($_->isa('LaTeX::TikZ::Mod::Layer')) {
-     push @$layers, $_;
-    } else {
-     push @$others, $_;
-    }
+  for ($set->mods) {
+   if ($_->isa('LaTeX::TikZ::Mod::Layer')) {
+    push @$layers, $_;
+   } else {
+    push @$others, $_;
    }
   }
 
@@ -99,7 +98,12 @@ sub render {
  my $h = $tikz->height;
  my $canvas = '';
  if (defined $w and defined $h) {
-  $seq->clip(Tikz->rectangle(Tikz->point(0) => [ $w, $h ]));
+  require LaTeX::TikZ::Set::Rectangle;
+  $seq->clip(LaTeX::TikZ::Set::Rectangle->new(
+   from   => 0,
+   width  => $w,
+   height => $h,
+  ));
   $_ = $tikz->len($_) for $w, $h;
   $canvas = ",papersize={$w,$h},body={$w,$h}";
  }
@@ -111,16 +115,12 @@ sub render {
  );
 
  my @decls;
- if (@layers) {
-  push @decls, LaTeX::TikZ::Mod::Layer->declare(@layers);
- }
- for (@other_mods) {
-  push @decls, $_->declare($tikz);
- }
+ push @decls, LaTeX::TikZ::Mod::Layer->declare(@layers) if  @layers;
+ push @decls, $_->declare($tikz)                        for @other_mods;
 
  my @content = (
   "\\begin{tikzpicture}",
-  $seq->draw($tikz)->instantiate,
+  @{ $seq->draw($tikz) },
   "\\end{tikzpicture}",
  );
 
@@ -160,6 +160,12 @@ sub thickness {
  0.8 * $width * ($tikz->scale / 5);
 }
 
+use LaTeX::TikZ::Interface formatter => sub {
+ shift;
+
+ __PACKAGE__->new(@_);
+};
+
 __PACKAGE__->meta->make_immutable;
 
 =head1 AUTHOR