public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value == null)
            {
                return(null);
            }

            var status = (UserStatus)value;

            var channel = status.SourceChannel ?? ChannelsManager.Channels.First(c => c.Configuration.DisplayName == "Twitter").Configuration;

            var profileuri = channel.ProfileInfoBuilder.BuildServiceProfileUrl(status.From);
            Uri uri        = Uri.IsWellFormedUriString(profileuri, UriKind.Absolute) ? new Uri(profileuri) : new Uri("http://www.google.com");

            var sender = new WebHyperlink {
                NavigateUri = uri, FontWeight = FontWeights.Bold, Style = (Style)Application.Current.FindResource("TitleNameHyperlink")
            };

            sender.Inlines.Add(new Run(status.From.DisplayName));

            var intro = new TextBlock {
                Text = "Reply to ", Style = (Style)Application.Current.FindResource("NormalTextBlock")
            };
            var text = new TextBlock {
                TextTrimming = TextTrimming.CharacterEllipsis, Foreground = (Brush)Application.Current.FindResource("SlightlyDimmedForegroundColor")
            };

            text.Inlines.Add(intro);
            text.Inlines.Add(" ");
            text.Inlines.Add(sender);
            text.Inlines.Add(" ");
            text.Inlines.Add(status.Status);

            return(text);
        }
示例#2
0
        private TextSegment getTextSegment(HNode node, TextState parentTextState)
        {
            TextSegment textSegment = null;

            // Text element
            if (node is HNodeText)
            {
                textSegment           = new TextSegment();
                textSegment.TextState = parentTextState;
                textSegment.Text      = (node as HNodeText).Text;


                if (hyperlinkNode != null)
                {
                    Aspose.Pdf.WebHyperlink pdfHyperlink = new WebHyperlink(hyperlinkNode.GetAttribute("href", "#"));
                    textSegment.Hyperlink = pdfHyperlink;
                }
            }
            // New Line element <br />
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.br)
            {
                /*
                 * //слетают стили!!!
                 * textSegment = new TextSegment();
                 * //textSegment.TextState = parentTextState;
                 * textSegment.Text = Environment.NewLine;
                 */

                pdfNewLine      = new TextSegment();
                pdfNewLine.Text = Environment.NewLine;
            }
            // Hyperlink element <a>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.a)
            {
                PUtil.TextStateUtil.TextState_ModifyForHyperlink(parentTextState);
                PUtil.TextStateUtil.TextState_ModifyFromHStyles((node as HNodeTag).Styles, parentTextState);
            }
            // Bold text element <b>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.b)
            {
                PUtil.TextStateUtil.TextState_ModifyForBold(parentTextState);
                PUtil.TextStateUtil.TextState_ModifyFromHStyles((node as HNodeTag).Styles, parentTextState);
            }
            // Italic text element <i>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.i)
            {
                PUtil.TextStateUtil.TextState_ModifyForItalic(parentTextState);
                PUtil.TextStateUtil.TextState_ModifyFromHStyles((node as HNodeTag).Styles, parentTextState);
            }
            // Image element <img>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.img)
            {
                pdfImage = getImage(node as HNodeTag);
            }
            // Form field element <input>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.input)
            {
                pdfFormField = getFormField(node as HNodeTag);
            }
            // Button element <button>
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.button)
            {
                pdfFormField = getFormFieldButton(node as HNodeTag);
            }

            // TODO - other inline tags


            return(textSegment);
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var status = (UserStatus)value;

            var channel = status.SourceChannel ?? ChannelsManager.Channels.First(c => c.Configuration.DisplayName == "Twitter").Configuration;

            var profileuri = channel.ProfileInfoBuilder.BuildServiceProfileUrl(status.From);
            Uri uri        = Uri.IsWellFormedUriString(profileuri, UriKind.Absolute) ? new Uri(profileuri) : new Uri("http://www.google.com");

            var sender = new WebHyperlink {
                NavigateUri = uri, FontWeight = FontWeights.Bold, Style = (Style)Application.Current.FindResource("TitleNameHyperlink")
            };

            sender.Inlines.Add(new Run(status.From.DisplayName));

            var text = new TextBlock {
                TextWrapping = TextWrapping.Wrap, Foreground = (Brush)Application.Current.FindResource("SlightlyDimmedForegroundColor")
            };

            text.Inlines.Add(sender);
            text.Inlines.Add(" ");

            if (status.To != null)
            {
                var toProfileuri = channel.ProfileInfoBuilder.BuildServiceProfileUrl(status.To);
                Uri toUri        = Uri.IsWellFormedUriString(toProfileuri, UriKind.Absolute) ? new Uri(toProfileuri) : new Uri("http://www.google.com");

                var recipient = new WebHyperlink {
                    NavigateUri = toUri, FontWeight = FontWeights.Bold, Style = (Style)Application.Current.FindResource("TitleNameHyperlink")
                };
                recipient.Inlines.Add(new Run(status.To.DisplayName));

                text.Inlines.Add(" » ");
                text.Inlines.Add(recipient);
                text.Inlines.Add(" ");
            }

            var source = status.Status.MakeLinksClickableIncludingMailto();

            if (channel.DisplayName == "Twitter")
            {
                source = source.MakeTwitterLinksClickable();
            }

            HtmlParser.AppendTo(text, source);

            foreach (var inline in text.Inlines)
            {
                // Attach markread handler to status updates
                if (inline is Hyperlink)
                {
                    (inline as Hyperlink).Click += delegate { status.TrackAction(ActionType.Read); }
                }
                ;
            }

            text.Inlines.Add("\n");
            text.Inlines.Add(new TextBlock {
                Text = status.SortDate.ToRelativeTime(), Opacity = 0.35, Style = (Style)Application.Current.FindResource("NormalTextBlock")
            });

            return(text);
        }
示例#4
0
        private void createNode(HNode node, TextState parentTextState)
        {
            TextState nodeTextState = new TextState();

            nodeTextState.ApplyChangesFrom(parentTextState);

            if (node is HNodeTag)
            {
                PUtil.TextStateUtil.TextState_ModifyFromHStyles((node as HNodeTag).Styles, nodeTextState);
            }

            // Block element
            if ((node is HNodeTag) && HUtil.TagUtil.IsBlockTag((node as HNodeTag).TagType))
            {
                addTextFragmentOnPage();
                createTextFragmentByTagType((node as HNodeTag).TagType);
            }
            // Inline element or Text element
            else if (
                (node is HNodeTag) && HUtil.TagUtil.IsInlineTag((node as HNodeTag).TagType)
                ||
                (node is HNodeText)
                )
            {
                if ((node is HNodeText) && (node as HNodeText).ParentNode != null && ((node as HNodeText).ParentNode is HNodeTag) && (((node as HNodeText).ParentNode as HNodeTag)).TagType == HTagType.button)
                {
                    //
                }
                else
                {
                    // Create TextSegment for element
                    TextSegment textSegment = getTextSegment(node, nodeTextState);

                    // New Line, <BR />
                    if (pdfNewLine != null)
                    {
                        double marginTop    = 0;
                        double marginBottom = 0;
                        if (pdfTextFragment != null)
                        {
                            marginBottom = pdfTextFragment.Margin.Bottom;
                            pdfTextFragment.Margin.Bottom = 0;
                        }

                        addTextFragmentOnPage();
                        createTextFragmentByTagType(HTagType.div);

                        if (pdfTextFragment != null)
                        {
                            pdfTextFragment.Margin.Top    = marginTop;
                            pdfTextFragment.Margin.Bottom = marginBottom;
                        }

                        pdfNewLine = null;
                    }
                    // Image
                    else if (pdfImage != null)
                    {
                        double     imageHeight = pdfImage.FixHeight;
                        MarginInfo margin      = new MarginInfo(0, 12, 0, 12);
                        if (pdfTextFragment == null || pdfTextFragment.Segments.Count == 0 || (pdfTextFragment.Segments.Count == 1 && pdfTextFragment.Segments[1].Text == String.Empty))
                        {
                        }
                        else
                        {
                            pdfTextFragment.Margin.Top += imageHeight;
                            margin = new MarginInfo(0, pdfTextFragment.Margin.Bottom, 0, -1 * imageHeight);
                        }

                        addTextFragmentOnPage(false);

                        pdfImage.IsInLineParagraph = true;
                        pdfImage.Margin            = margin;
                        inlineParagraphMargin      = margin;


                        if (hyperlinkNode != null)
                        {
                            Aspose.Pdf.WebHyperlink pdfHyperlink = new WebHyperlink(hyperlinkNode.GetAttribute("href", "#"));
                            pdfImage.Hyperlink = pdfHyperlink;
                        }

                        pdfPage.Paragraphs.Add(pdfImage);

                        if (node.NextNode == null)
                        {
                            updateCurrentPage();
                        }

                        pdfImage = null;
                    }
                    // Form Field Element
                    else if (pdfFormField != null)
                    {
                        //
                        //
                        //

                        double     inputHeight = pdfFormField.Height;
                        MarginInfo margin      = new MarginInfo(0, 12, 0, 12);
                        if (pdfTextFragment == null || pdfTextFragment.Segments.Count == 0 || (pdfTextFragment.Segments.Count == 1 && pdfTextFragment.Segments[1].Text == String.Empty))
                        {
                        }
                        else
                        {
                            double textFragmentHeight = pdfTextFragment.Rectangle.Height;

                            margin = pdfTextFragment.Margin;

                            pdfTextFragment.Margin.Bottom = textFragmentHeight - inputHeight;
                            pdfTextFragment.Margin.Top   += Math.Max(0, (inputHeight - textFragmentHeight));

                            pdfTextFragment.Margin.Top += inputHeight;
                        }


                        addTextFragmentOnPage(false);

                        pdfFormField.IsInLineParagraph = true;
                        pdfFormField.Margin            = margin;
                        inlineParagraphMargin          = new MarginInfo(pdfFormField.Width, margin.Bottom, margin.Right, margin.Top);


                        pdfPage.Paragraphs.Add(pdfFormField);

                        if (node.NextNode == null)
                        {
                            updateCurrentPage();
                        }

                        pdfFormField = null;
                    }
                    // TextFragment for InLineParagraph mode
                    else if (pdfTextFragment == null)
                    {
                        HTagType tagTypeForTextFragment           = HTagType.div;
                        bool     isInLineParagraphForTextFragment = false;


                        bool flagPreviousImage = false;
                        bool flagPreviousInput = false;

                        if (node.PrevNode != null && (node.PrevNode is HNodeTag) && (node.PrevNode as HNodeTag).TagType == HTagType.img)
                        {
                            // prev image element
                            if (node.ParentNode != null && (node.ParentNode is HNodeTag) && HUtil.TagUtil.IsBlockTag((node.ParentNode as HNodeTag).TagType))
                            {
                                tagTypeForTextFragment = (node.ParentNode as HNodeTag).TagType;
                            }

                            isInLineParagraphForTextFragment = true;
                            flagPreviousImage = true;
                        }
                        else if (node.PrevNode != null && (node.PrevNode is HNodeTag) && (node.PrevNode as HNodeTag).TagType == HTagType.input)
                        {
                            // prev input element
                            if (node.ParentNode != null && (node.ParentNode is HNodeTag) && HUtil.TagUtil.IsBlockTag((node.ParentNode as HNodeTag).TagType))
                            {
                                tagTypeForTextFragment = (node.ParentNode as HNodeTag).TagType;
                            }

                            isInLineParagraphForTextFragment = true;
                            flagPreviousInput = true;
                        }
                        else
                        {
                        }

                        createTextFragmentByTagType(tagTypeForTextFragment);
                        pdfTextFragment.IsInLineParagraph = isInLineParagraphForTextFragment;


                        if ((flagPreviousImage || flagPreviousInput) && inlineParagraphMargin != null)
                        {
                            pdfTextFragment.Margin.Top    = -1 * pdfTextFragment.Rectangle.Height - inlineParagraphMargin.Bottom;
                            pdfTextFragment.Margin.Bottom = inlineParagraphMargin.Bottom;

                            pdfTextFragment.Margin.Left = inlineParagraphMargin.Left;

                            inlineParagraphMargin = null;
                        }
                    }



                    if (textSegment != null && pdfTextFragment != null)
                    //if (textSegment != null)
                    {
                        pdfTextFragment.Segments.Add(textSegment);
                    }
                }
            }

            //
            // Create Nodes recursively with consider the hyperlink
            //
            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.a)
            {
                hyperlinkNode = (node as HNodeTag);
            }

            if (node is HNodeContainer)
            {
                foreach (HNode childNode in (node as HNodeContainer).ChildNodes)
                {
                    createNode(childNode, nodeTextState);
                }
            }

            if ((node is HNodeTag) && (node as HNodeTag).TagType == HTagType.a)
            {
                hyperlinkNode = null;
            }
            //
            //
            //


            //
            // Add Text Fragment on Page (if need)
            //
            if ((node is HNodeTag) && HUtil.TagUtil.IsBlockTag((node as HNodeTag).TagType))
            {
                addTextFragmentOnPage();
            }
            //
            //
            //
        }