Ejemplo n.º 1
0
        /// <summary>フォントの取得</summary>
        /// <param name="name">フォント名 全角 半角の違いに気を付ける</param>
        /// <param name="size">フォントサイズ</param>
        /// <param name="color">フォントの前景色</param>
        /// <param name="familyNumbering">フォントファミリー
        /// 1:Roman プロポーショナルフォントかつ serif
        /// 2:Swiss プロポーショナルフォントかつ sans-serif
        /// 3:Mordern 等幅フォント
        /// 4:Script 手書き風
        /// 5:Decorative カリグラフィーなどの装飾フォント
        ///
        /// serif 文字ストロークの端にある小さな飾り
        /// フォント名で適切なフォントを解決できない場合、上記に沿って 代替フォントを決定する
        /// </param>
        /// <param name="charSet">キャラクターセット 128: shift-jis
        /// フォント名で適切なフォントを解決できない場合、上記に沿って 代替フォントを決定する
        /// ※ 日本語の表記可能なフォントが設定されるらしい
        /// </param>
        /// <returns></returns>
        public static Font GetFont(FontName name             = null,
                                   FontSize size             = null,
                                   Color color               = null,
                                   int familyNumbering       = 3,
                                   int charSet               = 128,
                                   UnderlineValues underline = UnderlineValues.None)
        {
            var font = new Font
            {
                FontName            = name ?? DefaultFontName,
                FontSize            = size ?? DefaultFontSize,
                FontFamilyNumbering = new FontFamilyNumbering   {
                    Val = familyNumbering
                },
                FontCharSet = new FontCharSet           {
                    Val = charSet
                },
                Underline = new Underline             {
                    Val = underline
                }
            };

            if (color != null)
            {
                font.Color = color;
            }
            return(font);
        }
Ejemplo n.º 2
0
 protected void FindAndReplace(ref int i, List<Run> runs, string textToReplace, string newText, UnderlineValues underlineValue = UnderlineValues.Single)
 {
     for (; i < runs.Count(); i++)
     {
         var run = runs[i];
         var itemOld = FindByInnerText(run, textToReplace);
         if (itemOld == null)
         {
             continue;
         }
         run.RunProperties.Underline = new Underline() { Val = underlineValue };
         Replace(itemOld, textToReplace, newText);
         return;
     }
 }
Ejemplo n.º 3
0
 private void SetAllNull()
 {
     this.FontName           = null;
     this.CharacterSet       = null;
     this.FontFamily         = null;
     this.Bold               = null;
     this.Italic             = null;
     this.Strike             = null;
     this.Outline            = null;
     this.Shadow             = null;
     this.Condense           = null;
     this.Extend             = null;
     this.clrFontColor       = new SLColor(this.listThemeColors, this.listIndexedColors);
     HasFontColor            = false;
     this.FontSize           = null;
     this.vUnderline         = UnderlineValues.None;
     HasUnderline            = false;
     this.vVerticalAlignment = VerticalAlignmentRunValues.Baseline;
     HasVerticalAlignment    = false;
     this.vFontScheme        = FontSchemeValues.None;
     HasFontScheme           = false;
 }
Ejemplo n.º 4
0
 private void SetAllNull()
 {
     FontName             = null;
     CharacterSet         = null;
     FontFamily           = null;
     Bold                 = null;
     Italic               = null;
     Strike               = null;
     Outline              = null;
     Shadow               = null;
     Condense             = null;
     Extend               = null;
     clrFontColor         = new SLColor(listThemeColors, listIndexedColors);
     HasFontColor         = false;
     FontSize             = null;
     vUnderline           = UnderlineValues.None;
     HasUnderline         = false;
     vVerticalAlignment   = VerticalAlignmentRunValues.Baseline;
     HasVerticalAlignment = false;
     vFontScheme          = FontSchemeValues.None;
     HasFontScheme        = false;
 }
Ejemplo n.º 5
0
        private void SetFont(double size, string fontName, int fontFamilyId, bool bold, bool italic, UnderlineValues underlineValue, string fontColor = null)
        {
            Font font = new Font();

            font.FontSize = new FontSize()
            {
                Val = DoubleValue.FromDouble(size)
            };
            font.FontName = new FontName()
            {
                Val = StringValue.FromString(fontName)
            };
            font.FontFamilyNumbering = new FontFamilyNumbering()
            {
                Val = Int32Value.FromInt32(fontFamilyId)
            };
            font.Bold = new Bold()
            {
                Val = BooleanValue.FromBoolean(bold)
            };
            font.Italic = new Italic()
            {
                Val = BooleanValue.FromBoolean(italic)
            };
            font.Underline = new Underline()
            {
                Val = new EnumValue <UnderlineValues>(underlineValue)
            };
            if (!string.IsNullOrEmpty(fontColor))
            {
                font.Color = new Color()
                {
                    Rgb = fontColor
                };
            }

            //font.FontScheme = new FontScheme() { Val = new EnumValue<FontSchemeValues>(fontScheme) };
            //font.Color = new Color() { Theme = UInt32Value.FromUInt32(colorSchemeId) };

            ActualFonts.Append(font);
            SetFontsCount();
        }
Ejemplo n.º 6
0
 protected void FindAndReplace(ref int i, List <Run> runs, string textToReplace, string newText, UnderlineValues underlineValue = UnderlineValues.Single)
 {
     for (; i < runs.Count(); i++)
     {
         var run     = runs[i];
         var itemOld = FindByInnerText(run, textToReplace);
         if (itemOld == null)
         {
             continue;
         }
         run.RunProperties.Underline = new Underline()
         {
             Val = underlineValue
         };
         Replace(itemOld, textToReplace, newText);
         return;
     }
 }
        /// <summary>
        /// Add a style to the document
        /// </summary>
        /// <param name="isBold"> true --> bold; false --> not bold</param>
        /// <param name="isItalic"> true --> italic; false --> not italic </param>
        /// <param name="isUnderline"> true --> underline; false --> not underline </param>
        /// <param name="isOnlyRun"> If is true, return only a simple run, else do the other settings </param>
        /// <param name="rgbColor"> Text color of the run </param>
        /// <param name="underline"> Underline style </param>
        /// <returns></returns>
        public RunProperties AddStyle(MainDocumentPart mainPart, bool isBold = false, bool isItalic = false, bool isUnderline = false, bool isOnlyRun = false, string styleId = "00", string styleName = "Default", string fontName = "Calibri", int fontSize = 12, string rgbColor = "000000", UnderlineValues underline = UnderlineValues.Single)
        {
            // we have to set the properties
            RunProperties rPr   = new RunProperties();
            Color         color = new Color()
            {
                Val = rgbColor
            };
            RunFonts rFont = new RunFonts();

            rFont.Ascii = fontName;
            rPr.Append(color);
            rPr.Append(rFont);
            if (isBold)
            {
                rPr.Append(new Bold());
            }
            if (isItalic)
            {
                rPr.Append(new Italic());
            }
            if (isUnderline)
            {
                rPr.Append(new Underline()
                {
                    Val = underline
                });
            }
            rPr.Append(new FontSize()
            {
                Val = (fontSize * 2).ToString()
            });
            if (!isOnlyRun)
            {
                Style style = new Style();
                style.StyleId = styleId;
                if (styleName == null || styleName.Length == 0)
                {
                    styleName = styleId;
                }
                style.Append(new Name()
                {
                    Val = styleName
                });
                style.Append(rPr); //we are adding properties previously defined

                // we have to add style that we have created to the StylePart
                StyleDefinitionsPart stylePart;
                if (mainPart.StyleDefinitionsPart == null)
                {
                    stylePart        = mainPart.AddNewPart <StyleDefinitionsPart>();
                    stylePart.Styles = new Styles();
                }
                else
                {
                    stylePart = mainPart.StyleDefinitionsPart;
                }

                stylePart.Styles.Append(style);
                stylePart.Styles.Save(); // we save the style part
            }
            return(rPr);
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Set font underline.
 /// </summary>
 /// <param name="FontUnderline">Specifies the underline formatting style of the font text.</param>
 public void SetFontUnderline(UnderlineValues FontUnderline)
 {
     this.Font.Underline = FontUnderline;
 }
Ejemplo n.º 9
0
 private void SetAllNull()
 {
     this.FontName = null;
     this.CharacterSet = null;
     this.FontFamily = null;
     this.Bold = null;
     this.Italic = null;
     this.Strike = null;
     this.Outline = null;
     this.Shadow = null;
     this.Condense = null;
     this.Extend = null;
     this.clrFontColor = new SLColor(this.listThemeColors, this.listIndexedColors);
     HasFontColor = false;
     this.FontSize = null;
     this.vUnderline = UnderlineValues.None;
     HasUnderline = false;
     this.vVerticalAlignment = VerticalAlignmentRunValues.Baseline;
     HasVerticalAlignment = false;
     this.vFontScheme = FontSchemeValues.None;
     HasFontScheme = false;
 }