Browse Source

REPORT-130379 fix:NewUI富文本编辑器字体缩放适配

fbp/merge
Levy.Xie-解安森 3 months ago
parent
commit
26955702ee
  1. 20
      designer-realize/src/main/java/com/fr/design/report/RichTextEditingPane.java

20
designer-realize/src/main/java/com/fr/design/report/RichTextEditingPane.java

@ -14,12 +14,14 @@ import com.fr.log.FineLoggerFactory;
import com.fr.report.cell.cellattr.core.RichText; import com.fr.report.cell.cellattr.core.RichText;
import com.fr.report.cell.cellattr.core.RichTextConverter; import com.fr.report.cell.cellattr.core.RichTextConverter;
import java.awt.Font;
import java.awt.event.FocusAdapter; import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent; import java.awt.event.FocusEvent;
import java.awt.event.FocusListener; import java.awt.event.FocusListener;
import javax.swing.text.AttributeSet; import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultHighlighter; import javax.swing.text.DefaultHighlighter;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element; import javax.swing.text.Element;
import javax.swing.text.Highlighter; import javax.swing.text.Highlighter;
import javax.swing.text.StyledDocument; import javax.swing.text.StyledDocument;
@ -27,6 +29,8 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import static com.formdev.flatlaf.util.UIScale.scale;
/** /**
* 富文本的编辑区域 * 富文本的编辑区域
* *
@ -50,6 +54,22 @@ public class RichTextEditingPane extends UITextPane{
public RichTextEditingPane() { public RichTextEditingPane() {
this.addMouseListener(doubleClickFormulaListener); this.addMouseListener(doubleClickFormulaListener);
this.addFocusListener(focusListener); this.addFocusListener(focusListener);
setDocument(new ScaledStyledDocument());
}
/**
* 支持字体缩放的Document对象
*/
public static class ScaledStyledDocument extends DefaultStyledDocument {
@Override
public Font getFont(AttributeSet a) {
Font font = super.getFont(a);
if (font != null) {
return font.deriveFont(font.getStyle(), scale(font.getSize()));
}
return null;
}
} }
/** /**

Loading…
Cancel
Save