This tool will convert a polyline, polygon or rectangle into a curved line, either as a polyline, or as an ink annotation. It allows you to set a 'radius' to limit the size of the curve.
Background
There isn't any easy way to add curved markups (annotations) besides trying to approximate a curve by drawing a polyline with many points. The application has a built-in way to draw curves in the ink tool, but they are quite difficult to control.
This tool takes a polyline and draws quadratic curves between the start point, midpoints of interior lines, and end point; so it's more intuitive where the curves are.
The tool also allows editing of the curve by adjusting the original control line (if you delete the original control line, it will remember the coordinates of that line temporarily and recreate if you select the curved line and run the Poly to Curve tool, so you can still edit it, but only until you close the file).
Installation
Extract the zip file, and save the files into the Javascripts folder either at
%APPDATA%\Tracker Software\PDFXEditor\3.0\JavaScripts\
or at
%PROGRAMFILES%\Tracker Software\PDF Editor\Javascripts\
On restarting PDFX-Change, it will add a button to the Add-on tools to quickly convert a polyline into a curve (select the polyline first, then this tool - it will draw the curve and ends in edit mode. Delete the control line or close the progress dialog to stop editing): It will also add a menu item in the Home ribbon (and in Comments menu for classic UI) that makes the curve and directly opens the dialog: Select the polyline (you can select one or more to edit at the same time) to use as the control points for the curved line: Run the Poly to Curve tool to generate a curved line from it. It converts the polylines to curves, copies all the properties from the lines to the curves, and converts the original polyline to dashed blue/green color; then shows a dialog: Markup Type
- Select either polyline or ink annotation type for the curve. The polyline option uses a polyline (or polygon for closed shapes), and will allow you to individually edit points on the lines. The ink option makes a single object similar to the pencil tool and doesn't show the individual control points. Either of them can be edited with this tool, but the latter cannot have arrows.
- 'Auto' radius means it calculates the distance between the corner point and the midpoint of the line on each side at each corner. To round corners by a specific amount, enter a radius (in points). For example, to round the corners of a rectangle, enter 18 for the radius and it will only round the corners, similar to entering 0.25in for the radius in properties (18pt / 72ppi = 0.25in).
The dialog box updates a bit erratically, so you may need to select inside the edit box after editing to see the change.
- If selected, it will delete the original control line and just leave the generated curve. If not checked, when you select "OK" you keep both the control line and the curve:
To edit a curve, select it and run the tool or you can edit it when you first create it.
Once the original control line is deleted, you can still edit the curve only until the file is closed.
- If you select "Edit" the dialog closes and the selection tool is enabled. Now you can edit the original control line and the curve will follow: X to close it and go back to the dialog: To end editing, you can either just delete the control line, or there's a progress bar in the lower right corner: Click the
Options
Ink annotations have built-in smoothing of lines, so the curved line can be generated with much fewer points. It may print better, and doesn't increase the file size as much. But you can't have arrows on it, and the hatch tool will only approximately match the boundary (it uses straight lines between control points).
By default, the tool generates a polygon or polyline with at most 20 points per curve and ink with 6 points per curve. To change the number of points and how smooth the curve is, edit lines 59-60 to set the number of points you want. It also will reduce the number of points used to draw the curve based on a factor * square root of the line thickness. Line 61 can be set to zero to prevent this:
Code: Select all
const minCurvePoints = 20; // number of points to use in polyline
const minInkPoints = 6; // number of points to use in ink
const ptSpacingFactor = 1.5; // minimum spacing between curve points in points is determined by multiplying this * sqrt(linewidth). Set to zero to disable.
tl;dr
The shape appears approximately circular, but a quadratic curve has a varying radius that grows as it approaches the line on each end. It's more obvious at sharp than oblique angles.
Initially I thought I could just take the vertices from the polygon or polyline and put them into an ink annotation, because PXCE has built-in smoothing for that. But the way the ink annotation handles curves is not intuitive to me - it's some type of Bezier I guess, but I couldn't get it to behave without basically drawing most of the points.
By default the script calculates 6 points per curve for ink (pencil) annotations - more points than that for ink annotations didn't seem to have much effect. I still can't figure out how to get a perfectly smooth transition at the beginning and end of a polygon if using ink, so converted polygons will have a very small dimple: Editing works by setting up an interval timer that watches for changes to the control line, and redraws the curve after each change. It uses xutils for the improved timeout and interval functions. The only non-modal dialog that javascript has access to (as far as I know) is the thermometer progress dialog, so I used that as a way to end the interval. It also times out after about 40 seconds, and gives an option to stop editing.
Limitations
- I've not come up with a way to save the information from the original control line when the file is saved and closed. I currently assign a custom property 'curveData' to the ink annotation but that doesn't get saved with the file.
- After editing a polyline, "Cancel" doesn't undo any changes - the built-in 'undo' function should be able to step you back through, though.
- If you close the document while curve edit is running PXE immediately stops the repeating interval checking, so you'll be left with the progress dialog box stuck in the lower right corner. Run the tool again to clear it.