【新增】 优化PPT形状考点

This commit is contained in:
dlaren
2025-09-10 00:59:00 +08:00
parent d46347914b
commit da0338111a
2 changed files with 80 additions and 24 deletions

View File

@@ -16,6 +16,24 @@ import java.util.regex.Pattern;
public class ShapePage {
// 页眉页脚 文本
public static String getShapeHeaderFooterText(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTextBody ctTextBody = sp.getTxBody();
String text = "";
if (ctTextBody != null) {
List<CTTextParagraph> pList = ctTextBody.getP();
for (CTTextParagraph p : pList) {
List<Object> objectList = p.getEGTextRun();
for (Object o : objectList) {
if (o instanceof CTRegularTextRun) {
text += ((CTRegularTextRun) o).getT() + " ";
}
}
}
}
return text;
}
// 大小 - 高度
public static String getShapeSizeHeight(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTransform2D xfrm = sp.getSpPr().getXfrm();
@@ -161,7 +179,12 @@ public class ShapePage {
// 形状填充 填充透明度
public static String getShapeFillOpacity(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
CTShapeProperties ctShapeProperties = sp.getSpPr();
if (ctShapeProperties.getSolidFill() != null) {
CTPositiveFixedPercentage ctPositiveFixedPercentage = (CTPositiveFixedPercentage) ctShapeProperties.getSolidFill().getPrstClr().getEGColorTransform().get(0).getValue();
return (100 - (ctPositiveFixedPercentage.getVal() / 1000)) + "%";
}
return "";
}
// 形状线条 绘制
@@ -174,7 +197,7 @@ public class ShapePage {
// 宽度EMU -> pt
double widthPt = ln.getW() / 12700.0;
System.out.println("形状: " + sp.getNvSpPr().getCNvPr().getName());
System.out.println("线宽: " + widthPt + " pt");
System.out.println("线宽: " + widthPt + "");
// 颜色
if (ln.getSolidFill() != null && ln.getSolidFill().getSrgbClr() != null) {
@@ -203,9 +226,19 @@ public class ShapePage {
if (spPr != null && spPr.getLn() != null) {
CTLineProperties ln = spPr.getLn();
// 颜色
if (ln.getSolidFill() != null && ln.getSolidFill().getSrgbClr() != null) {
if (ln.getSolidFill() != null) {
CTSRgbColor rgb = ln.getSolidFill().getSrgbClr();
return rgb.getVal();
if (rgb != null) {
return rgb.getVal();
}
CTScRgbColor scrgb = ln.getSolidFill().getScrgbClr();
if (scrgb != null) {
return "RGB(" + scrgb.getR() + "," + scrgb.getG() + "," + scrgb.getB() + ")";
}
CTSchemeColor ctSchemeColor = ln.getSolidFill().getSchemeClr();
if (ctSchemeColor != null) {
return ctSchemeColor.getVal().value();
}
}
}
return "";
@@ -381,7 +414,7 @@ public class ShapePage {
// —— 2) 偏移描述dist EMU -> pt<1pt 视作“接触”,否则 "Xpt 偏移" —— //
double distPt = emuToPt(r.getDist()); // 可能为 0
String offsetLabel = distPt < 1.0 ? "接触" : (SlideUtils.fmt1(distPt) + "pt 偏移");
String offsetLabel = distPt < 1.0 ? "接触" : (SlideUtils.fmt1(distPt) + " 偏移");
return coverageLabel + " " + offsetLabel;
}
@@ -1007,7 +1040,9 @@ public class ShapePage {
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getIndent() != null) {
return paragraph.getPPr().getIndent() / 12700.0 + " pt"; // EMU 转 pt
// 结果保留1位小数点
String formattedNumber = String.format("%.1f", (double) paragraph.getPPr().getIndent() / 360000);
return formattedNumber + "厘米"; // EMU 转 pt
}
}
}
@@ -1021,7 +1056,7 @@ public class ShapePage {
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getSpcBef() != null) {
return paragraph.getPPr().getSpcBef().getSpcPts().getVal() / 100 + " pt"; // EMU 转 pt
return paragraph.getPPr().getSpcBef().getSpcPts().getVal() / 100 + ""; // EMU 转 pt
}
}
}
@@ -1035,7 +1070,7 @@ public class ShapePage {
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getSpcBef() != null) {
return paragraph.getPPr().getSpcAft().getSpcPts().getVal() / 100 + " pt"; // EMU 转 pt
return paragraph.getPPr().getSpcAft().getSpcPts().getVal() / 100 + ""; // EMU 转 pt
}
}
}
@@ -1067,7 +1102,7 @@ public class ShapePage {
if (paragraph.getPPr().getLnSpc().getSpcPct() != null) {
return (double) paragraph.getPPr().getLnSpc().getSpcPct().getVal() / 100000 + "倍行距"; // EMU 转 pt
} else if (paragraph.getPPr().getLnSpc().getSpcPts() != null) {
return (double) paragraph.getPPr().getLnSpc().getSpcPts().getVal() / 10 + "固定行距"; // EMU 转 pt
return (double) paragraph.getPPr().getLnSpc().getSpcPts().getVal() / 100 + ""; // EMU 转 pt
}
}
@@ -1231,7 +1266,7 @@ public class ShapePage {
long widthEmu = ctLineProperties.getW();
// 转换为磅1磅≈12700EMU
double widthPt = widthEmu / 12700.0;
return widthPt + "pt";
return widthPt + "";
}
}
}
@@ -1251,7 +1286,7 @@ public class ShapePage {
double fontSizePt = fontSize / 100.0;
// 估算轮廓高度通常为字体高度的10-15%
double outlineHeightPt = fontSizePt * 0.12; // 12%估算
return outlineHeightPt + "pt";
return outlineHeightPt + "";
}
}
}

View File

@@ -23,17 +23,28 @@ public class ShapePic {
if (prst != null && prst.getPrst() != null) {
STShapeType t = prst.getPrst();
switch (t) {
case HEXAGON: return "六边形";
case RECT: return "";
case ROUND_RECT: return "圆角矩形";
case ELLIPSE: return "椭圆";
case TRIANGLE: return "三角形";
case DIAMOND: return "";
case PARALLELOGRAM: return "平行四边形";
case TRAPEZOID: return "梯形";
case OCTAGON: return "八边形";
case PENTAGON: return "五边";
default: return "预设形状:" + t.value();
case HEXAGON:
return "六边";
case RECT:
return "矩形";
case ROUND_RECT:
return "圆角矩";
case ELLIPSE:
return "椭圆";
case TRIANGLE:
return "三角";
case DIAMOND:
return "菱形";
case PARALLELOGRAM:
return "平行四边形";
case TRAPEZOID:
return "梯形";
case OCTAGON:
return "八边形";
case PENTAGON:
return "五边形";
default:
return "预设形状:" + t.value();
}
}
if (ctShapeProperties.getCustGeom() != null) {
@@ -211,9 +222,19 @@ public class ShapePic {
if (spPr != null && spPr.getLn() != null) {
CTLineProperties ln = spPr.getLn();
// 颜色
if (ln.getSolidFill() != null && ln.getSolidFill().getSrgbClr() != null) {
if (ln.getSolidFill() != null) {
CTSRgbColor rgb = ln.getSolidFill().getSrgbClr();
return rgb.getVal();
if (rgb != null) {
return rgb.getVal();
}
CTScRgbColor scrgb = ln.getSolidFill().getScrgbClr();
if (scrgb != null) {
return "RGB(" + scrgb.getR() + "," + scrgb.getG() + "," + scrgb.getB() + ")";
}
CTSchemeColor ctSchemeColor = ln.getSolidFill().getSchemeClr();
if (ctSchemeColor != null) {
return ctSchemeColor.getVal().value();
}
}
}
return "";