aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client/views/pdf/PDFMenu.tsx6
-rw-r--r--src/client/views/pdf/PDFViewer.tsx30
-rw-r--r--src/client/views/pdf/Page.tsx8
3 files changed, 34 insertions, 10 deletions
diff --git a/src/client/views/pdf/PDFMenu.tsx b/src/client/views/pdf/PDFMenu.tsx
index b0735f63b..b44370e3d 100644
--- a/src/client/views/pdf/PDFMenu.tsx
+++ b/src/client/views/pdf/PDFMenu.tsx
@@ -18,7 +18,7 @@ export default class PDFMenu extends React.Component {
@observable private _pinned: boolean = false;
StartDrag: (e: PointerEvent) => void = emptyFunction;
- Highlight: (d: Doc | undefined) => void = emptyFunction;
+ Highlight: (d: Doc | undefined, color: string | undefined) => void = emptyFunction;
@observable Highlighting: boolean = false;
private _timeout: NodeJS.Timeout | undefined;
@@ -129,11 +129,11 @@ export default class PDFMenu extends React.Component {
@action
highlightClicked = (e: React.MouseEvent) => {
if (!this._pinned) {
- this.Highlight(undefined);
+ this.Highlight(undefined, "#f4f442");
}
else {
this.Highlighting = !this.Highlighting;
- this.Highlight(undefined);
+ this.Highlight(undefined, "#f4f442");
}
}
diff --git a/src/client/views/pdf/PDFViewer.tsx b/src/client/views/pdf/PDFViewer.tsx
index 9becfb419..d74a16f3f 100644
--- a/src/client/views/pdf/PDFViewer.tsx
+++ b/src/client/views/pdf/PDFViewer.tsx
@@ -23,6 +23,7 @@ import { Dictionary } from "typescript-collections";
import * as rp from "request-promise";
import { restProperty } from "babel-types";
import { DocServer } from "../../DocServer";
+import { number } from "prop-types";
export const scale = 2;
interface IPDFViewerProps {
@@ -141,10 +142,33 @@ class Viewer extends React.Component<IViewerProps> {
setTimeout(() => {
// this.renderPages(this.startIndex, this.endIndex, true);
- this.saveThumbnail();
+ this.initialLoad();
}, 1000);
}
+ @action
+ initialLoad = () => {
+ let pdf = this.props.pdf;
+ if (pdf) {
+ this._pageSizes = Array<{ width: number, height: number }>(pdf.numPages);
+ let rendered = 0;
+ for (let i = 0; i < pdf.numPages; i++) {
+ pdf.getPage(i + 1).then(
+ (page: Pdfjs.PDFPageProxy) => {
+ runInAction(() => {
+ this._pageSizes[i] = { width: page.view[2] * scale, height: page.view[3] * scale };
+ });
+ console.log(`page ${i} size retreieved`);
+ rendered++;
+ if (rendered === pdf!.numPages - 1) {
+ this.saveThumbnail();
+ }
+ }
+ );
+ }
+ }
+ }
+
private mainCont = (div: HTMLDivElement | null) => {
if (this._dropDisposer) {
this._dropDisposer();
@@ -186,7 +210,7 @@ class Viewer extends React.Component<IViewerProps> {
drop = async (e: Event, de: DragManager.DropEvent) => {
if (de.data instanceof DragManager.LinkDragData) {
let sourceDoc = de.data.linkSourceDocument;
- let destDoc = this.makeAnnotationDocument(sourceDoc);
+ let destDoc = this.makeAnnotationDocument(sourceDoc, 1, "red");
let targetAnnotations = DocListCast(this.props.parent.Document.annotations);
if (targetAnnotations) {
targetAnnotations.push(destDoc);
@@ -392,7 +416,7 @@ class Viewer extends React.Component<IViewerProps> {
let numPages = this.props.pdf ? this.props.pdf.numPages : 0;
let index = 0;
let currOffset = vOffset;
- while (index < numPages && currOffset - (this._pageSizes[index] ? this._pageSizes[index].height : 792 * scale) > 0) {
+ while (index < this._pageSizes.length && currOffset - (this._pageSizes[index] ? this._pageSizes[index].height : 792 * scale) > 0) {
currOffset -= this._pageSizes[index] ? this._pageSizes[index].height : this._pageSizes[0].height;
index++;
}
diff --git a/src/client/views/pdf/Page.tsx b/src/client/views/pdf/Page.tsx
index e706a0d5c..bb87ec9d4 100644
--- a/src/client/views/pdf/Page.tsx
+++ b/src/client/views/pdf/Page.tsx
@@ -133,9 +133,9 @@ export default class Page extends React.Component<IPageProps> {
}
@action
- highlight = (targetDoc?: Doc) => {
+ highlight = (targetDoc?: Doc, color: string = "red") => {
// creates annotation documents for current highlights
- let annotationDoc = this.props.makeAnnotationDocuments(targetDoc, scale, "#f4f442");
+ let annotationDoc = this.props.makeAnnotationDocuments(targetDoc, scale, color);
let targetAnnotations = Cast(this.props.parent.Document.annotations, listSpec(Doc));
if (targetAnnotations === undefined) {
Doc.GetProto(this.props.parent.Document).annotations = new List([annotationDoc]);
@@ -162,7 +162,7 @@ export default class Page extends React.Component<IPageProps> {
// document that this annotation is linked to
let targetDoc = Docs.TextDocument({ width: 200, height: 200, title: "New Annotation" });
targetDoc.targetPage = this.props.page;
- let annotationDoc = this.highlight(targetDoc);
+ let annotationDoc = this.highlight(targetDoc, "red");
// create dragData and star tdrag
let dragData = new DragManager.AnnotationDragData(thisDoc, annotationDoc, targetDoc);
if (this._textLayer.current) {
@@ -323,7 +323,7 @@ export default class Page extends React.Component<IPageProps> {
if (PDFMenu.Instance.Highlighting) {
- this.highlight(undefined);
+ this.highlight(undefined, "#f4f442");
}
else {
PDFMenu.Instance.StartDrag = this.startDrag;