head	1.25;
access;
symbols;
locks
	rohner:1.25; strict;
comment	@# @;


1.25
date	2003.01.24.20.00.20;	author rohner;	state Exp;
branches;
next	1.24;

1.24
date	98.09.02.10.22.03;	author rohner;	state Exp;
branches;
next	1.23;

1.23
date	98.06.07.13.14.23;	author marcel;	state Exp;
branches;
next	1.22;

1.22
date	98.06.04.18.40.19;	author marcel;	state Exp;
branches;
next	1.21;

1.21
date	98.06.03.19.19.49;	author marcel;	state Exp;
branches;
next	1.20;

1.20
date	98.06.02.19.09.35;	author marcel;	state Exp;
branches;
next	1.19;

1.19
date	98.05.27.17.30.59;	author marcel;	state Exp;
branches;
next	1.18;

1.18
date	98.05.26.18.47.47;	author marcel;	state Exp;
branches;
next	1.17;

1.17
date	98.05.25.18.54.37;	author marcel;	state Exp;
branches;
next	1.16;

1.16
date	98.05.24.14.46.35;	author marcel;	state Exp;
branches;
next	1.15;

1.15
date	98.05.24.12.25.49;	author marcel;	state Exp;
branches;
next	1.14;

1.14
date	98.05.23.18.22.11;	author marcel;	state Exp;
branches;
next	1.13;

1.13
date	98.05.23.17.19.57;	author marcel;	state Exp;
branches;
next	1.12;

1.12
date	98.05.23.09.24.58;	author marcel;	state Exp;
branches;
next	1.11;

1.11
date	98.05.21.17.58.03;	author marcel;	state Exp;
branches;
next	1.10;

1.10
date	98.05.20.17.27.33;	author marcel;	state Exp;
branches;
next	1.9;

1.9
date	98.05.18.17.38.18;	author marcel;	state Exp;
branches;
next	1.8;

1.8
date	98.05.18.17.24.58;	author marcel;	state Exp;
branches;
next	1.7;

1.7
date	98.05.17.12.58.53;	author marcel;	state Exp;
branches;
next	1.6;

1.6
date	98.05.17.12.43.29;	author marcel;	state Exp;
branches;
next	1.5;

1.5
date	98.05.17.12.06.52;	author marcel;	state Exp;
branches;
next	1.4;

1.4
date	98.05.17.09.26.23;	author marcel;	state Exp;
branches;
next	1.3;

1.3
date	98.05.16.12.11.22;	author marcel;	state Exp;
branches;
next	1.2;

1.2
date	98.05.16.10.05.07;	author marcel;	state Exp;
branches;
next	1.1;

1.1
date	98.05.15.19.59.22;	author marcel;	state Exp;
branches;
next	;


desc
@fig2sty converter, initial release
@


1.25
log
@scaling for version > 3.1 (R. Laboissiere)
@
text
@#!/usr/local/bin/perl
# fig2sty
# TeX Layout Generator
# Author: Marcel Rohner
# Date  : 16.5.98
# $Id: fig2sty,v 1.24 1998/09/02 10:22:03 rohner Exp rohner $

# Copyright (C) 1998  Marcel Rohner
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

=head1 NAME

fig2sty - LaTeX Layout Generator

=head1 SYNOPSIS

  fig2sty [-debug] [-baselineskip=..] [-fontsize=..]
          [-reference=(grid|upper|lower)] [-offset=..]
          [-figversion=..] [-nopipe] [-fig2dev=...] input-file

=item C<-debug>

Show base lines in background picture

=item C<-baselineskip>, C<-fontsize>, C<-reference>, C<-offset>

Default values. May be overriden by tags.

=item C<-figversion>

XFig format version which will be fed to C<fig2dev> to generate
background picture

=item C<-nopipe>

If your version of C<fig2dev> does not accept piped input use
this switch

=item C<-fig2dev>

If you have installed several versions of C<fig2dev> you
can specify which version to use

=head1 DESCRIPTION

fig2sty allows you to generate fancy layouts with LaTeX.
The basic idea is to draw layout definitions interactively
with XFig and transform this definition to a LaTeX style
file. You can then use LaTeX to typeset your text into
arbitrarily shaped polygons (frames) within the layout.

You can even add any graphical elements in the layout
definition which will appear in the LaTeX output as
a background picture.

=head1 How to draw the layout definition.

Any closed polygon or box may be a frame. But it must not
have an area fill such that your coloured background
boxes will not interfere with your frames. Tags are
associated to each frame. A tag is simply a text
C<key=value> marked as I<special> and positioned within
the I<bounding box> of the respective frame.
If there are any ambiguities, simply put your frame and its
tags into a compound. 

Several I<key> words are interpreted by C<fig2sty>:

=item C<type>

This tag is compulsory; a frame will not be detected as such
if you don't provide a type tag. You can have several
type tags in your layout, but you may as well have several
frames associated with the same type tag. Text will then
flow between all the frames of common type. The type tag
must neither contain numerals nor any special characters,
just plain alpha characters. If you care
about the ordering of the text flow you can use the
following tag:

=item C<n>

Text will flow between frames of common type in increasing
size of C<n>

=item C<baselineskip>

Text will be typeset in a fixed line grid. Baselineskip 
provides the distance between neighbouring lines. All
frames of a certain type share the same baselineskip. If you
provide several of them, the tag within the frame of lowest
C<n> will be used. If you have rectangular frames of equal widths
only you may set C<baselineskip=any>. Text will then by set in
ordinary horizontal mode. For any other kind of frame or
multiple rectangulars with differing width C<baselineskip=any>
is forbidden.

=item C<reference>

Lines of all frames will be aligned if you assign the
value C<grid> to this tag. Other possibilities are
C<upper>(C<lower>) which will align to the upper(lower) boundary
of your frame. Each frame has its private reference.

=item C<offset>

You can shift your base lines by an arbitrary amount by
providing the C<offset> tag. Each frame has its private
offset.

=item C<fontsize>

Used only as minimal distance from top baseline to
the upper boundary of the frame.

=item C<head>

LaTeX code to be prepended to the text

=item C<tail>

LaTeX code to be appended to the text

Default values to the tags are C<baselineskip=12>,
C<reference=grid>, C<offset=0>, but you can overwrite
these defaults by the command line options. All dimensions
are given in TeX pt.

=head1 How the baselines are chosen

First of all, you can't have lines split horizontally.
Lines will always go from the leftmost intersection of the
base line with the frame to the rightmost one. There is
not really any technical reason for this (except for
laziness, one of the virtues...). If you find this to be
a major restriction, please let me know.

The baselines are chosen such that the distance to the
reference point is a multiple of C<baselineskip>. C<fig2sty>
will ensure that no textual element of size C<fontsize> will
overlap the given frame. This is indeed the only use of the
C<fontsize> tag. C<fontsize=baselineskip> is usually a good
choice except when using small letters at wide vertical spacing.
The choice of the reference point is based on the C<reference>
tag. The value C<grid> means that a global reference point (the
upper-left corner of the layout) will be used. This allows text
in different frames to be aligned. C<reference=upper> means that
text will touch the upper boundary of your frame. The analogous
functionality is provided by the C<lower> value.

=head1 How to use in your LaTeX document.

If you have two frames of type 'C<abstract>' and 'C<text>' within
the layout C<fancylayout> you type:

\documentclass{article}
\usepackage{figtosty}
\usepackage{fancylayout}

	\begin{document}
	...
	\begin{fancylayout}
	\begin{figframe}{abstract}
	blah blah
	\end{figframe}

	\begin{figframe}{text}
	blah blah
	\end{figframe}
	\end{fancylayout}

	...
	\end{document}>

=head1 INSTALLATION

You will need XFig.pm in your Perl Library path
, figtosty.sty in your LaTeX search path and
fig2sty in your binary search path.

=head1 KNOWN BUGS

list environments do not respect frame boundaries

some mysterious bug with splines

doesn't work with \sloppy

=head1 AUTHOR

M. Rohner, rohner@@ife.ee.ethz.ch

=head1 CONTRIBUTORS

Thanks to Tobias Oetiker for his helpful comments

=head1 SEE ALSO

XFig.pm

=cut

use XFig;
use strict;
use Getopt::Long;

my $debug = 0;
my $defbaselineskip = 12;
my $deffontsize     = 12;
my $defreference    = 'grid';
my $defoffset       = 0;
my $figversion      = '';
my $nopipe          = 0;
my $fig2dev         = 'fig2dev';

&GetOptions("debug" => \$debug,
            "baselineskip=s" => \$defbaselineskip,
            "fontsize=i"     => \$deffontsize,
            "reference=s"    => \$defreference,
            "offset=i"       => \$defoffset,
            "figversion=s"   => \$figversion,
            "nopipe"         => \$nopipe,
            "fig2dev=s"      => \$fig2dev);

die "Usage: fig2sty layout.fig" if (@@ARGV != 1);

my $figname    = $ARGV[0];

$figname =~ m/^(.*)\.(.*?)$/;
my($jobname, $extension) = ($1, $2);
die "Unknown extension $extension" 
  if ($jobname && ($extension !~ /^fig$/));
my $texname    = "$jobname.sty";
my $background = "${jobname}back.ps";

if ($debug) {
  print STDERR "jobname    : $jobname\n";
  print STDERR "texname    : $texname\n";
  print STDERR "background : $background\n";
}

open TEX, ">$texname" || die "Can't open $texname";
my $fig = new XFig;
$fig->parsefile($figname);
die "Can't read file $figname" if ($fig->{'object'} < 0);

# insert marker to define zero point
my $marker = new XFig ('polyline');
$marker->{'thickness'} = 0;
$marker->{'points'} = [ [0,1], [0,0], [1,0] ];
$fig->add($marker);
$fig->{'version'} = $figversion if ($figversion);

# Process FIG input
my @@frames     = getFrames($fig);     # set of all frames
my %frameset   = sortFrames(@@frames); # frame hash indexed by frame type
# There are basically two types of tags
#  a) tags private to a tag
#  b) tags common to all frames of a certain type
my %commontags = ();
foreach (keys %frameset) {
  $commontags{$_} = {getFrameTags(@@{$frameset{$_}})};
  if ( (@@{$frameset{$_}} == 1) &&     # check for 'simple' frames
       ($frameset{$_}->[0]->{'subtype'} == 2) &&
       ($commontags{$_}->{'baselineskip'} =~ /^(any)?$/i) ) {
    # simple boxes function like parboxes. 
    # They have no fixed grid
    $commontags{$_}->{'simple'} = 1;
    my $width = $frameset{$_}->[0]->{'maxx'} - $frameset{$_}->[0]->{'minx'};
    my $frame;
    foreach $frame (@@{$frameset{$_}}) {
      die "baselineskip=any  requires rectangular frames of equal size in type=$_" 
        unless ( ($frameset{$_}->[0]->{'subtype'} == 2) ||
                 ($width == $frame->{'maxx'} - $frame->{'minx'}) );
      $frame->{'simple'} = 1;
    }
  }
}

# TeX output
my %vinfo = ();    # vertical info
my @@hinfo = ();    # horizontal info ([indentation, linewidth] ...)
my $baselineskip;
my $figscale;      # FIG version dependent scaling factor
$figscale = ($fig->{'version'} > '3.1')?0.95:1.0;

# Write style header
print TEX <<"EOTEX";
% This style file has been automatically generated by fig2sty
% Input FIG : $figname (Version $fig->{version})
% fig2sty is copyrighted by (c) M. Rohner
\\newenvironment\{$jobname\}\{
EOTEX

# leftx:  x of leftpost point of frame
# topy :  y of topmost  ...
# vsize:  vertical size of frame
# hinfo:  line size and indentation
my ($leftx, $topy, $vsize, $hinfo, $n);
my %topyset  = ();
my %vsizeset = ();
my %leftxset = ();
# Write paragraph info
foreach (keys %frameset) {
  print TEX "\\newbox\\${_}box\n";

  ($leftx, $topy, $vsize, $hinfo) = computeBaselines($frameset{$_}, $commontags{$_});
  $topyset{$_}  = $topy;
  $vsizeset{$_} = $vsize;
  $leftxset{$_} = $leftx;
  $baselineskip = $commontags{$_}->{'baselineskip'};
 
  print TEX "\\long\\outer\\def\\fts${_}\{% frame command\n";

  if ($commontags{$_}->{'simple'}) {   # simple frame

    print TEX <<"EOTEX"
\\global\\setbox\\${_}box=\\vbox\\bgroup%
%  \\begin\{minipage\}\{$hinfo->[0]pt\}
%   \\parbox\{$hinfo->[0]pt\}\\bgroup
  \\hsize=$hinfo->[0]pt
  \\setlength\{\\textwidth\}\{$hinfo->[0]pt\}
EOTEX

  } else {                             # complex frame -> parshape
    $n = scalar(@@$hinfo);

    print TEX <<"EOTEX";
\\global\\setbox\\${_}box=\\vbox\\bgroup%
%\\tolerance 9999\\emergencystretch 3em% sloppy
\\baselineskip=${baselineskip}pt
\\rigidize
\\simulpar
\\parshape=$n
EOTEX

    my $il;
    foreach $il (@@$hinfo) {
      print TEX " $il->[0]pt $il->[1]pt";
    }
  }
  print TEX "\n$commontags{$_}->{'head'}" 
    if ($commontags{$_}->{'head'});
  print TEX "\}\n",
            "\\long\\outer\\def\\ftsend${_}\{\\endgraf\n";
  print TEX "$commontags{$_}->{'tail'}\}\n" 
    if ($commontags{$_}->{'tail'});
#  print TEX "\\end\{minipage\}\n"
#  print TEX "\\egroup\n"
#    if ($commontags{$_}->{'simple'});
  print TEX "\}\n";
}
print TEX "\}\n";

# Placement of frames
print TEX "\{\\setbox1=\\vbox\{\\noindent",
          "\\includegraphics\[scale=$figscale\]\{$background\}\}\n",
          "\\dimendef\\w=0 \\w=\\wd1\n",
          "\\dimendef\\h=0 \\h=\\ht1\n",
          "\\splittopskip=0pt\n",
          "\\parindent=0pt\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n",
          "\\vbox to0pt\{\\unvbox1\\vss\}\n";

foreach (keys %frameset) {
  $topy = $topyset{$_};
  $vsize = $vsizeset{$_};
  $leftx = $leftxset{$_};
  while (@@$topy) {
    print TEX '\vbox to0pt{\kern', shift @@$topy, 'pt',
              '\hskip', shift @@$leftx, 'pt',
              "\\vsplit\\${_}box to", shift @@$vsize, 'pt\vss}', "\n";
  }
}
# Check wether text fits into frames
print TEX '}\unvbox0', "\n";  
foreach (keys %frameset) {
  print TEX "\\ifvoid\\${_}box \\else",
            "\\message\{fig2sty: Frame '${_}' overflow\}\\fi\n";
}
print TEX "\\vskip\\h\}\n";
close TEX;

# Generate output picture
if ($nopipe) {
  # some fig2dev versions don't accept pipes
  my $tmpfile;
  $tmpfile = "/tmp/fig2sty$$.tmp";
  $fig->writefile(">$tmpfile");
  `$fig2dev -Lps -e -p dummy $tmpfile > $background`;
  unlink $tmpfile;
} else {
  $fig->writefile("|$fig2dev -Lps -e -p dummy > $background");
  die "fig2dev failed" if $?;
};

# ------------------------------------------------------------------------------
# Subroutines
#
# getFrames
# Traverse Fig Tree
# Tags are removed
# line thickness of the frames is set to 0
# Input: fig tree
# Output: @@frames = (poly, ...)
sub getFrames {
  my $fig = shift;
  my @@frames = ();
  my @@polylist = ();
  my @@taglist  = ();

  # Find frames and tags within compound
  # Note: frames and tags must be within the same compound
  my $element;
  for $element ($fig->eachPrimitive()) {
    # element is poly
    do {
      # find bounding box
      my($minx, $maxx, $miny, $maxy) = (1e39, -1e39, 1e39, -1e39);
      foreach (@@{$element->{points}}) {
        $minx = $_->[0] if ($_->[0] < $minx);
        $maxx = $_->[0] if ($_->[0] > $maxx);
        $miny = $_->[1] if ($_->[1] < $miny);
        $maxy = $_->[1] if ($_->[1] > $maxy);
      }
      $element->{'minx'} = $minx;
      $element->{'maxx'} = $maxx;
      $element->{'miny'} = $miny;
      $element->{'maxy'} = $maxy;
      push @@polylist, $element;
    } if ($element->isPolyline() && 
          $element->isClosed() &&
          ($element->{'areafill'} == -1));

    # element is tag
    do {
      my($key, $value) = split '=', $element->{'text'};
      $element->{'key'} = $key;
      $element->{'value'} = $value;
      push @@taglist, $element;
#        if ($key =~ /(baselineskip|offset|reference|n)/);
    } if ($element->isText() &&
         ($element->{'fontflags'} & 2));
  }

  # assign tags to frames
  # Note: a tag is assigned to one frame only
  #       if two frames overlap, all tags will be assigned
  #          to one of them only
  my $tag;
  TAG: foreach $tag (@@taglist) {
    my ($key, $value) = @@$tag{'key', 'value'};
    my $poly;
    foreach $poly (@@polylist) {
      do {
        if ($debug) {
          print STDERR "assigned tag $key=$value at ",
                       "($tag->{'x'}, $tag->{'y'})\n";
        }
        $poly->{$key} = $value;
        $poly->{'isFrame'} = 1 if ($key =~ /type/);
        $tag->delete();             # delete tag from layout
        $poly->{'thickness'} = 0.0; # make frame invisible
        next TAG;
      } if ($tag->{'x'} > $poly->{'minx'} &&
            $tag->{'x'} < $poly->{'maxx'} &&
            $tag->{'y'} > $poly->{'miny'} &&
            $tag->{'y'} < $poly->{'maxy'});
    }
  }

  @@frames = grep { $_->{'isFrame'} } @@polylist;

  # recursion into compounds
  for $element ($fig->eachCompound()) {
    push @@frames, getFrames($element);
  }    

  return @@frames;
}

# sortFrames
# Sort by frametype and increasing n
sub sortFrames {
  my @@frames = @@_;
  my %frameset = ();
  
  # split into frame types
  foreach (@@frames) {
    push @@{$frameset{$_->{'type'}}}, $_;
  }

  # sort in increasing n
  foreach (keys %frameset) {
    @@{$frameset{$_}} = sort { $a->{'n'} <=> $b->{'n'} }
       @@{$frameset{$_}};
  }

  return %frameset;
}

# Find common tags
sub getFrameTags {
  my @@frames = @@_;
  my %tags = ();

  # default values
  $tags{'baselineskip'} = $defbaselineskip;
  $tags{'fontsize'}     = $deffontsize || $defbaselineskip;

  # user values
  my ($frame, $tagname);
  foreach $frame (reverse @@frames) {
    foreach $tagname ('baselineskip', 'fontsize', 'head', 'tail') {
      $tags{$tagname} = $frame->{$tagname}
        if ($frame->{$tagname}); 
    }
  }

  return %tags;
}

sub computeBaselines {
  my ($refframes, $reftags) = @@_;
  my $baselineskip = $reftags->{'baselineskip'};
  my $fontsize     = $reftags->{'fontsize'};

  my(@@hinfo, @@leftx, @@topy, @@vsize);
  my $frame;

  if ($reftags->{'simple'}) { # simple box
    foreach $frame (@@$refframes) {
      my @@x = sort { $a->[0] <=> $b->[0] } @@{$frame->{'points'}};
      my @@y = sort { $a->[1] <=> $b->[1] } @@{$frame->{'points'}};
      my $minx = $x[0]->[0];
      my $miny = $y[0]->[1];
      my $height = $y[3]->[1] - $y[0]->[1];
      my $width = $x[3]->[0] - $x[0]->[0];
      push @@leftx, fig2pt($minx);
      push @@topy,  fig2pt($miny);
      push @@vsize, fig2pt($height);
      push @@hinfo, fig2pt($width);
    }
    return (\@@leftx, \@@topy, \@@vsize, \@@hinfo);
  }

  my($refpoint, $nolines, $x1, $x2, $firstline, $liney, $offset, $reference);

  foreach $frame (@@$refframes) {
    $offset       = $frame->{'offset'} || $reftags->{'offset'};
    $reference    = $frame->{'reference'} || $reftags->{'reference'};
    $refpoint = $frame->{'miny'} if ($reference =~ /^u/i);
    $refpoint = $frame->{'maxy'} if ($reference =~ /^l/i);
    $refpoint += pt2fig($offset);
    if ($refpoint < $frame->{'miny'} ) { # round up
      $firstline = int (fig2pt($frame->{'miny'} - $refpoint) / $baselineskip + 1)
                    * $baselineskip;
    } else {
      $firstline = - int (fig2pt($refpoint - $frame->{'miny'}) / $baselineskip )
                    * $baselineskip;
    }
    $firstline += fig2pt($refpoint);
    $firstline += $baselineskip
       if ($firstline < (fig2pt($frame->{'miny'}) + $fontsize));
    $liney = pt2fig($firstline);

    $nolines = 0;
    while ( ($x1, $x2) = intersect($liney, @@{$frame->{'points'}})) {
      $nolines++;
      push @@hinfo, [fig2pt($x1), fig2pt($x2-$x1)];
      if ($debug) {
        my $debugline;
        $debugline = new XFig ('Polyline');
        $debugline->{'subtype'} = 1;  # line
        $debugline->{'points'} = [ [$x1, int($liney)], [$x2, int($liney)] ];
        $fig->add($debugline);
      }
      $liney += pt2fig($baselineskip);
    }
    push @@topy, $firstline - $fontsize;
    push @@leftx, fig2pt($x1);
    push @@vsize, $nolines*$baselineskip;
  } 

  return (\@@leftx, \@@topy, \@@vsize, \@@hinfo);
}

sub intersect {
  my ($firstline, @@points) = @@_;
  my $minx = 1e39;
  my $maxx = -1e39;
  my $isectfound = 0;
 
  my($p1, $p2, $x);
  $p2 = shift @@points; 
  while (@@points) {
    $p1 = $p2;
    $p2 = shift @@points;
    next if ( ($firstline - $p1->[1])*($firstline - $p2->[1]) > 0 ||
              ($p2->[1] == $p1->[1]));
    $x = $p1->[0] + ($p2->[0] - $p1->[0]) / ($p2->[1] - $p1->[1]) *
           ($firstline - $p1->[1]);
    $minx = $x if ($x < $minx);
    $maxx = $x if ($x > $maxx);
    $isectfound = 1;
  } 
  if ($isectfound) {
    return (int($minx), int($maxx));
  } else {
    return ();
  }
}

# ------------------------------------------------------------
# Conversion pt <-> fig
sub pt2fig {
  my $pts = shift;
  return $pts * $fig->{'resolution'} / 72.27;
}

sub fig2pt {
  my $figs = shift;
  return $figs * 72.27 / $fig->{'resolution'};
}
@


1.24
log
@fig2dev option
background picture renamed
documentation enhanced
multiple rectangular frames allowed
splittopskip set
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.23 1998/06/07 13:14:23 marcel Exp $
d105 2
a106 2
C<n> will be used. If you have one rectangular frame only
you may set C<baselineskip=any>. Text will then by set in
d169 1
a169 1
C<\documentclass{article}
d196 5
a200 1
...
d208 1
a208 1
Thanks to Tobias Oetiker for his assistance
d298 1
a298 1
$figscale = ($fig->{'version'} == '3.1')?0.95:1.0;
@


1.23
log
@head and tail support
comments/documentation added
variable renamed (ulx->leftx, uly->topy)
more debug output
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.22 1998/06/04 18:40:19 marcel Exp marcel $
d32 1
a32 1
          [-figversion=..] [-nopipe] input-file
d52 5
d88 3
a90 1
flow between all the frames of common type. If you care
d107 3
a109 1
ordinary horizontal mode.
d166 1
a166 1
If you have to frame types C<abstract> and C<text> within
d191 2
a192 1
and figtosty.sty in your LaTeX search path
d194 4
d223 1
d231 2
a232 1
            "nopipe"         => \$nopipe);
d243 1
a243 1
my $background = "$jobname.ps";
d278 8
a285 1
    $frameset{$_}->[0]->{'simple'} = 1;
d309 1
a309 1
my %topyset = ();
d311 1
d317 1
a317 1
  $topyset{$_} = $topy;
d319 1
d325 9
a333 3
    print TEX "\\global\\setbox\\${_}box=\\vbox to ${vsize}pt\\bgroup%\n",
              "\\hsize=", $hinfo+$leftx, "pt\n",
              "\\leftskip=${leftx}pt\n";
d336 1
d345 1
d354 1
a354 1
            "\\long\\outer\\def\\ftsend${_}\{\n";
d357 3
d369 1
d376 5
a380 7
  if ($commontags{$_}->{'simple'}) {
    print TEX '\vbox to0pt{\kern', $topy, "pt\\box\\${_}box\\vss\}\n";
  } else {
    while (@@$topy) {
      print TEX '\vbox to0pt{\kern', shift @@$topy, "pt\\vsplit\\${_}box to",
                shift @@$vsize, 'pt\vss}', "\n";
    }
d398 1
a398 1
  `fig2dev -Lps -e -p dummy $tmpfile > $background`;
d401 1
a401 1
  $fig->writefile("|fig2dev -Lps -e -p dummy > $background");
d536 3
d540 13
a552 7
    my @@x = sort { $a->[0] <=> $b->[0] } @@{$refframes->[0]->{'points'}};
    my @@y = sort { $a->[1] <=> $b->[1] } @@{$refframes->[0]->{'points'}};
    my $minx = $x[0]->[0];
    my $miny = $y[0]->[1];
    my $height = $y[3]->[1] - $y[0]->[1];
    my $width = $x[3]->[0] - $x[0]->[0];
    return (fig2pt($minx), fig2pt($miny), fig2pt($height), fig2pt($width));
d555 1
a555 2
  my($refpoint, $nolines, @@hinfo, @@leftx, @@topy, 
     @@vsize, $x1, $x2, $firstline, $liney, $offset, $reference);
a556 1
  my $frame;
@


1.22
log
@several errors concerning 'simple frames' corrected
 - horizontal indentation
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.21 1998/06/03 19:19:49 marcel Exp marcel $
d120 8
d221 1
d223 3
a225 1
my $jobname    = $1 || $ARGV[0];
d229 6
d247 6
a252 2
my @@frames = getFrames($fig);
my %frameset = sortFrames(@@frames);
d256 1
a256 1
  if ( (@@{$frameset{$_}} == 1) &&
d259 2
d267 2
a268 2
my %vinfo = ();
my @@hinfo = ();
d270 1
a270 1
my $figscale;
d273 1
d281 6
a286 2
my ($ulx, $uly, $vsize, $hinfo, $n);
my %ulyset = ();
d288 1
d292 2
a293 2
  ($ulx, $uly, $vsize, $hinfo) = computeBaselines($frameset{$_}, $commontags{$_});
  $ulyset{$_} = $uly;
d297 1
a297 2
  print TEX "\\long\\outer\\def\\b${_}\{% frame command\n";
  print TEX "\\global\\setbox\\${_}box=\\vbox\\bgroup%\n";
d299 5
a303 5
  if ($commontags{$_}->{'simple'}) {
    print TEX "\\hsize=", $hinfo+$ulx, "pt\n";
    print TEX "\\leftskip=${ulx}pt\n";
    print TEX "\}\n";
  } else {
d306 1
a316 1
    print TEX "\}\n";
d318 7
d326 1
d328 7
a334 6
print TEX "\}\{\n";
print TEX "\\setbox1=\\vbox\{\\noindent\\includegraphics\[scale=$figscale\]\{$background\}\}\n";
print TEX "\\dimendef\\w=0 \\w=\\wd1\n";
print TEX "\\dimendef\\h=0 \\h=\\ht1\n";
print TEX "\\parindent=0pt\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n";
print TEX "\\vbox to0pt\{\\unvbox1\\vss\}\n";
d337 1
a337 1
  $uly = $ulyset{$_};
d340 1
a340 1
    print TEX '\vbox to0pt{\kern', $uly, "pt\\unvbox\\${_}box\\vss\}\n";
d342 2
a343 2
    while (@@$uly) {
      print TEX '\vbox to0pt{\kern', shift @@$uly, "pt\\vsplit\\${_}box to",
d348 2
a349 1
print TEX '}\unvbox0', "\n";;
d351 2
a352 1
  print TEX "\\ifvoid\\${_}box \\else\\message\{fig2sty: Frame ${_} overflow\}\\fi\n";
d357 1
d429 4
d475 1
d482 1
a482 3
  $tags{'offset'}       = $defoffset;
  $tags{'reference'}    = $defreference;
  $tags{'fontsize'}     = $deffontsize;
d485 1
a485 1
  my $frame;
d487 4
a490 8
    $tags{'baselineskip'} = $frame->{'baselineskip'}
      if ($frame->{'baselineskip'}); 
    $tags{'reference'} = $frame->{'reference'}
      if ($frame->{'reference'}); 
    $tags{'offset'} = $frame->{'offset'}
      if ($frame->{'offset'}); 
    $tags{'fontsize'} = $frame->{'fontsize'}
        if ($frame->{'fontsize'}); 
d511 1
a511 1
  my($refpoint, $nolines, @@hinfo, @@ulx, @@uly, 
d546 2
a547 2
    push @@uly, $firstline - $fontsize;
    push @@ulx, fig2pt($x1);
d551 1
a551 1
  return (\@@ulx, \@@uly, \@@vsize, \@@hinfo);
@


1.21
log
@TeX output improved
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.20 1998/06/02 19:09:35 marcel Exp marcel $
d98 3
a100 1
C<n> will be used.
d272 2
a273 1
    print TEX "\\hsize=", $hinfo, "pt\n";
d324 1
a324 1
  #unlink $tmpfile;
@


1.20
log
@TeX output nicer (uses \bgroup ... \egroup)
uses new commands \rigidize, \simulpar in figtosty.sty
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.19 1998/05/27 17:30:59 marcel Exp marcel $
d289 6
a294 2
print TEX "\}\{\\parindent=0pt\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n";
print TEX "\\vbox to 0pt\{\\includegraphics\[scale=$figscale\]\{$background\}\\vss\}\n";
d312 1
a312 2
print TEX "\\setbox0=\\vbox\{\\includegraphics\[scale=$figscale\]\{$background\}\}\n";
print TEX "\\vskip\\ht0\}\n";
@


1.19
log
@several minor improvements:
  environment thing corrected
  verbatim i.o.
  documentation
  message if frame overflow
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.18 1998/05/26 18:47:47 marcel Exp marcel $
d201 1
a201 1
            "baselineskip=i" => \$defbaselineskip,
d233 6
d251 1
a251 1
%\\usepackage\{graphicx}
d260 1
a264 1
  $n = scalar(@@$hinfo);
d266 9
a274 3
  print TEX <<"EOTEX";
\\long\\outer\\def\\b${_}##1\\end##\{% frame command
\\global\\setbox\\${_}box=\\vbox\{%
d276 3
a278 6
\\baselineskip=${baselineskip}pt\\lineskip=\\baselineskip% normal text spacing
\\abovedisplayskip=\\baselineskip% displayed equations spacing
\\belowdisplayskip=\\baselineskip%
\\abovedisplayshortskip=\\baselineskip%
\\belowdisplayshortskip=\\baselineskip%
\\def\\par\{\\unskip \\penalty10000 \\hskip\\parfillskip\\break\\hskip\\parindent\}
d281 5
a285 3
  my $il;
  foreach $il (@@$hinfo) {
    print TEX " $il->[0]pt $il->[1]pt";
a286 1
  print TEX "\n##1\\endgraf\}\\end\}\}\n";
d289 1
a289 1
print TEX "\{\\parindent=0pt\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n";
d295 7
a301 3
  while (@@$uly) {
    print TEX '\vbox to0pt{\kern', shift @@$uly, "pt\\vsplit\\${_}box to",
              shift @@$vsize, 'pt\vss}', "\n";
d455 10
@


1.18
log
@LaTeX syntax improved (requires now figtosty.sty)
more documentation
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.17 1998/05/25 18:54:37 marcel Exp marcel $
d66 2
a67 2
Any closed polygon or box may be a frame. It must not
have an area fill. This way your coloured background
d69 1
a69 1
associated to each frame. A Tag is simply a text
d75 1
a75 1
Several I<key> words are interpreted by xfig:
d113 5
d136 1
a136 1
C<fontsize> tag. B<fontsize=baselineskip> is usually a good
d154 11
a164 11
\begin{document}
...
\begin{fancylayout}
\begin{figframe}{abstract}
blah blah
\end{figframe}

\begin{figframe}{text}
blah blah
\end{figframe}
\end{fancylayout}
d166 2
a167 2
...
\end{document}>
d169 1
a169 1
=head1 Installation
d174 1
a174 1
=head1 Author
d178 4
d261 2
a262 2
\\long\\outer\\def\\b${_}##1\\end##2\{% frame command
\\setbox\\${_}box=\\vbox\{%
d276 1
a276 1
  print TEX "\n##1\\endgraf\}\}\n";
d279 1
a279 1
print TEX "\}\{\\parindent=0pt\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n";
d291 3
d295 1
a295 1
print TEX "\\vskip\\ht0\\end\{figframe\}\}\n";
@


1.17
log
@documentation added
-nopipe option
\parindent=0pt added
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.16 1998/05/24 14:46:35 marcel Exp marcel $
d118 22
d142 21
a162 1
this is still subject to change
d167 1
d236 1
a236 1
\\usepackage\{graphicx}
d252 1
a252 1
\\long\\outer\\def\\b${_}##1\\e${_}\{% frame command
d283 1
a283 1
print TEX "\\vskip\\ht0\}\n";
@


1.16
log
@reference bug corrected
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.15 1998/05/24 12:25:49 marcel Exp marcel $
d24 112
d145 2
a146 1
my $deffigversion   = '';
d153 2
a154 1
            "figversion=s"   => \$deffigversion);
d174 1
a174 1
$fig->{'version'} = $deffigversion if ($deffigversion);
d227 1
a227 1
print TEX "\}\{\\baselineskip=0pt\\setbox0=\\vbox to0pt\{\n";
d243 11
a253 2
$fig->writefile("|fig2dev -Lps -e -p dummy > $background");
die "fig2dev failed" if $?;
@


1.15
log
@bug fixes
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.14 1998/05/23 18:22:11 marcel Exp marcel $
d274 10
a283 4
    $firstline = int (fig2pt($frame->{'miny'} - $refpoint) / $baselineskip + 1)
                    * $baselineskip + fig2pt($refpoint);
    $firstline += $baselineskip if ( ($firstline - $frame->{'miny'} ) < pt2fig($fontsize));
    $firstline -= $baselineskip if ( ($firstline - $frame->{'miny'} ) > pt2fig($baselineskip));
@


1.14
log
@LaTeX output
options processing
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.13 1998/05/23 17:19:57 marcel Exp marcel $
d29 12
a40 1
&GetOptions("debug" => \$debug);
d60 1
a60 1
$fig->{'version'} = '3.1';
d84 2
d89 2
d97 1
a97 1
\\tolerance 9999\\emergencystretch 3em% sloppy
d110 1
a110 1
  print TEX "\n##1\\endgraf\}\}\}\n";
d113 2
a114 2
print TEX "\{\\baselineskip=0pt\\setbox0=\\vbox\{\\vbox to0pt\{\n";
print TEX "\\includegraphics\[scale=$figscale\]\{$background\}\n";
d117 2
d125 2
a126 3
print TEX "\\setbox0=\\vbox\{\n";
print TEX "\\includegraphics\[scale=$figscale\]\{$background\}\n";
print TEX "\}\\vskip\\ht0\}\}\n";
d238 4
a241 4
  $tags{'baselineskip'} = 12;
  $tags{'offset'}       = 0;
  $tags{'reference'}    = 'grid';
  $tags{'fontsize'}     = 12;
d275 3
a277 1
                    * $baselineskip + fig2pt($refpoint) + $fontsize;
@


1.13
log
@pstex -> ps
@
text
@d1 1
a1 1
#!/usr/local/bin/perl -d
d6 1
a6 1
# $Id: fig2sty,v 1.12 1998/05/23 09:24:58 marcel Exp marcel $
d26 4
d36 1
a36 1
my $texname    = "$jobname.tex";
d62 3
d66 4
a69 1
\\input epsf
d80 1
a80 1
\\long\\outer\\def\\b${_}#1\\e${_}\{% frame command
d95 1
a95 1
  print TEX "\n#1\\endgraf\}\}\n";
d98 3
a100 5
print TEX '\def\endlayout{\baselineskip=0pt\setbox0=\vbox{',
          '\vbox to0pt{\epsfbox{', $background, '}}', "\n";
# FIG 3.1 had a strange scaling bug
#print TEX '\def\endlayout{\def\epsfsize##1##2{0.95##1}\baselineskip=0pt\setbox0=\vbox{',
#          '\vbox to0pt{\epsfbox{', $background, '}}', "\n";
d108 3
a110 1
print TEX "\\setbox0=\\vbox\{\\epsfbox\{$background\}\}\\vskip\\ht0\}\n\\endinput\n";
d266 7
@


1.12
log
@working version of complete revision
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.11 1998/05/21 17:58:03 marcel Exp marcel $
d33 1
a33 1
my $background = "$jobname.pstex";
d45 1
d103 1
a103 1
$fig->writefile("|fig2dev -Lpstex -e -p dummy > $background");
@


1.11
log
@complete revision. does not work, but compiles
@
text
@d1 1
a1 1
#!/usr/local/bin/perl
d6 1
a6 1
# $Id: fig2sty,v 1.10 1998/05/20 17:27:33 marcel Exp marcel $
d32 2
a33 2
my $texname    = "$1.tex";
my $background = "$1.pstex";
d38 1
a43 1
$marker->{'npoints'} = 3;
d50 1
a50 1
  $commontags{$_} = {getFrameTags(@@{$frameset{$_}})};;
d69 2
a70 2
\\long\\outer\\def\\b${_}#1\\e$_\{% frame command
\\setbox\\${_}box=\vbox\{%
d72 2
a73 2
\\baselineskip=${baselineskip}pt\\lineskip=\\baselineskip% normal text
\\abovedisplayskip=\\baselineskip% displayed equations
d84 1
a84 1
  print TEX "\n#1\\endgraf}}\n";
d92 1
a92 2
my $fname;
foreach $fname (keys %frameset) {
d94 2
a95 2
    print TEX '\vbox to0pt{\kern', shift @@$uly, "pt\\vsplit\\",
              $fname, 'box to', shift @@$vsize, 'pt\vss}', "\n";
d99 1
a99 1
print TEX "\\setbox0=\\vbox{\\epsfbox{$background}}\\vskip\\ht0}\n\\endinput\n";
d108 6
d127 1
a127 1
      my($minx, $maxx, $miny, $maxy) = (0, 0, 0, 0);
d134 5
a138 5
      push @@polylist, {'fig'   => $element,
                       'minx'  => $minx,
                       'maxx'  => $maxx,
                       'miny'  => $miny,
                       'maxy'  => $maxy} 
d140 2
a141 1
         ($element->{'subtype'} == 2) || ($element->{'subtype'} == 3));
d146 4
a149 3
      push @@taglist, {'fig'   => $element,
                      'key'   => $key,
                      'value' => $value};
d165 1
d169 4
a172 4
      } if ($tag->{'fig'}->{'x'} > $poly->{minx} &&
            $tag->{'fig'}->{'x'} < $poly->{maxx} &&
            $tag->{'fig'}->{'y'} > $poly->{miny} &&
            $tag->{'fig'}->{'y'} < $poly->{maxy});
d176 2
d179 2
a180 3
  my $frame;
  for $frame ($fig->eachCompound()) {
    push @@frames, getFrames($frame);
d186 2
d192 1
d197 1
a235 2
  my $offset       = $reftags->{'offset'};
  my $reference    = $reftags->{'reference'};
d237 2
a238 1
  my($refpoint, $nolines, @@hinfo, @@ulx, @@uly, @@vsize, $x1, $x2, $firstline, $liney);
d242 2
d276 2
a277 1
    next if ( ($firstline - $p1->[1])*($firstline - $p2->[1]) > 0 );
@


1.10
log
@GPL notice
FIG version handling improved
scaling bug in xfig commented out
bug with multiple frame types removed
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.9 1998/05/18 17:38:18 marcel Exp marcel $
d8 1
a8 1
#    Copyright (C) 1998  Marcel Rohner
d10 4
a13 4
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
d15 4
a18 4
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
d20 3
a22 3
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
d24 2
d29 9
a37 23
$ARGV[0] =~ m/^(.*)\..*$/;
$jobname = $1;
$texname = "$1.tex";
$background = "$1.pstex";

open TEX, ">$texname";
open FIG, "|fig2dev -Lpstex -e -p dummy > $background";

# Read Header Information
local $ver    = <>;
die "File does not seem to be in FIG format\n" 
  unless ($ver =~ /^#FIG\s*([\d\.]+)\s+$/);
local $figver = $1;
local $orient = <>;
local $just   = <>;
local $units  = <>;
if ($figver =~ /3\.2/) {
  $papersize = <>;
  $magnification = <>;
  $multiplepage = <>;
  $transparent = <>;
}
my ($upi, $ul)  = split ' ', <>;
a38 15
local @@frames    = ();
local @@tags      = ();
local %framelist = ();
local $line;
local $type;
local $subtype;
local $text;
local $minx, $maxx, $miny, $maxy;

# Header Information
print FIG $ver, $orient, $just, $units;
print FIG $papersize, $magnification, $multiplepage, $transparent
  if ($figver =~ /3\.2/);
print FIG $upi, " ", $ul, "\n";
print TEX "\\input epsf\n\\vsize=10000pt\n";
d40 12
a51 2
print FIG "2 1 0 0 -1 7 0 0 -1 0.000 0 0 -1 0 0 3\n";
print FIG "\t0 1 0 0 1 0\n";
d53 30
a82 50
$line = <>;
my $lpctrl = 1;
OBJLOOP:  while ($lpctrl) {
  $lpctrl = 0 if (eof);
  chomp $line;
  @@object   = split ' ', $line;
  $type     = $object[0];
  $subtype  = $object[1];
  $fillstyle = $object[8];
  if ($type == 2 &&                        # Polyline
     ($subtype == 2 || $subtype == 3) &&   # Polygon or Box
     ($fillstyle == -1)) {                 # no area fill
    my $cmdline = $line;
    my @@points   = ();
    my @@ptofline = ();
    while (($line = <>) =~ /^\s/ && !eof) {
      @@ptofline = split ' ', $line;
      while (@@ptofline) { 
        push @@points, [shift @@ptofline, shift @@ptofline]; 
      } 
    }
    $minx = $miny = 1e38; $maxx = $maxy = -1e38;
    foreach (@@points) {
      $minx = $_->[0] if ($_->[0] < $minx);
      $maxx = $_->[0] if ($_->[0] > $maxx);
      $miny = $_->[1] if ($_->[1] < $miny);
      $maxy = $_->[1] if ($_->[1] > $maxy);
    }
    push @@frames, { 'type' => ($subtype == 2)?'box':'polygon',
                     'minx' => $minx,
                     'maxx' => $maxx,
                     'miny' => $miny,
                     'maxy' => $maxy,
                     'points' => [@@points],
                     'entry' => $cmdline,
                     'entrylist' => [@@object]
                   };
    next OBJLOOP;
  } elsif ($type == 4 && (($object[8] & 2) == 2)) { # special text
    @@object  = split ' ', $line, 14;
    $text = $object[13];
    if ($text =~ /^\s*(\w+)\s*=\s*(\w+)\\001$/) {
      push @@tags, {'tag' => $1,
                   'value' => $2,
                   'x' => $object[11], 
                   'y' => $object[12], 
                   'entry' => $line};
      $line = <>;
      next OBJLOOP;
    }
d84 2
d87 10
a96 4
  # default action: print object
  print FIG join(' ', @@object), "\n";
  while (($line = <>) =~ /^\s/ && ~eof) {
    print FIG $line;
d99 6
d106 39
a144 11
# Assign Tags to frames
# Note: a tag is assigned to one frame only
#       if two frames overlap, all tags will be assigned
#          to one of them only
foreach $tag (@@tags) {
  foreach $obj (@@frames) {
    $obj->{'tags'}->{$tag->{'tag'}} = $tag->{'value'}
      if ($tag->{x} > $obj->{minx} &&
          $tag->{x} < $obj->{maxx} &&
          $tag->{y} > $obj->{miny} &&
          $tag->{y} < $obj->{maxy});
d146 29
d177 6
a182 5
# Make list of Frame Types (framelist)
foreach $obj (@@frames) {
  if ($obj->{tags}) {
    push @@{$framelist{$obj->{tags}->{type}}}, $obj;
    $obj->{entrylist}->[3] = 0;
d184 4
a187 4
  print FIG join(' ', @@{$obj->{entrylist}}), "\n";
#  print FIG $obj->{'entry'}, "\n\t";
  foreach (@@{$obj->{'points'}}) {
    print FIG $_->[0], " ", $_->[1], " ";
a188 2
  print FIG "\n";
}     
d190 1
a190 5
# Sort Frame Types
foreach (keys %framelist) {
  @@{$framelist{$_}} = sort { $a->{tags}->{n} <=> $b->{tags}->{n} }
      @@{$framelist{$_}};
  print TEX "\\newbox\\$_", "box\n";
d193 10
a202 8
# Find common tags per frametype (first frame has highest priority)
%commontags = ();
foreach $fname (keys %framelist) {
  # defaults
  $commontags->{$fname}->{baselineskip} = 12;
  $commontags->{$fname}->{offset}       = 0;
  $commontags->{$fname}->{reference}    = 'grid';
  $commontags->{$fname}->{fontsize}     = 12;
d204 10
a213 9
  foreach $frame (reverse @@{$framelist{$fname}}) {
    $commontags->{$fname}->{baselineskip} = $frame->{tags}->{baselineskip}
      if ($frame->{tags}->{baselineskip}); 
    $commontags->{$fname}->{reference} = $frame->{tags}->{reference}
      if ($frame->{tags}->{reference}); 
    $commontags->{$fname}->{offset} = $frame->{tags}->{offset}
      if ($frame->{tags}->{offset}); 
    $commontags->{$fname}->{fontsize} = $frame->{tags}->{fontsize}
      if ($frame->{tags}->{fontsize}); 
d215 2
d219 13
a231 18
# Compute baselines within frames
#    @@lines contains coordinates ( [i,l], ...)
#    @@ll lower left corners ( [y,x,vsize], ...)
#    @@vsize size of each frame 
%vinfo = ();
foreach $fname (keys %framelist) {
  @@hinfo = ();
  @@vinfo = ();
  @@vsize = ();
  foreach $frame (@@{$framelist{$fname}}) {
    $baselineskip = $commontags->{$fname}->{baselineskip};
    $fontsize     = $commontags->{$fname}->{fontsize};
    $offset       = $commontags->{$fname}->{offset};
    $reference    = $commontags->{$fname}->{reference};

    $refpoint = 0;
    $refpoint = $frame->{miny} if ($reference =~ /^u/i);
    $refpoint = $frame->{maxy} if ($reference =~ /^l/i);
d233 1
a233 1
    $firstline = int (fig2pt($frame->{miny} - $refpoint) / $baselineskip + 1)
d236 1
a236 1
                           
d238 1
a238 1
    while ( ($x1, $x2) = intersect($liney, @@{$frame->{points}})) {
a240 5

# output for visualization
#      print FIG "2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 0 0 2\n";
#      print FIG "\t$x1 ", int($liney), " $x2 ", int($liney), "\n";

d243 4
a246 22
    push @@vinfo, [$firstline - $fontsize, 
                 fig2pt($x1), 
                 $nolines*$baselineskip];
  }
  $vinfo{$fname} = [@@vinfo];
# TeX Output
  print TEX '\long\outer\def\b', $fname, '#1\e', $fname, 
            "{\\setbox\\", $fname, 'box=\vbox{',
            '\tolerance 9999\emergencystretch 3em',
            '\baselineskip=', $baselineskip, 
            'pt\lineskip=\baselineskip',
            '\abovedisplayskip=\baselineskip',
            '\belowdisplayskip=\baselineskip',
            '\abovedisplayshortskip=\baselineskip',
            '\belowdisplayshortskip=\baselineskip',
            '\parshape=', scalar(@@hinfo);
  foreach (@@hinfo) {
    print TEX " $_->[0]pt $_->[1]pt";
  }
  print TEX '\def\par{\unskip \penalty10000 \hskip\parfillskip\break\hskip\parindent}',
            '#1\endgraf}}';
  print TEX "\n";
d248 1
a249 13
# define 'output' routine \endlayout
print TEX '\def\endlayout{\baselineskip=0pt\setbox0=\vbox{',
          '\vbox to0pt{\epsfbox{', $background, '}}', "\n";
# FIG 3.1 had a strange scaling bug
#print TEX '\def\endlayout{\def\epsfsize##1##2{0.95##1}\baselineskip=0pt\setbox0=\vbox{',
#          '\vbox to0pt{\epsfbox{', $background, '}}', "\n";
foreach $fname (keys %framelist) {
  foreach $vinfo (@@{$vinfo{$fname}}) {
    print TEX '\vbox to0pt{\kern', $vinfo->[0], "pt\\vsplit\\",
              $fname, 'box to', $vinfo->[2], 'pt\vss}', "\n";
  }
}
print TEX '}\unvbox0', "\n";;
a250 7
print TEX "\\setbox0=\\vbox{\\epsfbox{$background}}\\vskip\\ht0}\n\\endinput\n";
print FIG;

close FIG;
close TEX;

# ------------------------------------------------------------
d257 1
a257 1
  my $p1, $p2, $x;
d280 1
a280 1
  return $pts * $upi / 72.27;
d285 1
a285 1
  return $figs * 72.27 / $upi;
@


1.9
log
@multi frame error corrected
@
text
@d6 18
a23 1
# $Id: fig2sty,v 1.8 1998/05/18 17:24:58 marcel Exp marcel $
d38 1
a38 1
  unless ($ver =~ /^#FIG (.*)$/);
d43 5
a47 5
if ($ver =~ /3\.2/) {
  local $papersize = <>;
  local $magnification = <>;
  local $multiplepage = <>;
  local $transparent = <>;
d62 2
a63 2
print FIG $papersize, $magnification, $multplepage, $transparent
  if ($ver =~ /3\.2/);
d159 2
a160 2
  @@$framelist{$_} = sort { $a->{tags}->{n} <=> $b->{tags}->{n} }
      @@$framelist{$_};
d171 1
a171 1
  $commontags->{$fname}->{fontsize}     = 10;
d214 2
a215 2
      print FIG "2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 0 0 2\n";
      print FIG "\t$x1 ", int($liney), " $x2 ", int($liney), "\n";
d244 1
a244 1
print TEX '\def\endlayout{\def\epsfsize##1##2{0.95##1}\baselineskip=0pt\setbox0=\vbox{',
d246 3
@


1.8
log
@Fig version is checked (3.1, 3.2)
displayed equations work
frames occur in postscript with linewidth 0pt
  (so the vertical spacing of the layout should be correct)
resolution in the Fig header is used
typesetting is 'sloppy' since columns are usually rather narrow
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.7 1998/05/17 12:58:53 marcel Exp marcel $
a233 1
  print TEX '}\unvbox0', "\n";;
d235 1
@


1.7
log
@more sane variable names
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.6 1998/05/17 12:43:29 marcel Exp marcel $
d20 3
d26 7
a32 1
my ($origin, $ul)  = split ' ', <>;
d44 4
a47 1
print FIG $ver, $orient, $just, $units, $origin, " ", $ul, "\n";
d87 2
a88 1
                     'entry' => $cmdline
d91 1
a91 1
  } elsif ($type == 4 && $object[8] == 2) { # special text
d128 1
a128 7
  if (!$obj->{'tags'}) {
    print FIG $obj->{'entry'}, "\n\t";
    foreach (@@{$obj->{'points'}}) {
      print FIG $_->[0], " ", $_->[1], " ";
    }
    print FIG "\n";
  } else {
d130 6
d137 1
d209 9
a217 2
            "{\\setbox\\", $fname, 'box=\vbox{\baselineskip=', $baselineskip, 
            'pt\lineskip=', $baselineskip, 'pt\parshape=', scalar(@@hinfo);
d273 1
a273 1
  return $pts * 1200 / 72.27;
d278 1
a278 1
  return $figs * 72.27 / 1200;
@


1.6
log
@tags processing improved
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.5 1998/05/17 12:06:52 marcel Exp marcel $
d36 1
a36 1
print TEX "\\input epsf\n\\vsize=10000pt\n\\voffset=-1in\n\\hoffset=-1in\n";
d158 1
a158 1
%ll = ();
d160 2
a161 2
  @@lines = ();
  @@ll = ();
d177 1
d179 2
a180 1
      push @@lines, [fig2pt($x1), fig2pt($x2-$x1)];
d188 3
a190 3
    push @@ll, [$firstline - $fontsize, 
               fig2pt($x1), 
               scalar(@@lines)*$baselineskip];
d192 1
a192 1
  $ll{$fname} = [@@ll];
d196 2
a197 2
            'pt\lineskip=', $baselineskip, 'pt\parshape=', scalar(@@lines);
  foreach (@@lines) {
d209 3
a211 3
  foreach $ll (@@{$ll{$fname}}) {
    print TEX '\vbox to0pt{\kern', $ll->[0], "pt\\vsplit\\",
              $fname, 'box to', $ll->[2], 'pt\vss}', "\n";
@


1.5
log
@xfig marker at (0,0)
\endinput
output routine replaced by \endlayout
inclusion of layout into normal TeX file possible
basic tag operations
@
text
@d6 1
a6 1
# $Id: fig2sty,v 1.4 1998/05/17 09:26:23 marcel Exp marcel $
d168 7
a174 2
    $firstline = int (fig2pt($frame->{miny}) / $baselineskip + 1)
                    * $baselineskip;
d186 1
a186 1
    push @@ll, [$firstline - $baselineskip, 
d188 1
a188 1
               fig2pt($frame->{maxy} - $frame->{miny}) + $baselineskip];
@


1.4
log
@TeX commands defined
\par redefined
@
text
@d6 1
a6 1
# $Id:$
d37 3
d130 22
d158 1
d164 4
a167 1
    $baselineskip = 12;
d185 1
d187 3
a189 8
  # \output should be defined once only
  print TEX '\output={\def\epsfsize#1#2{0.95#1}\baselineskip=0pt\shipout\vbox{';
  print TEX "\\vbox to0pt{\\epsfbox{$background}}\n";
  foreach (@@ll) {
    print TEX "\\vbox to0pt{\\kern$_->[0]pt\\vsplit255 to $_->[2]pt\\vss}"
  }
  print TEX "}}\n";
  print TEX '\long\outer\def\b', $fname, '#1\\e', $fname, '{\parshape=', scalar(@@lines);
d193 2
a194 1
  print TEX '\def\par{\unskip \penalty10000 \hskip\parfillskip\break\hskip\parindent}#1\endgraf}';
d198 12
a209 1
print TEX '\def\endlayout{\vfill\break\end}', "\n";
@


1.3
log
@only unfilled boxes are used as frames
vertical kern added
postscript must be scaled by 0.95 for some strange reason
improvements in TeX output
@
text
@d2 12
a13 6

die "Usage: fig2sty template.fig" if (@@ARGV != 1);

$texname = $ARGV[0];
$texname =~ s/^(.*)\..*$/$1/;
$texname .= '.tex';
d16 1
d34 3
a36 1
print $ver, $orient, $just, $units, $origin, " ", $ul, "\n";
d90 1
a90 1
  print join(' ', @@object), "\n";
d92 1
a92 1
    print $line;
d113 1
a113 1
    print $obj->{'entry'}, "\n\t";
d115 1
a115 1
      print $_->[0], " ", $_->[1], " ";
d117 1
a117 1
    print "\n";
d147 2
a148 2
      print "2 1 0 1 -1 7 0 0 -1 0.000 0 0 -1 0 0 2\n";
      print "\t$x1 ", int($liney), " $x2 ", int($liney), "\n";
d156 2
a157 1
  print TEX "\\input epsf\n\\vsize=10000pt\n";
d159 1
a159 1
  print TEX "\\vbox to0pt{\\epsfbox{??}}}\n";
d163 2
a164 2
  print TEX "\n";
  print TEX '\parshape=', scalar(@@lines);
d168 3
d172 2
a173 2
print TEX "\\vfill\\eject\\end\n";
print;
d175 1
@


1.2
log
@TeX Output improved
@
text
@d37 4
a40 1
  if ($type == 2 && ($subtype == 2 || $subtype == 3)) {
d130 5
a134 3
    $liney = pt2fig(int (fig2pt($frame->{miny}) / $baselineskip + 1)
                           * $baselineskip);
    while ( ($x1, $x2) = intersect($liney, @@{$frame->{'points'}})) {
d143 1
a143 1
    push @@ll, [fig2pt($liney) - $baselineskip, 
d147 3
a149 2
  print TEX '\vsize=10000pt', "\n";
  print TEX '\output={\baselineskip=0pt\shipout\vbox{';
d151 1
a151 1
    print TEX '\vbox to0pt{\vsplit255 to', $_->[2], 'pt\vss}'
d153 1
a153 1
  print TEX '\box255}}', "\n";
d159 1
a159 1

@


1.1
log
@Initial revision
@
text
@d140 1
a140 1
               fig2pt($frame->{maxy} - $frame->{miny})];
d143 1
a143 1
  print TEX '\output={\shipout\vbox{';
d145 1
a145 1
    print TEX '\vbox to0pt{\vsplit255 to', $_->[2], 'pt}'
@
