コード例 #1
0
        private static string GetTextFontItalicStyle(IPortionFormatEffectiveData format)
        {
            string fontWeight = format.FontBold ? "font-weight: bold;" : "";
            string fontStyle  = format.FontItalic ? "font-style: italic;" : "";

            return(string.Join(" ", fontWeight, fontStyle));
        }
コード例 #2
0
        public static void Run()
        {
            //ExStart:GetEffectiveValues
            // 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;

                ITextFrameFormat localTextFrameFormat = shape.TextFrame.TextFrameFormat;
                ITextFrameFormatEffectiveData effectiveTextFrameFormat = localTextFrameFormat.GetEffective();

                IPortionFormat localPortionFormat = shape.TextFrame.Paragraphs[0].Portions[0].PortionFormat;
                IPortionFormatEffectiveData effectivePortionFormat = localPortionFormat.GetEffective();
            }

            //ExEnd:GetEffectiveValues
        }
コード例 #3
0
        public static string GetTextStyle <T>(IPortionFormatEffectiveData format, ITextFrameFormatEffectiveData textFrameFormat, bool isTableContent, TemplateContext <T> model)
        {
            float fontHeight = format.FontHeight;

            string fontFillStyle = FillHelper.GetFillStyle(format.FillFormat, model);

            if (fontFillStyle.StartsWith("background-color: "))
            {
                // fix for solid fill
                fontFillStyle = fontFillStyle.Replace("background-color: ", "color: ");
            }
            else
            {
                // additional css for non-solid fills
                fontFillStyle += " -webkit-text-fill-color: transparent; -webkit-background-clip: text;";
            }

            string escapedTextStyle = "";

            if (format.Escapement != 0)
            {
                escapedTextStyle = string.Format("position: relative; top: {0}px;", -fontHeight * format.Escapement / 100);
                fontHeight      *= 0.67f;
            }

            string textDecorationStyle = "";

            if (format.StrikethroughType != TextStrikethroughType.None)
            {
                string underlineStyle = "";
                switch (format.StrikethroughType)
                {
                case TextStrikethroughType.Double:
                    underlineStyle = "double";
                    break;

                default:
                    underlineStyle = "solid";
                    break;
                }

                textDecorationStyle = string.Format("text-decoration: line-through {0};", underlineStyle);
            }

            if (format.FontUnderline != TextUnderlineType.None)
            {
                string underlineStyle = "";
                switch (format.FontUnderline)
                {
                case TextUnderlineType.Dotted:
                case TextUnderlineType.HeavyDotted:
                    underlineStyle = "dotted";
                    break;

                case TextUnderlineType.Dashed:
                case TextUnderlineType.DotDash:
                case TextUnderlineType.DotDotDash:
                case TextUnderlineType.LongDashed:
                case TextUnderlineType.HeavyDashed:
                case TextUnderlineType.HeavyDotDash:
                case TextUnderlineType.HeavyDotDotDash:
                case TextUnderlineType.HeavyLongDashed:
                    underlineStyle = "dashed";
                    break;

                case TextUnderlineType.Wavy:
                case TextUnderlineType.DoubleWavy:
                case TextUnderlineType.HeavyWavy:
                    underlineStyle = "wavy";
                    break;

                case TextUnderlineType.Double:
                    underlineStyle = "double";
                    break;

                default:
                    underlineStyle = "solid";
                    break;
                }

                textDecorationStyle = string.Format("text-decoration: underline {0} {1};", underlineStyle, ColorHelper.GetRrbaColorString(format.UnderlineFillFormat.SolidFillColor));
            }

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

            string outerShadowStyle = "";

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

            string strokeStyle = "";

            if (format.LineFormat.FillFormat.FillType == FillType.Solid)
            {
                strokeStyle = string.Format("-webkit-text-stroke: {0}px {1};", format.LineFormat.Width, ColorHelper.GetRrbaColorString(format.LineFormat.FillFormat.SolidFillColor));
            }
            else if (format.LineFormat.FillFormat.FillType == FillType.Gradient)
            {
                strokeStyle = "";
            }

            string spacingStyle = "";

            if (format.Spacing != 0)
            {
                spacingStyle = string.Format("letter-spacing: {0}px;", format.Spacing);
            }

            string fontBoldItalicStyle = GetTextFontItalicStyle(format);
            string fontFamilyStyle     = string.Format("font-family: {0};", format.LatinFont);
            string fontHeightStyle     = string.Format("font-size: {0}px;", fontHeight);
            string fontCapStyle        = "";

            if (format.TextCapType == TextCapType.All)
            {
                fontCapStyle = "text-transform: uppercase;";
            }
            else if (format.TextCapType == TextCapType.Small)
            {
                fontCapStyle = "font-variant: small-caps;";
            }

            return(string.Join(" ",
                               fontBoldItalicStyle,
                               fontFamilyStyle,
                               fontHeightStyle,
                               fontFillStyle,
                               escapedTextStyle,
                               textDecorationStyle,
                               outerShadowStyle,
                               strokeStyle,
                               spacingStyle,
                               fontCapStyle));
        }