-- txt2fig V1.0 --
Convert paragraphs of ascii text into xfig format, fully justified text


txt2fig converts paragraphs of text, into xfig format, fully justified text. This is useful if you want to add a lot of text to your xfig files, as there is no built in way to add multiline text in xfig, never mind justify it. This utility came into existance because all the startard text formatters that could create nicely formated text, were also unable to output eps files with transparent backgrounds. There doesn't appear to be any utilities that can convert an opaque eps file to transparent, so I was stuck.

This utility reads partially formatted text of the form: #width 9 Background

You might think such a program would already exist, making eps files transparent or adding lots of text to xfig files seems to be required quite a lot, yet the utilities just weren't there. This program was born out a quick hack based in bash, that morphed into a larger hack based on awk, which it still is now. It works by using a lookup table of character widths for the stardand Times-Roman font at size 25. The lookup table was generated with a bash script that converted each letter of the alphabet to a bitmap and then identified where the letter starts and ends from left to right. Using the widths of each character and a known ideal maximum width, it is then easy enough to read through text and output an xfig format file which places each character in exactly the right place to make the text fill a line as much as possible and be fully justified.
From this, the only additions are the ability to specifiy the line width (using the #width keyword) in the text file itself, and the option to output sections of text to different output files (using the #file keyword). The combination of the two mean a single input text file can create any number of .xfig files, each with different maximum widths.
and converts it with a line such as:
tr -dc "[:print:]\n" < inputtext.txt | ./txt2fig.awk > output.fig

Which generates the above paragraphs in .fig format and is 8 inches wide. The tr command removes any non-ascii junk, namely the two bytes OpenOffice adds when exporting as text. For the benefit of the browser, exporting the resultant .fig file as a png leads to this. Which was generated with this line:
./txt2fig.awk < background.txt | fig2dev -L png -m 4 > background.png


Two keywords at the moment:
#width x at the start of a line will set line width from then on to x inches.
#file filename at the start of a line will stop using stdout and write the following lines to the given file.

The bash script that generated the font widths is available here, and the initial .fig file is here


txt2fig.awk can be downloaded here.


0. Fix the bug that outputs a header to stdout, even if all output is written to named files.

1. Add all the things that make it whole, docs, man page, examples, rebustness.

2. Find a utility that acheives the same effect and so avoid having to support this program.

Change log

V1.0 1/3/2006
Initial test release, having written the program I thought it might be useful to somebody else.


Written by Greg: greg at csc liv ac uk. Would welcome any comments.


This software is released under the terms of the GNU GPL.