internal static CT_Picture Prototype() { if (XSSFPicture.prototype == null) { CT_Picture ctPicture = new CT_Picture(); CT_PictureNonVisual pictureNonVisual = ctPicture.AddNewNvPicPr(); CT_NonVisualDrawingProps visualDrawingProps = pictureNonVisual.AddNewCNvPr(); visualDrawingProps.id = 1U; visualDrawingProps.name = "Picture 1"; visualDrawingProps.descr = "Picture"; pictureNonVisual.AddNewCNvPicPr().AddNewPicLocks().noChangeAspect = true; CT_BlipFillProperties blipFillProperties = ctPicture.AddNewBlipFill(); blipFillProperties.AddNewBlip().embed = ""; blipFillProperties.AddNewStretch().AddNewFillRect(); CT_ShapeProperties ctShapeProperties = ctPicture.AddNewSpPr(); CT_Transform2D ctTransform2D = ctShapeProperties.AddNewXfrm(); CT_PositiveSize2D ctPositiveSize2D = ctTransform2D.AddNewExt(); ctPositiveSize2D.cx = 0L; ctPositiveSize2D.cy = 0L; CT_Point2D ctPoint2D = ctTransform2D.AddNewOff(); ctPoint2D.x = 0L; ctPoint2D.y = 0L; CT_PresetGeometry2D presetGeometry2D = ctShapeProperties.AddNewPrstGeom(); presetGeometry2D.prst = ST_ShapeType.rect; presetGeometry2D.AddNewAvLst(); XSSFPicture.prototype = ctPicture; } return(XSSFPicture.prototype); }
/** * Initialize default structure of a new shape group */ internal static CT_GroupShape Prototype() { if (prototype == null) { CT_GroupShape shape = new CT_GroupShape(); CT_GroupShapeNonVisual nv = shape.AddNewNvGrpSpPr(); CT_NonVisualDrawingProps nvpr = nv.AddNewCNvPr(); nvpr.id = (0); nvpr.name = ("Group 0"); nv.AddNewCNvGrpSpPr(); CT_GroupShapeProperties sp = shape.AddNewGrpSpPr(); CT_GroupTransform2D t2d = sp.AddNewXfrm(); CT_PositiveSize2D p1 = t2d.AddNewExt(); p1.cx = (0); p1.cy = (0); CT_Point2D p2 = t2d.AddNewOff(); p2.x = (0); p2.y = (0); CT_PositiveSize2D p3 = t2d.AddNewChExt(); p3.cx = (0); p3.cy = (0); CT_Point2D p4 = t2d.AddNewChOff(); p4.x = (0); p4.y = (0); prototype = shape; } return(prototype); }
/** * Initialize default structure of a new graphic frame */ public static CT_GraphicalObjectFrame Prototype() { CT_GraphicalObjectFrame graphicFrame = new CT_GraphicalObjectFrame(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_GraphicalObjectFrameNonVisual nvGraphic = graphicFrame.AddNewNvGraphicFramePr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps props = nvGraphic.AddNewCNvPr(); props.id = (0); props.name = ("Diagramm 1"); nvGraphic.AddNewCNvGraphicFramePr(); CT_Transform2D transform = graphicFrame.AddNewXfrm(); CT_PositiveSize2D extPoint = transform.AddNewExt(); CT_Point2D offPoint = transform.AddNewOff(); extPoint.cx = (0); extPoint.cy = (0); offPoint.x = (0); offPoint.y = (0); CT_GraphicalObject graphic = graphicFrame.AddNewGraphic(); prototype = graphicFrame; return(prototype); }
internal static CT_GroupShape Prototype() { if (XSSFShapeGroup.prototype == null) { CT_GroupShape ctGroupShape = new CT_GroupShape(); CT_GroupShapeNonVisual groupShapeNonVisual = ctGroupShape.AddNewNvGrpSpPr(); CT_NonVisualDrawingProps visualDrawingProps = groupShapeNonVisual.AddNewCNvPr(); visualDrawingProps.id = 0U; visualDrawingProps.name = "Group 0"; groupShapeNonVisual.AddNewCNvGrpSpPr(); CT_GroupTransform2D groupTransform2D = ctGroupShape.AddNewGrpSpPr().AddNewXfrm(); CT_PositiveSize2D ctPositiveSize2D1 = groupTransform2D.AddNewExt(); ctPositiveSize2D1.cx = 0L; ctPositiveSize2D1.cy = 0L; CT_Point2D ctPoint2D1 = groupTransform2D.AddNewOff(); ctPoint2D1.x = 0L; ctPoint2D1.y = 0L; CT_PositiveSize2D ctPositiveSize2D2 = groupTransform2D.AddNewChExt(); ctPositiveSize2D2.cx = 0L; ctPositiveSize2D2.cy = 0L; CT_Point2D ctPoint2D2 = groupTransform2D.AddNewChOff(); ctPoint2D2.x = 0L; ctPoint2D2.y = 0L; XSSFShapeGroup.prototype = ctGroupShape; } return(XSSFShapeGroup.prototype); }
/// <summary> /// CT_Inline class constructor /// </summary> public CT_Inline() { this.graphicField = new CT_GraphicalObject(); this.cNvGraphicFramePrField = new CT_NonVisualGraphicFrameProperties(); this.docPrField = new CT_NonVisualDrawingProps(); this.effectExtentField = new CT_EffectExtent(); this.extentField = new CT_PositiveSize2D(); }
public CT_PositiveSize2D AddNewExtent() { if (this.extentField == null) { this.extentField = new CT_PositiveSize2D(); } return(this.extentField); }
/** * Calculate the preferred size for this picture. * * @param scaleX the amount by which image width is multiplied relative to the original width. * @param scaleY the amount by which image height is multiplied relative to the original height. * @return XSSFClientAnchor with the preferred size for this image */ public IClientAnchor GetPreferredSize(double scaleX, double scaleY) { Size dim = ImageUtils.SetPreferredSize(this, scaleX, scaleY); CT_PositiveSize2D size2d = ctPicture.spPr.xfrm.ext; size2d.cx = (dim.Width); size2d.cy = (dim.Height); return(ClientAnchor); }
public XWPFPicture AddPicture(Stream pictureData, int pictureType, string filename, int width, int height) { XWPFDocument document = this.paragraph.GetDocument(); string id = document.AddPictureData(pictureData, pictureType); XWPFPictureData relationById = (XWPFPictureData)document.GetRelationById(id); try { CT_Inline ctInline = this.run.AddNewDrawing().AddNewInline(); XmlElement element = new XmlDocument().CreateElement("pic", "pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); ctInline.graphic = new CT_GraphicalObject(); ctInline.graphic.graphicData = new CT_GraphicalObjectData(); ctInline.graphic.graphicData.AddPicElement((XmlElement)element.Clone()); ctInline.distT = 0U; ctInline.distR = 0U; ctInline.distB = 0U; ctInline.distL = 0U; CT_NonVisualDrawingProps visualDrawingProps1 = ctInline.AddNewDocPr(); long num = this.GetParagraph().GetDocument().GetDrawingIdManager().ReserveNew(); visualDrawingProps1.id = (uint)num; visualDrawingProps1.name = "Drawing " + (object)num; visualDrawingProps1.descr = filename; CT_PositiveSize2D ctPositiveSize2D1 = ctInline.AddNewExtent(); ctPositiveSize2D1.cx = (long)width; ctPositiveSize2D1.cy = (long)height; NPOI.OpenXmlFormats.Dml.Picture.CT_Picture ctPicture = this.GetCTPictures((object)ctInline.graphic.graphicData)[0]; CT_PictureNonVisual pictureNonVisual = ctPicture.AddNewNvPicPr(); CT_NonVisualDrawingProps visualDrawingProps2 = pictureNonVisual.AddNewCNvPr(); visualDrawingProps2.id = 0U; visualDrawingProps2.name = "Picture " + (object)num; visualDrawingProps2.descr = filename; pictureNonVisual.AddNewCNvPicPr().AddNewPicLocks().noChangeAspect = true; CT_BlipFillProperties blipFillProperties = ctPicture.AddNewBlipFill(); blipFillProperties.AddNewBlip().embed = relationById.GetPackageRelationship().Id; blipFillProperties.AddNewStretch().AddNewFillRect(); CT_ShapeProperties ctShapeProperties = ctPicture.AddNewSpPr(); CT_Transform2D ctTransform2D = ctShapeProperties.AddNewXfrm(); CT_Point2D ctPoint2D = ctTransform2D.AddNewOff(); ctPoint2D.x = 0L; ctPoint2D.y = 0L; CT_PositiveSize2D ctPositiveSize2D2 = ctTransform2D.AddNewExt(); ctPositiveSize2D2.cx = (long)width; ctPositiveSize2D2.cy = (long)height; CT_PresetGeometry2D presetGeometry2D = ctShapeProperties.AddNewPrstGeom(); presetGeometry2D.prst = ST_ShapeType.rect; presetGeometry2D.AddNewAvLst(); XWPFPicture xwpfPicture = new XWPFPicture(ctPicture, this); this.pictures.Add(xwpfPicture); return(xwpfPicture); } catch (Exception ex) { throw new InvalidOperationException("", ex); } }
/** * Initialize default structure of a new auto-shape * */ public static CT_Connector Prototype() { CT_Connector shape = new CT_Connector(); CT_ConnectorNonVisual nv = shape.AddNewNvCxnSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr(); nvp.id = (1); nvp.name = ("Shape 1"); nv.AddNewCNvCxnSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp = shape.AddNewSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Transform2D t2d = sp.AddNewXfrm(); CT_PositiveSize2D p1 = t2d.AddNewExt(); p1.cx = (0); p1.cy = (0); CT_Point2D p2 = t2d.AddNewOff(); p2.x = (0); p2.y = (0); CT_PresetGeometry2D geom = sp.AddNewPrstGeom(); geom.prst = (ST_ShapeType.line); geom.AddNewAvLst(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeStyle style = shape.AddNewStyle(); CT_SchemeColor scheme = style.AddNewLnRef().AddNewSchemeClr(); scheme.val = (ST_SchemeColorVal.accent1); style.lnRef.idx = (1); CT_StyleMatrixReference fillref = style.AddNewFillRef(); fillref.idx = (0); fillref.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1); CT_StyleMatrixReference effectRef = style.AddNewEffectRef(); effectRef.idx = (0); effectRef.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1); CT_FontReference fontRef = style.AddNewFontRef(); fontRef.idx = (ST_FontCollectionIndex.minor); fontRef.AddNewSchemeClr().val = (ST_SchemeColorVal.tx1); prototype = shape; return(prototype); }
internal static CT_Shape Prototype() { if (XSSFSimpleShape.prototype == null) { CT_Shape ctShape = new CT_Shape(); CT_ShapeNonVisual ctShapeNonVisual = ctShape.AddNewNvSpPr(); CT_NonVisualDrawingProps visualDrawingProps = ctShapeNonVisual.AddNewCNvPr(); visualDrawingProps.id = 1U; visualDrawingProps.name = "Shape 1"; ctShapeNonVisual.AddNewCNvSpPr(); CT_ShapeProperties ctShapeProperties = ctShape.AddNewSpPr(); CT_Transform2D ctTransform2D = ctShapeProperties.AddNewXfrm(); CT_PositiveSize2D ctPositiveSize2D = ctTransform2D.AddNewExt(); ctPositiveSize2D.cx = 0L; ctPositiveSize2D.cy = 0L; CT_Point2D ctPoint2D = ctTransform2D.AddNewOff(); ctPoint2D.x = 0L; ctPoint2D.y = 0L; CT_PresetGeometry2D presetGeometry2D = ctShapeProperties.AddNewPrstGeom(); presetGeometry2D.prst = ST_ShapeType.rect; presetGeometry2D.AddNewAvLst(); CT_ShapeStyle ctShapeStyle = ctShape.AddNewStyle(); CT_SchemeColor ctSchemeColor = ctShapeStyle.AddNewLnRef().AddNewSchemeClr(); ctSchemeColor.val = ST_SchemeColorVal.accent1; ctSchemeColor.AddNewShade().val = 50000; ctShapeStyle.lnRef.idx = 2U; CT_StyleMatrixReference styleMatrixReference1 = ctShapeStyle.AddNewFillRef(); styleMatrixReference1.idx = 1U; styleMatrixReference1.AddNewSchemeClr().val = ST_SchemeColorVal.accent1; CT_StyleMatrixReference styleMatrixReference2 = ctShapeStyle.AddNewEffectRef(); styleMatrixReference2.idx = 0U; styleMatrixReference2.AddNewSchemeClr().val = ST_SchemeColorVal.accent1; CT_FontReference ctFontReference = ctShapeStyle.AddNewFontRef(); ctFontReference.idx = ST_FontCollectionIndex.minor; ctFontReference.AddNewSchemeClr().val = ST_SchemeColorVal.lt1; CT_TextBody ctTextBody = ctShape.AddNewTxBody(); CT_TextBodyProperties textBodyProperties = ctTextBody.AddNewBodyPr(); textBodyProperties.anchor = ST_TextAnchoringType.ctr; textBodyProperties.rtlCol = false; CT_TextParagraph ctTextParagraph = ctTextBody.AddNewP(); ctTextParagraph.AddNewPPr().algn = ST_TextAlignType.ctr; CT_TextCharacterProperties characterProperties = ctTextParagraph.AddNewEndParaRPr(); characterProperties.lang = "en-US"; characterProperties.sz = 1100; ctTextBody.AddNewLstStyle(); XSSFSimpleShape.prototype = ctShape; } return(XSSFSimpleShape.prototype); }
/** * Prototype with the default structure of a new auto-shape. */ protected internal static CT_Shape Prototype() { // in poi, method XmlObject set(XmlObject srcObj) will create a copy of XmlObject // so this prototype object would be newly set to shape object // but in .net, the prototype object will be modified and keep its contents, would // affect next usage. so comment the following code, and create a new prototype object // for every calling of Prototype(). //if (prototype == null) { CT_Shape shape = new CT_Shape(); CT_ShapeNonVisual nv = shape.AddNewNvSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr(); nvp.id = (/*setter*/ 1); nvp.name = (/*setter*/ "Shape 1"); nv.AddNewCNvSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp = shape.AddNewSpPr(); CT_Transform2D t2d = sp.AddNewXfrm(); CT_PositiveSize2D p1 = t2d.AddNewExt(); p1.cx = (/*setter*/ 0); p1.cy = (/*setter*/ 0); CT_Point2D p2 = t2d.AddNewOff(); p2.x = (/*setter*/ 0); p2.y = (/*setter*/ 0); CT_PresetGeometry2D geom = sp.AddNewPrstGeom(); geom.prst = (/*setter*/ ST_ShapeType.rect); geom.AddNewAvLst(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = shape.AddNewTxBody(); CT_TextBodyProperties bodypr = body.AddNewBodyPr(); bodypr.anchor = (/*setter*/ ST_TextAnchoringType.t); bodypr.rtlCol = (/*setter*/ false); CT_TextParagraph p = body.AddNewP(); p.AddNewPPr().algn = (/*setter*/ ST_TextAlignType.l); CT_TextCharacterProperties endPr = p.AddNewEndParaRPr(); endPr.lang = (/*setter*/ "en-US"); endPr.sz = (/*setter*/ 1100); CT_SolidColorFillProperties scfpr = endPr.AddNewSolidFill(); scfpr.AddNewSrgbClr().val = (/*setter*/ new byte[] { 0, 0, 0 }); body.AddNewLstStyle(); prototype = shape; } return(prototype); }
/** * Prototype with the default structure of a new auto-shape. */ protected internal static CT_Shape GetPrototype() { if (prototype == null) { CT_Shape shape = new CT_Shape(); CT_ShapeNonVisual nv = shape.AddNewNvSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr(); nvp.id = (/*setter*/ 1); nvp.name = (/*setter*/ "Shape 1"); nv.AddNewCNvSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sp = shape.AddNewSpPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Transform2D t2d = sp.AddNewXfrm(); CT_PositiveSize2D p1 = t2d.AddNewExt(); p1.cx = (/*setter*/ 0); p1.cy = (/*setter*/ 0); CT_Point2D p2 = t2d.AddNewOff(); p2.x = (/*setter*/ 0); p2.y = (/*setter*/ 0); CT_PresetGeometry2D geom = sp.AddNewPrstGeom(); geom.prst = (/*setter*/ ST_ShapeType.rect); geom.AddNewAvLst(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_TextBody body = shape.AddNewTxBody(); CT_TextBodyProperties bodypr = body.AddNewBodyPr(); bodypr.anchor = (/*setter*/ ST_TextAnchoringType.t); bodypr.rtlCol = (/*setter*/ false); CT_TextParagraph p = body.AddNewP(); p.AddNewPPr().algn = (/*setter*/ ST_TextAlignType.l); CT_TextCharacterProperties endPr = p.AddNewEndParaRPr(); endPr.lang = (/*setter*/ "en-US"); endPr.sz = (/*setter*/ 1100); CT_SolidColorFillProperties scfpr = endPr.AddNewSolidFill(); scfpr.AddNewSrgbClr().val = (/*setter*/ new byte[] { 0, 0, 0 }); body.AddNewLstStyle(); prototype = shape; } return(prototype); }
public XSSFChildAnchor(int x, int y, int cx, int cy) { t2d = new NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_Transform2D(); CT_Point2D off = t2d.AddNewOff(); CT_PositiveSize2D ext = t2d.AddNewExt(); off.x = (x); off.y = (y); ext.cx = (Math.Abs(cx - x)); ext.cy = (Math.Abs(cy - y)); if (x > cx) { t2d.flipH = (true); } if (y > cy) { t2d.flipV = (true); } }
public void SetCoordinates(int x1, int y1, int x2, int y2) { CT_GroupTransform2D xfrm = this.ctGroup.grpSpPr.xfrm; CT_Point2D off = xfrm.off; off.x = (long)x1; off.y = (long)y1; CT_PositiveSize2D ext = xfrm.ext; ext.cx = (long)x2; ext.cy = (long)y2; CT_Point2D chOff = xfrm.chOff; chOff.x = (long)x1; chOff.y = (long)y1; CT_PositiveSize2D chExt = xfrm.chExt; chExt.cx = (long)x2; chExt.cy = (long)y2; }
public XSSFChildAnchor(int x, int y, int cx, int cy) { this.t2d = new CT_Transform2D(); CT_Point2D ctPoint2D = this.t2d.AddNewOff(); CT_PositiveSize2D ctPositiveSize2D = this.t2d.AddNewExt(); ctPoint2D.x = (long)x; ctPoint2D.y = (long)y; ctPositiveSize2D.cx = (long)Math.Abs(cx - x); ctPositiveSize2D.cy = (long)Math.Abs(cy - y); if (x > cx) { this.t2d.flipH = true; } if (y <= cy) { return; } this.t2d.flipV = true; }
/** * Sets the coordinate space of this group. All children are constrained * to these coordinates. */ public void SetCoordinates(int x1, int y1, int x2, int y2) { CT_GroupTransform2D t2d = ctGroup.grpSpPr.xfrm; CT_Point2D off = t2d.off; off.x = (x1); off.y = (y1); CT_PositiveSize2D ext = t2d.ext; ext.cx = (x2); ext.cy = (y2); CT_Point2D chOff = t2d.chOff; chOff.x = (x1); chOff.y = (y1); CT_PositiveSize2D chExt = t2d.chExt; chExt.cx = (x2); chExt.cy = (y2); }
public static CT_GraphicalObjectFrame Prototype() { if (XSSFGraphicFrame.prototype == null) { CT_GraphicalObjectFrame graphicalObjectFrame = new CT_GraphicalObjectFrame(); CT_GraphicalObjectFrameNonVisual objectFrameNonVisual = graphicalObjectFrame.AddNewNvGraphicFramePr(); CT_NonVisualDrawingProps visualDrawingProps = objectFrameNonVisual.AddNewCNvPr(); visualDrawingProps.id = 0U; visualDrawingProps.name = "Diagramm 1"; objectFrameNonVisual.AddNewCNvGraphicFramePr(); CT_Transform2D ctTransform2D = graphicalObjectFrame.AddNewXfrm(); CT_PositiveSize2D ctPositiveSize2D = ctTransform2D.AddNewExt(); CT_Point2D ctPoint2D = ctTransform2D.AddNewOff(); ctPositiveSize2D.cx = 0L; ctPositiveSize2D.cy = 0L; ctPoint2D.x = 0L; ctPoint2D.y = 0L; graphicalObjectFrame.AddNewGraphic(); XSSFGraphicFrame.prototype = graphicalObjectFrame; } return(XSSFGraphicFrame.prototype); }
internal static CT_Picture Prototype() { CT_Picture pic = new CT_Picture(); CT_PictureNonVisual nvpr = pic.AddNewNvPicPr(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualDrawingProps nvProps = nvpr.AddNewCNvPr(); nvProps.id = (1); nvProps.name = ("Picture 1"); nvProps.descr = ("Picture"); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_NonVisualPictureProperties nvPicProps = nvpr.AddNewCNvPicPr(); nvPicProps.AddNewPicLocks().noChangeAspect = true; NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_BlipFillProperties blip = pic.AddNewBlipFill(); blip.AddNewBlip().embed = ""; blip.AddNewStretch().AddNewFillRect(); NPOI.OpenXmlFormats.Dml.Spreadsheet.CT_ShapeProperties sppr = pic.AddNewSpPr(); CT_Transform2D t2d = sppr.AddNewXfrm(); CT_PositiveSize2D ext = t2d.AddNewExt(); //should be original picture width and height expressed in EMUs ext.cx = (0); ext.cy = (0); CT_Point2D off = t2d.AddNewOff(); off.x = (0); off.y = (0); CT_PresetGeometry2D prstGeom = sppr.AddNewPrstGeom(); prstGeom.prst = (ST_ShapeType.rect); prstGeom.AddNewAvLst(); prototype = pic; return(prototype); }
public static CT_Connector Prototype() { if (XSSFConnector.prototype == null) { CT_Connector ctConnector = new CT_Connector(); CT_ConnectorNonVisual connectorNonVisual = ctConnector.AddNewNvCxnSpPr(); CT_NonVisualDrawingProps visualDrawingProps = connectorNonVisual.AddNewCNvPr(); visualDrawingProps.id = 1U; visualDrawingProps.name = "Shape 1"; connectorNonVisual.AddNewCNvCxnSpPr(); CT_ShapeProperties ctShapeProperties = ctConnector.AddNewSpPr(); CT_Transform2D ctTransform2D = ctShapeProperties.AddNewXfrm(); CT_PositiveSize2D ctPositiveSize2D = ctTransform2D.AddNewExt(); ctPositiveSize2D.cx = 0L; ctPositiveSize2D.cy = 0L; CT_Point2D ctPoint2D = ctTransform2D.AddNewOff(); ctPoint2D.x = 0L; ctPoint2D.y = 0L; CT_PresetGeometry2D presetGeometry2D = ctShapeProperties.AddNewPrstGeom(); presetGeometry2D.prst = ST_ShapeType.line; presetGeometry2D.AddNewAvLst(); CT_ShapeStyle ctShapeStyle = ctConnector.AddNewStyle(); ctShapeStyle.AddNewLnRef().AddNewSchemeClr().val = ST_SchemeColorVal.accent1; ctShapeStyle.lnRef.idx = 1U; CT_StyleMatrixReference styleMatrixReference1 = ctShapeStyle.AddNewFillRef(); styleMatrixReference1.idx = 0U; styleMatrixReference1.AddNewSchemeClr().val = ST_SchemeColorVal.accent1; CT_StyleMatrixReference styleMatrixReference2 = ctShapeStyle.AddNewEffectRef(); styleMatrixReference2.idx = 0U; styleMatrixReference2.AddNewSchemeClr().val = ST_SchemeColorVal.accent1; CT_FontReference ctFontReference = ctShapeStyle.AddNewFontRef(); ctFontReference.idx = ST_FontCollectionIndex.minor; ctFontReference.AddNewSchemeClr().val = ST_SchemeColorVal.tx1; XSSFConnector.prototype = ctConnector; } return(XSSFConnector.prototype); }
/** * Adds a picture to the run. This method handles * attaching the picture data to the overall file. * * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_EMF * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_WMF * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_PICT * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_JPEG * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_PNG * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_DIB * * @param pictureData The raw picture data * @param pictureType The type of the picture, eg {@link Document#PICTURE_TYPE_JPEG} * @param width width in EMUs. To convert to / from points use {@link org.apache.poi.util.Units} * @param height height in EMUs. To convert to / from points use {@link org.apache.poi.util.Units} * @throws NPOI.Openxml4j.exceptions.InvalidFormatException * @throws IOException */ public XWPFPicture AddPicture(Stream pictureData, int pictureType, String filename, int width, int height) { XWPFDocument doc = paragraph.GetDocument(); // Add the picture + relationship String relationId = doc.AddPictureData(pictureData, pictureType); XWPFPictureData picData = (XWPFPictureData)doc.GetRelationById(relationId); // Create the Drawing entry for it try { NPOI.OpenXmlFormats.Wordprocessing.CT_Drawing Drawing = run.AddNewDrawing(); CT_Inline inline = Drawing.AddNewInline(); // Do the fiddly namespace bits on the inline // (We need full control of what goes where and as what) //CT_GraphicalObject tmp = new CT_GraphicalObject(); //String xml = // "<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" + "\" />" + // "</a:graphicData>" + // "</a:graphic>"; //inline.Set((xml)); XmlDocument xmlDoc = new XmlDocument(); XmlElement el = xmlDoc.CreateElement("pic", "pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); inline.graphic = new CT_GraphicalObject(); inline.graphic.graphicData = new CT_GraphicalObjectData(); inline.graphic.graphicData.AddPicElement((XmlElement)el.Clone()); // Setup the inline inline.distT = (0); inline.distR = (0); inline.distB = (0); inline.distL = (0); CT_NonVisualDrawingProps docPr = inline.AddNewDocPr(); long id = GetParagraph().GetDocument().GetDrawingIdManager().ReserveNew(); docPr.id = (uint)(id); /* This name is not visible in Word 2010 anywhere. */ docPr.name = ("Drawing " + id); docPr.descr = (filename); CT_PositiveSize2D extent = inline.AddNewExtent(); extent.cx = (width); extent.cy = (height); // Grab the picture object CT_GraphicalObject graphic = inline.graphic; CT_GraphicalObjectData graphicData = graphic.graphicData; NPOI.OpenXmlFormats.Dml.Picture.CT_Picture pic = GetCTPictures(graphicData)[(0)]; // Set it up NPOI.OpenXmlFormats.Dml.Picture.CT_PictureNonVisual nvPicPr = pic.AddNewNvPicPr(); CT_NonVisualDrawingProps cNvPr = nvPicPr.AddNewCNvPr(); /* use "0" for the id. See ECM-576, 20.2.2.3 */ cNvPr.id = (0); /* This name is not visible in Word 2010 anywhere */ cNvPr.name = ("Picture " + id); cNvPr.descr = (filename); CT_NonVisualPictureProperties cNvPicPr = nvPicPr.AddNewCNvPicPr(); cNvPicPr.AddNewPicLocks().noChangeAspect = true; CT_BlipFillProperties blipFill = pic.AddNewBlipFill(); CT_Blip blip = blipFill.AddNewBlip(); blip.embed = (picData.GetPackageRelationship().Id); blipFill.AddNewStretch().AddNewFillRect(); CT_ShapeProperties spPr = pic.AddNewSpPr(); CT_Transform2D xfrm = spPr.AddNewXfrm(); CT_Point2D off = xfrm.AddNewOff(); off.x = (0); off.y = (0); CT_PositiveSize2D ext = xfrm.AddNewExt(); ext.cx = (width); ext.cy = (height); CT_PresetGeometry2D prstGeom = spPr.AddNewPrstGeom(); prstGeom.prst = (ST_ShapeType.rect); prstGeom.AddNewAvLst(); // Finish up XWPFPicture xwpfPicture = new XWPFPicture(pic, this); pictures.Add(xwpfPicture); return(xwpfPicture); } catch (Exception e) { throw new InvalidOperationException("", e); } }
public CT_PositiveSize2D AddNewExt() { this.extField = new CT_PositiveSize2D(); return this.extField; }
/** * Prototype with the default structure of a new auto-shape. */ internal static CT_Shape Prototype() { if (prototype == null) { CT_Shape shape = new CT_Shape(); CT_ShapeNonVisual nv = shape.AddNewNvSpPr(); CT_NonVisualDrawingProps nvp = nv.AddNewCNvPr(); nvp.id = (1); nvp.name = ("Shape 1"); nv.AddNewCNvSpPr(); CT_ShapeProperties sp = shape.AddNewSpPr(); CT_Transform2D t2d = sp.AddNewXfrm(); CT_PositiveSize2D p1 = t2d.AddNewExt(); p1.cx = (0); p1.cy = (0); CT_Point2D p2 = t2d.AddNewOff(); p2.x = (0); p2.y = (0); CT_PresetGeometry2D geom = sp.AddNewPrstGeom(); geom.prst = (ST_ShapeType.rect); geom.AddNewAvLst(); CT_ShapeStyle style = shape.AddNewStyle(); CT_SchemeColor scheme = style.AddNewLnRef().AddNewSchemeClr(); scheme.val = (ST_SchemeColorVal.accent1); scheme.AddNewShade().val = 50000; style.lnRef.idx = (2); CT_StyleMatrixReference Fillref = style.AddNewFillRef(); Fillref.idx = (1); Fillref.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1); CT_StyleMatrixReference effectRef = style.AddNewEffectRef(); effectRef.idx = (0); effectRef.AddNewSchemeClr().val = (ST_SchemeColorVal.accent1); CT_FontReference fontRef = style.AddNewFontRef(); fontRef.idx = (ST_FontCollectionIndex.minor); fontRef.AddNewSchemeClr().val = (ST_SchemeColorVal.lt1); CT_TextBody body = shape.AddNewTxBody(); CT_TextBodyProperties bodypr = body.AddNewBodyPr(); bodypr.anchor = (ST_TextAnchoringType.ctr); bodypr.rtlCol = (false); CT_TextParagraph p = body.AddNewP(); p.AddNewPPr().algn = (ST_TextAlignType.ctr); CT_TextCharacterProperties endPr = p.AddNewEndParaRPr(); endPr.lang = ("en-US"); endPr.sz = (1100); body.AddNewLstStyle(); prototype = shape; } return(prototype); }
/** * Calculate the preferred size for this picture. * * @param scale the amount by which image dimensions are multiplied relative to the original size. * @return XSSFClientAnchor with the preferred size for this image */ public IClientAnchor GetPreferredSize(double scale) { XSSFClientAnchor anchor = (XSSFClientAnchor)GetAnchor(); XSSFPictureData data = (XSSFPictureData)this.PictureData; Size size = GetImageDimension(data.GetPackagePart(), data.GetPictureType()); double scaledWidth = size.Width * scale; double scaledHeight = size.Height * scale; float w = 0; int col2 = anchor.Col1; int dx2 = 0; for (; ;) { w += GetColumnWidthInPixels(col2); if (w > scaledWidth) { break; } col2++; } if (w > scaledWidth) { double cw = GetColumnWidthInPixels(col2); double delta = w - scaledWidth; dx2 = (int)(EMU_PER_PIXEL * (cw - delta)); } anchor.Col2 = (col2); anchor.Dx2 = (dx2); double h = 0; int row2 = anchor.Row1; int dy2 = 0; for (; ;) { h += GetRowHeightInPixels(row2); if (h > scaledHeight) { break; } row2++; } if (h > scaledHeight) { double ch = GetRowHeightInPixels(row2); double delta = h - scaledHeight; dy2 = (int)(EMU_PER_PIXEL * (ch - delta)); } anchor.Row2 = (row2); anchor.Dy2 = (dy2); CT_PositiveSize2D size2d = ctPicture.spPr.xfrm.ext; size2d.cx = ((long)(scaledWidth * EMU_PER_PIXEL)); size2d.cy = ((long)(scaledHeight * EMU_PER_PIXEL)); return(anchor); }
public IClientAnchor GetPreferredSize(double scale) { XSSFClientAnchor anchor = (XSSFClientAnchor)this.GetAnchor(); XSSFPictureData pictureData = (XSSFPictureData)this.PictureData; Size imageDimension = XSSFPicture.GetImageDimension(pictureData.GetPackagePart(), pictureData.GetPictureType()); double num1 = (double)imageDimension.Width * scale; double num2 = (double)imageDimension.Height * scale; float num3 = 0.0f; int col1 = anchor.Col1; int num4 = 0; while (true) { num3 += this.GetColumnWidthInPixels(col1); if ((double)num3 <= num1) { ++col1; } else { break; } } if ((double)num3 > num1) { double columnWidthInPixels = (double)this.GetColumnWidthInPixels(col1); double num5 = (double)num3 - num1; num4 = (int)((double)XSSFShape.EMU_PER_PIXEL * (columnWidthInPixels - num5)); } anchor.Col2 = col1; anchor.Dx2 = num4; double num6 = 0.0; int row1 = anchor.Row1; int num7 = 0; while (true) { num6 += (double)this.GetRowHeightInPixels(row1); if (num6 <= num2) { ++row1; } else { break; } } if (num6 > num2) { double rowHeightInPixels = (double)this.GetRowHeightInPixels(row1); double num5 = num6 - num2; num7 = (int)((double)XSSFShape.EMU_PER_PIXEL * (rowHeightInPixels - num5)); } anchor.Row2 = row1; anchor.Dy2 = num7; CT_PositiveSize2D ext = this.ctPicture.spPr.xfrm.ext; ext.cx = (long)(num1 * (double)XSSFShape.EMU_PER_PIXEL); ext.cy = (long)(num2 * (double)XSSFShape.EMU_PER_PIXEL); return((IClientAnchor)anchor); }