Skip to content

Commit

Permalink
fix #617
Browse files Browse the repository at this point in the history
properties serialization issue in drawing1.xml
  • Loading branch information
tonyqus committed Oct 8, 2021
1 parent d77b671 commit 649cf37
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 54 deletions.
36 changes: 23 additions & 13 deletions OpenXmlFormats/Drawing/Text.cs
Original file line number Diff line number Diff line change
Expand Up @@ -497,16 +497,22 @@ public static CT_TextBodyProperties Parse(XmlNode node, XmlNamespaceManager name
if (node == null)
return null;
CT_TextBodyProperties ctObj = new CT_TextBodyProperties();
ctObj.rot = XmlHelper.ReadInt(node.Attributes["rot"]);
ctObj.rotFieldSpecified = node.Attributes["rot"] != null;
ctObj.rotField = XmlHelper.ReadInt(node.Attributes["rot"]);
ctObj.spcFirstLastPara = XmlHelper.ReadBool(node.Attributes["spcFirstLastPara"]);

ctObj.vertOverflowFieldSpecified = node.Attributes["vertOverflow"] != null;
if (node.Attributes["vertOverflow"] != null)
ctObj.vertOverflow = (ST_TextVertOverflowType)Enum.Parse(typeof(ST_TextVertOverflowType), node.Attributes["vertOverflow"].Value);
ctObj.vertOverflowField = (ST_TextVertOverflowType)Enum.Parse(typeof(ST_TextVertOverflowType), node.Attributes["vertOverflow"].Value);
ctObj.horzOverflowFieldSpecified = node.Attributes["horzOverflow"] != null;
if (node.Attributes["horzOverflow"] != null)
ctObj.horzOverflow = (ST_TextHorzOverflowType)Enum.Parse(typeof(ST_TextHorzOverflowType), node.Attributes["horzOverflow"].Value);
ctObj.horzOverflowField = (ST_TextHorzOverflowType)Enum.Parse(typeof(ST_TextHorzOverflowType), node.Attributes["horzOverflow"].Value);
ctObj.vertFieldSpecified = node.Attributes["vert"] != null;
if (node.Attributes["vert"] != null)
ctObj.vert = (ST_TextVerticalType)Enum.Parse(typeof(ST_TextVerticalType), node.Attributes["vert"].Value);
ctObj.vertField = (ST_TextVerticalType)Enum.Parse(typeof(ST_TextVerticalType), node.Attributes["vert"].Value);
ctObj.wrapFieldSpecified = node.Attributes["wrap"] != null;
if (node.Attributes["wrap"] != null)
ctObj.wrap = (ST_TextWrappingType)Enum.Parse(typeof(ST_TextWrappingType), node.Attributes["wrap"].Value);
ctObj.wrapField = (ST_TextWrappingType)Enum.Parse(typeof(ST_TextWrappingType), node.Attributes["wrap"].Value);
ctObj.lIns = XmlHelper.ReadInt(node.Attributes["lIns"]);
ctObj.tIns = XmlHelper.ReadInt(node.Attributes["tIns"]);
ctObj.rIns = XmlHelper.ReadInt(node.Attributes["rIns"]);
Expand All @@ -515,8 +521,9 @@ public static CT_TextBodyProperties Parse(XmlNode node, XmlNamespaceManager name
ctObj.spcCol = XmlHelper.ReadInt(node.Attributes["spcCol"]);
ctObj.rtlCol = XmlHelper.ReadBool(node.Attributes["rtlCol"]);
ctObj.fromWordArt = XmlHelper.ReadBool(node.Attributes["fromWordArt"]);
ctObj.anchorFieldSpecified = node.Attributes["anchor"] != null;
if (node.Attributes["anchor"] != null)
ctObj.anchor = (ST_TextAnchoringType)Enum.Parse(typeof(ST_TextAnchoringType), node.Attributes["anchor"].Value);
ctObj.anchorField = (ST_TextAnchoringType)Enum.Parse(typeof(ST_TextAnchoringType), node.Attributes["anchor"].Value);
ctObj.anchorCtr = XmlHelper.ReadBool(node.Attributes["anchorCtr"]);
ctObj.forceAA = XmlHelper.ReadBool(node.Attributes["forceAA"]);
ctObj.upright = XmlHelper.ReadBool(node.Attributes["upright"]);
Expand Down Expand Up @@ -548,15 +555,17 @@ public static CT_TextBodyProperties Parse(XmlNode node, XmlNamespaceManager name
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<a:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "rot", this.rot,true);
if(this.rotFieldSpecified)
XmlHelper.WriteAttribute(sw, "rot", this.rotField,true);
if(spcFirstLastPara)
XmlHelper.WriteAttribute(sw, "spcFirstLastPara", this.spcFirstLastPara);
XmlHelper.WriteAttribute(sw, "vertOverflow", this.vertOverflow.ToString());
if(this.horzOverflow!= ST_TextHorzOverflowType.overflow)
XmlHelper.WriteAttribute(sw, "horzOverflow", this.horzOverflow.ToString());
if(this.vert!= ST_TextVerticalType.vert)
if(this.vertOverflowFieldSpecified)
XmlHelper.WriteAttribute(sw, "vertOverflow", this.vertOverflowField.ToString());
if(this.horzOverflowFieldSpecified)
XmlHelper.WriteAttribute(sw, "horzOverflow", this.horzOverflowField.ToString());
if(this.vertFieldSpecified)
XmlHelper.WriteAttribute(sw, "vert", this.vert.ToString());
if(this.wrap!= ST_TextWrappingType.none)
if(this.wrapFieldSpecified && this.wrap!= ST_TextWrappingType.none)
XmlHelper.WriteAttribute(sw, "wrap", this.wrap.ToString());
XmlHelper.WriteAttribute(sw, "lIns", this.lIns);
XmlHelper.WriteAttribute(sw, "tIns", this.tIns);
Expand All @@ -566,7 +575,8 @@ internal void Write(StreamWriter sw, string nodeName)
XmlHelper.WriteAttribute(sw, "spcCol", this.spcCol);
XmlHelper.WriteAttribute(sw, "rtlCol", this.rtlCol);
XmlHelper.WriteAttribute(sw, "fromWordArt", this.fromWordArt, false);
XmlHelper.WriteAttribute(sw, "anchor", this.anchor.ToString());
if(this.anchorFieldSpecified)
XmlHelper.WriteAttribute(sw, "anchor", this.anchorField.ToString());
XmlHelper.WriteAttribute(sw, "anchorCtr", this.anchorCtr, false);
XmlHelper.WriteAttribute(sw, "forceAA", this.forceAA, false);
if(upright)
Expand Down
35 changes: 21 additions & 14 deletions OpenXmlFormats/Drawing/TextCharacter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ internal void Write(StreamWriter sw, string nodeName)
XmlHelper.WriteAttribute(sw, "panose", this.panose);
XmlHelper.WriteAttribute(sw, "pitchFamily", this.pitchFamily);
if(charsetField!=(sbyte)1)
XmlHelper.WriteAttribute(sw, "charset", this.charset);
XmlHelper.WriteAttribute(sw, "charset", this.charset, true);
sw.Write("/>");
}

Expand Down Expand Up @@ -404,20 +404,25 @@ public static CT_TextCharacterProperties Parse(XmlNode node, XmlNamespaceManager
ctObj.lang = XmlHelper.ReadString(node.Attributes["lang"]);
ctObj.altLang = XmlHelper.ReadString(node.Attributes["altLang"]);
ctObj.sz = XmlHelper.ReadInt(node.Attributes["sz"]);
ctObj.bFieldSpecified = node.Attributes["b"] != null;
if (node.Attributes["b"] != null)
ctObj.b = XmlHelper.ReadBool(node.Attributes["b"]);
ctObj.bField = XmlHelper.ReadBool(node.Attributes["b"]);
ctObj.iFieldSpecified = node.Attributes["i"] != null;
if (node.Attributes["i"] != null)
ctObj.i = XmlHelper.ReadBool(node.Attributes["i"]);
ctObj.iField = XmlHelper.ReadBool(node.Attributes["i"]);
ctObj.uFieldSpecified = node.Attributes["u"]!=null;
if (node.Attributes["u"] != null)
ctObj.u = (ST_TextUnderlineType)Enum.Parse(typeof(ST_TextUnderlineType), node.Attributes["u"].Value);
ctObj.uField = (ST_TextUnderlineType)Enum.Parse(typeof(ST_TextUnderlineType), node.Attributes["u"].Value);
ctObj.strikeFieldSpecified = node.Attributes["strike"] != null;
if (node.Attributes["strike"] != null)
ctObj.strike = (ST_TextStrikeType)Enum.Parse(typeof(ST_TextStrikeType), node.Attributes["strike"].Value);
ctObj.strikeField = (ST_TextStrikeType)Enum.Parse(typeof(ST_TextStrikeType), node.Attributes["strike"].Value);
ctObj.kern = XmlHelper.ReadInt(node.Attributes["kern"]);
if (node.Attributes["cap"] != null)
ctObj.cap = (ST_TextCapsType)Enum.Parse(typeof(ST_TextCapsType), node.Attributes["cap"].Value);
ctObj.spc = XmlHelper.ReadInt(node.Attributes["spc"]);
ctObj.normalizeH = XmlHelper.ReadBool(node.Attributes["normalizeH"]);
ctObj.baseline = XmlHelper.ReadInt(node.Attributes["baseline"]);
ctObj.baselineFieldSpecified = node.Attributes["baseline"] != null;
ctObj.baselineField = XmlHelper.ReadInt(node.Attributes["baseline"]);
ctObj.noProof = XmlHelper.ReadBool(node.Attributes["noProof"]);
if (node.Attributes["dirty"]!=null)
ctObj.dirty = XmlHelper.ReadBool(node.Attributes["dirty"]);
Expand Down Expand Up @@ -483,19 +488,21 @@ internal void Write(StreamWriter sw, string nodeName)
XmlHelper.WriteAttribute(sw, "lang", this.lang);
XmlHelper.WriteAttribute(sw, "altLang", this.altLang);
XmlHelper.WriteAttribute(sw, "sz", this.sz);
XmlHelper.WriteAttribute(sw, "b", this.b, true);
if (this.i)
XmlHelper.WriteAttribute(sw, "i", this.i);
if(this.u!= ST_TextUnderlineType.none)
XmlHelper.WriteAttribute(sw, "u", this.u.ToString());
if(strike!= ST_TextStrikeType.noStrike)
XmlHelper.WriteAttribute(sw, "strike", this.strike.ToString());
if(this.bFieldSpecified)
XmlHelper.WriteAttribute(sw, "b", this.bField, true);
if (this.iFieldSpecified)
XmlHelper.WriteAttribute(sw, "i", this.iField,true);
if(this.uFieldSpecified&&this.uField!= ST_TextUnderlineType.none)
XmlHelper.WriteAttribute(sw, "u", this.uField.ToString());
if(this.strikeFieldSpecified&&strikeField!= ST_TextStrikeType.noStrike)
XmlHelper.WriteAttribute(sw, "strike", this.strikeField.ToString());
XmlHelper.WriteAttribute(sw, "kern", this.kern);
if(this.cap!= ST_TextCapsType.none)
XmlHelper.WriteAttribute(sw, "cap", this.cap.ToString());
XmlHelper.WriteAttribute(sw, "spc", this.spc);
XmlHelper.WriteAttribute(sw, "normalizeH", this.normalizeH, false);
XmlHelper.WriteAttribute(sw, "baseline", this.baseline);
if(this.baselineFieldSpecified)
XmlHelper.WriteAttribute(sw, "baseline", this.baseline,true);
XmlHelper.WriteAttribute(sw, "noProof", this.noProof, false);
if (!dirty)
XmlHelper.WriteAttribute(sw, "dirty", this.dirty);
Expand Down
49 changes: 22 additions & 27 deletions OpenXmlFormats/Drawing/TextParagraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static CT_TextSpacingPercent Parse(XmlNode node, XmlNamespaceManager name
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<a:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "val", this.val);
XmlHelper.WriteAttribute(sw, "val", this.val, true);
sw.Write("/>");
}

Expand Down Expand Up @@ -751,18 +751,23 @@ public static CT_TextParagraphProperties Parse(XmlNode node, XmlNamespaceManager
CT_TextParagraphProperties ctObj = new CT_TextParagraphProperties();
ctObj.marL = XmlHelper.ReadInt(node.Attributes["marL"]);
ctObj.marR = XmlHelper.ReadInt(node.Attributes["marR"]);
ctObj.lvl = XmlHelper.ReadInt(node.Attributes["lvl"]);
ctObj.lvlFieldSpecified = node.Attributes["lvl"] != null;
ctObj.lvlField = XmlHelper.ReadInt(node.Attributes["lvl"]);
ctObj.indent = XmlHelper.ReadInt(node.Attributes["indent"]);
ctObj.algnFieldSpecified = node.Attributes["algn"] != null;
if (node.Attributes["algn"] != null)
ctObj.algn = (ST_TextAlignType)Enum.Parse(typeof(ST_TextAlignType), node.Attributes["algn"].Value);
ctObj.algnField = (ST_TextAlignType)Enum.Parse(typeof(ST_TextAlignType), node.Attributes["algn"].Value);
else
ctObj.algn = ST_TextAlignType.l;
ctObj.algnField = ST_TextAlignType.l;
ctObj.defTabSz = XmlHelper.ReadInt(node.Attributes["defTabSz"]);
ctObj.rtl = XmlHelper.ReadBool(node.Attributes["rtl"]);
ctObj.rtlFieldSpecified = node.Attributes["rtl"] != null;
ctObj.rtlField = XmlHelper.ReadBool(node.Attributes["rtl"]);
ctObj.eaLnBrk = XmlHelper.ReadBool(node.Attributes["eaLnBrk"]);
ctObj.fontAlgnFieldSpecified = node.Attributes["fontAlgn"] != null;
if (node.Attributes["fontAlgn"] != null)
ctObj.fontAlgn = (ST_TextFontAlignType)Enum.Parse(typeof(ST_TextFontAlignType), node.Attributes["fontAlgn"].Value);
ctObj.latinLnBrk = XmlHelper.ReadBool(node.Attributes["latinLnBrk"]);
ctObj.fontAlgnField = (ST_TextFontAlignType)Enum.Parse(typeof(ST_TextFontAlignType), node.Attributes["fontAlgn"].Value);
ctObj.latinLnBrkFieldSpecified = node.Attributes["latinLnBrk"]!=null;
ctObj.latinLnBrkField = XmlHelper.ReadBool(node.Attributes["latinLnBrk"]);
ctObj.hangingPunct = XmlHelper.ReadBool(node.Attributes["hangingPunct"]);

foreach (XmlNode childNode in node.ChildNodes)
Expand Down Expand Up @@ -812,16 +817,19 @@ internal void Write(StreamWriter sw, string nodeName)
sw.Write(string.Format("<a:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "marL", this.marL);
XmlHelper.WriteAttribute(sw, "marR", this.marR);
XmlHelper.WriteAttribute(sw, "lvl", this.lvl, true);
if(this.lvlFieldSpecified)
XmlHelper.WriteAttribute(sw, "lvl", this.lvlField, true);
XmlHelper.WriteAttribute(sw, "indent", this.indent);
if(algn!= ST_TextAlignType.l)
XmlHelper.WriteAttribute(sw, "algn", this.algn.ToString());
if(this.algnFieldSpecified)
XmlHelper.WriteAttribute(sw, "algn", this.algnField.ToString());
XmlHelper.WriteAttribute(sw, "defTabSz", this.defTabSz);
XmlHelper.WriteAttribute(sw, "rtl", this.rtl, false);
if(this.rtlFieldSpecified)
XmlHelper.WriteAttribute(sw, "rtl", this.rtlField);
XmlHelper.WriteAttribute(sw, "eaLnBrk", this.eaLnBrk, false);
if(this.fontAlgn!= ST_TextFontAlignType.auto)
XmlHelper.WriteAttribute(sw, "fontAlgn", this.fontAlgn.ToString());
XmlHelper.WriteAttribute(sw, "latinLnBrk", this.latinLnBrk, false);
if(this.fontAlgnFieldSpecified&& this.fontAlgn!= ST_TextFontAlignType.auto)
XmlHelper.WriteAttribute(sw, "fontAlgn", this.fontAlgnField.ToString());
if(this.latinLnBrkFieldSpecified)
XmlHelper.WriteAttribute(sw, "latinLnBrk", this.latinLnBrk, true);
XmlHelper.WriteAttribute(sw, "hangingPunct", this.hangingPunct, false);
sw.Write(">");
if (this.lnSpc != null)
Expand Down Expand Up @@ -1155,19 +1163,6 @@ public int lvl
}
}

[XmlIgnore]
public bool lvlSpecified
{
get
{
return this.lvlFieldSpecified;
}
set
{
this.lvlFieldSpecified = value;
}
}

[XmlAttribute]
public int indent
{
Expand Down
3 changes: 3 additions & 0 deletions main/NPOI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,13 @@
<Compile Include="SS\Formula\Atp\ArgumentsEvaluator.cs" />
<Compile Include="SS\Formula\Atp\DateParser.cs" />
<Compile Include="SS\Formula\Atp\IfError.cs" />
<Compile Include="SS\Formula\Atp\IfNa.cs" />
<Compile Include="SS\Formula\Atp\Ifs.cs" />
<Compile Include="SS\Formula\Atp\Maxifs.cs" />
<Compile Include="SS\Formula\Atp\MinIfs.cs" />
<Compile Include="SS\Formula\Atp\NetworkdaysFunction.cs" />
<Compile Include="SS\Formula\Atp\Switch.cs" />
<Compile Include="SS\Formula\Atp\TextJoinFunction.cs" />
<Compile Include="SS\Formula\BaseFormulaEvaluator.cs" />
<Compile Include="SS\Formula\Eval\NotImplementedFunctionException.cs" />
<Compile Include="SS\Formula\Atp\WorkdayCalculator.cs" />
Expand Down

0 comments on commit 649cf37

Please sign in to comment.