internal void ScriptItemize(RPLFormat.Directions direction) { SCRIPT_ITEM[] array = null; int num = 0; StringBuilder stringBuilder = new StringBuilder(); string nextTextBlock; while ((nextTextBlock = GetNextTextBlock()) != null) { if (nextTextBlock.Length <= 0) { continue; } SCRIPT_CONTROL psControl = default(SCRIPT_CONTROL); psControl.dword1 = 16777216u; SCRIPT_STATE psState = new ScriptState { uBidiLevel = ((direction != 0) ? 1 : 0) }.GetAs_SCRIPT_STATE(); SCRIPT_ITEM[] array2 = new SCRIPT_ITEM[nextTextBlock.Length + 1]; int pcItems = 0; int num2 = Win32.ScriptItemize(nextTextBlock, nextTextBlock.Length, array2.Length, ref psControl, ref psState, array2, ref pcItems); if (Win32.Failed(num2)) { Marshal.ThrowExceptionForHR(num2); } if (array == null) { array = array2; num = pcItems; } 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 += pcItems; } stringBuilder.Append(nextTextBlock); } if (num <= 0) { return; } List <SCRIPT_ITEM> list = new List <SCRIPT_ITEM>(); int num3 = -1; 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 && CanMergeItemizedRuns(array[j].iCharPos, array[j + 1].iCharPos - 1, stringBuilder)) { if (num3 < 0) { num3 = j; } continue; } if (num3 >= 0) { list.Add(array[num3]); } list.Add(array[j]); num3 = -1; } if (num3 >= 0) { list.Add(array[num3]); } list.Add(array[num]); array = null; num = list.Count - 1; if (num == 1) { for (int k = 0; k < m_runs.Count; k++) { m_runs[k].SCRIPT_ANALYSIS = list[0].analysis; } AnalyzeForBreakPositions(m_runs, stringBuilder.ToString()); return; } 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 = ExtractRuns(iCharPos, endingParaCharIndex, list[l].analysis); list2.AddRange(collection); } m_runs = list2; }
internal 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);