wxLatexDC is a device context that will generate a LaTeX2e file from graphics and text that were drawn onto it. It makes use of PSTricks (http://tug.org/PSTricks) to create Tex-compatible PostScript macros. I've shamelessly copied large parts of the code from the wxSVGFileDC and wxPostScriptDC classes. You can create a wxLatexDC in exactly the same way as a wxSVGFileDC. At present, only a small part of the DC drawing functions have been implemented. The major advantage of using LaTeX output rather than directly writing PostScript is that typesetting can be done in LaTeX, so that graphics seamlessly integrate into documents. A positive side effect is that the PSTricks macros are more easily readable than plain PostScript. The obvious disadvantage is that wxLatexDC can't know which font type and size will be used in the final document, so that all the functions that try to retrieve information about text size will not work (see comment in GetCharHeight). To still be able to position text precisely at the location that you want to have it in your final LaTeX document, you can make use of wxLatexDC::DrawLabelLatex which uses the same syntax as wxDC::DrawLabel(). This allows you to set your text alignment (left, right, top, bottom, horizontal and vertical center) relative to the wxRect that is passed as an argument.
Derived from
wxDC
Include files
<wx/dclatex.h>
Library
None (wxCode)
Members
wxLatexDC::wxLatexDC
wxLatexDC::~wxLatexDC
wxLatexDC::BeginDrawing
wxLatexDC::Blit
wxLatexDC::CalcBoundingBox
wxLatexDC::Clear
wxLatexDC::CrossHair
wxLatexDC::DestroyClippingRegion
wxLatexDC::DeviceToLogicalX
wxLatexDC::DeviceToLogicalXRel
wxLatexDC::DeviceToLogicalY
wxLatexDC::DeviceToLogicalYRel
wxLatexDC::DrawArc
wxLatexDC::DrawBitmap
wxLatexDC::DrawCheckMark
wxLatexDC::DrawCircle
wxLatexDC::DrawEllipse
wxLatexDC::DrawEllipticArc
wxLatexDC::DrawIcon
wxLatexDC::DrawLabelLatex
wxLatexDC::DrawLine
wxLatexDC::DrawLines
wxLatexDC::DrawPolygon
wxLatexDC::DrawPoint
wxLatexDC::DrawRectangle
wxLatexDC::DrawRotatedText
wxLatexDC::DrawRoundedRectangle
wxLatexDC::DrawSpline
wxLatexDC::DrawText
wxLatexDC::EndDoc
wxLatexDC::EndDrawing
wxLatexDC::EndPage
wxLatexDC::FloodFill
wxLatexDC::GetBackground
wxLatexDC::GetBackgroundMode
wxLatexDC::GetBrush
wxLatexDC::GetCharHeight
wxLatexDC::GetCharWidth
wxLatexDC::GetClippingBox
wxLatexDC::GetFont
wxLatexDC::GetLogicalFunction
wxLatexDC::GetMapMode
wxLatexDC::GetPen
wxLatexDC::GetPixel
wxLatexDC::GetSize
wxLatexDC::GetTextBackground
wxLatexDC::GetTextExtent
wxLatexDC::GetTextForeground
wxLatexDC::GetUserScale
wxLatexDC::LogicalToDeviceX
wxLatexDC::LogicalToDeviceXRel
wxLatexDC::LogicalToDeviceY
wxLatexDC::LogicalToDeviceYRel
wxLatexDC::MaxX
wxLatexDC::MaxY
wxLatexDC::MinX
wxLatexDC::MinY
wxLatexDC::Ok
wxLatexDC::ResetBoundingBox
wxLatexDC::SetAxisOrientation
wxLatexDC::SetDeviceOrigin
wxLatexDC::SetBackground
wxLatexDC::SetBackgroundMode
wxLatexDC::SetClippingRegion
wxLatexDC::SetPalette
wxLatexDC::SetBrush
wxLatexDC::SetFont
wxLatexDC::SetLogicalFunction
wxLatexDC::SetMapMode
wxLatexDC::SetPen
wxLatexDC::SetTextBackground
wxLatexDC::SetTextForeground
wxLatexDC::SetUserScale
wxLatexDC::StartDoc
wxLatexDC::StartPage
Constructors:
wxLatexDC(wxString filename)
Creates a file (filename) with default size 340x240 at 72.0 dots per inch (a frequent screen resolution).
wxLatexDC(wxString filename, int Width,int Height)
Creates a file (filename) with size Width by Height at 72.0 dots per inch
wxLatexDC(wxString filename, int Width,int Height,float dpi)
Creates a file (filename) with size Width by Height at dpi resolution.
~wxLatexDC()
Destructor.
Does nothing
bool Blit(wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord height, wxLatexDC* source, wxCoord xsrc, wxCoord ysrc, int logicalFunc = wxCOPY, bool useMask = FALSE, wxCoord xsrcMask = -1, wxCoord ysrcMask = -1)
Not implemented yet.
void CalcBoundingBox(wxCoord x, wxCoord y)
Adds the specified point to the bounding box which can be retrieved with MinX, MaxX and MinY, MaxY functions.
Note that the size and type of the fonts that will be used in the final document are not known when a wxLatexDC is created. Therefore, the extent of any text in the drawing will not be accounted for when the bounding box is calculated.
void Clear()
Does nothing.
void CrossHair(wxCoord x, wxCoord y)
Not Implemented
void DestroyClippingRegion()
Not Implemented
wxCoord DeviceToLogicalX(wxCoord x)
Convert device X coordinate to logical coordinate, using the current mapping mode.
wxCoord DeviceToLogicalXRel(wxCoord x)
Convert device X coordinate to relative logical coordinate, using the current mapping mode but ignoring the x axis orientation. Use this function for converting a width, for example.
wxCoord DeviceToLogicalY(wxCoord y)
Converts device Y coordinate to logical coordinate, using the current mapping mode.
wxCoord DeviceToLogicalYRel(wxCoord y)
Convert device Y coordinate to relative logical coordinate, using the current mapping mode but ignoring the y axis orientation. Use this function for converting a height, for example.
void DrawArc(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord xc, wxCoord yc)
Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) and ending at (x2, y2). The current pen is used for the outline and the current brush for filling the shape.
The arc is drawn in an anticlockwise direction from the start point to the end point.
void DrawBitmap(const wxBitmap& bitmap, wxCoord x, wxCoord y, bool transparent)
Not implemented. Would require converting the bitmap into an eps, I believe. Feel free to implement that.
void DrawCheckMark(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
void DrawCheckMark(const wxRect &rect)
Draws a check mark inside the given rectangle.
void DrawCircle(wxCoord x, wxCoord y, wxCoord radius)
void DrawCircle(const wxPoint& pt, wxCoord radius)
Draws a circle with the given centre and radius.
See also
void DrawEllipse(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
void DrawEllipse(const wxPoint& pt, const wxSize& size)
void DrawEllipse(const wxRect& rect)
Draws an ellipse contained in the rectangle specified either with the given top left corner and the given size or directly. The current pen is used for the outline and the current brush for filling the shape.
See also
void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double start, double end)
Draws an arc of an ellipse. The current pen is used for drawing the arc and the current brush is used for drawing the pie.
x and y specify the x and y coordinates of the upper-left corner of the rectangle that contains the ellipse.
width and height specify the width and height of the rectangle that contains the ellipse.
start and end specify the start and end of the arc relative to the three-o'clock position from the center of the rectangle. Angles are specified in degrees (360 is a complete circle). Positive values mean counter-clockwise motion. If start is equal to end, a complete ellipse will be drawn.
void DrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
Not implemented yet. See comment in DrawBitmap.
void DrawLabelLatex(const wxString& text, const wxRect& rect, int alignment = wxALIGN_LEFT | wxALIGN_TOP, int indexAccel = -1)
Draws text with the specified alignment relative to the rect. The rationale for having this function is that you can precisely position the rect on your drawing, and then align your text using this rectangle as a reference. The alignment will be kept even in your final document, independent of which font you will use in LaTeX. I couldn't find a way of overriding wxDC::DrawLabel to do exactly that, please notify me if you find a solution.
See also
void DrawLine(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Draws a line from the first point to the second. The current pen is used for drawing the line.
void DrawLines(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0)
void DrawLines(wxList *points, wxCoord xoffset = 0, wxCoord yoffset = 0)
Draws lines using an array of points of size n, or list of pointers to points, adding the optional offset coordinate. The current pen is used for drawing the lines. The programmer is responsible for deleting the list of points.
void DrawPolygon(int n, wxPoint points[], wxCoord xoffset = 0, wxCoord yoffset = 0,
int fill_style = wxODDEVEN_RULE)
void DrawPolygon(wxList *points, wxCoord xoffset = 0, wxCoord yoffset = 0,
int fill_style = wxODDEVEN_RULE)
Draws a filled polygon using an array of points of size n, or list of pointers to points, adding the optional offset coordinate.
The last argument specifies the fill rule: wxODDEVEN_RULE (the default) or wxWINDING_RULE.
The current pen is used for drawing the outline, and the current brush for filling the shape. Using a transparent brush suppresses filling. The programmer is responsible for deleting the list of points.
Note that wxWindows automatically closes the first and last points.
Only few filling styles have been implemented yet.
void DrawPoint(wxCoord x, wxCoord y)
Draws a point using the current pen.
void DrawRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
Draws a rectangle with the given top left corner, and with the given size. The current pen is used for the outline and the current brush for filling the shape.
void DrawRotatedText(const wxString& text, wxCoord x, wxCoord y, double angle)
Draws the text rotated by angle degrees. See comments in DrawLabelLatex, CalcBoundingBox and DrawText if you want to have better control of text positioning in your final LaTeX document.
See also
void DrawRoundedRectangle(wxCoord x, wxCoord y, wxCoord width, wxCoord height, double radius = 20)
Draws a rectangle with the given top left corner, and with the given size. The corners are quarter-circles using the given radius. The current pen is used for the outline and the current brush for filling the shape.
If radius is positive, the value is assumed to be the radius of the rounded corner. If radius is negative, the absolute value is assumed to be the proportion of the smallest dimension of the rectangle. This means that the corner can be a sensible size relative to the size of the rectangle, and also avoids the strange effects X produces when the corners are too big for the rectangle.
void DrawSpline(wxList *points)
This uses the base class implementation to draw a spline, which doesn't give nice results at present.
void DrawSpline(wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2, wxCoord x3, wxCoord y3)
This uses the base class implementation to draw a spline, which doesn't give nice results at present.
void DrawText(const wxString& text, wxCoord x, wxCoord y)
Draws a text string at the specified point, using the current text font, and the current text foreground and background colours.
The coordinates refer to the top-left corner of the rectangle bounding the string. Note that wxLatexDC has no idea which font you will use in your final LaTeX document, so there is no way how to find out the extent of the text. See DrawLabelLatex if you want to have better control of text positioning in your final LaTeX document.
See also
DrawLabelLatex, DrawRotatedText
void EndDoc()
Does nothing
void EndDrawing()
Does nothing
void EndPage()
Does nothing
void FloodFill(wxCoord x, wxCoord y, const wxColour& colour, int style=wxFLOOD_SURFACE)
Not implemented
wxBrush& GetBackground()
const wxBrush& GetBackground() const
Not implemented.
int GetBackgroundMode() const
Not implemented.
See also
wxBrush& GetBrush()
const wxBrush& GetBrush() const
Gets the current brush (see wxLatexDC::SetBrush).
wxCoord GetCharHeight()
Not implemented: Since wxLatexDC has no idea which font you will use in your final LaTeX document, there is no way to find out anything about character size and font style.
wxCoord GetCharWidth()
Not implemented: See GetCharHeight for reasons.
void GetClippingBox(wxCoord *x, wxCoord *y, wxCoord *width, wxCoord *height)
Not implemented
wxFont& GetFont()
const wxFont& GetFont() const
Not implemented: See GetCharHeight for reasons.
int GetLogicalFunction()
Gets the current logical function (see wxLatexDC::SetLogicalFunction).
int GetMapMode()
Gets the mapping mode for the device context (see wxLatexDC::SetMapMode).
wxPen& GetPen()
const wxPen& GetPen() const
Gets the current pen (see wxLatexDC::SetPen).
bool GetPixel(wxCoord x, wxCoord y, wxColour *colour)
Not implemented
void GetSize(wxCoord *width, wxCoord *height)
For a Windows printer device context, this gets the horizontal and vertical resolution.
wxColour& GetTextBackground()
const wxColour& GetTextBackground() const
Gets the current text background colour (see wxLatexDC::SetTextBackground).
void GetTextExtent(const wxString& string, wxCoord *w, wxCoord *h,
wxCoord *descent = NULL, wxCoord *externalLeading = NULL, wxFont *font = NULL)
Not implemented: See GetCharHeight for reasons.
See also wxLatexDC::SetFont.
wxColour& GetTextForeground()
const wxColour& GetTextForeground() const
Gets the current text foreground colour (see wxLatexDC::SetTextForeground).
void GetUserScale(double *x, double *y)
Gets the current user scale factor (set by SetUserScale).
wxCoord LogicalToDeviceX(wxCoord x)
Converts logical X coordinate to device coordinate, using the current mapping mode.
wxCoord LogicalToDeviceXRel(wxCoord x)
Converts logical X coordinate to relative device coordinate, using the current mapping mode but ignoring the x axis orientation. Use this for converting a width, for example.
wxCoord LogicalToDeviceY(wxCoord y)
Converts logical Y coordinate to device coordinate, using the current mapping mode.
wxCoord LogicalToDeviceYRel(wxCoord y)
Converts logical Y coordinate to relative device coordinate, using the current mapping mode but ignoring the y axis orientation. Use this for converting a height, for example.
wxCoord MaxX()
Gets the maximum horizontal extent used in drawing commands so far.
wxCoord MaxY()
Gets the maximum vertical extent used in drawing commands so far.
wxCoord MinX()
Gets the minimum horizontal extent used in drawing commands so far.
wxCoord MinY()
Gets the minimum vertical extent used in drawing commands so far.
bool Ok()
Returns true if the DC is ok to use; False values arise from being unable to write the file
void ResetBoundingBox()
Resets the bounding box: after a call to this function, the bounding box doesn't contain anything.
See also
void SetAxisOrientation(bool xLeftRight, bool yBottomUp)
Sets the x and y axis orientation (i.e., the direction from lowest to highest values on the axis). The default orientation is the natural orientation, e.g. x axis from left to right and y axis from bottom up.
Parameters
xLeftRight
yBottomUp
void SetDeviceOrigin(wxCoord x, wxCoord y)
Sets the device origin (i.e., the origin in pixels after scaling has been applied).
This function may be useful in Windows printing operations for placing a graphic on a page.
void SetBackground(const wxBrush& brush)
Sets the current background brush for the DC.
void SetBackgroundMode(int mode)
mode may be one of wxSOLID and wxTRANSPARENT. This setting determines whether text will be drawn with a background colour or not.
void SetClippingRegion(wxCoord x, wxCoord y, wxCoord width, wxCoord height)
void SetClippingRegion(const wxPoint& pt, const wxSize& sz)
void SetClippingRegion(const wxRect& rect)
void SetClippingRegion(const wxRegion& region)
Not implemented
void SetPalette(const wxPalette& palette)
Not implemented
void SetBrush(const wxBrush& brush)
Sets the current brush for the DC.
If the argument is wxNullBrush, the current brush is selected out of the device context, and the original brush restored, allowing the current brush to be destroyed safely.
void SetFont(const wxFont& font)
Not implemented: See GetCharHeight for reasons.
void SetLogicalFunction(int function)
Only wxCOPY is avalaible; trying to set one of the other values will fail
void SetMapMode(int int)
The mapping mode of the device context defines the unit of measurement used to convert logical units to device units. Note that in X, text drawing isn't handled consistently with the mapping mode; a font is always specified in point size. However, setting the user scale (see wxLatexDC::SetUserScale) scales the text appropriately. In Windows, scaleable TrueType fonts are always used; in X, results depend on availability of fonts, but usually a reasonable match is found.
Note that the coordinate origin should ideally be selectable, but for now is always at the top left of the screen/printer.
Drawing to a Windows printer device context under UNIX uses the current mapping mode, but mapping mode is currently ignored for PostScript output.
The mapping mode can be one of the following:
| wxMM_TWIPS | Each logical unit is 1/20 of a point, or 1/1440 of an inch. |
| wxMM_POINTS | Each logical unit is a point, or 1/72 of an inch. |
| wxMM_METRIC | Each logical unit is 1 mm. |
| wxMM_LOMETRIC | Each logical unit is 1/10 of a mm. |
| wxMM_TEXT | Each logical unit is 1 pixel. |
void SetPen(const wxPen& pen)
Sets the current pen for the DC.
If the argument is wxNullPen, the current pen is selected out of the device context, and the original pen restored.
void SetTextBackground(const wxColour& colour)
Sets the current text background colour for the DC.
void SetTextForeground(const wxColour& colour)
Sets the current text foreground colour for the DC.
void SetUserScale(double xScale, double yScale)
Sets the user scaling factor, useful for applications which require `zooming'.
bool StartDoc(const wxString& message)
Does nothing
bool StartPage()
Does nothing