예제 #1
0
        private List <PlaceholderLocationData> GetPlaceholders(IEnumerable <OpenXmlCompositeElement> compositeElements)
        {
            var filtered = Filter(compositeElements);
            var result   = new List <PlaceholderLocationData>(filtered.Count());

            foreach (var el in filtered)
            {
                var spPr    = el.Descendants <P.ShapeProperties>().Single();
                var t2d     = spPr.Transform2D;
                var phXml   = PlaceholderDataFrom(el);
                var newPhSl = new PlaceholderLocationData(phXml)
                {
                    X      = t2d.Offset.X.Value,
                    Y      = t2d.Offset.Y.Value,
                    Width  = t2d.Extents.Cx.Value,
                    Height = t2d.Extents.Cy.Value
                };

                // avoid duplicate non-custom placeholders
                if (result.Any(p => p.Equals(newPhSl)))
                {
                    continue;
                }

                result.Add(newPhSl);
            }

            return(result);
        }
예제 #2
0
        private List <PlaceholderLocationData> GetPlaceholders(IEnumerable <OpenXmlCompositeElement> compositeElements)
        {
            var filtered = Filter(compositeElements);
            var result   = new List <PlaceholderLocationData>(filtered.Count());

            foreach (var el in filtered)
            {
                var placeholderData = CreatePlaceholderData(el);
                // avoid duplicate non-custom placeholders
                if (result.Any(p => p.Equals(placeholderData)))
                {
                    continue;
                }

                var spPr = el.Descendants <P.ShapeProperties>().First();
                var t2D  = spPr.Transform2D;
                var placeholderLocationData = new PlaceholderLocationData(placeholderData)
                {
                    X      = t2D.Offset.X.Value,
                    Y      = t2D.Offset.Y.Value,
                    Width  = t2D.Extents.Cx.Value,
                    Height = t2D.Extents.Cy.Value
                };

                var presetGeometry = spPr.GetFirstChild <PresetGeometry>();
                if (presetGeometry != null)
                {
                    var name = presetGeometry.Preset.Value.ToString();
                    Enum.TryParse(name, true, out GeometryType geometryType);
                    placeholderLocationData.Geometry = geometryType;
                }

                result.Add(placeholderLocationData);
            }

            return(result);
        }