Esempio n. 1
0
        private void RenderText(TextLayout layout, IContentContainer container)
        {
            List <Verse> verses = layout.GetFormattedText();

            if (verses == null)
            {
                return;
            }
            if (verses.Count == 0)
            {
                return;
            }

            //	A text layout always starts a new paragraph. If the layout's text
            //	was generated from embedded HTML then the first verse will be a
            //	paragraph verse and that will start a new Word paragraph, but
            //	otherwise we must start the Word paragraph explicitly.
            IParagraph paragraph = null;

            if (!(verses[0] is ParagraphVerse))
            {
                paragraph = container.AddParagraph((s.TextStyle)layout.Style, layout.TrackingInfo);
            }

            foreach (Verse verse in verses)
            {
                if (verse is ParagraphVerse)
                {
                    paragraph = container.AddParagraph((s.TextStyle)layout.Style, layout.TrackingInfo);
                }
                else if (verse is LineBreakVerse)
                {
                    paragraph.AddLineBreak();
                }
                else
                {
                    paragraph.AddRun(verse.Text, verse.Format.Font, verse.Format.Color);
                }
            }
        }
Esempio n. 2
0
        private void RenderPhoto(PhotoLayout layout, IContentContainer container)
        {
            //	Add the photo part to the document
            string imageId = _document.AddImage(layout.PhotoData.RawData);

            //	Add a new paragraph and insert into it a reference to the photo.
            //
            //	A photo is always in a paragraph of its own, and the photo
            //	style's border and padding etc. are rendered on the paragraph.
//TODO: I'm not sure that that statement about styles is correct

            s.TextStyle paraStyle = null;
            if (layout.Style != null)
            {
                s.PhotoStyle photoStyle = (s.PhotoStyle)layout.Style;
                paraStyle         = new s.TextStyle();
                paraStyle.Border  = photoStyle.Border;
                paraStyle.Padding = photoStyle.Padding;
            }
            IParagraph paragraph = container.AddParagraph(paraStyle, layout.TrackingInfo);

            paragraph.AddImage(imageId, layout.Bounds.Width, layout.Bounds.Height);
        }
Esempio n. 3
0
        private void RenderListItem(ListItemLayout layout, IContentContainer container)
        {
            //	A list item, which is based on a single design layout, can
            //	include any number of design paragraphs introduced by embedded
            //	HTML <p> tags. To render these as a single item in the Word
            //	list, they must all be rendered as a single Word paragraph.
            //	We achieve this by concatenating all the design paragraphs
            //	together, with double line break separators. The first line
            //	break starts a new line, and the second inserts some whitespace.
            //
            //	A nested list is introduced by a group layout, which is a single
            //	item in the current list and which contains its own list.
            //
            //	We only support text content in list items - no photos.
            //
            //	So the list item layout's content sublayout is always either
            //	a text layout or a group layout. And the list item is always
            //	a single Word paragraph.

            //	The item style is to be found in the item's list's style
            s.ListStyle listStyle           = (s.ListStyle)layout.Style;
            s.TextStyle itemStyle           = listStyle.ItemStyle;
            IParagraph  paragraph           = container.AddParagraph(itemStyle, layout.TrackingInfo);
            int         numberingInstanceId = _numberingInstances.Peek();     // stack guaranteed not to be empty

            paragraph.SetNumbering(numberingInstanceId, _numberingLevel);

            switch (layout.ContentLayout.LayoutType)
            {
            case LayoutType.Text:
            {
                TextLayout   contentLayout = (TextLayout)layout.ContentLayout;
                List <Verse> verses        = contentLayout.GetFormattedText();
                if (verses == null)
                {
                    break;
                }
                if (verses.Count == 0)
                {
                    break;
                }
                foreach (Verse verse in verses)
                {
                    if (verse is ParagraphVerse)
                    {
                        //	Two line breaks to look like a new paragraph without actually
                        //	being a new Word paragraph. But don't do this if it's the first
                        //	verse.
                        if (verse == verses[0])
                        {
                            continue;
                        }
                        paragraph.AddLineBreak();
                        paragraph.AddLineBreak();
                    }
                    else if (verse is LineBreakVerse)
                    {
                        paragraph.AddLineBreak();
                    }
                    else
                    {
                        paragraph.AddRun(verse.Text, verse.Format.Font, verse.Format.Color);
                    }
                }
                break;
            }

            case LayoutType.Group:
            {
                foreach (Layout sublayout in layout.ContentLayout.SubLayouts)
                {
                    Render(sublayout, container);
                }
                break;
            }

            default:
            {
                break;
            }
            }
        }