[renderTextLayer] Decouple computation and DOM operations
See original GitHub issueCurrently 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 :
- abstract those DOM operations inside
renderTextLayer
- 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:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Should I just start the PR ?
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.