Xfig Renderer - Final Project for CSE6998-Advanced Internet Services


Larry Wong
Bellcore
445 South Street
Morristown, NJ 07962
Email address: larryw@notes.cc.bellcore.com
Work phone: 973-829-5114
Work fax: 973-829-5889

Abstract:

The java xfig renderer is a java applet that renders figures generated by the xfig drawing format. Xfig (Facility for Interactive Generation of figures) is a Unix drawing tool run under X11.

The xfig renderer displays xfig objects which includes embedded gifs (but not EPSF) and shading. The application is "read-only", the xfig object(s) are displayed, but currently the only way to modify the object is to modify it with the actual xfig program. This application's primary use is to embed line drawings into web pages at a better resolution than gif file.

Introduction:

gif files

Anyone who has tried to import a gif file into an application such as a html page or a Microsoft Power Point slide knows that the gif file has poor resolution. This is especially true if the gif file is forced to fit into a space different then the original data. The xfig renderer attempts to draw the original xfig data in a html page at a much higher resolution then if the user converted the xfig data to a gif file and imported to the html page.

xfig versions:

The applet will process xfig protocol 3.x only. Xfig protocol version is 3.2 is currently (May 1998) the latest version.

This report:

This report contains the following sections.

Architecture.

The xfig renderer recognizes formats 3.x only Those formats are described by 3.1 and 3.2 for use as the structure of the xfig file. Formats 3.0 and 3.1 are internally identical.

Components

The xfig renderer is divided into 2 sections

1. ConvertXfig - This is a pre-processor, this java program prepares the xfig data in a java applet friendly format. The output of this program is placed directly into a html file. The user does not have to perform any manual data entry and does not have to touch the data.

The ConvertXfig program is contained in one java file, ConvertXfig.java.

2. DrawXfig - This is the java applet which does the actual rendering of the xfig objects. The DrawXfig applet is invoked by html by the output of the ConvertXfig program. More on this later.

The DrawXfig java applet is contained in two java files, DrawXfig.java and Xfig.java. Xfig.java does the majority of the work. Xfig.java does all the data interpretation and graphics rendering. DrawXfig.java interfaces to html. If a xfig rendered is to be used for a different application, like Microsoft's power point, Xfig.java could be used with a different front-end.

Program Documentation.

ConvertXfig (a program for converting of the Xfig file to a html page) usage.

Run the program with a command of this format.

java ConvertXfig <input file> <output file> <width> <height>
<input file> is the xfig data file
<output file> is the output, for inclusion into a html document.
<width> the width of the output screen. This number is the width one would normally put it a html file.
<height> the heigh of the output screen, also in html units."

Place the <output file> directly into a hmtl file.

ConvertXfig example.

The user has a xfig file which contains data for a rectangle in it.

The file rect.fig contains the following data.
#FIG 3.1
Landscape
Center
Inches
1200 2
2 2 0 1 -1 7 0 0 -1 0.000 0 0 0 0 0 5
1200 1125 5700 1125 5700 3375 1200 3375 1200 1125

The user enters in the command

java ConvertXfig rect.fig rect.tmp 200 200

The above command creates a file called "rect.tmp", the user wants the final image to be of size 200 by 200.

We look into the file rect.tmp, it contains ...
<!-- rect.fig -->
<APPLET CODE="DrawXfig.class" WIDTH=200 HEIGHT=200>
<PARAM NAME=file VALUE="
<FIG 3.1 Landscape Center Inches 1200 2 2 2 0 1 -1 7 0 0 -1 0.000 0 0 0 0 0 5 1200 1125 5700 1125 5700 3375 1200 3375 1200 1125 ">
</APPLET>

The user places the rect.tmp file directly into a hmtl file. The user is done.

Some details on the ConvertXfig program.

This section describes the output of the ConvertXfig program in detail. We see that the ConvertXfig program automatically creates the lines

<!-- rect.fig -->

so the user knows which xfig file created the data.

<APPLET CODE="DrawXfig.class" WIDTH=200 HEIGHT=200>

The DrawXfig.class java applet is invoked with this statement. The width and height parameters are those that are inputed by the user.

The WIDTH and HEIGHT can be any size. The xfig rendered will scale the image appropriately to fit the image to the specified size. One caveat is that xfig circles will not be rendered as circles if the WIDTH and HEIGHT differ. If the WIDTH and HEIGHT are equal then the resulting xfig rendered circle will be round.

<PARAM NAME=file VALUE="

The ConvertXfig program creates the above line to allow the DrawXfig program to do a "getParameter ("file")" command to retrieve the data.

<FIG 3.1 Landscape Center Inches 1200 2 2 2 0 1 -1 7 0 0 -1 0.000 0 0 0 0 0 5 1200 1125 5700 1125 5700 3375 1200 3375 1200 1125 ">

The above line is the entire original xfig file compress onto one string. My original design was to read in individual lines of text. However, Netscape version 4.02 compressed the lines. When given this input


#FIG 3.1
Landscape
Center

Netscape interpreted the above data to be
#FIG 3.1LandscapeCenter

Oddly enough, the appletviewer program interpreted the data to be 3 different lines. I didn't have access to Hot Java or Microsoft Explorer, so I don't know how those browsers handle the data. Since my java applet needed a uniform input format, I decided to be proactve and forced the data into the above format.

One additional positive is that the above format makes the html file significantly smaller. One downside is that there is a concern if the line is too long then text editors and/or the DrawXfig program will not be able to interpret the string. I did input a line with over 500 xfig statements concatenated onto one line with no ill effects.


For completeness, this is a actual DrawXfig drawing of the above rect.tmp file.

Which looks like what a user would see if the user viewed the original rect.fig file under xfig.

Features:

This section describes what was successfully converted.

The 32 standard pre-defined colors.

Allowing the user to define 512 additional colors.

Arcs, all 4 flavors, filled closed pie-wedges, outline closed pie-wedges, filled open ended arcs, and outline open ended arcs. Note: the xfig closed fill pie-wedge looks like the sun partially eclipsed by the moon. The java.awt.Graphics equivalent looks similar to pac-man. I draw an addition slice to the pac-man shape with looks similar to the xfig version, however a very small number of pixels where the pac-man meets the slice might not be covered.

Circles / Ellipses, all 4 xfig formats, both filled and unfilled are rendered.

Lines / Rectanges / Polygons / Arc-boxes / Imported gif files are all rendered.

Arrowheads are rendered only on lines.

Splines are partially supported. See the limitations section for more details.

Text is fully supported except for a Greek letters font.

The 36 xfig font types are mapped to the following java fonts.
Java font Xfig font
Dialog AvantGarde
SansSerif New Century
Serif Palatino
Monospaced Bookman
Helvetica Helvetica & Helvetica narrow
TimesRoman Times
Courier Courier & Typewriter
ZapfDingbats Zapf

There are also plain, bold, and italic sub-fonts.

Current limitations:

This section describes the current limitations of the program. Generally these items had no java.awt.Graphics equivalent and were difficult to manually implement.

Single width lines, the java.awt.Graphics package only supports one line thickness. All lines are drawn with the java.awt.Graphics default line thickness. Also, no dotted or dashed lines as well.

Splines lines are rendered, but the lines are not smooth. java.awt.Graphics does not support splines. I took the xfig data points and connected them with straight lines. The open and closed splines look like a reasonable rendering, however the open interpolated spline and the close interpolated spline look very different.

No greek letter font. The standard ascii version in Times-Roman font would appear instead.

Filled areas in xfig can be filled-in with 43 different fill patterns. For example, a honeycomb pattern or a brick outline. This is not supported by java, so I just fill in the area with the specified color.

Possible overlap of data, xfig has some intelligence or fancy bitmap to not overwrite text. A xfig user could type in a line of black text followed by a blue filled in square on top of the text. The black text would appear inside the blue square. In this scenario, the xfig file would have the text statement object followed by the square object. The xfig rendered would draw the text, but the square would cover up the text. One area for future work would be for the text to be moved to the end of the data file and/or filled in object move to the front.

There is no validation of the xfig data file. However, the ConvertXfig program eliminates the need for users to touch/modify the xfig data.

Examples.

This xfig renderer color example demonstrates the 32 pre-defined xfig colors and 2 user defined colors.
This xfig renderer font example demonstrates the 35 xfig fonts.

These examples demonstrate the basic shapes.
various arcs
circles and ellipses
polylines, boxes, polygon, arc-boxes
imported gif files
splines
text
arrowheads

From some real xfig files I found in the professor's directory .
example 1
example 2
example 3
example 4
example 5

For a comparison these are the fonts as depicted by xfig via a imported gif file.

Installation Instructions:

Download the software. The software requires the JDK (Java Developement Kit) version 1.1.x or greater and a java enabled browser.

The source code is also located on the cs machines in
~lwong/public/ais

Design.

There are 7 basic objects in xfig (user-defined colors, arcs, compounds, ellipses, polylines, splines, and text). Each object has a different structure that defines it's attributes (fonts, color, etc.)

My program design.

Read in WIDTH, HEIGHT, and xfig data
Loop until all done
Determine what type of xfig object is next
Read the data into local variables.
Convert the xfig coordinates to java applet coordinates.
Set the proper color/font.
Determine the proper place to put the object based on WIDTH HEIGHT.
Call the appropriate java.awt.Graphics routine(s).

Notes / Future Work.

Testing:

I have done extensive testing with xfig version 3.1 patch level 3. I have also tested to a lesser degree version 3.2 files that I have collected. I have not done any testing with 3.0, but according to the documentation the differences are minor.

Environment:

Developed on Solaris version 5.5.1 using java's JDK 1.1.3 and Netscape version 4.02.

Future Work.:

Splines can be added in. The Xfig authors used the algorithms in xfig protocol version 3.2 from "X-Splines: A Spline Model Designed for the End User" by C. Blanc and C. Schlick, Proceedings of SIGGRAPH'95. Some effort would also be required to render the 3.1 version splines. which have a different input.

Possible overlap of data described in the limitations section.

Dotted or dashed lines can be made by drawing many line segments.

Slides.

The link to my slides.
Last Modified: 1998-05-6