-
-
Notifications
You must be signed in to change notification settings - Fork 184
Description
This is an extension of my Issue #124 .
Although the latest fix included in 2.44.0 did technically fix the problem in my original issue, I'm still not getting the desired result. After some more experimenting, I believe it is scrollHeight which is now being miscalculated. In my previous example I needed to use a wrapper div which I called "title-box" and/or "title-sizer". Ideally I would be able to do all calculations on the "title" div itself rather than needing a wrapper.
I've put together a simpler POC to illustrate the problem. You can run this project by cloning it and initializing in IntelliJ, the Gradle setup should hopefully do its thing and install dependencies. Once you run it through the IDE, simply hit localhost:8080 in your browser to see the resulting PDF.
The first example is a "current" example, which shows how things work in 2.44.0. This is the one that requires a wrapper div to make offsetHeight properly calculated.
I've also included a "future" example, which shows my ideal implementation. This "future" implementation actually works beautifully in a modern browser- you can see this by opening the test.html in your browser. The test.html file is included at the root of the project.
As you can see in these examples, when running this Javascript in your HtmlUnit parser, the scrollHeight is miscalculated. I see a scrollHeight of 60 being output when it's printed from the Javascript code, as well as from the Kotlin code itself using HtmlUnit methods getCalculatedHeight and getScrollHeight. The bottom text block (which is the ideal "future" case) is not shrunk properly. The offsetHeight is also very small (62), so I cannot refer to that value either. If either scrollHeight or offsetHeight were resulting in a much larger number, I could use that as a reference in my shrinking logic.
When the same code is run in the browser using the test.html file, however, you can see that the scrollHeight output in the console is 736. This allows the shrinking logic to work properly, and you see the desired result on the page.
Thank you very much for your continued work on this library. It is very much appreciated by me and my team. Please let me know if anything here doesn't make sense-- I'd be happy to have a video call with you to discuss further.
Here is a link to the POC: https://github.com/dvinitsky/text-shrink-poc.
Unfortunately I was not able to share my original code as it was on my work account. I was able to copy the files into this repo, but you'll have to use one of the .zip files or the .tar.gz file to retrieve the code.
Thank you.