Пример #1
0
        internal void Process(Run element, DocxNode node)
		{
			RunProperties properties = element.RunProperties;
			
			if (properties == null)
			{
				properties = new RunProperties();
			}
			
			//Order of assigning styles to run property is important. The order should not change.
            CheckFonts(node, properties);

            string color = node.ExtractStyleValue(DocxColor.color);
			
			if (!string.IsNullOrEmpty(color))
			{
				DocxColor.ApplyColor(color, properties);
			}

            CheckFontStyle(node, properties);

            ProcessBackGround(node, properties);

            ProcessVerticalAlign(node, properties);

			if (element.RunProperties == null && properties.HasChildren)
			{
				element.RunProperties = properties;
			}
		}
		internal void Process(TableCell cell, DocxTableProperties docxProperties, DocxNode node)
		{
			TableCellProperties cellProperties = new TableCellProperties();

            ProcessColSpan(node, cellProperties);
            ProcessWidth(node, cellProperties);
			
			if (HasRowSpan)
			{
				cellProperties.Append(new VerticalMerge() { Val = MergedCellValues.Restart });
			}
			
			//Processing border should be after colspan
            ProcessBorders(node, docxProperties, cellProperties);

            string backgroundColor = node.ExtractStyleValue(DocxColor.backGroundColor);
			
			if (!string.IsNullOrEmpty(backgroundColor))
			{
				DocxColor.ApplyBackGroundColor(backgroundColor, cellProperties);
			}

            ProcessVerticalAlignment(node, cellProperties);
			
			if (cellProperties.HasChildren)
			{
				cell.Append(cellProperties);
			}
		}
Пример #3
0
        private void ApplyStyle(DocxNode node)
        {
            string fontFamily = node.ExtractOwnStyleValue(DocxFontStyle.fontFamily);

            if (string.IsNullOrEmpty(fontFamily))
            {
                string face = node.ExtractAttributeValue("face");

                if (!string.IsNullOrEmpty(face))
                {
                    node.SetExtentedStyle(DocxFontStyle.fontFamily, face);
                }
            }

            string fontSize = node.ExtractOwnStyleValue(DocxFontStyle.fontSize);

            if (string.IsNullOrEmpty(fontSize))
            {
                SetFontSize(node);
            }

            string color = node.ExtractOwnStyleValue(DocxColor.color);

            if(string.IsNullOrEmpty(color))
            {
                color = node.ExtractAttributeValue("color");

                if(!string.IsNullOrEmpty(color))
                {
                    node.SetExtentedStyle(DocxColor.color, color);
                }
            }
        }
Пример #4
0
        private void ApplyStyle(DocxNode node)
        {
            string fontSizeValue = node.ExtractOwnStyleValue(DocxFontStyle.fontSize);
            string fontWeightValue = node.ExtractOwnStyleValue(DocxFontStyle.fontWeight);

            if (string.IsNullOrEmpty(fontSizeValue))
            {
                string headingFontSize = CalculateFontSize(GetHeaderNumber(node));
                string inheritedStyle = node.ExtractInheritedStyleValue(DocxFontStyle.fontSize);

                if (!string.IsNullOrEmpty(inheritedStyle))
                {
                    fontSizeValue = string.Concat(
                        context.Parser.CalculateRelativeChildFontSize(
                        inheritedStyle, headingFontSize).ToString("G29"), "px");
                }
                else
                {
                    fontSizeValue = headingFontSize;
                }
            }

            if (string.IsNullOrEmpty(fontWeightValue))
            {
                fontWeightValue = DocxFontStyle.bold;
            }

            node.SetExtentedStyle(DocxFontStyle.fontSize, fontSizeValue);
            node.SetExtentedStyle(DocxFontStyle.fontWeight, fontWeightValue);
        }
Пример #5
0
        private void ProcessBody(DocxNode node, ref Paragraph paragraph)
        {
            while (node != null)
            {
                if (node.IsText)
                {
                    if (!IsEmptyText(node.InnerHtml))
                    {
                        if (paragraph == null)
                        {
                            paragraph = body.AppendChild(new Paragraph());
                            OnParagraphCreated(node, paragraph);
                        }

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

                        RunCreated(node, run);
                    }
                }
                else
                {
                    node.ParagraphNode = node;
                    node.Parent = body;
                    ProcessChild(node, ref paragraph);
                }

                node = node.Next;
            }
        }
        private void ProcessTableBorder(DocxNode node, DocxTableProperties docxProperties, TableProperties tableProperties)
		{
            string borderStyle = node.ExtractAttributeValue(DocxBorder.borderName);
			
			if (borderStyle == "1")
			{
				TableBorders tableBorders = new TableBorders();
				DocxBorder.ApplyDefaultBorders(tableBorders);
				tableProperties.Append(tableBorders);
			}
			else
			{
                borderStyle = node.ExtractStyleValue(DocxBorder.borderName);
                string leftBorder = node.ExtractStyleValue(DocxBorder.leftBorderName);
                string topBorder = node.ExtractStyleValue(DocxBorder.topBorderName);
                string rightBorder = node.ExtractStyleValue(DocxBorder.rightBorderName);
                string bottomBorder = node.ExtractStyleValue(DocxBorder.bottomBorderName);
				
				TableBorders tableBorders = new TableBorders();
					
				DocxBorder.ApplyBorders(tableBorders, borderStyle, leftBorder, topBorder, 
					rightBorder, bottomBorder, docxProperties.HasDefaultBorder);
				
				if (tableBorders.HasChildren)
				{
					tableProperties.Append(tableBorders);
				}
			}
		}
Пример #7
0
 private Paragraph CreateParagraph(DocxNode node)
 {
     Paragraph paragraph = node.Parent.AppendChild(new Paragraph());
     OnParagraphCreated(node.ParagraphNode, paragraph);
    
     return paragraph;
 }
Пример #8
0
 private Paragraph CreateParagraph(DocxNode node, OpenXmlElement parent)
 {
     Paragraph para = parent.AppendChild(new Paragraph());
     OnParagraphCreated(node, para);
     OnOLParagraphCreated(this, new ParagraphEventArgs(para));
     return para;
 }
Пример #9
0
        private void SetFontSize(DocxNode node)
        {
            string size = node.ExtractAttributeValue("size");

            if (string.IsNullOrEmpty(size))
            {
                return;
            }

            Match match = Regex.Match(size, "^\\d+");
            Int32 sizeValue;
            Int32 fontSizeValue = 0;

            if (!match.Success || !Int32.TryParse(match.Value, out sizeValue))
            {
                return;
            }

            if (!fontSizes.TryGetValue(sizeValue, out fontSizeValue))
            {
                if (sizeValue > 7)
                {
                    fontSizeValue = 48;
                }
            }

            if (fontSizeValue != 0)
            {
                node.SetExtentedStyle(DocxFontStyle.fontSize, string.Concat(fontSizeValue.ToString(), "px"));
            }
        }
Пример #10
0
        private void ProcessWidth(DocxNode node, TableProperties tableProperties)
		{
            string width = node.ExtractAttributeValue(DocxUnits.width);
            string styleWidth = node.ExtractStyleValue(DocxUnits.width);
			
			if (!string.IsNullOrEmpty(styleWidth))
			{
				width = styleWidth;
			}
			
			if (!string.IsNullOrEmpty(width))
			{
				decimal value;
				TableWidthUnitValues unit;
				
				if (DocxUnits.TableUnitsFromStyle(width, out value, out unit))
				{
					TableWidth tableWidth = new TableWidth() {
						Width = value.ToString(),
						Type = unit
					};
					tableProperties.Append(tableWidth);
				}
			}
		}
Пример #11
0
        private void ProcessNonLinkText(DocxNode node, ref Paragraph paragraph)
        {
            foreach (DocxNode child in node.Children)
            {
                if (child.IsText)
                {
                    if (paragraph == null)
                    {
                        paragraph = node.Parent.AppendChild(new Paragraph());
                        OnParagraphCreated(node.ParagraphNode, paragraph);
                    }

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

                        RunCreated(node, run);
                    }
                }
                else
                {
                    child.ParagraphNode = node.ParagraphNode;
                    child.Parent = node.Parent;
                    node.CopyExtentedStyles(child);
                    ProcessChild(child, ref paragraph);
                }
            }
        }
Пример #12
0
 private void CreateParagraph(DocxNode node, ref Paragraph paragraph)
 {
     if (paragraph == null)
     {
         paragraph = node.Parent.AppendChild(new Paragraph());
         OnParagraphCreated(node.ParagraphNode, paragraph);
     }
 }
Пример #13
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            ProcessTextChild(node);
        }
Пример #14
0
        private void SetStyle(DocxNode node)
        {
            string value = node.ExtractStyleValue(DocxFontStyle.italic);

            if (string.IsNullOrEmpty(value))
            {
                node.SetExtentedStyle(DocxFontStyle.fontStyle, DocxFontStyle.italic);
            }
        }
Пример #15
0
        private void SetThStyleToRun(DocxNode run)
        {
            string value = run.ExtractStyleValue(DocxFontStyle.fontWeight);

            if (string.IsNullOrEmpty(value))
            {
                run.SetExtentedStyle(DocxFontStyle.fontWeight, DocxFontStyle.bold);
            }
        }
Пример #16
0
        private void ProcessVerticalAlign(DocxNode node, RunProperties properties)
        {
            string verticalAlign = node.ExtractStyleValue(DocxAlignment.verticalAlign);

            if(!string.IsNullOrEmpty(verticalAlign))
            {
                DocxAlignment.ApplyVerticalTextAlign(verticalAlign, properties);
            }
        }
Пример #17
0
        protected void ProcessTextElement(DocxNode node)
        {
            ITextElement element = context.ConvertTextElement(node);

            if (element != null)
            {
                element.Process(node);
            }
        }
Пример #18
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            node.Parent.AppendChild(new Run(new Break()));
        }
Пример #19
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || IsHidden(node))
            {
                return;
            }

            ProcessElement(node, ref paragraph);
        }
Пример #20
0
        protected void OnParagraphCreated(DocxNode node, Paragraph para)
        {
            DocxParagraphStyle style = new DocxParagraphStyle();
            style.Process(para, node);

            if (ParagraphCreated != null)
            {
                ParagraphCreated(this, new ParagraphEventArgs(para));
            }
        }
Пример #21
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            node.SetExtentedStyle(DocxAlignment.textAlign, DocxAlignment.center);
            ProcessTextChild(node);
        }
Пример #22
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            node.SetExtentedStyle(DocxFontStyle.fontWeight, DocxFontStyle.bold);
            ProcessTextChild(node);
        }
Пример #23
0
        void ITextElement.Process(DocxNode node)
        {
            if (IsHidden(node))
            {
                return;
            }

            node.SetExtentedStyle(DocxFontStyle.textDecoration, DocxFontStyle.underLine);
            ProcessTextChild(node);
        }
Пример #24
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }

            node.SetExtentedStyle(DocxAlignment.verticalAlign, DocxAlignment.sub);

            ProcessElement(node, ref paragraph);
        }
Пример #25
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }
            
            node.SetExtentedStyle(DocxFontStyle.textDecoration, DocxFontStyle.underLine);

            ProcessElement(node, ref paragraph);
        }
Пример #26
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }

            SetStyle(node);

            ProcessElement(node, ref paragraph);
        }
Пример #27
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || IsHidden(node))
            {
                return;
            }

            node.SetExtentedStyle(DocxFontStyle.fontWeight, DocxFontStyle.bold);

            ProcessElement(node, ref paragraph);
        }
Пример #28
0
        internal override void Process(DocxNode node, ref Paragraph paragraph)
        {
            if (node.IsNull() || node.Parent == null || IsHidden(node))
            {
                return;
            }

            paragraph = null;
            Paragraph headerParagraph = null;

            ProcessBlockElement(node, ref headerParagraph);
        }
        private void ProcessColSpan(DocxNode node, TableCellProperties cellProperties)
		{
			Int32 value;

            if (Int32.TryParse(node.ExtractAttributeValue(colspan), out value))
			{
				if (value > 1)
				{
					cellProperties.Append(new GridSpan() { Val = value });
				}
			}
		}
Пример #30
0
        private void SetDDProperties(DocxNode node)
        {
            DocxMargin margin = new DocxMargin(node);

            string leftMargin = margin.GetLeftMargin();

            if (string.IsNullOrEmpty(leftMargin))
            {
                //Default left margin of dd element
                margin.SetLeftMargin(defaultDDLeftMargin);
            }
        }
Пример #31
0
        protected void RunCreated(DocxNode node, Run run)
        {
            DocxRunStyle style = new DocxRunStyle();

            style.Process(run, node);
        }
Пример #32
0
        private void ProcessTd(int colIndex, DocxNode td, TableRow row, DocxTableProperties tableProperties)
        {
            TableCell cell       = new TableCell();
            bool      hasRowSpan = false;

            string rowSpan = td.ExtractAttributeValue(DocxTableProperties.rowSpan);
            Int32  rowSpanValue;

            if (Int32.TryParse(rowSpan, out rowSpanValue))
            {
                tableProperties.RowSpanInfo[colIndex] = rowSpanValue - 1;
                hasRowSpan = true;
            }

            DocxTableCellStyle style = new DocxTableCellStyle();

            style.HasRowSpan = hasRowSpan;
            style.Process(cell, tableProperties, td);

            if (td.HasChildren)
            {
                Paragraph para = null;

                //If the cell is th header, apply font-weight:bold to the text
                if (tableProperties.IsCellHeader)
                {
                    SetThStyleToRun(td);
                }

                foreach (DocxNode child in td.Children)
                {
                    td.CopyExtentedStyles(child);

                    if (child.IsText)
                    {
                        if (!IsEmptyText(child.InnerHtml))
                        {
                            if (para == null)
                            {
                                para = cell.AppendChild(new Paragraph());
                                OnParagraphCreated(DocxTableCellStyle.GetHtmlNodeForTableCellContent(td), para);
                            }

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

                            RunCreated(child, run);
                        }
                    }
                    else
                    {
                        child.ParagraphNode = DocxTableCellStyle.GetHtmlNodeForTableCellContent(td);
                        child.Parent        = cell;
                        td.CopyExtentedStyles(child);
                        ProcessChild(child, ref para);
                    }
                }
            }

            //The last element of the table cell must be a paragraph.
            var lastElement = cell.Elements().LastOrDefault();

            if (lastElement == null || !(lastElement is Paragraph))
            {
                cell.AppendChild(new Paragraph());
            }

            row.Append(cell);
        }
Пример #33
0
 internal override bool CanConvert(DocxNode node)
 {
     return(string.Compare(node.Tag, DocxTableProperties.tableName, StringComparison.InvariantCultureIgnoreCase) == 0);
 }
Пример #34
0
 bool ITextElement.CanConvert(DocxNode node)
 {
     return(CanConvert(node));
 }
Пример #35
0
 internal override bool CanConvert(DocxNode node)
 {
     return(IsTextTag(node.Tag));
 }
Пример #36
0
 internal DocxMargin(DocxNode node)
 {
     this.node = node;
 }
Пример #37
0
 internal abstract void Process(DocxNode node, ref Paragraph paragraph);
Пример #38
0
 bool ITextElement.CanConvert(DocxNode node)
 {
     return(string.Equals(node.Tag, "object", StringComparison.OrdinalIgnoreCase));
 }
Пример #39
0
 internal override bool CanConvert(DocxNode node)
 {
     return(string.Equals(node.Tag, "img", StringComparison.OrdinalIgnoreCase));
 }
Пример #40
0
 internal override bool CanConvert(DocxNode node)
 {
     return(isValid.IsMatch(node.Tag));
 }
Пример #41
0
        internal void Process(TableProperties tableProperties, DocxTableProperties docxProperties, DocxNode node)
        {
            ProcessWidth(node, tableProperties);

            ProcessTableBorder(node, docxProperties, tableProperties);
            ProcessTableCellMargin(docxProperties, tableProperties);
        }
Пример #42
0
 internal abstract bool CanConvert(DocxNode node);
Пример #43
0
 internal override bool CanConvert(DocxNode node)
 {
     return(string.Compare(node.Tag, "header", StringComparison.InvariantCultureIgnoreCase) == 0);
 }
Пример #44
0
 internal abstract void Process(DocxNode node, ref Paragraph paragraph, Dictionary <string, object> properties);