man XFig () - A parser for XFig files


XFig - A parser for XFig files


 use XFig;

 # Generate a parser

 $fig = new XFig;

 # Parse a Fig file

 die "Can't read file $figname" if ($fig->{'object'} < 0);

 # Get header information

 $fig->Version ()
 $fig->Orientation ()
 $fig->Justification ()
 $fig->Units ()
 $fig->Papersize ()
 $fig->Magnification ()
 $fig->MultiplePage ()
 $fig->Transparent ()
 $fig->Resolution ()
 $fig->CoordSystem ()

 # Create a new Fig element and add values to it

 $line = new XFig ('polyline');
 $line->{'subtype'} = 1;  # line
 $line->{'points'} = [ [0, 0], [1, 3] ];
 $line->{'comment'} = [ 'This is just a comment', 'that is continued on this line ];

 # Add an element to a Fig parsed file or compound element

 $fig->add ($line);

 # Loop through all elements in the parsed file and check their types

 for $element ($fig->eachPrimitive()) {
   print "Primitive\n" if $element->isPrimitive ();
   print "Color\n"     if $element->isColor ();
   print "Arc\n"       if $element->isArc ();
   print "Ellipse\n"   if $element->isEllipse ();
   print "Polyline\n"  if $element->isPolyline ();
   print "Spline\n"    if $element->isSpline ();
   print "Text\n"      if $element->isText ();
   print "Compound\n"  if $element->isCompound ();
   print "Closed\n"    if $element->isClosed ();

 # Write to an XFig file

 $fig->writefile ($figname);


The XFig module parses XFig files and allows access to its elements. It also allows the creation of new Fig elements, the addtion of elements to the parsed file object and the dumping to a Fig file.

Fig elements composing a XFig file are represent by hashes, whose keys mimic very closely the definitions given in the FORMAT file distributed with XFig. For instance, a polyline element is a hash with the following keys:

 'subtype', 'linestyle', 'thickness', 'pencolor', 'fillcolor',
 'depth', 'penstyle', 'areafill', 'styleval', 'joinstyle',
 'capstyle', 'radius', 'forwardarrow', 'backwardarrow', 'points'

$element->{points} is always a reference to a array of coordinates. Each coordinate is a reference to an array of length 2, containing the horizontal and vertical coordinates of the point.


 xfig(1), the FORMAT3.2 file.


Copyright (C) 1998 Marcel Rohner. This module is released under the terms of the GNU GPL.

This manual page was written by Rafael Laboissiere <>.