mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-166581 Incorrect font rendering in vcs change preview (new hidpi)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -214,7 +214,8 @@ public abstract class LineStatusMarkerPopup {
|
||||
}
|
||||
|
||||
EditorFragmentComponent fragmentComponent =
|
||||
EditorFragmentComponent.createEditorFragmentComponent(uEditor, myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);
|
||||
EditorFragmentComponent.createEditorFragmentComponent(myEditor.getContentComponent(), uEditor,
|
||||
myRange.getVcsLine1(), myRange.getVcsLine2(), false, false);
|
||||
|
||||
EditorFactory.getInstance().releaseEditor(uEditor);
|
||||
|
||||
|
||||
+32
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -47,17 +47,17 @@ public class EditorFragmentComponent extends JPanel {
|
||||
private static final int LINE_BORDER_THICKNESS = 1;
|
||||
private static final int EMPTY_BORDER_THICKNESS = 2;
|
||||
|
||||
private EditorFragmentComponent(EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
|
||||
private EditorFragmentComponent(Component component, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
|
||||
editor.setPurePaintingMode(true);
|
||||
try {
|
||||
doInit(editor, startLine, endLine, showFolding, showGutter);
|
||||
doInit(component, editor, startLine, endLine, showFolding, showGutter);
|
||||
}
|
||||
finally {
|
||||
editor.setPurePaintingMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void doInit(EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
|
||||
private void doInit(Component anchorComponent, EditorEx editor, int startLine, int endLine, boolean showFolding, boolean showGutter) {
|
||||
Document doc = editor.getDocument();
|
||||
final int endOffset = endLine < doc.getLineCount() ? doc.getLineEndOffset(endLine) : doc.getTextLength();
|
||||
boolean newRendering = editor instanceof EditorImpl;
|
||||
@@ -85,7 +85,8 @@ public class EditorFragmentComponent extends JPanel {
|
||||
editor.getScrollingModel().scrollHorizontally(0);
|
||||
}
|
||||
|
||||
final BufferedImage textImage = UIUtil.createImage(editor.getComponent(), textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
final BufferedImage textImage = UIUtil.createImage(anchorComponent == null ? editor.getContentComponent() : anchorComponent,
|
||||
textImageWidth, textImageHeight, BufferedImage.TYPE_INT_RGB);
|
||||
Graphics textGraphics = textImage.getGraphics();
|
||||
EditorUIUtil.setupAntialiasing(textGraphics);
|
||||
|
||||
@@ -224,23 +225,47 @@ public class EditorFragmentComponent extends JPanel {
|
||||
return hint;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param component Should be provided if editor is not currently displayable.
|
||||
* Makes for correct rendering on multi-monitor configurations.
|
||||
*/
|
||||
public static EditorFragmentComponent createEditorFragmentComponent(Component component, Editor editor,
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean showFolding, boolean showGutter) {
|
||||
return createEditorFragmentComponent(component, editor, startLine, endLine, showFolding, showGutter, true);
|
||||
}
|
||||
|
||||
public static EditorFragmentComponent createEditorFragmentComponent(Editor editor,
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean showFolding, boolean showGutter) {
|
||||
return createEditorFragmentComponent(editor, startLine, endLine, showFolding, showGutter, true);
|
||||
}
|
||||
|
||||
|
||||
public static EditorFragmentComponent createEditorFragmentComponent(Editor editor,
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean showFolding, boolean showGutter,
|
||||
boolean useCaretRowBackground) {
|
||||
return createEditorFragmentComponent(null, editor, startLine, endLine, showFolding, showGutter, useCaretRowBackground);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param component Should be provided if editor is not currently displayable.
|
||||
* Makes for correct rendering on multi-monitor configurations.
|
||||
*/
|
||||
public static EditorFragmentComponent createEditorFragmentComponent(Component component,
|
||||
Editor editor,
|
||||
int startLine,
|
||||
int endLine,
|
||||
boolean showFolding, boolean showGutter,
|
||||
boolean useCaretRowBackground) {
|
||||
final EditorEx editorEx = (EditorEx)editor;
|
||||
final Color old = editorEx.getBackgroundColor();
|
||||
Color backColor = getBackgroundColor(editor, useCaretRowBackground);
|
||||
editorEx.setBackgroundColor(backColor);
|
||||
EditorFragmentComponent fragmentComponent = new EditorFragmentComponent(editorEx, startLine, endLine,
|
||||
EditorFragmentComponent fragmentComponent = new EditorFragmentComponent(component, editorEx, startLine, endLine,
|
||||
showFolding, showGutter);
|
||||
fragmentComponent.setBackground(backColor);
|
||||
|
||||
|
||||
@@ -38,7 +38,6 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.HierarchyEvent;
|
||||
import java.awt.event.HierarchyListener;
|
||||
@@ -137,13 +136,13 @@ public class EditorView implements TextDrawingCallback, Disposable, Dumpable, Hi
|
||||
@Override
|
||||
public void hierarchyChanged(HierarchyEvent e) {
|
||||
if ((e.getChangeFlags() & HierarchyEvent.SHOWING_CHANGED) != 0 && e.getComponent().isShowing()) {
|
||||
checkFontRenderContext();
|
||||
checkFontRenderContext(null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visibleAreaChanged(VisibleAreaEvent e) {
|
||||
checkFontRenderContext();
|
||||
checkFontRenderContext(null);
|
||||
}
|
||||
public int yToVisualLine(int y) {
|
||||
return myMapper.yToVisualLine(y);
|
||||
@@ -263,6 +262,7 @@ public class EditorView implements TextDrawingCallback, Disposable, Dumpable, Hi
|
||||
public void paint(Graphics2D g) {
|
||||
assertIsDispatchThread();
|
||||
myEditor.getSoftWrapModel().prepareToMapping();
|
||||
checkFontRenderContext(g.getFontRenderContext());
|
||||
myPainter.paint(g);
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ public class EditorView implements TextDrawingCallback, Disposable, Dumpable, Hi
|
||||
default:
|
||||
myBidiFlags = Bidi.DIRECTION_DEFAULT_LEFT_TO_RIGHT;
|
||||
}
|
||||
setFontRenderContext();
|
||||
setFontRenderContext(null);
|
||||
myLogicalPositionCache.reset(false);
|
||||
myTextLayoutCache.resetToDocumentSize(false);
|
||||
invalidateFoldRegionLayouts();
|
||||
@@ -517,14 +517,13 @@ public class EditorView implements TextDrawingCallback, Disposable, Dumpable, Hi
|
||||
}
|
||||
}
|
||||
|
||||
private void setFontRenderContext() {
|
||||
JComponent component = myEditor.getContentComponent();
|
||||
myFontRenderContext = FontInfo.getFontRenderContext(component);
|
||||
private void setFontRenderContext(FontRenderContext context) {
|
||||
myFontRenderContext = context == null ? FontInfo.getFontRenderContext(myEditor.getContentComponent()) : context;
|
||||
}
|
||||
|
||||
private void checkFontRenderContext() {
|
||||
private void checkFontRenderContext(FontRenderContext context) {
|
||||
FontRenderContext oldContext = myFontRenderContext;
|
||||
setFontRenderContext();
|
||||
setFontRenderContext(context);
|
||||
if (!myFontRenderContext.equals(oldContext)) {
|
||||
myTextLayoutCache.resetToDocumentSize(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user