Skip to content
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

Using fitty synchronously #97

Open
miguelcobain opened this issue Nov 8, 2023 · 1 comment
Open

Using fitty synchronously #97

miguelcobain opened this issue Nov 8, 2023 · 1 comment

Comments

@miguelcobain
Copy link
Contributor

miguelcobain commented Nov 8, 2023

Problem: we have text with font-size from fitty. When the user tries to print the page, the page size changes, but fitty does not update.

I tried calling fit() on the beforeprint event, but that didn't help. The font-size still didn't update.
I then understood that fitty does its calculations and updates asynchronously in a requestAnimationFrame call. For the layout changes to be effective in the print layout, they need to be done synchronously inside the beforeprint event handler.

Proposed solutions:

  1. provide a way to make the calculations and updates synchronously fitSync() method?
  2. provide an observePrint option, much like the existing observeWindow, that listens to the beforeprint event and recalculates synchronously
@rikschennink
Copy link
Owner

@miguelcobain appreciate the thorough ticket, and PR. 🙏

I like introducing a sync option better as it doesn't pull in additional specific functionality and is thus more flexibly towards future situations that might also require sync redraw.

Perhaps we can add an options object to requestRedraw(options = { sync: false }), then it cancels the animation frame and calls redraw immediately after.

redrawAll(type) = () => could then change to redrawAll(type) = (options = { sync: false }) => then you could call fitAll({ sync: true })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants