diff --git a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar index e90552df..30ef87e0 100644 Binary files a/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar and b/com.actionsoft.apps.coe.pal/lib/com.actionsoft.apps.coe.pal.jar differ diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java index 1117ac09..bfe2c4ce 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/CoeDesignerShapeAPIManager.java @@ -41,10 +41,12 @@ import com.actionsoft.apps.coe.pal.pal.repository.designer.relation.model.Design import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; import com.google.common.collect.Lists; import org.apache.commons.lang.StringUtils; +import org.mozilla.javascript.Context; +import org.mozilla.javascript.Scriptable; public class CoeDesignerShapeAPIManager { - private static class Inner { + private static class Inner { private final static CoeDesignerShapeAPIManager instance = new CoeDesignerShapeAPIManager(); } @@ -1223,4 +1225,77 @@ public class CoeDesignerShapeAPIManager { return definition.toString(); } + /** + * 处理文本区域相对位置&大小问题 + * @param define + * @return + */ + public String updateTextBlock(String define) { + JSONObject definition = JSONObject.parseObject(define); + JSONObject elements = definition.getJSONObject("elements"); + Map> shapeAttrMap = new HashMap<>(); + Iterator it = elements.keySet().iterator(); + + while (it.hasNext()) { + String shapeId = it.next(); + JSONObject shape = elements.getJSONObject(shapeId); + String shapeName = shape.getString("name"); + if (!"linker".equals(shapeName)) { + // 替换textblock + JSONObject props = shape.getJSONObject("props"); + if (props != null) { + int w = props.getInteger("w"); + int h = props.getInteger("h"); + if (shape.containsKey("textBlock")) { + JSONObject textBlock = JSONObject.parseObject(shape.getString("textBlock")); + JSONObject textBlockFinal = new JSONObject(); + String textBlockX = textBlock.getString("x").replace("w", w + "").replace("h", h + "").replace("Mat" + h, "Math"); + String textBlockY = textBlock.getString("y").replace("w", w + "").replace("h", h + "").replace("Mat" + h, "Math"); + String textBlockW = textBlock.getString("w").replace("w", w + "").replace("h", h + "").replace("Mat" + h, "Math"); + String textBlockH = textBlock.getString("h").replace("w", w + "").replace("h", h + "").replace("Mat" + h, "Math"); + if (textBlockX.equals("0")) { + textBlockX = "0.0"; + } + if (textBlockY.equals("0")) { + textBlockY = "0.0"; + } + if (textBlockW.equals("0")) { + textBlockW = "0.0"; + } + if (textBlockH.equals("0")) { + textBlockH = "0.0"; + } + textBlockFinal.put("x", Double.parseDouble(runJs(textBlockX).toString())); + textBlockFinal.put("y", Double.parseDouble(runJs(textBlockY).toString())); + textBlockFinal.put("w", Double.parseDouble(runJs(textBlockW).toString())); + textBlockFinal.put("h", Double.parseDouble(runJs(textBlockH).toString())); + shape.put("textBlock", textBlock); + shape.put("textBlockFinal", textBlockFinal); + } + } + elements.put(shapeId, shape); + } + } + return definition.toString(); + } + + /** + * 转换为js + * + * @param val + * @return string + */ + private static String runJs(String val) { + String jsVal = ""; + try { + Context cx = Context.enter(); + Scriptable scope = cx.initStandardObjects(); + Object result = cx.evaluateString(scope, val, null, 1, null); + jsVal = Context.toString(result); + } finally { + Context.exit(); + } + return jsVal; + } + } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/io/image/CoeDesignerImage.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/io/image/CoeDesignerImage.java index 307875d0..50e65b12 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/io/image/CoeDesignerImage.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/pal/repository/designer/io/image/CoeDesignerImage.java @@ -37,6 +37,7 @@ public class CoeDesignerImage { if (bigImage) { // 处理连线箭头问题 String define = CoeDesignerShapeAPIManager.getInstance().updateLinkArrow(model.getDefinition()); + define = CoeDesignerShapeAPIManager.getInstance().updateTextBlock(define); String pathname =model.getPath()+model.getUUID()+".png"; byte[] desginerImg = null; try {