Skip to content

2.12.313 showpad #19

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: v2.12.313
Choose a base branch
from
Open
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@showpad:registry=https://gitlab.showpad.io/api/v4/packages/npm/
//gitlab.showpad.io/api/v4/packages/npm/:_authToken=${NPM_TOKEN}
//gitlab.showpad.io/api/v4/projects/227/packages/npm/:_authToken=${NPM_TOKEN}
93 changes: 93 additions & 0 deletions README_SHOWPAD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
Showpad uses pdfjs in the asset viewer to render pdfs.

Canvas layer: main visual of the page
Text Layer: for text selection
Annotation layer: for links/annotations

# Updates to src

## Showpad asset link support in annotation layer:

It is possible to add links to a range of showpad entities using urls with the 'showpad:' protocol.

By default pdfjs only allows certain protocols for example https: therefore out of the box showpad: links are not rendered.

To allow showpad links to be rendered we need to add showpad: to the valid protocols [here](./src/shared/util.js#L441)

The handler for when these links is clicked is handled by the asset viewer, this abstraction decouples the complication of making changes to the annotation builder as all that we require is that the links are rendered in html.

## Custom operator list param when rendering a page

For embedded media support we need to be able to pass a custom operator list. To achieve this we must add an 'operatorList' param to the render method of the PDFPageProxy exposed in the public api:

- [Added operatorList param to RenderParameters jsdoc so correct type definitions will be exported](./src/display/api.js#L1173)
- [Added operatorList param to RenderParameters passed to render call](./src/display/api.js#L1388)
- [Prioritized operatorList param over the intentState.operatorList](./src/display/api.js#L1507)

## Prevent throwing of errors in svg renderer for unsupported operations

For embedded media support we use the svg renderer to create an svg element from which we extract the images to calculate some required metadata.
The svg renderer is not officially supported so it does not support all operations, for example when an unsupported operation is encountered in the *_makeShadingPattern* function an error is thrown which results in the svg not being rendered. As the result of *_makeShadingPattern* are not requirements for our use case so we simply return null in this function to ensure that the svg is still created.

- [_makeShadingPattern](./src/display/svg.js#L1163)

## Force image smoothing

Currently there is a check to determine if smoothing should be enabled for an image, however we have found that this can in some cases (SP-57645) that the check returns false when visually it looks better as true therefore we simply return true in this function.

- [getImageSmoothingEnabled](./src/display/canvas.js#L1039)

## Skip checkFirstPage and checkLastPage

To assist in opening possibly corrupt pdfs a check is made when loading a document that fetches its last page, in some cases this results in a large number
of redundent byte range requests occuring which has a significant impact on the time to render a page. As we process pdfs we can assure that the correct
metadata fo numPages is defined so we simply skip these checks.

- [checkFirstPage](./src/core/worker.js#L175)
- [checkLastPage](./src/core/worker.js#L178)

## Bypass accelerated 2d canvas

There is an issue with Accelerated 2d canvas https://github.com/mozilla/pdf.js/issues/14641 that causes text to have issues https://jira.showpad.io/browse/SBE-8253

To fix this we need to add { willReadFrequently: true } to all getContext calls on the canvas to force the use of a software (instead of hardware accelerated) 2D canvas.

- [base_factory.js](./src/display/base_factory.js#L32)
- [font_loader.js](./src/display/font_loader.js#L279)
- [text_layer.js](./src/display/text_layer.js#L738)


# Updates to build process

- [Use hardcoded config to define version](./gulpfile.js#L282)
- [Update DIST_NAME](./gulpfile.js#L2034)
- [Update DIST_DESCRIPTION](./gulpfile.js#L2035)
- [Add publishConfig](./gulpfile.js#L2072)
- [Add .npmrc file](./.npmrc)

## Required artifacts

- pdf.js
- pdf.worker.js
- web/text_layer_builder.css
- web/annotation_layer_builder.css

By default [text_layer_builder.css](./web/text_layer_builder.css) and [annotation_layer_builder.css](./web/annotation_layer_builder.css) are bundled as part of the default [pdf_viewer.css](./web/pdf_viewer.css#L15), however as we only use these 2 layers we copy these to build/dist/web. They are then loaded later to ensure the layers are correctly styled.

## Release

PDFjs does not have a fixed release cycle it tends to be every couple of months, therefore when a new official release happens we should create a branch in our fork, apply the custom changes and create a new showpad release.

For example PDFjs releases version 2.12.313 then the corresponding showpad release will be 2.12.313-showpad-1, 2.12.313-showpad-2, 2.12.313-showpad-3 etc.

- Create branch in showpad fork from the upstream tag commit id
- update version [here](./version-showpad.json#L2)
- gulp dist-pre && cp web/annotation_layer_builder.css build/dist/web/annotation_layer_builder.css && cp web/text_layer_builder.css build/dist/web/text_layer_builder.css && cp .npmrc build/dist/
- cd build/dist
- npm publish






9 changes: 6 additions & 3 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function webpack2Stream(webpackConfig) {
}

function getVersionJSON() {
return JSON.parse(fs.readFileSync(BUILD_DIR + "version.json").toString());
return JSON.parse(fs.readFileSync("./version-showpad.json").toString());
}

function checkChromePreferencesFile(chromePrefsPath, webPrefs) {
Expand Down Expand Up @@ -2031,8 +2031,8 @@ gulp.task(
function packageBowerJson() {
const VERSION = getVersionJSON().version;

const DIST_NAME = "pdfjs-dist";
const DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library.";
const DIST_NAME = "@showpad/pdfjs-dist";
const DIST_DESCRIPTION = "Generic build of Mozilla's PDF.js library with extra showpad features.";
const DIST_KEYWORDS = ["Mozilla", "pdf", "pdf.js"];
const DIST_HOMEPAGE = "http://mozilla.github.io/pdf.js/";
const DIST_BUGS_URL = "https://github.com/mozilla/pdf.js/issues";
Expand Down Expand Up @@ -2069,6 +2069,9 @@ function packageBowerJson() {
type: "git",
url: DIST_REPO_URL,
},
publishConfig: {
'@showpad:registry': 'https://gitlab.showpad.io/api/v4/projects/227/packages/npm/',
},
};

const bowerManifest = {
Expand Down
Loading