public static void AddCharactersProperties(CharacterRun characterRun, StringBuilder style) { AddBorder(characterRun.GetBorder(), string.Empty, style); if (characterRun.IsCapitalized()) { style.Append("text-transform:uppercase;"); } if (characterRun.GetIco24() != -1) { style.Append("color:" + GetColor24(characterRun.GetIco24()) + ";"); } if (characterRun.IsHighlighted()) { style.Append("background-color:" + GetColor(characterRun.GetHighlightedColor()) + ";"); } if (characterRun.IsStrikeThrough()) { style.Append("text-decoration:line-through;"); } if (characterRun.IsShadowed()) { style.Append("text-shadow:" + characterRun.GetFontSize() / 24 + "pt;"); } if (characterRun.IsSmallCaps()) { style.Append("font-variant:small-caps;"); } if (characterRun.GetSubSuperScriptIndex() == 1) { style.Append("vertical-align:super;"); style.Append("font-size:smaller;"); } if (characterRun.GetSubSuperScriptIndex() == 2) { style.Append("vertical-align:sub;"); style.Append("font-size:smaller;"); } if (characterRun.GetUnderlineCode() > 0) { style.Append("text-decoration:underline;"); } if (characterRun.IsVanished()) { style.Append("visibility:hidden;"); } }
public static void SetCharactersProperties(CharacterRun characterRun, XmlElement inline) { StringBuilder textDecorations = new StringBuilder(); SetBorder(inline, characterRun.GetBorder(), string.Empty); if (characterRun.GetIco24() != -1) { inline.SetAttribute("color", GetColor24(characterRun.GetIco24())); } int opacity = (int)(characterRun.GetIco24() & 0xFF000000L) >> 24; if (opacity != 0 && opacity != 0xFF) { inline.SetAttribute("opacity", GetOpacity(characterRun.GetIco24())); } if (characterRun.IsCapitalized()) { inline.SetAttribute("text-transform", "uppercase"); } if (characterRun.isHighlighted()) { inline.SetAttribute("background-color", GetColor(characterRun.GetHighlightedColor())); } if (characterRun.IsStrikeThrough()) { if (textDecorations.Length > 0) { textDecorations.Append(" "); } textDecorations.Append("line-through"); } if (characterRun.IsShadowed()) { inline.SetAttribute("text-shadow", characterRun.GetFontSize() / 24 + "pt"); } if (characterRun.IsSmallCaps()) { inline.SetAttribute("font-variant", "small-caps"); } if (characterRun.GetSubSuperScriptIndex() == 1) { inline.SetAttribute("baseline-shift", "super"); inline.SetAttribute("font-size", "smaller"); } if (characterRun.GetSubSuperScriptIndex() == 2) { inline.SetAttribute("baseline-shift", "sub"); inline.SetAttribute("font-size", "smaller"); } if (characterRun.GetUnderlineCode() > 0) { if (textDecorations.Length > 0) { textDecorations.Append(" "); } textDecorations.Append("underline"); } if (characterRun.IsVanished()) { inline.SetAttribute("visibility", "hidden"); } if (textDecorations.Length > 0) { inline.SetAttribute("text-decoration", textDecorations.ToString()); } }
public void Test() { HWPFDocument doc = HWPFTestDataSamples.OpenSampleFile("Bug49919.doc"); range = doc.GetRange(); Paragraph par = FindParagraph("Paragraph normal\r"); Assert.AreEqual(0, par.GetLeftBorder().BorderType); Assert.AreEqual(0, par.GetRightBorder().BorderType); Assert.AreEqual(0, par.GetTopBorder().BorderType); Assert.AreEqual(0, par.GetBottomBorder().BorderType); par = FindParagraph("Paragraph with border\r"); Assert.AreEqual(18, par.GetLeftBorder().BorderType); Assert.AreEqual(17, par.GetRightBorder().BorderType); Assert.AreEqual(18, par.GetTopBorder().BorderType); Assert.AreEqual(17, par.GetBottomBorder().BorderType); Assert.AreEqual(15, par.GetLeftBorder().Color); par = FindParagraph("Paragraph with red border\r"); Assert.AreEqual(1, par.GetLeftBorder().BorderType); Assert.AreEqual(1, par.GetRightBorder().BorderType); Assert.AreEqual(1, par.GetTopBorder().BorderType); Assert.AreEqual(1, par.GetBottomBorder().BorderType); Assert.AreEqual(6, par.GetLeftBorder().Color); par = FindParagraph("Paragraph with bordered words.\r"); Assert.AreEqual(0, par.GetLeftBorder().BorderType); Assert.AreEqual(0, par.GetRightBorder().BorderType); Assert.AreEqual(0, par.GetTopBorder().BorderType); Assert.AreEqual(0, par.GetBottomBorder().BorderType); Assert.AreEqual(3, par.NumCharacterRuns); CharacterRun chr = par.GetCharacterRun(0); Assert.AreEqual(0, chr.GetBorder().BorderType); chr = par.GetCharacterRun(1); Assert.AreEqual(1, chr.GetBorder().BorderType); Assert.AreEqual(0, chr.GetBorder().Color); chr = par.GetCharacterRun(2); Assert.AreEqual(0, chr.GetBorder().BorderType); while (pos < range.NumParagraphs - 1) { par = range.GetParagraph(pos++); if (par.IsInTable()) { break; } } Assert.AreEqual(true, par.IsInTable()); Table tab = range.GetTable(par); // Border could be defined for the entire row, or for each cell, with the same visual appearance. Assert.AreEqual(2, tab.NumRows); TableRow row = tab.GetRow(0); Assert.AreEqual(1, row.GetLeftBorder().BorderType); Assert.AreEqual(1, row.GetRightBorder().BorderType); Assert.AreEqual(1, row.GetTopBorder().BorderType); Assert.AreEqual(1, row.GetBottomBorder().BorderType); Assert.AreEqual(2, row.NumCells()); TableCell cell = row.GetCell(1); Assert.AreEqual(3, cell.GetBrcTop().BorderType); row = tab.GetRow(1); cell = row.GetCell(0); // 255 Clears border inherited from row Assert.AreEqual(255, cell.GetBrcBottom().BorderType); }