use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.
the class XSSFConnector method prototype.
/**
* Initialize default structure of a new auto-shape
*
*/
protected static CTConnector prototype() {
if (prototype == null) {
CTConnector shape = CTConnector.Factory.newInstance();
CTConnectorNonVisual nv = shape.addNewNvCxnSpPr();
CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
nvp.setId(1);
nvp.setName("Shape 1");
nv.addNewCNvCxnSpPr();
CTShapeProperties sp = shape.addNewSpPr();
CTTransform2D t2d = sp.addNewXfrm();
CTPositiveSize2D p1 = t2d.addNewExt();
p1.setCx(0);
p1.setCy(0);
CTPoint2D p2 = t2d.addNewOff();
p2.setX(0);
p2.setY(0);
CTPresetGeometry2D geom = sp.addNewPrstGeom();
geom.setPrst(STShapeType.LINE);
geom.addNewAvLst();
CTShapeStyle style = shape.addNewStyle();
CTSchemeColor scheme = style.addNewLnRef().addNewSchemeClr();
scheme.setVal(STSchemeColorVal.ACCENT_1);
style.getLnRef().setIdx(1);
CTStyleMatrixReference fillref = style.addNewFillRef();
fillref.setIdx(0);
fillref.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
CTStyleMatrixReference effectRef = style.addNewEffectRef();
effectRef.setIdx(0);
effectRef.addNewSchemeClr().setVal(STSchemeColorVal.ACCENT_1);
CTFontReference fontRef = style.addNewFontRef();
fontRef.setIdx(STFontCollectionIndex.MINOR);
fontRef.addNewSchemeClr().setVal(STSchemeColorVal.TX_1);
prototype = shape;
}
return prototype;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.
the class XSSFDrawing method createObjectData.
@Override
public XSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
XSSFSheet sh = getSheet();
PackagePart sheetPart = sh.getPackagePart();
/*
* The shape id of the ole object seems to be a legacy shape id.
*
* see 5.3.2.1 legacyDrawing (Legacy Drawing Object):
* Legacy Shape ID that is unique throughout the entire document.
* Legacy shape IDs should be assigned based on which portion of the document the
* drawing resides on. The assignment of these ids is broken down into clusters of
* 1024 values. The first cluster is 1-1024, the second 1025-2048 and so on.
*
* Ole shapes seem to start with 1025 on the first sheet ...
* and not sure, if the ids need to be reindexed when sheets are removed
* or more than 1024 shapes are on a given sheet (see #51332 for a similar issue)
*/
XSSFSheet sheet = getSheet();
XSSFWorkbook wb = sheet.getWorkbook();
int sheetIndex = wb.getSheetIndex(sheet);
long shapeId = (sheetIndex + 1) * 1024 + newShapeId();
// add reference to OLE part
PackagePartName olePN;
try {
olePN = PackagingURIHelper.createPartName("/xl/embeddings/oleObject" + storageId + ".bin");
} catch (InvalidFormatException e) {
throw new POIXMLException(e);
}
PackageRelationship olePR = sheetPart.addRelationship(olePN, TargetMode.INTERNAL, POIXMLDocument.OLE_OBJECT_REL_TYPE);
// add reference to image part
XSSFPictureData imgPD = sh.getWorkbook().getAllPictures().get(pictureIndex);
PackagePartName imgPN = imgPD.getPackagePart().getPartName();
PackageRelationship imgSheetPR = sheetPart.addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
PackageRelationship imgDrawPR = getPackagePart().addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
// add OLE part metadata to sheet
CTWorksheet cwb = sh.getCTWorksheet();
CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
CTOleObject ole1 = oo.addNewOleObject();
ole1.setProgId("Package");
ole1.setShapeId(shapeId);
ole1.setId(olePR.getId());
XmlCursor cur1 = ole1.newCursor();
cur1.toEndToken();
cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML);
cur1.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, imgSheetPR.getId());
cur1.insertAttributeWithValue("defaultSize", "0");
cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML);
cur1.insertAttributeWithValue("moveWithCells", "1");
CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);
XmlCursor cur2 = ctAnchor.newCursor();
cur2.copyXmlContents(cur1);
cur2.dispose();
cur1.toParent();
cur1.toFirstChild();
cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from"));
cur1.toNextSibling();
cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to"));
cur1.dispose();
// add a new shape and link OLE & image part
CTShape ctShape = ctAnchor.addNewSp();
ctShape.set(XSSFObjectData.prototype());
ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor) anchor));
// workaround for not having the vmlDrawing filled
CTBlipFillProperties blipFill = ctShape.getSpPr().addNewBlipFill();
blipFill.addNewBlip().setEmbed(imgDrawPR.getId());
blipFill.addNewStretch().addNewFillRect();
CTNonVisualDrawingProps cNvPr = ctShape.getNvSpPr().getCNvPr();
cNvPr.setId(shapeId);
cNvPr.setName("Object " + shapeId);
XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor();
extCur.toFirstChild();
extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId);
extCur.dispose();
XSSFObjectData shape = new XSSFObjectData(this, ctShape);
shape.anchor = (XSSFClientAnchor) anchor;
return shape;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project poi by apache.
the class XSSFObjectData method prototype.
/**
* Prototype with the default structure of a new auto-shape.
*/
/**
* Prototype with the default structure of a new auto-shape.
*/
protected static CTShape prototype() {
final String drawNS = "http://schemas.microsoft.com/office/drawing/2010/main";
if (prototype == null) {
CTShape shape = CTShape.Factory.newInstance();
CTShapeNonVisual nv = shape.addNewNvSpPr();
CTNonVisualDrawingProps nvp = nv.addNewCNvPr();
nvp.setId(1);
nvp.setName("Shape 1");
// nvp.setHidden(true);
CTOfficeArtExtensionList extLst = nvp.addNewExtLst();
// https://msdn.microsoft.com/en-us/library/dd911027(v=office.12).aspx
CTOfficeArtExtension ext = extLst.addNewExt();
ext.setUri("{63B3BB69-23CF-44E3-9099-C40C66FF867C}");
XmlCursor cur = ext.newCursor();
cur.toEndToken();
cur.beginElement(new QName(drawNS, "compatExt", "a14"));
cur.insertNamespace("a14", drawNS);
cur.insertAttributeWithValue("spid", "_x0000_s1");
cur.dispose();
nv.addNewCNvSpPr();
CTShapeProperties sp = shape.addNewSpPr();
CTTransform2D t2d = sp.addNewXfrm();
CTPositiveSize2D p1 = t2d.addNewExt();
p1.setCx(0);
p1.setCy(0);
CTPoint2D p2 = t2d.addNewOff();
p2.setX(0);
p2.setY(0);
CTPresetGeometry2D geom = sp.addNewPrstGeom();
geom.setPrst(STShapeType.RECT);
geom.addNewAvLst();
prototype = shape;
}
return prototype;
}
use of org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps in project Gargoyle by callakrsos.
the class MSWord method addPicture.
/**
* 사진추가.
*
* @param imgFile
* @param id
* @param width
* @param height
* @param run
*/
public void addPicture(final String imgFile, final int id, int width, int height, final XWPFRun run) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream(imgFile);
final String blipId = run.getDocument().addPictureData(fileInputStream, Document.PICTURE_TYPE_JPEG);
final int EMU = 9525;
width *= EMU;
height *= EMU;
// String blipId =
// getAllPictures().get(id).getPackageRelationship().getId();
final CTInline inline = run.getCTR().addNewDrawing().addNewInline();
final String picXml = "" + "<a:graphic xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\">" + " <a:graphicData uri=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:pic xmlns:pic=\"http://schemas.openxmlformats.org/drawingml/2006/picture\">" + " <pic:nvPicPr>" + " <pic:cNvPr id=\"" + id + "\" name=\"Generated\"/>" + " <pic:cNvPicPr/>" + " </pic:nvPicPr>" + " <pic:blipFill>" + " <a:blip r:embed=\"" + blipId + "\" xmlns:r=\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\"/>" + " <a:stretch>" + " <a:fillRect/>" + " </a:stretch>" + " </pic:blipFill>" + " <pic:spPr>" + " <a:xfrm>" + " <a:off x=\"0\" y=\"0\"/>" + " <a:ext cx=\"" + width + "\" cy=\"" + height + "\"/>" + " </a:xfrm>" + " <a:prstGeom prst=\"rect\">" + " <a:avLst/>" + " </a:prstGeom>" + " </pic:spPr>" + " </pic:pic>" + " </a:graphicData>" + "</a:graphic>";
XmlToken xmlToken = null;
xmlToken = XmlToken.Factory.parse(picXml);
inline.set(xmlToken);
inline.setDistT(0);
inline.setDistB(0);
inline.setDistL(0);
inline.setDistR(0);
final CTPositiveSize2D extent = inline.addNewExtent();
extent.setCx(width);
extent.setCy(height);
final CTNonVisualDrawingProps docPr = inline.addNewDocPr();
docPr.setId(id);
docPr.setName("Picture " + id);
docPr.setDescr("Generated");
} catch (final Exception e) {
e.printStackTrace();
} finally {
// close streams
if (fileInputStream != null) {
try {
fileInputStream.close();
} catch (final IOException ioEx) {
// can be ignored
}
}
}
}
Aggregations