Ejemplo n.º 1
0
        public DW.Anchor Create()
        {
            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
            };

            if (_editId != null)
                anchor.EditId = _editId;
            if (_anchorId != null)
                anchor.AnchorId = _anchorId;

            // warning <wp:anchor simplePos> and <wp:simplePos x="0" y="0"/> are mandatory
            anchor.SimplePos = _simplePos;
            // Simple Positioning Coordinates
            // <wp:simplePos x="0" y="0"/>
            anchor.SimplePosition = _simplePosition;

            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;

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

            // 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());

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

            Graphic graphic = new Graphic(_embeddedReference, _width, _height);
            graphic.Rotation = _rotation;
            graphic.HorizontalFlip = _horizontalFlip;
            graphic.VerticalFlip = _verticalFlip;
            graphic.CompressionState = _compressionState;
            graphic.PresetShape = _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;
        }
Ejemplo n.º 2
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);
        }