/// <summary>Gets the sanitized waiting leaves.</summary> /// <returns>the sanitized waiting leaves</returns> public virtual IList <IElement> GetSanitizedWaitingLeaves() { if (collapseSpaces) { return(TrimUtil.TrimLeafElementsAndSanitize(waitingLeaves)); } else { return(waitingLeaves); } }
/// <summary>Creates the leaves container.</summary> /// <returns>a paragraph</returns> private Paragraph CreateLeavesContainer() { if (collapseSpaces) { waitingLeaves = TrimUtil.TrimLeafElementsAndSanitize(waitingLeaves); } if (CssConstants.CAPITALIZE.Equals(textTransform)) { Capitalize(waitingLeaves); } if (waitingLeaves.Count > 0) { Paragraph p = CreateParagraphContainer(); bool runningElementsOnly = true; foreach (IElement leaf in waitingLeaves) { if (leaf is ILeafElement) { runningElementsOnly = false; p.Add((ILeafElement)leaf); } else { if (leaf is IBlockElement) { runningElementsOnly = runningElementsOnly && leaf is RunningElement; p.Add((IBlockElement)leaf); } } } if (runningElementsOnly) { // TODO this might be avoided in future if we will come up with removing of completely empty // (both in terms of content and possible properties like background and borders) tags from // logical structure of resultant PDF documents p.GetAccessibilityProperties().SetRole(StandardRoles.ARTIFACT); } return(p); } else { return(null); } }
/// <summary>Adds text to the waiting leaves.</summary> /// <param name="text">the text</param> public virtual void Add(String text) { if (!keepLineBreaks && collapseSpaces) { text = WhiteSpaceUtil.CollapseConsecutiveSpaces(text); } else { if (keepLineBreaks && collapseSpaces) { StringBuilder sb = new StringBuilder(text.Length); for (int i = 0; i < text.Length; i++) { if (TrimUtil.IsNonLineBreakSpace(text[i])) { if (sb.Length == 0 || sb[sb.Length - 1] != ' ') { sb.Append(" "); } } else { sb.Append(text[i]); } } text = sb.ToString(); } else { // false == collapseSpaces // prohibit trimming first and last spaces StringBuilder sb = new StringBuilder(text.Length); sb.Append('\u200d'); for (int i = 0; i < text.Length; i++) { sb.Append(text[i]); if ('\n' == text[i] || ('\r' == text[i] && i + 1 < text.Length && '\n' != text[i + 1])) { sb.Append('\u200d'); } } if ('\u200d' == sb[sb.Length - 1]) { sb.Delete(sb.Length - 1, sb.Length); } text = sb.ToString(); } } if (CssConstants.UPPERCASE.Equals(textTransform)) { text = text.ToUpperInvariant(); } else { if (CssConstants.LOWERCASE.Equals(textTransform)) { text = text.ToLowerInvariant(); } } waitingLeaves.Add(new iText.Layout.Element.Text(text)); }