The Android ADXF library provides support for generation of DXF files for use with CAD programs using standard Android “draw” commands. The library provides a special Canvas subclass, DXFCanvas, that is associated with a DXF document and that renders draw commands into DXF syntax. A sequence of Android Canvas drawing method calls will thus create a structured DXF document that, when opened with a standard CAD program, will display the Canvas image as a CAD design that can be modified within the CAD program.
This library is released under the MIT License.
The class DXFCanvas implements the graphics operations defined by the standard Android Canvas class. To create a DXF drawing, you use the standard Android Canvas drawing calls (including drawing, transformations, etc.) on an instance of DXFCanvas. The DXFCanvas will encode these Android drawing commands as DXF objects in an associated DXFDocument, which can then be saved as a DXF file.
A DXFCanvas is associated with a DXFDocument. The basic workflow is:
/* Create a DXF document and get its associated DXFCanvas */
DXFDocument dxfDocument = new DXFDocument(“Example”);
DXFCanvas dxfCanvas = dxfDocument.getCanvas();
/* Do drawing commands as on any other Canvas */
Paint paint = new Paint();
dxfCanvas.drawLine(0, 0,100, 100, paint);
dxfCanvas.drawRect(120, 180, 400, 400, paint);
dxfCanvas.drawText(“Some text”, 200, 600, paint);
dxfCanvas.drawCircle(300, 300, 100, paint);
/* Write the DXF representation in the document to a file; DXF is just text, so the document generates a String as output */
String dxfText = dxfDocument.toDXFString();
String filePath = “path/to/file.dxf”;
FileWriter fileWriter = new FileWriter(filePath);
The ADXF library provides most of the drawing operations available in the standard Canvas class. However, certain methods are unimplemented at present (some due to lack of support in DXF). These unimplemented operations will be ignored or throw an UnsupportedOperationException if used, as indicated below. Some additional features currently have no or limited support, as indicated below.
- Drawing operations, including
- drawLine, drawLines
- Text operations
- Paint properties
- Line width
- Font properties: serif/sans-serif, size, bold, italic
- Matrix transformation operations
- State save and restore
- Saves and restores the transformation state of the graphics canvas
The library provides methods for creating and drawing B-splines on the standard Java canvas, as well as generating DXF code for splines.
- Dotted lines – represented as solid lines
- Underlined and strikethrough text – text drawn without underline/strikethrough
- Image drawing through drawBitmap – currently ignored
- Grid and 3D drawing through drawBitmapMesh and drawVertices – currently ignored
- Paint xfermodes – Ignored
- drawPaint, drawColor, drawRGB – currently ignored
- State-save flags and layer information are ignored – save(flags), saveLayer, and saveLayerAlpha all behave the same as plain save()
- quickReject() methods – always return false
- drawTextRun method – throws UnsupportedOperationException
- Clipping, including clipRect, clipRegion, clipPath, etc. – throws UnsupportedOperationException
- drawPath method – throws UnsupportedOperationException
- drawPicture method – throws UnsupportedOperationException
- drawPatch method – throws UnsupportedOperationException
Example DXF Files
Some example files generated with ADXF are at the links below. The Java source code used to generate these through the ADXF Library is available in the Example Code section.
- Example of basic graphics operations
- Example of basic text operations
- Example of matrix transformation operations on graphics
- Example of matrix transformation operators on text
A test project is available that illustrates how to use the library and that can also be used to test its functionality.
The downloads are supplied as gzipped tar archives; the library archive contains the compiled gnuapdf.jar file for inclusion in a project, while the source archive contains the Java source files that can be used to rebuild the .jar file or included as source files in a referencing project. The test app source contains source for a simple test app that uses the classes in the ADXF library.
||Test App Source|