From: Jean-Michel Sarlat Date: Sun, 23 Oct 2011 10:58:27 +0000 (+0200) Subject: Ajout du script epsnorm.pl et mise à jour de la doc des scripts X-Git-Url: https://melusine.eu.org/syracuse/G/git/?p=pst-anamorphosis.git;a=commitdiff_plain;h=3e04f689aaa6a3ccc8d437ebf44b3f7d840916cb Ajout du script epsnorm.pl et mise à jour de la doc des scripts --- diff --git a/opt/Makefile b/opt/Makefile index ee7b533..12dd058 100644 --- a/opt/Makefile +++ b/opt/Makefile @@ -1,8 +1,16 @@ +BIN = epsnorm psftopst PDOC = pst-anamorphosis-doc-scripts $(PDOC).pdf: $(PDOC).tex latex $< && dvips $(PDOC).dvi -o && ps2pdf -dNOSAFER $(PDOC).ps +install: $(BIN) +$(BIN) : % : %.pl + perl -c $< + cp $< $@ + cp $@ ~/bin/$@ + + clean: rm -f *.aux *.log *.dvi *.ps \ No newline at end of file diff --git a/opt/epsnorm b/opt/epsnorm new file mode 100755 index 0000000..f9f34b0 --- /dev/null +++ b/opt/epsnorm @@ -0,0 +1,123 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' + if 0; +use strict; +# ============================================================================== +# epsnorm +# Version 1.0 (Dimanche 23 octobre 2011) Jean-Michel Sarlat +# Ce script fait partie du projet pst-anamorphosis (Gilg, Luque, Sarlat) +# http://melusine.eu.org/syracuse/G/pst-anamorphosis Checkout +# http://melusine.eu.org/syracuse/G/git/?p=pst-anamorphosis.git git +# ============================================================================== + +our $windows_pstoedit = ''; + +our $on_windows = $^O =~ /^MSWin/; +our $GS = $on_windows ? "gswin32c" : "gs"; +our $PS = $on_windows ? $windows_pstoedit : "pstoedit"; + + +# === Acquisition des options de la ligne de commande ------------------------- +$::opt_dimmax = 4; # Dimension maximale : 4 cm par défaut +use Getopt::Long; +GetOptions( + "dimmax=s" +); + +our $debug = 1; + +our $cm = 28.3464567; + +our $Fichier = $ARGV[0]; +-f $Fichier or die "Fichier <$Fichier> introuvable !\n"; + +our ($Nom, $Dir, $Ext) = &FichierNRE($Fichier); + +our @Bbox = (); + +use File::Copy; +# === Première transformation par pstoedit ------------------------------------- +{ + my $f = "$Nom-original.$Ext"; + copy($Fichier, $f); + my @a = ($PS, "-f", "ps", $f, $Fichier); + $debug and print STDERR "Processing by pstoedit (1) ...\n"; + system(@a) == 0 or die "Running pstoedit failed\nCommand :".join(" ",@a)."\n"; + $debug and print STDERR "Ok!\n"; +} +# === Adaptation du fichier ---------------------------------------------------- +{ + my $ps = &FichierListe($Fichier); + my $n = 0; + my $p = 0; + foreach (@$ps) { + $n++; + not($p) and /^\%\%Page: 1 1/ and $p = $n; + /^\%\%BoundingBox\: ([\d\.-]+) ([\d\.-]+) ([\d\.-]+) ([\d\.-]+)/ and + &setBbox($1,$2,$3,$4); + } + my $t = &getTranslate(); + my $s = &getScale(); + $$ps[$p] .= "$::opt_dimmax $cm mul $s $t"; + open PS, "> $Fichier"; print PS join("\n", @$ps); close PS; +} +# === Seconde transformation par pstoedit -------------------------------------- +{ + my $f = "$Nom-temp.$Ext"; + copy($Fichier, $f); + my @a = ($PS, "-f", "ps", "-noclip", $f, $Fichier); + $debug and print STDERR "Processing by pstoedit (2)...\n"; + system(@a) == 0 or die "Running pstoedit failed\nCommand :".join(" ",@a)."\n"; + $debug and print STDERR "Ok!\n"; + unlink $f if -f $f; +} + + +# === Acquisition de la BoundingBox -------------------------------------------- +sub setBbox { + @Bbox = @_; +} +# === Translation -------------------------------------------------------------- +sub getTranslate { + my $tx = "$Bbox[2] $Bbox[0] add 2 div neg"; + my $ty = "$Bbox[3] $Bbox[1] add 2 div neg"; + return "$tx $ty translate"; +} +# === Échelle ------------------------------------------------------------------ +sub getScale { + my $lx = $Bbox[2] - $Bbox[0]; + my $ly = $Bbox[3] - $Bbox[1]; + my $m = $lx; $m = $ly if $ly > $lx; + return "$m div dup scale"; +} + +# === Contenu d'un fichier et éléments du nom ---------------------------------- +# ------------------------------------------------------------------------------ +# Contenu sous forme d'une liste de lignes +sub FichierListe { + my $f = shift; + open(FICH, $f) or die "Le fichier $f est introuvable !\n"; + my @l = ; + close FICH; + chomp @l; + return \@l; +} +# Contenu en un seul élément +sub FichierScalaire { + my $f = shift; + local $/; + open(FICH, $f) or die "Le fichier $f est introuvable !\n"; + my $c = ; + close FICH; + return $c; +} +# Nom, Repertoire et Extension d'un fichier +sub FichierNRE { + my $f = shift; + use File::Basename; + my ($n, $r, $e) = fileparse($f,qw{\..*}); + $e =~ s/^\.//; + return ($n, $r, $e); +} + + + diff --git a/opt/epsnorm.pl b/opt/epsnorm.pl new file mode 100755 index 0000000..f9f34b0 --- /dev/null +++ b/opt/epsnorm.pl @@ -0,0 +1,123 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' && eval 'exec perl -S $0 $argv:q' + if 0; +use strict; +# ============================================================================== +# epsnorm +# Version 1.0 (Dimanche 23 octobre 2011) Jean-Michel Sarlat +# Ce script fait partie du projet pst-anamorphosis (Gilg, Luque, Sarlat) +# http://melusine.eu.org/syracuse/G/pst-anamorphosis Checkout +# http://melusine.eu.org/syracuse/G/git/?p=pst-anamorphosis.git git +# ============================================================================== + +our $windows_pstoedit = ''; + +our $on_windows = $^O =~ /^MSWin/; +our $GS = $on_windows ? "gswin32c" : "gs"; +our $PS = $on_windows ? $windows_pstoedit : "pstoedit"; + + +# === Acquisition des options de la ligne de commande ------------------------- +$::opt_dimmax = 4; # Dimension maximale : 4 cm par défaut +use Getopt::Long; +GetOptions( + "dimmax=s" +); + +our $debug = 1; + +our $cm = 28.3464567; + +our $Fichier = $ARGV[0]; +-f $Fichier or die "Fichier <$Fichier> introuvable !\n"; + +our ($Nom, $Dir, $Ext) = &FichierNRE($Fichier); + +our @Bbox = (); + +use File::Copy; +# === Première transformation par pstoedit ------------------------------------- +{ + my $f = "$Nom-original.$Ext"; + copy($Fichier, $f); + my @a = ($PS, "-f", "ps", $f, $Fichier); + $debug and print STDERR "Processing by pstoedit (1) ...\n"; + system(@a) == 0 or die "Running pstoedit failed\nCommand :".join(" ",@a)."\n"; + $debug and print STDERR "Ok!\n"; +} +# === Adaptation du fichier ---------------------------------------------------- +{ + my $ps = &FichierListe($Fichier); + my $n = 0; + my $p = 0; + foreach (@$ps) { + $n++; + not($p) and /^\%\%Page: 1 1/ and $p = $n; + /^\%\%BoundingBox\: ([\d\.-]+) ([\d\.-]+) ([\d\.-]+) ([\d\.-]+)/ and + &setBbox($1,$2,$3,$4); + } + my $t = &getTranslate(); + my $s = &getScale(); + $$ps[$p] .= "$::opt_dimmax $cm mul $s $t"; + open PS, "> $Fichier"; print PS join("\n", @$ps); close PS; +} +# === Seconde transformation par pstoedit -------------------------------------- +{ + my $f = "$Nom-temp.$Ext"; + copy($Fichier, $f); + my @a = ($PS, "-f", "ps", "-noclip", $f, $Fichier); + $debug and print STDERR "Processing by pstoedit (2)...\n"; + system(@a) == 0 or die "Running pstoedit failed\nCommand :".join(" ",@a)."\n"; + $debug and print STDERR "Ok!\n"; + unlink $f if -f $f; +} + + +# === Acquisition de la BoundingBox -------------------------------------------- +sub setBbox { + @Bbox = @_; +} +# === Translation -------------------------------------------------------------- +sub getTranslate { + my $tx = "$Bbox[2] $Bbox[0] add 2 div neg"; + my $ty = "$Bbox[3] $Bbox[1] add 2 div neg"; + return "$tx $ty translate"; +} +# === Échelle ------------------------------------------------------------------ +sub getScale { + my $lx = $Bbox[2] - $Bbox[0]; + my $ly = $Bbox[3] - $Bbox[1]; + my $m = $lx; $m = $ly if $ly > $lx; + return "$m div dup scale"; +} + +# === Contenu d'un fichier et éléments du nom ---------------------------------- +# ------------------------------------------------------------------------------ +# Contenu sous forme d'une liste de lignes +sub FichierListe { + my $f = shift; + open(FICH, $f) or die "Le fichier $f est introuvable !\n"; + my @l = ; + close FICH; + chomp @l; + return \@l; +} +# Contenu en un seul élément +sub FichierScalaire { + my $f = shift; + local $/; + open(FICH, $f) or die "Le fichier $f est introuvable !\n"; + my $c = ; + close FICH; + return $c; +} +# Nom, Repertoire et Extension d'un fichier +sub FichierNRE { + my $f = shift; + use File::Basename; + my ($n, $r, $e) = fileparse($f,qw{\..*}); + $e =~ s/^\.//; + return ($n, $r, $e); +} + + + diff --git a/opt/pst-anamorphosis-doc-scripts.pdf b/opt/pst-anamorphosis-doc-scripts.pdf index 98162e5..351af73 100644 Binary files a/opt/pst-anamorphosis-doc-scripts.pdf and b/opt/pst-anamorphosis-doc-scripts.pdf differ diff --git a/opt/pst-anamorphosis-doc-scripts.tex b/opt/pst-anamorphosis-doc-scripts.tex index 84be60e..7300e09 100644 --- a/opt/pst-anamorphosis-doc-scripts.tex +++ b/opt/pst-anamorphosis-doc-scripts.tex @@ -199,7 +199,7 @@ la valeur \texttt{n} de votre choix à 4 avec cette option. \begin{center} \begin{pspicture}(-2,-2)(2,2) -\input{../exemplespst/tiger.pst} +\input{../pst/tiger.pst} \end{pspicture}\\ \verb|\input{tiger.pst}| \end{center} @@ -230,4 +230,52 @@ de ne pas être harmonieux... \end{itemize} +\section{epsnorm} + +Ce script transforme un fichier \textsf{EPS} vers un fichier au format +\textit{Flattened PostScript} et en modifiant la \textsf{BoundingBox} de +façon à ce qu'elle soit centrée sur l'origine \((0,0)\), sa dimension +maximale étant fixée (procédure décrite dans la documentation de +\textsf{pst-anamorphosis}: \emph{normalisation d'un fichier EPS}). + +Cette transformation permet d'obtenir un fichier directement exploitable +par la macro \verb|\psanamorphosis|, ce qui explique aussi que l'option +\verb|-noclip| soit passée à \textsf{pstoedit} pour éviter tout +\emph{clipping}. + +\subsection{Usage} +\begin{gbar}[OrangePale] +\begin{boxedverbatim} +$> epsnorm.pl [-dimmax n] monfichier.{eps|ps} +\end{boxedverbatim} +\end{gbar}%$ + +Le fichier est alors transformé, le contenu initial étant +sauvegardé dans \verb+monfichier-original.{eps|ps}+. + +\subsection{Option} + +\begin{description} +\item[\texttt{-dimmax n}] La transformation effectuée par le script +centre l'image sur \((0,0)\) et la met à l'échelle telle que la plus +grande des deux dimensions soit 4 cm par défaut. Vous pouvez substituer +la valeur \texttt{n} de votre choix à 4 avec cette option. +\end{description} + +\subsection{Notes} + +\begin{itemize} + +\item Pour les utilisateurs de \textsf{windows}: il faut, au préalable, +éditer le script et remplacer la chaîne \texttt{} (vers la ligne 12) par le chemin complet d'accès à +\textsf{pstoedit} sur votre sytème. Pour \textsf{Linux} ou +\textsf{MacOS}, l'hypothèse est faite que le programme est accessible +via la variable \texttt{PATH}. + +\item Le fichier à traiter ne doit comporter qu'une seule page, le +résultat peut être surprenant dans le cas contraire... + +\end{itemize} + \end{document} \ No newline at end of file