// Attach non-breaking elements to the text or object on // their left. internal static bool MoveNaviBackward(TextNavigator nav) { TextSymbolType type; bool continueLoop = true; TextPosition position = nav.CreatePosition(); type = nav.GetSymbolType(LogicalDirection.Backward); while (continueLoop) { if (nav.CompareTo(nav.TextContainer.Start) == 0) { return(false); } switch (type) { case TextSymbolType.Character: case TextSymbolType.EmbeddedObject: continueLoop = false; break; case TextSymbolType.ElementStart: case TextSymbolType.ElementEnd: if (IsBreakingSymbol(nav, LogicalDirection.Backward)) { continueLoop = false; } break; } nav.MoveByDistance(-1); type = nav.GetSymbolType(LogicalDirection.Backward); } return(nav.CompareTo(position) < 0); }
internal static string GenerateText(TextPosition begin, TextPosition end) { StringBuilder output = new StringBuilder(); TextNavigator navigator = begin.CreateNavigator(); TextSymbolType type; char[] buffer = new char[1]; char ch; if (begin.TextContainer != end.TextContainer) { throw new ArgumentException(SR.Get(SRID.BeginEndTextContainerMismatch)); } navigator.MoveToPosition(begin); type = navigator.GetSymbolType(LogicalDirection.Forward); while (navigator < end) { switch (type) { case TextSymbolType.Character: navigator.GetText(LogicalDirection.Forward, 1, navigator.TextContainer.End, buffer, 0); ch = buffer[0]; output.Append(ch); break; case TextSymbolType.EmbeddedObject: ch = '\xF8FF'; // Private use Unicode. output.Append(ch); break; case TextSymbolType.ElementStart: case TextSymbolType.ElementEnd: if (IsBreakingSymbol(navigator, LogicalDirection.Forward)) { output.Append(" "); } break; } navigator.MoveByDistance(1); type = navigator.GetSymbolType(LogicalDirection.Forward); } return(output.ToString()); }
private static bool IsBreakingSymbol(TextNavigator navigator, LogicalDirection direction) { TextSymbolType type = navigator.GetSymbolType(direction); // (JCS) - This will need to be reworked after the Avalon team has // an API that can be called to determine if an Element should be // "breaking" or not. return((type == TextSymbolType.None) || (type == TextSymbolType.EmbeddedObject) || (((type == TextSymbolType.ElementStart) || (type == TextSymbolType.ElementEnd) ) && (navigator.GetElementType(direction).IsAssignableFrom(typeof(InlineElement))) ) ); }