Browse Source

Pull request #1666: REPORT-30739 && REPORT-31475 【10.0.6开接口】字体统一改成像素的可行性研究,及开接口

Merge in DESIGN/design from ~KERRY/design_10.0:release/10.0 to release/10.0

* commit '8c6d591ffb458fcdae72cc201340fa7c4204c55a':
  REPORT-31475 问题修复
  REPORT-30739【10.0.6开接口】字体统一改成像素的可行性研究,及开接口
feature/big-screen
kerry 5 years ago
parent
commit
008de4f0a0
  1. 7
      designer-base/src/main/java/com/fr/design/fun/FormAdaptiveConfigUIProcessor.java
  2. 10
      designer-form/src/main/java/com/fr/design/designer/creator/XButton.java
  3. 5
      designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java
  4. 46
      designer-form/src/main/java/com/fr/design/form/util/FontTransformUtil.java
  5. 20
      designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentOperate.java
  6. 3
      designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java
  7. 68
      designer-form/src/test/java/com/fr/design/form/util/FontTransformUtilTest.java
  8. 22
      designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentCreateOperateTest.java
  9. 4
      designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java
  10. 20
      designer-realize/src/main/java/com/fr/design/cell/editor/RichTextToolBar.java

7
designer-base/src/main/java/com/fr/design/fun/FormAdaptiveConfigUIProcessor.java

@ -32,5 +32,12 @@ public interface FormAdaptiveConfigUIProcessor extends Immutable {
*/
BufferedImage paintFormElementCaseImage(Dimension size, JComponent elementCasePane);
/**
* 获取新自适应下字体显示的dpi
* @return dpi
*/
int fontResolution();
}

10
designer-form/src/main/java/com/fr/design/designer/creator/XButton.java

@ -3,8 +3,8 @@
*/
package com.fr.design.designer.creator;
import com.fr.base.ScreenResolution;
import com.fr.base.background.GradientBackground;
import com.fr.design.form.util.FontTransformUtil;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.widget.editors.ButtonTypeEditor;
@ -148,7 +148,7 @@ public class XButton extends XWidgetCreator {
FreeButton button = (FreeButton) data;
if (button.getFont() != null) {
contentLabel.setFont(button.getFont().applyResolutionNP(
ScreenResolution.getScreenResolution()));
FontTransformUtil.getDesignerFontResolution()));
contentLabel.setForeground(button.getFont().getForeground());
}
}
@ -240,7 +240,7 @@ public class XButton extends XWidgetCreator {
editor.add(l,BorderLayout.CENTER);
if (button.getFont() != null) {
contentLabel.setFont(button.getFont().applyResolutionNP(
ScreenResolution.getScreenResolution()));
FontTransformUtil.getDesignerFontResolution()));
contentLabel.setForeground(button.getFont().getForeground());
}
l.setBounds(0, 0, button.getButtonWidth() == 0 ? this.getWidth() : button.getButtonWidth(), button
@ -257,7 +257,7 @@ public class XButton extends XWidgetCreator {
FreeButton button = (FreeButton) data;
l.setText(button.getText());
if (button.isCustomStyle() && button.getFont() != null) {
l.setFont(button.getFont().applyResolutionNP(ScreenResolution.getScreenResolution()));
l.setFont(button.getFont().applyResolutionNP(FontTransformUtil.getDesignerFontResolution()));
l.setForeground(button.getFont().getForeground());
}
@ -303,7 +303,7 @@ public class XButton extends XWidgetCreator {
checkButonType();
if (button.getFont() != null) {
contentLabel.setFont(button.getFont().applyResolutionNP(
ScreenResolution.getScreenResolution()));
FontTransformUtil.getDesignerFontResolution()));
contentLabel.setForeground(button.getFont().getForeground());
}

5
designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java

@ -4,9 +4,9 @@
package com.fr.design.designer.creator;
import com.fr.base.BaseUtils;
import com.fr.base.ScreenResolution;
import com.fr.base.Style;
import com.fr.design.border.UIRoundedBorder;
import com.fr.design.form.util.FontTransformUtil;
import com.fr.design.form.util.XCreatorConstants;
import com.fr.design.gui.ilable.UILabel;
import com.fr.design.mainframe.widget.editors.FontEditor;
@ -98,7 +98,8 @@ public class XLabel extends XWidgetCreator {
.toString(), Style.getInstance(label.getFont()).deriveHorizontalAlignment(label.getTextalign())
.deriveVerticalAlignment(label.isVerticalCenter() ? SwingConstants.CENTER : SwingConstants.TOP)
.deriveTextStyle(label.isWrap() ? Style.TEXTSTYLE_WRAPTEXT : Style.TEXTSTYLE_SINGLELINE),
ScreenResolution.getScreenResolution());
FontTransformUtil.getDesignerFontResolution());
}
}

46
designer-form/src/main/java/com/fr/design/form/util/FontTransformUtil.java

@ -0,0 +1,46 @@
package com.fr.design.form.util;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.FormAdaptiveConfigUIProcessor;
import com.fr.stable.Constants;
import com.fr.stable.unit.PT;
/**
* Created by kerry on 2020-04-16
*/
public class FontTransformUtil {
/**
* 获取设计器字体显示dpi
* @return dpi
*/
public static int getDesignerFontResolution() {
int dpi = Constants.FR_PAINT_RESOLUTION;
FormAdaptiveConfigUIProcessor adaptiveConfigUI = ExtraDesignClassManager.getInstance().getSingle(FormAdaptiveConfigUIProcessor.MARK_STRING);
if (adaptiveConfigUI != null) {
dpi = adaptiveConfigUI.fontResolution();
}
return dpi;
}
/**
* pt值转px
* @param value pt值
* @return px值
*/
public static double pt2px(double value) {
return PT.pt2pix(value, getDesignerFontResolution());
}
/**
* px值转pt
* @param value px值
* @return pt值
*/
public static double px2pt(double value) {
return value * (double) Constants.DEFAULT_FONT_PAINT_RESOLUTION / (double) getDesignerFontResolution();
}
}

20
designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentOperate.java

@ -7,7 +7,10 @@ import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WCardLayout;
import com.fr.form.ui.container.WScaleLayout;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.widget.CRBoundsWidget;
import com.fr.general.ComparatorUtils;
import com.fr.json.JSONObject;
@ -24,13 +27,20 @@ public abstract class ComponentOperate implements TemplateOperate {
private Widget widget;
public ComponentOperate(Widget widget) {
if (widget.acceptType(WTitleLayout.class)) {
this.widget = ((WTitleLayout) widget).getBodyBoundsWidget().getWidget();
}else {
this.widget = widget;
}
Widget innerWidget = widget;
if (innerWidget.acceptType(WScaleLayout.class)) {
Widget crBoundsWidget = ((WScaleLayout) innerWidget).getBoundsWidget();
innerWidget = ((CRBoundsWidget) crBoundsWidget).getWidget();
} else if (innerWidget.acceptType(WTitleLayout.class)) {
CRBoundsWidget crBoundsWidget = ((WTitleLayout) innerWidget).getBodyBoundsWidget();
innerWidget = crBoundsWidget.getWidget();
} else if (innerWidget.acceptType(WCardMainBorderLayout.class)){
innerWidget = ((WCardMainBorderLayout) widget).getCardPart();
}
this.widget = innerWidget;
}
@Override
public JSONObject toJSONObject() {
JSONObject jo = new JSONObject();

3
designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java

@ -226,6 +226,9 @@ public class JFormProcessInfo extends TemplateProcessInfo<Form> {
private void addComponentRemoveInfo(JSONObject jsonObject) {
String componentID = jsonObject.getString("componentID");
if (componentID == null){
return;
}
JSONObject info = componentProcessInfoMap.get(componentID);
if (info == null) {
info = jsonObject;

68
designer-form/src/test/java/com/fr/design/form/util/FontTransformUtilTest.java

@ -0,0 +1,68 @@
package com.fr.design.form.util;
import com.fr.design.ExtraDesignClassManager;
import com.fr.design.fun.FormAdaptiveConfigUIProcessor;
import com.fr.stable.Constants;
import org.easymock.EasyMock;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.api.easymock.PowerMock;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
/**
* Created by kerry on 2020-05-14
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest(ExtraDesignClassManager.class)
public class FontTransformUtilTest {
@Test
public void testGetDesignerFontResolution() {
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION);
Assert.assertEquals(Constants.DEFAULT_FONT_PAINT_RESOLUTION, FontTransformUtil.getDesignerFontResolution());
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION);
Assert.assertEquals(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION, FontTransformUtil.getDesignerFontResolution());
}
@Test
public void testPt2px() {
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION);
Assert.assertEquals(12, (int) FontTransformUtil.pt2px(12));
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION);
Assert.assertEquals(16, (int) FontTransformUtil.pt2px(12));
}
@Test
public void testPx2pt() {
mockEnvironment(Constants.DEFAULT_FONT_PAINT_RESOLUTION);
Assert.assertEquals(12, (int) FontTransformUtil.px2pt(12));
mockEnvironment(Constants.DEFAULT_WEBWRITE_AND_SCREEN_RESOLUTION);
Assert.assertEquals(9, (int) FontTransformUtil.px2pt(12));
}
private void mockEnvironment(int dpi) {
ExtraDesignClassManager mockDesignManager = EasyMock.mock(ExtraDesignClassManager.class);
EasyMock.expect(mockDesignManager.getSingle(FormAdaptiveConfigUIProcessor.MARK_STRING))
.andReturn(mockProcessor(dpi)).anyTimes();
EasyMock.replay(mockDesignManager);
PowerMock.mockStatic(ExtraDesignClassManager.class);
EasyMock.expect(ExtraDesignClassManager.getInstance()).andReturn(mockDesignManager).once();
PowerMock.replayAll(ExtraDesignClassManager.class);
}
private FormAdaptiveConfigUIProcessor mockProcessor(int dpi) {
FormAdaptiveConfigUIProcessor processor = EasyMock.mock(FormAdaptiveConfigUIProcessor.class);
EasyMock.expect(processor.fontResolution()).andReturn(dpi).once();
EasyMock.replay(processor);
return processor;
}
}

22
designer-form/src/test/java/com/fr/design/mainframe/template/info/ComponentCreateOperateTest.java

@ -5,11 +5,15 @@ import com.fr.form.ui.CardSwitchButton;
import com.fr.form.ui.ChartEditor;
import com.fr.form.ui.ElementCaseEditor;
import com.fr.form.ui.FreeButton;
import com.fr.form.ui.TextEditor;
import com.fr.form.ui.Widget;
import com.fr.form.ui.container.WAbsoluteBodyLayout;
import com.fr.form.ui.container.WAbsoluteLayout;
import com.fr.form.ui.container.WCardLayout;
import com.fr.form.ui.container.WScaleLayout;
import com.fr.form.ui.container.WTitleLayout;
import com.fr.form.ui.container.cardlayout.WCardMainBorderLayout;
import com.fr.form.ui.widget.CRBoundsWidget;
import com.fr.general.ComparatorUtils;
import com.fr.json.JSONObject;
import org.junit.Assert;
@ -23,7 +27,7 @@ import java.awt.Rectangle;
public class ComponentCreateOperateTest {
@Test
public void testConstructor(){
public void testConstructor() {
ElementCaseEditor caseEditor = new ElementCaseEditor();
caseEditor.setWidgetName("report0");
caseEditor.setWidgetID("xxxx0");
@ -32,6 +36,22 @@ public class ComponentCreateOperateTest {
ComponentOperate componentOperate0 = new ComponentCreateOperate(caseEditor);
ComponentOperate componentOperate1 = new ComponentCreateOperate(wTitleLayout);
ComparatorUtils.equals(componentOperate0.toJSONObject(), componentOperate1.toJSONObject());
WScaleLayout scaleLayout = new WScaleLayout();
TextEditor textEditor = new TextEditor();
scaleLayout.addWidget(new CRBoundsWidget(textEditor, new Rectangle()));
ComponentOperate componentOperate3 = new ComponentCreateOperate(scaleLayout);
ComponentOperate componentOperate4 = new ComponentCreateOperate(textEditor);
ComparatorUtils.equals(componentOperate3.toJSONObject(), componentOperate4.toJSONObject());
WCardMainBorderLayout wCardMainBorderLayout = new WCardMainBorderLayout();
WCardLayout wCardLayout = new WCardLayout();
wCardMainBorderLayout.addCenter(wCardLayout);
ComponentOperate componentOperate5 = new ComponentCreateOperate(wCardMainBorderLayout);
ComponentOperate componentOperate6 = new ComponentCreateOperate(wCardLayout);
ComparatorUtils.equals(componentOperate5.toJSONObject(), componentOperate6.toJSONObject());
}
@Test

4
designer-form/src/test/java/com/fr/design/mainframe/template/info/JFormProcessInfoTest.java

@ -143,6 +143,10 @@ public class JFormProcessInfoTest {
JSONArray ja = jFormProcessInfo.getComponentsInfo();
Assert.assertEquals(2, ja.size());
Reflect.on(jFormProcessInfo).call("addComponentCreateInfo", new ComponentCreateOperate(button1).toJSONObject());
FreeButton button3 = new FreeButton();
Reflect.on(jFormProcessInfo).call("addComponentRemoveInfo", new ComponentDeleteOperate(button3).toJSONObject());
Assert.assertEquals(1, jFormProcessInfo.getComponentsInfo().size());
ja = jFormProcessInfo.getComponentsInfo();
Assert.assertEquals(0, ja.size());

20
designer-realize/src/main/java/com/fr/design/cell/editor/RichTextToolBar.java

@ -8,6 +8,7 @@ import com.fr.base.BaseUtils;
import com.fr.base.Utils;
import com.fr.design.dialog.BasicPane;
import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.form.util.FontTransformUtil;
import com.fr.design.formula.FormulaFactory;
import com.fr.design.formula.UIFormula;
import com.fr.design.gui.ibutton.UIButton;
@ -21,7 +22,6 @@ import com.fr.design.style.color.UIToolbarColorButton;
import com.fr.general.FRFont;
import com.fr.log.FineLoggerFactory;
import com.fr.report.cell.cellattr.core.RichTextConverter;
import com.fr.stable.Constants;
import com.fr.stable.StableUtils;
import com.fr.stable.StringUtils;
@ -308,7 +308,7 @@ public class RichTextToolBar extends BasicPane{
@Override
public void itemStateChanged(ItemEvent e) {
int fontSize = (Integer) RichTextToolBar.this.fontSizeComboBox.getSelectedItem();
fontSize = scaleUp(fontSize);
fontSize= scaleUp(fontSize);
// 调用setCharacterAttributes函数设置文本区选择文本的字体
MutableAttributeSet attr = new SimpleAttributeSet();
StyleConstants.setFontSize(attr, fontSize);
@ -493,21 +493,13 @@ public class RichTextToolBar extends BasicPane{
}
//pt转为px =*4/3
private int scaleUp(int fontSize){
return scale(fontSize, true);
private int scaleUp(int fontSize) {
return (int) FontTransformUtil.pt2px(fontSize);
}
//px转pt = *3/4
private int scaleDown(int fontSize){
return scale(fontSize, false);
}
private int scale(int fontSize, boolean isUp){
double dpi96 = Constants.FR_PAINT_RESOLUTION;
double dpi72 = Constants.DEFAULT_FONT_PAINT_RESOLUTION;
double scale = isUp ? (dpi96 / dpi72) : (dpi72 / dpi96);
return roundUp(fontSize * scale);
private int scaleDown(int fontSize) {
return (int) FontTransformUtil.px2pt(fontSize);
}
private DocumentListener inputListener = new DocumentListener() {

Loading…
Cancel
Save