Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lib/core/messages/notes_messages.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@ abstract class NotesMessages {
// ===== הערות אישיות =====
static const String emptyNoteNotSaved = 'ההערה ריקה, לא נשמרה';
static const String noteSaved = 'ההערה נשמרה בהצלחה';
static const String noteSavedDraftCleanupFailed =
'ההערה נשמרה, אך לא ניתן למחוק את הטיוטה הישנה';
static String noteDraftUpdateError(Object error) =>
'שגיאה בעדכון טיוטת ההערה: $error';
static const String noteUpdated = 'ההערה עודכנה';
static const String noteNoLongerExists = 'ההערה אינה קיימת עוד';
static const String noteMovedToDifferentBook =
'ההערה הועברה לספר אחר. יש לפתוח אותה מחדש לפני שמירה';
static const String noteDeleted = 'ההערה נמחקה';
static String noteDeleteFailed(Object error) => 'מחיקת ההערה נכשלה: $error';
static const String noteHasNoLocation = 'להערה הזו אין מיקום';
static const String choosePdfNotePoint = 'לחץ על הנקודה הרצויה בעמוד להערה';
static const String pdfNotePointUnavailable =
'בחר נקודה בתוך עמוד שנטען במלואו';
static const String pdfNoteLocationUnavailable =
'לא ניתן להגיע למיקום ההערה במסמך הזה';
static const String noteRepositioned = 'מיקום ההערה עודכן';
static String noteRepositionFailed(Object error) =>
'שינוי מיקום ההערה נכשל: $error';
static const String libraryNotLoadedYet = 'הספרייה לא נטענה עדיין';
static const String backupCompleted = 'הגיבוי הושלם בהצלחה';
static const String textExportCompleted = 'הייצוא לטקסט הושלם בהצלחה';
static const String wordExportCompleted = 'הייצוא לוורד הושלם בהצלחה';

static String notesListLoadError(Object error) =>
'שגיאה בטעינת רשימת ההערות: $error';
static const String notesLoadIncomplete =
'חלק מההערות לא נטענו. יש לנסות שוב לפני ייצוא.';

static String importFailed(Object error) => 'ייבוא ההערות נכשל: $error';

Expand Down
84 changes: 84 additions & 0 deletions lib/pdf_book/utils/pdf_personal_note_anchor.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import 'package:flutter/widgets.dart';
import 'package:otzaria/personal_notes/models/pdf_note_anchor.dart';
import 'package:pdfrx/pdfrx.dart';

/// עמודים שנראים בפועל, כולל קצה העמוד הבא בגלילה רציפה.
List<int> visiblePdfNotePageNumbers({
required List<Rect> pageLayouts,
required Rect visibleRect,
}) => [
for (var index = 0; index < pageLayouts.length; index++)
if (pageLayouts[index].overlaps(visibleRect)) index + 1,
];

/// ממיר תוצאת hit-test של pdfrx לנקודה שאינה תלויה בזום, בפריסה או בסיבוב.
/// ממדי העמוד ב-pdfrx מסובבים, ואילו נקודת ה-hit-test היא בקואורדינטות המקור.
PdfNoteAnchor? pdfNoteAnchorFromHit(
PdfPageHitTestResult? hit, {
String? documentId,
}) {
if (hit == null || !hit.page.isLoaded) return null;
final page = hit.page;
final swapped = page.rotation.index.isOdd;
final width = swapped ? page.height : page.width;
final height = swapped ? page.width : page.height;
if (!width.isFinite || !height.isFinite || width <= 0 || height <= 0) {
return null;
}
final x = hit.offset.x / width;
final y = hit.offset.y / height;
if (!x.isFinite || !y.isFinite) return null;
return PdfNoteAnchor(
pageNumber: page.pageNumber,
x: x.clamp(0.0, 1.0),
y: y.clamp(0.0, 1.0),
documentId: documentId,
);
}

/// ממיר נקודה שמורה לקואורדינטות הפריסה, כולל הסיבוב הנוכחי של העמוד.
Offset pdfNoteAnchorDocumentPosition(
PdfNoteAnchor anchor, {
required PdfPage page,
required Rect pageRect,
}) {
final swapped = page.rotation.index.isOdd;
final width = swapped ? page.height : page.width;
final height = swapped ? page.width : page.height;
return PdfPoint(anchor.x * width, anchor.y * height).toOffsetInDocument(
page: page,
pageRect: pageRect,
);
}

/// מרכז נקודה שמורה, בלי לשנות את הזום. ההורה מכין את נעילת הכפולה לפני הקריאה.
/// מחזיר false כשאי אפשר לנווט (מסמך נסגר, עמוד חסר או בקשה שהתיישנה).
Future<bool> navigateToPdfNoteAnchor(
PdfViewerController controller,
PdfNoteAnchor anchor, {
bool Function()? isActive,
}) async {
bool active() => controller.isReady && (isActive?.call() ?? true);
if (!active() || anchor.pageNumber > controller.pageCount) return false;
final document = controller.document;
var page = controller.pages[anchor.pageNumber - 1];
if (!page.isLoaded) {
final loaded = await page.waitForLoaded(
timeout: const Duration(seconds: 10),
);
if (loaded == null) return false;
page = loaded;
}
if (!active() || !identical(controller.document, document)) return false;
final pageLayouts = controller.layout.pageLayouts;
if (anchor.pageNumber > pageLayouts.length) return false;
final position = pdfNoteAnchorDocumentPosition(
anchor,
page: page,
pageRect: pageLayouts[anchor.pageNumber - 1],
);
await controller.goTo(controller.calcMatrixFor(position));
if (!active() || !identical(controller.document, document)) return false;
controller.setCurrentPageNumber(anchor.pageNumber);
return true;
}
Loading
Loading