@maqiuyao/dxf-viewer 0.2.4 → 0.2.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,6 +46,48 @@ export interface PdfData {
46
46
  layersAndThreejsObjects?: Record<string, THREE.Object3D[]>;
47
47
  loadedEntityCount: number;
48
48
  }
49
+ /**
50
+ * Options for {@link Viewer2d.print}.
51
+ */
52
+ export interface PrintOptions {
53
+ /**
54
+ * Print area.
55
+ * - "view": print the current viewport as-is.
56
+ * - "extents": temporarily fit the whole drawing to the view, then print.
57
+ * @default "view"
58
+ */
59
+ area?: "view" | "extents";
60
+ /**
61
+ * Paper size for the @page rule.
62
+ * @default "A4"
63
+ */
64
+ paperSize?: "A4" | "A3" | "A2" | "A1" | "A0" | "Letter";
65
+ /**
66
+ * Page orientation. "auto" picks landscape when the image is wider than tall.
67
+ * @default "auto"
68
+ */
69
+ orientation?: "auto" | "landscape" | "portrait";
70
+ /**
71
+ * Invert colors so the dark CAD background becomes white with dark lines (saves toner).
72
+ * @default false
73
+ */
74
+ invertColors?: boolean;
75
+ /**
76
+ * Scale the image to fit within the page. When false, the image fills the page width.
77
+ * @default true
78
+ */
79
+ fitToPage?: boolean;
80
+ /**
81
+ * Page margin in millimeters.
82
+ * @default 10
83
+ */
84
+ margins?: number;
85
+ /**
86
+ * Document title shown in the print dialog.
87
+ * @default "图纸"
88
+ */
89
+ title?: string;
90
+ }
49
91
  /**
50
92
  * @internal
51
93
  */
@@ -175,6 +217,8 @@ export declare class Viewer2d extends BaseViewer {
175
217
  private clickHighlightList?;
176
218
  /** 是否启用点击实体高亮,默认关闭 */
177
219
  private _enableClickHighlight;
220
+ /** 打印截图进行中:临时强制显示所有图符/文字,避免低缩放时被"视觉过小"逻辑隐藏 */
221
+ private _printCaptureMode;
178
222
  constructor(viewerCfg: Viewer2dConfig);
179
223
  get camera(): THREE.OrthographicCamera;
180
224
  private setupDefaultEvents;
@@ -388,6 +432,43 @@ export declare class Viewer2d extends BaseViewer {
388
432
  clearTextHighlight(): void;
389
433
  zoomIn(step?: number): void;
390
434
  zoomOut(step?: number): void;
435
+ /**
436
+ * @description {en} Prints the drawing. Captures the current viewport (or the whole drawing
437
+ * for area "extents") as an image, composites the overlay layer, and opens the browser
438
+ * print dialog via a hidden iframe with @page rules for the chosen paper size.
439
+ * @description {zh} 打印图纸。截取当前视图(area 为 "extents" 时先临时缩放至全图)渲染画面,
440
+ * 叠加标注层,通过隐藏 iframe 的 @page 规则按所选纸张调用浏览器打印对话框。
441
+ * @example
442
+ * ```typescript
443
+ * await viewer.print({ area: "extents", paperSize: "A3", invertColors: true });
444
+ * ```
445
+ */
446
+ print(options?: PrintOptions): Promise<void>;
447
+ /**
448
+ * Renders the scene (optionally fitted to the whole drawing) at high resolution and
449
+ * returns a PNG data URL with the WebGL canvas and the overlay canvas composited.
450
+ * For "extents", the result is cropped to the drawing's bounding box so the paper
451
+ * area is filled by the drawing itself (no letterbox margins). Camera/renderer state is restored.
452
+ */
453
+ private capturePrintImage;
454
+ /**
455
+ * Converts a dark-background CAD render to a white-background image for printing
456
+ * WITHOUT shifting hues: each pixel's HSL lightness is flipped (blue stays blue,
457
+ * cyan stays cyan) and darkened for paper contrast; dark background pixels are
458
+ * crushed to pure white; a color-carrying dilation thickens 1px hairlines and
459
+ * solidizes anti-aliased edges. Operates in-place on the canvas.
460
+ */
461
+ private invertForPrint;
462
+ /**
463
+ * Crops a canvas (rendered by the current orthographic top-down camera) to a world-space box.
464
+ * Returns a PNG data URL, or undefined if the box is degenerate/out of view.
465
+ */
466
+ private cropCanvasToBox;
467
+ /**
468
+ * Opens the browser print dialog with the image laid out on the selected paper size,
469
+ * via an offscreen hidden iframe (so the host page's own styles never leak into print).
470
+ */
471
+ private printImageInIframe;
391
472
  /**
392
473
  * @description {en} Gets dxf layers.
393
474
  * @description {zh} 获取dxf图层。
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maqiuyao/dxf-viewer",
3
- "version": "0.2.4",
3
+ "version": "0.2.5",
4
4
  "description": "基于 three.js 的 DXF 图纸 2D/3D 查看与对比库(Viewer2d / DxfCompareHelper)",
5
5
  "type": "module",
6
6
  "main": "./dist/dxf-viewer.cjs",