Esempio n. 1
0
        // SLFont takes on extra duties so you don't have to learn more classes. Just like SLRstType.
        internal A.Paragraph ToParagraph()
        {
            A.Paragraph para = new A.Paragraph();
            para.ParagraphProperties = new A.ParagraphProperties();

            A.DefaultRunProperties defrunprops = new A.DefaultRunProperties();

            string sFont = string.Empty;

            if (this.FontName != null && this.FontName.Length > 0)
            {
                sFont = this.FontName;
            }

            if (this.HasFontScheme)
            {
                if (this.FontScheme == FontSchemeValues.Major)
                {
                    sFont = "+mj-lt";
                }
                else if (this.FontScheme == FontSchemeValues.Minor)
                {
                    sFont = "+mn-lt";
                }
            }

            if (this.HasFontColor)
            {
                SLA.SLColorTransform clr = new SLA.SLColorTransform(new List <System.Drawing.Color>());
                if (this.clrFontColor.Rgb != null && this.clrFontColor.Rgb.Length > 0)
                {
                    clr.SetColor(SLTool.ToColor(this.clrFontColor.Rgb), 0);

                    defrunprops.Append(new A.SolidFill()
                    {
                        RgbColorModelHex = clr.ToRgbColorModelHex()
                    });
                }
                else if (this.clrFontColor.Theme != null)
                {
                    // potential casting error? If the SLFont class was set properly, there shouldn't be errors...
                    SLThemeColorIndexValues themeindex = (SLThemeColorIndexValues)this.clrFontColor.Theme.Value;
                    if (this.clrFontColor.Tint != null)
                    {
                        clr.SetColor(themeindex, this.clrFontColor.Tint.Value, 0);
                    }
                    else
                    {
                        clr.SetColor(themeindex, 0, 0);
                    }

                    defrunprops.Append(new A.SolidFill()
                    {
                        SchemeColor = clr.ToSchemeColor()
                    });
                }
            }

            if (sFont.Length > 0)
            {
                defrunprops.Append(new A.LatinFont()
                {
                    Typeface = sFont
                });
            }

            if (this.FontSize != null)
            {
                defrunprops.FontSize = (int)(this.FontSize.Value * 100);
            }

            if (this.Bold != null)
            {
                defrunprops.Bold = this.Bold.Value;
            }

            if (this.Italic != null)
            {
                defrunprops.Italic = this.Italic.Value;
            }

            if (this.HasUnderline)
            {
                if (this.Underline == UnderlineValues.Single || this.Underline == UnderlineValues.SingleAccounting)
                {
                    defrunprops.Underline = A.TextUnderlineValues.Single;
                }
                else if (this.Underline == UnderlineValues.Double || this.Underline == UnderlineValues.DoubleAccounting)
                {
                    defrunprops.Underline = A.TextUnderlineValues.Double;
                }
            }

            if (this.Strike != null)
            {
                defrunprops.Strike = this.Strike.Value ? A.TextStrikeValues.SingleStrike : A.TextStrikeValues.NoStrike;
            }

            if (this.HasVerticalAlignment)
            {
                if (this.VerticalAlignment == VerticalAlignmentRunValues.Superscript)
                {
                    defrunprops.Baseline = 30000;
                }
                else if (this.VerticalAlignment == VerticalAlignmentRunValues.Subscript)
                {
                    defrunprops.Baseline = -25000;
                }
                else
                {
                    defrunprops.Baseline = 0;
                }
            }

            para.ParagraphProperties.Append(defrunprops);

            return(para);
        }
Esempio n. 2
0
        // SLFont takes on extra duties so you don't have to learn more classes. Just like SLRstType.
        internal A.Paragraph ToParagraph()
        {
            A.Paragraph para = new A.Paragraph();
            para.ParagraphProperties = new A.ParagraphProperties();

            A.DefaultRunProperties defrunprops = new A.DefaultRunProperties();

            string sFont = string.Empty;
            if (this.FontName.Length > 0) sFont = this.FontName;

            if (this.HasFontScheme)
            {
                if (this.FontScheme == FontSchemeValues.Major) sFont = "+mj-lt";
                else if (this.FontScheme == FontSchemeValues.Minor) sFont = "+mn-lt";
            }

            if (this.HasFontColor)
            {
                SLA.SLColorTransform clr = new SLA.SLColorTransform(new List<System.Drawing.Color>());
                if (this.clrFontColor.Rgb != null && this.clrFontColor.Rgb.Length > 0)
                {
                    clr.SetColor(SLTool.ToColor(this.clrFontColor.Rgb), 0);

                    defrunprops.Append(new A.SolidFill()
                    {
                        RgbColorModelHex = clr.ToRgbColorModelHex()
                    });
                }
                else if (this.clrFontColor.Theme != null)
                {
                    // potential casting error? If the SLFont class was set properly, there shouldn't be errors...
                    SLThemeColorIndexValues themeindex = (SLThemeColorIndexValues)this.clrFontColor.Theme.Value;
                    if (this.clrFontColor.Tint != null)
                    {
                        clr.SetColor(themeindex, this.clrFontColor.Tint.Value, 0);
                    }
                    else
                    {
                        clr.SetColor(themeindex, 0, 0);
                    }

                    defrunprops.Append(new A.SolidFill()
                    {
                        SchemeColor = clr.ToSchemeColor()
                    });
                }
            }

            if (sFont.Length > 0) defrunprops.Append(new A.LatinFont() { Typeface = sFont });

            if (this.FontSize != null) defrunprops.FontSize = (int)(this.FontSize.Value * 100);

            if (this.Bold != null) defrunprops.Bold = this.Bold.Value;

            if (this.Italic != null) defrunprops.Italic = this.Italic.Value;

            if (this.HasUnderline)
            {
                if (this.Underline == UnderlineValues.Single || this.Underline == UnderlineValues.SingleAccounting)
                {
                    defrunprops.Underline = A.TextUnderlineValues.Single;
                }
                else if (this.Underline == UnderlineValues.Double || this.Underline == UnderlineValues.DoubleAccounting)
                {
                    defrunprops.Underline = A.TextUnderlineValues.Double;
                }
            }

            if (this.Strike != null)
            {
                defrunprops.Strike = this.Strike.Value ? A.TextStrikeValues.SingleStrike : A.TextStrikeValues.NoStrike;
            }

            if (this.HasVerticalAlignment)
            {
                if (this.VerticalAlignment == VerticalAlignmentRunValues.Superscript)
                {
                    defrunprops.Baseline = 30000;
                }
                else if (this.VerticalAlignment == VerticalAlignmentRunValues.Subscript)
                {
                    defrunprops.Baseline = -25000;
                }
                else
                {
                    defrunprops.Baseline = 0;
                }
            }

            para.ParagraphProperties.Append(defrunprops);

            return para;
        }