【修改】 针对 动画 进行优化,使其兼容性提高

This commit is contained in:
dlaren
2025-09-01 17:05:17 +08:00
parent 91d8018d39
commit 4906764628
7 changed files with 345 additions and 42 deletions

View File

@@ -5,6 +5,8 @@ import jakarta.xml.bind.JAXBException;
import org.docx4j.dml.*; import org.docx4j.dml.*;
import org.docx4j.jaxb.XPathBinderAssociationIsPartialException; import org.docx4j.jaxb.XPathBinderAssociationIsPartialException;
import org.pptx4j.pml.*; import org.pptx4j.pml.*;
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils.PtToCmConverter;
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils.Transition;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
@@ -17,7 +19,11 @@ public class ShapePage {
// 获取位置和尺寸(单位 EMU1英寸=914400 EMU1cm≈360000 EMU // 获取位置和尺寸(单位 EMU1英寸=914400 EMU1cm≈360000 EMU
CTPositiveSize2D ext = xfrm.getExt(); // 尺寸 CTPositiveSize2D ext = xfrm.getExt(); // 尺寸
double heightPt = emuToPt(ext.getCy()); double heightPt = emuToPt(ext.getCy());
return String.valueOf(heightPt); // 转换成磅
double pt = Math.round(heightPt * 100.0) / 100.0;
// 转换成厘米
double cm = PtToCmConverter.pointsToCm(pt);
return pt + "磅(" + cm + "厘米)";
} }
// 大小 - 宽度 // 大小 - 宽度
@@ -26,7 +32,11 @@ public class ShapePage {
// 获取位置和尺寸(单位 EMU1英寸=914400 EMU1cm≈360000 EMU // 获取位置和尺寸(单位 EMU1英寸=914400 EMU1cm≈360000 EMU
CTPositiveSize2D ext = xfrm.getExt(); // 尺寸 CTPositiveSize2D ext = xfrm.getExt(); // 尺寸
double widthPt = emuToPt(ext.getCx()); double widthPt = emuToPt(ext.getCx());
return String.valueOf(widthPt); // 转换成磅
double pt = Math.round(widthPt * 100.0) / 100.0;
// 转换成厘米
double cm = PtToCmConverter.pointsToCm(pt);
return pt + "磅(" + cm + "厘米)";
} }
// 大小 - 锁定纵横比 // 大小 - 锁定纵横比
@@ -313,12 +323,12 @@ public class ShapePage {
// 形状效果 阴影-效果 // 形状效果 阴影-效果
public static String getShapeShadowEffect(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { public static String getShapeShadowEffect(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp == null || sp.getSpPr() == null) { if (sp == null || sp.getSpPr() == null) {
return "无阴影"; return "";
} }
CTShapeProperties spPr = sp.getSpPr(); CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst(); CTEffectList effList = spPr.getEffectLst();
if (effList == null) { if (effList == null) {
return "无阴影"; return "";
} }
if (effList.getOuterShdw() != null) { if (effList.getOuterShdw() != null) {
@@ -328,7 +338,7 @@ public class ShapePage {
} else if (effList.getPrstShdw() != null) { } else if (effList.getPrstShdw() != null) {
return "预设阴影"; return "预设阴影";
} }
return "无阴影"; return "";
} }
// 形状效果 倒影-绘制 // 形状效果 倒影-绘制
@@ -336,21 +346,21 @@ public class ShapePage {
CTShapeProperties spPr = sp.getSpPr(); CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst(); CTEffectList effList = spPr.getEffectLst();
if (effList == null) { if (effList == null) {
return "无倒影"; return "";
} }
CTReflectionEffect reflection = effList.getReflection(); CTReflectionEffect reflection = effList.getReflection();
if (reflection != null) { if (reflection != null) {
// 如果需要详细参数,这里可以读取 // 如果需要详细参数,这里可以读取
return "有倒影"; return "";
} }
return "无倒影"; return "";
} }
// 形状效果 倒影-效果 // 形状效果 倒影-效果
public static String getShapeReflectionEffect(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { public static String getShapeReflectionEffect(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTReflectionEffect r = SlideUtils.getReflection(sp); CTReflectionEffect r = SlideUtils.getReflection(sp);
if (r == null) return "无倒影"; if (r == null) return "";
// —— 1) 倒影覆盖程度:用 stPos/endPos0..100000)估算 —— // // —— 1) 倒影覆盖程度:用 stPos/endPos0..100000)估算 —— //
double st = SlideUtils.to100k(BigInteger.valueOf(r.getStPos()), 0); double st = SlideUtils.to100k(BigInteger.valueOf(r.getStPos()), 0);
@@ -363,12 +373,12 @@ public class ShapePage {
} else if (coverage >= 0.45) { } else if (coverage >= 0.45) {
coverageLabel = "半倒影"; coverageLabel = "半倒影";
} else { } else {
coverageLabel = "倒影"; coverageLabel = "紧密倒影";
} }
// —— 2) 偏移描述dist EMU -> pt<1pt 视作“紧贴”,否则 "Xpt 偏移" —— // // —— 2) 偏移描述dist EMU -> pt<1pt 视作“接触”,否则 "Xpt 偏移" —— //
double distPt = emuToPt(r.getDist()); // 可能为 0 double distPt = emuToPt(r.getDist()); // 可能为 0
String offsetLabel = distPt < 1.0 ? "紧贴" : (SlideUtils.fmt1(distPt) + "pt 偏移"); String offsetLabel = distPt < 1.0 ? "接触" : (SlideUtils.fmt1(distPt) + "pt 偏移");
return coverageLabel + " " + offsetLabel; return coverageLabel + " " + offsetLabel;
} }
@@ -432,19 +442,47 @@ public class ShapePage {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "type"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "type");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; String type = value.split("-")[0];
// 动画类别
String presetClass = value.split("-")[1];
String presetClassCn = Transition.presetClass(presetClass);
// 动画效果
String presetID = value.split("-")[2];
return presetClassCn + "->" + presetID;
} }
return ""; return "";
} }
public static String getAniationInfo(List<Object> objects, List<Object> upObjects, String spId, String parameter) { public static String getAniationInfo(List<Object> objects, List<Object> upObjects, String spId, String parameter) {
boolean isDur = false;
boolean isDirection = false;
for (Object object : objects) { for (Object object : objects) {
// 判断持续时间
if (isDur) {
if (object instanceof CTTLAnimateEffectBehavior) {
return ((CTTLAnimateEffectBehavior) object).getCBhvr().getCTn().getDur();
}
}
// 判断方向
if (isDirection) {
if (object instanceof CTTLAnimateEffectBehavior) {
return ((CTTLAnimateEffectBehavior) object).getFilter();
}
}
if (object instanceof CTTLSetBehavior) { if (object instanceof CTTLSetBehavior) {
String spIds = ((CTTLSetBehavior) object).getCBhvr().getTgtEl().getSpTgt().getSpid(); String spIds = ((CTTLSetBehavior) object).getCBhvr().getTgtEl().getSpTgt().getSpid();
// 判断ID是否一致 // 判断ID是否一致
if (spIds.equals(spId)) { if (spIds.equals(spId)) {
// 持续时间 // 持续时间
if (parameter.equals("dur")) { if (parameter.equals("dur")) {
return ((CTTLSetBehavior) object).getCBhvr().getCTn().getDur(); isDur = true;
String dur = ((CTTLSetBehavior) object).getCBhvr().getCTn().getDur();
if (dur != null) {
return dur;
}
}
if (parameter.equals("direction")) {
isDirection = true;
} }
// 向上获取延迟 // 向上获取延迟
for (Object upObject : upObjects) { for (Object upObject : upObjects) {
@@ -452,10 +490,13 @@ public class ShapePage {
// 获取动画效果 // 获取动画效果
if (parameter.equals("type")) { if (parameter.equals("type")) {
Integer type = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetSubtype(); Integer type = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetSubtype();
return String.valueOf(type); String presetClass = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetClass().value();
Integer presetID = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetID();
return type + "-" + presetClass + "-" + presetID;
} }
// 触发方式 // 触发方式
if (parameter.equals("function")) { if (parameter.equals("function")) {
String CTTLTimeNodeParallelFunction = ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value();
return ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value(); return ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value();
} }
// 获取延迟方法 // 获取延迟方法
@@ -468,9 +509,28 @@ public class ShapePage {
} }
} }
} }
if (upObject instanceof CTTLCommonTimeNodeData) {
// 获取动画效果
if (parameter.equals("type")) {
Integer type = ((CTTLCommonTimeNodeData) upObject).getPresetSubtype();
String presetClass = ((CTTLCommonTimeNodeData) upObject).getPresetClass().value();
Integer presetID = ((CTTLCommonTimeNodeData) upObject).getPresetID();
return type + "-" + presetClass + "-" + presetID;
}
}
} }
} }
} }
// 特殊取值的情况
if (object instanceof CTTLCommonTimeNodeData) {
// 获取动画效果
if (parameter.equals("type")) {
Integer type = ((CTTLCommonTimeNodeData) object).getPresetSubtype();
String presetClass = ((CTTLCommonTimeNodeData) object).getPresetClass().value();
Integer presetID = ((CTTLCommonTimeNodeData) object).getPresetID();
return type + "-" + presetClass + "-" + presetID;
}
}
if (object instanceof CTTLTimeNodeParallel obj) { if (object instanceof CTTLTimeNodeParallel obj) {
String result = getAniationInfo(obj.getCTn().getChildTnLst().getParOrSeqOrExcl(), objects, spId, parameter); String result = getAniationInfo(obj.getCTn().getChildTnLst().getParOrSeqOrExcl(), objects, spId, parameter);
if (!result.isEmpty()) { if (!result.isEmpty()) {
@@ -490,7 +550,16 @@ public class ShapePage {
// 动画-方向 // 动画-方向
public static String getAnimateDirection(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { public static String getAnimateDirection(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发"; long spId = sp.getNvSpPr().getCNvPr().getId();
CTTimeNodeList ctTimeNodeList = timing.getTnLst();
if (ctTimeNodeList == null) return "无动画";
// 第一层
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "direction");
if (!value.isEmpty()) {
return value;
}
return "";
} }
// 动画 触发方式 // 动画 触发方式
@@ -502,7 +571,7 @@ public class ShapePage {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "function"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "function");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Transition.toCn(value);
} }
return ""; return "";
} }
@@ -516,7 +585,7 @@ public class ShapePage {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "dur"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "dur");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Integer.parseInt(value) / 1000 + "";
} }
return ""; return "";
} }
@@ -530,7 +599,7 @@ public class ShapePage {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "delay"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "delay");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Integer.parseInt(value) / 1000 + "";
} }
return ""; return "";
} }
@@ -1220,7 +1289,10 @@ public class ShapePage {
// 文字效果 发光→绘制 // 文字效果 发光→绘制
public static String getTextBoxParagraphGlowDraw(org.pptx4j.pml.Shape sp, CTSlideTiming timing) { public static String getTextBoxParagraphGlowDraw(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发"; if (sp == null || sp.getSpPr() == null) return null;
CTShapeProperties spPr = sp.getSpPr();
CTEffectList eff = spPr.getEffectLst();
return (eff != null) ? "" : "";
} }
// 文字效果 发光→效果 // 文字效果 发光→效果

View File

@@ -3,6 +3,7 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
import jakarta.xml.bind.JAXBElement; import jakarta.xml.bind.JAXBElement;
import org.docx4j.dml.*; import org.docx4j.dml.*;
import org.pptx4j.pml.*; import org.pptx4j.pml.*;
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils.Transition;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.List; import java.util.List;
@@ -302,12 +303,12 @@ public class ShapePic {
// 形状效果 阴影-效果 // 形状效果 阴影-效果
public static String getShapeShadowEffect(Pic sp, CTSlideTiming timing) { public static String getShapeShadowEffect(Pic sp, CTSlideTiming timing) {
if (sp == null || sp.getSpPr() == null) { if (sp == null || sp.getSpPr() == null) {
return "无阴影"; return "";
} }
CTShapeProperties spPr = sp.getSpPr(); CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst(); CTEffectList effList = spPr.getEffectLst();
if (effList == null) { if (effList == null) {
return "无阴影"; return "";
} }
if (effList.getOuterShdw() != null) { if (effList.getOuterShdw() != null) {
@@ -317,7 +318,7 @@ public class ShapePic {
} else if (effList.getPrstShdw() != null) { } else if (effList.getPrstShdw() != null) {
return "预设阴影"; return "预设阴影";
} }
return "无阴影"; return "";
} }
// 形状效果 倒影-绘制 // 形状效果 倒影-绘制
@@ -325,21 +326,21 @@ public class ShapePic {
CTShapeProperties spPr = sp.getSpPr(); CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst(); CTEffectList effList = spPr.getEffectLst();
if (effList == null) { if (effList == null) {
return "无倒影"; return "";
} }
CTReflectionEffect reflection = effList.getReflection(); CTReflectionEffect reflection = effList.getReflection();
if (reflection != null) { if (reflection != null) {
// 如果需要详细参数,这里可以读取 // 如果需要详细参数,这里可以读取
return "有倒影"; return "";
} }
return "无倒影"; return "";
} }
// 形状效果 倒影-效果 // 形状效果 倒影-效果
public static String getShapeReflectionEffect(Pic sp, CTSlideTiming timing) { public static String getShapeReflectionEffect(Pic sp, CTSlideTiming timing) {
CTReflectionEffect r = SlideUtils.getReflectionPic(sp); CTReflectionEffect r = SlideUtils.getReflectionPic(sp);
if (r == null) return "无倒影"; if (r == null) return "";
// —— 1) 倒影覆盖程度:用 stPos/endPos0..100000)估算 —— // // —— 1) 倒影覆盖程度:用 stPos/endPos0..100000)估算 —— //
double st = SlideUtils.to100k(BigInteger.valueOf(r.getStPos()), 0); double st = SlideUtils.to100k(BigInteger.valueOf(r.getStPos()), 0);
@@ -367,7 +368,7 @@ public class ShapePic {
if (sp == null || sp.getSpPr() == null) return null; if (sp == null || sp.getSpPr() == null) return null;
CTShapeProperties spPr = sp.getSpPr(); CTShapeProperties spPr = sp.getSpPr();
CTEffectList eff = spPr.getEffectLst(); CTEffectList eff = spPr.getEffectLst();
return (eff != null) ? eff.getGlow().toString() : null; return (eff != null) ? "" : "";
} }
// 形状效果 发光-效果 // 形状效果 发光-效果
@@ -418,19 +419,47 @@ public class ShapePic {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "type"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "type");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; String type = value.split("-")[0];
// 动画类别
String presetClass = value.split("-")[1];
String presetClassCn = Transition.presetClass(presetClass);
// 动画效果
String presetID = value.split("-")[2];
return presetClassCn + "->" + presetID;
} }
return ""; return "";
} }
public static String getAniationInfo(List<Object> objects, List<Object> upObjects, String spId, String parameter) { public static String getAniationInfo(List<Object> objects, List<Object> upObjects, String spId, String parameter) {
boolean isDur = false;
boolean isDirection = false;
for (Object object : objects) { for (Object object : objects) {
// 判断持续时间
if (isDur) {
if (object instanceof CTTLAnimateEffectBehavior) {
return ((CTTLAnimateEffectBehavior) object).getCBhvr().getCTn().getDur();
}
}
// 判断方向
if (isDirection) {
if (object instanceof CTTLAnimateEffectBehavior) {
return ((CTTLAnimateEffectBehavior) object).getFilter();
}
}
if (object instanceof CTTLSetBehavior) { if (object instanceof CTTLSetBehavior) {
String spIds = ((CTTLSetBehavior) object).getCBhvr().getTgtEl().getSpTgt().getSpid(); String spIds = ((CTTLSetBehavior) object).getCBhvr().getTgtEl().getSpTgt().getSpid();
// 判断ID是否一致 // 判断ID是否一致
if (spIds.equals(spId)) { if (spIds.equals(spId)) {
// 持续时间 // 持续时间
if (parameter.equals("dur")) { if (parameter.equals("dur")) {
return ((CTTLSetBehavior) object).getCBhvr().getCTn().getDur(); isDur = true;
String dur = ((CTTLSetBehavior) object).getCBhvr().getCTn().getDur();
if (dur != null) {
return dur;
}
}
if (parameter.equals("direction")) {
isDirection = true;
} }
// 向上获取延迟 // 向上获取延迟
for (Object upObject : upObjects) { for (Object upObject : upObjects) {
@@ -438,10 +467,13 @@ public class ShapePic {
// 获取动画效果 // 获取动画效果
if (parameter.equals("type")) { if (parameter.equals("type")) {
Integer type = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetSubtype(); Integer type = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetSubtype();
return String.valueOf(type); String presetClass = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetClass().value();
Integer presetID = ((CTTLTimeNodeParallel) upObject).getCTn().getPresetID();
return type + "-" + presetClass + "-" + presetID;
} }
// 触发方式 // 触发方式
if (parameter.equals("function")) { if (parameter.equals("function")) {
String CTTLTimeNodeParallelFunction = ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value();
return ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value(); return ((CTTLTimeNodeParallel) upObject).getCTn().getNodeType().value();
} }
// 获取延迟方法 // 获取延迟方法
@@ -454,9 +486,28 @@ public class ShapePic {
} }
} }
} }
if (upObject instanceof CTTLCommonTimeNodeData) {
// 获取动画效果
if (parameter.equals("type")) {
Integer type = ((CTTLCommonTimeNodeData) upObject).getPresetSubtype();
String presetClass = ((CTTLCommonTimeNodeData) upObject).getPresetClass().value();
Integer presetID = ((CTTLCommonTimeNodeData) upObject).getPresetID();
return type + "-" + presetClass + "-" + presetID;
}
}
} }
} }
} }
// 特殊取值的情况
if (object instanceof CTTLCommonTimeNodeData) {
// 获取动画效果
if (parameter.equals("type")) {
Integer type = ((CTTLCommonTimeNodeData) object).getPresetSubtype();
String presetClass = ((CTTLCommonTimeNodeData) object).getPresetClass().value();
Integer presetID = ((CTTLCommonTimeNodeData) object).getPresetID();
return type + "-" + presetClass + "-" + presetID;
}
}
if (object instanceof CTTLTimeNodeParallel obj) { if (object instanceof CTTLTimeNodeParallel obj) {
String result = getAniationInfo(obj.getCTn().getChildTnLst().getParOrSeqOrExcl(), objects, spId, parameter); String result = getAniationInfo(obj.getCTn().getChildTnLst().getParOrSeqOrExcl(), objects, spId, parameter);
if (!result.isEmpty()) { if (!result.isEmpty()) {
@@ -476,7 +527,16 @@ public class ShapePic {
// 动画-方向 // 动画-方向
public static String getAnimateDirection(org.pptx4j.pml.Pic sp, CTSlideTiming timing) { public static String getAnimateDirection(org.pptx4j.pml.Pic sp, CTSlideTiming timing) {
return "待开发"; long spId = sp.getNvPicPr().getCNvPr().getId();
CTTimeNodeList ctTimeNodeList = timing.getTnLst();
if (ctTimeNodeList == null) return "无动画";
// 第一层
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "direction");
if (!value.isEmpty()) {
return value;
}
return "";
} }
// 动画 触发方式 // 动画 触发方式
@@ -488,7 +548,7 @@ public class ShapePic {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "function"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "function");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Transition.toCn(value);
} }
return ""; return "";
} }
@@ -502,7 +562,7 @@ public class ShapePic {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "dur"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "dur");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Integer.parseInt(value) / 1000 + "";
} }
return ""; return "";
} }
@@ -516,7 +576,7 @@ public class ShapePic {
List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl(); List<Object> parOrSeqOrExcl = ctTimeNodeList.getParOrSeqOrExcl();
String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "delay"); String value = getAniationInfo(parOrSeqOrExcl, null, String.valueOf(spId), "delay");
if (!value.isEmpty()) { if (!value.isEmpty()) {
return value; return Integer.parseInt(value) / 1000 + "";
} }
return ""; return "";
} }

View File

@@ -33,27 +33,27 @@ public class SlideConversion {
List<SlidePart> slideParts = ppt.getMainPresentationPart().getSlideParts(); List<SlidePart> slideParts = ppt.getMainPresentationPart().getSlideParts();
int slideIndexFoFile = 0; int slideIndexFoFile = 0;
String firstId = getStringRandom(); String firstId = getStringRandom();
setSlideDataInfo(firstId, "", "幻灯片", "slide", "", false, dataInfoVOS); setSlideDataInfo(firstId, "", "幻灯片", "slide", "", false, "", dataInfoVOS);
for (SlidePart slidePart : slideParts) { for (SlidePart slidePart : slideParts) {
slideIndexFoFile ++; slideIndexFoFile ++;
String secondId = getStringRandom(); String secondId = getStringRandom();
setSlideDataInfo(secondId, firstId, ""+slideIndexFoFile+"", "sld", String.valueOf(slideIndexFoFile), false, dataInfoVOS); setSlideDataInfo(secondId, firstId, ""+slideIndexFoFile+"", "sld", String.valueOf(slideIndexFoFile), false, "", dataInfoVOS);
// 获取形状 // 获取形状
GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree(); GroupShape spTree = slidePart.getJaxbElement().getCSld().getSpTree();
List<Object> shapes = spTree.getSpOrGrpSpOrGraphicFrame(); List<Object> shapes = spTree.getSpOrGrpSpOrGraphicFrame();
int slideIndexFoShape = 0; int slideIndexFoShape = 0;
// 第三层 // 第三层
String thirdId = getStringRandom(); String thirdId = getStringRandom();
setSlideDataInfo(thirdId, secondId, "幻灯片设置", "slideSetting", String.valueOf(slideIndexFoFile) + "_0", true, dataInfoVOS); setSlideDataInfo(thirdId, secondId, "幻灯片设置", "slideSetting", String.valueOf(slideIndexFoFile) + "_0", true, ""+slideIndexFoFile+"", dataInfoVOS);
for (Object shapeObj : shapes) { for (Object shapeObj : shapes) {
slideIndexFoShape ++; slideIndexFoShape ++;
// 形状 // 形状
String fourId = getStringRandom(); String fourId = getStringRandom();
if (shapeObj instanceof Shape) { if (shapeObj instanceof Shape) {
setSlideDataInfo(fourId, secondId, "形状"+slideIndexFoShape+"->"+((Shape) shapeObj).getNvSpPr().getCNvPr().getName(), "shape", String.valueOf(slideIndexFoFile) + "_" + String.valueOf(slideIndexFoShape), true, dataInfoVOS); setSlideDataInfo(fourId, secondId, "形状"+slideIndexFoShape+"->"+((Shape) shapeObj).getNvSpPr().getCNvPr().getName(), "shape", String.valueOf(slideIndexFoFile) + "_" + String.valueOf(slideIndexFoShape), true, ""+slideIndexFoFile+"", dataInfoVOS);
} }
if (shapeObj instanceof Pic) { if (shapeObj instanceof Pic) {
setSlideDataInfo(fourId, secondId, "形状"+slideIndexFoShape+"->"+((Pic) shapeObj).getNvPicPr().getCNvPr().getName(), "shape", String.valueOf(slideIndexFoFile) + "_" + String.valueOf(slideIndexFoShape), true, dataInfoVOS); setSlideDataInfo(fourId, secondId, "形状"+slideIndexFoShape+"->"+((Pic) shapeObj).getNvPicPr().getCNvPr().getName(), "shape", String.valueOf(slideIndexFoFile) + "_" + String.valueOf(slideIndexFoShape), true, ""+slideIndexFoFile+"", dataInfoVOS);
} }
@@ -81,7 +81,7 @@ public class SlideConversion {
// 想数组中添加数据 // 想数组中添加数据
public static void setSlideDataInfo(String id, String parentId, String text, public static void setSlideDataInfo(String id, String parentId, String text,
String type, String index, boolean isTrue, List<SlideDataInfoVO> dataInfoVOS) throws Exception { String type, String index, boolean isTrue, String belongToName, List<SlideDataInfoVO> dataInfoVOS) throws Exception {
SlideDataInfoVO dataInfo = new SlideDataInfoVO(); SlideDataInfoVO dataInfo = new SlideDataInfoVO();
dataInfo.setId(id); dataInfo.setId(id);
dataInfo.setParentId(parentId); dataInfo.setParentId(parentId);
@@ -89,6 +89,7 @@ public class SlideConversion {
dataInfo.setType(type); dataInfo.setType(type);
dataInfo.setIndex(index); dataInfo.setIndex(index);
dataInfo.setClick(isTrue); dataInfo.setClick(isTrue);
dataInfo.setBelongTo(belongToName);
dataInfoVOS.add(dataInfo); dataInfoVOS.add(dataInfo);
} }
} }

View File

@@ -12,6 +12,7 @@ import org.pptx4j.pml.CTBackgroundProperties;
import org.pptx4j.pml.CTSlideTiming; import org.pptx4j.pml.CTSlideTiming;
import org.pptx4j.pml.*; import org.pptx4j.pml.*;
import org.docx4j.dml.*; import org.docx4j.dml.*;
import pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils.Transition;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.List; import java.util.List;
@@ -92,7 +93,8 @@ public class SlideSetting {
CTSlideTransition ctSlideTransition = slide.getTransition(); CTSlideTransition ctSlideTransition = slide.getTransition();
CTTransitionSoundAction ctTransitionSoundAction = ctSlideTransition.getSndAc(); CTTransitionSoundAction ctTransitionSoundAction = ctSlideTransition.getSndAc();
if (ctTransitionSoundAction != null) { if (ctTransitionSoundAction != null) {
return ctTransitionSoundAction.getStSnd().getSnd().getName(); // 将获取的声音文件,进行转换成中文
return Transition.getCnName(ctTransitionSoundAction.getStSnd().getSnd().getName());
} }
return ""; return "";
} }

View File

@@ -0,0 +1,42 @@
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils;
public class PtToCmConverter {
// 基础转换常数
public static final double POINTS_PER_INCH = 72.0;
public static final double CM_PER_INCH = 2.54;
public static final double PT_TO_CM = CM_PER_INCH / POINTS_PER_INCH;
/**
* 将点(pt)转换为厘米(cm)
* @param points 点数
* @return 厘米数
*/
public static double pointsToCm(double points) {
return points * PT_TO_CM;
}
/**
* 将厘米(cm)转换为点(pt)
* @param cm 厘米数
* @return 点数
*/
public static double cmToPoints(double cm) {
return cm / PT_TO_CM;
}
public static void main(String[] args) {
// 示例转换
double points = 10.0;
double cm = pointsToCm(points);
System.out.println(points + " pt = " + cm + " cm");
System.out.println("反向转换: " + cm + " cm = " + cmToPoints(cm) + " pt");
// 常见值的转换示例
System.out.println("\n常见值转换:");
System.out.println("8 pt = " + pointsToCm(8) + " cm");
System.out.println("12 pt = " + pointsToCm(12) + " cm");
System.out.println("72 pt = " + pointsToCm(72) + " cm (1 inch)");
}
}

View File

@@ -0,0 +1,124 @@
package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j.utils;
public class Transition {
public static String getCnName(String fileName) {
if (fileName == null) return "未知";
switch (fileName.toLowerCase()) {
case "wind.wav":
return "风声 / 微风";
case "applause.wav":
return "掌声";
case "breeze.wav":
return "清风 / 微风拂过";
case "whoosh.wav":
case "swoosh.wav":
return "呼啸 / 划过";
case "chime.wav":
return "叮当 / 玲声";
case "camera.wav":
return "相机快门";
case "cashregister.wav":
return "收银机";
case "typewriter.wav":
return "打字机";
case "laser.wav":
return "激光";
case "explosion.wav":
case "explode.wav":
return "爆炸";
case "drumroll.wav":
return "擂鼓 / 滚奏";
case "click.wav":
return "点击";
case "coin.wav":
return "硬币";
case "bomb.wav":
return "炸弹";
case "scream.wav":
return "尖叫";
case "arrow.wav":
return "箭矢";
case "push.wav":
return "推入声";
case "hammer.wav":
return "锤击";
case "tada.wav":
return "哒哒 / 庆祝";
case "horn.wav":
case "carhorn.wav":
return "喇叭 / 汽车喇叭";
case "doorbell.wav":
return "门铃";
case "ding.wav":
return "";
case "gong.wav":
return "";
case "beep.wav":
return "嘟声";
case "notify.wav":
return "提示音";
case "pop.wav":
return "啪嗒 / 弹出";
case "zip.wav":
case "zipper.wav":
return "拉链 / 嗖";
case "sparkle.wav":
return "闪光";
case "rattle.wav":
return "哗啦";
case "thunder.wav":
return "雷鸣";
case "bell.wav":
return "铃声";
case "ring.wav":
return "电话铃";
case "whistle.wav":
return "口哨";
default:
return "未知";
}
}
public static String toCn(String trigger) {
if (trigger == null) return "";
switch (trigger == null ? "" : trigger.trim().toLowerCase()) {
case "onclick":
case "clickeffect": return "单击时";
case "witheffect":
case "onbegin": return "与上一动画同时";
case "aftereffect":
case "onend": return "上一动画之后";
case "onnext": return "下一次单击";
case "onprev": return "上一次单击";
case "onload": return "幻灯片载入时";
case "onmouseover": return "鼠标移入时";
case "onmouseout": return "鼠标移出时";
case "ondblclick": return "双击时";
case "onstopaudio": return "音频停止时";
case "onbeginaudio":
case "onplay": return "音频开始时";
case "onendaudio": return "音频结束时";
case "onbookmark": return "书签到达时";
case "onresume": return "恢复播放时";
case "onpause": return "暂停时";
case "onstop": return "停止时";
default: return trigger; // 或者返回 "(未知触发)"
}
}
public static String presetClass(String trigger) {
if (trigger == null) return "";
switch (trigger.trim().toLowerCase()) {
case "entr": return "进入";
case "exit": return "退出";
case "emph": return "强调";
case "path": return "动作路径";
default: return "";
}
}
}

View File

@@ -15,5 +15,7 @@ public class SlideDataInfoVO {
private String index; private String index;
private String belongTo;
private boolean isClick; private boolean isClick;
} }