-
Notifications
You must be signed in to change notification settings - Fork 236
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
Calculating height of a paragraph (for the purpose of computing page size for printing) #132
Comments
There isn't any support for breaking text into pages. To calculate the height of text given the font, you could create a Text or TextFlow node, set the font, and get its preferred height. You could also try to look into You could also dig into into CodeArea to get the VirtualFlow. Resize the CodeArea to the printable size and then scroll to the top (e.g. Or, also using the enclosed VirtualFlow, to get the height of the first visible paragraph, you could just do |
Thanks for the prompt response. I tried creating both a Text and a TextFlow node using my font and font size and then asking for its height, but it gave me the wrong height as far as printing is concerned. I'd like to try your VirtualFlow idea to get the height of the first visible paragraph, but can you give me a little more information on how to get a virtual flow from the CodeArea? |
You probably also need to set some text for the Getting the VirtualFlow is not public API, so be advised that this may change in the future. Currently, it happens to be the first child of the first child of the CodeArea, so this is the direct way to get it: VirtualFlow<?, ?> vf = (VirtualFlow<?, ?>)
((Parent) codeArea.getChildrenUnmodifiable().get(0))
.getChildrenUnmodifiable().get(0); A little more robust way is to look it up by its style class: VirtualFlow<?, ?> vf = (VirtualFlow<?, ?>) codeArea.lookup(".virtual-flow"); Then, double height = vf.visibleCells().get(0).getNode().getLayoutBounds().getHeight(); |
Thank you! The last way works great. |
I'd like to be able to print the contents of a CodeArea that contains a hundred or more lines of code, which means I need to break it up into pages for printing. Each line of my code is one Paragraph. Therefore, using PageLayout.getPrintableHeight() to get the total number of points I have to work with on each page, and dividing that total by the number of points of height per paragraph, I can figure out how many paragraphs will fit on a page. But to do this, I need a way of getting the height of a paragraph. Is there a way to do it, given the font and font size of the paragraph, e.g., Courier 12? Or is there some other better way of breaking a CodeArea into pages for printing? (Also, should I have asked this question on StackOverflow instead of here?)
The text was updated successfully, but these errors were encountered: