public void fontReadGroupList(IShape iShape){
if(iShape instanceof IAutoShape){
ParagraphCollection paragraphs = ((IAutoShape) iShape).getTextFrame().getParagraphs();
for (int j = 0; j < paragraphs.size(); j++) {
ParagraphEx paragraphEx = paragraphs.get(j);
TextRangeCollection textRanges = paragraphEx.getTextRanges();
for (int k = 0; k < textRanges.size(); k++) {
if(textRanges.get(k).getText().contains("字体颜色大小可选择参考模板")){
if(textRanges.get(k).getLatinFont() !=null){
System.out.println(textRanges.get(k).getText() + " font-family " +textRanges.get(k).getLatinFont().getFontName());
}else {
System.out.println(textRanges.get(k).getText() + " font-family null");
}
}
}
}
}else if(iShape instanceof GroupShape){
ShapeCollection shapes = ((GroupShape) iShape).getShapes();
for (int i = 0; i < shapes.size(); i++) {
fontReadGroupList(shapes.get(i));
}
}
}
@Test
public void fontRead() throws Exception{
Presentation presentation = new Presentation();
presentation.loadFromFile("E:\\work\\1比1复现\\未解决问题\\斜体丢失\\新局面模板-字体不一致.pptx");
SlideCollection slides = presentation.getSlides();
ISlide iSlide = slides.get(0);
ShapeCollection shapes = iSlide.getShapes();
for (int i = 0; i < shapes.size(); i++) {
IShape iShape = shapes.get(i);
fontReadGroupList(iShape);
}
String s = new String(iSlide.saveToSVG(), StandardCharsets.UTF_8);
//System.out.println(s);
}
//调用fontRead 函数 四段文本 有三段读取不到字体
// 于是我尝试使用转 svg 读取字体 但是转svg 读取到的字体全都是 simsun 与原来的不一样
// spire for java 7.12.4