Files
BadNote/lib/editor/pdf/slide_export.dart
Akiba So ffb9e35755
All checks were successful
CI / Windows build (push) Successful in 14m34s
feat(slide): rebuild PPT annotator on the pen-first canvas
PPT slides now annotate with the single performant inking engine
(PenCanvas) instead of the old ink_canvas, per "all note features on the
pen-first canvas".

- PenSlideScreen: per-slide normalized strokes over each slide image,
  prev/next + slider nav, undo/redo, shared M3 palette, and the pressure
  curve / eraser size+mode / palm rejection from the shared canvas.
- slide_export: pure, tested export geometry. Because strokes are now
  normalized to the page rect, the PDF exporter maps them straight into
  each slide's draw rect — fixing the old exporter's known ink
  misalignment (it guessed live-widget size).
- Route PPT import + open -> PenSlideScreen; delete the dead old
  ppt_annotator_screen. (ink_canvas/annotation_toolbar remain for
  split_view, the last old-canvas screen.)

Tests: slide_export geometry (4). flutter analyze: 0 issues. Suite: 269/269.
2026-06-23 10:27:09 +08:00

37 lines
1.6 KiB
Dart

// lib/editor/pdf/slide_export.dart
//
// Pure geometry for exporting pen-first slide annotations to PDF. Because the
// pen canvas captures strokes NORMALIZED to the page rect ([0,1]), the export
// just maps each normalized point into the slide image's draw rectangle on the
// PDF page — no live-widget-size guessing, which is what made the old PPT
// exporter misalign ink (see the removed ppt_annotator_screen comment).
import 'dart:ui' show Offset, Rect, Size;
/// The rectangle a slide [image] occupies when drawn "contain"-fit and centered
/// on a PDF page of size [page]. Mirrors the live canvas's fit-to-view so the
/// exported ink lands exactly where it was drawn.
Rect slideDrawRect(Size page, Size image) {
final iw = image.width <= 0 ? 1.0 : image.width;
final ih = image.height <= 0 ? 1.0 : image.height;
final scale = (page.width / iw) < (page.height / ih)
? page.width / iw
: page.height / ih;
final drawW = iw * scale;
final drawH = ih * scale;
final offX = (page.width - drawW) / 2;
final offY = (page.height - drawH) / 2;
return Rect.fromLTWH(offX, offY, drawW, drawH);
}
/// Map a normalized stroke point ([0,1] of the page rect) to an absolute point
/// inside the slide's [drawRect] on the PDF page.
Offset normToSlide(double nx, double ny, Rect drawRect) =>
Offset(drawRect.left + nx * drawRect.width,
drawRect.top + ny * drawRect.height);
/// Absolute pen width (PDF units) for a stroke whose width is a fraction of the
/// page width, scaled into [drawRect].
double slideStrokeWidth(double normalizedWidth, Rect drawRect) =>
normalizedWidth * drawRect.width;