예제 #1
0
        public DW.Anchor Create()
        {
            int width;
            int height;

            zimg.CalculateImageWidthHeight(_pictureElement.File, _pictureElement.Width, _pictureElement.Height, out width, out height);
            long emuWidth  = OXmlTools.PixelToEmus(width);
            long emuHeight = OXmlTools.PixelToEmus(height);

            //DW.Anchor anchor = new DW.Anchor()
            //{
            //    DistanceFromTop = _distanceFromTop,
            //    DistanceFromBottom = _distanceFromBottom,
            //    DistanceFromLeft = _distanceFromLeft,
            //    DistanceFromRight = _distanceFromRight,
            //    RelativeHeight = _relativePosition,
            //    BehindDoc = _behindDoc,
            //    LayoutInCell = _layoutInCell,
            //    AllowOverlap = _allowOverlap,
            //    Locked = _locked,
            //    Hidden = _hidden
            //};

            DW.Anchor anchor = new DW.Anchor();

            OXmlAnchorPictureDrawing pictureDrawing = (OXmlAnchorPictureDrawing)_pictureElement.PictureDrawing;

            if (pictureDrawing.AnchorId != null)
            {
                anchor.AnchorId = pictureDrawing.AnchorId;
            }
            if (pictureDrawing.EditId != null)
            {
                anchor.EditId = pictureDrawing.EditId;
            }

            if (pictureDrawing.DistanceFromTop != null)
            {
                anchor.DistanceFromTop = (uint)pictureDrawing.DistanceFromTop;
            }
            if (pictureDrawing.DistanceFromBottom != null)
            {
                anchor.DistanceFromBottom = (uint)pictureDrawing.DistanceFromBottom;
            }
            if (pictureDrawing.DistanceFromLeft != null)
            {
                anchor.DistanceFromLeft = (uint)pictureDrawing.DistanceFromLeft;
            }
            if (pictureDrawing.DistanceFromRight != null)
            {
                anchor.DistanceFromRight = (uint)pictureDrawing.DistanceFromRight;
            }

            OXmlHorizontalPosition oxmlHorizontalPosition = pictureDrawing.HorizontalPosition;

            DW.HorizontalPosition horizontalPosition = new DW.HorizontalPosition();
            horizontalPosition.RelativeFrom = oxmlHorizontalPosition.RelativeFrom;
            if (oxmlHorizontalPosition.PositionOffset != null)
            {
                horizontalPosition.PositionOffset = new DW.PositionOffset(OXmlTools.PixelToEmus((int)oxmlHorizontalPosition.PositionOffset).ToString());
            }
            if (oxmlHorizontalPosition.HorizontalAlignment != null)
            {
                horizontalPosition.HorizontalAlignment = new DW.HorizontalAlignment(oxmlHorizontalPosition.HorizontalAlignment);
            }
            anchor.HorizontalPosition = horizontalPosition;

            OXmlVerticalPosition oxmlVerticalPosition = pictureDrawing.VerticalPosition;

            DW.VerticalPosition verticalPosition = new DW.VerticalPosition();
            verticalPosition.RelativeFrom = oxmlVerticalPosition.RelativeFrom;
            if (oxmlVerticalPosition.PositionOffset != null)
            {
                verticalPosition.PositionOffset = new DW.PositionOffset(OXmlTools.PixelToEmus((int)oxmlVerticalPosition.PositionOffset).ToString());
            }
            if (oxmlVerticalPosition.VerticalAlignment != null)
            {
                verticalPosition.VerticalAlignment = new DW.VerticalAlignment(oxmlVerticalPosition.VerticalAlignment);
            }
            anchor.VerticalPosition = verticalPosition;

            if (pictureDrawing.EffectExtent != null)
            {
                anchor.EffectExtent = pictureDrawing.EffectExtent.ToEffectExtent();
            }

            // mandatory
            anchor.AllowOverlap = pictureDrawing.AllowOverlap;
            // mandatory
            anchor.BehindDoc = pictureDrawing.BehindDoc;
            // not mandatory
            anchor.Hidden = pictureDrawing.Hidden;
            // mandatory
            anchor.LayoutInCell = pictureDrawing.LayoutInCell;
            // mandatory
            anchor.Locked = pictureDrawing.Locked;
            // mandatory
            anchor.RelativeHeight = (uint)pictureDrawing.RelativeHeight;

            // warning <wp:anchor simplePos> and <wp:simplePos x="0" y="0"/> are mandatory
            if (pictureDrawing.SimplePosition != null)
            {
                anchor.SimplePos = true;
                // Simple Positioning Coordinates, <wp:simplePos x="0" y="0"/>
                anchor.SimplePosition = new DW.SimplePosition {
                    X = pictureDrawing.SimplePosition.X, Y = pictureDrawing.SimplePosition.Y
                };
            }
            else
            {
                anchor.SimplePos      = false;
                anchor.SimplePosition = new DW.SimplePosition {
                    X = 0, Y = 0
                };
            }

            // Inline Drawing Object Extents
            //   Cx : Extent Length ???
            //   Cy : Extent Width ???
            // <wp:extent cx="3576638" cy="3570696"/>
            anchor.Extent = new DW.Extent()
            {
                Cx = emuWidth, Cy = emuHeight
            };


            //if (_horizontalPosition != null)
            //    // Horizontal Positioning
            //    // <wp:positionH relativeFrom="margin">
            //    //   <wp:posOffset>-38099</wp:posOffset>
            //    // </wp:positionH>
            //    anchor.HorizontalPosition = _horizontalPosition;

            //if (_verticalPosition != null)
            //    // Vertical Positioning
            //    // <wp:positionV relativeFrom="paragraph">
            //    //   <wp:posOffset>723900</wp:posOffset>
            //    // </wp:positionV>
            //    anchor.VerticalPosition = _verticalPosition;


            // Object Extents Including Effects
            //   BottomEdge : Additional Extent on Bottom Edge (b)
            //   LeftEdge   : Additional Extent on Left Edge (l)
            //   RightEdge  : Additional Extent on Right Edge (r)
            //   TopEdge    : Additional Extent on Top Edge (t)
            // <wp:effectExtent b="0" l="0" r="0" t="0"/>
            //if (_effectExtent == null)
            //    _effectExtent = new DW.EffectExtent();
            // <wp:effectExtent> is not mandatory
            //if (_effectExtent != null)
            //    anchor.EffectExtent = _effectExtent;

            //if (_wrapElement == null)
            //    SetWrapNone();
            //anchor.AppendChild(_wrapElement);
            anchor.AppendChild(CreateWrap(pictureDrawing.Wrap));

            // <wp:docPr> Non-Visual Properties, possible child : HyperlinkOnClick <a:hlinkClick> HyperlinkOnHover <a:hlinkHover> NonVisualDrawingPropertiesExtensionList <a:extLst>
            // <wp:docPr id="1" name="Picture1" title="" descr=""/>
            // Title = _title
            anchor.AppendChild(new DW.DocProperties()
            {
                Id = _id, Name = _name, Description = _pictureElement.Description
            });

            Graphic graphic = new Graphic(_embeddedReference, emuWidth, emuHeight);

            graphic.Rotation         = _pictureElement.Rotation;
            graphic.HorizontalFlip   = _pictureElement.HorizontalFlip;
            graphic.VerticalFlip     = _pictureElement.VerticalFlip;
            graphic.CompressionState = _pictureElement.CompressionState;
            graphic.PresetShape      = _pictureElement.PresetShape;
            anchor.AppendChild(graphic.Create());

            //if (_relativeHeight != null)
            //    // <wp14:sizeRelV> RelativeHeight (Office2010 or above),
            //    anchor.AppendChild(_relativeHeight);
            //if (_relativeWidth != null)
            //    // <wp14:sizeRelH> RelativeWidth (Office2010 or above), possible child : PercentageWidth <wp14:pctWidth>
            //    anchor.AppendChild(_relativeWidth);

            return(anchor);
        }
예제 #2
0
파일: OXmlDoc.cs 프로젝트: 24/source_04
        private ODW.Inline CreateInlineDrawing_v2()
        {
            int width;
            int height;

            zimg.CalculateImageWidthHeight(_pictureElement.File, _pictureElement.Width, _pictureElement.Height, out width, out height);
            long emuWidth  = OXmlTools.PixelToEmus(width);
            long emuHeight = OXmlTools.PixelToEmus(height);

            // DW.Inline.EditId : ??? (<wp:inline wp14:editId="">)

            //if (_name == null)
            //    throw new PBException("missing image name");
            //if (width != null && height == null)
            //    throw new PBException("missing height (width has a value)");
            //if (width == null && height != null)
            //    throw new PBException("missing width (height has a value)");

            // <wp:inline>
            ODW.Inline inline = new ODW.Inline()
            {
                DistanceFromTop    = 0, // distT
                DistanceFromBottom = 0, // distB
                DistanceFromLeft   = 0, // distL
                DistanceFromRight  = 0  // distR
                                        //EditId = "50D07946"         // wp14:editId
            };

            // <wp:extent>
            inline.AppendChild(new ODW.Extent()
            {
                Cx = emuWidth, Cy = emuHeight
            });
            // <wp:effectExtent>
            inline.AppendChild(new ODW.EffectExtent()
            {
                LeftEdge = 0L, TopEdge = 0L, RightEdge = 0L, BottomEdge = 0L
            });
            // <wp:docPr>
            // Id = (UInt32Value)1U, Name = "Picture 1"
            inline.AppendChild(new ODW.DocProperties()
            {
                Id = _id, Name = _name, Description = _pictureElement.Description
            });
            // <wp:cNvGraphicFramePr>, <a:graphicFrameLocks>          { NoChangeAspect = true }
            inline.AppendChild(new ODW.NonVisualGraphicFrameDrawingProperties(new OA.GraphicFrameLocks()));

            // <a:graphic>
            OA.Graphic graphic = new OA.Graphic();
            // <a:graphicData>
            OA.GraphicData graphicData = new OA.GraphicData()
            {
                Uri = "http://schemas.openxmlformats.org/drawingml/2006/picture"
            };
            // <pic:pic>
            ODP.Picture picture = new ODP.Picture();

            // <pic:nvPicPr>
            ODP.NonVisualPictureProperties pictureProperties = new ODP.NonVisualPictureProperties();
            // <pic:cNvPr>
            pictureProperties.AppendChild(new ODP.NonVisualDrawingProperties()
            {
                Id = (UInt32Value)0U, Name = "Image"
            });
            // <pic:cNvPicPr>
            pictureProperties.AppendChild(new ODP.NonVisualPictureDrawingProperties());
            picture.AppendChild(pictureProperties);

            // <pic:blipFill>
            ODP.BlipFill blipFill = new ODP.BlipFill();

            // <a:blip>
            // CompressionState = A.BlipCompressionValues.Print
            OA.Blip blip = new OA.Blip()
            {
                Embed = _embeddedReference, CompressionState = _pictureElement.CompressionState
            };

            // $$pb todo comment
            // <a:extLst>
            OA.BlipExtensionList blipExtensions = new OA.BlipExtensionList();
            // <a:ext>
            blipExtensions.AppendChild(new OA.BlipExtension()
            {
                Uri = "{28A0092B-C50C-407E-A947-70E740481C1C}"
            });
            blip.AppendChild(blipExtensions);
            // $$pb todo comment end

            blipFill.AppendChild(blip);

            // <a:stretch>
            OA.Stretch stretch = new OA.Stretch();
            // <a:fillRect>
            stretch.AppendChild(new OA.FillRectangle());
            blipFill.AppendChild(stretch);

            picture.AppendChild(blipFill);

            // <pic:spPr>
            ODP.ShapeProperties shapeProperties = new ODP.ShapeProperties();

            // <a:xfrm>
            OA.Transform2D transform2D = new OA.Transform2D();
            // new A.Offset
            // <a:off>
            transform2D.AppendChild(new OA.Offset()
            {
                X = 0L, Y = 0L
            });
            // <a:ext>
            transform2D.AppendChild(new OA.Extents()
            {
                Cx = emuWidth, Cy = emuHeight
            });
            shapeProperties.AppendChild(transform2D);

            // <a:prstGeom>
            // Preset = A.ShapeTypeValues.Rectangle
            OA.PresetGeometry presetGeometry = new OA.PresetGeometry()
            {
                Preset = _pictureElement.PresetShape
            };
            // <a:avLst>
            presetGeometry.AppendChild(new OA.AdjustValueList());
            shapeProperties.AppendChild(presetGeometry);

            picture.AppendChild(shapeProperties);

            graphicData.AppendChild(picture);
            graphic.AppendChild(graphicData);
            inline.AppendChild(graphic);

            return(inline);
        }