/** * Gets the font family for the specified font char range. * If fcr is null, the font char range "ascii" is used * * @param fcr the font char range, defaults to "ansi" * @return a string representing the font famil */ public String GetFontFamily(FontCharRange fcr) { CT_RPr pr = run.rPr; if (pr == null || !pr.IsSetRFonts()) { return(null); } CT_Fonts fonts = pr.rFonts; switch (fcr == FontCharRange.None ? FontCharRange.Ascii : fcr) { default: case FontCharRange.Ascii: return(fonts.ascii); case FontCharRange.CS: return(fonts.cs); case FontCharRange.EastAsia: return(fonts.eastAsia); case FontCharRange.HAnsi: return(fonts.hAnsi); } }
/** * Specifies the fonts which shall be used to display the text contents of * this run. Specifies a font which shall be used to format all characters * in the ASCII range (0 - 127) within the parent run * * @param fontFamily */ public void SetFontFamily(String fontFamily) { CT_RPr pr = run.IsSetRPr() ? run.rPr : run.AddNewRPr(); CT_Fonts fonts = pr.IsSetRFonts() ? pr.rFonts : pr.AddNewRFonts(); fonts.ascii = (fontFamily); }
/** * Specifies the fonts which shall be used to display the text contents of * this run. Specifies a font which shall be used to format all characters * in the ASCII range (0 - 127) within the parent run * * @return a string representing the font family */ public String GetFontFamily() { CT_RPr pr = run.rPr; return((pr != null && pr.IsSetRFonts()) ? pr.rFonts.ascii : null); }
public string GetFontFamily() { CT_RPr rPr = this.run.rPr; if (rPr == null || !rPr.IsSetRFonts()) { return((string)null); } return(rPr.rFonts.ascii); }
/** * Specifies the fonts which shall be used to display the text contents of * this run. The default handling for fcr == null is to overwrite the * ascii font char range with the given font family and also set all not * specified font ranges * * @param fontFamily * @param fcr FontCharRange or null for default handling */ public void SetFontFamily(String fontFamily, FontCharRange fcr) { CT_RPr pr = run.IsSetRPr() ? run.rPr : run.AddNewRPr(); CT_Fonts fonts = pr.IsSetRFonts() ? pr.rFonts : pr.AddNewRFonts(); if (fcr == FontCharRange.None) { fonts.ascii = (fontFamily); if (!fonts.IsSetHAnsi()) { fonts.hAnsi = (fontFamily); } if (!fonts.IsSetCs()) { fonts.cs = (fontFamily); } if (!fonts.IsSetEastAsia()) { fonts.eastAsia = (fontFamily); } } else { switch (fcr) { case FontCharRange.Ascii: fonts.ascii = (fontFamily); break; case FontCharRange.CS: fonts.cs = (fontFamily); break; case FontCharRange.EastAsia: fonts.eastAsia = (fontFamily); break; case FontCharRange.HAnsi: fonts.hAnsi = (fontFamily); break; } } }
/// <summary> /// 设置字体 /// </summary> /// <param name="run"></param> /// <param name="nameType"></param> public static void SetFontName(this XWPFRun run, FontNameType nameType) { string fontName = GetFontName(nameType); CT_R r = run.GetCTR(); CT_RPr rpr = r.IsSetRPr() ? r.rPr : r.AddNewRPr(); CT_Fonts fonts = rpr.IsSetRFonts() ? rpr.rFonts : rpr.AddNewRFonts(); fonts.ascii = fontName; if (string.IsNullOrEmpty(fonts.eastAsia)) { fonts.eastAsia = fontName; } if (string.IsNullOrEmpty(fonts.cs)) { fonts.cs = fontName; } if (string.IsNullOrEmpty(fonts.hAnsi)) { fonts.hAnsi = fontName; } }
public void SetFontFamily(string fontFamily) { CT_RPr ctRpr = this.run.IsSetRPr() ? this.run.rPr : this.run.AddNewRPr(); (ctRpr.IsSetRFonts() ? ctRpr.rFonts : ctRpr.AddNewRFonts()).ascii = fontFamily; }