public static TextGroup Join(this IEnumerable <ITextItem> textItems, string separator = "", string borderLeft = "", string borderRight = "") { var textGroup = new TextGroup(separator, borderLeft, borderRight); textGroup.Items.AddRange(textItems); return(textGroup); }
public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { IList <IElement> l = new List <IElement>(); //draw everything between the brackets at once if (currentContent.Count > 0) { IList <IElement> list = new List <IElement>(); foreach (IElement element in currentContent) { if (element is TextPathGroup) { l.Add(element); } else if (element is Text) { list.Add(element); } } if (list.Count > 0) { TextGroup group = new TextGroup(list, 0, 0, 500f, 500f, tag.CSS); l.Add(group); } } //draw the content return(l); }
/// <summary> /// Checks upcoming groups if there is at least one of specified types /// </summary> private static bool HasInFuture(IList <TextGroup> groups, int currentIndex, TextGroupType[] hasThese, TextGroupType[] ignoreThese, out TextGroupType?foundType, out int foundIndex) { foundIndex = currentIndex; foundType = null; for (int i = currentIndex + 1; i < groups.Count; i++) { TextGroup gt = groups[i]; // has one of these? if (Array.IndexOf(hasThese, gt.Type) != -1) { foundType = gt.Type; foundIndex = i; return(true); } // if not, then it should be one of these if (Array.IndexOf(ignoreThese, gt.Type) != -1) { continue; } else { // or otherwise we exit return(false); } } return(false); }
void StoreLineBreakGroup(int count = 1) { for (int i = 0; i < count; i++) { TextGroup group = CreateEmptyTextGroup(); group.text = space; groups.Add(group); } }
void StoreGroup(TextGroup group) { // Reject group if no text if (string.IsNullOrEmpty(group.text)) { return; } groups.Add(group); }
public TabletDebugger() { Title = "Tablet Debugger"; var debugger = new StackLayout { HorizontalContentAlignment = HorizontalAlignment.Stretch, Height = 270, Padding = 5, Spacing = 5, Items = { new StackLayoutItem { Control = deviceNameBox = new TextGroup("Device") }, new StackLayoutItem { Expand = true, Control = new TableLayout { Spacing = new Size(5, 5), Rows = { new TableRow { ScaleHeight = true, Cells = { new TableCell(rawTabletBox = new TextGroup("Raw Tablet Data"), true), new TableCell(tabletBox = new TextGroup("Tablet Report"), true) } } } } }, new StackLayoutItem(reportRateBox = new TextGroup("Report Rate")) } }; this.Content = new Splitter { Orientation = Orientation.Vertical, Width = 640, Height = 640, FixedPanel = SplitterFixedPanel.Panel2, Panel1 = new DebuggerGroup { Text = "Visualizer", Content = tabletVisualizer = new TabletVisualizer() }, Panel2 = debugger }; }
/// <summary> /// 教学 第一步 /// </summary> private void Tutorial_1() { IsTeaching = false; TextGroup.transform.GetChild(1).GetComponent <Text>().text = ""; baize.DOFillAmount(1, 1.0f).OnComplete(() => { TextGroup.DOFillAlpha(1, 0.5f).OnComplete(() => { ContentText.DOText(Tips[0], Time_daziji[0]).OnComplete(() => { TimeTool.Instance.AddDelayed(TimeDownType.NoUnityTimeLineImpact, DelayTime, () => { BG_Close(); Teach1_Anima_Open(); IsTeaching = true; }); }); }); }); }
protected override IList <MediaDataNote> LoadNotesFromDataSource() { var notes = new List <MediaDataNote>(); if (MediaScheduleSettings.FlightDateStart.HasValue && MediaScheduleSettings.FlightDateEnd.HasValue) { var startDate = MediaScheduleSettings.FlightDateStart.Value; var endDate = MediaScheduleSettings.FlightDateEnd.Value; while (startDate < endDate) { var noteEndDate = startDate.AddDays(6); notes.AddRange(MediaSchedule.SnapshotContent.Snapshots .Where(s => !s.ActiveWeeks.Any() || s.ActiveWeeks.Any(w => w.StartDate == startDate && w.FinishDate == noteEndDate)) .Select(s => { var textGroup = new TextGroup(); textGroup.Items.Add(new TextItem(String.Format("{0} - ", s.Name), true)); var programsText = String.Join(", ", s.Programs.Select(program => String.Format("{0}{1} {2}x {3}", s.ShowStation ? String.Format("{0} ", program.Station) : String.Empty, (s.ShowProgram && !String.IsNullOrEmpty(program.Name)) || (s.ShowTime && !String.IsNullOrEmpty(program.Time)) ? String.Format("({0}{1})", s.ShowProgram && !String.IsNullOrEmpty(program.Name) ? String.Format("{0} ", program.Name) : String.Empty, s.ShowTime && !String.IsNullOrEmpty(program.Time) ? String.Format("{0}", program.Time) : String.Empty) : String.Empty, program.TotalSpots, program.StartDayLetter == program.EndDayLetter ? program.StartDayLetter : String.Format("{0}-{1}", program.StartDayLetter, program.EndDayLetter) ) )); textGroup.Items.Add(new TextItem(programsText, false)); return(new MediaDataNote(this) { StartDay = startDate, FinishDay = noteEndDate, MediaData = textGroup }); }) ); startDate = startDate.AddDays(7); } } return(notes); }
public override IList <IElement> End(IWorkerContext ctx, Tag tag, IList <IElement> currentContent) { Path path = null; try { IDictionary <String, String> attributes = tag.Attributes; SvgPipelineContext context = GetSvgPipelineContext(ctx); String id; if (attributes.TryGetValue("xlink:href", out id) && id != null) { IList <IElement> list = context.GetSymbolById(id.Substring(1)); //TODO need to check that the element list contains only one element //and the type needs to be Path if (list != null && list.Count == 1) { path = (Path)list[0]; } } } catch (NoCustomContextException e) { throw new RuntimeWorkerException(e); } //if the path is not found, do exactly the same as when Text if (path == null && currentContent.Count > 0) { TextGroup group = new TextGroup(currentContent, 0, 0, 500f, 500f, tag.CSS); IList <IElement> l = new List <IElement>(1); l.Add(group); return(l); } else if (currentContent.Count > 0) { TextPathGroup group = new TextPathGroup(currentContent, 0, 0, 500f, 500f, tag.CSS, path); IList <IElement> l = new List <IElement>(1); l.Add(group); return(l); } //draw the content return(new List <IElement>(0)); }
public TabletDebugger() { Title = "Tablet Debugger"; var mainLayout = new TableLayout { Width = 640, Height = 480, Spacing = new Size(5, 5), Rows = { new TableRow { Cells = { new TableCell(rawTabletBox = new TextGroup("Raw Tablet Data"), true), new TableCell(tabletBox = new TextGroup("Tablet Report"), true) }, ScaleHeight = true }, new TableRow { Cells = { new TableCell(rawAuxBox = new TextGroup("Raw Aux Data"), true), new TableCell(auxBox = new TextGroup("Aux Report"), true) }, ScaleHeight = true } } }; this.Content = new StackLayout { Padding = 5, Spacing = 5, Items = { new StackLayoutItem(mainLayout, HorizontalAlignment.Stretch, true), new StackLayoutItem(reportRateBox = new TextGroup("Report Rate"),HorizontalAlignment.Stretch) } }; InitializeAsync(); }
/// <summary> /// 教学 第二步 /// </summary> public void Tutorial_2() { Teach1_Anima_Hide(); IsTeaching = false; BGCanvasGroup.blocksRaycasts = true; TextGroup.transform.GetChild(1).GetComponent <Text>().text = ""; BGCanvasGroup.DOFillAlpha(1, 0.5f).OnComplete(() => { TextGroup.DOFillAlpha(1, 0.5f).OnComplete(() => { ContentText.DOText(Tips[1], Time_daziji[1]).OnComplete(() => { TimeTool.Instance.AddDelayed(TimeDownType.NoUnityTimeLineImpact, DelayTime, () => { baize.enabled = false; BG_Close(); Teach2.DOFillAlpha(1, 0.5f).OnComplete(() => { IsTeaching = true; }); }); }); }); }); }
public void notify(string text, Color color, float holdTime) { var textObjectInst = GameObject.Instantiate(notificationText.gameObject, notificationText.rectTransform.parent); var notTextInst = textObjectInst.GetComponent <Text> (); notTextInst.text = text; // Debug.Log(notTextInst.rectTransform.sizeDelta.ToString ()); notTextInst.gameObject.SetActive(true); color.a = 0; notTextInst.color = color; notTextInst.rectTransform.sizeDelta.ToString(); var tg = new TextGroup(); tg.textObject = textObjectInst; tg.textInst = notTextInst; tg.pos = notificationText.rectTransform.localPosition; tg.fadeTime = releaseTime; tg.holdTime = holdTime; textGroupL.Add(tg); StartCoroutine(reorder()); }
// Constructor. public TextTree(TextBuffer buffer, TextLayout layout) { // set the buffer for this text tree this.buffer = buffer; // set the layout for this text tree this.layout = layout; // set the root for this text tree root = new TextGroup(); // insert a new line into the buffer buffer.Insert(0, '\n'); // create the first line TextLine line = new TextLine (buffer.MarkPosition(0, true), buffer.MarkPosition(1, true)); // insert the first line into the tree root.InsertChild(null, line); // update the metrics information root.UpdateMetrics(layout, true); // create the caret position caret = buffer.MarkPosition(0, false); // create the selection position selection = buffer.MarkPosition(0, false); }
public bool ReformatBook(string filename) { if (string.IsNullOrEmpty(filename)) { return(false); } // Try to open book BookFile book = new BookFile(); if (!BookReplacement.TryImportBook(filename, book) && !book.OpenBook(DaggerfallUnity.Instance.Arena2Path, filename)) { return(false); } // Clear existing Clear(); // Combine all tokens from all pages // The classic concept of pages becomes List <TextFile.Token> allPageTokens = new List <TextFile.Token>(); for (int page = 0; page < book.PageCount; page++) { TextFile.Token[] tokens = book.GetPageTokens(page); foreach (TextFile.Token token in tokens) { allPageTokens.Add(token); } } // Read all tokens and merge into text groups DaggerfallFont prevFont = DaggerfallUI.DefaultFont; TextFile.Token prevToken = new TextFile.Token(TextFile.Formatting.Nothing); TextGroup workingGroup = CreateEmptyTextGroup(prevFont); foreach (TextFile.Token token in allPageTokens) { switch (token.formatting) { // Set font on current group case TextFile.Formatting.FontPrefix: workingGroup.font = prevFont = DaggerfallUI.Instance.GetFont(token.x); break; // Text is added to working group case TextFile.Formatting.Text: workingGroup.text += token.text; break; // Newline becomes a space unless previous token was also newline // This will be treated as a paragraph break case TextFile.Formatting.NewLine: if (prevToken.formatting == TextFile.Formatting.NewLine) { StoreGroup(workingGroup); StoreLineBreakGroup(); workingGroup = CreateEmptyTextGroup(prevFont); } else { workingGroup.text += space; } break; // Set left justify on current group case TextFile.Formatting.JustifyLeft: workingGroup.alignment = HorizontalAlignment.None; break; // Set centre justify on current group case TextFile.Formatting.JustifyCenter: workingGroup.alignment = HorizontalAlignment.Center; break; } prevToken = token; } return(true); }
private void Awake() { instance = this; }
private void BG_Close() { TextGroup.DOFillAlpha(0, 0.5f); BGCanvasGroup.DOFillAlpha(0, 0.5f); BGCanvasGroup.blocksRaycasts = false; }
void OnGUI() { if (_serializedObject == null) { return; } if (TypeStyleName == "自定义风格" || TypeStyleName == "所有风格") { EditorLock = true; } else { EditorLock = false; } if (AllName.Count <= 0) { return; } if (SaveText.Count <= 0) { return; } GUILayout.Space(20); _serializedObject.Update(); Text_serializedObject.Update(); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("创建一个新的text风格", GUILayout.Width(150), GUILayout.Height(30))) { EditorGUILayoutPopup.ShowCreatWindow(); } if (GUILayout.Button("刷新", GUILayout.Width(150), GUILayout.Height(30))) { UpdateTag(); EditorApplication.update(); } if (GUILayout.Button("删除此类风格", GUILayout.Width(150), GUILayout.Height(30))) { } if (GUILayout.Button(LockName, GUILayout.Width(150), GUILayout.Height(30))) { SizeLock = !SizeLock; LockName = SizeLock?"解锁位置信息":"锁定位置信息"; } } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); if (IsEditor) { Debug.Log(TypeStyleName); EditorGUILayout.PropertyField(TypeNameProperty); } EditorGUI.BeginDisabledGroup(AcitonBool); SaveNub = EditorGUILayout.Popup(SaveNub, AllName.ToArray()); EditorGUI.EndDisabledGroup(); EditorGroup = (TextGroup)SaveNub; if (AllName[SaveNub] != lastNub) { UpdateMessage(); } EditorGUI.BeginDisabledGroup(EditorLock); EditorGUILayout.BeginHorizontal(); { GUI.color = Color.green; EditorGUILayout.PropertyField(_OutLineProperty, true); EditorGUILayout.PropertyField(_ShadowProperty, true); EditorGUILayout.PropertyField(_GradientProperty, true); GUI.color = Color.white; } EditorGUILayout.EndHorizontal(); GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_FontColorProperty, true); EditorGUILayout.PropertyField(_FontColorProperty, true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_FontSizeProperty, true); EditorGUILayout.PropertyField(_FontSizeProperty, true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_FontProperty, true); EditorGUILayout.PropertyField(_FontProperty, true); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_RaycastProperty, true); EditorGUILayout.PropertyField(_RaycastProperty, true); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUI.BeginDisabledGroup(SizeLock); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_SizeProperty, true); EditorGUILayout.PropertyField(_SizeProperty, true); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.PropertyField(bool_PositionProperty, true); EditorGUILayout.PropertyField(_PositionProperty, true); } EditorGUILayout.EndHorizontal(); GUILayout.Space(10); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("偏移组件", GUILayout.Width(150), GUILayout.Height(30))) { MovePosition(); } MoveVector = EditorGUILayout.Vector3Field("输入偏移量:", MoveVector); } EditorGUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); if (_OutLineProperty.boolValue) { GUILayout.Space(20); GUILayout.Box("描边特效"); EditorGUILayout.PropertyField(_OutLine_StartColorProperty, true); EditorGUILayout.PropertyField(_EffectSizeProperty, true); EditorGUILayout.PropertyField(_ShadowVectorProperty, true); } if (_ShadowProperty.boolValue) { GUILayout.Space(20); GUILayout.Box("阴影特效"); EditorGUILayout.PropertyField(_Shadow_StartColorProperty, true); EditorGUILayout.PropertyField(_ShadowEffectSizeProperty, true); } if (_GradientProperty.boolValue) { GUILayout.Space(20); GUILayout.Box("渐变色特效"); EditorGUILayout.PropertyField(_GradientTypeProperty, true); if ((GradientType)_GradientTypeProperty.enumValueIndex == GradientType.Horizontal) { EditorGUILayout.PropertyField(_StartColorProperty, true); EditorGUILayout.PropertyField(_EndColorProperty, true); } if ((GradientType)_GradientTypeProperty.enumValueIndex == GradientType.Vertica) { EditorGUILayout.PropertyField(_StartColorProperty, true); EditorGUILayout.PropertyField(_EndColorProperty, true); } if ((GradientType)_GradientTypeProperty.enumValueIndex == GradientType.HorizontalMore) { EditorGUILayout.PropertyField(_StartColorProperty, true); EditorGUILayout.PropertyField(_CenterColorProperty, true); EditorGUILayout.PropertyField(_EndColorProperty, true); } } GUILayout.Space(20); EditorGUILayout.BeginHorizontal(); { if (!IsEditor) { EditorGUILayout.BeginVertical(); { if (GUILayout.Button("设置此类text风格", GUILayout.Width(250), GUILayout.Height(30))) { if (EditorUtility.DisplayDialog("提示消息", "确实要覆盖此类字体的样式吗", "确定", "取消")) { SetActionStyle(); //EditorApplication.SaveScene (); } } GUILayout.Space(10); if (GUILayout.Button("编辑此类text风格", GUILayout.Width(250), GUILayout.Height(30))) { AcitonBool = true; if (EditorUtility.DisplayDialog("编辑字体之前请保存当前场景的设置", "是否要保存当前场景设置?", "确定", "取消")) { EditorApplication.SaveScene(); } EditorText.Clear(); IsEditor = true; LastSceneName = EditorApplication.currentScene; EditorApplication.NewScene(); if (EditorDemoText == null) { Canvas[] GetDemotext = Resources.LoadAll <Canvas> (""); foreach (Canvas child in GetDemotext) { if (child.name == "DemoSytleEditor") { GameObject textdemo = GameObject.Instantiate(child.gameObject); EditorDemoText = textdemo.GetComponentInChildren <Text> (); DemoGradient = EditorDemoText.GetComponent <TextStyleMessage> (); break; } } Camera.main.clearFlags = CameraClearFlags.Color; Camera.main.backgroundColor = Color.white; TypeStyleName = MyText.TextMark; LastTypeName = TypeStyleName; NowTypename = TypeStyleName; } return; } GUILayout.Space(10); } EditorGUILayout.EndVertical(); EditorGUI.EndDisabledGroup(); GUILayout.Space(20); EditorGUILayout.BeginVertical(); { if (GUILayout.Button("刷新", GUILayout.Width(250), GUILayout.Height(30))) { GetObjType(lastNub); } ScrollView = GUILayout.BeginScrollView(ScrollView); { TextList.DoLayoutList(); } } EditorGUILayout.EndVertical(); GUILayout.EndScrollView(); } else { if (GUILayout.Button("返回", GUILayout.Width(250), GUILayout.Height(30))) { if (!CheckName(TypeStyleName)) { if (EditorUtility.DisplayDialog("提示消息", "名字已被使用,请重新定义风格名称", "确定")) { return; } } if (TypeStyleName != string.Empty) { MyText.TextMark = TypeStyleName; } AcitonBool = false; IsEditor = false; EditorApplication.OpenScene(LastSceneName); UpdateAssetName(); UpdateSytleMessage(AllName[SaveNub]); } if (EditorDemoText != null && DemoGradient != null) { SetFontDemoSytle(); EditorUtility.SetDirty(EditorDemoText.gameObject); DemoGradient.UpdateState(); } } } EditorGUILayout.EndHorizontal(); GUILayout.Space(20); if (GUILayout.Button("关闭窗口", GUILayout.Width(150), GUILayout.Height(20))) { this.Close(); } if (EditorGUI.EndChangeCheck()) { if (_serializedObject != null) { _serializedObject.ApplyModifiedProperties(); } Text_serializedObject.ApplyModifiedProperties(); } }
/// <summary> /// Seperates the text into different groups by different types /// </summary> private static List <TextGroup> GroupTheText(string text) { var strColl = new List <TextGroup>(); for (int i = 0; i < text.Length; i++) { char c = text[i]; TextGroup group; if (strColl.Count > 0) { group = strColl[strColl.Count - 1]; } else { group = new TextGroup(TextGroupType.Space); strColl.Add(group); } if (char.IsWhiteSpace(c)) { if (group.Type == TextGroupType.Space) { group.Text.Append(c); } else { group = new TextGroup(TextGroupType.Space); group.Text.Append(c); strColl.Add(group); } } else if (IsSymbolChar(c)) { // NOTE: every symbol is a group itself group = new TextGroup(TextGroupType.Symbol); group.Text.Append(c); strColl.Add(group); } else if (char.IsNumber(c)) { if (group.Type == TextGroupType.Number) { group.Text.Append(c); } else { group = new TextGroup(TextGroupType.Number); group.Text.Append(c); strColl.Add(group); } } else if (IsPersianChar(c)) { if (group.Type == TextGroupType.Persian) { group.Text.Append(c); } else { group = new TextGroup(TextGroupType.Persian); group.Text.Append(c); strColl.Add(group); } } else { if (group.Type == TextGroupType.English) { group.Text.Append(c); } else { group = new TextGroup(TextGroupType.English); group.Text.Append(c); strColl.Add(group); } } } return(strColl); }
// Rebalance the tree at this node. public override void Rebalance(TextTree tree) { // get this node TextGroup node = this; // rebalance up the tree while(node != null) { // enforce upper bound on child count while(node.childCount > MAX_CHILD_COUNT) { // create a new root before splitting current root if(node.parent == null) { // create the new root node TextGroup root = new TextGroup(); // set the new root's level root.level = (node.level + 1); // insert the old root under the new root root.InsertChild(null, node); // set the root of the tree to the new root tree.root = root; } // create the new group for the excess children TextGroup group = new TextGroup(); // set the new group's level group.level = node.level; // get the first child of the node to be split TextNode child = node.first; // find the first excess child for(int i = 1; i < MIN_CHILD_COUNT; ++i) { child = child.next; } // insert first excess child under the new group group.InsertChildren(null, child.next); // insert group under the current node's parent node.parent.InsertChild(node, group); // set the current node to the new group node = group; } // enforce lower bound on child count while(node.childCount < MIN_CHILD_COUNT) { // handle the root node case if(node.parent == null) { // root needs at least two children or one line if((node.childCount == 1) && (node.level > 1)) { // set the root to its only child tree.root = (TextGroup)node.first; // remove new root from the old root node.RemoveChild(tree.root); } // we're done rebalancing return; } // rebalance the parent, if too few siblings if(node.parent.ChildCount < 2) { // rebalance the parent node.parent.Rebalance(tree); // try the current node again continue; } // get the next sibling of the current node TextGroup next = (TextGroup)node.next; // use previous and swap, if no next sibling if(next == null) { // set the next node to the current node next = node; // reset current node to previous sibling node = (TextGroup)node.prev; } // calculate the total child count for the nodes int fullCount = node.childCount + next.childCount; // merge the nodes or split up the children if(fullCount <= MAX_CHILD_COUNT) { // merge the children under a single node node.InsertChildren(node.last, next.first); // remove the empty node from the tree node.parent.RemoveChild(next); // continue rebalancing at this node, if needed if(fullCount < MIN_CHILD_COUNT) { continue; } } else { // calculate the first node's new child count int halfCount = (fullCount / 2); // move children around as needed if(node.childCount < halfCount) { // move the needed children to the first node node.InsertChildren (node.last, next.first, (halfCount - node.childCount)); } else if(node.childCount > halfCount) { // get the first child of the first node TextNode child = node.first; // get the first of the children to move for(int i = 1; i < halfCount; ++i) { child = child.next; } // move extra children to the second node next.InsertChildren(null, child); } } } // set the current node to its parent node = (TextGroup)node.parent; } }
/// <summary> /// Reordering RTL groups to display corrently in LTR context /// </summary> private static List <TextGroup> ReorderRtlGroupsForLtr(List <TextGroup> strGroups) { var lstFinal = new List <TextGroup>(); TextGroupType lastGroupType = TextGroupType.Start; var lstTemp = new List <TextGroup>(); // previous command required to skip the upcoming group bool skipTheNextGroup = false; Func <TextGroupAction?> commandToDo = null; for (int i = 0; i < strGroups.Count; i++) { TextGroupAction textGroupAction = TextGroupAction.FlushLastAndJustAdd; TextGroup group = strGroups[i]; TextGroupType thisGroupType = group.Type; TextGroupType?changeLastGroupType = null; // ----------------------------- // Initializations int nextItemIndex = i + 1; int futureItemIndex = i + 2; int previousItemIndex = i - 1; TextGroup nextItem = null, futureItem = null; TextGroup previousItem = null; if (nextItemIndex < strGroups.Count) { nextItem = strGroups[nextItemIndex]; } if (futureItemIndex < strGroups.Count) { futureItem = strGroups[futureItemIndex]; } if (previousItemIndex >= 0 && previousItemIndex < strGroups.Count) { previousItem = strGroups[previousItemIndex]; } // ------------------------- // conditions // ------------------------- // the previous action requires this group to be skipped if (skipTheNextGroup) { textGroupAction = TextGroupAction.SkipThis; skipTheNextGroup = false; } else if (thisGroupType == TextGroupType.Space) { // Status = 1 if (lastGroupType == TextGroupType.Start) { textGroupAction = TextGroupAction.FlushLastAndJustAdd; } else { textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } else if (thisGroupType == TextGroupType.English) { if (nextItem != null) { if (nextItem.Type == TextGroupType.Persian) { // status 5 textGroupAction = TextGroupAction.JoinCheckedThenFlush; } else if (nextItem.Type == TextGroupType.English) { // impossoble textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.Number) { // staus = 16 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.Symbol) { // status 15 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.Space) { if (futureItem == null) { // status 8 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (futureItem.Type == TextGroupType.Persian) { // status = ?? textGroupAction = TextGroupAction.JoinCheckedThenFlush; } else if (futureItem.Type == TextGroupType.Symbol) { TextGroupType?foundType; int foundIndex; bool has = HasInFuture(strGroups, i, new[] { TextGroupType.English, }, new[] { TextGroupType.Symbol, TextGroupType.Number, TextGroupType.Space, }, out foundType, out foundIndex); if (has) { // status ?? textGroupAction = TextGroupAction.JoinThisAndNextCheckLast; skipTheNextGroup = true; } else { // status = ?? textGroupAction = TextGroupAction.JoinThisCheckLast; } } else { // status 14 textGroupAction = TextGroupAction.JoinThisAndNextCheckLast; skipTheNextGroup = true; } } else { throw new Exception("Unknown condition!"); textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } else { // statsu =?? textGroupAction = TextGroupAction.JoinCheckedThenFlush; } } else if (thisGroupType == TextGroupType.Persian) { if (nextItem != null) { if (nextItem.Type == TextGroupType.Persian) { // statusu =self textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.English) { // staus 4 textGroupAction = TextGroupAction.JoinCheckedThenFlush; } else if (nextItem.Type == TextGroupType.Number) { // staus = 7 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.Symbol) { // status 9 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (nextItem.Type == TextGroupType.Space) { if (futureItem == null) { // status 8 textGroupAction = TextGroupAction.JoinThisCheckLast; } else if (futureItem.Type == TextGroupType.English) { // status = ?? textGroupAction = TextGroupAction.JoinCheckedThenFlush; } else if (futureItem.Type == TextGroupType.Symbol) { TextGroupType?foundType; int foundIndex; bool has = HasInFuture(strGroups, i, new[] { TextGroupType.Persian, }, new[] { TextGroupType.Symbol, TextGroupType.Number, TextGroupType.Space, }, out foundType, out foundIndex); if (has) { // status ?? textGroupAction = TextGroupAction.JoinThisAndNextCheckLast; skipTheNextGroup = true; } else { // status = ?? textGroupAction = TextGroupAction.JoinThisCheckLast; } } else { // status 10 textGroupAction = TextGroupAction.JoinThisAndNextCheckLast; skipTheNextGroup = true; } } else { throw new Exception("Unknown condition!"); textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } else { // statsu =?? textGroupAction = TextGroupAction.JoinCheckedThenFlush; } } else if (thisGroupType == TextGroupType.Symbol) { int foundIndex; TextGroupType?prevAlphabet; // is there any alphabet in previous secions? bool hasAlphabetInPrevious = HasInPrevious(strGroups, i, new[] { TextGroupType.Persian, TextGroupType.English, }, new[] { TextGroupType.Symbol, TextGroupType.Space, TextGroupType.Number, }, out prevAlphabet, out foundIndex); if (hasAlphabetInPrevious) { TextGroupType?nextAlphabet; // is there any same alphabet in coming groups? bool hasAlphabetInNext = HasInFuture(strGroups, i, new[] { prevAlphabet.Value, }, new[] { TextGroupType.Symbol, TextGroupType.Space, TextGroupType.Number, }, out nextAlphabet, out foundIndex); if (hasAlphabetInNext) { // status=?? textGroupAction = TextGroupAction.DoCommand; commandToDo = () => // do TextGroupAction { // let the loop continute on the alphabet, intead of anything else foundIndex--; for (int index = i; index <= foundIndex; index++) { // adding all the groups in the range/ they behave same lstTemp.Add(strGroups[index]); } TextGroup combined = JoinGroups(lstTemp); lstTemp.Clear(); lstTemp.Add(combined); // changing index of current group/ skiping added groups i = foundIndex; // changing the last group type group = combined; // don't do anything return(TextGroupAction.SkipThis); }; } else { // no alphabet in upcoming group so ,bracket kind characters should be switched group.Text = ReverseBrackedKindChar(group.Text); if (prevAlphabet != null && prevAlphabet.Value == TextGroupType.English) { // in english, if there is number after symbol, orders changes TextGroupType?hasNumber; // is there any same alphabet in coming groups? bool hasNumberInNext = HasInFuture(strGroups, i, new[] { TextGroupType.Number, }, new[] { TextGroupType.Symbol, TextGroupType.Space, TextGroupType.Number, }, out nextAlphabet, out foundIndex); if (hasNumberInNext) { textGroupAction = TextGroupAction.JoinThisDontCheck; changeLastGroupType = prevAlphabet.Value; //// next group checks the type, needed group.Type = prevAlphabet.Value; } else { // status = 17, 18, 19, 20, 2 textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } else { // status = 17, 18, 19, 20, 2 textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } } else { // status = 17, 18, 19, 20, 2 textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } else if (thisGroupType == TextGroupType.Number) { int foundIndex; TextGroupType?prevAlphabet; // is there any alphabet in previous secions? bool hasAlphabetInPrevious = HasInPrevious(strGroups, i, new[] { TextGroupType.Persian, TextGroupType.English, }, new[] { TextGroupType.Symbol, TextGroupType.Space, TextGroupType.Number, }, out prevAlphabet, out foundIndex); if (hasAlphabetInPrevious) { TextGroupType?nextAlphabet; // is there any same alphabet in coming groups? bool hasAlphabetInNext = HasInFuture(strGroups, i, new[] { prevAlphabet.Value, }, new[] { TextGroupType.Symbol, TextGroupType.Space, TextGroupType.Number, }, out nextAlphabet, out foundIndex); if (hasAlphabetInNext) { textGroupAction = TextGroupAction.DoCommand; commandToDo = () => // do TextGroupAction { // let the loop continute on the alphabet, intead of anything else foundIndex--; for (int index = i; index <= foundIndex; index++) { // adding all the groups in the range/ they behave same lstTemp.Add(strGroups[index]); } TextGroup combined = JoinGroups(lstTemp); lstTemp.Clear(); lstTemp.Add(combined); // changing index of current group/ skiping added groups i = foundIndex; // chaning the last group type group = combined; // don't do anything return(TextGroupAction.SkipThis); }; } else { // is previous item alphabet? if (previousItem != null && (previousItem.Type == TextGroupType.Persian || previousItem.Type == TextGroupType.English)) { // status =?? textGroupAction = TextGroupAction.JoinThisDontCheck; changeLastGroupType = previousItem.Type; // next group checks the type, needed group.Type = previousItem.Type; } else { // is next item alphabet? if (nextItem != null && (nextItem.Type == TextGroupType.Persian || nextItem.Type == TextGroupType.English)) { // status =?? textGroupAction = TextGroupAction.JoinThisDontCheck; changeLastGroupType = nextItem.Type; // next group checks the type, needed group.Type = nextItem.Type; } else { // status = ?? textGroupAction = TextGroupAction.JoinThisDontCheck; } } } } else { if (nextItem != null && (nextItem.Type == TextGroupType.Persian || nextItem.Type == TextGroupType.English)) { // status =?? textGroupAction = TextGroupAction.JoinThisDontCheck; changeLastGroupType = nextItem.Type; // next group checks the type, needed group.Type = nextItem.Type; } else { // status = ?? textGroupAction = TextGroupAction.FlushLastAndJustAdd; } } } else { // status = ?? textGroupAction = TextGroupAction.FlushLastAndJustAdd; } // ------------------------- // performing the specified actions // ------------------------- // if any specific command requred! if (textGroupAction == TextGroupAction.DoCommand) { if (commandToDo != null) { // setting the result textGroupAction = commandToDo() ?? TextGroupAction.SkipThis; } } // the actions switch (textGroupAction) { // ------------------------ case TextGroupAction.FlushLastAndJustAdd: TextGroup combinedFlush = JoinGroups(lstTemp); if (combinedFlush != null) { lstFinal.Add(combinedFlush); } lstTemp.Clear(); // just add lstFinal.Add(group); break; // ------------------------ case TextGroupAction.JoinCheckedThenFlush: if (lstTemp.Count > 0 && lstTemp[0].Type != thisGroupType) { TextGroup combine1 = JoinGroups(lstTemp); if (combine1 != null) { lstFinal.Add(combine1); } lstTemp.Clear(); } // add to grouop first lstTemp.Add(group); TextGroup combine2 = JoinGroups(lstTemp); if (combine2 != null) { lstFinal.Add(combine2); } lstTemp.Clear(); break; // ------------------------ case TextGroupAction.JoinThisCheckLast: // check the previous type, if it differs then flush it! if (lstTemp.Count > 0 && lstTemp[0].Type != thisGroupType) { TextGroup combine = JoinGroups(lstTemp); if (combine != null) { lstFinal.Add(combine); } lstTemp.Clear(); } lstTemp.Add(group); break; // ------------------------ case TextGroupAction.JoinThisAndNextCheckLast: // check the previous type, if it differs then flush it! if (lstTemp.Count > 0 && lstTemp[0].Type != thisGroupType) { TextGroup combine = JoinGroups(lstTemp); if (combine != null) { lstFinal.Add(combine); } lstTemp.Clear(); } lstTemp.Add(group); if (nextItem != null) { lstTemp.Add(nextItem); } break; // ------------------------ case TextGroupAction.JoinThisDontCheck: lstTemp.Add(group); break; // ------------------------ case TextGroupAction.DoCommand: // already done! break; // ------------------------ case TextGroupAction.SkipThis: // do nothing! break; } // saving last group type // check if custom type is requested if (changeLastGroupType != null) { lastGroupType = changeLastGroupType.Value; } else { lastGroupType = group.Type; } } TextGroup combineFinal = JoinGroups(lstTemp); if (combineFinal != null) { lstFinal.Add(combineFinal); } lstFinal.Reverse(); return(lstFinal); }