diff --git a/Common/OfficeDrawing/Record.cs b/Common/OfficeDrawing/Record.cs index 742bf466..cbccaaa2 100644 --- a/Common/OfficeDrawing/Record.cs +++ b/Common/OfficeDrawing/Record.cs @@ -131,13 +131,20 @@ virtual public bool DoAutomaticVerifyReadToEnd public void VerifyReadToEnd() { - long streamPos = this.Reader.BaseStream.Position; - long streamLen = this.Reader.BaseStream.Length; + try + { + long streamPos = this.Reader.BaseStream.Position; + long streamLen = this.Reader.BaseStream.Length; - if (streamPos != streamLen) + if (streamPos != streamLen) + { + TraceLogger.DebugInternal("Record {3} didn't read to end: (stream position: {1} of {2})\n{0}", + this, streamPos, streamLen, this.GetIdentifier()); + } + } + catch (Exception) { - TraceLogger.DebugInternal("Record {3} didn't read to end: (stream position: {1} of {2})\n{0}", - this, streamPos, streamLen, this.GetIdentifier()); + } } @@ -295,6 +302,7 @@ public static Record ReadRecord(BinaryReader reader) TraceLogger.DebugInternal(e.InnerException.ToString()); throw e.InnerException; } + } else { diff --git a/Common/OfficeDrawing/RegularContainer.cs b/Common/OfficeDrawing/RegularContainer.cs index e9b394c9..ae45d034 100644 --- a/Common/OfficeDrawing/RegularContainer.cs +++ b/Common/OfficeDrawing/RegularContainer.cs @@ -25,7 +25,6 @@ public RegularContainer(BinaryReader _reader, uint size, uint typeCode, uint ver while (readSize < this.BodySize) { Record child = null; - try { child = Record.ReadRecord(this.Reader); diff --git a/Common/OpenXmlLib/OpenXmlPartContainer.cs b/Common/OpenXmlLib/OpenXmlPartContainer.cs index 9f0301f5..3671b629 100644 --- a/Common/OpenXmlLib/OpenXmlPartContainer.cs +++ b/Common/OpenXmlLib/OpenXmlPartContainer.cs @@ -68,7 +68,7 @@ public virtual string TargetDirectoryAbsolute path = resolvedPath.Substring(rootPath.Length + 1); } } - + path = path.Replace("/", "\\"); if (path == "ppt\\slides\\media") return "ppt\\media"; if (path == "ppt\\slideLayouts\\media") return "ppt\\media"; if (path == "ppt\\notesSlides\\media") return "ppt\\media"; @@ -211,7 +211,7 @@ protected virtual void WriteRelationshipPart(OpenXmlWriter writer) { //reform the URI path for Word //Word does not accept forward slahes in the path of a local file - writer.WriteAttributeString("Target", "file:///" + rel.TargetUri.AbsolutePath.Replace("/", "\\")); + writer.WriteAttributeString("Target", "file:///" + rel.TargetUri.AbsolutePath); } else { diff --git a/Common/StructuredStorage/Common/InternalBitConverter.cs b/Common/StructuredStorage/Common/InternalBitConverter.cs index 4f883799..01adab60 100644 --- a/Common/StructuredStorage/Common/InternalBitConverter.cs +++ b/Common/StructuredStorage/Common/InternalBitConverter.cs @@ -57,13 +57,8 @@ internal string ToString(byte[] value) Array.Reverse(value); } - var enc = new UnicodeEncoding(); - string result = enc.GetString(value); - if (result.Contains("\0")) - { - result = result.Remove(result.IndexOf("\0")); - } - return result; + string result = Encoding.Unicode.GetString(value); + return result.TrimEnd('\0'); } diff --git a/Ppt/PptFileFormat/FontEntityAtom.cs b/Ppt/PptFileFormat/FontEntityAtom.cs index 041ea4ff..aadc90de 100644 --- a/Ppt/PptFileFormat/FontEntityAtom.cs +++ b/Ppt/PptFileFormat/FontEntityAtom.cs @@ -17,7 +17,7 @@ public FontEntityAtom(BinaryReader _reader, uint size, uint typeCode, uint versi var facename = this.Reader.ReadBytes(64); this.TypeFace = Encoding.Unicode.GetString(facename); - this.TypeFace = this.TypeFace.Substring(0, this.TypeFace.IndexOf("\0")); + this.TypeFace = this.TypeFace.TrimEnd('\0'); //TODO: read other flags diff --git a/Ppt/PresentationMLMapping/ShapeTreeMapping.cs b/Ppt/PresentationMLMapping/ShapeTreeMapping.cs index ceb11f28..e455f451 100644 --- a/Ppt/PresentationMLMapping/ShapeTreeMapping.cs +++ b/Ppt/PresentationMLMapping/ShapeTreeMapping.cs @@ -1450,14 +1450,14 @@ public void Apply(ShapeContainer container, string footertext, string headertext { var bytes = this.so.OptionsByID[ShapeOptions.PropertyId.gtextUNICODE].opComplex; string sText = Encoding.Unicode.GetString(bytes); - if (sText.Contains("\0")) sText = sText.Substring(0, sText.IndexOf("\0")); + if (sText.Contains("\0")) sText = sText.TrimEnd('\0'); this._writer.WriteStartElement("a", "r", OpenXmlNamespaces.DrawingML); if (this.so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.gtextFont)) { bytes = this.so.OptionsByID[ShapeOptions.PropertyId.gtextFont].opComplex; string sFont = Encoding.Unicode.GetString(bytes); - if (sFont.Contains("\0")) sFont = sFont.Substring(0, sFont.IndexOf("\0")); + if (sFont.Contains("\0")) sFont = sFont.TrimEnd('\0'); this._writer.WriteStartElement("a", "rPr", OpenXmlNamespaces.DrawingML); if (this.so.OptionsByID.ContainsKey(ShapeOptions.PropertyId.gtextSize)) diff --git a/Ppt/PresentationMLMapping/TextMapping.cs b/Ppt/PresentationMLMapping/TextMapping.cs index 482cc299..98ad3925 100644 --- a/Ppt/PresentationMLMapping/TextMapping.cs +++ b/Ppt/PresentationMLMapping/TextMapping.cs @@ -721,7 +721,7 @@ private void writeP(ParagraphRun p, MasterTextPropRun tp, ShapeOptions so, TextR else if (!defaultStyle.PRuns[tp.indentLevel].BulletCharPresent) { this._writer.WriteStartElement("a", "buChar", OpenXmlNamespaces.DrawingML); - this._writer.WriteAttributeString("char", "•"); + this._writer.WriteAttributeString("char", "?"); this._writer.WriteEndElement(); //buChar } @@ -1186,7 +1186,7 @@ private void writeP(ParagraphRun p, MasterTextPropRun tp, ShapeOptions so, TextR else if (!bulletWritten && !p.BulletCharPresent) { this._writer.WriteStartElement("a", "buChar", OpenXmlNamespaces.DrawingML); - this._writer.WriteAttributeString("char", "•"); + this._writer.WriteAttributeString("char", "?"); this._writer.WriteEndElement(); //buChar } }