Skip to content
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

7455 - PDF document scaling #7485

Merged
merged 78 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
7347dc5
maintain scale of current selections
Zasa-san Nov 25, 2024
395ac3a
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 26, 2024
5208a26
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 26, 2024
5e62de4
stateful scaling + device zoom adjustments
Zasa-san Nov 26, 2024
877f388
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 26, 2024
e16d7d9
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 27, 2024
4c0630e
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 28, 2024
5144f2b
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Nov 28, 2024
052d619
centered pdf with no scaling
Zasa-san Nov 28, 2024
f8dc69f
use container size for intial width
Zasa-san Nov 28, 2024
789fa8d
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 2, 2024
5500d50
final scale adjustments on the sidepanel
Zasa-san Dec 2, 2024
6e5e88c
better scalling + atom
Zasa-san Dec 2, 2024
08458b4
test scaling helper
Zasa-san Dec 2, 2024
6517764
fix scaling on entity view
Zasa-san Dec 2, 2024
c7d13a3
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 3, 2024
ebf1abc
better scalling calculation
Zasa-san Dec 3, 2024
270924e
move necessary styles to sheet
Zasa-san Dec 3, 2024
cf1ba0b
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 4, 2024
3e83783
Merge branch '7455-pdf-document-scaling' of https://github.com/hurido…
Zasa-san Dec 4, 2024
2eddb48
minimal scaling
Zasa-san Dec 5, 2024
32fc6f8
update spec
Zasa-san Dec 5, 2024
487f399
refactor + scale new selections
Zasa-san Dec 5, 2024
78f7388
type update + metadata extractor new selections
Zasa-san Dec 9, 2024
1060230
make excepition for empty rectangles
Zasa-san Dec 9, 2024
0867bd1
refactor and test handler
Zasa-san Dec 9, 2024
4f11999
adjust existing selections in main pdf view
Zasa-san Dec 9, 2024
a87d8c5
cover with snaptshot
Zasa-san Dec 9, 2024
911ebb3
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 10, 2024
4e785d2
display existing references
Zasa-san Dec 10, 2024
f2006de
handle new references
Zasa-san Dec 10, 2024
74b33d5
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 11, 2024
775cd1e
add document scale to redux for toc
Zasa-san Dec 11, 2024
a67388f
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 12, 2024
acf24c4
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 13, 2024
28ec2e6
effectivly scaling regardless of dpr
Zasa-san Dec 13, 2024
b5c712a
include scaling in test
Zasa-san Dec 16, 2024
ef14957
adjust container padding
Zasa-san Dec 16, 2024
baa1855
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 16, 2024
8cc9410
optional parameter
Zasa-san Dec 16, 2024
8b6e239
refactor
Zasa-san Dec 16, 2024
1279aed
revert unnecessary normalization
Zasa-san Dec 16, 2024
266e306
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 16, 2024
5aca9c3
fix lint
Zasa-san Dec 16, 2024
58a7f4d
Revert "revert unnecessary normalization"
Zasa-san Dec 17, 2024
4df7c6e
adjustments to styles & selections
Zasa-san Dec 18, 2024
fcf0587
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Dec 18, 2024
23b6b1f
avoid scaling twice
Zasa-san Dec 20, 2024
2e8b1cc
better prop for pdf container width + test update
Zasa-san Dec 20, 2024
6fe16ca
safely adjust selections for scale
Zasa-san Dec 23, 2024
4b3c22b
extract event bus and reduce rerenders
Zasa-san Jan 2, 2025
da90074
update snapshot
Zasa-san Jan 3, 2025
08017e9
scroll element into view
Zasa-san Jan 3, 2025
096b4e0
adjust selector and snapshot
Zasa-san Jan 3, 2025
e475d9e
refactor pdf page rendering
Zasa-san Jan 5, 2025
872ebd8
optimize rendering
Zasa-san Jan 5, 2025
036cf47
optimize pdf rendering
Zasa-san Jan 5, 2025
27fcf5e
adjusted e2e
Zasa-san Jan 5, 2025
d281c81
remove duplicated class
Zasa-san Jan 6, 2025
4c287c2
wip unit test for v2 pdf
Zasa-san Jan 6, 2025
6dd7334
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Jan 7, 2025
033697a
use e2e instead of unit test
Zasa-san Jan 7, 2025
01e5878
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Jan 7, 2025
62d8902
add responsive checks
Zasa-san Jan 7, 2025
6b18566
remove unused dep
Zasa-san Jan 7, 2025
29df701
removed unused package
Zasa-san Jan 7, 2025
ca922f1
use realClick
Zasa-san Jan 7, 2025
12a901f
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Jan 8, 2025
20a2ff3
extract method for testing
Zasa-san Jan 8, 2025
4261374
unit test + remove cavas dev dep
Zasa-san Jan 8, 2025
bba8690
increase timeout to avoid failure
Zasa-san Jan 8, 2025
a1bea1a
remove odd console.log
Zasa-san Jan 8, 2025
e51230c
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Jan 9, 2025
00e1c8c
use smaller snapshots
Zasa-san Jan 9, 2025
523f6ac
Merge branch 'development' into 7455-pdf-document-scaling
Zasa-san Jan 9, 2025
aefa059
make sure video exists before saving
Zasa-san Jan 9, 2025
54569b9
stabilze e2e
Zasa-san Jan 9, 2025
4b742e2
stabilize new e2e
Zasa-san Jan 9, 2025
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
22 changes: 22 additions & 0 deletions app/react/App/scss/elements/_pdfViewer.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pdf-container {
margin: auto;
width: fit-content;

.pdf-page {
position: relative;
}

& .canvasWrapper {
margin: 0;
display: block;
width: 100%;
height: 100%;

& canvas {
margin: 0;
display: block;
width: 100%;
height: 100%;
}
}
}
1 change: 1 addition & 0 deletions app/react/App/scss/styles.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@import 'elements/item';
@import 'elements/linkField';
@import 'elements/panel';
@import 'elements/pdfViewer';
@import 'elements/breadcrumbs';
@import 'elements/draggable';
@import 'elements/dropdown';
Expand Down
62 changes: 34 additions & 28 deletions app/react/Documents/components/ShowToc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,20 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { scrollToToc } from 'app/Viewer/actions/uiActions';
import Immutable from 'immutable';
import ShowIf from 'app/App/ShowIf';
import { t } from 'app/I18N';
import { Icon } from 'UI';

import { selectionHandlers } from 'V2/Components/PDFViewer';
import './scss/showToc.scss';

export class ShowToc extends Component {
class ShowToc extends Component {
scrollTo(tocElement, e) {
e.preventDefault();
this.props.scrollToToc(tocElement.toJS());
this.props.scrollToToc(tocElement);
}

render() {
const toc = Immutable.fromJS(this.props.toc);

if (!toc.size) {
if (!this.props.toc.length) {
return (
<div className="blank-state">
<Icon icon="font" />
Expand All @@ -28,29 +25,34 @@ export class ShowToc extends Component {
);
}

const { documentScale } = this.props;

return (
<div className="toc">
<ul className="toc-view">
{toc.map((tocElement, index) => (
<li className={`toc-indent-${tocElement.get('indentation')}`} key={index}>
<ShowIf if={!this.props.readOnly}>
<a
className="toc-view-link"
href="#"
onClick={this.scrollTo.bind(this, tocElement)}
>
{tocElement.get('label')}
<span className="page-number">
{tocElement.getIn(['selectionRectangles', 0]) &&
tocElement.getIn(['selectionRectangles', 0]).get('page')}
</span>
</a>
</ShowIf>
<ShowIf if={this.props.readOnly}>
<span className="toc-view-link">{tocElement.get('label')}</span>
</ShowIf>
</li>
))}
{this.props.toc.map((tocElement, index) => {
const scaledToc = selectionHandlers.adjustSelectionsToScale(tocElement, documentScale);

return (
<li className={`toc-indent-${scaledToc.indentation}`} key={index}>
<ShowIf if={!this.props.readOnly}>
<a
className="toc-view-link"
href="#"
onClick={this.scrollTo.bind(this, scaledToc)}
>
{scaledToc.label}
<span className="page-number">
{scaledToc.selectionRectangles[0] && scaledToc.selectionRectangles[0].page}
</span>
</a>
</ShowIf>
<ShowIf if={this.props.readOnly}>
<span className="toc-view-link">{scaledToc.label}</span>
</ShowIf>
</li>
);
})}
</ul>
</div>
);
Expand All @@ -65,10 +67,14 @@ ShowToc.propTypes = {
toc: PropTypes.array,
readOnly: PropTypes.bool,
scrollToToc: PropTypes.func,
documentScale: PropTypes.number,
};

function mapDispatchToProps() {
return { scrollToToc };
}

export default connect(null, mapDispatchToProps)(ShowToc);
const mapStateToProps = store => ({ documentScale: store.documentViewer.documentScale });

export { ShowToc };
export default connect(mapStateToProps, mapDispatchToProps)(ShowToc);
4 changes: 0 additions & 4 deletions app/react/Documents/components/SnippetList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,7 @@ const DocumentContentSnippets = ({
{documentSnippets.map((snippet, index) => {
const selected = snippet.get('text') === selectedSnippet.get('text') ? 'selected' : '';
const filename = snippet.get('filename');
console.log('filename', filename);
const page = snippet.get('page');
console.log(
`${documentViewUrl}?page=${page}&searchTerm=${searchTerm || ''}${filename ? `&file=${filename}` : ''}`
);
return (
<li key={index} className={`snippet-list-item fulltext-snippet ${selected}`}>
<I18NLink
Expand Down
3 changes: 2 additions & 1 deletion app/react/Documents/components/TocForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { Component } from 'react';
import { Form, Field } from 'react-redux-form';
import { Icon } from 'UI';

export class TocForm extends Component {
class TocForm extends Component {
constructor(props) {
super(props);
this.submit = this.submit.bind(this);
Expand Down Expand Up @@ -70,4 +70,5 @@ TocForm.propTypes = {
onSubmit: PropTypes.func,
};

export { TocForm };
export default TocForm;
8 changes: 5 additions & 3 deletions app/react/Metadata/components/MetadataExtractor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ type OwnPropTypes = {
locale?: string;
};

type selection = {
type Selection = {
text: string;
selectionRectangles: SelectionRectanglesSchema;
};

const mapStateToProps = (state: IStore) => ({
selection: state.documentViewer.uiState
.get('reference')
.get('sourceRange') as unknown as selection,
.get('sourceRange') as unknown as Selection,
});

const mapDispatchToProps = (dispatch: Dispatch<{}>, ownProps: OwnPropTypes) => {
Expand Down Expand Up @@ -60,7 +60,9 @@ const MetadataExtractorComponent = ({
'warning'
);
}

setSelection(selection);

updateField(selection.text);
};

Expand All @@ -79,5 +81,5 @@ const MetadataExtractorComponent = ({

const container = connector(MetadataExtractorComponent);

export type { selection };
export type { Selection };
export { container as MetadataExtractor };
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import { screen, act, fireEvent } from '@testing-library/react';
import { notificationActions } from 'app/Notifications';
import { defaultState, renderConnectedContainer } from 'app/utils/test/renderConnected';
import * as actions from '../../actions/metadataExtractionActions';
import { MetadataExtractor, selection } from '../MetadataExtractor';
import { MetadataExtractor, Selection } from '../MetadataExtractor';

describe('MetadataExtractor', () => {
let selected: selection | undefined;
let selected: Selection | undefined;

beforeEach(() => {
spyOn(actions, 'updateSelection').and.returnValue(() => {});
Expand Down
28 changes: 17 additions & 11 deletions app/react/PDF/components/PDF.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class PDF extends Component {
this.pageLoading = this.pageLoading.bind(this);
this.onPageVisible = this.onPageVisible.bind(this);
this.onPageHidden = this.onPageHidden.bind(this);
this.containerWidth = 0;
}

componentDidMount() {
Expand All @@ -42,6 +43,8 @@ class PDF extends Component {
});
document.addEventListener('textlayerrendered', this.props.onPageLoaded, { once: true });
}

this.containerWidth = this.props.parentRef.current?.clientWidth;
}

shouldComponentUpdate(nextProps, nextState) {
Expand Down Expand Up @@ -148,21 +151,22 @@ class PDF extends Component {

render() {
return (
<div
ref={ref => {
this.pdfContainer = ref;
}}
style={this.props.style}
<HandleTextSelection
onSelect={this.props.onTextSelection}
onDeselect={this.props.onTextDeselection}
>
<HandleTextSelection
onSelect={this.props.onTextSelection}
onDeselect={this.props.onTextDeselection}
<div
ref={ref => {
this.pdfContainer = ref;
}}
style={this.props.style}
id="pdf-container"
>
{(() => {
const pages = [];
for (let page = 1; page <= this.state.pdf.numPages; page += 1) {
pages.push(
<div className="page-wrapper" key={page}>
<div key={page}>
<SelectionRegion regionId={page.toString()}>
<PDFPage
onUnload={this.pageUnloaded}
Expand All @@ -172,15 +176,16 @@ class PDF extends Component {
page={page}
pdf={this.state.pdf}
highlightReference={this.props.highlightReference}
containerWidth={this.containerWidth}
/>
</SelectionRegion>
</div>
);
}
return pages;
})()}
</HandleTextSelection>
</div>
</div>
</HandleTextSelection>
);
}
}
Expand All @@ -207,6 +212,7 @@ PDF.propTypes = {
onLoad: PropTypes.func.isRequired,
style: PropTypes.object,
highlightReference: PropTypes.func,
parentRef: PropTypes.object.isRequired,
};

export default PDF;
16 changes: 13 additions & 3 deletions app/react/PDF/components/PDFPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import React, { Component } from 'react';
import { isClient } from 'app/utils';
import { PageReferences } from 'app/Viewer/components/PageReferences';
import { PageSelections } from 'app/Viewer/components/PageSelections';
import { calculateScaling } from 'V2/Components/PDFViewer';
import { atomStore, pdfScaleAtom } from 'V2/atoms';
import PDFJS, { EventBus } from '../PDFJS';

class PDFPage extends Component {
Expand Down Expand Up @@ -112,17 +114,24 @@ class PDFPage extends Component {
this.props.onLoading(this.props.page);
this.setState({ rendered: true });
this.props.pdf.getPage(this.props.page).then(page => {
const scale = 1;
const originalViewport = page.getViewport({ scale: 1 });
const scale = calculateScaling(
originalViewport.width * PDFJS.PixelsPerInch.PDF_TO_CSS_UNITS,
this.props.containerWidth
);
const defaultViewport = page.getViewport({ scale });

this.pdfPageView = new PDFJS.PDFPageView({
container: this.pageContainer,
id: this.props.page,
scale,
defaultViewport: page.getViewport({ scale }),
defaultViewport,
textLayerMode: 1,
eventBus: new EventBus(),
});

atomStore.set(pdfScaleAtom, scale);

this.pdfPageView.setPdfPage(page);
this.pdfPageView
.draw()
Expand All @@ -144,7 +153,7 @@ class PDFPage extends Component {
return (
<div
id={`page-${this.props.page}`}
className="doc-page"
className="pdf-page"
ref={ref => {
this.pageContainer = ref;
}}
Expand Down Expand Up @@ -172,6 +181,7 @@ PDFPage.propTypes = {
onUnload: PropTypes.func.isRequired,
pdf: PropTypes.object.isRequired,
highlightReference: PropTypes.func,
containerWidth: PropTypes.number.isRequired,
};

export default PDFPage;
1 change: 1 addition & 0 deletions app/react/PDF/components/specs/PDF.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ describe('PDF', () => {
file: 'file_url',
filename: 'original.pdf',
onLoad: jasmine.createSpy('onLoad'),
parentRef: { current: { clientWidth: 500 } },
};
});

Expand Down
Loading
Loading