Browse Source
* commit 'de14edf625f7a14e0437fa427478b19680a625e5': REPORT-70562 帮助文档 url更新 REPORT-70562 导出字体字号问题-添加配置 REPORT-72570 富文本导出问题bugfix/10.0
superman
2 years ago
8 changed files with 210 additions and 7 deletions
@ -0,0 +1,42 @@ |
|||||||
|
package com.fr.design.form.util; |
||||||
|
|
||||||
|
import com.fr.base.Style; |
||||||
|
import com.fr.general.FRFont; |
||||||
|
import com.fr.log.FineLoggerFactory; |
||||||
|
import java.util.regex.Matcher; |
||||||
|
import java.util.regex.Pattern; |
||||||
|
|
||||||
|
/** |
||||||
|
* 富文本导出工具栏 |
||||||
|
* |
||||||
|
* @author hades |
||||||
|
* @version 11.0 |
||||||
|
* Created by hades on 2022/5/19 |
||||||
|
*/ |
||||||
|
public class HtmlPaintUtils { |
||||||
|
|
||||||
|
|
||||||
|
private static final Pattern FONT_SIZE_PATTERN = Pattern.compile(Pattern.quote("font-size:") + "(.*?)" + Pattern.quote("px")); |
||||||
|
|
||||||
|
/** |
||||||
|
* 设置单元格字体为富文本中的最大字体 |
||||||
|
* |
||||||
|
* @param style |
||||||
|
*/ |
||||||
|
public static Style deriveMaxFontFromRichChar(Style style, String html) { |
||||||
|
int maxSize = style.getFRFont().getSize(); |
||||||
|
Matcher matcher = FONT_SIZE_PATTERN.matcher(html); |
||||||
|
while (matcher.find()) { |
||||||
|
String value = matcher.group(1); |
||||||
|
try { |
||||||
|
double pxSize = Double.parseDouble(value); |
||||||
|
int ptSize = FontTransformUtil.roundUp(FontTransformUtil.px2pt(pxSize)); |
||||||
|
maxSize = Math.max(maxSize, ptSize); |
||||||
|
} catch (Throwable e) { |
||||||
|
FineLoggerFactory.getLogger().debug(e.getMessage(), e); |
||||||
|
} |
||||||
|
} |
||||||
|
FRFont cellFont = style.getFRFont(); |
||||||
|
return style.deriveFRFont(cellFont.applySize(maxSize)); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,49 @@ |
|||||||
|
package com.fr.design.form.util; |
||||||
|
|
||||||
|
import com.fr.base.Style; |
||||||
|
import junit.framework.TestCase; |
||||||
|
import org.junit.Assert; |
||||||
|
|
||||||
|
|
||||||
|
/** |
||||||
|
* @author hades |
||||||
|
* @version 11.0 |
||||||
|
* Created by hades on 2022/5/25 |
||||||
|
*/ |
||||||
|
public class HtmlPaintUtilsTest extends TestCase { |
||||||
|
|
||||||
|
public void testDeriveMaxFontFromRichChar() { |
||||||
|
// 富文本字体size更大
|
||||||
|
String testHtml0 = "<span style=\"font-size:21px;font-family:'宋体';\">这是一条测试数据</span>"; |
||||||
|
Style style0 = Style.DEFAULT_STYLE; |
||||||
|
Assert.assertEquals(16, HtmlPaintUtils.deriveMaxFontFromRichChar(style0, testHtml0).getFRFont().getSize()); |
||||||
|
|
||||||
|
// 单元格字体size更大
|
||||||
|
String testHtml1 = "<span style=\"font-size:7px;font-family:'宋体';\">这是一条测试数据</span>"; |
||||||
|
Style style1 = Style.DEFAULT_STYLE; |
||||||
|
int oldFontSize = style1.getFRFont().getSize(); |
||||||
|
Assert.assertEquals(oldFontSize, HtmlPaintUtils.deriveMaxFontFromRichChar(style1, testHtml1).getFRFont().getSize()); |
||||||
|
|
||||||
|
// 富文本字体size更大 不同文本 有不同size
|
||||||
|
String testHtml2 = "<span style=\"font-size:21px;font-family:'宋体';\">这是一条测</span><span style=\"font-size:31px;font-family:'宋体';\">试数</span><span style=\"font-size:21px;font-family:'宋体';\">据</span>"; |
||||||
|
Style style2 = Style.DEFAULT_STYLE; |
||||||
|
Assert.assertEquals(23, HtmlPaintUtils.deriveMaxFontFromRichChar(style2, testHtml2).getFRFont().getSize()); |
||||||
|
|
||||||
|
|
||||||
|
// 异常场景1
|
||||||
|
String testHtml3 = "xxxx奇怪的格式xxxx"; |
||||||
|
Style style3 = Style.DEFAULT_STYLE; |
||||||
|
oldFontSize = style1.getFRFont().getSize(); |
||||||
|
Assert.assertEquals(oldFontSize, HtmlPaintUtils.deriveMaxFontFromRichChar(style3, testHtml3).getFRFont().getSize()); |
||||||
|
|
||||||
|
// 异常场景2
|
||||||
|
String testHtml4 = "<span style=\"font-size:xxxxpx;font-family:'宋体';\">这是一条测试数据</span>"; |
||||||
|
Style style4 = Style.DEFAULT_STYLE; |
||||||
|
oldFontSize = style1.getFRFont().getSize(); |
||||||
|
Assert.assertEquals(oldFontSize, HtmlPaintUtils.deriveMaxFontFromRichChar(style4, testHtml4).getFRFont().getSize()); |
||||||
|
|
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
@ -0,0 +1,81 @@ |
|||||||
|
package com.fr.design.report; |
||||||
|
|
||||||
|
import com.fr.base.CustomConfig; |
||||||
|
import com.fr.config.Configuration; |
||||||
|
import com.fr.design.constants.UIConstants; |
||||||
|
import com.fr.design.dialog.BasicPane; |
||||||
|
import com.fr.design.gui.icheckbox.UICheckBox; |
||||||
|
import com.fr.design.gui.ilable.ActionLabel; |
||||||
|
import com.fr.design.gui.ilable.UILabel; |
||||||
|
import com.fr.design.i18n.Toolkit; |
||||||
|
import com.fr.design.layout.FRGUIPaneFactory; |
||||||
|
import com.fr.design.utils.BrowseUtils; |
||||||
|
import com.fr.general.CloudCenter; |
||||||
|
import com.fr.transaction.Configurations; |
||||||
|
import com.fr.transaction.WorkerFacade; |
||||||
|
import java.awt.BorderLayout; |
||||||
|
import java.awt.Color; |
||||||
|
import java.awt.event.ActionEvent; |
||||||
|
import java.awt.event.ActionListener; |
||||||
|
import javax.swing.BorderFactory; |
||||||
|
import javax.swing.JPanel; |
||||||
|
|
||||||
|
/** |
||||||
|
* @author hades |
||||||
|
* @version 11.0 |
||||||
|
* Created by hades on 2022/5/26 |
||||||
|
*/ |
||||||
|
public class ExportUniversalPane extends BasicPane { |
||||||
|
|
||||||
|
private static final String HELP_URL = CloudCenter.getInstance().acquireUrlByKind("help.alt_font.zh_CN", "https://help.fanruan.com/finereport/doc-view-4707.html"); |
||||||
|
|
||||||
|
private UICheckBox specialCharacterExport; |
||||||
|
|
||||||
|
public ExportUniversalPane() { |
||||||
|
this.setLayout(FRGUIPaneFactory.createBorderLayout()); |
||||||
|
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
||||||
|
JPanel outerNorthPane =FRGUIPaneFactory.createTitledBorderPane(Toolkit.i18nText("Fine-Design_Report_Universal_Export_Config")); |
||||||
|
JPanel northPane = FRGUIPaneFactory.createY_AXISBoxInnerContainer_M_Pane(); |
||||||
|
JPanel specialCharacterExportPane =FRGUIPaneFactory.createNormalFlowInnerContainer_M_Pane(); |
||||||
|
specialCharacterExport = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Universal_Export_Special_Character")); |
||||||
|
specialCharacterExport.setSelected(true); |
||||||
|
specialCharacterExportPane.add(specialCharacterExport); |
||||||
|
northPane.add(specialCharacterExportPane); |
||||||
|
JPanel labelPane = new JPanel(new BorderLayout()); |
||||||
|
labelPane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); |
||||||
|
UILabel centerLabel = new UILabel(Toolkit.i18nText("Fine-Design_Report_Universal_Export_Special_Character_Tip")); |
||||||
|
centerLabel.setForeground(Color.GRAY); |
||||||
|
ActionLabel rightLabel = new ActionLabel(Toolkit.i18nText("Fine-Design_Report_Universal_Export_More_Alternative_Fonts"), UIConstants.FLESH_BLUE); |
||||||
|
rightLabel.addActionListener(new ActionListener() { |
||||||
|
@Override |
||||||
|
public void actionPerformed(ActionEvent e) { |
||||||
|
BrowseUtils.browser(HELP_URL); |
||||||
|
} |
||||||
|
}); |
||||||
|
labelPane.add(centerLabel, BorderLayout.CENTER); |
||||||
|
labelPane.add(rightLabel, BorderLayout.EAST); |
||||||
|
northPane.add(labelPane); |
||||||
|
outerNorthPane.add(northPane); |
||||||
|
this.add(outerNorthPane); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
protected String title4PopupWindow() { |
||||||
|
return "ExportUniversalPane"; |
||||||
|
} |
||||||
|
|
||||||
|
public void populate() { |
||||||
|
this.specialCharacterExport.setSelected(CustomConfig.getInstance().isOptimizedSpecialCharacterExport()); |
||||||
|
} |
||||||
|
|
||||||
|
public void update() { |
||||||
|
Configurations.modify(new WorkerFacade(CustomConfig.class) { |
||||||
|
@Override |
||||||
|
public void run() { |
||||||
|
CustomConfig.getInstance().setOptimizedSpecialCharacterExport(specialCharacterExport.isSelected()); |
||||||
|
} |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
|
||||||
|
} |
Loading…
Reference in new issue