Skip to content

Commit

Permalink
Merge pull request #894 from nissl-lab/get-rid-of-drawing-common
Browse files Browse the repository at this point in the history
Get rid of drawing common
  • Loading branch information
tonyqus committed Jul 31, 2022
2 parents aa76619 + 3faac26 commit 04681f1
Show file tree
Hide file tree
Showing 49 changed files with 240 additions and 210 deletions.
2 changes: 1 addition & 1 deletion OpenXmlFormats/NPOI.OpenXmlFormats.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '.net 4.5 release|AnyCPU'">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<OutputPath>..\solution\Lib\.net45\</OutputPath>
<DefineConstants>TRACE;HIDE_UNREACHABLE_CODE</DefineConstants>
<Optimize>true</Optimize>
Expand Down
2 changes: 1 addition & 1 deletion OpenXmlFormats/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
</dependentAssembly>
</assemblyBinding>
</runtime>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/></startup></configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/></startup></configuration>
2 changes: 1 addition & 1 deletion main/DDF/EscherMetafileBlip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ namespace NPOI.DDF
using System;
using System.IO;
using System.Text;
using System.Drawing;
using NPOI.Util;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using ICSharpCode.SharpZipLib.Zip.Compression;
using NPOI.HSSF.UserModel;
using SixLabors.ImageSharp;

/// <summary>
/// @author Daniel Noll
Expand Down
2 changes: 1 addition & 1 deletion main/DDF/EscherPictBlip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ namespace NPOI.DDF
using System;
using System.IO;
using System.Text;
using System.Drawing;
using NPOI.Util;
using ICSharpCode.SharpZipLib.Zip.Compression;
using ICSharpCode.SharpZipLib.Zip.Compression.Streams;
using SixLabors.ImageSharp;

/// <summary>
/// @author Daniel Noll
Expand Down
24 changes: 12 additions & 12 deletions main/HSSF/UserModel/EscherGraphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ namespace NPOI.HSSF.UserModel
using System;
using NPOI.HSSF.Util;
using NPOI.Util;

using System.Drawing;
using NPOI.SS.UserModel;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.Fonts;

/**
* Translates Graphics calls into escher calls. The translation Is lossy so
Expand Down Expand Up @@ -64,8 +65,8 @@ public class EscherGraphics : IDisposable
private HSSFWorkbook workbook;
private float verticalPointsPerPixel = 1.0f;
private float verticalPixelsPerPoint;
private Color foreground;
private Color background = Color.White;
private Rgb24 foreground;
private Rgb24 background = new Rgb24(255, 255, 255);
private Font font;
private static POILogger Logger = POILogFactory.GetLogger(typeof(EscherGraphics));

Expand All @@ -83,7 +84,7 @@ public EscherGraphics(HSSFShapeGroup escherGroup, HSSFWorkbook workbook, Color f
this.workbook = workbook;
this.verticalPointsPerPixel = verticalPointsPerPixel;
this.verticalPixelsPerPoint = 1 / verticalPointsPerPixel;
this.font = new Font("Arial", 10);
this.font = new Font(SystemFonts.Get("Arial"), 10);
this.foreground = forecolor;
// background = backcolor;
}
Expand Down Expand Up @@ -132,7 +133,6 @@ protected virtual void Dispose(bool disposing)
{
if (null != font)
{
font.Dispose();
font = null;
}
}
Expand Down Expand Up @@ -285,11 +285,11 @@ public void DrawString(String str, int x, int y)
{
if (string.IsNullOrEmpty(str))
return;

using (Font excelFont = new Font(font.Name.Equals("SansSerif") ? "Arial" : font.Name, (int)(font.Size / verticalPixelsPerPoint), font.Style))
// TODO-Fonts: Fallback for missing font
Font excelFont = new Font(SystemFonts.Get(font.Name.Equals("SansSerif") ? "Arial" : font.Name),
(int)(font.Size / verticalPixelsPerPoint), font.FontMetrics.Description.Style);
{
FontDetails d = StaticFontMetrics.GetFontDetails(excelFont);
int width = (int)((d.GetStringWidth(str) * 8) + 12);
int width = (int)((TextMeasurer.Measure(str, new TextOptions(excelFont)).Width * 8) + 12);
int height = (int)((font.Size / verticalPixelsPerPoint) + 6) * 2;
y -= Convert.ToInt32((font.Size / verticalPixelsPerPoint) + 2 * verticalPixelsPerPoint); // we want to Draw the shape from the top-left
HSSFTextbox textbox = escherGroup.CreateTextbox(new HSSFChildAnchor(x, y, x + width, y + height));
Expand All @@ -308,8 +308,8 @@ private HSSFFont MatchFont(Font font)
.FindColor((byte)foreground.R, (byte)foreground.G, (byte)foreground.B);
if (hssfColor == null)
hssfColor = workbook.GetCustomPalette().FindSimilarColor((byte)foreground.R, (byte)foreground.G, (byte)foreground.B);
bool bold = font.Bold;
bool italic = font.Italic;
bool bold = font.IsBold;
bool italic = font.IsItalic;
HSSFFont hssfFont = (HSSFFont)workbook.FindFont(bold ? (short)NPOI.SS.UserModel.FontBoldWeight.Bold : (short)NPOI.SS.UserModel.FontBoldWeight.Normal,
hssfColor.Indexed,
(short)(font.Size * 20),
Expand Down
8 changes: 4 additions & 4 deletions main/HSSF/UserModel/HSSFPicture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
namespace NPOI.HSSF.UserModel
{
using System;
using System.Drawing;
using System.Text;
using System.IO;
using NPOI.DDF;
Expand All @@ -27,6 +26,7 @@ namespace NPOI.HSSF.UserModel
using NPOI.HSSF.Model;
using NPOI.HSSF.Record;
using NPOI.SS.Util;
using SixLabors.ImageSharp;


/// <summary>
Expand Down Expand Up @@ -194,7 +194,7 @@ protected Size GetResolution(Image r)
{
//int hdpi = 96, vdpi = 96;
//double mm2inch = 25.4;
return new Size((int)r.HorizontalResolution, (int)r.VerticalResolution);
return new Size((int)r.Metadata.HorizontalResolution, (int)r.Metadata.VerticalResolution);
}

/// <summary>
Expand All @@ -210,9 +210,9 @@ public Size GetImageDimension()

using (MemoryStream ms = RecyclableMemory.GetStream(data))
{
using (Image img = Image.FromStream(ms))
using (Image img = Image.Load(ms))
{
return img.Size;
return img.Size();
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions main/HSSF/UserModel/HSSFSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace NPOI.HSSF.UserModel
using NPOI.Util;
using NPOI.SS.UserModel.Helpers;
using NPOI.HSSF.UserModel.helpers;
using SixLabors.Fonts;



Expand Down Expand Up @@ -2388,9 +2389,10 @@ public List<CellRangeAddress> MergedRegions
/// </summary>
/// <param name="font1">The font.</param>
/// <returns></returns>
public System.Drawing.Font HSSFFont2Font(HSSFFont font1)
public Font HSSFFont2Font(HSSFFont font1)
{
return new System.Drawing.Font(font1.FontName, (float)font1.FontHeightInPoints);
// TODO-Fonts: Fallback for missing font
return new Font(SystemFonts.Get(font1.FontName), (float)font1.FontHeightInPoints);
}

/// <summary>
Expand Down
3 changes: 2 additions & 1 deletion main/HSSF/UserModel/StaticFontMetrics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ namespace NPOI.HSSF.UserModel
using System;
using System.Collections;
using System.IO;
using System.Drawing;
using System.Configuration;
using NPOI.Util.Collections;

Expand Down Expand Up @@ -51,6 +50,7 @@ class StaticFontMetrics
* @param font the font to lookup.
* @return the fake font.
*/
/* TODO - SixLabors.Fonts:
public static FontDetails GetFontDetails(Font font)
{
// If we haven't alReady identified out font metrics file,
Expand Down Expand Up @@ -140,5 +140,6 @@ public static FontDetails GetFontDetails(Font font)
}
}
*/
}
}
7 changes: 4 additions & 3 deletions main/NPOI.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
<PackageReference Include="Enums.NET" Version="4.0.0" />
<PackageReference Include="MathNet.Numerics.Signed" Version="4.15.0" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" Version="2.2.0" />
<PackageReference Include="Portable.BouncyCastle" Version="1.8.9" />
<PackageReference Include="Portable.BouncyCastle" Version="1.9.0" />
<PackageReference Include="SharpZipLib" Version="1.3.3" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta18" />
<PackageReference Include="SixLabors.ImageSharp" Version="2.1.3" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.5.0" />
<PackageReference Include="System.Drawing.Common" Version="4.5.0" />
<PackageReference Include="System.Text.Encoding" Version="4.3.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="4.7.0" />
<PackageReference Include="System.Text.Encoding.CodePages" Version="5.0.0" />
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.0" PrivateAssets="All" />
</ItemGroup>

Expand Down
15 changes: 9 additions & 6 deletions main/NPOI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == '.net 4.5 release|AnyCPU'">
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<OutputPath>..\solution\Lib\.net45\</OutputPath>
<DefineConstants>TRACE;HIDE_UNREACHABLE_CODE</DefineConstants>
<DocumentationFile>..\solution\Lib\.net45\NPOI.XML</DocumentationFile>
Expand All @@ -88,9 +88,6 @@
<Reference Include="System.Data">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Data.dll</HintPath>
</Reference>
<Reference Include="System.Drawing">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.Drawing.dll</HintPath>
</Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml">
<HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\System.XML.dll</HintPath>
Expand Down Expand Up @@ -1401,14 +1398,20 @@
<Version>4.15.0</Version>
</PackageReference>
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream">
<Version>1.4.1</Version>
<Version>2.2.0</Version>
</PackageReference>
<PackageReference Include="Portable.BouncyCastle">
<Version>1.8.9</Version>
<Version>1.9.0</Version>
</PackageReference>
<PackageReference Include="SharpZipLib">
<Version>1.3.3</Version>
</PackageReference>
<PackageReference Include="SixLabors.Fonts">
<Version>1.0.0-beta18</Version>
</PackageReference>
<PackageReference Include="SixLabors.ImageSharp">
<Version>2.1.3</Version>
</PackageReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
7 changes: 7 additions & 0 deletions main/POIUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@
using System.Collections;
using System.Collections.Generic;
using System;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;

namespace NPOI.Util
{
public class POIUtils
Expand Down Expand Up @@ -93,6 +96,10 @@ public static void CopyNodeRecursively(Entry entry, DirectoryEntry target)
// System.err.println("CopyNodes called");
CopyNodes(source.Root, target.Root, excepts);
}

// TODO-ImageSharp: Not sure how to translate System.Drawing.Color.Empty - should
// we use null instead, or is System.Drawing.Color.Empty used in NPOI like RGB=0?
public static readonly Rgb24 Color_Empty = new Rgb24(0, 0, 0);
}

}
4 changes: 2 additions & 2 deletions main/SS/Format/CellFormat.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace NPOI.SS.Format
using NPOI.SS.UserModel;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Drawing;
using NPOI.Util;

/**
* Format a value according to the standard Excel behavior. This "standard" is
Expand Down Expand Up @@ -112,7 +112,7 @@ public GeneralCellFormat()
public override CellFormatResult Apply(Object value)
{
String text = (new CellGeneralFormatter()).Format(value);
return new CellFormatResult(true, text, Color.Empty);
return new CellFormatResult(true, text, POIUtils.Color_Empty);
}
}

Expand Down
11 changes: 6 additions & 5 deletions main/SS/Format/CellFormatPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ namespace NPOI.SS.Format

using NPOI.HSSF.Util;
using System.Collections.Generic;
using System.Drawing;
using System.Collections;
using System.Text.RegularExpressions;
using System.Text;
using SixLabors.ImageSharp;
using NPOI.Util;

/**
* Objects of this class represent a single part of a cell format expression.
Expand Down Expand Up @@ -84,7 +85,7 @@ static CellFormatPart()
if (name.Equals(name.ToUpper()))
{
byte[] rgb = hc.RGB;
Color c = Color.FromArgb(rgb[0], rgb[1], rgb[2]);
Color c = Color.FromRgb(rgb[0], rgb[1], rgb[2]);
if (!NAMED_COLORS.ContainsKey(name))
{
NAMED_COLORS.Add(name, c);
Expand Down Expand Up @@ -282,8 +283,8 @@ private static Color GetColor(Match m)
{
String cdesc = m.Groups[(COLOR_GROUP)].Value.ToUpper();
if (cdesc == null || cdesc.Length == 0)
return Color.Empty;
Color c = Color.Empty;
return POIUtils.Color_Empty;
Color c = POIUtils.Color_Empty;
if (NAMED_COLORS.ContainsKey(cdesc))
c = NAMED_COLORS[(cdesc)];
//if (c == null)
Expand Down Expand Up @@ -487,7 +488,7 @@ public CellFormatResult Apply(Object value)
else
{
text = format.SimpleFormat(value);
textColor = Color.Empty;
textColor = POIUtils.Color_Empty;
}
return new CellFormatResult(applies, text, textColor);
}
Expand Down
10 changes: 6 additions & 4 deletions main/SS/Format/CellFormatResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@
==================================================================== */
namespace NPOI.SS.Format
{
using NPOI.Util;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.PixelFormats;
using System;
using System.Drawing;



Expand Down Expand Up @@ -57,7 +59,7 @@ public String Text
* The color the format Sets, or <tt>null</tt> if the format Sets no color.
* This will always be <tt>null</tt> if {@link #applies} is <tt>false</tt>.
*/
public Color TextColor
public Rgb24 TextColor
{
get{return _textcolor;}
set{_textcolor=value;}
Expand All @@ -70,14 +72,14 @@ public Color TextColor
* @param text The value for {@link #text}.
* @param textColor The value for {@link #textColor}.
*/
public CellFormatResult(bool applies, String text, Color textColor)
public CellFormatResult(bool applies, String text, Rgb24 textColor)
{
if (text == null)
throw new ArgumentException("CellFormatResult text may not be null");

this.Applies = applies;
this.Text = text;
this.TextColor = (applies ? textColor : Color.Empty);
this.TextColor = (applies ? textColor : POIUtils.Color_Empty);
}
}
}
4 changes: 2 additions & 2 deletions main/SS/UserModel/ExtendedColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
namespace NPOI.SS.UserModel
{
using System;
using System.Drawing;
using System.Text;
using NPOI.HSSF.Util;
using NPOI.SS.UserModel;
using NPOI.Util;
using SixLabors.ImageSharp.PixelFormats;

/**
* Represents a XSSF-style color (based on either a
Expand All @@ -30,7 +30,7 @@ namespace NPOI.SS.UserModel
*/
public abstract class ExtendedColor : IColor
{
protected void SetColor(Color clr)
protected void SetColor(Rgb24 clr)
{
RGB = (new byte[] { clr.R, clr.G, clr.B });
}
Expand Down
1 change: 0 additions & 1 deletion main/SS/UserModel/IndexedColors.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
using NPOI.HSSF.Util;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
namespace NPOI.SS.UserModel
{
Expand Down
Loading

0 comments on commit 04681f1

Please sign in to comment.