diff --git a/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java b/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java deleted file mode 100644 index 829d320e8c..0000000000 --- a/designer-form/src/main/java/com/fr/design/fit/common/BaseUtils.java +++ /dev/null @@ -1,1266 +0,0 @@ -package com.fr.design.fit.common; - -import com.fr.base.AutoChangeLineAndDrawManager; -import com.fr.base.FRContext; -import com.fr.base.GraphHelper; -import com.fr.base.Style; -import com.fr.base.SynchronizedLiveDataModelUtils; -import com.fr.base.TableData; -import com.fr.base.regist.LicenseConfigManager; -import com.fr.config.ServerPreferenceConfig; -import com.fr.data.api.TableDataAssist; -import com.fr.design.fit.PX; -import com.fr.general.ComparatorUtils; -import com.fr.general.FArray; -import com.fr.general.FRFont; -import com.fr.general.GeneralContext; -import com.fr.general.GeneralUtils; -import com.fr.general.IOUtils; -import com.fr.general.data.DataModel; -import com.fr.general.data.TableDataException; -import com.fr.general.xml.GeneralXMLTools; -import com.fr.json.JSONArray; -import com.fr.json.JSONException; -import com.fr.json.JSONObject; -import com.fr.json.JSONUtils; -import com.fr.json.revise.EmbedJson; -import com.fr.locale.InterProviderFactory; -import com.fr.log.FineLoggerFactory; -import com.fr.plugin.injectable.PluginModule; -import com.fr.report.fun.VerticalTextProcessor; -import com.fr.report.fun.impl.DefaultVerticalTextProcessor; -import com.fr.script.Calculator; -import com.fr.stable.ColumnRow; -import com.fr.stable.Constants; -import com.fr.stable.GraphDrawHelper; -import com.fr.stable.ListSet; -import com.fr.stable.StableUtils; -import com.fr.stable.StringUtils; -import com.fr.stable.bridge.ObjectHolder; -import com.fr.stable.fun.AutoChangeLineAndDrawProcess; -import com.fr.stable.fun.FontProcessor; -import com.fr.stable.plugin.ExtraClassManagerProvider; -import com.fr.stable.project.ProjectConstants; -import com.fr.stable.script.CalculatorProvider; -import com.fr.stable.unit.FU; -import com.fr.stable.unit.UNIT; -import com.fr.workspace.WorkContext; - -import javax.swing.Icon; -import javax.swing.ImageIcon; -import javax.swing.JFrame; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Graphics2D; -import java.awt.Image; -import java.awt.Paint; -import java.awt.geom.AffineTransform; -import java.awt.geom.Dimension2D; -import java.awt.image.BufferedImage; -import java.awt.image.CropImageFilter; -import java.awt.image.FilteredImageSource; -import java.io.IOException; -import java.io.InputStream; -import java.text.NumberFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Locale; -import java.util.Map; - - -/** - * 基本的工具类 - */ -public class BaseUtils { - - private BaseUtils() { - } - - /** - * 从缓存中读取图片(如果缓存中存在的话则直接从缓存中读取,如果不存在则从磁盘读取并将读取的结果缓存起来) - * - * @param resource 图片的路径 - * @return 图片 - * @see IOUtils#readImageWithCache(String) - * @deprecated - */ - public static BufferedImage readImageWithCache(String resource) { - return IOUtils.readImageWithCache(resource); - } - - /** - * 从缓存中读取图片,如果缓存中不存在则返回null - * - * @param resource 图片路径 - * @return 图片,缓存中没有则返回null - * @see IOUtils#readCacheImage(String) - * @deprecated - */ - public static BufferedImage readCacheImage(String resource) { - return IOUtils.readCacheImage(resource); - } - - /** - * 直接从磁盘中读取图片,这种方法效率稍低但每次图片更改了也能即时反应出来 - * - * @param resource 图片的路径 - * @return 图片 - * @see IOUtils#readImage(String) - * @deprecated - */ - public static BufferedImage readImage(String resource) { - //daniel bug 5400 图片读取 默认关闭缓存 - return IOUtils.readImage(resource); - } - - /** - * 读取图标,该方法启用了缓存 - * - * @param resource 图标文件的存放路径 - * @return 图标 - * @see IOUtils#readIcon(String) - * @deprecated - */ - public static Icon readIcon(String resource) { - return IOUtils.readIcon(resource); - } - - /** - * 从输入流中读取图片 - * - * @param input 输入流 - * @return 图片 - * @throws IOException - * @see IOUtils#readImage(InputStream) - * @deprecated - */ - public static BufferedImage readImage(InputStream input) throws IOException { - return IOUtils.readImage(input); - } - - /** - * 将行列对象转换成其字符串的表示形式 - * 转换后的字符串将像A2,B4,C45这样的 - *
- * 将A1单元格转化成字符串"A1": - *
- * BaseUtils.convertColumnRowToCellString(ColumnRow.valueOf(0,0));
- *
- * @param columnRow 要转换的行列对象
- * @return 表示行列位置的字符串
- */
- public static String convertColumnRowToCellString(ColumnRow columnRow) {
- if (columnRow == null) {
- return "";
- }
-
- return columnRow.toString();
- }
-
- /**
- * 将表示行列位置的字符串转换成行列对象
- * 如果转换失败,将会返回{@link ColumnRow}
- *
- * @param columnRowString 表示行列位置的字符串对象
- * @return 行列对象
- * @see ColumnRow#valueOf(String)
- * @deprecated
- */
- public static ColumnRow convertCellStringToColumnRow(String columnRowString) {
- return ColumnRow.valueOf(columnRowString);
- }
-
- /**
- * 读取jar的版本号
- *
- * @return 版本号
- * @see GeneralUtils#readBuildNO()
- * @deprecated
- */
- public static String readBuildNO() {
- return GeneralUtils.readBuildNO();
- }
-
- /**
- * 把指定位置的资源以默认的GBK编码的形式读取成字符串
- *
- * @param path 资源存放的路径
- * @return 表示资源内容的字符串
- * @see IOUtils#readResourceAsString(String)
- * @deprecated
- */
- public static String readResourceAsString(String path) {
- return IOUtils.readResourceAsString(path);
- }
-
- /**
- * 将指定位置的资源以指定的编码形式读取成字符串
- *
- * @param path 资源存放的路径
- * @param encode 读取资源所用的编码
- * @return 表示资源内容的字符串
- * @see IOUtils#readResourceAsString(String, String)
- * @deprecated
- */
- public static String readResourceAsString(String path, String encode) {
- return IOUtils.readResourceAsString(path, encode);
- }
-
- @Deprecated
- public static String[] getDependence(Object value, CalculatorProvider c) {
-
- try {
- return (String[]) StableUtils.invokeMethod("com.fr.form.FormUtils", "getDependence", new Class[]{Object.class, CalculatorProvider.class}, new Object[]{value, c});
- } catch (Exception e) {
- FineLoggerFactory.getLogger().error(e.getMessage(), e);
- }
- return null;
- }
-
- /**
- * 读取资源
- *
- * @param path 资源存放的路径,可以是一个URL
- * @return 返回资源的输入流
- * @see IOUtils#readResource(String)
- * @deprecated
- */
- public static InputStream readResource(String path) {
- return IOUtils.readResource(path);
- }
-
- /**
- * 截取图片的指定区域作为一个图标
- *
- * @param image 原始的图片
- * @param startx 截取的横向起始位置
- * @param starty 截取的纵向起始位置
- * @param width 截取的图标的宽度
- * @param height 截取的图标的高度
- * @return 图标
- */
- public static ImageIcon createIcon(Image image, int startx, int starty, int width, int height) {
- JFrame jc = new JFrame();
- Image cropImage = jc.createImage(new FilteredImageSource(image.getSource(), new CropImageFilter(startx, starty, width, height)));
- return new ImageIcon(cropImage);
- }
-
- /**
- * 将一个长整形数组以指定的分隔符转化成一个字符串
- *
- * @param array 数组
- * @param decimal 分隔符
- * @return 表示数组的字符串
- */
- public static String toLongArrayString(long[] array, char decimal) {
- StringBuffer sb = new StringBuffer();
- if (array != null) {
- for (int i = 0; i < array.length; i++) {
- if (i != 0) {
- sb.append(decimal);
- }
- sb.append(array[i]);
- }
- }
- return sb.toString();
- }
-
- /**
- * 将一个有规则的字符串按指定的分隔符分割并转化成一个长整型数组
- *
- * @param str 有规则的字符串
- * @param decimal 分隔符
- * @return 长整型数组
- */
- public static long[] toLongArrayFromStr(String str, char decimal) {
- List list = new ArrayList();
- if (str == null) {
- return new long[0];
- }
- String[] strarray = StableUtils.splitString(str, String.valueOf(decimal));
- for (int i = 0; i < strarray.length; i++) {
- String text = strarray[i].trim();
- list.add(Long.valueOf(text));
- }
-
- long[] res = new long[list.size()];
- for (int i = 0; i < res.length; i++) {
- res[i] = ((Long) list.get(i)).longValue();
- }
-
- return res;
- }
-
-
- /**
- * 获取样式中字体的类型
- *
- * @param g2d 图形上下文
- * @param style 样式
- * @param resolution 屏幕分辨率
- * @return 字体
- */
- public static Font getStyleFont(Graphics2D g2d, Style style, int resolution) {
- FRFont font = style.getFRFont();
- Font rfont = initFontWithLocaleAndG2d(g2d, font, resolution);
- if (!ComparatorUtils.equals(rfont, g2d.getFont())) {
- g2d.setFont(rfont);
- }
- Color foreground = font.getForeground();
- if (!ComparatorUtils.equals(foreground, g2d.getPaint())) {
- g2d.setPaint(foreground);
- }
-
- return rfont;
- }
-
-
- private static Font initFontWithLocaleAndG2d(Graphics2D g2d, FRFont font, int resolution) {
- Locale locale = GeneralContext.getLocale();
- Font rfont;
- if (ComparatorUtils.equals(Locale.ENGLISH, locale)) {
- rfont = FRFont.getInstance("Dialog", font.getStyle(), font.getSize());
- }
-
- rfont = font.applyResolutionNP(resolution);
- //itext的bug 用SimSun导出无法实现粗体斜体, 其作者解释是使用basefont是不支持这些style的, 要转成itext的亚洲字体
- //这边不用instance of的原因就是不想把itext包引到applet包里面去.
- if (g2d.toString().indexOf("PdfGraphics2D") != -1 && ComparatorUtils.equals(FRFont.DEFAULT_FONTNAME, font.getName())) {
- //不要把这边的'宋体'改成'Simsun', 就这么设定的
- rfont = FRFont.getInstance(InterProviderFactory.getProvider().getLocText("Fine-Core_Base_Song_TypeFace"), rfont.getStyle(), rfont.getSize(),
- font.getForeground(), font.getUnderline(), font.isStrikethrough(), font.isShadow(),
- font.isSuperscript(), font.isSubscript());
- }
-
- return rfont;
- }
-
- /**
- * 获取样式中关于水平方向上的对齐类型
- *
- * @param style 样式
- * @return 水平方向上的对齐类型
- */
- public static int getAlignment4Horizontal(Style style) {
- return getAlignment4Horizontal(style, null);
- }
-
- /**
- * 获取DataMoodel中第columnIndex列的数据.
- *
- * @param model 取数的数据来源
- * @param columnIndex 取数的数据列序号
- * @return 返回数据数组Object[]
- */
- public static Object[] getDistinctValues(DataModel model, int columnIndex) throws TableDataException {
- ListSet list = new ListSet();
- if (columnIndex != DataModel.COLUMN_NAME_NOT_FOUND) {
- for (int i = 0, len = model.getRowCount(); i < len; i++) {
- list.add(model.getValueAt(i, columnIndex));
- }
- }
-
- return list.toArray();
- }
-
- /**
- * 获取水平方向上的对齐样式
- *
- * @param style 样式
- * @param value 单元格的值,默认情况下,当不设置对齐类型时,如果单元格的值是数字则靠右对齐,字符串则靠左对齐
- * @return 水平方向上的对齐样式
- */
- public static int getAlignment4Horizontal(Style style, Object value) {
- int horizontalAlignment = style.getHorizontalAlignment();
- //若是默认值:判断 bug5188 数字居右
- if (value != null && horizontalAlignment == Constants.NULL) {
- if (value instanceof String) {
- if (style.getFormat() instanceof NumberFormat || StableUtils.isNumber((String) value)) {
- horizontalAlignment = Constants.RIGHT;
- } else {
- //字符串:靠左
- horizontalAlignment = Constants.LEFT;
- }
- } else if (value instanceof Number) {
- horizontalAlignment = Constants.RIGHT;
- }
- }
- return horizontalAlignment;
- }
-
- /**
- * 基本的画文本的方法,只考虑样式中的字体和对齐方式
- *
- * @param g2d 图形上下文
- * @param width 画文本的区域的宽度
- * @param height 画文本的区域的高度
- * @param text 要画的文本
- * @param style 样式
- * @param resolution 屏幕分辨率
- */
- public static void drawStringStyleInRotation(Graphics2D g2d, int width, int height, String text, Style style, int resolution) {
- if (StringUtils.isBlank(text)) {
- return;
- }
-
- Paint oldPaint = g2d.getPaint();
- Font oldFont = g2d.getFont();
-
- if (style == null) {
- style = Style.DEFAULT_STYLE;
- }
-
- Font font = getStyleFont(g2d, style, resolution);
- font = readExtraFont(g2d, font);
- int horizontalAlignment = BaseUtils.getAlignment4Horizontal(style, text);
-
- if (style.getRotation() != 0 && style.getVerticalText() == Style.HORIZONTALTEXT) {
- drawHorizontalText(g2d, text, font, style, width, height, horizontalAlignment);
- } else {
- drawRotationText(g2d, text, style, font, width, height, horizontalAlignment, resolution);
- }
-
- g2d.setFont(oldFont);
- g2d.setPaint(oldPaint);
- }
-
- private static Font readExtraFont(Graphics2D g2d, Font font) {
- ExtraClassManagerProvider pluginProvider = PluginModule.getAgent(PluginModule.ExtraCore);
- if (pluginProvider != null) {
- FontProcessor processor = pluginProvider.getSingle(FontProcessor.MARK_STRING);
- if (processor != null) {
- font = processor.readExtraFont(font);
- g2d.setFont(font);
- }
- }
- return font;
- }
-
- private static void drawHorizontalText(Graphics2D g2d, String text, Font rfont, Style style, double width, double height, int horizontalAlignment) {
- AffineTransform trans = new AffineTransform();
- trans.rotate(-Math.toRadians(style.getRotation()));
-
- double textX = width / 2.0;
- double textY = height / 2.0;
-
- Dimension2D textDimension = GraphHelper.stringDimensionWithRotation(text, rfont, -style.getRotation(), g2d.getFontRenderContext());
-
- if (textDimension.getWidth() < width) {
- if (horizontalAlignment == Constants.LEFT) {
- textX = textDimension.getWidth() / 2.0;
- } else if (horizontalAlignment == Constants.RIGHT) {
- textX = width - textDimension.getWidth() / 2.0 - style.getPaddingLeft() *
- Math.cos(Math.toRadians(style.getRotation()));
- } else {
- }
- }
-
- // adjust y, height.
- if (textDimension.getHeight() < height) {
- if (style.getVerticalAlignment() == Constants.TOP) {
- textY = textDimension.getHeight() / 2.0;
- } else if (style.getVerticalAlignment() == Constants.BOTTOM) {
- textY = height - textDimension.getHeight() / 2.0 - style.getPaddingLeft() * Math.sin(Math.toRadians(style.getRotation()));
- } else {
- }
- }
-
- GraphHelper.drawRotatedString(g2d, text, textX, textY, -style.getRotation());
- }
-
- private static void drawRotationText(Graphics2D g2d, String text, Style style, Font rfont, int width, int height, int horizontalAlignment, int resolution) {
- AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess();
- if (process != null) {
- process.drawRotationText(g2d, text, new ObjectHolder(style), rfont, width, height, horizontalAlignment, resolution);
- return;
- }
-
- FontMetrics cellFM = GraphHelper.getFontMetrics(rfont);
- List lineTextList = BaseUtils.getLineTextList(text, style, rfont, height, width, resolution);
-
- if (width <= 0 || lineTextList.isEmpty()) {
- return;
- }
-
- int textAscent = cellFM.getAscent();
- int textHeight = cellFM.getHeight();
-
- int textY = calculateTextY(style, height, textHeight, textAscent, lineTextList, resolution);
-
- int maxWidth = 0;
- for (int i = 0; i < lineTextList.size(); i++) {
- String paint_str = (String) lineTextList.get(i);
- int textWidth = cellFM.stringWidth(paint_str);
- if (textWidth > maxWidth) {
- maxWidth = textWidth;
- }
- }
- for (int i = 0; i < lineTextList.size(); i++) {
- String paint_str = (String) lineTextList.get(i);
- //把自定义角度为0的横排和竖排区分开来
- if (style.getRotation() == 0 && style.getVerticalText() == style.HORIZONTALTEXT) {
- maxWidth = cellFM.stringWidth(paint_str);
- }
- boolean textLonger = false;//KevinWang: 标志一下:是否串长大于列宽
- if (maxWidth > width - style.getPaddingLeft() - style.getPaddingRight()) {
- textLonger = true;//added by KevinWang <处理分散对齐时使用>
- } //待会串长大于列宽时需要特别处理:只从中抽取合适长度的串值显示
-
- int textX = (int) calculateTextX(style, width, maxWidth, horizontalAlignment, resolution);
- int textWidth = width - style.getPaddingRight();
- if (isAutomaticLine(style, horizontalAlignment, textLonger)) {//自动换行时
- GraphHelper.drawString2(g2d, paint_str, textX, textY, textWidth);
- } else if (isDistributeAlign(style, horizontalAlignment, textLonger)) {
- drawTextWihenDistributeAlign(g2d, paint_str, cellFM, textWidth, textX, textY);
- } else { //这里不能删除
- GraphHelper.drawString(g2d, paint_str, textX, textY);
- }
- textY += textHeight;// TODO 只增加了Y.
- textY += PX.toPixWithResolution(style.getLineSpacing(), resolution);
- }
- }
-
- public static int calculateTextY(Style style, int height, int textHeight, int textAscent, List lineTextList, int resolution) {
- return calculateTextY(style, height, textHeight, textAscent, lineTextList, resolution, 1);
- }
-
- /**
- * 计算Y的高度
- *
- * @param style 样式
- * @param height 总高度
- * @param textHeight 文本高度
- * @param textAscent 字体的基线到大多数字母数字字符顶部的距离
- * @param lineTextList 文本列
- * @param resolution 分辨率
- * @return Y高度
- */
- public static int calculateTextY(Style style, int height, int textHeight, int textAscent, List lineTextList, int resolution, int scale) {
- // 计算Y的高度.
- int textY = 0;
- int textAllHeight = textHeight * lineTextList.size();
- double spacingBefore = PX.toPixWithResolution(style.getSpacingBefore() * scale, resolution);
- double spacingAfter = PX.toPixWithResolution(style.getSpacingAfter() * scale, resolution);
- double lineSpacing = PX.toPixWithResolution(style.getLineSpacing() * scale, resolution);
- textAllHeight += spacingBefore + spacingAfter + lineSpacing * lineTextList.size();
- if (style.getVerticalAlignment() == Constants.TOP) {
- } else if (style.getVerticalAlignment() == Constants.CENTER) {
- if (height > textAllHeight) {// 如果所有文本的高度小于当前可以绘区域的高度,就从0开始画字符.
- textY = (height - textAllHeight) / 2;
- }
- } else if (style.getVerticalAlignment() == Constants.BOTTOM) {
- if (height > textAllHeight) {
- textY = height - textAllHeight;
- }
- }
- textY += textAscent;// 在绘画的时候,必须添加Ascent的高度.
- textY += spacingBefore + lineSpacing;//james:加上"段前间距"+“行间距”
- return textY;
- }
-
-
- public static int calculateTextX(Style style, Font rfont, String paint_str, int width, int textWidth, int horizontalAlignment) {
- return calculateTextX(style, rfont, paint_str, width, textWidth, horizontalAlignment, 1);
- }
-
- /**
- * 计算X宽度
- *
- * @param style 样式
- * @param rfont 字体
- * @param paint_str 字符串
- * @param width 宽度
- * @param textWidth 文本宽度
- * @param horizontalAlignment 垂向对齐
- * @return X宽度
- */
- public static int calculateTextX(Style style, Font rfont, String paint_str, int width, int textWidth, int horizontalAlignment, int scale) {
- int textX = style.getPaddingLeft() * scale;
- if (horizontalAlignment == Constants.CENTER) {
- textX += (width - textWidth - textX) / 2;
- } else if (horizontalAlignment == Constants.RIGHT) {
- textX = width - style.getPaddingRight() * scale - textWidth;
-//// // TODO alex:just for flash print && for font.Tahoma
-// if (Boolean.TRUE == FRCoreContext.TMAP.get()
-// && ComparatorUtils.equals(rfont.getFontName(), "Tahoma")) {
-// textX -= paint_str.length() / 3;
-// }
- }
- return textX;
- }
-
- /**
- * 计算X宽度
- *
- * @param style 样式
- * @param width 宽度
- * @param textWidth 文本宽度
- * @param horizontalAlignment 垂向对齐
- * @param resolution 分辨率
- * @return X宽度
- */
- public static double calculateTextX(Style style, int width, int textWidth, int horizontalAlignment, int resolution) {
- return calculateTextX(style, width, textWidth, horizontalAlignment, resolution, 1);
- }
-
- /**
- * 计算文本X位置
- *
- * @param style 样式
- * @param width 宽度
- * @param textWidth 文本宽度
- * @param horizontalAlignment 水平对齐
- * @return X宽度
- */
- public static double calculateTextX(Style style, int width, int textWidth, int horizontalAlignment, int resolution, int scale) {
- double textX = padding2PixExcludeRight(style.getPaddingLeft(), resolution);
- if (horizontalAlignment == Constants.CENTER) {
- textX += (width - textWidth - textX) / 2f;
- } else if (horizontalAlignment == Constants.RIGHT) {
- textX = width - style.getPaddingRight() * scale - textWidth;
- }
- return textX;
- }
-
- /**
- * 将缩减、段间距转为对应dpi下的pix Ps:除了右缩进
- *
- * @param padding
- * @param resolution
- * @return
- */
- public static double padding2PixExcludeRight(int padding, int resolution) {
- return PX.toPixWithResolution(padding, resolution);
- }
-
- /**
- * 将右缩进转为对应dpi下的pix
- *
- * @param paddingRight
- * @param resolution
- * @return
- */
- public static double paddingRight2Pix(int paddingRight, int resolution) {
- if (paddingRight == Style.DEFAULT_PADDING) {
- return 0;
- }
- return paddingRight;
- }
-
- public static boolean isAutomaticLine(Style style, int horizontalAlignment, boolean textLonger) {
- return horizontalAlignment == Constants.DISTRIBUTED
- && style.getTextStyle() == Style.TEXTSTYLE_WRAPTEXT
- || horizontalAlignment == Constants.DISTRIBUTED
- && style.getTextStyle() == Style.TEXTSTYLE_SINGLELINE
- && !textLonger;
- }
-
- public static boolean isDistributeAlign(Style style, int horizontalAlignment, boolean textLonger) {
- return horizontalAlignment == Constants.DISTRIBUTED
- && style.getTextStyle() == Style.TEXTSTYLE_SINGLELINE
- && textLonger;
- }
-
- public static void drawTextWihenDistributeAlign(Graphics2D g2d, String paint_str, FontMetrics cellFM, int width, int textX, int textY) {
- drawTextWihenDistributeAlign(g2d, paint_str, cellFM, width, textX, textY, 1f);
- }
-
- /**
- * 画字符串:分散对齐
- * @param scale 缩放比例,主目前要用于删除线、下划线及阴影的绘制
- */
- public static void drawTextWihenDistributeAlign(Graphics2D g2d, String paint_str, FontMetrics cellFM, int width, int textX, int textY, float scale) {
- String lineText = getSingleLineText(paint_str, cellFM, width);
- if (StringUtils.isNotEmpty(lineText)) {
- GraphDrawHelper.drawString4DistributeAlign(g2d, lineText, textX, textY, width, scale);
- }
- }
-
- /**
- * 获取用于单行显示的text
- *
- * @param lineText 分行显示时第i行的内容,但是也可能单行
- * @param cellFM 字体
- * @param width 宽度
- * @return 拆分后的字符串
- */
- private static String getSingleLineText(String lineText, FontMetrics cellFM, int width) {
- // 单行显示时的分散对齐实现e
- // 串长大于列宽时需要特别处理:只从中抽取合适长度的串值显示
- StringBuffer strBuff = new StringBuffer();
- for (int charIndex = 0; charIndex < lineText.length(); charIndex++) {
- strBuff.append(lineText.charAt(charIndex));
- int buffWidth = cellFM.stringWidth(new String(strBuff));
- if (buffWidth > width) { //长度足够了,开始显示
- return strBuff.substring(0, 0 == charIndex ? 0 : charIndex - 1);//只画一行
- }
- }
- //上面的width没有减去padding-left,可能啥也没画
- return strBuff.toString();
- }
-
- /**
- * 将输入字符串转换为实际字符,\代表转义字符。
- *
- * @param text 字符串
- * @return the real value 实际字符
- */
- public static String textToString(String text) {
- //跟这里的drawText算法是一致的,这样"所见即所得",
- //如果把drawText的参数text先用此方法转换也行的,但是会遍历俩次,所以先留着
- if (text == null) {
- return "";
- }
-
- int len = text.length();
- StringBuffer sb = new StringBuffer(len);
-
- for (int i = 0; i < len; i++) {
- char c = text.charAt(i);
- if (c == '\\' && i + 1 < len) {
- char next = text.charAt(i + 1);
- if (next == 'n') {
- i++;
- c = '\n';
- } else if (next == '\\') {
- i++;
- }
-
- }
- sb.append(c);
- }
- return sb.toString();
- }
-
- /**
- * daniel: 自动换行算法, 这个算法要求跟DHTML中Table的自动换行表现结果一样
- * 所以统一72dpi进行处理
- *
- * @param text
- * @param style
- * @param paintWidth
- * @return
- */
- public static List getLineTextList(String text, Style style, Font font, double paintWidth, int resolution) {
- List lineTextList = new ArrayList();
- if (text == null || text.length() <= 0) {
- return lineTextList;
- }
-
- style = style == null ? Style.DEFAULT_STYLE : style;
-
- if (style.getRotation() != 0) {
- lineTextList.add(text);
- return lineTextList;
- }
-
- if (style.getTextStyle() != Style.TEXTSTYLE_WRAPTEXT) {
- return lineTextListNotChangeLine(lineTextList, text);
- }
- // 自动换行
- else {
- UNIT width = FU.valueOfPix((int) paintWidth, resolution);
- return lineTextListAutoChangeLine(lineTextList, text, font, style, width, resolution);
- }
- }
-
- private static List lineTextListNotChangeLine(List lineTextList, String text) {
- char tmpChar;
- StringBuffer tmpTextBuf = new StringBuffer();
- for (int t = 0; t < text.length(); t++) {
- tmpChar = text.charAt(t);
- if (tmpChar == '\\') {// 判断是否是 "\n"
- if (t + 1 < text.length() && text.charAt(t + 1) == 'n') {
- // 是"\n"字符串,但不是换行符.
- t++;
- lineTextList.add(tmpTextBuf.toString());
- tmpTextBuf.delete(0, tmpTextBuf.length());
- } else {
- tmpTextBuf.append(tmpChar);
- }
- } else {
- tmpTextBuf.append(tmpChar);
- }
- }
-
- // 最后一个
- if (tmpTextBuf.length() > 0) {
- lineTextList.add(tmpTextBuf.toString());
- tmpTextBuf.delete(0, tmpTextBuf.length());
- }
-
- return lineTextList;
- }
-
- /**
- * 这里需要用resolution 72的dpi进行分行,因为96dpi会导致font有小数导致获取的宽度不正确
- *
- * @param lineTextList
- * @param text
- * @param style
- * @return
- */
- private static List lineTextListAutoChangeLine(List lineTextList, String text, Font font, Style style, UNIT unitWidth, int resolution) {
-
- AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess();
- if (process != null) {
- return process.autoChangeLine(text, new ObjectHolder(style), unitWidth);
- }
- if (font == null) {
- font = style.getFRFont();
- }
- FontMetrics fontMetrics = GraphHelper.getFontMetrics(font);
- double paintWidth = unitWidth.toPixD(resolution);
- double width = paintWidth - style.getPaddingLeft() - style.getPaddingRight() - style.getBorderLeftWidth();
- StringBuffer lineTextBuf = new StringBuffer();
- int lineTextWidth = 0;
-
- StringBuffer wordBuf = new StringBuffer();
- int wordWidth = 0;
- int[] tmpWidth = new int[2];
- tmpWidth[0] = wordWidth;
- tmpWidth[1] = lineTextWidth;
-
- lineTextListDealWithText(text, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics);
-
- // 最后处理
- if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) {
- lineTextList.add(lineTextBuf.toString());
- lineTextList.add(wordBuf.toString());
- } else {
- lineTextBuf.append(wordBuf);
- lineTextList.add(lineTextBuf.toString());
- }
- return lineTextList;
- }
- private static void lineTextListDealWithText(String text, List lineTextList, double width, int[] tmpWidth,
- StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) {
- for (int t = 0; t < text.length(); t++) {
- if (t != 0 && isNumOrLetter(text.charAt(t)) && isNumOrLetter(text.charAt(t - 1))) {
- dealWithTextNumOrLetter(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics);
- } else if (text.charAt(t) == '\n' || (text.charAt(t) == '\r' && t + 1 < text.length() - 1 && text.charAt(t + 1) != '\n')) {
- dealWithTextChangeLineSymbol(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics);
- } else if (text.charAt(t) == '\\' && t + 1 < text.length() && text.charAt(t + 1) == 'n') {// 判断是否是 "\n"
- // 是"\n"字符串,但不是换行符,依然需要换行.
- dealWidthTextManualChangeLine(text, t, lineTextList, width, tmpWidth, wordBuf, lineTextBuf, fontMetrics);
- // 需要跳过后面的n
- t++;
- } else {
- int increaseStep = 0;
- if (text.charAt(t) == '\\' && t + 1 < text.length() && text.charAt(t + 1) == '\\') {// 判断是否是转义字符'\'
- // _denny: 增加了转义字符'\\'用来表示\,使"\n"可以输入
- t++;
- increaseStep++;
- }
- if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) {
- if (isPunctuationAtLineHead(t, text)) {
- for (int index = lineTextBuf.length(); index > 0; index--) {
- char prec = lineTextBuf.charAt(index - 1);
- lineTextBuf.deleteCharAt(index - 1);
- if (!isPunctuation(prec)) {
- break;
- }
- }
- }
- lineTextList.add(lineTextBuf.toString());
- lineTextBuf.delete(0, lineTextBuf.length());
- tmpWidth[1] = isPunctuationAtLineHead(t, text) ? dealWithPunctuationAtLinehead(t, fontMetrics, text, lineTextBuf, wordBuf.length(), increaseStep) : 0;
- }
- lineTextBuf.append(wordBuf);
- tmpWidth[1] += tmpWidth[0];
-
- wordBuf.delete(0, wordBuf.length());
- tmpWidth[0] = 0;
- wordBuf.append(text.charAt(t));
- tmpWidth[0] = fontMetrics.charWidth(text.charAt(t));
- }
- }
- }
-
-
-
- /**
- * 标点符号是否在换行后的行首
- */
- private static boolean isPunctuationAtLineHead(int t, String text) {
- return t > 1 && BaseUtils.isPunctuation(text.charAt(t - 1));
- }
-
- private static int dealWithPunctuationAtLinehead(int t, FontMetrics fontMetrics, String text, StringBuffer lineTextBuf, int wordBufLength, int increaseStep) {
- //lineTextBuf 最后一个字符下标 与 text当前字符下标 t 的距离 + 1
- int indexDistance = 1 + wordBufLength + increaseStep;
- if (t < indexDistance) {
- return 0;
- }
- int lineWidth = 0;
- for (int index = t - indexDistance; index >= 0; index--) {
- lineWidth += fontMetrics.charWidth(text.charAt(index));
- lineTextBuf.insert(0, text.charAt(index));
- if (!isPunctuation(text.charAt(index))) {
- break;
- }
- }
- return lineWidth;
- }
-
- private static void dealWithTextNumOrLetter(String text, int t, List lineTextList, double width, int[] tmpWidth,
- StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) {
- if (tmpWidth[0] + fontMetrics.charWidth(text.charAt(t)) > width) {
- if (tmpWidth[1] > 0) {
- lineTextList.add(lineTextBuf.toString());
- lineTextBuf.delete(0, lineTextBuf.length());
- tmpWidth[1] = 0;
- }
-
- lineTextList.add(wordBuf.toString());
- wordBuf.delete(0, wordBuf.length());
- tmpWidth[0] = 0;
- }
-
- wordBuf.append(text.charAt(t));
- tmpWidth[0] += fontMetrics.charWidth(text.charAt(t));
- }
-
- private static void dealWithTextChangeLineSymbol(String text, int t, List lineTextList, double width, int[] tmpWidth,
- StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) {
- wordBuf.append('\n');
- if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) {
- lineTextList.add(lineTextBuf.toString());
- lineTextList.add(wordBuf.toString());
- } else {
- lineTextBuf.append(wordBuf);
- lineTextList.add(lineTextBuf.toString());
- }
- lineTextBuf.delete(0, lineTextBuf.length());
- tmpWidth[1] = 0;
- wordBuf.delete(0, wordBuf.length());
- tmpWidth[0] = 0;
- }
-
- private static void dealWidthTextManualChangeLine(String text, int t, List lineTextList, double width, int[] tmpWidth,
- StringBuffer wordBuf, StringBuffer lineTextBuf, FontMetrics fontMetrics) {
- t++;// 忽略'n'字符.
- wordBuf.append('\n');
- if (tmpWidth[1] + tmpWidth[0] > width && lineTextBuf.length() > 0) {
- lineTextList.add(lineTextBuf.toString());
- lineTextList.add(wordBuf.toString());
- } else {
- lineTextBuf.append(wordBuf);
- lineTextList.add(lineTextBuf.toString());
- }
- lineTextBuf.delete(0, lineTextBuf.length());
- tmpWidth[1] = 0;
- wordBuf.delete(0, wordBuf.length());
- tmpWidth[0] = 0;
- }
-
-
- /**
- * @param cuChar
- * @return
- * @see StableUtils
- * @deprecated
- */
- public static boolean isNum(char cuChar) {
- return StableUtils.isNum(cuChar);
- }
-
-
- /**
- * 判断字符是否为数字或字母
- *
- * @param curChar 被检查的字符
- * @return 是否为数字或字母
- */
- public static boolean isNumOrLetter(char curChar) {
- return GeneralUtils.isLetter(curChar) || StableUtils.isNum(curChar);
- }
-
- public static boolean isPunctuation(char c) {
- int type = Character.getType(c);
- return type == Character.OTHER_PUNCTUATION
- || type == Character.DASH_PUNCTUATION
- || type == Character.START_PUNCTUATION
- || type == Character.END_PUNCTUATION
- || type == Character.CONNECTOR_PUNCTUATION;
- }
-
-
- public static List getLineTextList(String text, Style style, Font font, double paintHeight, double paintWidth) {
- return getLineTextList(text, style, font, paintHeight, paintWidth, Constants.DEFAULT_PRINT_AND_EXPORT_RESOLUTION);
- }
-
- /**
- * james daniel 放一起
- * 同时含有height和width参数表示会根据style自动判断字体为竖排还是横排
- * TODO
- */
- public static List getLineTextList(String text, Style style, Font font, double paintHeight, double paintWidth, int resolution) {
- //正常文字
- if (style == null
- || style.getVerticalText() != Style.VERTICALTEXT) {//james:正常的文字时
- return BaseUtils.getLineTextList(text, style, font, paintWidth, resolution);
- }
- ExtraClassManagerProvider pluginProvider = PluginModule.getAgent(PluginModule.ExtraCore);
- if (pluginProvider != null) {
- VerticalTextProcessor processor = pluginProvider.getSingle(VerticalTextProcessor.XML_TAG, DefaultVerticalTextProcessor.class);
- String[] res = processor.process(text, style, font, paintHeight, paintWidth, resolution);
- return Arrays.asList(res);
- }
- String[] res = new DefaultVerticalTextProcessor().process(text, style, font, paintHeight, paintWidth, resolution);
- return Arrays.asList(res);
- }
-
- /**
- * 返回边框宽
- *
- * @param borderType 边框类型
- * @return 宽度
- */
- public static int getBorderWidth(int borderType) {
- switch (borderType) {
- case Constants.LINE_NONE:
- return 0;
- case Constants.LINE_SLIM:
- return 1;
- case Constants.LINE_THIN:
- return 1;
- case Constants.LINE_DASH:
- return 1;
- case Constants.LINE_HAIR:
- return 1;
- case Constants.LINE_HAIR2:
- return 1;
- case Constants.LINE_THICK:
- return 3;
- case Constants.LINE_DOT:
- return 1;
- default:
- return 2;
- }
- }
-
- /**
- * 将边框转为对应的字符串描述
- *
- * @param borderStyle 边框线型
- * @return web端对应的边框
- */
- public static String border2Style(int borderStyle) {
- switch (borderStyle) {
- case Constants.LINE_NONE:
- return "none";
- case Constants.LINE_SLIM:
- return "solid";
- case Constants.LINE_THIN:
- return "solid";
- case Constants.LINE_MEDIUM:
- return "solid";
- case Constants.LINE_THICK:
- return "solid";
- case Constants.LINE_DOUBLE:
- return "double";
- case Constants.LINE_DOT:
- return "double";
- case Constants.LINE_DASH_DOT:
- return "double";
- case Constants.LINE_DASH_DOT_DOT:
- return "dotted";
- default:
- return "dashed";
- }
- }
-
- /**
- * 克隆对象
- *
- * @param object 对象
- * @return 克隆出的对象
- * @throws CloneNotSupportedException 不被支持的克隆异常
- * @see StableUtils#cloneObject(Object)
- * @deprecated
- */
- public static Object cloneObject(Object object) throws CloneNotSupportedException {
- return StableUtils.cloneObject(object);
- }
-
-
- /**
- * 把java.util.Map转成一段JSONObject的String与上面方法对应
- *
- * @param map map对象
- * @return json对象
- * @throws JSONException json异常
- */
- public static JSONObject map2JSON(Map map) throws JSONException {
- JSONObject jo = new JSONObject();
- Iterator iter = map.keySet().iterator();
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Object value = entry.getValue();
- if (value instanceof FArray) {
- JSONArray ja = new JSONArray();
- FArray array = (FArray) value;
- for (int i = 0; i < array.length(); i++) {
- ja.put(array.elementAt(i));
- }
- value = ja;
- }
- jo.put((String) entry.getKey(), value);
- }
- return jo;
- }
-
- /**
- * 将一个对象转化成json样式的字符串
- *
- * @param o 待转化的对象
- * @return json样式的字符串
- * @throws JSONException json异常
- * @see EmbedJson#encode(Object) (Object)
- * @deprecated
- */
- public static String jsonEncode(Object o) throws JSONException {
- return EmbedJson.encode(o);
- }
-
-
- /**
- * 将一个字符串转化成JSON格式的对象
- *
- * @param str 要转化的字符串
- * @return JSON格式的对象
- * @throws JSONException json异常
- * @see JSONUtils#jsonDecode(String)
- * @deprecated
- */
- public static Object jsonDecode(String str) throws JSONException {
- return JSONUtils.jsonDecode(str);
- }
-
- /**
- * 检查图片1和2是否相同.
- *
- * @param img1 图片1
- * @param img2 图片2
- * @return 图片1和2是否相同
- */
- public static boolean imageEquals(Image img1, Image img2) {
- if (img1 == img2) {
- return true;
- }
-
- if (img1 == null || img2 == null) {//null < not null
- return img1 == null && img2 == null;
- }
-
- //开始比较图片.
- byte[] buf1 = GeneralXMLTools.imageEncode(img1);
- byte[] buf2 = GeneralXMLTools.imageEncode(img2);
- if (buf1.length != buf2.length) {
- return false;
- }
-
- for (int i = 0; i < buf1.length; i++) {
- if (buf1[i] != buf2[i]) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * 根据数据集名获取数据模型
- *
- * @param cal 算子
- * @param tdName 列表名
- * @return 数据模型
- */
- public static DataModel getDataModelFromTableDataName(Calculator cal, String tdName) {
- String tableDataName = tdName;
- //先看当前的报表中的私有数据源
- DataModel resultSet = SynchronizedLiveDataModelUtils.getSELiveDataModel4Share(cal, tableDataName);
- if (resultSet == null) {
- TableData td = TableDataAssist.getTableData(cal, tableDataName);
- resultSet = td == null ? null : td.createDataModel(cal);
- }
- return resultSet;
- }
-
-
- /**
- * kunsnat: List转化为二维表
- *
- * @param list 列表
- * @return 二维数组
- */
- public static Object[][] list2Array2D(List list) {
- int rowNum = list.size();
- int colNum = 0;
- for (int i = 0; i < rowNum; i++) {
- List row = (List) list.get(i);
- if (row.size() > colNum) {
- colNum = row.size();
- }
- }
- Object[][] result = new Object[rowNum][colNum];
-
- for (int i = 0; i < rowNum; i++) {
- List row = (List) list.get(i);
- for (int j = 0; j < colNum; j++) {
- if (j < row.size()) {
- result[i][j] = row.get(j);
- } else {
- result[i][j] = null;
- }
- }
- }
-
- return result;
- }
-
- /**
- * 判断当前Env下是否有lic文件
- *
- * @return 判断当前Env下是否有lic文件
- */
- public static boolean checkLicExist() {
-
- if (ServerPreferenceConfig.getInstance().isLicUseLock()) {
- return true;//加密狗
- } else if (!LicenseConfigManager.getInstance().isUseFile()) {
- //不使用文件,说明用户配置了注册信息,一定是注册了
- return true;
- }
-
- try {
- String licName = FRContext.getCommonOperator().getLicenseName();
- byte[] bytes = WorkContext.getWorkResource().readFully(StableUtils.pathJoin(ProjectConstants.RESOURCES_NAME, licName));
- return bytes != null && bytes.length != 0;
- } catch (Exception ignored) {
- }
-
- return false;
- }
-
- /**
- * 判断是否内容为图表相关.
- *
- * @param cellOption 单元格属性
- * @return 返回是否为图表单元格相关.
- */
- public static boolean isChartCell(JSONObject cellOption) {
- if (cellOption != null) {
- JSONObject value = cellOption.optJSONObject("value");
- if (value != null) {
- return ComparatorUtils.equals("simplechart", value.optString("type"));
- }
- }
-
- return false;
- }
-}
diff --git a/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java b/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java
deleted file mode 100644
index a937ba2d45..0000000000
--- a/designer-form/src/main/java/com/fr/design/fit/common/NewFormStyle.java
+++ /dev/null
@@ -1,2030 +0,0 @@
-/*
- * Copyright(c) 2001-2010, FineReport Inc, All Rights Reserved.
- */
-package com.fr.design.fit.common;
-
-import com.fr.base.BaseFormula;
-import com.fr.base.CoreDecimalFormat;
-import com.fr.base.FRContext;
-import com.fr.base.FormatRepository;
-import com.fr.base.GraphHelper;
-import com.fr.base.ImageProvider;
-import com.fr.base.Painter;
-import com.fr.base.Style;
-import com.fr.base.Utils;
-import com.fr.base.background.ImageBackground;
-import com.fr.common.annotations.Open;
-import com.fr.data.DataBaseUtils;
-import com.fr.general.Background;
-import com.fr.general.ComparatorUtils;
-import com.fr.general.DateUtils;
-import com.fr.general.DefaultValues;
-import com.fr.general.FRFont;
-import com.fr.general.GeneralUtils;
-import com.fr.json.JSONException;
-import com.fr.json.JSONObject;
-import com.fr.stable.AssistUtils;
-import com.fr.stable.Constants;
-import com.fr.stable.CoreGraphHelper;
-import com.fr.stable.StableUtils;
-import com.fr.stable.StringUtils;
-import com.fr.stable.unit.PT;
-import com.fr.stable.web.Repository;
-import com.fr.stable.web.ServletContext;
-import com.fr.stable.web.ServletContextAdapter;
-import org.jetbrains.annotations.Nullable;
-
-import java.awt.Color;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Graphics2D;
-import java.awt.Image;
-import java.awt.Paint;
-import java.awt.Rectangle;
-import java.awt.Shape;
-import java.awt.geom.Rectangle2D;
-import java.io.InvalidObjectException;
-import java.io.Serializable;
-import java.sql.Clob;
-import java.text.DateFormat;
-import java.text.Format;
-import java.text.NumberFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-
-/**
- * 用于表示样式的类,包括边框、颜色、字体、缩进、间距等
- * 注意:这是一个开放类,所有的修改都要注意保持兼容
- */
-@Open
-public class NewFormStyle extends Style implements Serializable, Cloneable {
-
- // temp rectangle
- private static Rectangle2D tempRectangle2D = new Rectangle2D.Double(0, 0, 0, 0);
-
- public static final int TEXTSTYLE_WRAPTEXT = 0; // 换行.
- public static final int TEXTSTYLE_SINGLELINE = 1; // 单行,超出部分不显示.
- public static final int TEXTSTYLE_SINGLELINEADJUSTFONT = 2; // 单行,调整字体来显示所有的字.
- public static final int TEXTSTYLE_MULTILINEADJUSTFONT = 3; //多行,固定单元格高和宽,调整字体来显示所有的字
-
- public static final int VERTICALTEXT = 1;// 竖排,与Excel中的设置值相同
- public static final int HORIZONTALTEXT = 0;// 横排
-
- public static final int LEFT_TO_RIGHT = 1;// JAMES:垂直文字时,文字为从左向右顺序排列
- public static final int RIGHT_TO_LEFT = 0;// JAMES:垂直文字时,文字为从右向左顺序排列
-
- //EXCEL 宋体11号字, 一个缩进单位对应96dpi下27px
- public static final int PADDING_ARG = 27;
- public static final int DEFAULT_PADDING = 2;
- /**
- * 细线透明度值
- */
- public static final double FACTORY_ALPHA = 0.4;
- public static final NewFormStyle NULL_STYLE = null;
-
- /**
- * Default Style
- */
- public static final NewFormStyle DEFAULT_STYLE = new NewFormStyle();
-
- /**
- * Border Style
- */
- public static final NewFormStyle BORDER_STYLE = new NewFormStyle();
-
- private static final long serialVersionUID = -1675056857456167839L;
- private static final int MAX_FONT_SIZE = 100;
- private static final int N_SIZE = 9;
- private static final int MIN_SIZE = 8;
- private static final int MAX_SIZE = 26;
-
- private static final int LINE_HEIGHT_FIX = 4;
- private static final int LINE_HEIGHT_FIX2 = 3;
-
- private static class ContentLineGroup {
- Style style;
- List newLineTextList;
- int newTextHeight;
-
- public ContentLineGroup(Style style, List lineList, int textHeight) {
- this.style = style;
- this.newLineTextList = lineList;
- this.newTextHeight = textHeight;
- }
-
- public int totalHeight() {
- return newTextHeight * newLineTextList.size();
- }
- }
-
- private static Map clsFontFamily = null;
-
- // 全局Style的map
- private static Map initializeStyle = new ConcurrentHashMap();// BaseUtils.getLineTextList
, 等于BaseUtils.getLineTextList().size()
- * Denny: 为了提高速度和性能,才单独拿出来的
- * TODO: 重构
- *
- * @param text 文本
- * @param style 样式
- * @param paintWidth 单元格宽度
- * @return paintWidth 单位为PT
- */
- public static int getLineTextCount(String text, Style style, UNIT paintWidth) {
- if (style.getRotation() != 0) {
- return 1;
- }
-
-
- if (style.getTextStyle() != Style.TEXTSTYLE_WRAPTEXT) {
- return dealNotWrapTextCount(text.toCharArray());
- } else {// 自动换行
- return dealWrapTextCount(text, style, paintWidth);
- }
- }
-
- private static int dealNotWrapTextCount(char[] text_chars) {
- boolean remain_chars = false;
- int count = 0;
- for (int t = 0; t < text_chars.length; t++) {
- if (text_chars[t] == '\\') {// 判断是否是 "\n"
- if (t + 1 < text_chars.length && text_chars[t + 1] == 'n') {
- // 是"\n"字符串,但不是换行符.
- t++;
- count++;
- if (remain_chars) {
- remain_chars = false;
- }
- } else {
- if (!remain_chars) {
- remain_chars = true;
- }
- }
- } else if (text_chars[t] == '\n' || (text_chars[t] == '\r' && t + 1 < text_chars.length - 1 && text_chars[t + 1] != '\n')) {
- count++;
- if (remain_chars) {
- remain_chars = false;
- }
- } else {
- if (!remain_chars) {
- remain_chars = true;
- }
- }
- }
-
- // 最后一个
- if (remain_chars) {
- count++;
- }
-
- return count;
- }
-
- // 自动换行
- //neil:style里面, 默认值padding right = 2时, 默认不生效, 这边算行高时也不要计算入内
- //临时处理, 去掉左边框线, 因为浏览器计算时需要考虑左边框线宽度, 但这边还是存在问题的
- //同样需要考虑的是导出和web端展示, padding计算方式也不一致.
- private static int dealWrapTextCount(String text, Style style, UNIT unitWidth) {
- AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess();
- if (process != null) {
- return process.getAutoChangeLineCount(text, new ObjectHolder(style), unitWidth);
- }
- int count = 0;
- char[] text_chars = text.toCharArray();
- FontMetrics fontMetrics = getFontMetrics(style);
- double paintWidth = unitWidth.toPixD(Constants.FR_PAINT_RESOLUTION);
- double width = paintWidth - style.getPaddingLeft() - (style.getPaddingRight() == Style.DEFAULT_PADDING ? 0 : style.getPaddingRight()) - style.getBorderLeftWidth();
- boolean remain_lineText = false;
- int lineTextWidth = 0;
- int wordWidth = 0;
- for (int t = 0, len = text_chars.length; t < len; t++) {
- if (t != 0 && BaseUtils.isNumOrLetter(text_chars[t]) && BaseUtils.isNumOrLetter(text_chars[t - 1])) {
- if (wordWidth + fontMetrics.charWidth(text_chars[t]) > width) {
- if (lineTextWidth > 0) {
- count++;
- remain_lineText = false;
- lineTextWidth = 0;
- }
- count++;
- wordWidth = 0;
- }
- wordWidth += fontMetrics.charWidth(text_chars[t]);
- } else if (isSwitchLine(text_chars, t) || isLN(text_chars, t)) {// 判断是否是 "\n"
- if (isLN(text_chars, t)) {
- t++;// 忽略'n'字符.// 是"\n"字符串,但不是换行符,依然需要换行.
- }
- if (lineTextWidth + wordWidth > width && remain_lineText) {
- count += 2;
- } else {
- count++;
- }
- remain_lineText = false;
- lineTextWidth = 0;
- wordWidth = 0;
- } else {
- if (text_chars[t] == '\\' && t + 1 < text_chars.length && text_chars[t + 1] == '\\') {// 判断是否是转义字符'\'
- t++;// _denny: 增加了转义字符'\\'用来表示\,使"\n"可以输入
- }
- if (lineTextWidth + wordWidth > width && remain_lineText) {
- count++;
- lineTextWidth = isPunctuationAtLineHead(t, text_chars) ? dealLineWidthWithPunctuation(t, text_chars, fontMetrics) : 0;
- }
- remain_lineText = true;
- lineTextWidth += wordWidth;
- wordWidth = fontMetrics.charWidth(text_chars[t]);
- }
- }
- if (lineTextWidth + wordWidth > width && remain_lineText) {
- count += 2;
- } else {
- count++;
- }
- return count;
- }
-
- /**
- * 标点符号是否在换行后的行首
- */
- private static boolean isPunctuationAtLineHead(int t, char[] text_chars) {
- if (t > 1 && BaseUtils.isPunctuation(text_chars[t - 1])) {
- return true;
- }
- return false;
- }
-
- /**
- * 防止有连续多个标点符号,要找一个非标点符号字符
- *
- * @date 2014-4-17
- */
- private static int dealLineWidthWithPunctuation(int t, char[] text_chars, FontMetrics fontMetrics) {
- if (t < 2) {
- return 0;
- }
- int lineWidth = 0;
- for (int index = t - 2; index >= 0; index--) {
- lineWidth += fontMetrics.charWidth(text_chars[index]);
- if (!BaseUtils.isPunctuation(text_chars[index])) {
- break;
- }
- }
- return lineWidth;
- }
-
- private static boolean isSwitchLine(char[] text_chars, int t) {
- return text_chars[t] == '\n' || (text_chars[t] == '\r' && t + 1 < text_chars.length - 1 && text_chars[t + 1] != '\n');
- }
-
- private static boolean isLN(char[] text_chars, int t) {
- return text_chars[t] == '\\' && t + 1 < text_chars.length && text_chars[t + 1] == 'n';
- }
-
- /**
- * Gets the preferred width.
- */
- public static UNIT getPreferredWidth(CellElement cell, UNIT height) {
- if (cell == null) {
- return UNIT.ZERO;
- }
-
- Object value = cell.getShowValue();
- // 只接受Text,Number,和SeparatorPainter
- // got the text
- if (value instanceof BaseFormula) {
- if (((BaseFormula) value).getResult() != null) {
- value = ((BaseFormula) value).getResult();
- } else {
- value = StringUtils.EMPTY;
- }
- }
- Style style = cell.getStyle();
- if (style == null) {
- style = Style.DEFAULT_STYLE;
- }
- CellGUIAttr cg = cell.getCellGUIAttr() == null ? new CellGUIAttr() : cell.getCellGUIAttr();
- value = Utils.resolveOtherValue(value, cg.isShowAsImage(), PresentationType.EXPORT);
- String text = Style.valueToText(value, style.getFormat());
-
- FontMetrics cellFM = getFontMetrics(style);
- //bug 12151 有边框线的单元格 自动调整列宽 会多一行
- UNIT padding = new PT(style.getPaddingLeft() + style.getPaddingRight());
-
- if (cg.isShowAsHTML()) {
- return Html2ImageUtils.getHtmlWidth(text, height, style);
- }
-
- return FU.valueOfPix(cellFM.stringWidth(text) + UNIT_SIZE, Constants.FR_PAINT_RESOLUTION).add(padding);
- }
-
- private static FontMetrics getFontMetrics(Style style) {
- Font font = style.getFRFont().applyResolutionNP(Constants.FR_PAINT_RESOLUTION);
- FontProcessor processor = ExtraClassManager.getInstance().getSingle(FontProcessor.MARK_STRING);
- if (processor != null) {
- font = processor.readExtraFont(font);
- }
- return GraphHelper.getFontMetrics(font);
- }
-
- /**
- * Preferred height. (Got the shrink preferred height of CellElement).
- * 单位格的预计算高度
- *
- * @param cellElement 单元格内容
- * @param paintWidth 画的宽度
- * @return UNIT 单位
- */
- public static UNIT analyzeCellElementPreferredHeight(CellElement cellElement, UNIT paintWidth) {
- // 计算高度用显示值
- Object value = cellElement.getShowValue();
- // 只接受Text,Number,和SeparatorPainter
- Style style = cellElement.getStyle();
- // got the text
- if (value instanceof BaseFormula) {
- if (((BaseFormula) value).getResult() != null) {
- value = ((BaseFormula) value).getResult();
- } else {
- value = StringUtils.EMPTY;
- }
- }
- CellGUIAttr cg = cellElement.getCellGUIAttr() == null ? new CellGUIAttr() : cellElement.getCellGUIAttr();
- if (!(value instanceof String) && !(value instanceof Integer)) {
- value = DataUtils.resolveOtherValue(value, cg.isShowAsImage(), cg.isShowAsDownload(), null, true);
- }
- String text = Style.valueToText(value, style.getFormat());
-
- if (cg.isShowAsHTML()) {
- return Html2ImageUtils.getHtmlHeight(text, paintWidth, style);
- }
-
- return PaintUtils.analyzeCellElementPreferredHeight(text, style, paintWidth, cg.isShowAsHTML());
- }
-
- /**
- * 单位格的预计算高度
- * 单位PT
- *
- * @param text 文本
- * @param style 格式
- * @param paintWidth 画的宽度
- * @param isShowAsHtml 是否以html展示
- * @return 返回 单位
- */
- private static UNIT analyzeCellElementPreferredHeight(String text, Style style, UNIT paintWidth, boolean isShowAsHtml) {
- if (style == null) {
- //peter:获取默认的Style.
- style = Style.DEFAULT_STYLE;
- }
-
- // got the text
- if (text == null || text.length() <= 0) {
- return PT.valueOf(0);
- }
-
- // 变成Line Text List.
- if (style.getRotation() != 0) { // more easy to paint.
- // attribute map.
- return PT.valueOf((float) GraphHelper.stringDimensionWithRotation(text, style.getFRFont(), -style.getRotation(),
- CoreConstants.DEFAULT_FRC).getHeight());
- }
- // 先获得FontMetics.
- int lineCount = getLineTextCount(text, style, paintWidth);
- AutoChangeLineAndDrawProcess process = AutoChangeLineAndDrawManager.getProcess();
- if (process != null) {
- //算了这两个接口分开做
- return process.getLinedTextHeight(lineCount, new ObjectHolder(style));
- }
-
- // carl:和paint那边一致,添上段前段后和行间距
- PT lineSpacing = PT.valueOf(style.getSpacingAfter() + style.getSpacingBefore() + style.getLineSpacing() * lineCount);
- FontMetrics fontMetrics = getFontMetrics(style);
- int textHeight = fontMetrics.getHeight();
- FU allTextHeight = FU.valueOfPix(textHeight * lineCount, Constants.FR_PAINT_RESOLUTION);
- return lineSpacing.add(allTextHeight);// 需要给底部添加Leading.
- }
-
- /**
- * 截取文字,只考虑了垂直方向,水平方向没意义且难度大.
- *
- * @param value 画的值
- * @param style 字体样式格式.
- * @param blockArea 冻结的范围
- * @param resolution 分辨率
- * @return 返回的字符串
- */
- public static String clipBlockValue(Object value, Style style, Rectangle primitiveArea, Rectangle blockArea, int resolution, boolean isShowAsHTML) {
- if (value == null) {
- return null;
- }
- if (value instanceof BaseFormula) {
- value = ((BaseFormula) value).getResult();
- }
- if (blockArea.y >= primitiveArea.height || blockArea.y + blockArea.height <= 0) {
- return null;
- }
- //截取位置,相对于clipArea
- int startY = blockArea.y > 0 ? blockArea.y : 0;
- int endY = blockArea.y + blockArea.height < primitiveArea.height ? blockArea.y + blockArea.height : primitiveArea.height;
- if (blockArea.x >= primitiveArea.width || blockArea.x + blockArea.width <= 0) {
- return null;
- }
- if (isShowAsHTML) {
- return Html2ImageUtils.clipHtmlContent(value, style, primitiveArea, resolution, startY, endY);
- }
- List lineList = BaseUtils.getLineTextList((String) value, style, style.getFRFont().applyResolutionNP(resolution), primitiveArea.width, resolution);
- if (lineList.isEmpty()) {
- return null;
- }
- double spacingBefore = PT.pt2pix(style.getSpacingBefore(), resolution);
- double spacingAfter = PT.pt2pix(style.getSpacingAfter(), resolution);
- double lineSpacing = PT.pt2pix(style.getLineSpacing(), resolution);
- double lineHeight = lineSpacing + GraphHelper.getFontMetrics(style.getFRFont().applyResolutionNP(resolution)).getHeight();
- int textAllHeight = (int) (lineHeight * lineList.size() + spacingBefore + spacingAfter);
- //第一行文字距区域高度
- int textStartY = (int) spacingBefore;
-
- if (style.getVerticalAlignment() == Constants.BOTTOM) {
- textStartY += (primitiveArea.height - textAllHeight);
- }
- if (endY <= textStartY || startY >= textStartY + lineHeight * lineList.size()) {
- return null;
- }
- int lineStart = getLineStart(lineList, lineHeight, textStartY, startY);//截取区域起始行
- int lineEnd = getLineEnd(lineList, lineHeight, endY, textStartY);//截取区域结束行
- String text = "";
- for (; lineStart <= lineEnd; lineStart++) {
- text += lineList.get(lineStart);
- }
- return text;
- }
-
- private static int getLineStart(List lineList, double lineHeight, int textStartY, int startY) {
- int lineStart = 0;
- for (int i = 0; i < lineList.size(); i++) {
- if (textStartY + lineHeight * (i) <= startY && textStartY + lineHeight * (i + 1) > startY) {//压线
- if (startY - textStartY - lineHeight * (i) > lineHeight / 2) {
- lineStart = i + 1;
- } else {
- lineStart = i;
- }
- }
- }
- return lineStart;
- }
-
- private static int getLineEnd(List lineList, double lineHeight, int endY, int textStartY) {
- int lineEnd = lineList.size() - 1;
- for (int i = 0; i < lineList.size(); i++) {
- if (textStartY + lineHeight * (i) < endY && textStartY + lineHeight * (i + 1) >= endY) {//压线
- //neil:仿宋,12号字, 行间距8为例, 转为px的行间距大小为10.666, 这边算出的应该有31.98行, 因此要进位
- if (endY - textStartY - lineHeight * (i) >= lineHeight / 2) {
- lineEnd = i;
- } else {
- lineEnd = i - 1;
- }
- }
- }
- return lineEnd;
- }
-
- /**
- * paintBarcode
- */
- public static void paintBarcode(Graphics2D g2d, int width, int height, String text, Style style, BarcodeAttr barcodeAttr) {
- BarcodeImpl barcodeImpl;
- try {
- barcodeImpl = BarCodeUtils.getBarcodeImpl(barcodeAttr, text);
- } catch (BarcodeException exp) {
- try {
- //设置默认值.
- barcodeImpl = BarCodeUtils.getBarcodeImpl(new BarcodeAttr(), null);
- } catch (BarcodeException e) {
- FineLoggerFactory.getLogger().error(e.getMessage(), e);
- return;
- }
- }
-
- //字体
- if (style.getFRFont() != null) {
- barcodeImpl.setFont(style.getFRFont());
- barcodeImpl.setForeground(style.getFRFont().getForeground());
- }
- //背景
- Background background = style.getBackground();
- if (background != null && background instanceof ColorBackground) {
- barcodeImpl.setBackground(((ColorBackground) background).getColor());
- }
-
- //根据宽度和高度来确定起始点
- int pointX = (width - barcodeImpl.getWidth()) / 2;
- int pointY = (height - barcodeImpl.getHeight()) / 2;
-
- barcodeImpl.draw(g2d, pointX, pointY);
- }
-
- /**
- * create font attribute map, 创建属性map
- *
- * @param font 字体
- * @return map 返回字体创建的Map
- */
- public static Map createFontAttributeMap(Font font) {
- Map returnFontAttributeMap = (Map) fontAttributeMapCache.get(font);
- if (returnFontAttributeMap == null) {// create
- // returnFontAttributeMap.
- returnFontAttributeMap = font.getAttributes();
- fontAttributeMapCache.put(font, returnFontAttributeMap);
- }
-
- if (font instanceof FRFont) {
- FRFont frFont = (FRFont) font;
-
- // Strikethrough
- if (frFont.isStrikethrough()) {
- returnFontAttributeMap.put(TextAttribute.STRIKETHROUGH, TextAttribute.STRIKETHROUGH_ON);
- }
- }
-
- return returnFontAttributeMap;
- }
-
-}
diff --git a/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java b/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java
deleted file mode 100644
index 811d39af5e..0000000000
--- a/designer-realize/src/main/java/com/fr/design/fit/AdaptiveCellElementPainter.java
+++ /dev/null
@@ -1,27 +0,0 @@
-package com.fr.design.fit;
-
-
-import com.fr.design.file.HistoryTemplateListCache;
-import com.fr.design.fit.common.PaintUtils;
-import com.fr.design.mainframe.JForm;
-import com.fr.grid.CellElementPainter;
-import com.fr.report.cell.TemplateCellElement;
-import com.fr.report.elementcase.ElementCase;
-
-import java.awt.Graphics2D;
-
-/**
- * Created by kerry on 2020-04-21
- */
-public class AdaptiveCellElementPainter extends CellElementPainter {
-
- public void paintContent(Graphics2D g2d, ElementCase report, TemplateCellElement ce, int width, int height, int resolution) {
- if (HistoryTemplateListCache.getInstance().getCurrentEditingTemplate() instanceof JForm) {
- PaintUtils.paintGridCellContent(g2d, ce, width, height, resolution);
- }else {
- super.paintContent(g2d, report, ce, width, height, resolution);
- }
- }
-
-
-}
diff --git a/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java b/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java
new file mode 100644
index 0000000000..4f1e883674
--- /dev/null
+++ b/designer-realize/src/main/java/com/fr/design/fit/NewUIModeCellElementPainter.java
@@ -0,0 +1,21 @@
+package com.fr.design.fit;
+
+import com.fr.design.fit.common.NewUIModeRotationDraw;
+import com.fr.grid.CellElementPainter;
+import com.fr.report.cell.TemplateCellElement;
+import com.fr.report.core.PaintUtils;
+import com.fr.report.elementcase.ElementCase;
+
+import java.awt.Graphics2D;
+
+/**
+ * Created by kerry on 2020-04-21
+ */
+public class NewUIModeCellElementPainter extends CellElementPainter {
+
+ public void paintContent(Graphics2D g2d, ElementCase report, TemplateCellElement ce, int width, int height, int resolution) {
+ PaintUtils.paintGridCellContent(g2d, ce, width, height, resolution, new NewUIModeRotationDraw());
+ }
+
+
+}
diff --git a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java
index 750422bc38..5961700e26 100644
--- a/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java
+++ b/designer-realize/src/main/java/com/fr/design/mainframe/form/FormElementCasePaneDelegate.java
@@ -9,6 +9,7 @@ import com.fr.design.actions.form.FormECFrozenAction;
import com.fr.design.designer.creator.XElementCase;
import com.fr.design.event.TargetModifiedEvent;
import com.fr.design.event.TargetModifiedListener;
+import com.fr.design.fit.NewUIModeCellElementPainter;
import com.fr.design.fit.common.FormDesignerUtil;
import com.fr.design.gui.frpane.HyperlinkGroupPane;
import com.fr.design.mainframe.*;
@@ -18,6 +19,7 @@ import com.fr.design.menu.MenuDef;
import com.fr.design.menu.ShortCut;
import com.fr.design.menu.ToolBarDef;
import com.fr.design.present.ConditionAttributesGroupPane;
+import com.fr.form.fit.common.LightTool;
import com.fr.form.main.Form;
import com.fr.grid.Grid;
import com.fr.grid.GridColumn;
@@ -44,7 +46,9 @@ public class FormElementCasePaneDelegate extends ElementCasePane