Skip to content

Commit 66f87dc

Browse files
committed
Merge branch 'develop9' of https://github.com/EPPlusSoftware/EPPlus into develop9
2 parents fe006b0 + 68b8ab0 commit 66f87dc

4 files changed

Lines changed: 78 additions & 71 deletions

File tree

‎src/EPPlus.Export.Pdf/Settings/PdfPageSettings.cs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,8 @@ internal PdfPageSettings CloneForSheet()
249249
c.SearchSystemDirectories = SearchSystemDirectories;
250250
c.EmbeddFonts = EmbeddFonts;
251251
c.defaultFontName = defaultFontName;
252+
c.GsubFeatures = GsubFeatures;
253+
c.GposFeatures = GposFeatures;
252254
c.Debug = Debug;
253255
c.PrintAsText = PrintAsText;
254256
return c;

‎src/EPPlus/Drawing/Chart/Style/ExcelChartStyleManager.cs‎

Lines changed: 68 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public class ExcelChartStyleManager : XmlHelper
3838
internal readonly ExcelChart _chart;
3939
private readonly ExcelThemeManager _theme;
4040
private static bool _hasLoadedLibraryFiles=false;
41+
private readonly object _syncRoot = new object();
4142
internal ExcelChartStyleManager(XmlNamespaceManager nameSpaceManager, ExcelChart chart) : base(nameSpaceManager)
4243
{
4344
_chart = chart;
@@ -72,11 +73,11 @@ internal ExcelChartStyleManager(XmlNamespaceManager nameSpaceManager, ExcelChart
7273
/// A library where chart styles can be loaded for easier access.
7374
/// EPPlus loads most buildin styles into this collection.
7475
/// </summary>
75-
public static Dictionary<int, ExcelChartStyleLibraryItem> StyleLibrary = new Dictionary<int, ExcelChartStyleLibraryItem>();
76+
public Dictionary<int, ExcelChartStyleLibraryItem> StyleLibrary = new Dictionary<int, ExcelChartStyleLibraryItem>();
7677
/// <summary>
7778
/// A library where chart color styles can be loaded for easier access
7879
/// </summary>
79-
public static Dictionary<int, ExcelChartStyleLibraryItem> ColorsLibrary = new Dictionary<int, ExcelChartStyleLibraryItem>();
80+
public Dictionary<int, ExcelChartStyleLibraryItem> ColorsLibrary = new Dictionary<int, ExcelChartStyleLibraryItem>();
8081
/// <summary>
8182
/// Creates an empty style and color for chart, ready to be customized
8283
/// </summary>
@@ -112,7 +113,7 @@ private void CreateColorXml(ZipPackage p)
112113
/// Loads the default chart style library from the internal resource library.
113114
/// Loads styles, colors and the default theme.
114115
/// </summary>
115-
public static void LoadStyles()
116+
public void LoadStyles()
116117
{
117118
var assembly = Assembly.GetExecutingAssembly();
118119
var defaultStyleLibrary = assembly.GetManifestResourceStream("OfficeOpenXml.resources.DefaultChartStyles.ecs");
@@ -124,7 +125,7 @@ public static void LoadStyles()
124125
/// </summary>
125126
/// <param name="directory">Load all *.ecs files from the directory</param>
126127
/// <param name="clearLibrary">If true, clear the library before load.</param>
127-
public static void LoadStyles(DirectoryInfo directory, bool clearLibrary=true)
128+
public void LoadStyles(DirectoryInfo directory, bool clearLibrary=true)
128129
{
129130
if (clearLibrary)
130131
{
@@ -140,7 +141,7 @@ public static void LoadStyles(DirectoryInfo directory, bool clearLibrary=true)
140141
/// </summary>
141142
/// <param name="ecsFile">The file to load</param>
142143
/// <param name="clearLibrary">If true, clear the library before load.</param>
143-
public static void LoadStyles(FileInfo ecsFile, bool clearLibrary = true)
144+
public void LoadStyles(FileInfo ecsFile, bool clearLibrary = true)
144145
{
145146
using (var fs = ecsFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read))
146147
{
@@ -152,91 +153,91 @@ public static void LoadStyles(FileInfo ecsFile, bool clearLibrary = true)
152153
/// </summary>
153154
/// <param name="stream">The stream to load</param>
154155
/// <param name="clearLibrary">If true, clear the library before load.</param>
155-
public static void LoadStyles(Stream stream, bool clearLibrary = true)
156+
public void LoadStyles(Stream stream, bool clearLibrary = true)
156157
{
157158
LoadStyles(stream, clearLibrary, "The stream");
158159
}
159-
private static void LoadStyles(Stream stream, bool clearLibrary, string filename)
160+
private void LoadStyles(Stream stream, bool clearLibrary, string filename)
160161
{
161-
if (clearLibrary)
162-
{
163-
StyleLibrary.Clear();
164-
}
165-
try
166-
{
167-
using (stream)
162+
if (clearLibrary)
168163
{
169-
var zipStream = new ZipInputStream(stream);
170-
ZipEntry entry;
171-
while ((entry = zipStream.GetNextEntry()) != null)
164+
StyleLibrary.Clear();
165+
}
166+
try
167+
{
168+
using (stream)
172169
{
173-
if (entry.IsDirectory || !entry.FileName.EndsWith(".xml") || entry.UncompressedSize <= 0) continue;
174-
175-
var name = new FileInfo(entry.FileName).Name;
176-
int id=0;
177-
try
170+
var zipStream = new ZipInputStream(stream);
171+
ZipEntry entry;
172+
while ((entry = zipStream.GetNextEntry()) != null)
178173
{
179-
if (name.StartsWith("colors", StringComparison.InvariantCultureIgnoreCase))
174+
if (entry.IsDirectory || !entry.FileName.EndsWith(".xml") || entry.UncompressedSize <= 0) continue;
175+
176+
var name = new FileInfo(entry.FileName).Name;
177+
int id = 0;
178+
try
180179
{
181-
id = int.Parse(name.Substring(6, name.Length - 10));
182-
if (ColorsLibrary.ContainsKey(id)) continue;
180+
if (name.StartsWith("colors", StringComparison.InvariantCultureIgnoreCase))
181+
{
182+
id = int.Parse(name.Substring(6, name.Length - 10));
183+
if (ColorsLibrary.ContainsKey(id)) continue;
184+
}
185+
else if (name.StartsWith("style", StringComparison.InvariantCultureIgnoreCase))
186+
{
187+
id = int.Parse(name.Substring(5, name.Length - 9));
188+
if (StyleLibrary.ContainsKey(id)) continue;
189+
}
190+
else if (name.Equals("defaulttheme.xml", StringComparison.InvariantCultureIgnoreCase))
191+
{
192+
var themeXml = UncompressEntry(zipStream, entry);
193+
ExcelThemeManager._defaultTheme = themeXml;
194+
continue;
195+
}
196+
else
197+
{
198+
if (name.StartsWith("defaulttheme", StringComparison.InvariantCultureIgnoreCase) == false)
199+
{
200+
throw (new InvalidDataException($"{filename} contains a the file {entry.FileName}, with an invalid filename. Please make sure files in the library are named Colors[id].xml or style[id].xml, where [id] is replaced by the id to access the style in the library"));
201+
}
202+
}
183203
}
184-
else if (name.StartsWith("style", StringComparison.InvariantCultureIgnoreCase))
204+
catch
185205
{
186-
id = int.Parse(name.Substring(5, name.Length - 9));
187-
if (StyleLibrary.ContainsKey(id)) continue;
206+
throw (new InvalidDataException($"{filename} contains a the file {entry.FileName}, with an invalid filename. Please make sure files in the library are named Colors[id].xml or style[id].xml, where [id] is replaced by the id to access the style in the library"));
188207
}
189-
else if (name.Equals("defaulttheme.xml", StringComparison.InvariantCultureIgnoreCase))
208+
209+
210+
//Extract and set
211+
var uncompressedContent = UncompressEntry(zipStream, entry);
212+
var item = new ExcelChartStyleLibraryItem() { Id = id, XmlString = uncompressedContent };
213+
if (name[0] == 'c') //Colors
190214
{
191-
var themeXml = UncompressEntry(zipStream, entry);
192-
ExcelThemeManager._defaultTheme = themeXml;
193-
continue;
215+
if (ColorsLibrary.ContainsKey(item.Id) == false)
216+
{
217+
ColorsLibrary.Add(item.Id, item);
218+
}
194219
}
195220
else
196221
{
197-
if (name.StartsWith("defaulttheme", StringComparison.InvariantCultureIgnoreCase)==false)
222+
if (StyleLibrary.ContainsKey(item.Id) == false)
198223
{
199-
throw (new InvalidDataException($"{filename} contains a the file {entry.FileName}, with an invalid filename. Please make sure files in the library are named Colors[id].xml or style[id].xml, where [id] is replaced by the id to access the style in the library"));
224+
StyleLibrary.Add(item.Id, item);
200225
}
201226
}
202227
}
203-
catch
204-
{
205-
throw (new InvalidDataException($"{filename} contains a the file {entry.FileName}, with an invalid filename. Please make sure files in the library are named Colors[id].xml or style[id].xml, where [id] is replaced by the id to access the style in the library"));
206-
}
207-
208-
209-
//Extract and set
210-
var uncompressedContent = UncompressEntry(zipStream, entry);
211-
var item = new ExcelChartStyleLibraryItem() { Id = id, XmlString = uncompressedContent };
212-
if (name[0] == 'c') //Colors
213-
{
214-
if (ColorsLibrary.ContainsKey(item.Id) == false)
215-
{
216-
ColorsLibrary.Add(item.Id, item);
217-
}
218-
}
219-
else
220-
{
221-
if (StyleLibrary.ContainsKey(item.Id)==false)
222-
{
223-
StyleLibrary.Add(item.Id, item);
224-
}
225-
}
226228
}
227229
}
228-
}
229-
catch(Exception ex)
230-
{
231-
if(ex is InvalidDataException)
232-
{
233-
throw;
234-
}
235-
else
230+
catch (Exception ex)
236231
{
237-
throw (new InvalidDataException($"{filename} has an invalid format.", ex));
232+
if (ex is InvalidDataException)
233+
{
234+
throw;
235+
}
236+
else
237+
{
238+
throw (new InvalidDataException($"{filename} has an invalid format.", ex));
239+
}
238240
}
239-
}
240241
}
241242

242243
private static string UncompressEntry(ZipInputStream zipStream, ZipEntry entry)

‎src/EPPlus/Export/PdfExport/Layout/PdfLayout.cs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ internal static Transform GetCatalog(int firstPageNumber, PdfDictionaries dictio
112112
{
113113
AddHeadingCells(pageSettings, dictionaries, page, pageLayout, contentStartX, contentStartY, page.HeadingWidth, page.HeadingHeight, pdfPages[i].HeadingFontName, pdfPages[i].HeadingFontSize, pdfPages[i].HeadingFill);
114114
AddPrintTitleHeadings(pageSettings, dictionaries, page, pageLayout, pdfPages[i].HeadingFontName, pdfPages[i].HeadingFontSize, pdfPages[i].HeadingFill);
115-
AddSpillCells(pageSettings, dictionaries, page, pageLayout);
116115
}
116+
AddSpillCells(pageSettings, dictionaries, page, pageLayout);
117117
AddPrintTitleCells(pageSettings, dictionaries, page, pageLayout);
118118
double y = contentStartY;
119119
double x = contentStartX;
@@ -1459,8 +1459,11 @@ private static double[] BandEdgesY(Dictionary<int, double> topY, int fromRow, in
14591459

14601460
private static PdfCell RangeCell(PdfRange range, int row, int col)
14611461
{
1462-
if (row < range.Range._fromRow || row > range.Range._toRow) return null;
1463-
if (col < range.Range._fromCol || col > range.Range._toCol) return null;
1462+
//if (row < range.Range._fromRow || row > range.Range._toRow) return null;
1463+
//if (col < range.Range._fromCol || col > range.Range._toCol) return null;
1464+
//return range.Map[row, col];
1465+
if (row < range.Map.FromRow || row > range.Map.ToRow) return null;
1466+
if (col < range.Map.FromColumn || col > range.Map.ToColumn) return null;
14641467
return range.Map[row, col];
14651468
}
14661469

‎src/EPPlus/Export/PdfExport/PdfCatalog.cs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Date Author Change
1818
using OfficeOpenXml.Export.PdfExport.Data;
1919
using OfficeOpenXml.Export.PdfExport.Layout;
2020
using OfficeOpenXml.Export.PdfExport.RowResize;
21+
using OfficeOpenXml.Export.PdfExport.Settings;
2122
using OfficeOpenXml.Export.PdfExport.TextMapping;
2223
using OfficeOpenXml.Export.PdfExport.TextShaping;
2324
using System;
@@ -289,7 +290,7 @@ private Transform GetLayout(PdfPageSettings pageSettings, PdfWorksheet[] pdfShee
289290
{
290291
var sheetSettings = new PdfPageSettings[pdfSheets.Length];
291292
for (int i = 0; i < pdfSheets.Length; i++)
292-
sheetSettings[i] = pageSettings;
293+
sheetSettings[i] = GetPdfSettings.GetPdfSettingsForSheet(pageSettings, pdfSheets[i].Worksheet.PrinterSettings);
293294
var Layout = PdfLayout.GetLayout(sheetSettings, _dictionaries, pdfSheets);
294295
return Layout;
295296
}

0 commit comments

Comments
 (0)