Ejemplo n.º 1
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                numberFormat = GetNumberFormat(node);

                InitNumberDefinitions(numberFormat);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, numberFormat);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private NumberFormatValues GetNumberFormat(DocxNode node)
        {
            NumberFormatValues numberFormat = NumberFormatValues.Decimal;

            string type = node.ExtractAttributeValue("type");

            if (!string.IsNullOrEmpty(type))
            {
                switch (type)
                {
                case "1":
                    numberFormat = NumberFormatValues.Decimal;
                    break;

                case "a":
                    numberFormat = NumberFormatValues.LowerLetter;
                    break;

                case "A":
                    numberFormat = NumberFormatValues.UpperLetter;
                    break;

                case "i":
                    numberFormat = NumberFormatValues.LowerRoman;
                    break;

                case "I":
                    numberFormat = NumberFormatValues.UpperRoman;
                    break;
                }
            }

            return(numberFormat);
        }
Ejemplo n.º 3
0
        private void InitNumberDefinitions(NumberFormatValues numberFormat)
        {
            AbstractNum abstractNum = new AbstractNum()
            {
                AbstractNumberId = numberId
            };

            Level level = new Level()
            {
                LevelIndex = 0
            };
            StartNumberingValue startNumberingValue = new StartNumberingValue()
            {
                Val = 1
            };
            NumberingFormat numberingFormat = new NumberingFormat()
            {
                Val = numberFormat
            };
            LevelText levelText = new LevelText()
            {
                Val = "%1."
            };
            LevelJustification levelJustification = new LevelJustification()
            {
                Val = LevelJustificationValues.Left
            };

            PreviousParagraphProperties previousParagraphProperties = new PreviousParagraphProperties();
            Indentation indentation = new Indentation()
            {
                Left    = "720",
                Hanging = "360"
            };

            previousParagraphProperties.Append(indentation);

            level.Append(startNumberingValue);
            level.Append(numberingFormat);
            level.Append(levelText);
            level.Append(levelJustification);
            level.Append(previousParagraphProperties);

            abstractNum.Append(level);

            NumberingInstance numberingInstance = new NumberingInstance()
            {
                NumberID = numberId
            };
            AbstractNumId abstractNumId = new AbstractNumId()
            {
                Val = numberId
            };

            numberingInstance.Append(abstractNumId);

            context.SaveNumberingDefinition(numberId, abstractNum, numberingInstance);
        }
Ejemplo n.º 4
0
        private void SetListProperties(NumberFormatValues numberFormat, ParagraphProperties paragraphProperties)
        {
            ParagraphStyleId paragraphStyleId = new ParagraphStyleId() { Val = "ListParagraph" };

            NumberingProperties numberingProperties = new NumberingProperties();
            NumberingLevelReference numberingLevelReference = new NumberingLevelReference() { Val = 0 };
            NumberingId numberingId = new NumberingId() { Val = ((Int32)numberFormat) + 1 };

            numberingProperties.Append(numberingLevelReference);
            numberingProperties.Append(numberingId);

            paragraphProperties.Append(paragraphStyleId);
            paragraphProperties.Append(numberingProperties);
        }
Ejemplo n.º 5
0
        public static IStringifier Create(NumberFormatValues value)
        {
            switch (value)
            {
            case NumberFormatValues.LowerRoman: return(new LowerRomanStringifier());

            case NumberFormatValues.UpperRoman: return(new UpperRomanStringifier());

            case NumberFormatValues.LowerLetter: return(new LowerLetterStringifier());

            case NumberFormatValues.UpperLetter: return(new UpperLetterStringifier());

            case NumberFormatValues.Ordinal: return(new OrdinalNumberStringifier());

            case NumberFormatValues.OrdinalText: return(new OrdinalTextStringifier());

            case NumberFormatValues.DecimalZero: return(new DecimalZeroStringifier());

            default: return(new DecimalStringifier());
            }
        }
Ejemplo n.º 6
0
        private void DefineLevel(NumberFormatValues numberFormat, int levelIndex)
        {
            Level level = new Level()
            {
                LevelIndex = gLevelId
            };
            StartNumberingValue startNumberingValue = new StartNumberingValue()
            {
                Val = 1
            };
            NumberingFormat numberingFormat = new NumberingFormat()
            {
                Val = numberFormat
            };
            LevelText levelText = new LevelText()
            {
                Val = $"%{gLevelId + 1})"
            };                                                                   //Later we need a provison to configure this text.
            LevelJustification levelJustification = new LevelJustification()
            {
                Val = LevelJustificationValues.Left
            };

            PreviousParagraphProperties previousParagraphProperties = new PreviousParagraphProperties();
            Indentation indentation = new Indentation()
            {
                Left    = (indent * (levelIndex + 1)).ToString(),
                Hanging = "360"
            };

            previousParagraphProperties.Append(indentation);

            level.Append(startNumberingValue);
            level.Append(numberingFormat);
            level.Append(levelText);
            level.Append(levelJustification);
            level.Append(previousParagraphProperties);

            abstractNum.Append(level);
        }
Ejemplo n.º 7
0
        private void InitNumberDefinitions(NumberFormatValues numberFormat)
        {
            if (!context.HasNumberingDefinition(numberFormat))
            {
                //Enum values starting from zero. We need non zero values here
                Int32 numberId = ((Int32)numberFormat) + 1;

                AbstractNum abstractNum = new AbstractNum() { AbstractNumberId = numberId };

                Level level = new Level() { LevelIndex = 0 };
                StartNumberingValue startNumberingValue = new StartNumberingValue() { Val = 1 };
                NumberingFormat numberingFormat = new NumberingFormat() { Val = numberFormat };
                LevelText levelText = new LevelText() { Val = "%1." };
                LevelJustification levelJustification = new LevelJustification() { Val = LevelJustificationValues.Left };

                PreviousParagraphProperties previousParagraphProperties = new PreviousParagraphProperties();
                Indentation indentation = new Indentation()
                {
                    Start = "720",
                    Hanging = "360"
                };

                previousParagraphProperties.Append(indentation);

                level.Append(startNumberingValue);
                level.Append(numberingFormat);
                level.Append(levelText);
                level.Append(levelJustification);
                level.Append(previousParagraphProperties);

                abstractNum.Append(level);

                NumberingInstance numberingInstance = new NumberingInstance() { NumberID = numberId };
                AbstractNumId abstractNumId = new AbstractNumId() { Val = numberId };

                numberingInstance.Append(abstractNumId);

                context.SaveNumberingDefinition(numberFormat, abstractNum, numberingInstance);
            }
        }
Ejemplo n.º 8
0
        public void SaveNumberingDefinition(NumberFormatValues format, AbstractNum abstractNum, NumberingInstance numberingInstance)
        {
            if (abstractNumList == null)
            {
                abstractNumList = new Dictionary <NumberFormatValues, AbstractNum>();
            }

            if (numberingInstanceList == null)
            {
                numberingInstanceList = new Dictionary <NumberFormatValues, NumberingInstance>();
            }

            if (!abstractNumList.ContainsKey(format))
            {
                abstractNumList.Add(format, abstractNum);
            }

            if (!numberingInstanceList.ContainsKey(format))
            {
                numberingInstanceList.Add(format, numberingInstance);
            }
        }
Ejemplo n.º 9
0
        internal override void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;
            int levelIndex = properties.ContainsKey(levelIndexName) ? Convert.ToInt32(properties[levelIndexName]) : 0;

            if (abstractNum == null)
            {
                InitNumberDefinitions();
            }

            if (node.HasChildren)
            {
                NumberFormatValues numberFormat = GetNumberFormat(node);

                int levelId = gLevelId = gNextLevelId++;

                DefineLevel(numberFormat, levelIndex);

                var newProperties = properties.ToDictionary(x => x.Key, x => x.Value);
                newProperties[levelIndexName] = levelIndex + 1;

                foreach (DocxNode child in node.Children)
                {
                    gLevelIndex = levelIndex;
                    gLevelId    = levelId;

                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, newProperties);
                    }
                }
            }
        }
Ejemplo n.º 10
0
        private void SetListProperties(NumberFormatValues numberFormat, ParagraphProperties paragraphProperties)
        {
            ParagraphStyleId paragraphStyleId = new ParagraphStyleId()
            {
                Val = "ListParagraph"
            };

            NumberingProperties     numberingProperties     = new NumberingProperties();
            NumberingLevelReference numberingLevelReference = new NumberingLevelReference()
            {
                Val = 0
            };
            NumberingId numberingId = new NumberingId()
            {
                Val = ((Int32)numberFormat) + 1
            };

            numberingProperties.Append(numberingLevelReference);
            numberingProperties.Append(numberingId);

            paragraphProperties.Append(paragraphStyleId);
            paragraphProperties.Append(numberingProperties);
        }
        internal static Level CreateLevel(NumberFormatValues nfv, int startIndent, int hangingIndent)
        {
            _levelIndex++;

            return(new Level(new StartNumberingValue {
                Val = 1
            },

                             new NumberingFormat {
                Val = nfv
            },
                             new LevelText {
                Val = $"%{_levelIndex + 1}."
            },
                             new PreviousParagraphProperties(new Indentation
            {
                Start = startIndent.ToString(CultureInfo.InvariantCulture),
                Hanging = hangingIndent.ToString(CultureInfo.InvariantCulture)
            }))
            {
                LevelIndex = _levelIndex
            });
        }
Ejemplo n.º 12
0
        private void ProcessLi(DocxNode li, OpenXmlElement parent, NumberFormatValues numberFormat)
        {
            Paragraph paragraph = null;

            isParagraphCreated = false;

            ParagraphCreated = OnOLParagraphCreated;

            foreach (DocxNode child in li.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        if (paragraph == null)
                        {
                            paragraph = CreateParagraph(li, parent);
                        }

                        Run run = paragraph.AppendChild(new Run(new Text()
                        {
                            Text  = ClearHtml(child.InnerHtml),
                            Space = SpaceProcessingModeValues.Preserve
                        }));

                        RunCreated(li, run);
                    }
                }
                else
                {
                    child.ParagraphNode = li;
                    child.Parent        = parent;
                    li.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
        private static Level CreateLevelElement(int levelIndex, NumberFormatValues numberFormat, string levelText, int indentationLeft, int indentationHanging, string bulletFontName)
        {
            if (levelIndex < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(levelIndex), levelIndex, "The prameter is must be greater than equal 0.");
            }
            if (levelText == null)
            {
                throw new ArgumentNullException(nameof(levelText), "Cannot use null for this parameter.");
            }
            if (indentationLeft < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(indentationLeft), indentationLeft, "The prameter is must be greater than equal 0.");
            }
            if (indentationHanging < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(indentationHanging), indentationHanging, "The prameter is must be greater than equal 0.");
            }
            if (string.IsNullOrWhiteSpace(bulletFontName))
            {
                throw new ArgumentOutOfRangeException(nameof(bulletFontName), bulletFontName, "The bullet font name is not valid.");
            }

            return(new Level(
                       new StartNumberingValue()
            {
                Val = 1,      // The start number of the list.
            },
                       new NumberingFormat()
            {
                Val = numberFormat,      // The bullet style.
            },
                       new LevelText()
            {
                Val = levelText,      // The bullet character (text).
            },
                       new LevelJustification()
            {
                Val = LevelJustificationValues.Left,
            },
                       new PreviousParagraphProperties(
                           new Indentation()
            {
                Left = indentationLeft.ToString(),
                Hanging = indentationHanging.ToString(),
            }
                           ),
                       new NumberingSymbolRunProperties(
                           // The font for the bullet.
                           new RunFonts()
            {
                Ascii = bulletFontName,
                HighAnsi = bulletFontName,
                ComplexScript = bulletFontName,
                Hint = FontTypeHintValues.Default,
            }
                           )
                       )
            {
                LevelIndex = levelIndex,
            });
        }
Ejemplo n.º 14
0
 public bool HasNumberingDefinition(NumberFormatValues format)
 {
     return(abstractNumList != null && numberingInstanceList != null && abstractNumList.ContainsKey(format) && numberingInstanceList.ContainsKey(format));
 }
Ejemplo n.º 15
0
        public void SaveNumberingDefinition(NumberFormatValues format, AbstractNum abstractNum, NumberingInstance numberingInstance)
        {
            if (abstractNumList == null)
            {
                abstractNumList = new Dictionary<NumberFormatValues, AbstractNum>();
            }

            if (numberingInstanceList == null)
            {
                numberingInstanceList = new Dictionary<NumberFormatValues, NumberingInstance>();
            }

            if (!abstractNumList.ContainsKey(format))
            {
                abstractNumList.Add(format, abstractNum);
            }

            if (!numberingInstanceList.ContainsKey(format))
            {
                numberingInstanceList.Add(format, numberingInstance);
            }
        }
Ejemplo n.º 16
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || !CanConvert(node) || IsHidden(node))
            {
                return;
            }

            paragraph = null;

            if (node.HasChildren)
            {
                numberFormat = GetNumberFormat(node);

                InitNumberDefinitions(numberFormat);

                foreach (DocxNode child in node.Children)
                {
                    if (string.Compare(child.Tag, liName, StringComparison.InvariantCultureIgnoreCase) == 0)
                    {
                        node.CopyExtentedStyles(child);
                        ProcessLi(child, node.Parent, numberFormat);
                    }
                }
            }
        }
Ejemplo n.º 17
0
        private NumberFormatValues GetNumberFormat(DocxNode node)
        {
            NumberFormatValues numberFormat = NumberFormatValues.Decimal;

            string type = node.ExtractAttributeValue("type");

            if (!string.IsNullOrEmpty(type))
            {
                switch (type)
                {
                    case "1":
                        numberFormat = NumberFormatValues.Decimal;
                        break;

                    case "a":
                        numberFormat = NumberFormatValues.LowerLetter;
                        break;

                    case "A":
                        numberFormat = NumberFormatValues.UpperLetter;
                        break;

                    case "i":
                        numberFormat = NumberFormatValues.LowerRoman;
                        break;

                    case "I":
                        numberFormat = NumberFormatValues.UpperRoman;
                        break;
                }
            }

            return numberFormat;
        }
Ejemplo n.º 18
0
        private void ProcessLi(DocxNode li, OpenXmlElement parent, NumberFormatValues numberFormat)
        {
            Paragraph paragraph = null;
            isParagraphCreated = false;

            ParagraphCreated = OnOLParagraphCreated;

            foreach (DocxNode child in li.Children)
            {
                if (child.IsText)
                {
                    if (!IsEmptyText(child.InnerHtml))
                    {
                        if (paragraph == null)
                        {
                            paragraph = CreateParagraph(li, parent);
                        }

                        Run run = paragraph.AppendChild(new Run(new Text()
                        {
                            Text = ClearHtml(child.InnerHtml),
                            Space = SpaceProcessingModeValues.Preserve
                        }));

                        RunCreated(li, run);
                    }
                }
                else
                {
                    child.ParagraphNode = li;
                    child.Parent = parent;
                    li.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Ejemplo n.º 19
0
 public bool HasNumberingDefinition(NumberFormatValues format)
 {
     return abstractNumList != null && numberingInstanceList != null && abstractNumList.ContainsKey(format) && numberingInstanceList.ContainsKey(format);
 }