mxGraph
Classes | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Properties | List of all members
com.mxgraph.mxGdiCanvas2D Class Reference

Used for exporting images. To render to an image from a given XML string, graph size and and background color, the following code is used: More...

Inheritance diagram for com.mxgraph.mxGdiCanvas2D:
com.mxgraph.mxICanvas2D

Classes

class  CanvasState
 

Public Member Functions

 mxGdiCanvas2D (Graphics g)
 
void Save ()
 
void Restore ()
 
void Scale (double value)
 Sets the given scale. More...
 
void Translate (double dx, double dy)
 Translates the canvas. More...
 
void Rotate (double theta, bool flipH, bool flipV, double cx, double cy)
 Rotates the canvas. More...
 
void SetShadowOffset (double dx, double dy)
 Prepares the canvas to draw a gradient. More...
 
void SetGradient (String color1, String color2, double x, double y, double w, double h, String direction, double alpha1, double alpha2)
 Sets the given gradient. More...
 
void Rect (double x, double y, double w, double h)
 Draws a rectangle. More...
 
void Roundrect (double x, double y, double w, double h, double dx, double dy)
 
void Ellipse (double x, double y, double w, double h)
 Draws an ellipse. More...
 
void Image (double x, double y, double w, double h, String src, bool aspect, bool flipH, bool flipV)
 Draws an image. More...
 
void Text (double x, double y, double w, double h, string str, string align, string valign, bool wrap, string format, string overflow, bool clip, double rotation)
 
void Begin ()
 
void MoveTo (double x, double y)
 
void LineTo (double x, double y)
 
void QuadTo (double x1, double y1, double x2, double y2)
 
void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3)
 
void Close ()
 
void Stroke ()
 
void Fill ()
 
void FillAndStroke ()
 
- Public Member Functions inherited from com.mxgraph.mxICanvas2D
void SetGradient (string color1, string color2, double x, double y, double w, double h, string direction, double alpha1, double alpha2)
 Prepares the canvas to draw a gradient. More...
 
void Image (double x, double y, double w, double h, string src, bool aspect, bool flipH, bool flipV)
 Draws the given image. More...
 

Static Public Member Functions

static StringFormat CreateStringFormat (string align, string valign, bool wrap, bool clip)
 Creates the specified string format. More...
 

Protected Member Functions

Color ParseColor (string hex)
 Helper method that uses mxUtils#parseColor(String). Subclassers More...
 
void DrawImage (Image image, Rectangle bounds)
 Implements the call to the graphics API. More...
 
Image LoadImage (String src)
 Loads the specified image. More...
 
Rectangle GetImageBounds (Image img, double x, double y, double w, double h, bool aspect)
 Returns the bounds for the given image. More...
 
Size GetImageSize (Image image)
 Returns the size for the given image. More...
 
void ConfigureImageGraphics (double x, double y, double w, double h, bool flipH, bool flipV)
 
PointF GetMargin (String align, String valign)
 
void PaintCurrentPath (bool filled, bool stroked)
 
void PaintShadow (bool filled, bool stroked)
 
void UpdateFont ()
 
Font CreateFont (String family, FontStyle style, float size)
 
String GetFontName (String family)
 Returns a font name for the given font family. More...
 
void UpdatePen ()
 

Protected Attributes

bool matchHtmlAlignment = true
 matchHtmlAlignment More...
 
bool htmlAsPlainText = true
 htmlAsPlainText More...
 
bool wrapPlainText = true
 htmlAsPlainText More...
 
Graphics graphics
 
CanvasState state = new CanvasState()
 
Stack< CanvasStatestack = new Stack<CanvasState>()
 
GraphicsPath currentPath
 
mxPoint lastPoint
 Holds the last point of a moveTo or lineTo operation to determine if the More...
 
Font lastFont = null
 FontCaching More...
 
FontStyle lastFontStyle = 0
 FontCaching More...
 
float lastFontSize = 0
 FontCaching More...
 
String lastFontFamily = ""
 FontCaching More...
 

Properties

double StrokeWidth [set]
 Sets the strokewidth. More...
 
string StrokeColor [set]
 
bool Dashed [set]
 Specifies if lines are dashed. More...
 
string DashPattern [set]
 Sets the dashpattern. More...
 
string LineCap [set]
 Sets the linecap. More...
 
string LineJoin [set]
 Sets the linejoin. More...
 
double MiterLimit [set]
 Sets the miterlimit. More...
 
double FontSize [set]
 Sets the fontsize. More...
 
string FontColor [set]
 Sets the fontcolor. More...
 
string FontBackgroundColor [set]
 Default value 0. See mxConstants#STYLE_FONTSTYLE. More...
 
string FontBorderColor [set]
 Default value 0. See mxConstants#STYLE_FONTSTYLE. More...
 
string FontFamily [set]
 Sets the font family. More...
 
int FontStyle [set]
 Sets the given fontstyle. More...
 
double Alpha [set]
 Sets the given alpha. More...
 
string FillColor [set]
 Sets the given fillcolor. More...
 
bool Shadow [set]
 Default value mxConstants#NONE. More...
 
string ShadowColor [set]
 Default value mxConstants#NONE. More...
 
double ShadowAlpha [set]
 Default value 1. This method may add rendering overhead and should be used with care. More...
 
- Properties inherited from com.mxgraph.mxICanvas2D
double StrokeWidth [set]
 Sets the stroke width. This should default to 1 if unset. More...
 
string StrokeColor [set]
 Sets the stroke color. This should default to mxConstants.NONE if unset. More...
 
bool Dashed [set]
 Sets the dashed state. This should default to false if unset. More...
 
string DashPattern [set]
 Sets the dash pattern. This should default to "3 3" if unset. More...
 
string LineCap [set]
 Sets the linecap. This should default to "flat" if unset. More...
 
string LineJoin [set]
 Sets the linejoin. This should default to "miter" if unset. More...
 
double MiterLimit [set]
 Sets the miterlimit. This should default to 10 if unset. More...
 
double FontSize [set]
 Default value mxConstants.DEFAULT_FONTSIZE. More...
 
string FontColor [set]
 Default value "#000000". More...
 
string FontFamily [set]
 Default value mxConstants#DEFAULT_FONTFAMILY. More...
 
int FontStyle [set]
 Default value 0. See mxConstants#STYLE_FONTSTYLE. More...
 
string FontBackgroundColor [set]
 Default value 0. See mxConstants#STYLE_FONTSTYLE. More...
 
string FontBorderColor [set]
 Default value 0. See mxConstants#STYLE_FONTSTYLE. More...
 
double Alpha [set]
 Default value 1. This method may add rendering overhead and should be used with care. More...
 
string FillColor [set]
 Default value mxConstants#NONE. More...
 
bool Shadow [set]
 Default value mxConstants#NONE. More...
 
string ShadowColor [set]
 Default value mxConstants#NONE. More...
 
double ShadowAlpha [set]
 Default value 1. This method may add rendering overhead and should be used with care. More...
 

Detailed Description

Used for exporting images. To render to an image from a given XML string, graph size and and background color, the following code is used:

Image image = mxUtils.CreateImage(width, height, background); Graphics g = Graphics.FromImage(image); g.SmoothingMode = SmoothingMode.HighQuality; mxSaxOutputHandler handler = new mxSaxOutputHandler(new mxGdiCanvas2D(g)); handler.Read(new XmlTextReader(new StringReader(xml)));

Text rendering is available for plain text only, with optional word wrapping.

Constructor & Destructor Documentation

com.mxgraph.mxGdiCanvas2D.mxGdiCanvas2D ( Graphics  g)
inline

Constructs a new graphics export canvas.

Member Function Documentation

void com.mxgraph.mxGdiCanvas2D.Begin ( )
inline
void com.mxgraph.mxGdiCanvas2D.Close ( )
inline

Closes the current path.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.ConfigureImageGraphics ( double  x,
double  y,
double  w,
double  h,
bool  flipH,
bool  flipV 
)
inlineprotected

Creates a graphic instance for rendering an image.

Font com.mxgraph.mxGdiCanvas2D.CreateFont ( String  family,
FontStyle  style,
float  size 
)
inlineprotected

Hook for subclassers to implement font caching.

static StringFormat com.mxgraph.mxGdiCanvas2D.CreateStringFormat ( string  align,
string  valign,
bool  wrap,
bool  clip 
)
inlinestatic
void com.mxgraph.mxGdiCanvas2D.CurveTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
inline
void com.mxgraph.mxGdiCanvas2D.DrawImage ( Image  image,
Rectangle  bounds 
)
inlineprotected

Implements the call to the graphics API.

void com.mxgraph.mxGdiCanvas2D.Ellipse ( double  x,
double  y,
double  w,
double  h 
)
inline

Draws an ellipse.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.Fill ( )
inline
void com.mxgraph.mxGdiCanvas2D.FillAndStroke ( )
inline
String com.mxgraph.mxGdiCanvas2D.GetFontName ( String  family)
inlineprotected

Returns a font name for the given font family.

Rectangle com.mxgraph.mxGdiCanvas2D.GetImageBounds ( Image  img,
double  x,
double  y,
double  w,
double  h,
bool  aspect 
)
inlineprotected

Returns the bounds for the given image.

Size com.mxgraph.mxGdiCanvas2D.GetImageSize ( Image  image)
inlineprotected

Returns the size for the given image.

void com.mxgraph.mxGdiCanvas2D.Image ( double  x,
double  y,
double  w,
double  h,
String  src,
bool  aspect,
bool  flipH,
bool  flipV 
)
inline

Draws an image.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.LineTo ( double  x,
double  y 
)
inline
Image com.mxgraph.mxGdiCanvas2D.LoadImage ( String  src)
inlineprotected

Loads the specified image.

References com.mxgraph.mxUtils.LoadImage().

void com.mxgraph.mxGdiCanvas2D.MoveTo ( double  x,
double  y 
)
inline
void com.mxgraph.mxGdiCanvas2D.PaintCurrentPath ( bool  filled,
bool  stroked 
)
inlineprotected

Parameters
value
void com.mxgraph.mxGdiCanvas2D.PaintShadow ( bool  filled,
bool  stroked 
)
inlineprotected

Parameters
value
Color com.mxgraph.mxGdiCanvas2D.ParseColor ( string  hex)
inlineprotected

Helper method that uses mxUtils#parseColor(String). Subclassers

can override this to implement caching for frequently used colors.

References com.mxgraph.mxConstants.NONE.

void com.mxgraph.mxGdiCanvas2D.QuadTo ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline
void com.mxgraph.mxGdiCanvas2D.Rect ( double  x,
double  y,
double  w,
double  h 
)
inline

Draws a rectangle.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.Restore ( )
inline

Restores the last canvas state.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.Rotate ( double  theta,
bool  flipH,
bool  flipV,
double  cx,
double  cy 
)
inline

Rotates the canvas.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.PaintShape().

void com.mxgraph.mxGdiCanvas2D.Roundrect ( double  x,
double  y,
double  w,
double  h,
double  dx,
double  dy 
)
inline

Draws a rounded rectangle.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.Save ( )
inline

Saves the current canvas state.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement(), and com.mxgraph.mxStencil.PaintShape().

void com.mxgraph.mxGdiCanvas2D.Scale ( double  value)
inline

Sets the given scale.

Parameters
value

Implements com.mxgraph.mxICanvas2D.

void com.mxgraph.mxGdiCanvas2D.SetGradient ( String  color1,
String  color2,
double  x,
double  y,
double  w,
double  h,
String  direction,
double  alpha1,
double  alpha2 
)
inline
void com.mxgraph.mxGdiCanvas2D.SetShadowOffset ( double  dx,
double  dy 
)
inline

Prepares the canvas to draw a gradient.

Implements com.mxgraph.mxICanvas2D.

void com.mxgraph.mxGdiCanvas2D.Stroke ( )
inline
void com.mxgraph.mxGdiCanvas2D.Text ( double  x,
double  y,
double  w,
double  h,
string  str,
string  align,
string  valign,
bool  wrap,
string  format,
string  overflow,
bool  clip,
double  rotation 
)
inline

Draws the given text.

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawElement().

void com.mxgraph.mxGdiCanvas2D.Translate ( double  dx,
double  dy 
)
inline

Translates the canvas.

Parameters
dx
dy

Implements com.mxgraph.mxICanvas2D.

Referenced by com.mxgraph.mxStencil.DrawShadow().

void com.mxgraph.mxGdiCanvas2D.UpdateFont ( )
inlineprotected
void com.mxgraph.mxGdiCanvas2D.UpdatePen ( )
inlineprotected

Member Data Documentation

GraphicsPath com.mxgraph.mxGdiCanvas2D.currentPath
protected

Holds the current path.

Graphics com.mxgraph.mxGdiCanvas2D.graphics
protected

Reference to the graphics instance for painting.

bool com.mxgraph.mxGdiCanvas2D.htmlAsPlainText = true
protected

htmlAsPlainText

Font com.mxgraph.mxGdiCanvas2D.lastFont = null
protected

FontCaching

String com.mxgraph.mxGdiCanvas2D.lastFontFamily = ""
protected

FontCaching

float com.mxgraph.mxGdiCanvas2D.lastFontSize = 0
protected

FontCaching

FontStyle com.mxgraph.mxGdiCanvas2D.lastFontStyle = 0
protected

FontCaching

mxPoint com.mxgraph.mxGdiCanvas2D.lastPoint
protected

Holds the last point of a moveTo or lineTo operation to determine if the

current path is orthogonal.

bool com.mxgraph.mxGdiCanvas2D.matchHtmlAlignment = true
protected

matchHtmlAlignment

Stack<CanvasState> com.mxgraph.mxGdiCanvas2D.stack = new Stack<CanvasState>()
protected

Stack of states for save/restore.

CanvasState com.mxgraph.mxGdiCanvas2D.state = new CanvasState()
protected

Represents the current state of the canvas.

bool com.mxgraph.mxGdiCanvas2D.wrapPlainText = true
protected

htmlAsPlainText

Property Documentation

double com.mxgraph.mxGdiCanvas2D.Alpha
set
bool com.mxgraph.mxGdiCanvas2D.Dashed
set

Specifies if lines are dashed.

Referenced by com.mxgraph.mxStencil.DrawElement(), and com.mxgraph.mxStencil.PaintShape().

string com.mxgraph.mxGdiCanvas2D.DashPattern
set

Sets the dashpattern.

Referenced by com.mxgraph.mxStencil.DrawElement().

string com.mxgraph.mxGdiCanvas2D.FillColor
set

Sets the given fillcolor.

Referenced by com.mxgraph.mxStencil.DrawElement(), and com.mxgraph.mxStencil.PaintShape().

string com.mxgraph.mxGdiCanvas2D.FontBackgroundColor
set

Default value 0. See mxConstants#STYLE_FONTSTYLE.

string com.mxgraph.mxGdiCanvas2D.FontBorderColor
set

Default value 0. See mxConstants#STYLE_FONTSTYLE.

string com.mxgraph.mxGdiCanvas2D.FontColor
set

Sets the fontcolor.

Referenced by com.mxgraph.mxStencil.DrawElement().

string com.mxgraph.mxGdiCanvas2D.FontFamily
set

Sets the font family.

Referenced by com.mxgraph.mxStencil.DrawElement().

double com.mxgraph.mxGdiCanvas2D.FontSize
set

Sets the fontsize.

Referenced by com.mxgraph.mxStencil.DrawElement().

int com.mxgraph.mxGdiCanvas2D.FontStyle
set

Sets the given fontstyle.

Referenced by com.mxgraph.mxStencil.DrawElement().

string com.mxgraph.mxGdiCanvas2D.LineCap
set

Sets the linecap.

Referenced by com.mxgraph.mxStencil.DrawElement().

string com.mxgraph.mxGdiCanvas2D.LineJoin
set

Sets the linejoin.

Referenced by com.mxgraph.mxStencil.DrawElement().

double com.mxgraph.mxGdiCanvas2D.MiterLimit
set

Sets the miterlimit.

Referenced by com.mxgraph.mxStencil.DrawElement().

bool com.mxgraph.mxGdiCanvas2D.Shadow
set

Default value mxConstants#NONE.

double com.mxgraph.mxGdiCanvas2D.ShadowAlpha
set

Default value 1. This method may add rendering overhead and should be used with care.

string com.mxgraph.mxGdiCanvas2D.ShadowColor
set

Default value mxConstants#NONE.

string com.mxgraph.mxGdiCanvas2D.StrokeColor
set

Caches color conversion as it is expensive.

Referenced by com.mxgraph.mxStencil.DrawElement(), and com.mxgraph.mxStencil.PaintShape().

double com.mxgraph.mxGdiCanvas2D.StrokeWidth
set

The documentation for this class was generated from the following file: