- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 Apache POI 绘制弧线。为此,我还不清楚需要哪个 API 来设置用于绘图的点。
protected void draw(final XMLSlideShow ppt, final XSLFGroupShape containerGroupShape) {
final XSLFFreeformShape shape = containerGroupShape.createFreeform();
// Positioning
double x = container.toPptX(pos.getX());
double y = container.toPptY(pos.getY());
double w = container.toPpt(pos.getW());
double h = container.toPpt(pos.getH());
// Set shape type & anchor
shape.setShapeType(ShapeType.ARC);
shape.setAnchor(new Rectangle2D.Double(x, y, w, h));
shape.setFillColor(toAwtColor(fillColor));
shape.setLineColor(toAwtColor(strokeColor));
// Which API do I need here?
Path2D.Double gp = new Path2D.Double();
gp.moveTo(0, 0);
gp.lineTo(10, 10);
gp.closePath();
shape.setPath(gp);
}
(注意:这是负责在 pptx 文件中创建弧线的方法)
我知道 Polygons 使用 Path2D.Double
,但这种方法不起作用(或者我的示例数据是错误的?)。我什至尝试查看 VCS 存储库,但我没有找到任何使用弧形的测试用例
有人知道弧线数据(起始角度、弧长)是如何配置的吗?
编辑:
为了避免将来的困惑:
最佳答案
如前所述,您可以创建 XSLFSimpleShape ShapeType.ARC
类型。默认圆弧是 anchor 描述的矩形中的四分之一圆。 或者您使用路径创建自由形状。但您不能将两者结合起来。
如果您创建默认的 ShapeType.ARC
并在 PowerPoint
中查看它,您将看到两个用于设置开始和结束角度的 handle 。操作它们,然后保存文件,然后只需解压缩 *.pptx
文件并查看 /ppt/slides/slide1.xml
。在那里你会发现
<a:avLst>
<a:gd name="adj1" fmla="val [startAngle]"/>
<a:gd name="adj2" fmla="val [endAngle]"/>
</a:avLst>
因此我们需要 AvLst
,它是一个 CTGeomGuideList
,然后我们可以通过编程方式操作两个 handle (调整)。
我们唯一必须知道的是起始角度和结束角度的可能值是多少。一些测试设置导致 0 点位于 3 点钟位置,一整圈为 21,600,000。所以6点钟位置是5,400,000,9点钟位置是10,800,000,12点钟位置是16,200,000。这些值与整个圆的大小无关,如果矩形不是正方形,因此弧是椭圆形,这些值甚至是正确的。
以下代码演示了如何使用 ShapeType.ARC
绘制圆弧。
它还展示了如何使用 XSLFFreeformShape
绘制圆弧。这里最简单的方法是绘制贝塞尔弧,因为 java.awt.geom.Path2D.Double已经提供了创建贝塞尔路径的方法。
import java.io.FileOutputStream;
import org.apache.poi.xslf.usermodel.*;
import org.apache.poi.sl.usermodel.*;
import org.apache.xmlbeans.XmlObject;
import org.openxmlformats.schemas.presentationml.x2006.main.CTShape;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuideList;
import org.openxmlformats.schemas.drawingml.x2006.main.CTGeomGuide;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.geom.Path2D;
import java.awt.geom.Path2D.Double;
public class CreatePPTXArcShape {
private static XSLFAutoShape createArcShape(XSLFSlide slide, Rectangle positionAndSize,
int startAngle, int endAngle, Color color) {
XSLFAutoShape arcShape = ((XSLFSlide)slide).createAutoShape();
arcShape.setShapeType(ShapeType.ARC);
arcShape.setLineColor(color);
arcShape.setAnchor(positionAndSize);
startAngle = startAngle % 360;
endAngle = endAngle % 360;
XmlObject xmlObject = arcShape.getXmlObject();
CTShape ctShape = (CTShape)xmlObject;
CTGeomGuideList ctGeomGuideList = ctShape.getSpPr().getPrstGeom().getAvLst();
CTGeomGuide ctGeomGuide = ctGeomGuideList.addNewGd();
ctGeomGuide.setName("adj1");
ctGeomGuide.setFmla("val " + (21600000/360*startAngle));
ctGeomGuide = ctGeomGuideList.addNewGd();
ctGeomGuide.setName("adj2");
ctGeomGuide.setFmla("val " + (21600000/360*endAngle));
return arcShape;
}
public static void main(String[] args) throws Exception {
SlideShow slideShow = new XMLSlideShow();
Slide slide = slideShow.createSlide();
XSLFAutoShape arcShape;
//circle arcs
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(100, 100, 100, 100),
0, 90, Color.BLUE); //0 degrees = 3 o'clock position, 90 degrees = 6 o'clock position,
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(150, 100, 100, 100),
180, 0, Color.BLUE); //180 degrees = 9 o'clock position
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(200, 100, 100, 100),
270, 90, Color.BLUE); //270 degrees = 12 o'clock position
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(300, 100, 100, 100),
180+45, 270+45, Color.BLUE);
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(400, 100, 100, 100),
0, 359, Color.BLUE);
//elliptic arcs
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(100, 250, 100, 50),
0, 90, Color.BLUE);
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(150, 250, 100, 50),
180, 0, Color.BLUE);
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(200, 250, 100, 50),
270, 90, Color.BLUE);
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(300, 250, 100, 50),
180+45, 270+45, Color.BLUE);
arcShape = createArcShape((XSLFSlide)slide, new Rectangle(400, 250, 100, 50),
0, 359, Color.BLUE);
//Bézier freeform arcs
XSLFFreeformShape bezierShape = ((XSLFSlide)slide).createFreeform();
bezierShape.setLineColor(Color.BLUE);
Path2D.Double path = new Path2D.Double();
path.moveTo(100d, 400d); // x = 100px from left of slide, y = 400px from top of slide
path.curveTo(100d, 400d, 150d, 600d, 200d, 400d); // y of middle point is greater than y of baseline => arc downwards
bezierShape.setPath(path);
bezierShape = ((XSLFSlide)slide).createFreeform();
bezierShape.setLineColor(Color.BLUE);
path = new Path2D.Double();
path.moveTo(300d, 400d);
path.curveTo(300d, 400d, 350d, 200d, 400d, 400d); // y of middle point is less than y of baseline => arc upwards
bezierShape.setPath(path);
FileOutputStream out = new FileOutputStream("CreatePPTXArcShape.pptx");
slideShow.write(out);
out.close();
}
}
关于java - 在 PPTX 中绘制圆弧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50946195/
我正在尝试让角色以弧形向目标扔东西。 我知道顶点(x,y)和目标(x,y),我想得到一条从原点(x,y)到目标的最大高度为 vertex.y 的弧 我所拥有的是基于 y = a(x-h)^2 + k
我正在使用 html5 canvas 创建财富之轮。它与填充样式颜色配合得很好。我想要随机切片填充样式图案中的两(2)个不同图像。我如何实现这一目标。 这是我的 JS function rand(mi
我不明白为什么我需要在某些 block 中有一个弱的 self ,而其他的似乎工作正常。 如果我在 Notification block 中没有对 self 的弱引用,dealloc 将不会被释放。不
我正在尝试弄清楚如何在极坐标图中的两点之间创建弧线,但我绘制的线是连接它们的直线,即使该图是极坐标。 我需要使用其他绘图函数来代替 ax.plot 吗? 我注意到 matplotlib 中有一些补丁,
我正在尝试在 d3 中创建一个半圆。使用 cardinal interpolation产生一条接近我想要的路径,但不够“圆形”。如何编写自己的插值器来更好地绕过这条路径,或者有更好的方法吗? 这是我目
我正在开发一个启用 ARC 的项目。我正在从 View Controller 中推送 MyClass, - (void)pushMyClass { MyClass *myClass = [[
我有四点。它是可拖动的。在任何时候我点击“绘制”按钮我想显示 Angular 。我尝试过,但它会在外面画出陡峭 Angular 弧线。但我想在形状内的任意点绘制圆弧。 $(document).read
我正在尝试为 Android 设备修改操纵杆组件。目前该组件能够跟踪您手指的 x 和 y 位置并在那里绘制一个小圆圈。现在我要做的是从中心到手指的 x 和 y 位置绘制一个矩形或圆弧。 据我所知,矩形
有没有人有在 svgwrite (python) 中完成的弧形切片(奶酪切片或吃 bean 人)的工作示例,我已经尝试过这个,试图获得一个从 (100,100) 开始的西北象限,但得到一个奇怪的形状:
我正在开发一个 iPad(仅限)应用程序,我偶然发现了一个奇怪的问题。该应用程序在 iPad 1 上出现内存警告后终止,但在 iPad 2 上运行正常。我正在使用 ARC 并以 iOS 5 为目标。我
dealloc(下)会释放静态变量exampleString指向的NSString吗? // ExampleClass.h @interface ExampleClass : NSObject @
我正在尝试使用 WPF 在 Canvas 上绘制导入的 DXF 文件。我一直在使用 DXFLib(可用 here)来读取和解析各种文件,它似乎工作得很好。 我现在正在绘制 DXF 中的所有实体,但我受
我正在使用 NSManagedObjects,我想返回任务的预算或任务类别的预算。 但是,该方法给出了错误: Implicit conversion of int to Budget * is dis
我正在使用 JQuery.path沿贝塞尔曲线移动对象。单击该项目时,我可以确定起点和终点。如何计算 Angular 和长度,使元素在与起点和终点相交的 1/4 圆弧上从 A 点移动到 B 点? 我基
当转换到 ARC 时,我收到以下编译器错误:“删除未使用的自动释放消息是不安全的”。 如果我简单地删除自动释放消息,obj 将在 getAutoreleasedObj 结束时立即被释放,这将导致 pr
我是 Instruments 的新手,但我之前已经成功地找到了漏洞。这一次,不是这样——每次我调用这段代码时都会有 34MB 的泄漏!我试图在下面发布所有相关代码,同时删除 DDLogging 等内容
我正在从手动内存管理过渡到 ARC,但遇到了问题。大多数时候,我通过在我的模型类中调用 performSelectorInBackground 来异步执行数据加载。问题是当模型收到 nil(发布)时,
我正在尝试将项目转换为使用 ARC。 我有一个这样的声明属性: @property (nonatomic, retain, setter=setSomeProperty:) SomeClass * s
在关于为特定类禁用 ARC 编译器机制的 stackoverflow 主题之后,我将 -fno-objc-arc 参数添加到 Compile Sources 部分(TARGETS 项目中的 Buil
考虑这个 ARC 代码: - (void)main { NSString *s = [[NSString alloc] initWithString:@"s"]; [NSApp beg
我是一名优秀的程序员,十分优秀!