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

Issue457: Fractional Scaling on Windows #524

Merged

Conversation

ptorngren
Copy link

Add support for FPAPI: Add new class SwingUtils with methods for leveraging the FPAPI

Modify concerned classes and methods to call SwingUtils and use Rectangle2D and float/double variables instead of Rectangle and integers:

  • DefaultTokenPainter.paintBackground()
  • RSyntaxUtilities.getLineWidthUpTo()
  • SyntaxView: tabBase, tabSize, clipStart, clipEnd, .calculateLongestLine(), lineToRect(), damageLineRange(), modelToView(), nextTabStop(), paint()
  • Token.listOffsetToView()
  • TokenImpl: getListOffset(), getWidthUpTo(), listOffsetToView()
  • VisibleWhitespaceTokenPainter()
  • WrappedSyntaxView.modelToView()

Layout/painter changes:

  • SyntaxViiew.nextTabStop(): Add offset for tabs to avoid losing tabs that occur on the same pixel as the preceding character end
  • ConfigurableCaret: use Rectangle2D and floats/doubles, primarily to avoid double lines on thick vertical line style
  • Add RSyntaxTextArea.onGraphicsChange() to let owner refresh font metrics when graphic properties change
  • DefaultTokenPainter: Fix tab lines by offsetting the line location slightly
  • SwingUtils.drawChars(): Use TextLayout for very long lines or containing complex characters (inspired by SwingUtilities2)

Adapt to Java 11: Replace calls to deprecated elements with corresponding elements for Java 9 or later
Rectangles and bounds:

  • add SwingUtils.getBounds() to wrap calls to modelToView2D(pos).getBounds() in a null-safe way
  • replace calls to JTextComponent.modelToView(int pos) with calls to SwingUtils.getBounds(JTextComponent c, int pos)
  • replace calls to JTextComponent.viewToModel(Point p) with calls to JTextComponent.viewToModel2D(Point2D p)

Events:

  • replace calls to InputEvent.getModifiers() with calls to MouseEvent.getModifiersEx()
  • replace calls to Toolkit.getMenuShortcutKeyMask() Toolkit.getMenuShortcutKeyMaskEx()
  • replace references to Event.META_MASK with InputEvent.META_DOWN_MASK
  • replace references to Event.CTRL_MASK with InputEvent.CTRL_DOWN_MASK
  • replace references to MouseEvent.BUTTON1_MASK with MouseEvent.BUTTON1_DOWN_MASK Not modified:
  • SyntaxScheme calls deprecated XMLReaderFactory.createXMLReader() which should be replaced with SaxParserFactory

Also modified the Demo Root Pane:

  • add a text example
  • show a larger screen centered on monitor
  • add a font selector
  • add menu option to make whitespace visible

p2rsoftware and others added 30 commits January 11, 2023 14:40
- Add SwingUtils with methods for leveraging the FPAPI
- Modify DefaultTokenPainter and VisibleWhitespaceTokenPainter to call SwingUtils
- set tabsize 4 in DemoRootPane (to match text sample)
- fix bug in SwingUtils.charWidth(...)
- modify SyntaxView to use floats for calculating tab stops:
  - SyntaxView.tabSize is now float
  - SyntaxView.calculateLongestLine() now calls SwingUtils.charWidth()
  - SyntaxView.nextTabStop() adapted for float tabSize
…hts and positions.

Modify concerned classes and methods to use Rectangle2D and float variables instead of Rectangle and integers:
- DefaultTokenPainter.paintBackground()
- RSyntaxUtilities.getLineWidthUpTo()
- SyntaxView: tabBase, clipStart, clipEnd, lineToRect(), damageLineRange(), modelToView(), paint()
- Token.listOffsetToView()
- TokenImpl.getWidthUpTo() now calls SwingUtils.charsWidth()
- TokenImpl.listOffsetToView()
- WrappedSyntaxView.modelToView()
…rily to avoid double lines on thick vertical line style

NOTE: ConfigurableCaret.damage() still runs on integers as a result of superclass implementation. No negative effects have been observed.
…() to use FPAPI

Refactor: move code from ConfigurableCaret.paint() to SwingUtils.drawLine()
…corresponding elements for Java 9 or later

Rectangles and bounds:
- add SwingUtils.getBounds() to wrap calls to modelToView2D(pos).getBounds() in a null-safe way
- replace calls to JTextComponent.modelToView(int pos) with calls to SwingUtils.getBounds(JTextComponent c, int pos)
- replace calls to JTextComponent.viewToModel(Point p) with calls to JTextComponent.viewToModel2D(Point2D p)

Events:
- replace calls to InputEvent.getModifiers() with calls to MouseEvent.getModifiersEx()
- replace calls to Toolkit.getMenuShortcutKeyMask() Toolkit.getMenuShortcutKeyMaskEx()
- replace references to Event.META_MASK with InputEvent.META_DOWN_MASK
- replace references to Event.CTRL_MASK with InputEvent.CTRL_DOWN_MASK
- replace references to MouseEvent.BUTTON1_MASK with MouseEvent.BUTTON1_DOWN_MASK

Not modified:
- SyntaxScheme calls deprecated XMLReaderFactory.createXMLReader() which should be replaced with SaxParserFactory
- Add SwingUtils with methods for leveraging the FPAPI
- Modify DefaultTokenPainter and VisibleWhitespaceTokenPainter to call SwingUtils
- set tabsize 4 in DemoRootPane (to match text sample)
- fix bug in SwingUtils.charWidth(...)
- modify SyntaxView to use floats for calculating tab stops:
  - SyntaxView.tabSize is now float
  - SyntaxView.calculateLongestLine() now calls SwingUtils.charWidth()
  - SyntaxView.nextTabStop() adapted for float tabSize
p2rsoftware and others added 23 commits December 4, 2024 09:11
…corresponding elements for Java 9 or later

Rectangles and bounds:
- add SwingUtils.getBounds() to wrap calls to modelToView2D(pos).getBounds() in a null-safe way
- replace calls to JTextComponent.modelToView(int pos) with calls to SwingUtils.getBounds(JTextComponent c, int pos)
- replace calls to JTextComponent.viewToModel(Point p) with calls to JTextComponent.viewToModel2D(Point2D p)

Events:
- replace calls to InputEvent.getModifiers() with calls to MouseEvent.getModifiersEx()
- replace calls to Toolkit.getMenuShortcutKeyMask() Toolkit.getMenuShortcutKeyMaskEx()
- replace references to Event.META_MASK with InputEvent.META_DOWN_MASK
- replace references to Event.CTRL_MASK with InputEvent.CTRL_DOWN_MASK
- replace references to MouseEvent.BUTTON1_MASK with MouseEvent.BUTTON1_DOWN_MASK

Not modified:
- SyntaxScheme calls deprecated XMLReaderFactory.createXMLReader() which should be replaced with SaxParserFactory
…hts and positions.

Modify concerned classes and methods to use Rectangle2D and float variables instead of Rectangle and integers:
- DefaultTokenPainter.paintBackground()
- RSyntaxUtilities.getLineWidthUpTo()
- SyntaxView: tabBase, clipStart, clipEnd, lineToRect(), damageLineRange(), modelToView(), paint()
- Token.listOffsetToView()
- TokenImpl.getWidthUpTo() now calls SwingUtils.charsWidth()
- TokenImpl.listOffsetToView()
- WrappedSyntaxView.modelToView()
…rily to avoid double lines on thick vertical line style

NOTE: ConfigurableCaret.damage() still runs on integers as a result of superclass implementation. No negative effects have been observed.
…dows' into issue-457-fractional-scaling-Windows

# Conflicts:
#	RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/ParserManager.java
#	RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/VisibleWhitespaceTokenPainter.java
#	RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/WrappedSyntaxView.java
#	RSyntaxTextArea/src/main/java/org/fife/ui/rtextarea/ConfigurableCaret.java
#	RSyntaxTextArea/src/main/java/org/fife/util/SwingUtils.java
#	RSyntaxTextAreaDemo/src/main/java/org/fife/ui/rsyntaxtextarea/demo/DemoRootPane.java
#	RSyntaxTextAreaDemo/src/main/resources/org/fife/ui/rsyntaxtextarea/demo/TextAlignmentExample.txt
@ptorngren
Copy link
Author

ptorngren commented Dec 4, 2024 via email

@bobbylight bobbylight changed the base branch from master to java-11 December 8, 2024 20:08
Copy link

codecov bot commented Dec 8, 2024

Codecov Report

Attention: Patch coverage is 80.61594% with 214 lines in your changes missing coverage. Please review.

Project coverage is 80.30%. Comparing base (30a8237) to head (b08857c).
Report is 116 commits behind head on java-11.

Files with missing lines Patch % Lines
.../fife/ui/rsyntaxtextarea/modes/RustTokenMaker.java 89.24% 32 Missing and 5 partials ⚠️
.../org/fife/ui/rsyntaxtextarea/RSyntaxUtilities.java 14.28% 14 Missing and 4 partials ⚠️
...org/fife/ui/rsyntaxtextarea/modes/DTokenMaker.java 68.00% 16 Missing ⚠️
...g/fife/ui/rsyntaxtextarea/modes/XMLTokenMaker.java 60.60% 13 Missing ⚠️
...java/org/fife/ui/rtextarea/RTextAreaEditorKit.java 40.90% 4 Missing and 9 partials ⚠️
...n/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java 84.28% 9 Missing and 2 partials ⚠️
...a/org/fife/ui/rsyntaxtextarea/RSyntaxTextArea.java 62.96% 10 Missing ⚠️
.../fife/ui/rsyntaxtextarea/modes/PerlTokenMaker.java 74.28% 9 Missing ⚠️
.../java/org/fife/ui/rtextarea/ConfigurableCaret.java 77.41% 4 Missing and 3 partials ⚠️
.../src/main/java/org/fife/ui/rtextarea/FontUtil.java 81.08% 1 Missing and 6 partials ⚠️
... and 28 more
Additional details and impacted files
@@              Coverage Diff              @@
##             java-11     #524      +/-   ##
=============================================
+ Coverage      73.35%   80.30%   +6.95%     
- Complexity      6594     7800    +1206     
=============================================
  Files            175      179       +4     
  Lines          29855    30297     +442     
  Branches        3878     3918      +40     
=============================================
+ Hits           21899    24329    +2430     
+ Misses          6130     4297    -1833     
+ Partials        1826     1671     -155     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@bobbylight
Copy link
Owner

Thanks for the PR!

@bobbylight bobbylight merged commit 9f7a61c into bobbylight:java-11 Dec 8, 2024
7 checks passed
@bobbylight
Copy link
Owner

BTW, this is still on the java-11 branch. I'ma do a bit more tidying up, and test on Windows (only have access to Windows 10 but can do some basic testing with Java 11, 17 and 21).

Folks interested in trying this out can use the 4.0.0-SNAPSHOT from Sonatype:

repositories {
  mavenCentral()
  maven {
    url 'https://oss.sonatype.org/content/repositories/snapshots'
  }
}

Note that 3.5.3 was just relesed as the latest version supporting Java 8, and as needed I'll release a 3.5.4, etc., and continue to rebase the Java 11/4.0.0 stuff on top of it, until it's ready to go.

@bobbylight bobbylight added this to the 4.0.0 milestone Dec 8, 2024
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

Successfully merging this pull request may close these issues.

3 participants