internal virtual FlexiTableRowBlock CreateFlexiTableRowBlock(FlexiTableType type,
                                                                     BlockProcessor childBlockProcessor,
                                                                     List <ColumnDefinition> columnDefinitions,
                                                                     int numColumns,
                                                                     int rowIndex,
                                                                     Row row,
                                                                     bool isHeaderRow)
        {
            var flexiTableRowBlock = new FlexiTableRowBlock(isHeaderRow);

            for (int columnIndex = 0; columnIndex < numColumns;)
            {
                Cell cell = row[columnIndex];
                columnIndex = cell.EndColumnIndex + 1;

                if (cell.StartRowIndex < rowIndex) // Cell with rowspan that's already been created
                {
                    continue;
                }

                // Create cell block
                FlexiTableCellBlock flexiTableCellBlock = CreateFlexiTableCellBlock(type, childBlockProcessor, columnDefinitions, cell);

                // Add cell block to row block
                flexiTableRowBlock.Add(flexiTableCellBlock);
            }

            // Could be empty if all cells have rowspan and have already been created. We return it anyway since it could be relevant.
            // For example, if we remove this row and some cells in the row have rowspan 3 while others only have rowspan 2, the cells
            // with rowspan 3 will erroneously span into an extra row.
            return(flexiTableRowBlock);
        }
Example #2
0
        private void WriteCellBlock(HtmlRenderer htmlRenderer,
                                    string blockName,
                                    string elementName,
                                    string className,
                                    FlexiTableCellBlock labelFlexiTableCellBlock,
                                    FlexiTableCellBlock flexiTableCellBlock)
        {
            // Colspan, rowspan and alignment
            htmlRenderer.
            Write('<').
            Write(elementName).
            Write(" class=\"").
            WriteElementClass(blockName, className);
            if (flexiTableCellBlock.ContentAlignment != ContentAlignment.None) // Avoid array access if unecessary
            {
                htmlRenderer.WriteElementKeyValueModifierClass(blockName, className, "align", _alignments[(int)flexiTableCellBlock.ContentAlignment]);
            }
            htmlRenderer.
            Write('"').
            Write(flexiTableCellBlock.Colspan > 1, " colspan=\"", flexiTableCellBlock.Colspan.ToString(), "\"").     // TODO avoid allocation. Use a map or String.Create
            Write(flexiTableCellBlock.Rowspan > 1, " rowspan=\"", flexiTableCellBlock.Rowspan.ToString(), "\"").     // TODO avoid allocation. Use a map or String.Create
            WriteLine(">");

            // Label
            bool renderLabel = labelFlexiTableCellBlock != null;

            if (renderLabel)
            {
                htmlRenderer.
                WriteElementLine("div", blockName, "label", labelFlexiTableCellBlock, labelFlexiTableCellBlock.Count == 1).     // Don't need a <p> wrapper if there is only 1 leaf block
                WriteStartTagLine("div", blockName, "content");
            }

            // Content
            htmlRenderer.
            WriteChildren(flexiTableCellBlock, flexiTableCellBlock.Count == 1).     // Don't need a <p> wrapper if there is only 1 leaf block
            EnsureLine().
            WriteEndTagLine(renderLabel, "div").
            WriteEndTagLine(elementName);
        }
        internal virtual FlexiTableCellBlock CreateFlexiTableCellBlock(FlexiTableType type,
                                                                       BlockProcessor childBlockProcessor,
                                                                       List <ColumnDefinition> columnDefinitions,
                                                                       Cell cell)
        {
            // Colspan and rowspan
            int startColumnIndex = cell.StartColumnIndex;
            int colspan          = cell.EndColumnIndex - startColumnIndex + 1;
            int rowspan          = cell.EndRowIndex - cell.StartRowIndex + 1;

            if (type != FlexiTableType.Unresponsive && (rowspan > 1 || colspan > 1))
            {
                throw new OptionsException(nameof(IFlexiTableBlockOptions.Type), Strings.OptionsException_FlexiTableBlockFactory_TypeInvalidForTablesWithCellsThatHaveRowspanOrColspan);
            }

            // Create
            var flexiTableCellBlock = new FlexiTableCellBlock(colspan,
                                                              rowspan,
                                                              columnDefinitions?[startColumnIndex].ContentAlignment ?? ContentAlignment.None);

            // Process cell block contents
            childBlockProcessor.LineIndex = cell.LineIndex;
            childBlockProcessor.Open(flexiTableCellBlock);
            ref StringLineGroup stringLineGroup = ref cell.Lines;