【新增】 第三版PPT考点

This commit is contained in:
dlaren
2025-08-15 18:07:13 +08:00
parent 0a4cd9e61f
commit db0d26c8bd
2 changed files with 696 additions and 16 deletions

View File

@@ -2,11 +2,12 @@ package pc.exam.pp.module.judgement.utils.wps_pptx.pptx4j;
import jakarta.xml.bind.JAXBElement;
import jakarta.xml.bind.JAXBException;
import org.apache.poi.sl.usermodel.TextParagraph;
import org.docx4j.dml.*;
import org.docx4j.jaxb.XPathBinderAssociationIsPartialException;
import org.docx4j.openpackaging.parts.PresentationML.SlidePart;
import org.pptx4j.pml.CTSlideTiming;
import org.pptx4j.pml.CTTimeNodeList;
import org.pptx4j.pml.*;
import org.pptx4j.model.*;
import java.math.BigInteger;
import java.util.List;
@@ -21,6 +22,7 @@ public class ShapePage {
double heightPt = emuToPt(ext.getCy());
return String.valueOf(heightPt);
}
// 大小 - 宽度
public static String getShapeSizeWidthPt(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTransform2D xfrm = sp.getSpPr().getXfrm();
@@ -29,6 +31,7 @@ public class ShapePage {
double widthPt = emuToPt(ext.getCx());
return String.valueOf(widthPt);
}
// 大小 - 锁定纵横比
public static String getShapeSizeLockAspectRatio(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTransform2D xfrm = sp.getSpPr().getXfrm();
@@ -50,11 +53,17 @@ public class ShapePage {
}
return String.valueOf(lockAspectRatio);
}
// EMU 转 pt
private static double emuToPt(long emu) {
return emu / 12700.0;
}
/// 大小 旋转
public static String getShapeSizeRotate(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 位置 水平位置
public static String getShapePositionLeft(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTransform2D xfrm = sp.getSpPr().getXfrm();
@@ -64,6 +73,7 @@ public class ShapePage {
}
return "";
}
// 位置 垂直位置
public static String getShapePositionTop(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTTransform2D xfrm = sp.getSpPr().getXfrm();
@@ -73,6 +83,10 @@ public class ShapePage {
}
return "";
}
/// 替换文字 说明
public static String getShapeText(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状填充 填充方式
public static String getShapeFillType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
@@ -101,7 +115,7 @@ public class ShapePage {
}
// 形状填充 图片填充-效果
public static String getShapeFillPictureType(org.pptx4j.pml.Shape sp, CTSlideTiming timing){
public static String getShapeFillPictureType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTShapeProperties spPr = sp.getSpPr();
if (spPr != null && spPr.getBlipFill() != null) {
@@ -131,12 +145,12 @@ public class ShapePage {
// 形状填充 幻灯片背景填充-效果
public static String getShapeFillSlideBackgroundType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "";
return "待开发";
}
// 形状填充 填充透明度
public static String getShapeFillOpacity(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "";
return "待开发";
}
// 形状线条 绘制
@@ -215,12 +229,17 @@ public class ShapePage {
STCompoundLine cmpd = ln.getCmpd(); // 可能为 null
String v = (cmpd != null) ? cmpd.value() : "sng"; // 默认单线
switch (v) {
case "dbl": return "双线 (dbl)";
case "thickThin": return "粗-细双线 (thickThin)";
case "thinThick": return "细-粗双线 (thinThick)";
case "tri": return "三重线 (tri)";
case "dbl":
return "双线 (dbl)";
case "thickThin":
return "粗-细双线 (thickThin)";
case "thinThick":
return "细-粗双线 (thinThick)";
case "tri":
return "三重线 (tri)";
case "sng":
default: return "单线 (sng)";
default:
return "单线 (sng)";
}
}
@@ -251,6 +270,29 @@ public class ShapePage {
// 3) 未设置 → 视为实线
return "solid";
}
// 形状线条 开始箭头类型
public static String getShapeLineStartArrow(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTShapeProperties spPr = sp.getSpPr();
if (spPr != null && spPr.getLn() != null) {
CTLineProperties ln = spPr.getLn();
if (ln.getHeadEnd() != null) {
return ln.getHeadEnd().getType().value();
}
}
return "无箭头";
}
// 形状线条 开始箭头粗细
public static String getShapeLineStartArrowWidth(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状线条 结尾箭头类型
public static String getShapeLineEndArrow(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状线条 结尾箭头粗细
public static String getShapeLineEndArrowWidth(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状效果 阴影-绘制
@@ -347,6 +389,25 @@ public class ShapePage {
CTSoftEdgesEffect se = getSoftEdge(sp);
return (se != null) ? "" : "";
}
// 形状效果 柔化边缘→大小
public static String getShapeSoftEdgesSize(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
CTSoftEdgesEffect se = getSoftEdge(sp);
return (se != null) ? String.valueOf(se.getRad()) : null;
}
// 形状效果 三维效果→绘制
public static String getShape3DEffectDraw(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状效果 三维格式→效果
public static String getShape3DEffect(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
// 形状效果 三维旋转→效果
public static String getShape3DRotation(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/* —— 内部spPr/effectLst/softEdge —— */
private static CTSoftEdgesEffect getSoftEdge(org.pptx4j.pml.Shape shape) {
if (shape == null || shape.getSpPr() == null) return null;
@@ -358,18 +419,637 @@ public class ShapePage {
// 动画 效果
public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing, SlidePart slidePart) throws JAXBException, XPathBinderAssociationIsPartialException {
public static String getAnimation(org.pptx4j.pml.Shape sp, CTSlideTiming timing) throws JAXBException, XPathBinderAssociationIsPartialException {
// 获取形状中的ID
if (sp == null) return "无动画";
long spId = sp.getNvSpPr().getCNvPr().getId();
// 获取动画效果
// 1. 查询所有 p:spTgt 节点(形状目标)
List<Object> shapeTargets = slidePart.getJAXBNodesViaXPath("//p:spTgt", false);
for (Object target : shapeTargets) {
CTTimeNodeList timeNodeList = timing.getTnLst();
for (Object obj : timeNodeList.getParOrSeqOrExcl()) {
if (obj instanceof CTTLTimeNodeParallel) {
CTTLTimeNodeParallel par = (CTTLTimeNodeParallel) obj;
CTTLCommonTimeNodeData node = par.getCTn();
if (node.getDur() != null && !"indefinite".equals(node.getDur())) {
return node.getDur();
}
// 情况2检查子节点
// if (node.getChildTnLst() != null) {
// for (Object child : node.getChildTnLst().getParOrSeqOrExcl()) {
// if (child instanceof CTTLTimeNodeParallel) {
// String duration = getRealDuration(((CTTLTimeNodeParallel)child).getCTn());
// if (duration != null) return duration;
// }
// else if (child instanceof CTTLAnimateEffectBehavior) {
// return ((CTTLAnimateEffectBehavior)child).getDur();
// }
// // 其他类型处理...
// }
// }
System.out.println(par.getCTn());
}
}
return "待开发";
}
/// 形状动作,鼠标单机-动作
/// 文本框 文本
public static String getTextBoxText(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
StringBuilder textContent = new StringBuilder();
// 检查形状是否有文本框
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun textRun) {
if (textRun.getT() != null) {
textContent.append(textRun.getT());
}
}
}
textContent.append("\n"); // 段落间添加换行
}
}
return textContent.toString().trim();
}
/// 文本框 文本-垂直对齐
public static String getTextBoxVerticalAlign(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBodyProperties textBody = sp.getTxBody().getBodyPr();
STTextAnchoringType anchor = textBody.getAnchor();
// 遍历所有段落
if (anchor.value().equals("t")) {
return "顶部对齐";
} else if (anchor.value().equals("ctr")) {
return "居中对齐";
} else if (anchor.value().equals("b")) {
return "底部对齐";
} else if (anchor.value().equals("just")) {
return "两端对齐";
} else if (anchor.value().equals("dist")) {
return "分散对齐";
}
}
return "";
}
/// 文本框 文本-对齐
public static String getTextBoxAlign(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
STTextVerticalType stTextVerticalType = sp.getTxBody().getBodyPr().getVert();
if (stTextVerticalType != null) {
return stTextVerticalType.value();
} else {
return "无垂直对齐设置";
}
}
/// 文本框 文本-大小调整方式
public static String getTextBoxSizeAdjust(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() == null || sp.getTxBody().getBodyPr() == null) {
return "noAutofit"; // 默认值
}
CTTextBodyProperties bodyPr = sp.getTxBody().getBodyPr();
if (bodyPr.getNoAutofit() != null) {
return "noAutofit";
} else if (bodyPr.getNormAutofit() != null) {
return "normAutofit";
} else if (bodyPr.getSpAutoFit() != null) {
return "spAutofit";
}
return "noAutofit"; // 默认值
}
/// 文本框 上边距
public static String getTextBoxTopMargin(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null && sp.getTxBody().getBodyPr() != null) {
CTTextBodyProperties bodyPr = sp.getTxBody().getBodyPr();
Integer top = bodyPr.getTIns();
return top.toString();
}
return "";
}
/// 文本框 下边距
public static String getTextBoxBottomMargin(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null && sp.getTxBody().getBodyPr() != null) {
CTTextBodyProperties bodyPr = sp.getTxBody().getBodyPr();
Integer bottom = bodyPr.getBIns();
return bottom.toString();
}
return "";
}
/// 文本框 左边距
public static String getTextBoxLeftMargin(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null && sp.getTxBody().getBodyPr() != null) {
CTTextBodyProperties bodyPr = sp.getTxBody().getBodyPr();
Integer left = bodyPr.getLIns();
return left.toString();
}
return "";
}
/// 文本框 右边距
public static String getTextBoxRightMargin(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null && sp.getTxBody().getBodyPr() != null) {
CTTextBodyProperties bodyPr = sp.getTxBody().getBodyPr();
Integer right = bodyPr.getRIns();
return right.toString();
}
return "";
}
/// 文本框 自动换行
public static String getTextBoxAutoWrap(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null
&& sp.getTxBody().getBodyPr() != null) {
STTextWrappingType stTextWrappingType = sp.getTxBody().getBodyPr().getWrap();
return stTextWrappingType.value();
}
return "";
}
/// 字体 西文字体
public static String getTextBoxFontFamily(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
return ctRegularTextRun.getRPr().getLatin().getTypeface();
}
}
}
return "";
}
// 字体 中文字体
public static String getTextBoxFontFamilyChinese(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
return ctRegularTextRun.getRPr().getEa().getTypeface();
}
}
}
return "";
}
/// 字体 字体大小
public static String getTextBoxFontSize(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
return String.valueOf(ctRegularTextRun.getRPr().getSz());
}
}
}
return "";
}
/// 字体 加粗
public static String getTextBoxFontBold(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
if (ctRegularTextRun.getRPr().isB()) {
return "";
} else {
return "";
}
}
}
}
return "";
}
/// 字体 倾斜
public static String getTextBoxFontItalic(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
if (ctRegularTextRun.getRPr().isI()) {
return "";
} else {
return "";
}
}
}
}
return "";
}
/// 字体 字体颜色
public static String getTextBoxFontColor(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
return ctRegularTextRun.getRPr().getSolidFill().getSrgbClr().getVal();
}
}
}
return "";
}
/// 字体 下划线线型
public static String getTextBoxFontUnderline(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
// 遍历段落中的所有文本运行
Object obj = paragraph.getEGTextRun().get(0);
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
return ctRegularTextRun.getRPr().getU().value();
}
}
}
return "";
}
/// 字体 下划线颜色
public static String getTextBoxFontUnderlineColor(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
for (CTTextParagraph paragraph : textBody.getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
if (rPr != null && rPr.getUFill() != null && rPr.getUFill().getSolidFill() != null) {
return rPr.getUFill().getSolidFill().getSrgbClr().getVal();
}
}
}
}
}
return "";
}
/// 字体 删除线
public static String getTextBoxFontStrike(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
// 获取文本框字体是否有删除线
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
for (CTTextParagraph paragraph : textBody.getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
if (rPr != null && rPr.getStrike() != null) {
return "";
}
}
}
}
}
return "";
}
/// 字体 双删除线
public static String getTextBoxFontDoubleStrike(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 上标
public static String getTextBoxFontSuperscript(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 下标
public static String getTextBoxFontSubscript(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 偏移量
public static String getTextBoxFontOffset(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 小型大写字母
public static String getTextBoxFontSmallCaps(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 全部大写
public static String getTextBoxFontAllCaps(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 字体 等高字符
public static String getTextBoxFontFixedWidth(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 段落 对齐方式
public static String getTextBoxParagraphAlign(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getFontAlgn() != null) {
return paragraph.getPPr().getFontAlgn().value();
}
}
}
return "";
}
/// 段落 文本之前
public static String getTextBoxParagraphIndentBefore(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getSpcBef() != null) {
return String.valueOf(paragraph.getPPr().getSpcBef().getSpcPts().getVal());
}
}
}
return "0";
}
/// 段落 缩进→特殊
public static String getTextBoxParagraphIndentSpecial(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getIndent() != null) {
return paragraph.getPPr().getIndent() > 0 ? "首行缩进" : "悬挂缩进";
}
}
}
return "0";
}
/// 段落 缩进→度量值
public static String getTextBoxParagraphIndentMeasure(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getIndent() != null) {
return paragraph.getPPr().getIndent() / 12700.0 + " pt"; // EMU 转 pt
}
}
}
return "0";
}
/// 段落 间距→段前
public static String getTextBoxParagraphSpaceBefore(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getSpcBef() != null) {
return paragraph.getPPr().getSpcBef().getSpcPts().getVal() / 100 + " pt"; // EMU 转 pt
}
}
}
return "";
}
/// 段落 间距→段后
public static String getTextBoxParagraphSpaceAfter(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getSpcBef() != null) {
return paragraph.getPPr().getSpcAft().getSpcPts().getVal() / 100 + " pt"; // EMU 转 pt
}
}
}
return "";
}
/// 段落 间距→行距→类型
public static String getTextBoxParagraphSpaceLine(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getLnSpc().getSpcPct() != null) {
return "百分比行距"; // EMU 转 pt
} else if (paragraph.getPPr().getLnSpc().getSpcPts() != null) {
return "固定行距"; // EMU 转 pt
}
}
}
return "";
}
/// 段落 间距→行距→设置值
public static String getTextBoxParagraphSpaceLineValue(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
// 遍历所有段落
for (CTTextParagraph paragraph : textBody.getP()) {
if (paragraph.getPPr().getLnSpc().getSpcPct() != null) {
return paragraph.getPPr().getLnSpc().getSpcPct().getVal() / 100000 + "倍行距"; // EMU 转 pt
} else if (paragraph.getPPr().getLnSpc().getSpcPts() != null) {
return paragraph.getPPr().getLnSpc().getSpcPts().getVal() / 10 + "磅固定行距"; // EMU 转 pt
}
}
}
return "";
}
/// 段落 项目符号和编号→类型
public static String getTextBoxParagraphSymbol(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本填充 填充方式
public static String getTextBoxParagraphFillType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
for (CTTextParagraph paragraph : textBody.getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
if (rPr.getSolidFill() != null) {
return "纯色填充";
}
if (rPr.getGradFill() != null) {
return "渐变填充";
}
if (rPr.getBlipFill() != null) {
return "图片填充";
}
if (rPr.getPattFill() != null) {
return "图案填充";
}
if (rPr.getAltLang() != null) {
return "纹理填充";
}
if (rPr.getNoFill() != null) {
return "无填充";
}
}
}
}
}
return "";
}
/// 文本填充 纯色填充→颜色
public static String getTextBoxParagraphFillColor(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
CTTextBody textBody = sp.getTxBody();
for (CTTextParagraph paragraph : textBody.getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
if (rPr.getSolidFill() != null) {
if (rPr.getSolidFill().getSrgbClr() != null) {
return rPr.getSolidFill().getSrgbClr().getVal();
} else if (rPr.getSolidFill().getSchemeClr() != null) {
return rPr.getSolidFill().getSchemeClr().getVal().value();
} else if (rPr.getSolidFill().getSysClr() != null) {
return rPr.getSolidFill().getSysClr().getVal();
}
return "暂未查询到";
}
}
}
}
}
return "";
}
/// 文本填充 渐变填充→效果
public static String getTextBoxParagraphFillGradient(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本填充 图片填充→效果
public static String getTextBoxParagraphFillImage(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本填充 纹理填充→效果
public static String getTextBoxParagraphFillTexture(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本填充 图案填充→效果
public static String getTextBoxParagraphFillPattern(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本填充 填充透明度
public static String getTextBoxParagraphFillOpacity(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本轮廓 颜色
public static String getTextBoxParagraphOutlineColor(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
for (CTTextParagraph paragraph : sp.getTxBody().getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
CTLineProperties ctLineProperties = rPr.getLn();
return ctLineProperties.getSolidFill().getSrgbClr().getVal();
}
}
}
}
return "";
}
/// 文本轮廓 透明度
public static String getTextBoxParagraphOutlineOpacity(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
for (CTTextParagraph paragraph : sp.getTxBody().getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
CTLineProperties ctLineProperties = rPr.getLn();
CTSolidColorFillProperties fill = ctLineProperties.getSolidFill();
if (fill == null) return "不透明";
int alpha = 0;
if (fill.getSrgbClr() != null) {
alpha = Integer.parseInt(fill.getSrgbClr().getVal());
}
else if (fill.getSchemeClr() != null) {
alpha = fill.getSchemeClr().getVal().ordinal();
}
return String.valueOf((100000 - alpha) / 1000.0);
}
}
}
}
return "";
}
/// 文本轮廓 宽度
public static String getTextBoxParagraphOutlineWidth(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
for (CTTextParagraph paragraph : sp.getTxBody().getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
CTLineProperties ctLineProperties = rPr.getLn();
// 获取宽度单位EMU
long widthEmu = ctLineProperties.getW();
// 转换为磅1磅≈12700EMU
double widthPt = widthEmu / 12700.0;
return widthPt + "pt";
}
}
}
}
return "";
}
/// 文本轮廓 高度
public static String getTextBoxParagraphOutlineHeight(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
if (sp.getTxBody() != null) {
for (CTTextParagraph paragraph : sp.getTxBody().getP()) {
for (Object obj : paragraph.getEGTextRun()) {
if (obj instanceof CTRegularTextRun ctRegularTextRun) {
CTTextCharacterProperties rPr = ctRegularTextRun.getRPr();
// 获取字体大小(单位:百分之一磅)
int fontSize = rPr.getSz();
double fontSizePt = fontSize / 100.0;
// 估算轮廓高度通常为字体高度的10-15%
double outlineHeightPt = fontSizePt * 0.12; // 12%估算
return outlineHeightPt + "pt";
}
}
}
}
return "";
}
/// 文本轮廓 复合类型
public static String getTextBoxParagraphOutlineType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}
/// 文本轮廓 短划线类型
public static String getTextBoxParagraphOutlineDashType(org.pptx4j.pml.Shape sp, CTSlideTiming timing) {
return "待开发";
}

View File

@@ -74,11 +74,11 @@ public class SlideMaster {
// 目标对象
ShapePage shapeFunction = new ShapePage();
// 获取参数中类型的定义
Class<?>[] paramTypes = {Shape.class, CTSlideTiming.class, SlidePart.class};
Class<?>[] paramTypes = {Shape.class, CTSlideTiming.class};
// 带参数的方法调用示例
Method methodWithArgs = shapeFunction.getClass().getMethod(function, paramTypes);
// 实际参数值
Object[] arguments = {shape, timing, slidePart};
Object[] arguments = {shape, timing};
String value = (String) methodWithArgs.invoke(shapeFunction, arguments);
System.out.println(value);
}