jfig.objects
Class FigWriter

java.lang.Object
  extended byjfig.objects.FigWriter
Direct Known Subclasses:
FigWriter, FilteredFigWriter

public class FigWriter
extends java.lang.Object

write FIG 3.1 and 3.2 files.


Field Summary
(package private)  int BACKWARD
           
(package private)  ColorCache colorCache
           
protected  FigObject currentObject
           
(package private)  boolean debug
           
(package private)  int FORWARD
           
(package private)  int line_number
           
(package private)  int n_errors
           
(package private)  double resolution
           
(package private)  double scale_factor
           
(package private)  Format styleValFormat
           
 
Constructor Summary
FigWriter()
           
FigWriter(java.lang.Object app)
           
 
Method Summary
(package private)  java.lang.String buildCharacterEscape(char c)
          Build octal character escape for characters with c>= 128.
(package private)  java.lang.String buildTextString(FigText obj)
          Wrapper function for handling of accent and similar stuff when writing FIG 3.1 text objects.
 void fake_fig32_controlpoints(FigPrintWriter f, FigObject obj)
          fake the FIG 3.2 X-spline model control point parameters from FIG 3.1 spline / bezier spline objects.
 double fig_scale(double x)
           
 int fig_scale(int x)
          Scale from jfig units (2400 dpi) to standard FIG 3.1 units (1200 dpi), both with the origin at the top left corner.
 int getArcDirection(FigArc obj)
           
 int getAreaFill(FigAttribs attribs)
           
 int getBackwardArrowFlag(FigAttribs attribs)
           
 int getCapStyle(FigAttribs attribs)
           
 int getDepth(FigAttribs attribs)
           
 double getEllipseAngle(FigAttribs attribs)
           
 int getEllipseDirection(FigAttribs attribs)
           
 int getFillColorIndex(FigAttribs attribs)
           
 int getFont(FigAttribs attribs)
           
 double getFontAngle(FigAttribs attribs)
           
 int getFontFlags(FigAttribs attribs)
           
 double getFontSize(FigAttribs attribs)
           
 int getForwardArrowFlag(FigAttribs attribs)
           
 java.lang.String getHexString(int value, int n_chars)
          return a hex-formatted String of 'value' at least 'n_chars' wide, filling with leading zeroes as necessary.
 int getJoinStyle(FigAttribs attribs)
           
 int getLineColorIndex(FigAttribs attribs)
           
 int getLineStyle(FigAttribs attribs)
           
 int getLineThickness(double FIGwidth)
           
 int getLineThickness(int FIGwidth)
           
 int getPenStyle(FigAttribs attribs)
           
 int getRadius(FigAttribs attribs)
           
 java.lang.String getStyleVal(FigAttribs attribs)
           
 double getTextHeight(FigText obj)
          Get text height and width --- taken from text object bounding box.
 double getTextLength(FigText obj)
           
 void reset_debug()
           
 void set_debug()
           
 void setResolution(int i)
           
 void write_arrow_line(FigPrintWriter f, int direction, FigObject obj)
          Write the FIG 3.1 arrow representation of the forward or backward arrow on the FigObject obj.
 void write_fig31_arc(FigPrintWriter f, FigArc obj)
          write the FIG 3.1 representation of a jfig FigArc object
 void write_fig31_cpointline(FigPrintWriter f, FigObject obj)
           
 void write_fig31_ellipse(FigPrintWriter f, FigEllipse obj)
          Write the FIG 3.1 representation of a jfig FigEllipse object to stream f.
 int write_fig31_file(java.io.DataOutputStream f, boolean top_level, FigObjectList OL)
          write a FIG3.1 file to stream f, where the editor objects are taken from the object list OL.
 int write_fig31_file(java.io.PrintWriter _f, boolean top_level, FigObjectList OL)
           
 void write_fig31_header(FigPrintWriter f, FigAttribs attribs)
          Write a FIG3.1 file header to stream f.
 void write_fig31_object_comment(FigPrintWriter f, FigObject obj)
          write the per-object comment for the given FigObject.
 void write_fig31_pointline(FigPrintWriter f, FigObject obj)
          write a FIG3.1 polyline coordinate line to stream f
 void write_fig31_polyline(FigPrintWriter f, FigObject obj)
          Write a jfig polyline in FIG3.1 format to the stream f.
 void write_fig31_pseudocolors(FigPrintWriter f)
          Search through our colorCache and look for colors with numbers from 32 to 543.
 void write_fig31_rectangle(FigPrintWriter f, FigRectangle obj)
          Write a jfig rectangle in FIG3.1 format to the stream f.
 void write_fig31_spline(FigPrintWriter f, FigObject obj)
          Write the FIG 3.1 representation of a FigSpline object to stream f Only normal splines supported by now, no control splines.
 void write_fig31_text(FigPrintWriter f, FigText obj)
          Write the FIG 3.1 representation of a jfig FigText object to stream f.
 void write_fig32_header(FigPrintWriter f, FigAttribs attribs)
          Write a FIG3.2 file header to stream f.
 void write_jfig_trigger(FigPrintWriter f, FigTrigger obj)
           
 void writeAsResource(java.io.PrintWriter _ps, FigObject obj)
          default implementation of 'writeAsResource'.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FORWARD

final int FORWARD
See Also:
Constant Field Values

BACKWARD

final int BACKWARD
See Also:
Constant Field Values

debug

boolean debug

line_number

int line_number

n_errors

int n_errors

colorCache

ColorCache colorCache

resolution

double resolution

scale_factor

double scale_factor

currentObject

protected FigObject currentObject

styleValFormat

Format styleValFormat
Constructor Detail

FigWriter

public FigWriter(java.lang.Object app)

FigWriter

public FigWriter()
Method Detail

set_debug

public void set_debug()

reset_debug

public void reset_debug()

setResolution

public void setResolution(int i)

getLineStyle

public int getLineStyle(FigAttribs attribs)

getLineThickness

public int getLineThickness(int FIGwidth)

getLineThickness

public int getLineThickness(double FIGwidth)

getLineColorIndex

public int getLineColorIndex(FigAttribs attribs)

getFillColorIndex

public int getFillColorIndex(FigAttribs attribs)

getDepth

public int getDepth(FigAttribs attribs)

getPenStyle

public int getPenStyle(FigAttribs attribs)

getAreaFill

public int getAreaFill(FigAttribs attribs)

getStyleVal

public java.lang.String getStyleVal(FigAttribs attribs)

getJoinStyle

public int getJoinStyle(FigAttribs attribs)

getCapStyle

public int getCapStyle(FigAttribs attribs)

getRadius

public int getRadius(FigAttribs attribs)

getForwardArrowFlag

public int getForwardArrowFlag(FigAttribs attribs)

getBackwardArrowFlag

public int getBackwardArrowFlag(FigAttribs attribs)

getEllipseDirection

public int getEllipseDirection(FigAttribs attribs)

getEllipseAngle

public double getEllipseAngle(FigAttribs attribs)

getFont

public int getFont(FigAttribs attribs)

getFontSize

public double getFontSize(FigAttribs attribs)

getFontAngle

public double getFontAngle(FigAttribs attribs)

getFontFlags

public int getFontFlags(FigAttribs attribs)

getTextHeight

public double getTextHeight(FigText obj)
Get text height and width --- taken from text object bounding box. Note that the resulting values might be somewhat different from the original FIG 3.1. file data, because of a substituted Font...


getTextLength

public double getTextLength(FigText obj)

getArcDirection

public int getArcDirection(FigArc obj)

fig_scale

public int fig_scale(int x)
Scale from jfig units (2400 dpi) to standard FIG 3.1 units (1200 dpi), both with the origin at the top left corner.


fig_scale

public double fig_scale(double x)

write_jfig_trigger

public void write_jfig_trigger(FigPrintWriter f,
                               FigTrigger obj)

write_arrow_line

public void write_arrow_line(FigPrintWriter f,
                             int direction,
                             FigObject obj)
Write the FIG 3.1 arrow representation of the forward or backward arrow on the FigObject obj. Write nothing, if no arrow on this object. No support for 'solder dot' arrows yet.


write_fig31_pseudocolors

public void write_fig31_pseudocolors(FigPrintWriter f)
Search through our colorCache and look for colors with numbers from 32 to 543. These are user-defined pseudocolors that have to appear at the top of the FIG 3.1/3.2 file (but after the header).


getHexString

public java.lang.String getHexString(int value,
                                     int n_chars)
return a hex-formatted String of 'value' at least 'n_chars' wide, filling with leading zeroes as necessary.


write_fig31_ellipse

public void write_fig31_ellipse(FigPrintWriter f,
                                FigEllipse obj)
Write the FIG 3.1 representation of a jfig FigEllipse object to stream f.


write_fig31_spline

public void write_fig31_spline(FigPrintWriter f,
                               FigObject obj)
Write the FIG 3.1 representation of a FigSpline object to stream f Only normal splines supported by now, no control splines.


buildCharacterEscape

java.lang.String buildCharacterEscape(char c)
Build octal character escape for characters with c>= 128. Currently only the German umlaute are handled here.


buildTextString

java.lang.String buildTextString(FigText obj)
Wrapper function for handling of accent and similar stuff when writing FIG 3.1 text objects.


write_fig31_text

public void write_fig31_text(FigPrintWriter f,
                             FigText obj)
Write the FIG 3.1 representation of a jfig FigText object to stream f.

While rotated text cannot be displayed in jfig, the attribute is maintained and used on output. German and other accents, however, are not yet supported.

As xfig don't likes empty texts, we just return if the text object has no text in it.


write_fig31_arc

public void write_fig31_arc(FigPrintWriter f,
                            FigArc obj)
write the FIG 3.1 representation of a jfig FigArc object


write_fig31_cpointline

public void write_fig31_cpointline(FigPrintWriter f,
                                   FigObject obj)

fake_fig32_controlpoints

public void fake_fig32_controlpoints(FigPrintWriter f,
                                     FigObject obj)
fake the FIG 3.2 X-spline model control point parameters from FIG 3.1 spline / bezier spline objects. A control parameter value of -1.0 means that the curve exactly passes through the corresponding point, a value of +1.0 means an approximated point. Finally, the value 0.0 is used for the start and end points of open (vs. closed) spline objects.

Therefore, we generate the following contol point lines:


write_fig31_pointline

public void write_fig31_pointline(FigPrintWriter f,
                                  FigObject obj)
write a FIG3.1 polyline coordinate line to stream f


write_fig31_rectangle

public void write_fig31_rectangle(FigPrintWriter f,
                                  FigRectangle obj)
Write a jfig rectangle in FIG3.1 format to the stream f.


write_fig31_polyline

public void write_fig31_polyline(FigPrintWriter f,
                                 FigObject obj)
Write a jfig polyline in FIG3.1 format to the stream f.

The string 'line' will contain the following: object_code (2), sub_type( polyline/polygon), line_style, thickness, pen_color, fill_color, depth, pen_style (unused), area_fill. style_val, join_style, cap_style, radius, forward-arrow, backward-arrow, npoints. Then follow the forward-arrow and backward-arrow and point lines.


write_fig31_object_comment

public void write_fig31_object_comment(FigPrintWriter f,
                                       FigObject obj)
write the per-object comment for the given FigObject. Note that the comment may consist of multiple, '\n' separated lines. This is the Unix-convention, and "\n\r" line separators should not be used! For each line, we write a hash-sign, a blank, and the comment line.


write_fig32_header

public void write_fig32_header(FigPrintWriter f,
                               FigAttribs attribs)
Write a FIG3.2 file header to stream f.


write_fig31_header

public void write_fig31_header(FigPrintWriter f,
                               FigAttribs attribs)
Write a FIG3.1 file header to stream f.


write_fig31_file

public int write_fig31_file(java.io.DataOutputStream f,
                            boolean top_level,
                            FigObjectList OL)
write a FIG3.1 file to stream f, where the editor objects are taken from the object list OL.

The flag 'top_level' indicates that we should write the FIG3.1 header. This is set to true on the first call, and set to false on recursive calls when writing compound objects.

Return the number of errors, if any.


write_fig31_file

public int write_fig31_file(java.io.PrintWriter _f,
                            boolean top_level,
                            FigObjectList OL)

writeAsResource

public void writeAsResource(java.io.PrintWriter _ps,
                            FigObject obj)
default implementation of 'writeAsResource'. This will write a nearly xfig-compatible version of all basic FigObjects.