Repository navigation
fix(w2d): read AutoCAD-plotted DWF sheets to their end - #3
Merged
Merged
Conversation
- Extended binary objects are skipped by size - 2: the size counts the 2-byte opcode, the payload and the closing brace (WHIP! specification). Skipping the full size desynchronised the parser after the first one. - Decode contour sets (0x0b, k), Gouraud polylines (0x11, q), automatic object nodes (0x0e) and symbol records (0x8d, m, M, G, S, s); symbol placements are reported, not drawn. - Loop instead of push(...primitives): a million-item sheet overflowed the call stack on Node 20. - Resolve absolute XPS ImageSource and FontUri part names from the package root. - flatGouraud render option for contexts without a raster canvas, and an even-odd fill rule for paths. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Count only visible placements. Before revision 6.01 a placement draws a built-in marker at the marker size (S/s; a single pixel at the default 0), so a sized marker is a visible loss (warning), as is any stream that defines symbols ((Macro ...) or (Glyph ...)). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We use dwf-viewer on a server to turn plotted DWF and DWFx drawings into PDF (its parser and Canvas2D renderers drawing into a PDF-backed canvas). On a set of 13 real AutoCAD-plotted drawings (8 DWF, 5 DWFx), 7 of the DWF sheets stopped early: the reader got through 0% to 48% of the W2D stream (one 99.8%) and the rest of the sheet was missing. These changes read all of them to the end, with no unsupported-opcode diagnostics. The drawings cannot be shared, so the regression tests build synthetic byte sequences.
What was wrong, and the fix
{counts the 2-byte opcode, the payload and the closing}(WHIP! specification, "The Extended binary opcode"), so the object endssize - 2bytes after the opcode. Skippingsizebytes landed inside the next instruction, and the parser stopped at a meaningless "unknown opcode" (0xba, 0xa7, 0xfa in our files).0x8din four of our files). Added, with operand layouts from the WHIP! specification and the opcode table of Autodesk's DWF Toolkit (facts only, no Toolkit code):0x0b(16-bit) /k(32-bit): one filledpathprimitive withfillRule: 'evenodd', so inner contours are holes;0x11/q: segments in their vertex colours;0x0e(no operand);0x8d/m/M, macro indexG, macro scaleS/s. Placements are read but not drawn;W2D_MACRO_NOT_DRAWNreports them, asinfowhen the stream defines no symbol ((Macro ...)), aswarningwhen it does. This keeps the parser fail-closed, as CONTRIBUTING.md asks.primitives.push(...parsed.primitives)overflowed on Node 20 for sheets of about a million primitives (two of our files), and the page fell back to its thumbnail. It's a loop now.ImageSource(andFontUri) values like/Resources/scan.tifhad their leading slash removed and were resolved against the page's folder, so raster images, such as a scanned sheet, were "ZIP entry not found". They now resolve from the package root, falling back to the old page-relative lookup.flatGouraudrender option (new, off by default): fill each Gouraud triangle with the average of its vertex colours instead of rasterising it throughownerDocument.createElement('canvas'). It's for contexts that have no document, such as vector exports; the raster pixel budget doesn't apply to it.drawPrimitiveCanvashonours the pathfillRule.Tests:
scripts/w2d-real-plots.test.mjs(7 tests), added totest:w2dand to the publish gate.node --test scripts/w2d-gouraud.test.mjs scripts/w2d-real-plots.test.mjspasses (18), and so doesnpm run validate:production.Contributed under AGPL-3.0-only.
🤖 Generated with Claude Code