Android ADXF Library

adxf_screenshot

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.

Basic Workflow

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();
paint.setColor(Color.RED);
paint.setTypeface(Typeface.SERIF);
paint.setTextSize(38);
paint.setStyle(Style.STROKE);
dxfCanvas.drawLine(0, 0,100, 100, paint);
dxfCanvas.drawRect(120, 180, 400, 400, paint);
dxfCanvas.drawText(“Some text”, 200, 600, paint);
paint.setStyle(Style.FILL);
dxfCanvas.skew(0.1f, 0.2f);
dxfCanvas.rotate(-35);
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);
fileWriter.write(dxfText);
fileWriter.flush();
fileWriter.close();

Features

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.

Supported operations

  • Drawing operations, including
    • drawLine, drawLines
    • drawArc
    • drawCircle
    • drawOval
    • drawRect
    • drawRoundRect
    • drawPoints
  • Text operations
    • drawText
    • drawPosText
    • drawTextOnPath
  • Paint properties
    • Color
    • Line width
    • Font properties: serif/sans-serif, size, bold, italic
  • Matrix transformation operations
    • scale
    • skew
    • translate
    • rotate
    • concat
  • State save and restore
    • Saves and restores the transformation state of the graphics canvas

Extensions

The library provides methods for creating and drawing B-splines on the standard Java canvas, as well as generating DXF code for splines.

Not supported

  • 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 Code

A test project is available that illustrates how to use the library and that can also be used to test its functionality.

  • ADXFTest.java
  • ADXFTestView.java

Download example source

Documentation

Downloads

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.

Version
Library (.jar)
Source
Test App Source
 1.0 adxf_lib_v1.0.tar.gz adxf_src_v1.0.tar.gz adxf_tst_src_v1.0.tar.gz
1.1 adxf_lib_v1.1.1.tar.gz adxf_src_v1.1.1.tar.gz adxf_tst_src_v1.1.tar.gz

Revision History

Version
Date Changes
1.0 2016-12-13 Initial release
1.1 2017-08-31 Add AutoCAD support

 

Notes

Version 1.1 adds DXF elements that are not strictly required by the standard, but are required in order to open the files in AutoCAD.

Computing, lutherie, mathematics, finance, and other resources