Skip to content

Commit

Permalink
Merge pull request #1433 from antony-liu/poi/v3.16-patch8
Browse files Browse the repository at this point in the history
Patches from poi
  • Loading branch information
tonyqus authored Oct 19, 2024
2 parents 7bc2131 + 031256d commit e6051b2
Show file tree
Hide file tree
Showing 32 changed files with 427 additions and 445 deletions.
11 changes: 6 additions & 5 deletions main/HSSF/UserModel/HSSFAnchor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations Under the License.
==================================================================== */

using NPOI.DDF;
using NPOI.SS.UserModel;
namespace NPOI.HSSF.UserModel
{

Expand All @@ -25,7 +26,7 @@ namespace NPOI.HSSF.UserModel
/// or within another containing shape.
/// @author Glen Stampoultzis (glens at apache.org)
/// </summary>
public abstract class HSSFAnchor
public abstract class HSSFAnchor: IChildAnchor
{
protected bool _isHorizontallyFlipped = false;
protected bool _isVerticallyFlipped = false;
Expand Down Expand Up @@ -69,7 +70,7 @@ public static HSSFAnchor CreateAnchorFromEscher(EscherContainerRecord container)
/// Gets or sets the DX1.
/// </summary>
/// <value>The DX1.</value>
public abstract int Dx1
public virtual int Dx1
{
get;
set;
Expand All @@ -78,7 +79,7 @@ public abstract int Dx1
/// Gets or sets the dy1.
/// </summary>
/// <value>The dy1.</value>
public abstract int Dy1
public virtual int Dy1
{
get;
set;
Expand All @@ -87,7 +88,7 @@ public abstract int Dy1
/// Gets or sets the dy2.
/// </summary>
/// <value>The dy2.</value>
public abstract int Dy2
public virtual int Dy2
{
get;
set;
Expand All @@ -96,7 +97,7 @@ public abstract int Dy2
/// Gets or sets the DX2.
/// </summary>
/// <value>The DX2.</value>
public abstract int Dx2
public virtual int Dx2
{
get;
set;
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/UserModel/HSSFComment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public IClientAnchor ClientAnchor
{
get
{
HSSFAnchor ha = base.Anchor;
HSSFAnchor ha = base.Anchor as HSSFAnchor;
if (ha is IClientAnchor)
{
return (IClientAnchor)ha;
Expand Down
6 changes: 3 additions & 3 deletions main/HSSF/UserModel/HSSFPatriarch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace NPOI.HSSF.UserModel
/// little other than act as a container for other shapes and Groups.
/// @author Glen Stampoultzis (glens at apache.org)
/// </summary>
public class HSSFPatriarch : HSSFShapeContainer, IDrawing
public class HSSFPatriarch : HSSFShapeContainer, IDrawing, IDrawing<HSSFShape>
{
//private static POILogger log = POILogFactory.GetLogger(typeof(HSSFPatriarch));
List<HSSFShape> _shapes = new List<HSSFShape>();
Expand Down Expand Up @@ -359,11 +359,11 @@ public IComment CreateCellComment(IClientAnchor anchor)
private void SetFlipFlags(HSSFShape shape)
{
EscherSpRecord sp = (EscherSpRecord)shape.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID);
if (shape.Anchor.IsHorizontallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsHorizontallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
}
if (shape.Anchor.IsVerticallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsVerticallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
}
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/UserModel/HSSFPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ public IClientAnchor ClientAnchor
{
get
{
HSSFAnchor a = Anchor;
HSSFAnchor a = Anchor as HSSFAnchor;
return (a is HSSFClientAnchor) ? (HSSFClientAnchor)a : null;
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/UserModel/HSSFPolygon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected override EscherContainerRecord CreateSpContainer()

opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));

EscherRecord anchor = Anchor.GetEscherAnchor();
EscherRecord anchor = (Anchor as HSSFAnchor).GetEscherAnchor();
clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
clientData.Options = ((short)0x0000);

Expand Down
67 changes: 54 additions & 13 deletions main/HSSF/UserModel/HSSFShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace NPOI.HSSF.UserModel
/// reverse them and draw shapes vertically or horizontally flipped!
/// </summary>
[Serializable]
public abstract class HSSFShape //: IShape
public abstract class HSSFShape : IShape
{
public const int LINEWIDTH_ONE_PT = 12700; // 12700 = 1pt
public const int LINEWIDTH_DEFAULT = 9525;
Expand Down Expand Up @@ -118,21 +118,34 @@ public virtual int ShapeId
cod.ObjectId = (short)(value % 1024);
}
}

public uint ID
{
get => (uint)ShapeId;
set => ShapeId = (int)value;
}

public string Name
{
get => ShapeName;
set => throw new NotImplementedException();
}

/// <summary>
/// Gets the parent shape.
/// </summary>
/// <value>The parent.</value>
public HSSFShape Parent
public IShape Parent
{
get { return this.parent; }
set { this.parent = value; }
set { this.parent = (HSSFShape)value; }
}

/// <summary>
/// Gets or sets the anchor that is used by this shape.
/// </summary>
/// <value>The anchor.</value>
public HSSFAnchor Anchor
public IChildAnchor Anchor
{
get { return anchor; }
set
Expand Down Expand Up @@ -179,22 +192,19 @@ public HSSFAnchor Anchor
_escherContainer.RemoveChildRecord(anch);
}
}
var anchor = value as HSSFAnchor;
if (-1 == recordId)
{
_escherContainer.AddChildRecord(value.GetEscherAnchor());
_escherContainer.AddChildRecord(anchor.GetEscherAnchor());
}
else
{
_escherContainer.AddChildBefore(value.GetEscherAnchor(), recordId);
_escherContainer.AddChildBefore(anchor.GetEscherAnchor(), recordId);
}
this.anchor = value;
this.anchor = anchor;
}
}

//public void SetLineStyleColor(int lineStyleColor)
//{
// this.lineStyleColor = lineStyleColor;
//}
/// <summary>
/// The color applied to the lines of this shape.
/// </summary>
Expand Down Expand Up @@ -264,7 +274,7 @@ public void SetFillColor(int red, int green, int blue)
/// Gets or sets with width of the line in EMUs. 12700 = 1 pt.
/// </summary>
/// <value>The width of the line.</value>
public int LineWidth
public double LineWidth
{
get
{
Expand All @@ -273,7 +283,7 @@ public int LineWidth
}
set
{
SetPropertyValue(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, value));
SetPropertyValue(new EscherSimpleProperty(EscherProperties.LINESTYLE__LINEWIDTH, (int)value));
}
}

Expand Down Expand Up @@ -435,6 +445,37 @@ public HSSFPatriarch Patriarch
}
}

/**
* @return the name of this shape
*/
public String ShapeName
{
get
{
EscherOptRecord eor = GetOptRecord();
if (eor == null)
{
return null;
}
EscherProperty ep = eor.Lookup(EscherProperties.GROUPSHAPE__SHAPENAME);
if (ep is EscherComplexProperty) {
return StringUtil.GetFromUnicodeLE(((EscherComplexProperty)ep).ComplexData);
}
return null;
}
}

public LineEndingCapType LineEndingCapType
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}

public CompoundLineType CompoundLineType
{
get { throw new NotImplementedException(); }
set { throw new NotImplementedException(); }
}
protected internal ObjRecord GetObjRecord()
{
return _objRecord;
Expand Down
3 changes: 2 additions & 1 deletion main/HSSF/UserModel/HSSFShapeContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,13 @@ limitations Under the License.
namespace NPOI.HSSF.UserModel
{
using System.Collections.Generic;
using NPOI.SS.UserModel;

/// <summary>
/// An interface that indicates whether a class can contain children.
/// @author Glen Stampoultzis (glens at apache.org)
/// </summary>
public interface HSSFShapeContainer : IEnumerable<HSSFShape>
public interface HSSFShapeContainer : IShapeContainer<HSSFShape>
{
/// <summary>
/// Gets Any children contained by this shape.
Expand Down
10 changes: 5 additions & 5 deletions main/HSSF/UserModel/HSSFShapeGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ protected override EscherContainerRecord CreateSpContainer()
opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.PROTECTION__LOCKAGAINSTGROUPING, 0x00040004));
opt.AddEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x00080000));

anchor = Anchor.GetEscherAnchor();
anchor = this.anchor.GetEscherAnchor();
clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
clientData.Options = ((short)0x0000);

Expand Down Expand Up @@ -197,11 +197,11 @@ public HSSFSimpleShape CreateShape(HSSFChildAnchor anchor)
shapes.Add(shape);
OnCreate(shape);
EscherSpRecord sp = (EscherSpRecord)shape.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID);
if (shape.Anchor.IsHorizontallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsHorizontallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
}
if (shape.Anchor.IsVerticallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsVerticallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
}
Expand Down Expand Up @@ -255,11 +255,11 @@ public HSSFPicture CreatePicture(HSSFChildAnchor anchor, int pictureIndex)
shapes.Add(shape);
OnCreate(shape);
EscherSpRecord sp = (EscherSpRecord)shape.GetEscherContainer().GetChildById(EscherSpRecord.RECORD_ID);
if (shape.Anchor.IsHorizontallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsHorizontallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPHORIZ);
}
if (shape.Anchor.IsVerticallyFlipped)
if ((shape.Anchor as HSSFAnchor).IsVerticallyFlipped)
{
sp.Flags = (sp.Flags | EscherSpRecord.FLAG_FLIPVERT);
}
Expand Down
4 changes: 2 additions & 2 deletions main/HSSF/UserModel/HSSFSimpleShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace NPOI.HSSF.UserModel
/// @author Glen Stampoultzis (glens at apache.org)
/// </summary>
[Serializable]
public class HSSFSimpleShape: HSSFShape
public class HSSFSimpleShape: HSSFShape, ISimpleShape
{
// The commented out ones haven't been tested yet or aren't supported
// by HSSFSimpleShape.
Expand Down Expand Up @@ -223,7 +223,7 @@ protected override EscherContainerRecord CreateSpContainer()

spContainer.AddChildRecord(sp);
spContainer.AddChildRecord(optRecord);
spContainer.AddChildRecord(this.Anchor.GetEscherAnchor());
spContainer.AddChildRecord(this.anchor.GetEscherAnchor());
spContainer.AddChildRecord(clientData);
spContainer.AddChildRecord(escherTextbox);
return spContainer;
Expand Down
2 changes: 1 addition & 1 deletion main/HSSF/UserModel/HSSFTextbox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ protected override EscherContainerRecord CreateSpContainer()
opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.FILL__NOFILLHITTEST, NO_FILLHITTEST_FALSE));
opt.SetEscherProperty(new EscherBoolProperty(EscherProperties.GROUPSHAPE__PRINT, 0x080000));

EscherRecord anchor = Anchor.GetEscherAnchor();
EscherRecord anchor = (Anchor as HSSFAnchor).GetEscherAnchor();
clientData.RecordId = (EscherClientDataRecord.RECORD_ID);
clientData.Options = ((short)0x0000);
escherTextbox.RecordId = (EscherTextboxRecord.RECORD_ID);
Expand Down
5 changes: 3 additions & 2 deletions main/SS/Formula/Atp/AnalysisToolPak.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,12 @@ public override FreeRefFunction FindFunction(String name)
{
// functions that are available in Excel 2007+ have a prefix _xlfn.
// if you save such a .xlsx workbook as .xls
if (name.StartsWith("_xlfn.")) name = name.Substring(6);
String prefix = "_xlfn.";
if (name.StartsWith(prefix)) name = name.Substring(prefix.Length);

string key = name.ToUpper();
if (_functionsByName.ContainsKey(key))
return (FreeRefFunction)_functionsByName[key];
return _functionsByName[key];

return null;
}
Expand Down
4 changes: 4 additions & 0 deletions main/SS/UserModel/Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,8 @@ public interface IDrawing
IClientAnchor CreateAnchor(int dx1, int dy1, int dx2, int dy2, int col1, int row1, int col2, int row2);
}

public interface IDrawing<T> : IShapeContainer<T> where T : class, IShape
{

}
}
48 changes: 48 additions & 0 deletions main/SS/UserModel/IChildAnchor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */


namespace NPOI.SS.UserModel
{
/// <summary>
/// Common interface for anchors.
///
/// An anchor is what specifics the position of a shape within a client object
/// or within another containing shape.
/// </summary>
public interface IChildAnchor
{
/// <summary>
/// get or set x coordinate of the left up corner
/// </summary>
int Dx1 { get; set; }

/// <summary>
/// get or set y coordinate of the left up corner
/// </summary>
int Dy1 { get; set; }

/// <summary>
/// get or set x coordinate of the right down corner
/// </summary>
int Dx2 { get; set; }
/// <summary>
/// get or set y coordinate of the right down corner
/// </summary>
int Dy2 { get; set; }
}
}
Loading

0 comments on commit e6051b2

Please sign in to comment.