// 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 bool BreakText(TextPosition start, TextPosition end, bool isSpelling, out ArrayList positionList) { string breakingString; ArrayList indexList; int currentIndex = 0; int lastIndex = 0; int i; TextNavigator nav = start.CreateNavigator(); positionList = null; // Convert input and execute main work. if (nav.CompareTo(nav.TextContainer.Start) != 0) { MoveNaviBackward(nav); MoveNaviForward(nav); } breakingString = GenerateText(nav, end); if (!BreakText(breakingString, isSpelling, out indexList)) { return(false); } // Convert from indices to TextPositions and return. positionList = new ArrayList(); if (0 == start.CompareTo(start.TextContainer.Start)) { positionList.Add(start); } foreach (Object item in indexList) { currentIndex = (int)item; for (i = 0; i < (currentIndex - lastIndex); ++i) { MoveNaviForward(nav); } positionList.Add(nav.CreatePosition()); lastIndex = currentIndex; } if (0 == end.CompareTo(end.TextContainer.End)) { // Add the end of the container as the last break. positionList.Add(end); } return(true); }