command line: how to get correct y coordinate and height of doc (not drawing) of an existing svg?

Asked by knb

Scripting inkscape

Using the command line, how can I get the correct y-coordinate and height of doc (not drawing) of an existing svg?

I fetch the coordinates of all paths in the image with

inkscape --without-gui --query-all $svgfile | grep path
(1)

Then I do something with selected paths in $svgfile.

Then I export a small area containing the path I am interested in

inkscape --file=p072.svg --export-dpi=300 --without-gui --export-png="tmp/p072.svg.path104.png" --export-area=495,7325:694,755:534,5275:718,54

The y coordinate is I get from command (1) is wrong. The origin is false. i have to correct it with the document height. How can I get it from the command line? I am not interested in the --query-height option. It gets the height of the drawing, not the document.

See the kludge I have found for my problem:
sub get_all_path_coords {
 my ($svgfile ) = @_;
 #The --query-* command line parameters now return the true SVG bounding box of the object
 #instead of the Inkscape coordinate system bbox (with inverted Y axis).
 #The new behavior makes more sense for scripting use of Inkscape
 my @lines = `inkscape --without-gui -S $svgfile | grep path`;
 # expample:
 #path730,604.2825,636.2775,43.395,22.13375
 my %pathcoords = ();
 my $dx = 2.3;
 my $dy = 1.65;
 foreach my $p (@lines){
  chomp $p;
  my @c = split /,/, $p; # decimal sep = comma
  my $path = shift @c;
  my @cdot = map { $_} @c;
  $cdot[0] = $c[0] + $dx;
  $cdot[2] = $c[2] - 2 * $dx;
  $cdot[1] = 1030.5 - $c[1] - $dy;
  $cdot[3] = $c[3] + $dy;

  $pathcoords{$path} = join ":", ($c[0], $c[1], $c[0]+$c[2], $c[1] + $c[3]);
 }
 return \%pathcoords;
}

I have found by working with the gui that the document height is 1030.5 , --query--height gives 835 or so. then I subtract a few pixels for some reason .
There must be a better way to get the correct y coordinate that I can pass to --export-area

Question information

Language:
English Edit question
Status:
Solved
For:
Inkscape Edit question
Assignee:
No assignee Edit question
Solved by:
knb
Solved:
Last query:
Last reply:
Revision history for this message
pbhj (pbhj) said :
#1

Could you attack it by including a known object in the file with the dimensions of the document? Just a thought.

Revision history for this message
knb (knb) said :
#2

pghj: yes I thought about that but it is too complicated.

Answering my own question:

I think in my perl program I will use the following xpath expression

//@height

on the shell you could do:

echo "xpath //@height" | xmllint --noent --shell "../p054.svg" | perl -nle "/(\d+\.\d+)/ && print \$1"
1052.5

then this number is used in the shell cmd that calls inkscape