net.paulhertz.aifile
Class PointText

java.lang.Object
  extended by net.paulhertz.aifile.DisplayComponent
      extended by net.paulhertz.aifile.PointText
All Implemented Interfaces:
Visitable

public class PointText
extends DisplayComponent

Implements an Adobe Illustrator 7.0 Point Text object with a subset of the available tags. Provides methods to set the fill, stroke, and stroke weight of the text, although these are part of the graphics state and not part of the text object itself. Be aware that they will remain in effect in the file until they are changed.


Field Summary
 int objectType
          text object type, default 0, other types unsupported as yet
 
Constructor Summary
PointText()
          PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup.
PointText(double tx, double ty, String text)
          Creates a new PointText displaced (ty,ty) from the origin (0,0).
PointText(PApplet parent)
          Creates a new PointText at (0,0).
PointText(PApplet parent, double tx, double ty, String text)
          Creates a new PointText displaced (ty,ty) from the origin (0,0).
 
Method Summary
 void accept(ComponentVisitor visitor)
          Accepts a ComponentVisitor that traverses a document structure tree.
 void accept(ComponentVisitor visitor, boolean order)
          Accepts a ComponentVisitor that traverses a document structure tree in preorder or postorder.
 void add(ArrayList<? extends DisplayComponent> comps)
          Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal.
 void add(DisplayComponent component)
          Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.
 int alignment()
           
 ArrayList<DisplayComponent> children()
           
 void draw()
          Draws geometry or text to the Processing window.
 void draw(PGraphics pg)
          Draws a component to a supplied PGraphics.
 int fillColor()
           
 int fillOpacity()
           
 String fontname()
           
 DisplayComponent get(int index)
          Returns the component at index from the children of this component, throws an UnsupportedOperationException if component is terminal.
 PFont getFont()
           
 int getObjectType()
           
 boolean isTerminal()
           
 Iterator<DisplayComponent> iterator()
          Returns an iterator over children, throws an UnsupportedOperationException if component is terminal.
 double leading()
           
 void loadFont(String name)
           
 double[] matrix()
           
 String outputString()
           
 double paragraphLeading()
           
 String pFontname()
           
 boolean remove(DisplayComponent component)
          Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal.
 int render()
           
 void setAlignment(int alignment)
           
 void setFillColor(int newFillColor)
           
 void setFillColor(RGBColor newFillColor)
           
 void setFillOpacity(int opacity)
          Sets opacity of current fill color.
 void setFont(PFont font)
          Sets the Processing font to the supplied PFont.
 void setFont(String fontname, String pFontname, double weight, double leading)
           
 void setFontname(String fontname)
           
 void setLeading(double leading)
           
 void setMatrix(double[] matrix)
           
 void setMatrix(Matrix3 matx)
          Uses a Matrix3 to set the internal matrix used by Adobe Illustrator.
 void setNoFill()
           
 void setNoStroke()
           
 void setParagraphLeading(double paragraphLeading)
           
 void setPFontname(String pFontname)
           
 void setRender(int render)
          Sets the render mode of text, generally safe to stick with the default 0, or with 1 or 2.
 void setSize(double size)
           
 void setStartPt(double startPt)
           
 void setStrokeColor(int newStrokeColor)
           
 void setStrokeColor(RGBColor newStrokeColor)
           
 void setStrokeOpacity(int opacity)
          Sets opacity of current stroke color.
 void setText(String text)
           
 void setTx(double tx)
           
 void setTy(double ty)
           
 void setUseTransparency(boolean useTransparency)
           
 void setWeight(float newWeight)
           
 double size()
           
 double startPt()
           
 int strokeColor()
           
 int strokeOpacity()
           
 String text()
           
 void transform(Matrix3 matx)
          Illustrator will display the transformed text.
 double tx()
           
 double ty()
           
 boolean useTransparency()
           
 float weight()
           
 void write(PrintWriter pw)
          Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.
 
Methods inherited from class net.paulhertz.aifile.DisplayComponent
hide, id, isLocked, isVisible, parentComponent, setLocked, setParentComponent, setVisible, show
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

objectType

public final int objectType
text object type, default 0, other types unsupported as yet

See Also:
Constant Field Values
Constructor Detail

PointText

public PointText(PApplet parent)
Creates a new PointText at (0,0).


PointText

public PointText()
PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup. If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException. Creates a new PointText at (0,0).


PointText

public PointText(PApplet parent,
                 double tx,
                 double ty,
                 String text)
Creates a new PointText displaced (ty,ty) from the origin (0,0).

Parameters:
parent - PApplet used for calls to the Processing environment.
tx - x translation
ty - y translation
text - the text

PointText

public PointText(double tx,
                 double ty,
                 String text)
Creates a new PointText displaced (ty,ty) from the origin (0,0). PApplet used for calls to the Processing environment is obtained from IgnoCodeLib, which must be correctly initialized in setup. If IgnoCodeLib does not have a reference to a PApplet, it throws a NullPointerException.

Parameters:
tx - x translation
ty - y translation
text - the text
Method Detail

matrix

public double[] matrix()
Returns:
the matrix, last two entries are tx and ty.

setMatrix

public void setMatrix(double[] matrix)
Parameters:
matrix - the matrix to set, concatenated with CTM (current transformation matrix). It's generally safe to use the default values 1 0 0 1 tx ty. An exact explanation of what the matrix represents may be found in Adobe's Postscript Language Reference Manual, section 4.3.3 Matrix Representation and Manipulation (page 201). Briefly, if a transformation matrix is represented as: a b 0 c d 0 tx ty 1 then the representation in the Adobe Illustrator file omits the third column, thus: a b c d tx ty The net.paulhertz.geom.Matrix3 class provides utility methods for concatenating transforms and can be used to derive useful values for the matrix.

setMatrix

public void setMatrix(Matrix3 matx)
Uses a Matrix3 to set the internal matrix used by Adobe Illustrator. Code shows exactly how values in the supplied matrix correspond to the 6-element matrix used by Illustrator.

Parameters:
matx - a Matrix3 that encapsulates a transform. Third column is ignored.

tx

public double tx()
Returns:
tx, translation along x-axis.

setTx

public void setTx(double tx)
Parameters:
tx - translation along x-axis to set

ty

public double ty()
Returns:
ty, translation along y-axis.

setTy

public void setTy(double ty)
Parameters:
ty - the translation along y-axis to set

startPt

public double startPt()
Returns:
the startPt

setStartPt

public void setStartPt(double startPt)
Parameters:
startPt - the startPt to set, only meaningful for text on a path, where it indicates a position on the path.

text

public String text()
Returns:
the text

setText

public void setText(String text)
Parameters:
text - the text to set

render

public int render()
Returns:
the render

setRender

public void setRender(int render)
Sets the render mode of text, generally safe to stick with the default 0, or with 1 or 2.

Parameters:
render - the render to set 0 Ñ filled text 1 Ñ stroked text 2 Ñ filled and stroked text 3 Ñ invisible text 4 Ñ masked and filled text 5 Ñ masked and stroked text 6 Ñ masked, filled, and stroked text 7 Ñ masked (only) text 8 Ñ filled text followed by render mode 9 (pattern prototype only) 9 Ñ stroked text (preceded by render mode 8 text, pattern prototype only)

fontname

public String fontname()
Returns:
the fontname.

setFontname

public void setFontname(String fontname)
Parameters:
fontname - the fontname to set. If no font is supplied, Illustrator uses its default font. You may need to determine AI's naming conventions by inspecting a legacy file format in a text editor. Typical names include: MyriadPro-Regular, Helvetica, Times-Roman, Times-Bold, Times-Italic, Times-BoldItalic, Tekton-Bold, etc. These will be bracketed by the appropriate tags when written to file.

pFontname

public String pFontname()
Returns:
the pFontname, name of the font used by Processing.

setPFontname

public void setPFontname(String pFontname)
Parameters:
pFontname - the Processing font to use. See http://processing.org/reference/text_.html

loadFont

public void loadFont(String name)
Parameters:
name - the name of the .vlw file to use

getFont

public PFont getFont()
Returns:
the font

setFont

public void setFont(PFont font)
Sets the Processing font to the supplied PFont. This is the preferred method for setting the Processing font, with the least chance of errors.

Parameters:
font - the font to set

size

public double size()
Returns:
the size in points

setSize

public void setSize(double size)
Parameters:
size - the size to set, in points

leading

public double leading()
Returns:
the leading between lines, in points (default 0 = auto)

setLeading

public void setLeading(double leading)
Parameters:
leading - the leading between lines, in points

setFont

public void setFont(String fontname,
                    String pFontname,
                    double weight,
                    double leading)
Parameters:
fontname - name of the font used in Illustrator
pFontname - name of the font used in Processing
weight - font weight (size in points)
leading - leading between lines, commonly 1.25 * weight

paragraphLeading

public double paragraphLeading()
Returns:
the leading between paragraphs, in points

setParagraphLeading

public void setParagraphLeading(double paragraphLeading)
Parameters:
paragraphLeading - the leading between paragraphs, in points (default 0 = auto)

alignment

public int alignment()
Returns:
the alignment

setAlignment

public void setAlignment(int alignment)
Parameters:
alignment - the alignment to set 0Ñleft aligned 1Ñcenter aligned 2Ñright aligned 3Ñjustified (right and left) 4Ñjustified including last line

getObjectType

public int getObjectType()
Returns:
the objectType

fillColor

public int fillColor()

setFillColor

public void setFillColor(int newFillColor)

setFillColor

public void setFillColor(RGBColor newFillColor)

setNoFill

public void setNoFill()

strokeColor

public int strokeColor()

setStrokeColor

public void setStrokeColor(int newStrokeColor)

setStrokeColor

public void setStrokeColor(RGBColor newStrokeColor)

setNoStroke

public void setNoStroke()

setFillOpacity

public void setFillOpacity(int opacity)
Sets opacity of current fill color.

Parameters:
opacity - a number in the range 0..255. Value is not checked!

fillOpacity

public int fillOpacity()
Returns:
the opacity value of the current fill color

setStrokeOpacity

public void setStrokeOpacity(int opacity)
Sets opacity of current stroke color.

Parameters:
opacity - a number in the range 0..255. Value is not checked!

strokeOpacity

public int strokeOpacity()
Returns:
the opacity value of the current stroke color

useTransparency

public boolean useTransparency()

setUseTransparency

public void setUseTransparency(boolean useTransparency)

weight

public float weight()

setWeight

public void setWeight(float newWeight)

outputString

public String outputString()

add

public void add(DisplayComponent component)
Description copied from class: DisplayComponent
Adds a component to children of this component, throws an UnsupportedOperationException if component is terminal.

Specified by:
add in class DisplayComponent
Parameters:
component - DisplayComponent to add to this component's children
Throws:
UnsupportedOperationException, - this is a terminal component

add

public void add(ArrayList<? extends DisplayComponent> comps)
Description copied from class: DisplayComponent
Adds all components in a list to this component, throws an UnsupportedOperationException if component is terminal.

Specified by:
add in class DisplayComponent
Parameters:
comps - an ArrayList of DisplayComponents
Throws:
UnsupportedOperationException, - this is a terminal component

remove

public boolean remove(DisplayComponent component)
Description copied from class: DisplayComponent
Removes a component from children of this component, throws an UnsupportedOperationException if component is terminal.

Overrides:
remove in class DisplayComponent
Parameters:
component - DisplayComponent to remove from this component's children
Returns:
true if component was found and removed, false otherwise.
Throws:
UnsupportedOperationException, - this is a terminal component

get

public DisplayComponent get(int index)
Description copied from class: DisplayComponent
Returns the component at index from the children of this component, throws an UnsupportedOperationException if component is terminal. Throws an IndexOutOfBoundsException if index is out of range (index < 0 || index >= size).

Overrides:
get in class DisplayComponent
Parameters:
index - index to component
Returns:
the DisplayComponent at the supplied index
Throws:
UnsupportedOperationException, - this is a terminal component

iterator

public Iterator<DisplayComponent> iterator()
Description copied from class: DisplayComponent
Returns an iterator over children, throws an UnsupportedOperationException if component is terminal.

Overrides:
iterator in class DisplayComponent
Returns:
an Iterator over the children array of this component
Throws:
UnsupportedOperationException, - this is a terminal component

children

public ArrayList<DisplayComponent> children()
Overrides:
children in class DisplayComponent
Returns:
null, this is a terminal component

isTerminal

public boolean isTerminal()
Specified by:
isTerminal in class DisplayComponent
Returns:
true, this is a terminal component

draw

public void draw()
Description copied from class: DisplayComponent
Draws geometry or text to the Processing window. Component must be flagged as visible (the default).

Specified by:
draw in class DisplayComponent

draw

public void draw(PGraphics pg)
Description copied from class: DisplayComponent
Draws a component to a supplied PGraphics. Except for the document component, a component must be visible (the default) to draw. Structural components simply iterate over their children. Graphic components should call beginShape and endShape on their own. It's up to the user to call beginDraw() and endDraw() on the PGraphics instance.

Specified by:
draw in class DisplayComponent
Parameters:
pg - a PGraphics instance

write

public void write(PrintWriter pw)
Description copied from class: DisplayComponent
Writes an Adobe Illustrator 7.0 file format encoding structure, geometry and text.

Specified by:
write in class DisplayComponent
Parameters:
pw - a PrintWriter for file output.

transform

public void transform(Matrix3 matx)
Illustrator will display the transformed text. Except for translation, Processing doesn't transform text.

Specified by:
transform in class DisplayComponent
Parameters:
matx - a Matrix3 that encapsulates an affine geometric transform.
See Also:
DisplayComponent.transform(net.paulhertz.geom.Matrix3)

accept

public void accept(ComponentVisitor visitor)
Description copied from interface: Visitable
Accepts a ComponentVisitor that traverses a document structure tree.

When called from an object that implements the Visitable interface:

  1. each visited object passes a reference to itself back to the visitor
  2. each visited object calls accept( visitor ) on all its children

The reference is passed back to the visitor through a method of the form visitor.visit<ComponentClassName>( this ); See ComponentVisitor

The order of steps 1 and 2 determines if traversal of the composite structure is preorder or postorder. As shown above, it's preorder. Depending on what you want to do, one traversal may be better suited than the other. Preorder visits parents first, postorder visits children first.

Parameters:
visitor - a ComponentVisitor

accept

public void accept(ComponentVisitor visitor,
                   boolean order)
Description copied from interface: Visitable
Accepts a ComponentVisitor that traverses a document structure tree in preorder or postorder.

Parameters:
visitor - a ComponentVisitor
order - boolean to determine if traversal is preorder or postorder accept( visitor ) should implement the default order of traversal, accept( visitor, <false> ) should implement the other order.


Processing library IgnoCodeLib by Paul Hertz. (C) 2013