diff --git a/designer-base/src/main/java/com/fr/design/fun/FormAdaptiveConfigUIProcessor.java b/designer-base/src/main/java/com/fr/design/fun/FormAdaptiveConfigUIProcessor.java index 1f2853b91..ebe0e8c3d 100644 --- a/designer-base/src/main/java/com/fr/design/fun/FormAdaptiveConfigUIProcessor.java +++ b/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(); + } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java b/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java index e94022ebe..44996df8c 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XButton.java +++ b/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; @@ -40,13 +40,13 @@ import java.beans.IntrospectionException; * @since 6.5.3 */ public class XButton extends XWidgetCreator { - + public final static Background DEFAULTBG = new GradientBackground(new Color(247,247,247),new Color(210,210,210), GradientBackground.TOP2BOTTOM); public final static Font DEFAULTFT = new Font("Song_TypeFace",0,12); public final static Color DEFAULTFOREGROUNDCOLOR = Color.BLACK; private Background bg; private UILabel contentLabel; - + public XButton(Button widget, Dimension initSize) { this(new FreeButton(widget),initSize); } @@ -54,11 +54,11 @@ public class XButton extends XWidgetCreator { public XButton(FreeButton widget, Dimension initSize) { super(widget, initSize); } - + public XButton(FormSubmitButton widget, Dimension initSize) { super(widget, initSize); } - + public Background getContentBackground() { return bg; } @@ -74,7 +74,7 @@ public class XButton extends XWidgetCreator { public void setContentLabel(UILabel contentLabel) { this.contentLabel = contentLabel; } - + /** *根据下拉框选择返回按钮样式的默认设置或自定义设置列表 * @return 列表 @@ -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()); } } @@ -205,7 +205,7 @@ public class XButton extends XWidgetCreator { protected UILabel initContentLabel() { return new UILabel(); } - + @Override public void paintComponent(Graphics g) { super.paintComponent(g); @@ -218,15 +218,15 @@ public class XButton extends XWidgetCreator { bg.paint(g, new Rectangle2D.Double(0, 0, panelSize.getWidth(), panelSize.getHeight())); } } - + public void setButtonText(String text) { contentLabel.setText(text); } - + private void checkButonType() { UILabel l = contentLabel; FreeButton button = (FreeButton) data; - + if (!button.isCustomStyle()) { l.setBorder(BorderFactory.createLineBorder(new Color(148, 148, 148))); bg = DEFAULTBG; @@ -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 @@ -248,7 +248,7 @@ public class XButton extends XWidgetCreator { bg = button.getInitialBackground(); } } - + @Override protected void initXCreatorProperties() { super.initXCreatorProperties(); @@ -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()); } diff --git a/designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java b/designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java index 233c369c4..df2252c7a 100644 --- a/designer-form/src/main/java/com/fr/design/designer/creator/XLabel.java +++ b/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()); + } } diff --git a/designer-form/src/main/java/com/fr/design/form/util/FontTransformUtil.java b/designer-form/src/main/java/com/fr/design/form/util/FontTransformUtil.java new file mode 100644 index 000000000..769707ebe --- /dev/null +++ b/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(); + } + +} diff --git a/designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentOperate.java b/designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentOperate.java index b6fd79d27..0791e42d4 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/template/info/ComponentOperate.java +++ b/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(); diff --git a/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java b/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java index c9f7d761e..180215a24 100644 --- a/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java +++ b/designer-form/src/main/java/com/fr/design/mainframe/template/info/JFormProcessInfo.java @@ -226,6 +226,9 @@ public class JFormProcessInfo extends TemplateProcessInfo