PdfViewerGetMagnifierRectForAnchor typedef

PdfViewerGetMagnifierRectForAnchor = Rect Function(PdfTextSelectionAnchor anchor, PdfViewerSelectionMagnifierParams params, Offset clampedPointerPosition)

Function to get the magnifier rectangle for the anchor.

This function determines what part of the PDF document to show in the magnifier.

Parameters:

  • anchor: The text selection anchor with character information
  • params: Magnifier parameters
  • clampedPointerPosition: The clamped pointer position in viewport coordinates. This is the raw pointer position adjusted for viewport edge clamping to prevent content sliding when the magnifier widget itself is clamped at the viewport edge. Use PdfViewerController.globalToDocument to convert to document coordinates if needed.

Returns a Rect in document coordinates representing the area to magnify.

Example:

getMagnifierRectForAnchor: (textAnchor, params, clampedPointerPosition) {
  final c = textAnchor.page.charRects[textAnchor.index];
  final baseUnit = switch (textAnchor.direction) {
    PdfTextDirection.ltr || PdfTextDirection.rtl || PdfTextDirection.unknown => c.height,
    PdfTextDirection.vrtl => c.width,
  };
  // Convert to document coordinates for positioning
  final pointerInDocument = controller.globalToDocument(clampedPointerPosition) ?? textAnchor.anchorPoint;
  return Rect.fromLTRB(
    pointerInDocument.dx - baseUnit * 2.5,
    textAnchor.rect.top - baseUnit * 0.5,
    pointerInDocument.dx + baseUnit * 2.5,
    textAnchor.rect.bottom + baseUnit * 0.5,
 );
}

Implementation

typedef PdfViewerGetMagnifierRectForAnchor =
    Rect Function(
      PdfTextSelectionAnchor anchor,
      PdfViewerSelectionMagnifierParams params,
      Offset clampedPointerPosition,
    );