From 24adb8beaec5cdac66a6a5fb2f865876ef1509e0 Mon Sep 17 00:00:00 2001 From: ROM-Knowledgeware Date: Wed, 8 Aug 2018 09:12:14 +0300 Subject: [PATCH] Bugfix: correctly support color being set to "auto" Exception was thrown in some cases --- Xceed.Words.NET/Src/Formatting.cs | 4 ++-- Xceed.Words.NET/Src/Table.cs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Xceed.Words.NET/Src/Formatting.cs b/Xceed.Words.NET/Src/Formatting.cs index c9c0b452..94630d60 100644 --- a/Xceed.Words.NET/Src/Formatting.cs +++ b/Xceed.Words.NET/Src/Formatting.cs @@ -784,7 +784,7 @@ public static Formatting Parse( XElement rPr, Formatting formatting = null ) var color = option.GetAttribute( XName.Get( "color", DocX.w.NamespaceName ) ); if( !string.IsNullOrEmpty( color ) ) { - formatting.UnderlineColor = System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", color ) ); + formatting.UnderlineColor = ( color == "auto") ? Color.Black : System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", color ) ); } } catch( Exception ) @@ -806,7 +806,7 @@ public static Formatting Parse( XElement rPr, Formatting formatting = null ) var fill = option.GetAttribute( XName.Get( "fill", DocX.w.NamespaceName ) ); if( !string.IsNullOrEmpty( fill ) ) { - formatting.Shading = System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", fill ) ); + formatting.Shading = ( fill == "auto") ? Color.White : System.Drawing.ColorTranslator.FromHtml( string.Format( "#{0}", fill ) ); } break; case "rStyle": diff --git a/Xceed.Words.NET/Src/Table.cs b/Xceed.Words.NET/Src/Table.cs index bd6ffccb..02abf8f2 100644 --- a/Xceed.Words.NET/Src/Table.cs +++ b/Xceed.Words.NET/Src/Table.cs @@ -2194,7 +2194,7 @@ public Border GetBorder( TableBorderType borderType ) // The color attribute is used for the border color var color = tblBorderType.Attribute( XName.Get( "color", DocX.w.NamespaceName ) ); - if( color == null ) + if( color == null || color.Value == "auto" ) { // uses default border style } @@ -2931,7 +2931,7 @@ public Color Shading XAttribute fill = shd?.Attribute( XName.Get( "fill", DocX.w.NamespaceName ) ); // If fill is null, this cell contains no Color information. - if( fill == null ) + if( fill == null || fill.Value == "auto" ) return Color.White; return ColorTranslator.FromHtml( string.Format( "#{0}", fill.Value ) ); @@ -3512,7 +3512,7 @@ public Color FillColor XElement tcPr = Xml.Element( XName.Get( "tcPr", DocX.w.NamespaceName ) ); XElement shd = tcPr?.Element( XName.Get( "shd", DocX.w.NamespaceName ) ); XAttribute fill = shd?.Attribute( XName.Get( "fill", DocX.w.NamespaceName ) ); - if( fill == null ) + if( fill == null || fill.Value == "auto" ) return Color.Empty; int argb = Int32.Parse( fill.Value.Replace( "#", "" ), NumberStyles.HexNumber ); @@ -3916,7 +3916,7 @@ public Border GetBorder( TableCellBorderType borderType ) // The color attribute is used for the border color XAttribute color = tcBorderType.Attribute( XName.Get( "color", DocX.w.NamespaceName ) ); - if( color == null ) + if( color == null || color.Value == "auto" ) { // uses default border style }