Пример #1
0
        public void GetPlaceholderType_Test()
        {
            var ms      = new MemoryStream(Properties.Resources._008);
            var xmlDoc  = PresentationDocument.Open(ms, false);
            var sldPart = xmlDoc.PresentationPart.SlideParts.First();
            var spId3   = sldPart.Slide.CommonSlideData.ShapeTree.Elements <DocumentFormat.OpenXml.Presentation.Shape>().Single(sp => sp.GetId() == 3);

            // ACT
            var phXml = PlaceholderLocationService.CreatePlaceholderData(spId3);

            // CLOSE
            xmlDoc.Close();

            // ASSERT
            Assert.Equal(PlaceholderType.DateAndTime, phXml.PlaceholderType);
        }
Пример #2
0
        /// <summary>
        /// Tries gets font height. Return null if font height is not defined.
        /// </summary>
        /// <param name="sdkCompositeElement">Placeholder element.</param>
        /// <param name="pLvl">Paragraph level.</param>
        /// <returns></returns>
        public int?TryGetFontHeight(OpenXmlCompositeElement sdkCompositeElement, int pLvl)  //TODO: use pattern Try
        {
            Check.NotNull(sdkCompositeElement, nameof(sdkCompositeElement));

            var paramPlaceholderData = PlaceholderLocationService.CreatePlaceholderData(sdkCompositeElement);

            // From slide layout element
            var lPlaceholder = _layoutPlaceholders.Value.FirstOrDefault(e => e.Equals(paramPlaceholderData));

            if (lPlaceholder != null && lPlaceholder.LvlFontHeights.ContainsKey(pLvl))
            {
                return(lPlaceholder.LvlFontHeights[pLvl]);
            }

            // From slide master element
            var mPlaceholder = _masterPlaceholders.Value.FirstOrDefault(e => e.Equals(paramPlaceholderData));

            if (mPlaceholder != null && mPlaceholder.LvlFontHeights.ContainsKey(pLvl))
            {
                return(mPlaceholder.LvlFontHeights[pLvl]);
            }

            // Title type
            var masterGlobalTextStyle = _sdkSldPart.SlideLayoutPart.SlideMasterPart.SlideMaster.TextStyles;

            if (paramPlaceholderData.PlaceholderType == PlaceholderType.Title)
            {
                return(masterGlobalTextStyle.TitleStyle.Level1ParagraphProperties.GetFirstChild <A.DefaultRunProperties>().FontSize.Value);
            }

            // Master body type placeholder settings
            if (_masterBodyFontHeights.Value.ContainsKey(pLvl))
            {
                return(_masterBodyFontHeights.Value[pLvl]);
            }

            return(null);
        }