Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into FixRoundDown
Browse files Browse the repository at this point in the history
  • Loading branch information
Bykiev committed Apr 23, 2024
2 parents b78e992 + 4eb5d0e commit 76d1af8
Show file tree
Hide file tree
Showing 19 changed files with 197 additions and 130 deletions.
8 changes: 4 additions & 4 deletions OpenXmlFormats/Drawing/WordprocessingDrawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,10 @@ public static CT_Inline Parse(XmlNode node, XmlNamespaceManager namespaceManager
if (node == null)
return null;
CT_Inline ctObj = new CT_Inline();
ctObj.distT = XmlHelper.ReadUInt(node.Attributes["wp:distT"]);
ctObj.distB = XmlHelper.ReadUInt(node.Attributes["wp:distB"]);
ctObj.distL = XmlHelper.ReadUInt(node.Attributes["wp:distL"]);
ctObj.distR = XmlHelper.ReadUInt(node.Attributes["wp:distR"]);
ctObj.distT = XmlHelper.ReadUInt(node.Attributes["distT"]);
ctObj.distB = XmlHelper.ReadUInt(node.Attributes["distB"]);
ctObj.distL = XmlHelper.ReadUInt(node.Attributes["distL"]);
ctObj.distR = XmlHelper.ReadUInt(node.Attributes["distR"]);
foreach (XmlNode childNode in node.ChildNodes)
{
if (childNode.LocalName == "extent")
Expand Down
13 changes: 7 additions & 6 deletions OpenXmlFormats/Wordprocessing/Font.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,16 +488,17 @@ public static CT_Fonts Parse(XmlNode node, XmlNamespaceManager namespaceManager)
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
if (this.hint != ST_Hint.@default || this.hintFieldSpecified)
XmlHelper.WriteAttribute(sw, "w:hint", this.hint.ToString());
XmlHelper.WriteAttribute(sw, "w:ascii", this.ascii);
XmlHelper.WriteAttribute(sw, "w:hAnsi", this.hAnsi);
if(this.eastAsiaTheme !=null)
XmlHelper.WriteAttribute(sw, "w:eastAsiaTheme", this.eastAsiaTheme.ToString());
XmlHelper.WriteAttribute(sw, "w:eastAsia", this.eastAsia);
XmlHelper.WriteAttribute(sw, "w:hAnsi", this.hAnsi);
XmlHelper.WriteAttribute(sw, "w:cs", this.cs);
if (this.asciiTheme != null)
if(this.hint != ST_Hint.@default || this.hintFieldSpecified)
XmlHelper.WriteAttribute(sw, "w:hint", this.hint.ToString());

if(this.asciiTheme != null)
XmlHelper.WriteAttribute(sw, "w:asciiTheme", this.asciiTheme.ToString());
if (this.eastAsiaTheme !=null)
XmlHelper.WriteAttribute(sw, "w:eastAsiaTheme", this.eastAsiaTheme.ToString());
if (this.hAnsiTheme != ST_Theme.majorEastAsia)
XmlHelper.WriteAttribute(sw, "w:hAnsiTheme", this.hAnsiTheme.ToString());
if (this.cstheme != null)
Expand Down
25 changes: 4 additions & 21 deletions OpenXmlFormats/Wordprocessing/Paragraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,8 +1035,6 @@ public override bool IsEmpty
{
sw.Write(string.Format("<w:{0}", nodeName));
sw.Write(">");
if (this.sectPr != null)
this.sectPr.Write(sw, "sectPr");
if (this.pPrChange != null)
this.pPrChange.Write(sw, "pPrChange");
if (this.pStyle != null)
Expand Down Expand Up @@ -1105,6 +1103,8 @@ public override bool IsEmpty
this.outlineLvl.Write(sw, "outlineLvl");
if (this.rPr != null)
this.rPr.Write(sw, "rPr");
if(this.sectPr != null)
this.sectPr.Write(sw, "sectPr");
if (this.textDirection != null)
this.textDirection.Write(sw, "textDirection");
if (this.textAlignment != null)
Expand Down Expand Up @@ -2637,27 +2637,9 @@ public class CT_SectPr

public CT_SectPr()
{
//this.sectPrChangeField = new CT_SectPrChange();
//this.printerSettingsField = new CT_Rel();
this.docGridField = new CT_DocGrid();
this.docGrid.type = ST_DocGrid.lines;
this.docGrid.typeSpecified = true;
this.docGrid.linePitch = "312";

//this.rtlGutterField = new CT_OnOff();
//this.bidiField = new CT_OnOff();
//this.textDirectionField = new CT_TextDirection();
//this.titlePgField = new CT_OnOff();
//this.noEndnoteField = new CT_OnOff();
//this.vAlignField = new CT_VerticalJc();
//this.formProtField = new CT_OnOff();
this.colsField = new CT_Columns();
this.cols.space = 425;
this.cols.spaceSpecified = true;
//this.pgNumTypeField = new CT_PageNumber();
//this.lnNumTypeField = new CT_LineNumber();
//this.pgBordersField = new CT_PageBorders();
//this.paperSrcField = new CT_PaperSource();
this.pgMarField = new CT_PageMar();
this.pgMar.top = 1440;
this.pgMar.right = 1800;
Expand Down Expand Up @@ -7647,7 +7629,8 @@ internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "w:type", this.type.ToString());
XmlHelper.WriteAttribute(sw, "w:clear", this.clear.ToString());
if(this.clear!= ST_BrClear.none)
XmlHelper.WriteAttribute(sw, "w:clear", this.clear.ToString());
sw.Write(">");
sw.WriteEndW(nodeName);
}
Expand Down
2 changes: 1 addition & 1 deletion OpenXmlFormats/Wordprocessing/Styles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2304,11 +2304,11 @@ internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "w:val", this.val.ToString());
XmlHelper.WriteAttribute(sw, "w:color", this.color);
if (this.sz != null)
XmlHelper.WriteAttribute(sw, "w:sz", (ulong)this.sz, true);
if (this.space != null)
XmlHelper.WriteAttribute(sw, "w:space", (ulong)this.space, true);
XmlHelper.WriteAttribute(sw, "w:color", this.color);
if(this.themeColor!= ST_ThemeColor.none)
XmlHelper.WriteAttribute(sw, "w:themeColor", this.themeColor.ToString());
XmlHelper.WriteAttribute(sw, "w:themeTint", this.themeTint);
Expand Down
6 changes: 3 additions & 3 deletions OpenXmlFormats/Wordprocessing/Table.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1912,9 +1912,9 @@ public static CT_Height Parse(XmlNode node, XmlNamespaceManager namespaceManager
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "w:val", this.val);
if(this.hRule!= ST_HeightRule.auto)
XmlHelper.WriteAttribute(sw, "w:hRule", this.hRule.ToString());
XmlHelper.WriteAttribute(sw, "w:val", this.val);
sw.Write("/>");
}

Expand Down Expand Up @@ -5703,8 +5703,8 @@ internal void Write(StreamWriter sw, string nodeName)
sw.Write(string.Format("<w:{0}", nodeName));
XmlHelper.WriteAttribute(sw, "w:rsidR", this.rsidR);
XmlHelper.WriteAttribute(sw, "w:rsidRPr", this.rsidRPr);
//XmlHelper.WriteAttribute(sw, "w14:paraId", this.paraIdField);
//XmlHelper.WriteAttribute(sw, "w14:textId", this.textIdField);
XmlHelper.WriteAttribute(sw, "w14:paraId", this.paraIdField);
XmlHelper.WriteAttribute(sw, "w14:textId", this.textIdField);
XmlHelper.WriteAttribute(sw, "w:rsidDel", this.rsidDel);
XmlHelper.WriteAttribute(sw, "w:rsidTr", this.rsidTr);
sw.Write(">");
Expand Down
7 changes: 5 additions & 2 deletions OpenXmlFormats/Wordprocessing/wml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2255,8 +2255,11 @@ public static CT_Text Parse(XmlNode node, XmlNamespaceManager namespaceManager)
internal void Write(StreamWriter sw, string nodeName)
{
sw.Write(string.Format("<w:{0}", nodeName));
this.space = "preserve";
XmlHelper.WriteAttribute(sw, "xml:space", this.space);
if(valueField!=null&&(valueField.StartsWith(" ")||valueField.EndsWith(" ")||valueField.StartsWith("\t")||valueField.EndsWith("\t")))
{
this.space = "preserve";
XmlHelper.WriteAttribute(sw, "xml:space", this.space);
}
sw.Write(">");
if (this.valueField != null)
{
Expand Down
4 changes: 2 additions & 2 deletions main/NPOI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
<PackageReference Include="MathNet.Numerics.Signed" Version="5.0.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="3.0.0" />
<PackageReference Include="BouncyCastle.Cryptography" Version="2.3.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="SharpZipLib" Version="1.4.2" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.1" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.7" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.8" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' != 'net472' ">
Expand Down
57 changes: 37 additions & 20 deletions main/POIFS/FileSystem/Ole10Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ namespace NPOI.POIFS.FileSystem
*
* @author Rainer Schwarze
*/

public class Ole10Native
{
public static String OLE10_NATIVE = "\x0001Ole10Native";
protected static String ISO1 = "ISO-8859-1";

// (the fields as they appear in the raw record:)
private int totalSize; // 4 bytes, total size of record not including this field

private short flags1 = 2; // 2 bytes, unknown, mostly [02 00]
private String label; // ASCIIZ, stored in this field without the terminating zero
private String fileName; // ASCIIZ, stored in this field without the terminating zero
Expand All @@ -46,8 +48,10 @@ public class Ole10Native

/**
* the field encoding mode - merely a try-and-error guess ...
**/
private enum EncodingMode {
**/

private enum EncodingMode
{
/**
* the data is stored in parsed format - including label, command, etc.
*/
Expand All @@ -61,8 +65,9 @@ private enum EncodingMode {
*/
compact
}

private EncodingMode mode;

/// <summary>
/// Creates an instance of this class from an embedded OLE Object. The OLE Object is expected
/// to include a stream &quot;{01}Ole10Native&quot; which Contains the actual
Expand Down Expand Up @@ -91,15 +96,17 @@ public static Ole10Native CreateFromEmbeddedOleObject(DirectoryNode directory)

return new Ole10Native(data, 0);
}

/**
* Creates an instance and fills the fields based on ... the fields
*/

public Ole10Native(String label, String filename, String command, byte[] data)
{
Label=(label);
FileName=(filename);
Command=(command);
DataBuffer=(data);
Label = (label);
FileName = (filename);
Command = (command);
DataBuffer = (data);
mode = EncodingMode.parsed;
}

Expand All @@ -110,6 +117,7 @@ public Ole10Native(String label, String filename, String command, byte[] data)
* @param offset The start offset of the record in the buffer
* @throws Ole10NativeException on invalid or unexcepted data format
*/

public Ole10Native(byte[] data, int offset)
{
int ofs = offset; // current offset, Initialized to start
Expand Down Expand Up @@ -172,25 +180,31 @@ public Ole10Native(byte[] data, int offset)
}

break;

case EncodingMode.compact:
flags1 = LittleEndian.GetShort(data, ofs);
ofs += LittleEndianConsts.SHORT_SIZE;
dataSize = totalSize - LittleEndianConsts.SHORT_SIZE;
break;

case EncodingMode.unparsed:
dataSize = totalSize;
break;
}

if ((long)dataSize + (long)ofs > (long)data.Length)
{ //cast to avoid overflow
throw new Ole10NativeException("Invalid Ole10Native: declared data length > available data");
}
dataBuffer = new byte[dataSize];
Array.Copy(data, ofs, dataBuffer, 0, dataSize);
ofs += dataSize;

}

/*
* Helper - determine length of zero terminated string (ASCIIZ).
*/

private static int GetStringLength(byte[] data, int ofs)
{
int len = 0;
Expand All @@ -208,6 +222,7 @@ private static int GetStringLength(byte[] data, int ofs)
*
* @return the totalSize
*/

public int TotalSize
{
get
Expand All @@ -221,6 +236,7 @@ public int TotalSize
*
* @return the flags1
*/

public short Flags1
{
get
Expand All @@ -236,6 +252,7 @@ public short Flags1
*
* @return the label
*/

public String Label
{
get
Expand All @@ -254,6 +271,7 @@ public String Label
*
* @return the fileName
*/

public String FileName
{
get
Expand All @@ -271,6 +289,7 @@ public String FileName
*
* @return the flags2
*/

public short Flags2
{
get
Expand All @@ -288,6 +307,7 @@ public short Flags2
*
* @return the unknown1
*/

public short Unknown1
{
get
Expand All @@ -306,6 +326,7 @@ public short Unknown1
*
* @return the command
*/

public String Command
{
get
Expand All @@ -322,10 +343,10 @@ public String Command
*
* @return the dataSize
*/

public int DataSize
{
get{return dataBuffer.Length;}

get { return dataBuffer.Length; }
}

/**
Expand All @@ -336,17 +357,19 @@ public int DataSize
*
* @return the dataBuffer
*/

public byte[] DataBuffer
{
get { return dataBuffer; }
set { dataBuffer =(byte[])value.Clone(); }
set { dataBuffer = (byte[])value.Clone(); }
}

/**
* Returns the flags3 - currently unknown.
*
* @return the flags3
*/

public short Flags3
{
get
Expand All @@ -365,12 +388,13 @@ public short Flags3
* around, but non atom classes will just request the bytes from their
* children, then chuck on their header and return)
*/

public void WriteOut(Stream out1)
{
byte[] intbuf = new byte[LittleEndianConsts.INT_SIZE];
byte[] shortbuf = new byte[LittleEndianConsts.SHORT_SIZE];
byte[] zerobuf = { 0, 0, 0, 0 };

LittleEndianOutputStream leosOut = new LittleEndianOutputStream(out1);

switch (mode)
Expand Down Expand Up @@ -405,20 +429,13 @@ public void WriteOut(Stream out1)
leosOut.WriteShort(Flags1);
out1.Write(DataBuffer, 0, DataBuffer.Length);
break;

default:
case EncodingMode.unparsed:
leosOut.WriteInt(DataSize);
out1.Write(DataBuffer, 0, DataBuffer.Length);
break;
}

}

}

}





Loading

0 comments on commit 76d1af8

Please sign in to comment.