From da0338111a96793d00a85beae60e32918a37064d Mon Sep 17 00:00:00 2001 From: dlaren Date: Wed, 10 Sep 2025 00:59:00 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E6=96=B0=E5=A2=9E=E3=80=91=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96PPT=E5=BD=A2=E7=8A=B6=E8=80=83=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../utils/wps_pptx/pptx4j/ShapePage.java | 57 +++++++++++++++---- .../utils/wps_pptx/pptx4j/ShapePic.java | 47 ++++++++++----- 2 files changed, 80 insertions(+), 24 deletions(-) diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java index c3ac175b..603aa719 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePage.java @@ -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 pList = ctTextBody.getP(); + for (CTTextParagraph p : pList) { + List 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 + "磅"; } } } diff --git a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePic.java b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePic.java index 59595a4b..465b3ca3 100644 --- a/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePic.java +++ b/exam-module-judgement/exam-module-judgement-biz/src/main/java/pc/exam/pp/module/judgement/utils/wps_pptx/pptx4j/ShapePic.java @@ -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 "";