Skip to content

Font size change corrupts inactive tabs #7321

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

Closed
kravlost opened this issue Mar 14, 2018 · 10 comments · Fixed by #11650
Closed

Font size change corrupts inactive tabs #7321

kravlost opened this issue Mar 14, 2018 · 10 comments · Fixed by #11650
Labels
Component: IDE user interface The Arduino IDE's user interface IDE 1.9.x Beta Related to the Arduino IDE Beta Build Type: Bug Upstream notified Related to a software component maintained by someone else. They have been notified of it

Comments

@kravlost
Copy link

kravlost commented Mar 14, 2018

I have a sketch with several tabs. If I change the font size using the menu, the active tab refreshes correctly. If I then click on another tab, the text isn't drawn correctly and overlaps (see below). If I then change the font scale the active tab refreshes correctly.

image

Arduino IDE 1.8.5, Arduino IDE 1.8.14 Hourly Build 2021/03/09 09:33

@facchinm facchinm added Component: IDE user interface The Arduino IDE's user interface IDE 1.9.x Beta Related to the Arduino IDE Beta Build labels Mar 14, 2018
@facchinm
Copy link
Member

Confirmed, thanks for reporting, will take a look later today 😉

@facchinm
Copy link
Member

The bug lies here: https://github.com/bobbylight/RSyntaxTextArea/blame/master/src/main/java/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java#L2067

If you modify the font size on the fly and select a tab which hasn't been opened, the result is fine. As soon as you open it once, the repain() doesn't call refreshFontMetrics() so the spaces between letters are wrong. Looks quite difficult to fix on our side, probably opening an issue upstream is the way to go.

@per1234 per1234 added the Upstream notified Related to a software component maintained by someone else. They have been notified of it label Mar 16, 2018
@JaredReabow
Copy link

This is still not fixed

@bobbylight
Copy link

bobbylight commented Aug 16, 2021

Howdy - the RSyntaxTextArea source has changed since this ticket was opened. I'm interested in taking a look again. Can someone let me know how you're updating the font size on these already-displayed editors and let me know you believe it's failing?

The following two approaches should work, with caveats, provided the editor is displayable:

  • Calling setFont(newFont) - this works as long as only a single font and font size are used for all token types in the editor (using bold & italics is OK). This updates all token types using the "default" font's font family and size, which by default all tokens use the same font so this just works.
  • Use RSyntaxTextAreaEditorKit.IncreaseFontSizeAction and DecreaseFontSizeAction, which should always work, even if different fonts are used for different token types.

In any case, let me know how to reproduce this and I'll try to get it fixed in the next RSTA release.

@facchinm
Copy link
Member

Hi @bobbylight ,
thanks for taking a look. I'm attaching a vide of the behaviour (tested with 3.1.3 so the issue is still not fixed).

out_EDIT.mp4

Let me know if you need any addidional info to reproduce and thanks for your great work!

@bobbylight
Copy link

bobbylight commented Aug 18, 2021

@facchinm , is that a standard JTabbedPane - and thus, are the editors in each tab always in the UI until their tab is closed? Or are you removing RSyntaxTextAreas and adding new ones when tabs are clicked (or something similar like swapping out the Document)?

I'm still struggling a little to see how this can happen - any call to setFont() or setSyntaxScheme() should refresh the font metrics cache, provided the editor is displayable, which is why I'm wondering if you're not using a standard RSyntaxTextArea-per-tab setup.

If you're doing something like that, one possible fix on my side is to set metricsNefverRefreshed to false in removeNotify(), which would be symmetric with what we do in addNotify() and trigger a refresh of the font metrics cache the next time the editor is added to a UI.

@cmaglie
Copy link
Member

cmaglie commented Aug 18, 2021

We extended RSyntaxTextArea as a SketchTextArea here: https://github.com/arduino/Arduino/blob/master/app/src/processing/app/syntax/SketchTextArea.java#L77

We don't swap Document to reuse the same SketchTextArea, in the Editor we collect a list of EditorTab each one having a separate SketchTextArea:

https://github.com/arduino/Arduino/blob/master/app/src/processing/app/Editor.java#L122
https://github.com/arduino/Arduino/blob/master/app/src/processing/app/EditorTab.java#L72

any call to setFont() or setSyntaxScheme() should refresh the font metrics cache, provided the editor is displayable

Is there a reason why the editor must be displayable to recalculate the metrics?

@cmaglie
Copy link
Member

cmaglie commented Aug 18, 2021

Just to give you some more context, here is how we "change tab" in the editor: https://github.com/arduino/Arduino/blob/master/app/src/processing/app/Editor.java#L1437-L1462

maybe it gives some clues maybe not...

@cmaglie
Copy link
Member

cmaglie commented Aug 18, 2021

...and I think I fixed it by forcing a setFont call inside the selectTab function: #11650

I don't know if this is the correct fix, I see that in selectTab the text area is removed from the JPanel when is hidden, maybe that is the reason why the font metrics are wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE user interface The Arduino IDE's user interface IDE 1.9.x Beta Related to the Arduino IDE Beta Build Type: Bug Upstream notified Related to a software component maintained by someone else. They have been notified of it
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants
@cmaglie @bobbylight @JaredReabow @kravlost @per1234 @facchinm and others