43 lines
1.6 KiB
Dart
43 lines
1.6 KiB
Dart
|
|
// lib/editor/pdf/pdfrx_page_document_source.dart
|
||
|
|
//
|
||
|
|
// Production [PageDocumentSource] backed by a pdfrx PdfDocument — the thin
|
||
|
|
// device-side adapter that feeds real page geometry into the (pure, tested)
|
||
|
|
// continuous-single layout math.
|
||
|
|
//
|
||
|
|
// SOURCE-PIN (plan SF4 / P0.5 step 12): this file references the exact pdfrx
|
||
|
|
// 2.4.4 page-geometry API (`PdfDocument.pages`, `PdfPage.width`, `PdfPage.height`).
|
||
|
|
// Because it lives under lib/editor/, the Oracle's `flutter analyze lib/editor`
|
||
|
|
// type-checks it against the installed pdfrx on every run — so a version bump
|
||
|
|
// that renames/retypes these members FAILS analysis instead of silently
|
||
|
|
// drifting. (Static pin only: exercising it needs pdfium at runtime, which is
|
||
|
|
// the device-gated path.)
|
||
|
|
|
||
|
|
import 'dart:ui' show Size;
|
||
|
|
|
||
|
|
import 'package:pdfrx/pdfrx.dart';
|
||
|
|
|
||
|
|
import 'pdf_document_source.dart';
|
||
|
|
|
||
|
|
/// Snapshots page sizes (PDF points) from an open pdfrx [PdfDocument] so the
|
||
|
|
/// layout layer can read them synchronously (pdfrx loads pages asynchronously;
|
||
|
|
/// once open, `document.pages[i].width/height` are available).
|
||
|
|
class PdfrxPageDocumentSource implements PageDocumentSource {
|
||
|
|
const PdfrxPageDocumentSource.fromSizes(this._sizes);
|
||
|
|
|
||
|
|
/// Snapshot the intrinsic size of every page from an open [document].
|
||
|
|
factory PdfrxPageDocumentSource.fromDocument(PdfDocument document) {
|
||
|
|
final sizes = document.pages
|
||
|
|
.map((page) => Size(page.width, page.height))
|
||
|
|
.toList(growable: false);
|
||
|
|
return PdfrxPageDocumentSource.fromSizes(sizes);
|
||
|
|
}
|
||
|
|
|
||
|
|
final List<Size> _sizes;
|
||
|
|
|
||
|
|
@override
|
||
|
|
int get pageCount => _sizes.length;
|
||
|
|
|
||
|
|
@override
|
||
|
|
Size pageSize(int index) => _sizes[index];
|
||
|
|
}
|