diff --git a/ClosedXML/ClosedXML/ClosedXML.sln b/ClosedXML/ClosedXML/ClosedXML.sln index d57b0b6..1a34dee 100644 --- a/ClosedXML/ClosedXML/ClosedXML.sln +++ b/ClosedXML/ClosedXML/ClosedXML.sln @@ -6,6 +6,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5C94E22C-85AA-48FD-B082-CF929FFC6C31}" ProjectSection(SolutionItems) = preProject ClosedXML.vsmdi = ClosedXML.vsmdi + DocumentFormat.OpenXml.dll = DocumentFormat.OpenXml.dll Local.testsettings = Local.testsettings TraceAndTestImpact.testsettings = TraceAndTestImpact.testsettings EndProjectSection diff --git a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj index 3f56652..550502f 100644 --- a/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj +++ b/ClosedXML/ClosedXML/ClosedXML/ClosedXML.csproj @@ -112,7 +112,7 @@ - D:\Downloads\DocumentFormat.OpenXml.dll + ..\DocumentFormat.OpenXml.dll diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs index a23430e..383a9fa 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Columns/XLColumn.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Drawing; namespace ClosedXML.Excel { @@ -287,6 +288,7 @@ public IXLColumn AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth) { + var fontCache = new Dictionary(); Double colMaxWidth = minWidth; foreach (XLCell c in Column(startRow, endRow).CellsUsed()) { @@ -351,17 +353,17 @@ if (newLinePosition >= 0) { if (newLinePosition > 0) - runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition)); + runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition), fontCache); if (runningWidth > thisWidthMax) thisWidthMax = runningWidth; runningWidth = newLinePosition < formattedString.Length - 2 - ? f.GetWidth(formattedString.Substring(newLinePosition + 2)) + ? f.GetWidth(formattedString.Substring(newLinePosition + 2), fontCache) : 0; } else - runningWidth += f.GetWidth(formattedString); + runningWidth += f.GetWidth(formattedString, fontCache); #endregion } @@ -372,15 +374,15 @@ if (textRotation == 255) { if (runningWidth <= 0) - runningWidth = f.GetWidth("X"); + runningWidth = f.GetWidth("X", fontCache); if (newLinePosition >= 0) - runningWidth += f.GetWidth("X"); + runningWidth += f.GetWidth("X", fontCache); } else { rotated = true; - Double vWidth = f.GetWidth("X"); + Double vWidth = f.GetWidth("X", fontCache); if (vWidth > maxLineWidth) maxLineWidth = vWidth; @@ -389,17 +391,17 @@ lineCount++; if (newLinePosition > 0) - runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition)); + runningWidth += f.GetWidth(formattedString.Substring(0, newLinePosition), fontCache); if (runningWidth > thisWidthMax) thisWidthMax = runningWidth; runningWidth = newLinePosition < formattedString.Length - 2 - ? f.GetWidth(formattedString.Substring(newLinePosition + 2)) + ? f.GetWidth(formattedString.Substring(newLinePosition + 2), fontCache) : 0; } else - runningWidth += f.GetWidth(formattedString); + runningWidth += f.GetWidth(formattedString, fontCache); } #endregion @@ -429,7 +431,7 @@ #endregion } else - thisWidthMax = c.Style.Font.GetWidth(c.GetFormattedString()); + thisWidthMax = c.Style.Font.GetWidth(c.GetFormattedString(), fontCache); if (thisWidthMax >= maxWidth) { colMaxWidth = maxWidth; diff --git a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs index dc42ae9..4e6fb31 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Excel/Rows/XLRow.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Drawing; namespace ClosedXML.Excel { @@ -267,6 +268,7 @@ public IXLRow AdjustToContents(Int32 startColumn, Int32 endColumn, Double minHeight, Double maxHeight) { + var fontCache = new Dictionary(); Double rowMaxHeight = minHeight; foreach (XLCell c in from XLCell c in Row(startColumn, endColumn).CellsUsed() where !c.IsMerged() select c) { @@ -306,7 +308,7 @@ } Double maxLongCol = kpList.Max(kp => kp.Value.Length); - Double maxHeightCol = kpList.Max(kp => kp.Key.GetHeight()); + Double maxHeightCol = kpList.Max(kp => kp.Key.GetHeight(fontCache)); Int32 lineCount = kpList.Count(kp => kp.Value.Contains(Environment.NewLine)) + 1; if (textRotation == 0) thisHeight = maxHeightCol * lineCount; @@ -327,7 +329,7 @@ } } else - thisHeight = c.Style.Font.GetHeight(); + thisHeight = c.Style.Font.GetHeight( fontCache); if (thisHeight >= maxHeight) { diff --git a/ClosedXML/ClosedXML/ClosedXML/Extensions.cs b/ClosedXML/ClosedXML/ClosedXML/Extensions.cs index 212b26c..24707c4 100644 --- a/ClosedXML/ClosedXML/ClosedXML/Extensions.cs +++ b/ClosedXML/ClosedXML/ClosedXML/Extensions.cs @@ -184,24 +184,23 @@ public static class FontBaseExtensions { - private static readonly Dictionary FontCache = new Dictionary(); - private static Font GetCachedFont(IXLFontBase fontBase) + private static Font GetCachedFont(IXLFontBase fontBase, Dictionary fontCache) { Font font; - if (!FontCache.TryGetValue(fontBase, out font)) + if (!fontCache.TryGetValue(fontBase, out font)) { font = new Font(fontBase.FontName, (float)fontBase.FontSize, GetFontStyle(fontBase)); - FontCache.Add(fontBase, font); + fontCache.Add(fontBase, font); } return font; } - public static Double GetWidth(this IXLFontBase fontBase, String text) + public static Double GetWidth(this IXLFontBase fontBase, String text, Dictionary fontCache) { if (StringExtensions.IsNullOrWhiteSpace(text)) return 0; - var font = GetCachedFont(fontBase); + var font = GetCachedFont(fontBase, fontCache); var textSize = TextRenderer.MeasureText(text, font); double width = (((textSize.Width / (double)7) * 256) - (128 / 7)) / 256; @@ -220,9 +219,9 @@ return fontStyle; } - public static Double GetHeight(this IXLFontBase fontBase) + public static Double GetHeight(this IXLFontBase fontBase, Dictionary fontCache) { - var font = GetCachedFont(fontBase); + var font = GetCachedFont(fontBase, fontCache); var textSize = TextRenderer.MeasureText("X", font); return (double)textSize.Height * 0.85; } diff --git a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj index 1bb81a3..a1e5278 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Examples/ClosedXML_Examples.csproj @@ -113,6 +113,9 @@ ClosedXML.snk + + ..\DocumentFormat.OpenXml.dll + diff --git a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj index a184d52..04e8fad 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Net3.5/ClosedXML_Net3.5.csproj @@ -110,7 +110,7 @@ - D:\Downloads\DocumentFormat.OpenXml.dll + ..\DocumentFormat.OpenXml.dll diff --git a/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj b/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj index 860a343..270798f 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Sandbox/ClosedXML_Sandbox.csproj @@ -105,7 +105,7 @@ False - C:\Temp\DocumentFormat.OpenXml.dll + ..\DocumentFormat.OpenXml.dll diff --git a/ClosedXML/ClosedXML/ClosedXML_Tests/ClosedXML_Tests.csproj b/ClosedXML/ClosedXML/ClosedXML_Tests/ClosedXML_Tests.csproj index 226787b..1809157 100644 --- a/ClosedXML/ClosedXML/ClosedXML_Tests/ClosedXML_Tests.csproj +++ b/ClosedXML/ClosedXML/ClosedXML_Tests/ClosedXML_Tests.csproj @@ -44,7 +44,7 @@ - D:\Downloads\DocumentFormat.OpenXml.dll + ..\DocumentFormat.OpenXml.dll diff --git a/ClosedXML/ClosedXML/DocumentFormat.OpenXml.dll b/ClosedXML/ClosedXML/DocumentFormat.OpenXml.dll new file mode 100644 index 0000000..a3249c1 --- /dev/null +++ b/ClosedXML/ClosedXML/DocumentFormat.OpenXml.dll Binary files differ