Skip to content
Closed
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ PDF.js is community-driven and supported by Mozilla. Our goal is to
create a general-purpose, web standards-based platform for parsing and
rendering PDFs.

## One difference from Mozilla repo
This fork of pdf.js has one single extra feature and that is to go back and forth (Use the Key B) to any link inside the pdf and come back. And we can create marked positions (Mark aline using M) and move between those positions in the pdf using a shortcut key "C"

## Contributing

PDF.js is an open source project and always looking for more contributors. To
Expand Down
31 changes: 31 additions & 0 deletions l10n/en-US/viewer.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,37 @@ pdfjs-editor-undo-bar-close-button =
.title = Close
pdfjs-editor-undo-bar-close-button-label = Close

## Jump history (marks, and returning from links)

# Variables:
# $page (Number) - the page number of the position to return to
pdfjs-jump-history-back-button =
.title = Return to page { $page } (B)
.aria-label = Return to page { $page }
pdfjs-jump-history-back-button-empty =
.title = Nothing to return to yet; follow a link, or use the outline, first (B)
.aria-label = Nothing to return to yet
pdfjs-jump-history-list-button =
.title = Show marks (C / Shift+C to cycle)
.aria-label = Show marks
pdfjs-jump-history-panel-title = Marks
pdfjs-jump-history-save-button = Save to file
pdfjs-jump-history-max-entries-label = Marks to remember
# Variables:
# $page (Number) - the page number of the mark
pdfjs-jump-history-entry-page = Page { $page }
pdfjs-jump-history-entry-empty = No marks yet. Press M, or select text and use the mark button.
pdfjs-jump-history-clear-button = Clear all
pdfjs-jump-history-clear-button-confirm = Confirm clear
pdfjs-jump-history-mark-floating-button =
.title = Mark this line (M)
pdfjs-jump-history-mark-floating-button-label = Mark this line
pdfjs-jump-history-list-floating-button =
.title = Show marks
pdfjs-jump-history-list-floating-button-label = Show marks
pdfjs-jump-history-entry-loading = Loading…
pdfjs-jump-history-entry-no-text = (no text on this line)

## Add a signature dialog

pdfjs-editor-add-signature-dialog-label = This modal allows the user to create a signature to add to a PDF document. The user can edit the name (which also serves as the alt text), and optionally save the signature for repeated use.
Expand Down
17 changes: 9 additions & 8 deletions src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -2275,17 +2275,18 @@ class PDFDocument {
}

get calculationOrderIds() {
const co = this.catalog.acroForm?.get("CO");
let ids = null;
const calculationOrder = this.catalog.acroForm?.get("CO");
if (!Array.isArray(calculationOrder) || calculationOrder.length === 0) {
return shadow(this, "calculationOrderIds", null);
}

if (Array.isArray(co)) {
for (const id of co) {
if (id instanceof Ref) {
(ids ??= []).push(id.toString());
}
const ids = [];
for (const id of calculationOrder) {
if (id instanceof Ref) {
ids.push(id.toString());
}
}
return shadow(this, "calculationOrderIds", ids);
return shadow(this, "calculationOrderIds", ids.length ? ids : null);
}

get annotationGlobals() {
Expand Down
4 changes: 2 additions & 2 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -3020,7 +3020,7 @@ class PartialEvaluator {

for (let i = 0, ii = glyphs.length; i < ii; i++) {
const glyph = glyphs[i];
const { category } = glyph;
const { category, originalCharCode } = glyph;

if (category.isInvisibleFormatMark) {
continue;
Expand All @@ -3030,7 +3030,7 @@ class PartialEvaluator {
const glyphWidth = font.vertical ? glyph.vmetric[0] : glyph.width;
let scaledDim = glyphWidth * scale;

if (glyph.isSpace) {
if (originalCharCode === 0x20) {
charSpacing += textState.wordSpacing;
}

Expand Down
6 changes: 1 addition & 5 deletions src/core/fonts.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ function amendFallbackToUnicode(properties) {

class Glyph {
constructor(
fontExtraProperties,
originalCharCode,
fontChar,
unicode,
Expand All @@ -254,9 +253,7 @@ class Glyph {
isInFont,
isRotated
) {
if (fontExtraProperties) {
this.originalCharCode = originalCharCode;
}
this.originalCharCode = originalCharCode;
this.fontChar = fontChar;
this.unicode = unicode;
this.accent = accent;
Expand Down Expand Up @@ -3675,7 +3672,6 @@ class Font {
}

glyph = new Glyph(
this.fontExtraProperties,
charcode,
fontChar,
unicode,
Expand Down
5 changes: 5 additions & 0 deletions src/display/editor/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,11 @@ class FloatingToolbar {
}
);

for (const { className, l10nId, labelL10nId, onClick } of this.#uiManager
.floatingToolbarButtons) {
this.#makeButton(className, l10nId, labelL10nId, onClick);
}

return editToolbar;
}

Expand Down
22 changes: 22 additions & 0 deletions src/display/editor/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,8 @@ class AnnotationEditorUIManager {

#floatingToolbar = null;

#floatingToolbarButtons = [];

#idManager = new IdManager();

#isEnabled = false;
Expand Down Expand Up @@ -1218,6 +1220,26 @@ class AnnotationEditorUIManager {
return !!this.#commentManager;
}

/**
* Add a button to the floating toolbar shown when selecting text, after the
* built-in ones; the selection is still available when it's clicked.
* @param {object} button
* @param {string} button.className - Used to style the button, e.g. its icon.
* @param {string} button.l10nId - For the title of the button.
* @param {string} button.labelL10nId - For the label of the button.
* @param {Function} button.onClick
*/
addFloatingToolbarButton(button) {
this.#floatingToolbarButtons.push(button);
// Re-create the toolbar, if already used, to include the new button.
this.#floatingToolbar?.hide();
this.#floatingToolbar = null;
}

get floatingToolbarButtons() {
return this.#floatingToolbarButtons;
}

editComment(editor, posX, posY, options) {
this.#commentManager?.showDialog(this, editor, posX, posY, options);
}
Expand Down
8 changes: 8 additions & 0 deletions web/annotation_editor_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,14 @@
&.deleteButton::before {
mask-image: var(--editor-toolbar-delete-image);
}

&.jumpHistoryMarkButton::before {
mask-image: url(images/toolbarButton-bookmark.svg);
}

&.jumpHistoryListButton::before {
mask-image: url(images/toolbarButton-viewOutline.svg);
}
}

> * {
Expand Down
39 changes: 39 additions & 0 deletions web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ import { PDFDocumentProperties } from "web-pdf_document_properties";
import { PDFFindBar } from "web-pdf_find_bar";
import { PDFFindController } from "./pdf_find_controller.js";
import { PDFHistory } from "./pdf_history.js";
import { PDFJumpHistory } from "./pdf_jump_history.js";
import { PDFLayerViewer } from "web-pdf_layer_viewer";
import { PDFOutlineViewer } from "web-pdf_outline_viewer";
import { PDFPresentationMode } from "web-pdf_presentation_mode";
Expand Down Expand Up @@ -138,6 +139,8 @@ const PDFViewerApplication = {
pdfTextExtractor: null,
/** @type {PDFHistory} */
pdfHistory: null,
/** @type {PDFJumpHistory} */
pdfJumpHistory: null,
/** @type {ViewsManager} */
viewsManager: null,
/** @type {PDFOutlineViewer} */
Expand Down Expand Up @@ -767,6 +770,14 @@ const PDFViewerApplication = {
linkService.setHistory(this.pdfHistory);
}

if (appConfig.jumpHistory) {
this.pdfJumpHistory = new PDFJumpHistory(
appConfig.jumpHistory,
eventBus,
pdfViewer
);
}

if (!this.supportsIntegratedFind && appConfig.findBar) {
this.findBar = new PDFFindBar(
appConfig.findBar,
Expand Down Expand Up @@ -1379,6 +1390,7 @@ const PDFViewerApplication = {
this.pdfLayerViewer?.reset();

this.pdfHistory?.reset();
this.pdfJumpHistory?.reset();
this.findBar?.reset();
this.toolbar?.reset();
this.secondaryToolbar?.reset();
Expand Down Expand Up @@ -2259,6 +2271,8 @@ const PDFViewerApplication = {
// Scale was not initialized: invalid bookmark or scale was not specified.
// Setting the default one.
this.pdfViewer.currentScaleValue ||= DEFAULT_SCALE_VALUE;

this.pdfJumpHistory?.initialize(this.store, this._docFilename);
},

/**
Expand Down Expand Up @@ -3530,6 +3544,25 @@ function onKeyDown(evt) {
this.rotatePages(90);
break;

case 66: // 'b'
if (this.pdfJumpHistory?.canReturn) {
this.pdfJumpHistory.toggleReturn();
handled = true;
}
break;
case 77: // 'm'
if (this.pdfJumpHistory) {
this.pdfJumpHistory.markCurrentPosition();
handled = true;
}
break;
case 67: // 'c'
if (this.pdfJumpHistory?.hasMarks) {
this.pdfJumpHistory.cycleBack();
handled = true;
}
break;

case 115: // F4
this.viewsManager?.toggle();
break;
Expand Down Expand Up @@ -3574,6 +3607,12 @@ function onKeyDown(evt) {
case 82: // 'r'
this.rotatePages(-90);
break;
case 67: // 'c'
if (this.pdfJumpHistory?.hasMarks) {
this.pdfJumpHistory.cycleForward();
handled = true;
}
break;
}
}

Expand Down
Loading
Loading