Table of Contents

Class CadRender

Namespace
OpenCAD2D
Assembly
OpenCAD2D.Rendering.dll

Draws a drawing of a file to pixels, an SVG or a PDF with no window, as the canvas of the app draws it: the same renderer, the same fonts and the same colours, so that a picture of a drawing is the pixels the app's canvas shows of it (with its grid, UCS icon and grips off, which are the canvas's and not the drawing's). It draws with the app's default settings, never the user's: a picture is the same on every machine that has the same fonts.

public static class CadRender
Inheritance
CadRender
Inherited Members

Remarks

The size of a picture, where Width and Height do not give it: one of the two given, the other follows the aspect of the part drawn, rounded (800 wide of a part 400 by 300 is 600 high); neither, a layout is its part in millimetres times Dpi over 25.4 (an A3 sheet at 96 dpi is 1 587 by 1 123 pixels; a layout whose paper units are inches is its part in inches times the dpi, so its A3 sheet of 16.54 by 11.69 inches is the same 1 587 by 1 123), and model space is 1 600 pixels along the longer side (a drawing 400 by 300 mm is 1 600 by 1 200 pixels). A picture of more than 16 384 pixels a side or 100 000 000 pixels in all is refused: it would hold 400 MB. One picture is drawn at a time in a process; the renderer's caches are not locked against two threads drawing at once.

Methods

Draw(CadDocument, CadRenderOptions)

Draws a space of a drawing and gives its pixels, as the canvas of the app draws it: nothing selected, the drawing's lineweights shown where its $LWDISPLAY says so, and images read before the picture is drawn. A drawing whose extents are 400 by 300 mm is a picture of 1 600 by 1 200 pixels, 5 760 000 bytes.

DrawLabels(CadDocument, CadRenderOptions, int[])

Draws a space of a drawing in flat ids and gives, for every pixel, the class of what is drawn on it and the entity that draws it: the picture Draw(CadDocument, CadRenderOptions) makes for the same options, as labels for training a vision model. It is the renderer of the canvas, drawing each item in the colour that is its id with no antialiasing, in the order the drawing draws them, so what is on top in the picture is on top in the labels; a pixel is of one entity and one class, exactly. A text under 5 pixels high is a bar, as in the picture; the paper of a layout, the frame of a viewport and raster images are not labelled. The classes are those of CadLabelClass. An INSERT's items are classed by what they are unless blocks are asked for, when all of them are class 5. The ground option has no effect: the ground is class 0.

Prepare(CadDocument)

Sets a drawing up as the app sets one up on opening it, so that a picture of it is the canvas's: the canvas's measure of TrueType letters (once in the process: MTEXT of several looks is laid out with it), the fonts and support folders of the default settings, and their default lineweight. A drawing of Open(string) draws its text in the canvas's font until this is done and lays an MTEXT out with every letter 0.6 of its height wide. A display built before is laid out again, once: preparing a drawing again does nothing. The other members call it first, so it is needed only to read the bounds or the display of a drawing as the picture sees them.

Transform(CadDocument, CadRenderOptions)

Gives the matrix from the drawing to the pixels of the picture Draw(CadDocument, CadRenderOptions) makes for the same options: the very view the renderer draws by, nine numbers of a 3 by 3 row by row, [a, c, e, b, d, f, 0, 0, 1], so that a point (x, y) of the space is at the pixel position (a x + c y + e, b x + d y + f). Pixel (column, row) is the square from (column, row) to (column + 1, row + 1), row 0 at the top and y of the drawing upward, so the pixel a point falls in is the floor of both numbers and the centre of a pixel is at column + 0.5. For a drawing 400 by 300 whose extents are drawn at 1 600 by 1 200 pixels with the margin ZOOM Extents leaves (a scale of 3.6), the point (0, 0) is at (80, 1 140) and (400, 300) at (1 520, 60). On a layout it maps the paper in millimetres; the model entities a viewport shows have the viewport's own matrix on top, which is not given here. The inverse is the matrix inverted.

WritePdf(string, CadDocument, string)

Plots a space of a drawing to a PDF file of one page, replacing a file of the name, as EXPORTPDF does: the page setup of the layout (its sheet, scale and plot style), the lines at the lineweights of the plot, text as text, and for model space the extents. An A3 sheet on its side is 1 190.5512 by 841.8898 points. A space with no sheet recorded in its plot settings (a drawing made in code, never set up) is fitted to the default sheet, ISO A3, as AutoCAD fits a page setup it has not been given; one with a sheet is plotted at the scale it records.

WritePng(string, CadDocument, CadRenderOptions)

Draws a space of a drawing to a PNG file, replacing a file of the name: the picture of Draw(CadDocument, CadRenderOptions) as 8-bit red, green and blue with no alpha, as PNGOUT writes it.

WriteSvg(string, CadDocument, CadRenderOptions)

Draws a space of a drawing to an SVG file, replacing a file of the name: the picture of WritePng(string, CadDocument, CadRenderOptions) in vectors, its width and height the pixels of the picture, the images in it as PNG data. It is drawn by the renderer of the canvas, so it keeps the canvas's level of detail at the picture's size: an item under half a pixel is one dot, a text under 5 pixels high is a solid bar of its colour and a hatch whose lines come closer than 2 pixels is a tint. The PDF of WritePdf(string, CadDocument, string) is the full-detail form.