mxGraph
|
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)));
Classes | |
class | CanvasState |
Public Member Functions | |
mxGdiCanvas2D (Graphics g) | |
void | Save () |
void | Restore () |
void | Scale (double value) |
Sets the given scale. | |
void | Translate (double dx, double dy) |
Translates the canvas. | |
void | Rotate (double theta, bool flipH, bool flipV, double cx, double cy) |
Rotates the canvas. | |
void | SetShadowOffset (double dx, double dy) |
Prepares the canvas to draw a gradient. | |
void | SetGradient (String color1, String color2, double x, double y, double w, double h, String direction, double alpha1, double alpha2) |
Sets the given gradient. | |
void | Rect (double x, double y, double w, double h) |
Draws a rectangle. | |
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. | |
void | Image (double x, double y, double w, double h, String src, bool aspect, bool flipH, bool flipV) |
Draws an image. | |
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 () |
Static Public Member Functions | |
static StringFormat | CreateStringFormat (string align, string valign, bool wrap, bool clip) |
Creates the specified string format. | |
Protected Member Functions | |
Color | ParseColor (string hex) |
Helper method that uses mxUtils#parseColor(String). Subclassers. | |
void | DrawImage (Image image, Rectangle bounds) |
Implements the call to the graphics API. | |
Image | LoadImage (String src) |
Loads the specified image. | |
Rectangle | GetImageBounds (Image img, double x, double y, double w, double h, bool aspect) |
Returns the bounds for the given image. | |
Size | GetImageSize (Image image) |
Returns the size for the given image. | |
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. | |
void | UpdatePen () |
Protected Attributes | |
bool | matchHtmlAlignment = true |
matchHtmlAlignment | |
bool | htmlAsPlainText = true |
htmlAsPlainText | |
bool | wrapPlainText = true |
htmlAsPlainText | |
Graphics | graphics |
CanvasState | state = new CanvasState() |
Stack< CanvasState > | stack = new Stack<CanvasState>() |
GraphicsPath | currentPath |
mxPoint | lastPoint |
Holds the last point of a moveTo or lineTo operation to determine if the. | |
Font | lastFont = null |
FontCaching. | |
FontStyle | lastFontStyle = 0 |
FontCaching. | |
float | lastFontSize = 0 |
FontCaching. | |
String | lastFontFamily = "" |
FontCaching. | |
Properties | |
double | StrokeWidth [set] |
Sets the strokewidth. | |
string | StrokeColor [set] |
bool | Dashed [set] |
Specifies if lines are dashed. | |
string | DashPattern [set] |
Sets the dashpattern. | |
string | LineCap [set] |
Sets the linecap. | |
string | LineJoin [set] |
Sets the linejoin. | |
double | MiterLimit [set] |
Sets the miterlimit. | |
double | FontSize [set] |
Sets the fontsize. | |
string | FontColor [set] |
Sets the fontcolor. | |
string | FontBackgroundColor [set] |
Default value 0. See mxConstants#STYLE_FONTSTYLE. | |
string | FontBorderColor [set] |
Default value 0. See mxConstants#STYLE_FONTSTYLE. | |
string | FontFamily [set] |
Sets the font family. | |
int | FontStyle [set] |
Sets the given fontstyle. | |
double | Alpha [set] |
Sets the given alpha. | |
string | FillColor [set] |
Sets the given fillcolor. | |
bool | Shadow [set] |
Default value mxConstants#NONE. | |
string | ShadowColor [set] |
Default value mxConstants#NONE. | |
double | ShadowAlpha [set] |
Default value 1. This method may add rendering overhead and should be used with care. |
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.
com.mxgraph.mxGdiCanvas2D.mxGdiCanvas2D | ( | Graphics | g | ) | [inline] |
Constructs a new graphics export canvas.
void com.mxgraph.mxGdiCanvas2D.Begin | ( | ) | [inline] |
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.Close | ( | ) | [inline] |
Closes the current path.
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.ConfigureImageGraphics | ( | double | x, |
double | y, | ||
double | w, | ||
double | h, | ||
bool | flipH, | ||
bool | flipV | ||
) | [inline, protected] |
Creates a graphic instance for rendering an image.
Font com.mxgraph.mxGdiCanvas2D.CreateFont | ( | String | family, |
FontStyle | style, | ||
float | size | ||
) | [inline, protected] |
Hook for subclassers to implement font caching.
static StringFormat com.mxgraph.mxGdiCanvas2D.CreateStringFormat | ( | string | align, |
string | valign, | ||
bool | wrap, | ||
bool | clip | ||
) | [inline, static] |
Creates the specified string format.
void com.mxgraph.mxGdiCanvas2D.CurveTo | ( | double | x1, |
double | y1, | ||
double | x2, | ||
double | y2, | ||
double | x3, | ||
double | y3 | ||
) | [inline] |
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.DrawImage | ( | Image | image, |
Rectangle | bounds | ||
) | [inline, protected] |
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.
void com.mxgraph.mxGdiCanvas2D.Fill | ( | ) | [inline] |
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.FillAndStroke | ( | ) | [inline] |
Implements com.mxgraph.mxICanvas2D.
String com.mxgraph.mxGdiCanvas2D.GetFontName | ( | String | family | ) | [inline, protected] |
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 | ||
) | [inline, protected] |
Returns the bounds for the given image.
Size com.mxgraph.mxGdiCanvas2D.GetImageSize | ( | Image | image | ) | [inline, protected] |
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.
void com.mxgraph.mxGdiCanvas2D.LineTo | ( | double | x, |
double | y | ||
) | [inline] |
Implements com.mxgraph.mxICanvas2D.
Image com.mxgraph.mxGdiCanvas2D.LoadImage | ( | String | src | ) | [inline, protected] |
Loads the specified image.
void com.mxgraph.mxGdiCanvas2D.MoveTo | ( | double | x, |
double | y | ||
) | [inline] |
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.PaintCurrentPath | ( | bool | filled, |
bool | stroked | ||
) | [inline, protected] |
value |
void com.mxgraph.mxGdiCanvas2D.PaintShadow | ( | bool | filled, |
bool | stroked | ||
) | [inline, protected] |
value |
Color com.mxgraph.mxGdiCanvas2D.ParseColor | ( | string | hex | ) | [inline, protected] |
Helper method that uses mxUtils#parseColor(String). Subclassers.
can override this to implement caching for frequently used colors.
void com.mxgraph.mxGdiCanvas2D.QuadTo | ( | double | x1, |
double | y1, | ||
double | x2, | ||
double | y2 | ||
) | [inline] |
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.Rect | ( | double | x, |
double | y, | ||
double | w, | ||
double | h | ||
) | [inline] |
Draws a rectangle.
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.Restore | ( | ) | [inline] |
Restores the last canvas state.
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.Rotate | ( | double | theta, |
bool | flipH, | ||
bool | flipV, | ||
double | cx, | ||
double | cy | ||
) | [inline] |
Rotates the canvas.
Implements com.mxgraph.mxICanvas2D.
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.
void com.mxgraph.mxGdiCanvas2D.Save | ( | ) | [inline] |
Saves the current canvas state.
Implements com.mxgraph.mxICanvas2D.
void com.mxgraph.mxGdiCanvas2D.Scale | ( | double | value | ) | [inline] |
void com.mxgraph.mxGdiCanvas2D.SetGradient | ( | String | color1, |
String | color2, | ||
double | x, | ||
double | y, | ||
double | w, | ||
double | h, | ||
String | direction, | ||
double | alpha1, | ||
double | alpha2 | ||
) | [inline] |
Sets the given gradient.
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] |
Implements com.mxgraph.mxICanvas2D.
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.
void com.mxgraph.mxGdiCanvas2D.Translate | ( | double | dx, |
double | dy | ||
) | [inline] |
void com.mxgraph.mxGdiCanvas2D.UpdateFont | ( | ) | [inline, protected] |
void com.mxgraph.mxGdiCanvas2D.UpdatePen | ( | ) | [inline, protected] |
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
double com.mxgraph.mxGdiCanvas2D.Alpha [set] |
Sets the given alpha.
Implements com.mxgraph.mxICanvas2D.
bool com.mxgraph.mxGdiCanvas2D.Dashed [set] |
Specifies if lines are dashed.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.DashPattern [set] |
Sets the dashpattern.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.FillColor [set] |
Sets the given fillcolor.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.FontBackgroundColor [set] |
Default value 0. See mxConstants#STYLE_FONTSTYLE.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.FontBorderColor [set] |
Default value 0. See mxConstants#STYLE_FONTSTYLE.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.FontColor [set] |
Sets the fontcolor.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.FontFamily [set] |
Sets the font family.
Implements com.mxgraph.mxICanvas2D.
double com.mxgraph.mxGdiCanvas2D.FontSize [set] |
Sets the fontsize.
Implements com.mxgraph.mxICanvas2D.
int com.mxgraph.mxGdiCanvas2D.FontStyle [set] |
Sets the given fontstyle.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.LineCap [set] |
Sets the linecap.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.LineJoin [set] |
Sets the linejoin.
Implements com.mxgraph.mxICanvas2D.
double com.mxgraph.mxGdiCanvas2D.MiterLimit [set] |
Sets the miterlimit.
Implements com.mxgraph.mxICanvas2D.
bool com.mxgraph.mxGdiCanvas2D.Shadow [set] |
Default value mxConstants#NONE.
Implements com.mxgraph.mxICanvas2D.
double com.mxgraph.mxGdiCanvas2D.ShadowAlpha [set] |
Default value 1. This method may add rendering overhead and should be used with care.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.ShadowColor [set] |
Default value mxConstants#NONE.
Implements com.mxgraph.mxICanvas2D.
string com.mxgraph.mxGdiCanvas2D.StrokeColor [set] |
Caches color conversion as it is expensive.
Implements com.mxgraph.mxICanvas2D.
double com.mxgraph.mxGdiCanvas2D.StrokeWidth [set] |
Sets the strokewidth.
Implements com.mxgraph.mxICanvas2D.