Skip to content

Commit

Permalink
added custom renderer for entire layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ishan Kaul committed Dec 7, 2022
1 parent 97d8b87 commit 4809c6b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/Page.jsx
Expand Up @@ -79,6 +79,7 @@ export class PageInternal extends PureComponent {

const {
canvasBackground,
customTextLayerRenderer,
customTextRenderer,
devicePixelRatio,
onGetAnnotationsError,
Expand All @@ -98,6 +99,7 @@ export class PageInternal extends PureComponent {
return {
canvasBackground,
customTextRenderer,
customTextLayerRenderer,
devicePixelRatio,
onGetAnnotationsError,
onGetAnnotationsSuccess,
Expand Down Expand Up @@ -382,6 +384,7 @@ PageInternal.propTypes = {
canvasBackground: PropTypes.string,
children: PropTypes.node,
className: isClassName,
customTextLayerRenderer: PropTypes.func,
customTextRenderer: PropTypes.func,
devicePixelRatio: PropTypes.number,
error: isFunctionOrNode,
Expand Down
8 changes: 6 additions & 2 deletions src/Page/TextLayer.jsx
Expand Up @@ -145,7 +145,7 @@ export class TextLayerInternal extends PureComponent {
const container = this.layerElement.current;

const { viewport } = this;
const { customTextRenderer, pageIndex, pageNumber } = this.props;
const { customTextLayerRenderer, customTextRenderer, pageIndex, pageNumber } = this.props;

// If another rendering is in progress, let's cancel it
cancelRunningTask(this.runningTask);
Expand All @@ -168,7 +168,10 @@ export class TextLayerInternal extends PureComponent {
container.append(end);
this.endElement.current = end;

if (customTextRenderer) {
if (customTextLayerRenderer) {
this.customTextLayerRenderer(textContent.items, this.layerElement.current.children, pageIndex, pageNumber);
}
else if (customTextRenderer) {
let index = 0;
textContent.items.forEach((item, itemIndex) => {
const child = this.layerElement.current.children[index];
Expand Down Expand Up @@ -208,6 +211,7 @@ export class TextLayerInternal extends PureComponent {
}

TextLayerInternal.propTypes = {
customTextLayerRenderer: PropTypes.func,
customTextRenderer: PropTypes.func,
onGetTextError: PropTypes.func,
onGetTextSuccess: PropTypes.func,
Expand Down

0 comments on commit 4809c6b

Please sign in to comment.