public void ScriptItemize(RPLFormat.Directions direction) { SCRIPT_ITEM[] array = null; int num = 0; StringBuilder stringBuilder = new StringBuilder(); string nextTextBlock; while ((nextTextBlock = this.GetNextTextBlock()) != null) { if (nextTextBlock.Length > 0) { SCRIPT_CONTROL sCRIPT_CONTROL = default(SCRIPT_CONTROL); sCRIPT_CONTROL.dword1 = 16777216u; ScriptState scriptState = new ScriptState(); scriptState.uBidiLevel = ((direction != 0) ? 1 : 0); SCRIPT_STATE as_SCRIPT_STATE = scriptState.GetAs_SCRIPT_STATE(); SCRIPT_ITEM[] array2 = new SCRIPT_ITEM[nextTextBlock.Length + 1]; int num2 = 0; int num3 = Win32.ScriptItemize(nextTextBlock, nextTextBlock.Length, array2.Length, ref sCRIPT_CONTROL, ref as_SCRIPT_STATE, array2, ref num2); if (Win32.Failed(num3)) { Marshal.ThrowExceptionForHR(num3); } if (array == null) { array = array2; num = num2; } else { SCRIPT_ITEM[] array3 = new SCRIPT_ITEM[num + array2.Length]; Array.Copy(array, 0, array3, 0, num); for (int i = 0; i < array2.Length; i++) { SCRIPT_ITEM sCRIPT_ITEM = array2[i]; sCRIPT_ITEM.iCharPos += stringBuilder.Length; array3[num + i] = sCRIPT_ITEM; } array = array3; num += num2; } stringBuilder.Append(nextTextBlock); } } if (num > 0) { List <SCRIPT_ITEM> list = new List <SCRIPT_ITEM>(); int num4 = -1; bool flag = false; for (int j = 0; j < num; j++) { int bidiLevel = ScriptState.GetBidiLevel(array[j].analysis.state.word1); int bidiLevel2 = ScriptState.GetBidiLevel(array[j + 1].analysis.state.word1); if (bidiLevel == bidiLevel2 && this.CanMergeItemizedRuns(array[j].iCharPos, array[j + 1].iCharPos - 1, stringBuilder)) { if (num4 < 0) { num4 = j; } } else { if (num4 >= 0) { list.Add(array[num4]); } list.Add(array[j]); num4 = -1; } } if (num4 >= 0) { list.Add(array[num4]); } list.Add(array[num]); array = null; num = list.Count - 1; if (num == 1) { for (int k = 0; k < this.m_runs.Count; k++) { this.m_runs[k].SCRIPT_ANALYSIS = list[0].analysis; } Paragraph.AnalyzeForBreakPositions(this.m_runs, stringBuilder.ToString()); } else { List <TextRun> list2 = new List <TextRun>(); for (int l = 0; l < num; l++) { int iCharPos = list[l].iCharPos; int endingParaCharIndex = list[l + 1].iCharPos - 1; List <TextRun> collection = this.ExtractRuns(iCharPos, endingParaCharIndex, list[l].analysis); list2.AddRange(collection); } this.m_runs = list2; } } }
public static extern int ScriptItemize([MarshalAs(UnmanagedType.LPWStr)] string pwcInChars, int cInChars, int cMaxItems, ref SCRIPT_CONTROL psControl, ref SCRIPT_STATE psState, [In][Out] SCRIPT_ITEM[] pItems, ref int pcItems);