Пример #1
0
        private void RenderList(ListLayout layout, IContentContainer container)
        {
            ++_numberingLevel;
            s.ListStyle listStyle = (s.ListStyle)layout.Style;

            //	Translate the bullet text from design syntax to Word syntax. The
            //	design specification can include formatting of its own, unrelated
            //	to the list style. The easiest way to interpret such formatting
            //	is to create a text layout from the bullet text, which will
            //	separate the formatting from the text. If the bullet includes
            //	formatting then the new text layout will start with a paragraph
            //	verse, which we'll ignore. And it could contain any
            //	number of other verses, but a numbering definition in Word supports
            //	only a single run, so we just concatenate the text from all the
            //	verses, and apply the first verse format we find. Note that our
            //	report design language doesn't support including lower level numbers
            //	in the number, such as 3x in 1, 2, 3a, 3b, 3c, 4, 5 etc.
            s.BulletStyle bulletStyle = listStyle.BulletStyle;
            string        bulletText  = bulletStyle.BulletText
                                        .Replace("%", "%%")
                                        .Replace(ListItemLayout.BulletNumberProperty, $"%{_numberingLevel+1}");
            TextFormat bulletFormat = new TextFormat(bulletStyle.Font, bulletStyle.Color);
            TextBlock  block        = new TextBlock(bulletText, bulletFormat, _generator);

            bulletText   = block.Verses.Select(v => v.Text).Aggregate((c, n) => c + n);
            bulletFormat = block.Verses.Select(v => v.Format).Where(f => f != null).FirstOrDefault();
            int numberingStyleId = _document.AddNumberingStyle(bulletStyle, _numberingLevel, bulletText);

            //	Create a numbering instance based on the numbering style, and add it
            //	to the paragraph. As far as I can make out, in a sequence of numbered
            //	paragraphs every paragraph refers to the one numbering instance.
            //	Any number of such sequences can get their numbering from the one
            //	underlying abstract definition, but each sequence would have its own
            //	instance. Instances are stored in the numbering part along with the
            //	abstract definitions.
            //
            //	We have to store abstract definitions in a dictionary in the document
            //	because we need random access to them so that different layouts in the
            //	design can share a single definition. But we can store instances in a
            //	simple stack in this class because each one is needed only for the
            //	current list.
            int numberingInstanceId = _document.AddNumberingInstance(numberingStyleId);

            _numberingInstances.Push(numberingInstanceId);



            //	Lists in the design can be nested - that's how we do indented list
            //	levels. But in Word each item must be its own paragraph, and the
            //	items together form the list by being contiguous paragraphs with
            //	a common numbering style. That is, Word doesn't have lists, but
            //	rather just has numbered paragraphs.
            foreach (Layout sublayout in layout.SubLayouts)
            {
                Render(sublayout, container);
            }

            _numberingInstances.Pop();
            --_numberingLevel;
        }
Пример #2
0
        /// <summary>
        /// If any sublayout is a list layout with its "merge" property set, then
        /// replace that layout in this list with its individual elements.
        /// </summary>
        private void MergeSubLists()
        {
            List <Layout> afterMerge = new List <Layout>();

            foreach (Layout layout in _subLayouts)
            {
                ListLayout sublist = layout as ListLayout;
                if (sublist != null && sublist._merge)
                {
                    //	Recursively merge any sublists of the sublist
                    sublist.MergeSubLists();

                    //	Add the sublist's items to our new list
                    afterMerge.AddRange(sublist._subLayouts);
                }
                else
                {
                    //	Add the layout to our new list, unchanged
                    afterMerge.Add(layout);
                }
            }

            _subLayouts.Clear();
            foreach (Layout layout in afterMerge)
            {
                AddSubLayout(layout);
            }
        }
Пример #3
0
 /// <summary>
 /// Copy constructor used during layout expansion and page break handling.
 /// </summary>
 public ListLayout(ListLayout src)
     : base(src)
 {
     _emptyText  = src._emptyText;
     _whenEmpty  = src._whenEmpty?.DeepCopy();
     _merge      = src._merge;
     _style      = src._style;
     _emptyStyle = src._emptyStyle;
 }
Пример #4
0
        private void RenderListLayout(ListLayout layout, Page page)
        {
            //	Draw the border before the content so that
            //	if for any reason the text exceeds the bounds (which should be impossible)
            //	then at least the text will still be visible.
            ListStyle style = (ListStyle)layout.Style;

            RenderBorder(layout.Bounds, style.Border, page);

            foreach (ListItemLayout item in layout.SubLayouts)
            {
                RenderListItemLayout(item, page);
            }
        }