处理模型图因为textBlockFinal错误导致的形状文本位置不对错误
This commit is contained in:
parent
f32acebef0
commit
d86a1facb0
Binary file not shown.
@ -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<String, Map<String, PALMethodAttributeModel>> shapeAttrMap = new HashMap<>();
|
||||
Iterator<String> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user