https://bz.apache.org/bugzilla/show_bug.cgi?id=69522
Bug ID: 69522
Summary: XmlComplexContentImpl cannot be cast to
CTPath2DQuadBezierTo
Product: POI
Version: 5.3.0-FINAL
Hardware: PC
Status: NEW
Severity: blocker
Priority: P2
Component: XSLF
Assignee: [email protected]
Reporter: [email protected]
Target Milestone: ---
Created attachment 39963
--> https://bz.apache.org/bugzilla/attachment.cgi?id=39963&action=edit
The reproduce class
This is a blocker problem for user can NOT use the export functionality.
Call me if need any other staffs.
# The error output:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException:
org.apache.xmlbeans.impl.values.XmlComplexContentImpl cannot be cast to
org.openxmlformats.schemas.drawingml.x2006.main.CTPath2DQuadBezierTo
at
org.openxmlformats.schemas.drawingml.x2006.main.impl.CTPath2DImpl.addNewQuadBezTo(CTPath2DImpl.java:555)
at
org.apache.poi.xslf.usermodel.XSLFFreeformShape.addQuadBezierTo(XSLFFreeformShape.java:204)
at
org.apache.poi.xslf.usermodel.XSLFFreeformShape.setPath(XSLFFreeformShape.java:90)
at org.apache.poi.sl.draw.SLGraphics.fill(SLGraphics.java:330)
at
poi.test.general.path.TriangleDrawingExample$TrianglePanel.drawShape(TriangleDrawingExample.java:94)
at
poi.test.general.path.TriangleDrawingExample$TrianglePanel.paintComponent(TriangleDrawingExample.java:49)
at javax.swing.JComponent.paint(JComponent.java:1050)
at
poi.test.general.path.TriangleDrawingExample.lambda$0(TriangleDrawingExample.java:125)
# how to reproduce the problem
So see the attachment.
package poi.test.general.path;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.geom.Arc2D;
import java.awt.geom.GeneralPath;
import java.awt.geom.Point2D;
import java.awt.geom.QuadCurve2D;
import java.awt.geom.Rectangle2D;
import java.io.FileOutputStream;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import org.apache.poi.sl.draw.SLGraphics;
import org.apache.poi.xslf.usermodel.XMLSlideShow;
import org.apache.poi.xslf.usermodel.XSLFGroupShape;
import org.apache.poi.xslf.usermodel.XSLFSlide;
public class TriangleDrawingExample extends JFrame {
TrianglePanel comp = new TrianglePanel();
public TriangleDrawingExample() {
// 设置 JFrame 的标题
setTitle("Triangle Drawing Example");
// 设置 JFrame 的大小
setSize(400, 400);
// 设置 JFrame 的关闭操作
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// 将自定义面板添加到 JFrame
add(comp);
// 设置 JFrame 可见
setVisible(true);
}
// 自定义 JPanel 用于绘制三角形
class TrianglePanel extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.BLUE);
drawShape(g2d);
}
private void drawShape(Graphics2D g2d) {
int centerX = getWidth() / 2;
int centerY = getHeight() / 2;
int innerRadius = 50;
int sourceStartAngle = 0;
int targetStartAngle = 100;
int targetEndAngle = 145;
int sourceEndAngle = 40;
Point2D.Double sourceEndPoint = new Point2D.Double(0,
0);
Point2D.Double sourceStartPoint = new Point2D.Double(0,
0);
Point2D.Double targetStartPoint = new
Point2D.Double(getWidth(), getHeight());
Point2D.Double targetEndPoint = new
Point2D.Double(getWidth(), getHeight());
GeneralPath path = new GeneralPath();
{
Arc2D arc2 = new Arc2D.Double(centerX -
innerRadius, centerY - innerRadius, 2 * innerRadius,
2 * innerRadius,
sourceStartAngle, sourceEndAngle - sourceStartAngle, Arc2D.OPEN);
path.append(arc2, true);
QuadCurve2D chord = new
QuadCurve2D.Double(sourceEndPoint.getX(), sourceEndPoint.getY(), centerX,
centerY,
targetStartPoint.getX(), targetStartPoint.getY());
path.append(chord, true);
}
{
Arc2D arc2 = new Arc2D.Double(centerX -
innerRadius, centerY - innerRadius, 2 * innerRadius,
2 * innerRadius,
targetStartAngle, targetEndAngle - targetStartAngle, Arc2D.OPEN);
path.append(arc2, true);
QuadCurve2D chord = new
QuadCurve2D.Double(targetEndPoint.getX(), targetEndPoint.getY(), centerX,
centerY,
sourceStartPoint.getX(), sourceStartPoint.getY());
path.append(chord, true);
}
path.closePath();
g2d.setColor(Color.BLACK);
g2d.fill(path);
}
}
public static void main(String[] args) {
// 创建并运行 JFrame 实例
Runnable doRun = () -> {
TriangleDrawingExample triangleDrawingExample = new
TriangleDrawingExample();
TrianglePanel comp2 = triangleDrawingExample.comp;
try (XMLSlideShow ppt = new XMLSlideShow();
FileOutputStream out = new
FileOutputStream("C:\\Users\\yudal\\Desktop\\a.pptx")) {
Dimension size = comp2.getSize();
// Set the size of the slide to match JPanel
size
ppt.setPageSize(size);
// bar chart data. The first value is the bar
color, the second is the width
XSLFSlide slide = ppt.createSlide();
XSLFGroupShape group = slide.createGroup();
// define position of the drawing in the slide
Rectangle2D bounds = new Rectangle2D.Double(0,
0, size.getWidth(), size.getHeight());
group.setAnchor(bounds);
group.setInteriorAnchor(bounds);
Graphics2D graphics = new SLGraphics(group);
comp2.paint(graphics);
//这是用来辅助定位的一个Anchor 矩形,先不绘制了
//graphics.draw(group.getInteriorAnchor());
graphics.dispose();
ppt.write(out);
} catch (IOException e) {
e.printStackTrace();
}
};
SwingUtilities.invokeLater(doRun);
}
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]