【新增】 pptx部分考点

This commit is contained in:
dlaren
2025-08-14 23:13:08 +08:00
parent c40f4a5f1a
commit 7deb304642
2 changed files with 114 additions and 0 deletions

View File

@@ -2,6 +2,9 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
import org.docx4j.dml.*;
import java.math.BigInteger;
import java.text.DecimalFormat;
public class Shape {
// 大小 - 高度
@@ -244,4 +247,89 @@ public class Shape {
}
// 形状效果 阴影-绘制
public static String getShapeShadowDraw(org.pptx4j.pml.Shape sp) {
CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst();
if (effList == null) {
return "";
}
// 判断三种阴影效果
return effList.getOuterShdw() != null
|| effList.getInnerShdw() != null
|| effList.getPrstShdw() != null ? "" : "";
}
// 形状效果 阴影-效果
public static String getShapeShadowEffect(org.pptx4j.pml.Shape sp) {
if (sp == null || sp.getSpPr() == null) {
return "无阴影";
}
CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst();
if (effList == null) {
return "无阴影";
}
if (effList.getOuterShdw() != null) {
return "外阴影";
} else if (effList.getInnerShdw() != null) {
return "内阴影";
} else if (effList.getPrstShdw() != null) {
return "预设阴影";
}
return "无阴影";
}
// 形状效果 倒影-绘制
public static String getShapeReflectionDraw(org.pptx4j.pml.Shape sp) {
CTShapeProperties spPr = sp.getSpPr();
CTEffectList effList = spPr.getEffectLst();
if (effList == null) {
return "无倒影";
}
CTReflectionEffect reflection = effList.getReflection();
if (reflection != null) {
// 如果需要详细参数,这里可以读取
return "有倒影";
}
return "无倒影";
}
// 形状效果 倒影-效果
public static String getShapeReflectionEffect(org.pptx4j.pml.Shape sp) {
CTReflectionEffect r = SlideUtils.getReflection(sp);
if (r == null) return "无倒影";
// —— 1) 倒影覆盖程度:用 stPos/endPos0..100000)估算 —— //
double st = SlideUtils.to100k(BigInteger.valueOf(r.getStPos()), 0);
double ed = SlideUtils.to100k(BigInteger.valueOf(r.getEndPos()), 100000); // 默认 100%
double coverage = Math.max(0, ed - st) / 100000.0; // 0.0 ~ 1.0
String coverageLabel;
if (coverage >= 0.85) {
coverageLabel = "全倒影";
} else if (coverage >= 0.45) {
coverageLabel = "半倒影";
} else {
coverageLabel = "短倒影";
}
// —— 2) 偏移描述dist EMU -> pt<1pt 视作“紧贴”,否则 "Xpt 偏移" —— //
double distPt = emuToPt(r.getDist()); // 可能为 0
String offsetLabel = distPt < 1.0 ? "紧贴" : (SlideUtils.fmt1(distPt) + "pt 偏移");
return coverageLabel + " " + offsetLabel;
}
// 形状效果 发光
public static String getShapeGlow(org.pptx4j.pml.Shape sp) {
if (sp == null || sp.getSpPr() == null) return null;
CTShapeProperties spPr = sp.getSpPr();
CTEffectList eff = spPr.getEffectLst();
return (eff != null) ? eff.getGlow().toString() : null;
}
}

View File

@@ -3,6 +3,9 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
import org.docx4j.dml.*;
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
import java.math.BigInteger;
import java.text.DecimalFormat;
public class SlideUtils {
public static String getFillType(CTShapeProperties spPr) {
if (spPr == null) return "未知";
@@ -110,4 +113,27 @@ public class SlideUtils {
}
}
/* ——— 内部:拿到 spPr/effectLst/reflection ——— */
public static CTReflectionEffect getReflection(org.pptx4j.pml.Shape shape) {
if (shape == null || shape.getSpPr() == null) return null;
CTShapeProperties spPr = shape.getSpPr();
CTEffectList eff = spPr.getEffectLst();
return (eff != null) ? eff.getReflection() : null;
// 如遇到效果写在 effectDag可再补充从 spPr.getEffectDag() 解析。
}
/* ——— 工具 ——— */
public static double emuToPt(BigInteger emu) {
if (emu == null) return 0.0;
return emu.doubleValue() / 12700.0; // 1 pt = 12700 EMU
}
public static double to100k(BigInteger v, int def) {
return v == null ? def : v.doubleValue();
}
public static String fmt1(double d) {
return new DecimalFormat("#.##").format(d); // 保留 1~2 位,去掉多余 0
}
}