My first attempt(command line options not yet implemented). Please tell me if you see something that can be improved.
Code:
#!/usr/bin/perl
#Default values
$startRegex = ".*begin\{tikzpicture\}.*";
$endRegex = ".*end\{tikzpicture\}.*";
$shift_x = 0;
$shift_y = 1000;
$scale_x = 1;
$scale_y = -1;
$precision = 1;
#Insert code to accept command line arguments
$process = 0;
while(<STDIN>)
{
if($_ =~ $endRegex) { $process=0 };
if($process)
{
my @lines = split(';', $_);
foreach my $line (@lines)
{
my $newline = '';
while($line =~ m/\((-{0,1}\d*\.{0,1}\d+),(-{0,1}\d*\.{0,1}\d+)\)/)
{
$line = $';
my $x = int(($1*$scale_x+$shift_x)/$precision)*$precision;
my $y = int(($2*$scale_y+$shift_y)/$precision)*$precision;
$newline .= "$`($x,$y)";
}
$newline .= "$line;";
print "$newline\n";
}
}
else
{
print;
}
if($_ =~ $startRegex) { $process=1 };
}
Usage:
./ink2TikZpost.pl <test.tex >newTest.tex
Test input:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1, inner sep=0pt, outer sep=0pt]
\path[draw=black,miter limit=4.00,line width=2.835pt,rounded corners=0.0000cm] (100.0000,115.2193) rectangle (560.0000,483.7908);\path[draw=black,line join=miter,line cap=butt,miter limit=4.00,line width=2.835pt] (237.1429,303.7908) -- (468.5714,623.7908);\path[draw=black,miter limit=4.00,line width=2.835pt] (317.1429,696.6479)arc(0.000:180.000:90.000)arc(-180.000:0.000:90.000) -- cycle;\path[draw=black,miter limit=4.00,line width=2.835pt] (622.8571,789.5051)arc(0.000:180.000:100.000000 and 42.857)arc(-180.000:0.000:100.000000 and 42.857) -- cycle;\path[draw=black,miter limit=4.00,line width=2.835pt] (331.4286,939.5051)arc(0.000:100.000:77.142860 and 35.714);
\end{tikzpicture}
\end{document}
Output:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\begin{document}
\begin{tikzpicture}[y=0.80pt,x=0.80pt,yscale=-1, inner sep=0pt, outer sep=0pt]
\path[draw=black,miter limit=4.00,line width=2.835pt,rounded corners=0.0000cm] (100,884) rectangle (560,516);
\path[draw=black,line join=miter,line cap=butt,miter limit=4.00,line width=2.835pt] (237,696) -- (468,376);
\path[draw=black,miter limit=4.00,line width=2.835pt] (317,303)arc(0.000:180.000:90.000)arc(-180.000:0.000:90.000) -- cycle;
\path[draw=black,miter limit=4.00,line width=2.835pt] (622,210)arc(0.000:180.000:100.000000 and 42.857)arc(-180.000:0.000:100.000000 and 42.857) -- cycle;
\path[draw=black,miter limit=4.00,line width=2.835pt] (331,60)arc(0.000:100.000:77.142860 and 35.714);
;
\end{tikzpicture}
\end{document}
Command line arguments can not yet be given. Extra line with ; wronly added in output. Angles is not rounded.
coord_transformed.append("%.4fcm" % ((x-self.x_o)*self.x_scale))instead ofcoord_transformed.append("%.4f" % x). – Alexander Sep 3 '12 at 9:23