public static string GetTextStyle <T>(IParagraphFormatEffectiveData format, TemplateContext <T> model)
        {
            string alignment        = TextHelper.GetHorizontalAlignmentStyle(format.Alignment);
            string lineSpacingStyle = TextHelper.GetLineSpacingStyle(format);

            return(string.Join(" ", alignment, lineSpacingStyle));
        }
Exemple #2
0
        public static void Run()
        {
            //ExStart:
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_Text();


            using (Presentation pres = new Presentation(dataDir + "Presentation1.pptx"))
            {
                IAutoShape shape = pres.Slides[0].Shapes[0] as IAutoShape;

                ITextStyleEffectiveData effectiveTextStyle = shape.TextFrame.TextFrameFormat.TextStyle.GetEffective();

                for (int i = 0; i <= 8; i++)
                {
                    IParagraphFormatEffectiveData effectiveStyleLevel = effectiveTextStyle.GetLevel(i);
                    Console.WriteLine("= Effective paragraph formatting for style level #" + i + " =");

                    Console.WriteLine("Depth: " + effectiveStyleLevel.Depth);
                    Console.WriteLine("Indent: " + effectiveStyleLevel.Indent);
                    Console.WriteLine("Alignment: " + effectiveStyleLevel.Alignment);
                    Console.WriteLine("Font alignment: " + effectiveStyleLevel.FontAlignment);
                }
            }

            //ExEnd:
        }
        public static string GetLineSpacingStyle(IParagraphFormatEffectiveData format)
        {
            string result = "";

            if (format.SpaceWithin != 100 && format.SpaceWithin != 90)
            {
                result = string.Format("line-height: {0};", format.SpaceWithin / 100);
            }

            return(result);
        }
        public static double[] GetParagraphMargins <T>(IParagraphFormatEffectiveData format, TextFrame parentTextFrame, SizeF parentContainerSize, TemplateContext <T> model)
        {
            Paragraph contextObject   = model.Object as Paragraph;
            var       textFrameFormat = parentTextFrame.TextFrameFormat.GetEffective();

            var firstPortionFormatEffective = (model.Object as Paragraph).Portions[0].PortionFormat.GetEffective();

            // left, top, right, bottom
            double[] margins = new double[] { format.MarginLeft + textFrameFormat.MarginLeft,
                                              0,
                                              format.MarginRight + textFrameFormat.MarginRight,
                                              0 };

            // margins adjustment for vertical text (...)
            switch (format.Alignment)
            {
            case TextAlignment.Center:
            case TextAlignment.Distributed:
            case TextAlignment.Justify:
            case TextAlignment.JustifyLow:
                if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical)
                {
                    margins[1] += (parentContainerSize.Height - contextObject.GetRect().Width) / 2;
                }
                else if (textFrameFormat.TextVerticalType == TextVerticalType.WordArtVertical)
                {
                    margins[1] = -((parentContainerSize.Height - contextObject.GetRect().Width) / 2);
                }
                else if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical270)
                {
                    margins[3] += (parentContainerSize.Height - contextObject.GetRect().Width) / 2;
                }
                break;

            case TextAlignment.Right:
                if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical)
                {
                    margins[1] += parentContainerSize.Height - contextObject.GetRect().Width;
                }
                break;

            case TextAlignment.Left:
                if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical270)
                {
                    margins[3] = parentContainerSize.Height - contextObject.GetRect().Width;
                }
                else if (textFrameFormat.TextVerticalType == TextVerticalType.WordArtVertical)
                {
                    margins[1] = -(parentContainerSize.Height - contextObject.GetRect().Width);
                }
                break;
            }

            switch (textFrameFormat.AnchoringType)
            {
            case TextAnchorType.Center:
            case TextAnchorType.Distributed:
            case TextAnchorType.Justified:
                if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical270)
                {
                    margins[2] = (parentContainerSize.Width - contextObject.GetRect().Height) / 2;
                }
                break;

            case TextAnchorType.Bottom:
                if (textFrameFormat.TextVerticalType == TextVerticalType.Vertical270)
                {
                    margins[2] = parentContainerSize.Width - contextObject.GetRect().Height;
                }
                break;
            }

            if ((textFrameFormat.TextVerticalType == TextVerticalType.Vertical || textFrameFormat.TextVerticalType == TextVerticalType.Vertical270) && parentTextFrame.Paragraphs.Count > 1)
            {
                margins[0] = 0;
                margins[2] = 0;
            }

            if (textFrameFormat.TextVerticalType == TextVerticalType.Horizontal)
            {
                double lineSpacingAdjustment = 0;
                if (firstPortionFormatEffective.FontHeight > 25)
                {
                    lineSpacingAdjustment = -firstPortionFormatEffective.FontHeight / 10;
                }

                margins[1] = lineSpacingAdjustment;
                margins[3] = lineSpacingAdjustment;
            }


            return(margins);
        }
        public static float GetPictureBulletSize <T>(IParagraphFormatEffectiveData format, TemplateContext <T> model)
        {
            var firstPortionFormatEffective = (model.Object as Paragraph).Portions[0].PortionFormat.GetEffective();

            return(format.Bullet.Height * firstPortionFormatEffective.FontHeight / 100 * 0.75f);
        }
 public static string GetPictureBulletStyle <T>(IParagraphFormatEffectiveData format, TemplateContext <T> model)
 {
     return(string.Format("width: {0}px; height: {0}px;", GetPictureBulletSize(format, model)));
 }
        public static string GetTextBulletStyle <T>(IParagraphFormatEffectiveData format, ITextFrameFormatEffectiveData textFrameFormat, bool isTableContent, TemplateContext <T> model)
        {
            var firstPortionFormatEffective = (model.Object as Paragraph).Portions[0].PortionFormat.GetEffective();

            string fontBoldItalicStyle = GetTextFontItalicStyle(firstPortionFormatEffective);

            string fontFill = "";

            switch (format.Bullet.Type)
            {
            case BulletType.Symbol:
            case BulletType.Numbered:
                if (format.Bullet.IsBulletHardColor)
                {
                    fontFill = string.Format("color: {0};", ColorHelper.GetRrbaColorString(format.Bullet.FillFormat.SolidFillColor));
                }
                else
                {
                    fontFill = FillHelper.GetFillStyle(firstPortionFormatEffective.FillFormat, model);
                    if (fontFill.StartsWith("background-color: "))
                    {
                        // fix for solid fill
                        fontFill = fontFill.Replace("background-color: ", "color: ");
                    }
                    else
                    {
                        // additional css for non-solid fills
                        fontFill += " -webkit-text-fill-color: transparent; -webkit-background-clip: text;";
                    }
                }
                break;

            case BulletType.Picture:
                // picture bullet
                break;
            }

            IFontData bulletFont = firstPortionFormatEffective.LatinFont;

            if (format.Bullet.IsBulletHardFont && format.Bullet.Type != BulletType.Numbered)
            {
                bulletFont = format.Bullet.Font;
            }

            var shadowFix = (textFrameFormat.TextVerticalType == TextVerticalType.Vertical || textFrameFormat.TextVerticalType == TextVerticalType.Vertical270 ? -1 : 1)
                            * (isTableContent ? 0.5f : 1);

            string outerShadowStyle = "";

            if (firstPortionFormatEffective.EffectFormat.OuterShadowEffect != null)
            {
                outerShadowStyle = string.Format("text-shadow: {0}px {1}px {2}px {3};",
                                                 shadowFix * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Distance * Math.Cos((Math.PI / 180) * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Direction),
                                                 shadowFix * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Distance * Math.Sin((Math.PI / 180) * firstPortionFormatEffective.EffectFormat.OuterShadowEffect.Direction),
                                                 firstPortionFormatEffective.EffectFormat.OuterShadowEffect.BlurRadius,
                                                 ColorHelper.GetRrbaColorString(firstPortionFormatEffective.EffectFormat.OuterShadowEffect.ShadowColor));
            }

            string fontHeightStyle = string.Format("font-size: {0}px;", format.Bullet.Height * firstPortionFormatEffective.FontHeight / 100);
            string fontFamilyStyle = string.Format("font-family: {0};", bulletFont);

            return(string.Join(" ", fontBoldItalicStyle, fontFill, outerShadowStyle, fontHeightStyle, fontFamilyStyle));
        }