private bool WriteFontAttr(int ws, string sAttr, ExportStyleInfo esi, string sCss, bool fTopLevel) { FontInfo fi = esi.FontInfoForWs(ws); bool fInherited = false; string sInheritance = String.Empty; if (sCss == null && !fTopLevel) sInheritance = "\t/* inherited through cascaded environment */"; if (sCss == null) sInheritance = "\t/* cascaded environment */"; else if (!fTopLevel) sInheritance = "\t/* inherited */"; switch (sAttr) { case "font-family": if (fi.m_fontName.ValueIsSet) { string sFontName = esi.RealFontNameForWs(ws); if (String.IsNullOrEmpty(sFontName)) m_writer.WriteLine(" font-family: \"{0}\", serif;{1}", fi.m_fontName.Value, sInheritance); else m_writer.WriteLine(" font-family: \"{0}\", serif;{1}", sFontName, sInheritance); return true; } fInherited = fi.m_fontName.IsInherited; break; case "font-size": bool superSub = fi.m_superSub.ValueIsSet && fi.m_superSub.Value != FwSuperscriptVal.kssvOff; if (fi.m_fontSize.ValueIsSet) { var pointSize = fi.m_fontSize.Value; if (superSub) pointSize = pointSize*55/100; m_writer.WriteLine(" font-size: {0}pt;{1}", ConvertMptToPt(pointSize), sInheritance); return true; } if (superSub) { m_writer.WriteLine(" font-size: 55%;{0}", sInheritance); return true; } fInherited = fi.m_fontSize.IsInherited; break; case "font-weight": if (fi.m_bold.ValueIsSet) { m_writer.WriteLine(" font-weight: {0};{1}", fi.m_bold.Value ? "bold" : "normal", sInheritance); return true; } fInherited = fi.m_bold.IsInherited; break; case "font-style": if (fi.m_italic.ValueIsSet) { m_writer.WriteLine(" font-style: {0};{1}", fi.m_italic.Value ? "italic" : "normal", sInheritance); return true; } fInherited = fi.m_italic.IsInherited; break; case "color": if (fi.m_fontColor.ValueIsSet) { //Black as a font color is a default setting, we will ignore it (LT-10891) //however, if it is explicitly set we need to include it. if (fi.m_fontColor.Value != Color.Black || fi.m_fontColor.IsExplicit) { m_writer.WriteLine(" color: rgb({0},{1},{2});{3}", fi.m_fontColor.Value.R, fi.m_fontColor.Value.G, fi.m_fontColor.Value.B, sInheritance); } return true; } fInherited = fi.m_fontColor.IsInherited; break; case "background-color": if (fi.m_backColor.ValueIsSet) { //White as a background color is a default setting, we will ignore it (LT-10891) //however, if it is explicitly set we need to include it. if (fi.m_backColor.Value != Color.White || fi.m_fontColor.IsExplicit) { m_writer.WriteLine(" background-color: rgb({0},{1},{2});{3}", fi.m_backColor.Value.R, fi.m_backColor.Value.G, fi.m_backColor.Value.B, sInheritance); } return true; } fInherited = fi.m_backColor.IsInherited; break; case "vertical-align": if (fi.m_superSub.ValueIsSet) { m_writer.WriteLine(" vertical-align: {0};{1}", GetVerticalAlign(fi.m_superSub.Value), sInheritance); return true; } if (fi.m_offset.ValueIsSet) { m_writer.WriteLine(" vertical-align: {0}pt;{1}", ConvertMptToPt(fi.m_offset.Value), sInheritance); return true; } fInherited = fi.m_offset.IsInherited || fi.m_superSub.IsInherited; break; case "text-decoration": if (fi.m_underline.ValueIsSet) { m_writer.WriteLine(" text-decoration: {0};{1}", (fi.m_underline.Value == FwUnderlineType.kuntNone ? "none" : "underline"), sInheritance); return true; } fInherited = fi.m_underline.IsInherited; break; } if (fInherited) { string sBaseStyle = esi.InheritsFrom; BaseStyleInfo bsiBase; if (!String.IsNullOrEmpty(sBaseStyle) && m_styleTable.TryGetValue(GetValidCssClassName(sBaseStyle), out bsiBase)) { if (WriteFontAttr(ws, sAttr, bsiBase as ExportStyleInfo, sCss, false)) return true; } if (!String.IsNullOrEmpty(sCss)) { List<string> rgsStyles; if (m_mapCssToStyleEnv.TryGetValue(sCss, out rgsStyles)) { foreach (string sParaStyle in rgsStyles) { BaseStyleInfo bsiPara; if (m_styleTable.TryGetValue(GetValidCssClassName(sParaStyle), out bsiPara) && WriteFontAttr(ws, sAttr, bsiPara as ExportStyleInfo, null, false)) { return true; } } } } } return false; }
private bool WriteFontAttr(int ws, string sAttr, ExportStyleInfo esi, string sCss, bool fTopLevel) { FontInfo fi = esi.FontInfoForWs(ws); bool fExplicit = false; bool fInherited = false; string sInheritance = String.Empty; if (sCss == null && !fTopLevel) sInheritance = "\t/* inherited through cascaded environment */"; if (sCss == null) sInheritance = "\t/* cascaded environment */"; else if (!fTopLevel) sInheritance = "\t/* inherited */"; switch (sAttr) { case "font-family": if (fi.m_fontName.ValueIsSet) { string sFontName = esi.RealFontNameForWs(ws); if (String.IsNullOrEmpty(sFontName)) m_writer.WriteLine(" font-family: \"{0}\", serif;{1}", fi.m_fontName.Value, sInheritance); else m_writer.WriteLine(" font-family: \"{0}\", serif;{1}", sFontName, sInheritance); return true; } fExplicit = fi.m_fontName.IsExplicit; fInherited = fi.m_fontName.IsInherited; break; case "font-size": if (fi.m_fontSize.ValueIsSet) { m_writer.WriteLine(" font-size: {0}pt;{1}", ConvertMptToPt(fi.m_fontSize.Value), sInheritance); return true; } fExplicit = fi.m_fontSize.IsExplicit; fInherited = fi.m_fontSize.IsInherited; break; case "font-weight": if (fi.m_bold.ValueIsSet) { m_writer.WriteLine(" font-weight: {0};{1}", fi.m_bold.Value ? "bold" : "normal", sInheritance); return true; } fExplicit = fi.m_bold.IsExplicit; fInherited = fi.m_bold.IsInherited; break; case "font-style": if (fi.m_italic.ValueIsSet) { m_writer.WriteLine(" font-style: {0};{1}", fi.m_italic.Value ? "italic" : "normal", sInheritance); return true; } fExplicit = fi.m_italic.IsExplicit; fInherited = fi.m_italic.IsInherited; break; case "color": if (fi.m_fontColor.ValueIsSet) { m_writer.WriteLine(" color: rgb({0},{1},{2});{3}", fi.m_fontColor.Value.R, fi.m_fontColor.Value.G, fi.m_fontColor.Value.B, sInheritance); return true; } fExplicit = fi.m_fontColor.IsExplicit; fInherited = fi.m_fontColor.IsInherited; break; case "background-color": if (fi.m_backColor.ValueIsSet) { m_writer.WriteLine(" background-color: rgb({0},{1},{2});{3}", fi.m_backColor.Value.R, fi.m_backColor.Value.G, fi.m_backColor.Value.B, sInheritance); return true; } fExplicit = fi.m_backColor.IsExplicit; fInherited = fi.m_backColor.IsInherited; break; case "vertical-align": if (fi.m_superSub.ValueIsSet) { m_writer.WriteLine(" vertical-align: {0};{1}", GetVerticalAlign(fi.m_superSub.Value), sInheritance); return true; } if (fi.m_offset.ValueIsSet) { m_writer.WriteLine(" vertical-align: {0}pt;{1}", ConvertMptToPt(fi.m_offset.Value), sInheritance); return true; } fExplicit = fi.m_offset.IsExplicit || fi.m_superSub.IsExplicit; fInherited = fi.m_offset.IsInherited || fi.m_superSub.IsInherited; break; case "text-decoration": if (fi.m_underline.ValueIsSet) { m_writer.WriteLine(" text-decoration: {0};{1}", (fi.m_underline.Value == FwUnderlineType.kuntNone ? "none" : "underline"), sInheritance); return true; } fExplicit = fi.m_underline.IsExplicit; fInherited = fi.m_underline.IsInherited; break; } if (fInherited) { string sBaseStyle = esi.InheritsFrom; BaseStyleInfo bsiBase; if (!String.IsNullOrEmpty(sBaseStyle) && m_styleTable.TryGetValue(sBaseStyle, out bsiBase)) { if (WriteFontAttr(ws, sAttr, bsiBase as ExportStyleInfo, sCss, false)) return true; } if (!String.IsNullOrEmpty(sCss)) { List<string> rgsStyles; if (m_mapCssToStyleEnv.TryGetValue(sCss, out rgsStyles)) { foreach (string sParaStyle in rgsStyles) { BaseStyleInfo bsiPara; if (m_styleTable.TryGetValue(sParaStyle, out bsiPara) && WriteFontAttr(ws, sAttr, bsiPara as ExportStyleInfo, null, false)) { return true; } } } } } return false; }