Beispiel #1
0
        [ElementProcessing] // require refactoring (again)
        public bool ProcessParagraph(IElementProcessingState state, Paragraph p)
        {
            var props = p.ParagraphProperties;

            state.SetContext(props);
            state.ProcessingState.GetContext(out ICssRegistrator registrator);
            state.GetContext(out ParagraphContext pContext);
            var parentVNode = pContext.Parent;

            // Build and register class
            var param = new ParagraphClassParam(props);

            // Add table properties
            if (state.GetContext(out TableContext tableContext))
            {
                var tableCell = p.Ancestors <TableCell>().FirstOrDefault();
                if (tableCell != null)
                {
                    var cellState = tableContext.GetCell(tableCell);
                    param.TableProperties = cellState.ParagraphProperties;
                }
            }

            // Add numbering properties
            if (state.GetContext(out NumberingContext numberingContext) &&
                props != null)
            {
                // Add the numbering to the cls param
                param.NumberingId    = numberingContext.NumberingId;
                param.NumberingLevel = numberingContext.Level;

                // Register the run mark and add the class to the numbering numbering
                var numberingCls = registrator.RegisterRun(new RunClassParam
                {
                    InlineProperties = props.ParagraphMarkRunProperties,
                    ParagraphStyleId = param.StyleId,
                    NumberingId      = numberingContext.NumberingId,
                    NumberingLevel   = numberingContext.Level
                });
                parentVNode.AddClasses(_config.ContainerWithNumberingCssClassSuffix.Substring(1));
                numberingContext.NumberingNumber.AddClasses(numberingCls.Name);
            }

            // Add the class to the VNode containing the paragraph
            var pCls = registrator.RegisterParagraph(param);

            parentVNode.AddClasses(pCls.Name);

            // Set the paragraph css context
            state.SetContext(new ParagraphCssContext
            {
                CssClass = pCls
            });

            return(false);
        }
Beispiel #2
0
        public bool ProcessParagraph(IElementProcessingState state, Paragraph paragraph)
        {
            var pData = _numberingMapper.GetNumbering(paragraph);

            if (pData == null)
            {
                return(false);
            }

            var numberingContainer = BuildNumberingContainer();
            var numberingNumber    = BuildNumberingNumber(pData);

            numberingContainer.VLayers[0].Content.Add(numberingNumber);

            if (!state.GetContext(out ParagraphContext paragraphContext))
            {
                return(false);
            }
            paragraphContext.Parent.VLayers[0].Prefix.Add(numberingContainer);

            state.SetContext(new NumberingContext
            {
                NumberingId     = pData.NumberingId,
                Level           = pData.LevelIndex,
                NumberingNumber = numberingNumber
            });
            return(false);
        }
Beispiel #3
0
        private void TryAddTable(IElementProcessingState state, Table table)
        {
            if (!state.GetContext(out TableContext tc))
            {
                tc = new TableContext();
                tc.GridStateFactory = GridStateFactory;
                state.SetContext(tc);
            }
            var grid = tc.AddTable(table, state.Index);

            state.AddContent(grid.VNode);
            state.CurrentVNode = grid.VNode;
        }
Beispiel #4
0
        public bool ProcessElement(IElementProcessingState state, Paragraph paragraph)
        {
            if (!(paragraph.Parent is Body))
            {
                var container = new VNode("div");
                container.AddClasses("container");
                state.AddContent(container);
                state.CurrentVNode = container;
            }
            var vP = new VNode {
                Tag = _config.ParagraphTag
            };

            vP.Index  = state.Index;
            vP.Length = paragraph.InnerText.Length;
            vP.Text   = "​"; // zero width white psace
            vP.AddClasses(_config.ParagraphCls);
            state.SetContext(new ParagraphContext {
                Parent = state.CurrentVNode
            });
            state.AddContent(vP);
            state.CurrentVNode = vP;
            return(true);
        }