-
Notifications
You must be signed in to change notification settings - Fork 33
feat: add PDF viewer with highlighting #238
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
Conversation
Can you please add to this section? Did a quick test in Storybook. I see the new |
jhpedemonte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the major things you were investigating was highlighting on Japanese text, correct? You should include a sample doc to show this off (similar to __fixtures__/Art Effects.pdf).
...mponents/src/components/DocumentPreview/components/PdfViewerHighlight/PdfViewerHighlight.tsx
Outdated
Show resolved
Hide resolved
...mponents/src/components/DocumentPreview/components/PdfViewerHighlight/PdfViewerHighlight.tsx
Show resolved
Hide resolved
...mponents/src/components/DocumentPreview/components/PdfViewerHighlight/PdfViewerHighlight.tsx
Outdated
Show resolved
Hide resolved
...ents/src/components/DocumentPreview/components/PdfViewerHighlight/PdfViewerWithHighlight.tsx
Outdated
Show resolved
Hide resolved
...ents/src/components/DocumentPreview/components/PdfViewerHighlight/PdfViewerWithHighlight.tsx
Outdated
Show resolved
Hide resolved
...umentPreview/components/PdfViewerHighlight/utils/textBoxMapping/MappingTargetCellProvider.ts
Outdated
Show resolved
Hide resolved
.../components/DocumentPreview/components/PdfViewerHighlight/utils/textLayout/BaseTextLayout.ts
Show resolved
Hide resolved
...s/DocumentPreview/components/PdfViewerHighlight/utils/textLayout/PdfTextContentTextLayout.ts
Outdated
Show resolved
Hide resolved
...ponents/src/components/DocumentPreview/components/PdfViewerHighlight/utils/textLayout/dom.ts
Outdated
Show resolved
Hide resolved
...ponents/src/components/DocumentPreview/components/PdfViewerHighlight/utils/textLayout/dom.ts
Outdated
Show resolved
Hide resolved
Thank you for pointing this out. They should work. I found some issue with them and will fix. |
I just added a small Japanese PDF sample. |
- add return type - add document to methods/classes
|
jhpedemonte
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good overall and functions well in Storybook. Found a few minor things. With those fixed, approved.
|
|
||
| /** | ||
| * Flag to whether or not to use bbox information from html field in the document. | ||
| * True by default. This is for testing and debugging purpose. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should better denote that these properties aren't meant to be used normally by end users. Best I can think is to prepend an underscore to the name:
_useHtmlBbox?: boolean;
...onents/src/components/DocumentPreview/components/PdfViewerHighlight/utils/common/nonEmpty.ts
Outdated
Show resolved
Hide resolved
| @@ -0,0 +1,25 @@ | |||
| .withTextSelection { | |||
| display: flex; | |||
| height: 800px; | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this have an explicit height? Is it possible to make it relative?
|
|
||
| .highlight { | ||
| opacity: 0.4; | ||
| background: rgba(255, 64, 128, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check what Carbon says about highlighting text and which colors/opacity to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only thing I found so far is $highlight from https://www.carbondesignsystem.com/guidelines/color/usage. That's fine if there's a single highlight in the component, but we'll need more guidance if we have to handle multiple highlight colors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I update the code to use the $highlight color so far.
| const heightB = bottomB - topB; | ||
|
|
||
| // compare height ratio | ||
| const OVERLAP_RATIO = 0.8; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Move this constant out of the function and to the top of the file.
- Also, what is the purpose of this constance? How was it calculated? Add a description comment.
| */ | ||
| export function nonEmpty<T>(value: T | null | undefined): value is T { | ||
| return value !== null && value !== undefined; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function is generic and not specific to PdfViewerHighlight. Move it up to the top-level utils/.
| } | ||
|
|
||
| /** | ||
| * Text box mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't really explain this component. What does this map between?
| const MAX_HISTORY = 3; | ||
|
|
||
| export type TextMatch = { | ||
| /** matched text span */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For single line comments like these, let's keep with convention of just starting with // and leave /** for multi-line comments (here and elsewhere in PR).
(Wonder if there's an eslint/prettier plugin for this?)
| export const LEFT = 0; | ||
| export const TOP = 1; | ||
| export const RIGHT = 2; | ||
| export const BOTTOM = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where are these used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They were used in dom.ts. I refactored the code to use destructuring assignment.
| opacity: 0.5; | ||
| background: rgba(0, 0, 255, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: need to check with Design about use of highlight color/opacity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Use the Carbon color with opacity as a default and check with design.
Not yet, but I agree that it has to be considered to make this work as editor, too. I'm thinking to add a selection handler such as
I tried scanned document. Currently no highlight is shown on scanned document and need to fix it. On scanned PDF, highlight relies on bboxes in HTML field. With a document I tried, the bboxes spans on multiple lines and highlight were not accurate. Smaller bboxes are required for more accuracy. |
* origin/master: chore: publish v1.5.0-beta.10 [ci skip] build: support Node 16 (#268) chore: publish v1.5.0-beta.9 [ci skip] chore: create a global rollup cmd (#262) chore: publish v1.5.0-beta.8 [ci skip] feat: document provider interface (#249) fix: mitigate overlapped or segmented highlight on PDF (#252) chore: publish v1.5.0-beta.7 [ci skip] fix: fix PDF highlight misalignment issue (#253) chore: publish v1.5.0-beta.6 [ci skip] chore: update Carbon to 10.46.0/7.46.0 (#254) chore: update Carbon to 10.46.0/7.46.0 (#250) chore: publish v1.5.0-beta.5 [ci skip] feat: add PDF viewer with highlighting (#238)
What do these changes do/fix?
This depends on #237.
This PR is to add
PDFViewerHighlightercomponent which is a highlight layer for PDF based on text spans on fields in search result document. This also implementsPDFViewerWithHighlightwhich is PDFViewerHighlighter integrated with PDFViewer.The implementation includes a logic to find calculate bboxes for highlighting. Overview of the logic is in README.md.
TextLayoutstextBoxMappingandHighlighterHow do you test/verify these changes?
htmlfrom the dropdown on the topHave you documented your changes (if necessary)?
Are there any breaking changes included in this pull request?