question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[renderTextLayer] Decouple computation and DOM operations

See original GitHub issue

Currently renderTextLayer will compute the different properties (left, top, font-style, scale…) using canvas.measureText() and build the result view using vanilla DOM operations.

I’m working on an Angular PDF viewer based on pdf.js engine and not just a dummy wrapper. I would like to know if it possible to either :

  1. abstract those DOM operations inside renderTextLayer
  2. to extract the computation part so we could build our own renderTextLayer.

1) would most certainly result in an API break, while 2) could be contained on internal stuff and new API.

I can see at least 2 benefits :

  • We could avoid the DOM rebuild and just update the style of existing nodes on certain cases (when we zoom on the page for example).
  • We should* be able to make this work with server side rendering. (* still not sure about how to handle measureText() on node).

I will propose one or several implementation if you approve the idea.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ghetolaycommented, Sep 21, 2017

Should I just start the PR ?

0reactions
Snuffleupaguscommented, May 28, 2021

I really don’t think that we want to complicate and/or possibly slow down the general textLayer building by introducing e.g. a callback function, provided from the outside, for handling text measurement. Furthermore, with somewhat recent changes, note that we’re now also relying even more on the browser to obtain information about fonts used for the textLayer; see e.g. https://github.com/mozilla/pdf.js/blob/d285580f486178a41a316d615f3157ec7e1afcb3/src/display/text_layer.js#L51-L116


This is probably the sort of thing that belongs in a custom implementation/fork of the PDF.js library, given the somewhat specialized use-case outlined in https://github.com/mozilla/pdf.js/issues/8575#issue-238494962. All-in-all, I do believe that this issue as filed should now be closed as WONTFIX.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage HTML DOM with vanilla JavaScript - HTML DOM
Manage HTML DOM with vanilla JavaScript. ... Attach or detach an event handler · Calculate the mouse position relative to an element.
Read more >
What is the Document Object Model? - W3C
The Document Object Model (DOM) is an application programming interface (API) for HTML and XML documents. It defines the logical structure of documents...
Read more >
JavaScript DOM Manipulation – Full Course for Beginners
Learn about JavaScript DOM manipulation in this beginner's tutorial. This is when you use JavaScript to add, remove, and modify elements of ...
Read more >
The Basics of DOM Manipulation in Vanilla JavaScript (No ...
Sebastian Seitz gives you a crash course in DOM manipulation with vanilla JavaScript, ... To get the computed values, we can use, .window....
Read more >
Introduction to the DOM - Web APIs | MDN
The Document Object Model (DOM) is the data representation of the objects ... in HTML) and manipulation of the DOM (written in JavaScript), ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found