TinyLine
v2.0

com.tinyline.svg
Class SVGDocument

java.lang.Object
  extended bycom.tinyline.svg.SVGDocument

public class SVGDocument
extends java.lang.Object

The SVGDocument class implements the header object in the SVG object hierarchy.

The SVGDocument class represents the entire SVG document. It has the pointer to the root of the document tree, and provides the primary access to the document's data.

Since SVG nodes cannot exist outside the context of a SVGDocument, the SVGDocument also contains the factory methods needed to create these objects. The SVGNode objects created have a ownerDocument attribute which associates them with the SVGDocument within whose context they were created.

Besides being the header object in the SVG object hierarchy the SVGDocument plays other roles.

It supports fontTable for SVG fonts defined in the current SVG document. It also provides the default SVG font. The default SVG font must be set before any SVG document can be loaded.

    SVGDocument doc =  loadSVG("helvetica.svg");
    SVGFontElem font = SVGDocument.getFont(doc,SVG.VAL_DEFAULT_FONTFAMILY);
    SVGDocument.defaultFont = font;
 

The SVGDocument plays a role of SMIL time container for SVG animations. It has a list of animations targets (animTargets), the current document time (currentTime) and the animations callback. The animations callback (acb) should be registered so playing animations can notify it about SMIL events.

As some devices do not have a pointer device, there is a need to traverse links using keys. For that, the SVGDocument supports a list of linked elements (linkTargets) along with a current selected element (linkIndex).

Version:
2.0

Author:
Andrew Girow

Field Summary
 AnimationCallback acb
          Posts the SMIL event from an animation element to an interested party.
 TinyVector animTargets
          The animated targets array
 int currentTime
          The current Time
static SVGFontElem defaultFont
          The static default font
 TinyHash fontTable
          The font table - cache for SVGFontElem's.
 TinyHash idTable
          The hashtable for SVGNode's with Ids.
 int linkIndex
          The index in links targets array
 TinyVector linkTargets
          The xlink_href links targets array
 int nActiveAnimations
          The number of active animations
 SVGRaster renderer
          An SVGDocument renderer.
 SVGNode root
          The SVG Tree root node.
 
Constructor Summary
SVGDocument()
          Constructs a new empty SVGDoccument object.
 
Method Summary
 void addAnimations(SVGNode node)
          Traverses SVG tree nodes and adds animation elements to animTargets array.
static int addFont(SVGDocument document, SVGFontElem node)
          Adds the given SVGNode font object to the font cache table.
 void addIds(SVGNode node)
          Traverses SVG tree nodes and adds elements with IDs to idTable hash.
 void addLinks(SVGNode node)
          Traverses SVG tree nodes and adds 'a' elements to linkTargets array.
 TinyRect animate(int t)
          SMIL: The animation effect function F(t,u) The effect of an animation for any point in the duration of animations.
 SVGNode createElement(int qName)
          Creates an element for the element handle specified.
 int getCurrentTime()
          SMIL: Returns the current document time.
static SVGFontElem getFont(SVGDocument document, TinyString fontFamily)
          Returns SVGNode font object for the given fontFamily value or null.
 boolean isZoomAndPanAnable()
          Returns true if "magnification" is enabled.
 void postSMILEvent(int eventType, TinyString theEvent)
          SMIL: Posts the event from an animation element to the registered callback.
 boolean resolveEventBased(TinyString id)
          SMIL: Resolves event-based times of animation elements.
 boolean resolveLinkBased(TinyString id)
          SMIL: Resolves link-based times of animation elements.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

root

public SVGNode root
The SVG Tree root node.


renderer

public SVGRaster renderer
An SVGDocument renderer.


fontTable

public TinyHash fontTable
The font table - cache for SVGFontElem's.


defaultFont

public static SVGFontElem defaultFont
The static default font


idTable

public TinyHash idTable
The hashtable for SVGNode's with Ids.


nActiveAnimations

public int nActiveAnimations
The number of active animations


animTargets

public TinyVector animTargets
The animated targets array


currentTime

public int currentTime
The current Time


acb

public AnimationCallback acb
Posts the SMIL event from an animation element to an interested party.


linkTargets

public TinyVector linkTargets
The xlink_href links targets array


linkIndex

public int linkIndex
The index in links targets array

Constructor Detail

SVGDocument

public SVGDocument()
Constructs a new empty SVGDoccument object.

Method Detail

createElement

public SVGNode createElement(int qName)
Creates an element for the element handle specified.

Parameters:
qName - The element handle.
Returns:
A new SVGNode object.

addFont

public static int addFont(SVGDocument document,
                          SVGFontElem node)
Adds the given SVGNode font object to the font cache table.


getFont

public static SVGFontElem getFont(SVGDocument document,
                                  TinyString fontFamily)
Returns SVGNode font object for the given fontFamily value or null.


isZoomAndPanAnable

public boolean isZoomAndPanAnable()
Returns true if "magnification" is enabled. otherwise returns false.

Returns:
true if the current SVGT document allows zoom and pan operations; otherwise returns false.

addLinks

public void addLinks(SVGNode node)
Traverses SVG tree nodes and adds 'a' elements to linkTargets array.

Parameters:
node - The SVGNode node

addIds

public void addIds(SVGNode node)
Traverses SVG tree nodes and adds elements with IDs to idTable hash.

Parameters:
node - The SVGNode node

addAnimations

public void addAnimations(SVGNode node)
Traverses SVG tree nodes and adds animation elements to animTargets array.

Parameters:
node - The SVGNode node

getCurrentTime

public int getCurrentTime()
SMIL: Returns the current document time.


animate

public TinyRect animate(int t)
SMIL: The animation effect function F(t,u) The effect of an animation for any point in the duration of animations. This maps times and an underlying value to a value for the target attribute. A time value of 0 corresponds to the time at which the animation begins. F(t,u) combines the simple animation function f(t) with all the other aspects of animation and timing controls.

Parameters:
t - The document time (0<=t<).
Returns:
The dirty area needs to be updated.

postSMILEvent

public void postSMILEvent(int eventType,
                          TinyString theEvent)
SMIL: Posts the event from an animation element to the registered callback. The SMIL event type can be one of

Parameters:
eventType - The SMIL event type
theEvent - The SMIL event

resolveEventBased

public boolean resolveEventBased(TinyString id)
SMIL: Resolves event-based times of animation elements. The event-activation support provides a means of associating an event with the begin or active end time for an animation element. When the event is raised (e.g. when the user clicks on something), the associated time is resolved to a determinate time.

Parameters:
id - The Id-value or eventbase-element.
Returns:
True if the time was resolved, otherwise false.

resolveLinkBased

public boolean resolveLinkBased(TinyString id)
SMIL: Resolves link-based times of animation elements. Related to event-activation is link-activation. A hyperlink can be targeted at an animation element that does not have a scheduled begin time. When the link is traversed, the animation element begins.

Parameters:
id - The Id-value.
Returns:
True if the time was resolved, otherwise false.

TinyLine
v2.0

Provided under the terms of the TinyLine License Agreement that has been included with this distribution