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, string dir)
 
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...
 
Color ParseColor (string hex, double alpha)
 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...
 
bool FixDash [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...
 
double StrokeAlpha [set]
 Sets the given alpha. More...
 
double FillAlpha [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...
 
bool FixDash [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...
 
double FillAlpha [set]
 Default value 1. More...
 
double StrokeAlpha [set]
 Default value 1. 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

◆ mxGdiCanvas2D()

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

Constructs a new graphics export canvas.

Member Function Documentation

◆ Begin()

void com.mxgraph.mxGdiCanvas2D.Begin ( )
inline

◆ Close()

void com.mxgraph.mxGdiCanvas2D.Close ( )
inline

Closes the current path.

Implements com.mxgraph.mxICanvas2D.

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

◆ ConfigureImageGraphics()

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.

◆ CreateFont()

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

Hook for subclassers to implement font caching.

◆ CreateStringFormat()

static StringFormat com.mxgraph.mxGdiCanvas2D.CreateStringFormat ( string  align,
string  valign,
bool  wrap,
bool  clip 
)
inlinestatic

◆ CurveTo()

void com.mxgraph.mxGdiCanvas2D.CurveTo ( double  x1,
double  y1,
double  x2,
double  y2,
double  x3,
double  y3 
)
inline

◆ DrawImage()

void com.mxgraph.mxGdiCanvas2D.DrawImage ( Image  image,
Rectangle  bounds 
)
inlineprotected

Implements the call to the graphics API.

◆ Ellipse()

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().

◆ Fill()

void com.mxgraph.mxGdiCanvas2D.Fill ( )
inline

◆ FillAndStroke()

void com.mxgraph.mxGdiCanvas2D.FillAndStroke ( )
inline

◆ GetFontName()

String com.mxgraph.mxGdiCanvas2D.GetFontName ( String  family)
inlineprotected

Returns a font name for the given font family.

◆ GetImageBounds()

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.

◆ GetImageSize()

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

Returns the size for the given image.

◆ 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().

◆ LineTo()

void com.mxgraph.mxGdiCanvas2D.LineTo ( double  x,
double  y 
)
inline

◆ LoadImage()

Image com.mxgraph.mxGdiCanvas2D.LoadImage ( String  src)
inlineprotected

Loads the specified image.

References com.mxgraph.mxUtils.LoadImage().

◆ MoveTo()

void com.mxgraph.mxGdiCanvas2D.MoveTo ( double  x,
double  y 
)
inline

◆ PaintCurrentPath()

void com.mxgraph.mxGdiCanvas2D.PaintCurrentPath ( bool  filled,
bool  stroked 
)
inlineprotected

Parameters
value

◆ PaintShadow()

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

Parameters
value

◆ ParseColor() [1/2]

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.

◆ ParseColor() [2/2]

Color com.mxgraph.mxGdiCanvas2D.ParseColor ( string  hex,
double  alpha 
)
inlineprotected

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

can override this to implement caching for frequently used colors.

References com.mxgraph.mxConstants.NONE.

◆ QuadTo()

void com.mxgraph.mxGdiCanvas2D.QuadTo ( double  x1,
double  y1,
double  x2,
double  y2 
)
inline

◆ Rect()

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().

◆ Restore()

void com.mxgraph.mxGdiCanvas2D.Restore ( )
inline

Restores the last canvas state.

Implements com.mxgraph.mxICanvas2D.

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

◆ Rotate()

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().

◆ Roundrect()

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().

◆ Save()

void com.mxgraph.mxGdiCanvas2D.Save ( )
inline

◆ Scale()

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

Sets the given scale.

Parameters
value

Implements com.mxgraph.mxICanvas2D.

◆ SetGradient()

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

◆ SetShadowOffset()

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

Prepares the canvas to draw a gradient.

Implements com.mxgraph.mxICanvas2D.

◆ Stroke()

void com.mxgraph.mxGdiCanvas2D.Stroke ( )
inline

◆ Text()

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,
string  dir 
)
inline

◆ Translate()

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().

◆ UpdateFont()

void com.mxgraph.mxGdiCanvas2D.UpdateFont ( )
inlineprotected

◆ UpdatePen()

void com.mxgraph.mxGdiCanvas2D.UpdatePen ( )
inlineprotected

Member Data Documentation

◆ currentPath

GraphicsPath com.mxgraph.mxGdiCanvas2D.currentPath
protected

Holds the current path.

◆ graphics

Graphics com.mxgraph.mxGdiCanvas2D.graphics
protected

Reference to the graphics instance for painting.

◆ htmlAsPlainText

bool com.mxgraph.mxGdiCanvas2D.htmlAsPlainText = true
protected

htmlAsPlainText

◆ lastFont

Font com.mxgraph.mxGdiCanvas2D.lastFont = null
protected

FontCaching

◆ lastFontFamily

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

FontCaching

◆ lastFontSize

float com.mxgraph.mxGdiCanvas2D.lastFontSize = 0
protected

FontCaching

◆ lastFontStyle

FontStyle com.mxgraph.mxGdiCanvas2D.lastFontStyle = 0
protected

FontCaching

◆ lastPoint

mxPoint com.mxgraph.mxGdiCanvas2D.lastPoint
protected

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

current path is orthogonal.

◆ matchHtmlAlignment

bool com.mxgraph.mxGdiCanvas2D.matchHtmlAlignment = true
protected

matchHtmlAlignment

◆ stack

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

Stack of states for save/restore.

◆ state

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

Represents the current state of the canvas.

◆ wrapPlainText

bool com.mxgraph.mxGdiCanvas2D.wrapPlainText = true
protected

htmlAsPlainText

Property Documentation

◆ Alpha

double com.mxgraph.mxGdiCanvas2D.Alpha
set

◆ Dashed

bool com.mxgraph.mxGdiCanvas2D.Dashed
set

Specifies if lines are dashed.

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

◆ DashPattern

string com.mxgraph.mxGdiCanvas2D.DashPattern
set

Sets the dashpattern.

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

◆ FillAlpha

double com.mxgraph.mxGdiCanvas2D.FillAlpha
set

Sets the given alpha.

◆ FillColor

string com.mxgraph.mxGdiCanvas2D.FillColor
set

Sets the given fillcolor.

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

◆ FixDash

bool com.mxgraph.mxGdiCanvas2D.FixDash
set

Specifies if lines are dashed.

◆ FontBackgroundColor

string com.mxgraph.mxGdiCanvas2D.FontBackgroundColor
set

Default value 0. See mxConstants#STYLE_FONTSTYLE.

◆ FontBorderColor

string com.mxgraph.mxGdiCanvas2D.FontBorderColor
set

Default value 0. See mxConstants#STYLE_FONTSTYLE.

◆ FontColor

string com.mxgraph.mxGdiCanvas2D.FontColor
set

Sets the fontcolor.

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

◆ FontFamily

string com.mxgraph.mxGdiCanvas2D.FontFamily
set

Sets the font family.

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

◆ FontSize

double com.mxgraph.mxGdiCanvas2D.FontSize
set

Sets the fontsize.

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

◆ FontStyle

int com.mxgraph.mxGdiCanvas2D.FontStyle
set

Sets the given fontstyle.

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

◆ LineCap

string com.mxgraph.mxGdiCanvas2D.LineCap
set

Sets the linecap.

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

◆ LineJoin

string com.mxgraph.mxGdiCanvas2D.LineJoin
set

Sets the linejoin.

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

◆ MiterLimit

double com.mxgraph.mxGdiCanvas2D.MiterLimit
set

Sets the miterlimit.

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

◆ Shadow

bool com.mxgraph.mxGdiCanvas2D.Shadow
set

Default value mxConstants#NONE.

◆ ShadowAlpha

double com.mxgraph.mxGdiCanvas2D.ShadowAlpha
set

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

◆ ShadowColor

string com.mxgraph.mxGdiCanvas2D.ShadowColor
set

Default value mxConstants#NONE.

◆ StrokeAlpha

double com.mxgraph.mxGdiCanvas2D.StrokeAlpha
set

Sets the given alpha.

◆ StrokeColor

string com.mxgraph.mxGdiCanvas2D.StrokeColor
set

Caches color conversion as it is expensive.

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

◆ StrokeWidth

double com.mxgraph.mxGdiCanvas2D.StrokeWidth
set

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