protected override List <StyleClass> ListStyles(XElement documentRoot) { System.Diagnostics.Debug.Assert(DocumentRoot != null); // <w:styles // ... // <w:style var styleList = new List <StyleClass>(); var stylesRoot = DocumentRoot.Descendants(w + "styles").FirstOrDefault(); System.Diagnostics.Debug.Assert(stylesRoot != null); foreach (var styleElem in stylesRoot.Elements(w + "style")) { List <string> lstFontNames = null; var rPr = GetElement(styleElem, w + "rPr"); // not all styles have font formatting if (rPr != null) { // first check to see if there's a wx:font... (this is a single value and usually (always?) // is the fonts that are used var strFontName = GetElementAttributeValue(rPr, CxNameElementForStyleFontName, CxNameAttributeForStyleFontName); if (!String.IsNullOrEmpty(strFontName)) { lstFontNames = new List <string> { strFontName }; } else { // if not, then check to see if there's a w:rFonts // <w:rPr> // <w:rFonts w:ascii="Tahoma" w:h-ansi="Tahoma" /> var rFonts = GetElement(rPr, CxNameElementForStyleFontNames); if (rFonts != null) { lstFontNames = new List <string>(); lstFontNames.AddRange(GetAllAttributeValues(rFonts)); } } } var styleClass = new StyleClass { Id = GetAttributeValue(styleElem, w + "styleId"), Name = GetStyleName(styleElem), FontNames = lstFontNames, AssociatedStyleElem = styleElem }; styleList.Add(styleClass); } return(styleList); }
protected override void ReplaceFontNameAtParagraphLevel(string strFontNameOld, string strFontNameNew) { /* * <w:p ...> * <w:pPr> * <w:rPr> * <w:rFonts w:ascii="VG2000 Main" w:h-ansi="VG2000 Main" /> <============= replace these bits * <wx:font wx:val="VG2000 Main" /> * </w:rPr> * </w:pPr> * ... * </w:p> */ var paragraphStyles = DocumentRoot.Descendants(w + "pPr"); foreach (var elemFormatting in paragraphStyles.Select(GetRunFormattingParent) .Where(elemFormatting => elemFormatting != null)) { UpdateAllChildElementAttributesValue(elemFormatting, strFontNameOld, strFontNameNew); } }