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

Open
wants to merge 52 commits into
base: master
Choose a base branch
from

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 22 commits October 27, 2023 09:27
…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
…dows' into issue-457-fractional-scaling-Windows

# Conflicts:
#	RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/DefaultTokenPainter.java
#	RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/SyntaxView.java
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.

None yet

2 participants