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

How to read contents in a page #127

Closed
gamedev-pgd opened this issue Aug 21, 2012 · 2 comments
Closed

How to read contents in a page #127

gamedev-pgd opened this issue Aug 21, 2012 · 2 comments

Comments

@gamedev-pgd
Copy link

Hello,

Sorry to post this message here but there is no other user forum for Monocle so I gotta do it here. Is there any way to read the contents of the page being displayed? We are trying to implement a read aloud feature in monocle that would sync an audio file with the text being displayed in the reader. As far as my understanding of Monocle so far goes, the iFrame content is being divided into pages depending on the dimensions of the reader and the iFrame is being translated accordingly. But is there any function or way to hack into it such that only the contents of the current page are retrieved?

Thank you,

@joseph
Copy link
Owner

joseph commented Aug 27, 2012

You can do this using the getClientRects DOM function. Basically, if you know the pixel offset of the current page (crudely: page-width * page-number), you can go through each DOM element and check whether any of its rectangles are in the rectangle of the current page.

Obviously this is computationally expensive and you probably want to cache your rectangles if you are doing it frequently.

This is exactly how the Stencil control works — if Stencil doesn't do what you need, I recommend reading through that code and adapt the technique to your needs.

@joseph joseph closed this as completed Aug 27, 2012
@gamedev-pgd
Copy link
Author

Thanks for your help. I will try it and let you know.

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