@truedxf/plot
v0.1.1
Published
CTB/STB plot styles and DXF page setups: pens, lineweights and plot transforms exactly as AutoCAD plots them.
Maintainers
Readme
@truedxf/plot
CTB/STB plot styles and DXF page setups: pens, lineweights and plot transforms exactly as AutoCAD plots them.
Install
pnpm add @truedxf/plotESM only. No DOM and no Node.js APIs: runs in browsers, workers and Node.
What it does
import { builtinPlotStyleTable, penForAci, readPageSetup, readPlotStyleTable } from "@truedxf/plot";
const setup = readPageSetup(layout.object); // area, scale, offset, style sheet name, flags
const table = setup.styleSheet
? (builtinPlotStyleTable(setup.styleSheet) ?? readPlotStyleTable(ctbBytes))
: undefined;
const pen = table && penForAci(table, 1); // colour / lineweight (mm) / … or undefined = objectreadPageSetupinterprets the stored plot settings: plot area, scale (standard scales, custom ratio or fit), paper and margins, offset and centering, style sheet name and the plot flags.readPlotStyleTable/writePlotStyleTableread and write .ctb/.stb files (PIA container, zlib text). The parsed tree is kept, so files round-trip.builtinPlotStyleTablereturns equivalents of the stock tables, which we cannot ship (acad, monochrome, Grayscale, Screening 25/50/75/100 %, Fill Patterns; pen for pen identical to AutoCAD 2027's).buildColorTable/buildNamedTablecreate tables in code.penForObject+applyPlotStyleapply a pen as AutoCAD's PLOT does: the pen of the resolved ACI (true colours and colour-book colours get none; gradients never use a pen), pen colour, grayscale, screening, pen lineweight, end/join style, fill style and linetype.penLinetypeDasheslays out the pen linetypes 1–30 along a run (fixed lengths on the sheet, fixed or adaptive mode);fillStyleInkgives the raster tiles of fill styles 65–72.plotPlacementmaps drawing coordinates to the device: printable area (sheet minus margins), rotation, offset, 148/149, scale, fit and centring.
const placement = plotPlacement(setup, { unitsPerMm: 600 / 25.4 }); // raster setups: pixels
const [a, b, c, d, e, f] = placement.matrix; // X = a·x + c·y + e, Y = b·x + d·y + f (Y down)The DXF holds only the name of the style table, not its pens. The device resolution, the plotted area of extents/limits/display/view plots and the registry sysvars (LWDEFAULT, PLOTTRANSPARENCYOVERRIDE, …) are not in the DXF either, so the caller supplies them.
@truedxf/render uses all of this: pens while
drawing, and the placement for PlotRequest.pageSetup. STB style names are resolved per entity
by @truedxf/model (390, 380).
License
MIT. AutoCAD and DXF are trademarks of Autodesk, Inc. truedxf is not affiliated with or endorsed by Autodesk.
