public static bool ContainsEmoji(string str) { if (string.IsNullOrEmpty(str)) { return(false); } TextElementEnumerator elementEnumerator = StringInfo.GetTextElementEnumerator(str); bool flag1 = elementEnumerator.MoveNext(); while (flag1) { string textElement1 = elementEnumerator.GetTextElement(); string hexString1 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1)); if (hexString1 == "") { flag1 = elementEnumerator.MoveNext(); } else { bool flag2 = true; bool flag3 = BrowserNavigationService._flagsPrefixes.Contains(hexString1); int elementIndex = elementEnumerator.ElementIndex; if ((flag3 || BrowserNavigationService._modificatableSmiles.Contains(hexString1)) && elementEnumerator.MoveNext()) { string textElement2 = elementEnumerator.GetTextElement(); string hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); if (hexString2 == "" && elementEnumerator.MoveNext()) { textElement2 = elementEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); } if (hexString2 != "" && (flag3 || BrowserNavigationService._smilesModificators.Contains(hexString2))) { flag2 = false; hexString1 += hexString2; textElement1 += textElement2; } else { elementEnumerator.Reset(); elementEnumerator.MoveNext(); while (elementEnumerator.ElementIndex != elementIndex) { elementEnumerator.MoveNext(); } } } if (flag2) { BrowserNavigationService.CheckRelationsSmiles(ref hexString1, ref elementEnumerator, ref textElement1); } if (Emoji.Dict.ContainsKey(hexString1)) { return(true); } flag1 = elementEnumerator.MoveNext(); } } return(false); }
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RichTextBox text_block = d as RichTextBox; if (text_block == null) { return; } bool disableHyperlinks = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block); string textId = BrowserNavigationService.GetTextId((DependencyObject)text_block); text_block.Blocks.Clear(); Paragraph par = new Paragraph(); string s = (string)e.NewValue; if (string.IsNullOrEmpty(s)) { return; } foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(s))) { char[] chArray = new char[1] { '\b' }; string[] strArray = str1.Split(chArray); if (strArray.Length == 1) { BrowserNavigationService.AddRawText(text_block, par, strArray[0]); } else if (strArray.Length > 1) { if (disableHyperlinks) { BrowserNavigationService.AddRawText(text_block, par, strArray[1]); } else { if (strArray[0].Contains(BrowserNavigationService._searchFeedPrefix)) { int num = strArray[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length; string str2 = strArray[0].Substring(num); strArray[0] = strArray[0].Substring(0, num) + WebUtility.UrlEncode(str2); } Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(strArray[1], strArray[0], (Action <Hyperlink, string>)((h, navstr) => { EventAggregator.Current.Publish((object)new HyperlinkClickedEvent() { HyperlinkOwnerId = textId }); BrowserNavigationService.NavigateOnHyperlink(navstr); }), text_block.Foreground); par.Inlines.Add((Inline)hyperlink); } } } text_block.Blocks.Add((Block)par); }
private void ParseLineExtended(string allText) { if (string.IsNullOrEmpty(allText)) { return; } int startIndex = this.MAX_STR_LENGTH; if (startIndex >= allText.Length) { startIndex = allText.Length - 1; } int num1 = allText.IndexOf(".", startIndex); if (num1 >= 0 && num1 - startIndex < 200) { startIndex = num1; } else { int num2 = allText.IndexOf(' ', startIndex); if (num2 >= 0 && num2 - startIndex < 100) { startIndex = num2; } } while (startIndex + 1 < allText.Length && (int)allText[startIndex + 1] == 32) { ++startIndex; } string str = allText.Substring(0, startIndex + 1); RichTextBox textBlock = this.GetTextBlock(); BrowserNavigationService.SetText((DependencyObject)textBlock, str); this.stackPanel.Children.Add((UIElement)textBlock); allText = allText.Substring(startIndex + 1); if (allText.Length <= 0) { return; } this.ParseLineExtended(allText); }
private void ParseText(string value) { if (value == null) { value = ""; } if (this.stackPanel == null) { return; } ((PresentationFrameworkCollection <UIElement>)((Panel)this.stackPanel).Children).Clear(); if (this.CheckFitInMaxRenderHeight(value)) { RichTextBox textBlock = this.GetTextBlock(); BrowserNavigationService.SetText((DependencyObject)textBlock, value); this.stackPanel.Children.Add((UIElement)textBlock); } else { this.ParseLineExtended(value); } }
private RichTextBox GetTextBlock() { RichTextBox richTextBox = new RichTextBox(); richTextBox.Tap += new EventHandler <GestureEventArgs>(this.textBlock_Tap); richTextBox.TextWrapping = this.TextWrapping; if (this.LineHeight > 0.0) { richTextBox.LineStackingStrategy = LineStackingStrategy.BlockLineHeight; richTextBox.LineHeight = this.LineHeight; } richTextBox.IsReadOnly = true; richTextBox.FontSize = this.FontSize; richTextBox.FontFamily = this.FontFamily; richTextBox.HorizontalContentAlignment = this.HorizontalContentAlignment; richTextBox.TextAlignment = this.TextAlignment; richTextBox.Foreground = this.Foreground; richTextBox.Padding = new Thickness(-12.0, 0.0, 0.0, 0.0); BrowserNavigationService.SetDisableHyperlinks((DependencyObject)richTextBox, this.DisableHyperlinks); BrowserNavigationService.SetTextId((DependencyObject)richTextBox, this.TextId); return(richTextBox); }
private RichTextBox GetTextBlock() { RichTextBox richTextBox = new RichTextBox(); ((UIElement)richTextBox).Tap += (new EventHandler <System.Windows.Input.GestureEventArgs>(this.textBlock_Tap)); richTextBox.TextWrapping = this.TextWrapping; if (this.LineHeight > 0.0) { richTextBox.LineStackingStrategy = ((LineStackingStrategy)1); richTextBox.LineHeight = this.LineHeight; } richTextBox.IsReadOnly = true; richTextBox.FontSize = base.FontSize; richTextBox.FontFamily = base.FontFamily; richTextBox.HorizontalContentAlignment = base.HorizontalContentAlignment; richTextBox.TextAlignment = this.TextAlignment; richTextBox.Foreground = base.Foreground; richTextBox.Padding = (new Thickness(-12.0, 0.0, -12.0, 0.0)); BrowserNavigationService.SetDisableHyperlinks((DependencyObject)richTextBox, this.DisableHyperlinks); BrowserNavigationService.SetTextId((DependencyObject)richTextBox, this.TextId); BrowserNavigationService.SetHideHyperlinksForeground((DependencyObject)richTextBox, this.HideHyperlinksForeground); return(richTextBox); }
private static void CheckRelationsSmiles(ref string bytesStr, ref TextElementEnumerator textEnumerator, ref string text) { bool flag1 = true; int elementIndex1 = textEnumerator.ElementIndex; bool flag2 = bytesStr == "D83DDC68"; if ((flag2 || bytesStr == "D83DDC69") && textEnumerator.MoveNext()) { string textElement1 = textEnumerator.GetTextElement(); string hexString1 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1)); if (hexString1 == "" && textEnumerator.MoveNext()) { textElement1 = textEnumerator.GetTextElement(); hexString1 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1)); } if (hexString1 == "2764" && textEnumerator.MoveNext()) { string textElement2 = textEnumerator.GetTextElement(); string hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); if (hexString2 == "" && textEnumerator.MoveNext()) { textElement2 = textEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); } string str1 = ""; string str2 = ""; if (hexString2 == "D83DDC8B" && textEnumerator.MoveNext()) { str1 = textElement2; str2 = hexString2; textElement2 = textEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); if (hexString2 == "" && textEnumerator.MoveNext()) { textElement2 = textEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); } } if (flag2 && hexString2 == "D83DDC68" || !flag2 && hexString2 == "D83DDC69") { flag1 = false; bytesStr = bytesStr + hexString1 + str2 + hexString2; text = text + textElement1 + str1 + textElement2; } } else if ((hexString1 == "D83DDC68" || hexString1 == "D83DDC69") && (!(bytesStr == "D83DDC69") || !(hexString1 == "D83DDC68")) && textEnumerator.MoveNext()) { string textElement2 = textEnumerator.GetTextElement(); string hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); if (hexString2 == "" && textEnumerator.MoveNext()) { textElement2 = textEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); } if (hexString2 == "D83DDC67" || hexString2 == "D83DDC66") { bool flag3 = false; int elementIndex2 = textEnumerator.ElementIndex; flag1 = false; if (textEnumerator.MoveNext()) { string textElement3 = textEnumerator.GetTextElement(); string hexString3 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement3)); if (hexString3 == "" && textEnumerator.MoveNext()) { textElement3 = textEnumerator.GetTextElement(); hexString3 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement3)); } if ((hexString3 == "D83DDC67" || hexString3 == "D83DDC66") && (!(hexString2 == "D83DDC66") || !(hexString3 == "D83DDC67"))) { flag3 = true; bytesStr = bytesStr + hexString1 + hexString2 + hexString3; text = text + textElement1 + textElement2 + textElement3; } else { textEnumerator.Reset(); textEnumerator.MoveNext(); while (textEnumerator.ElementIndex != elementIndex2) { textEnumerator.MoveNext(); } } } if (!flag3) { bytesStr = bytesStr + hexString1 + hexString2; text = text + textElement1 + textElement2; } } } } if (!(textEnumerator.ElementIndex != elementIndex1 & flag1)) { return; } textEnumerator.Reset(); textEnumerator.MoveNext(); while (textEnumerator.ElementIndex != elementIndex1) { textEnumerator.MoveNext(); } }
private static void AddRawText(RichTextBox text_block, Paragraph par, string raw_text) { TextElementEnumerator elementEnumerator = StringInfo.GetTextElementEnumerator(raw_text); StringBuilder stringBuilder = new StringBuilder(); bool flag1 = elementEnumerator.MoveNext(); while (flag1) { string textElement1 = elementEnumerator.GetTextElement(); string hexString1 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement1)); if (hexString1 == "") { flag1 = elementEnumerator.MoveNext(); } else { bool flag2 = true; bool flag3 = BrowserNavigationService._flagsPrefixes.Contains(hexString1); int elementIndex = elementEnumerator.ElementIndex; if ((flag3 || BrowserNavigationService._modificatableSmiles.Contains(hexString1)) && elementEnumerator.MoveNext()) { string textElement2 = elementEnumerator.GetTextElement(); string hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); if (hexString2 == "" && elementEnumerator.MoveNext()) { textElement2 = elementEnumerator.GetTextElement(); hexString2 = BrowserNavigationService.ConvertToHexString(Encoding.BigEndianUnicode.GetBytes(textElement2)); } if (hexString2 != "" && (flag3 || BrowserNavigationService._smilesModificators.Contains(hexString2))) { flag2 = false; hexString1 += hexString2; textElement1 += textElement2; } else { elementEnumerator.Reset(); elementEnumerator.MoveNext(); while (elementEnumerator.ElementIndex != elementIndex) { elementEnumerator.MoveNext(); } } } if (flag2) { BrowserNavigationService.CheckRelationsSmiles(ref hexString1, ref elementEnumerator, ref textElement1); } string name; Emoji.Dict.TryGetValue(hexString1, out name); if (name != null) { string text = stringBuilder.ToString(); stringBuilder = stringBuilder.Clear(); if (text != string.Empty) { ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetRunWithStyle(text, text_block)); } ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetImage(name)); } else { stringBuilder = stringBuilder.Append(textElement1); } flag1 = elementEnumerator.MoveNext(); } } string text1 = stringBuilder.ToString(); if (!(text1 != string.Empty)) { return; } ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)BrowserNavigationService.GetRunWithStyle(text1, text_block)); }
private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { RichTextBox text_block = d as RichTextBox; if (text_block == null) { return; } bool disableHyperlinks = BrowserNavigationService.GetDisableHyperlinks((DependencyObject)text_block); string textId = BrowserNavigationService.GetTextId((DependencyObject)text_block); bool hyperlinksForeground = BrowserNavigationService.GetHideHyperlinksForeground((DependencyObject)text_block); ((PresentationFrameworkCollection <Block>)text_block.Blocks).Clear(); Paragraph par = new Paragraph(); // ISSUE: explicit reference operation string newValue = (string)e.NewValue; if (string.IsNullOrEmpty(newValue)) { return; } foreach (string str1 in BrowserNavigationService.ParseText(BrowserNavigationService.PreprocessTextForGroupBoardMentions(newValue))) { string[] innerSplit = str1.Split('\b'); if (innerSplit.Length == 1) { BrowserNavigationService.AddRawText(text_block, par, innerSplit[0]); } else if (innerSplit.Length > 1) { if (disableHyperlinks) { BrowserNavigationService.AddRawText(text_block, par, innerSplit[1]); } else { if (innerSplit[0].Contains(BrowserNavigationService._searchFeedPrefix)) { int num = innerSplit[0].IndexOf(BrowserNavigationService._searchFeedPrefix) + BrowserNavigationService._searchFeedPrefix.Length; string str2 = innerSplit[0].Substring(num); innerSplit[0] = innerSplit[0].Substring(0, num) + WebUtility.UrlEncode(str2); } Hyperlink hyperlink = HyperlinkHelper.GenerateHyperlink(innerSplit[1], innerSplit[0], (Action <Hyperlink, string>)((h, navstr) => { EventAggregator.Current.Publish(new HyperlinkClickedEvent() { HyperlinkOwnerId = textId }); if (!string.IsNullOrEmpty(textId)) { string str = navstr; if (innerSplit.Length > 2) { str = str.Replace("https://", "vkontakte://"); } EventAggregator.Current.Publish(new PostInteractionEvent() { PostId = textId, Action = PostInteractionAction.link_click, Link = str }); } BrowserNavigationService.NavigateOnHyperlink(navstr); }), ((Control)text_block).Foreground, hyperlinksForeground ? HyperlinkState.MatchForeground : HyperlinkState.Normal); ((PresentationFrameworkCollection <Inline>)par.Inlines).Add((Inline)hyperlink); } } } ((PresentationFrameworkCollection <Block>)text_block.Blocks).Add((Block)par); }