private static bool TrySplitLine(string line, bool isWordSplitAllowed, MeasureTextLineWidthDelegate measureHandler, out string lineWithoutLastWord, out string lastWord) { return (TryCutLastWord(line, out lineWithoutLastWord, out lastWord) || ( (isWordSplitAllowed || line.HasJapaneseChineseSymbols()) && TryCutWordTail(line, measureHandler, out lineWithoutLastWord, out lastWord) )); }
private static bool TryCutWordTail(string textLine, MeasureTextLineWidthDelegate measureHandler, out string currentLinePart, out string nextLinePart) { currentLinePart = null; nextLinePart = null; var cutFrom = CalcFittedCharactersCount(textLine, measureHandler); if (cutFrom > 0) { AdjustLineBreakPosition(textLine, ref cutFrom); nextLinePart = textLine.Substring(cutFrom); currentLinePart = textLine.Substring(0, cutFrom); return(true); } else { return(false); } }
private static int CalcFittedCharactersCount(string textLine, MeasureTextLineWidthDelegate measureHandler) { int min = 0; int max = textLine.Length; int mid = 0; bool isLineLonger = false; do { mid = min + ((max - min) / 2); isLineLonger = !measureHandler(textLine, 0, mid); if (isLineLonger) { max = mid; } else { min = mid; } }while (min < max && !(!isLineLonger && ((max - min) / 2) == 0)); return(mid); }
public static bool CarryLastWordToNextLine(List <string> strings, int line, bool isWordSplitAllowed, MeasureTextLineWidthDelegate measureHandler) { string lastWord; string lineWithoutLastWord; if (TrySplitLine(strings[line], isWordSplitAllowed, measureHandler, out lineWithoutLastWord, out lastWord)) { PushWordToLine(lastWord, strings, line + 1); strings[line] = lineWithoutLastWord; return(true); } else { return(false); } }