Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/EPPlus.Export.Pdf/ExcelPdf.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ Date Author Change
using EPPlus.Export.Pdf.PdfSettings;
using OfficeOpenXml.Style;
using EPPlus.Fonts.OpenType;
using OfficeOpenXml.Interfaces.Fonts;

namespace EPPlus.Export.Pdf
{
Expand Down
1 change: 1 addition & 0 deletions src/EPPlus.Export.Pdf/PdfLayout/PdfCellContentLayout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Date Author Change
using EPPlus.Graphics.Math;
using OfficeOpenXml;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Interfaces.Fonts;
using OfficeOpenXml.Style;
using System.Collections.Generic;
using System.Linq;
Expand Down
1 change: 1 addition & 0 deletions src/EPPlus.Export.Pdf/PdfLayout/PdfCellData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Date Author Change
using EPPlus.Export.Pdf.Pdfhelpers;
using EPPlus.Fonts.OpenType;
using EPPlus.Graphics;
using OfficeOpenXml.Interfaces.Fonts;
using OfficeOpenXml.Style;
using System.Collections.Generic;
using System.Drawing;
Expand Down
1 change: 1 addition & 0 deletions src/EPPlus.Export.Pdf/PdfObjects/PdfContentStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Date Author Change
using EPPlus.Graphics;
using EPPlus.Graphics.Math;
using OfficeOpenXml;
using OfficeOpenXml.Interfaces.Fonts;
using OfficeOpenXml.Style;
using System;
using System.Collections.Generic;
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus.Export.Pdf/PdfResources/PdfFontResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Date Author Change
using System;
using System.Collections.Generic;
using EPPlus.Graphics;
using OfficeOpenXml.Interfaces.Fonts;

namespace EPPlus.Export.Pdf.PdfResources
{
Expand All @@ -34,7 +35,7 @@ public PdfFontResource(string fontName, FontSubFamily subFamily, int labelNumber
: base("F", labelNumber)
{
this.fontName = fontName;
fontData = OpenTypeFonts.GetFontData(pageSettings.FontDirectories, fontName, subFamily, pageSettings.SearchSystemDirectories);
fontData = OpenTypeFonts.LoadFont(fontName, subFamily, pageSettings.FontDirectories, pageSettings.SearchSystemDirectories);
}

//Get the Font Descriptor object to write in PDF.
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus.Export.Pdf/Pdfhelpers/PdfTextData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Date Author Change
using EPPlus.Fonts.OpenType;
using EPPlus.Fonts.OpenType.Tables.Cmap;
using EPPlus.Fonts.OpenType.Tables.Kern;
using OfficeOpenXml.Interfaces.Fonts;
using System;
using System.Linq;

Expand All @@ -23,7 +24,7 @@ internal static class PdfTextData
{
internal static OpenTypeFont GetFontData(PdfPageSettings pageSettings, string fontName, FontSubFamily subFamily)
{
return OpenTypeFonts.GetFontData(pageSettings.FontDirectories, fontName, subFamily, pageSettings.SearchSystemDirectories);
return OpenTypeFonts.LoadFont(fontName, subFamily, pageSettings.FontDirectories, pageSettings.SearchSystemDirectories);
}

internal static double MeasureFontHeight(OpenTypeFont font, double fontSize)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType;
using EPPlus.Fonts.OpenType.TextShaping;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Interfaces.Fonts;

[MemoryDiagnoser]
[SimpleJob(warmupCount: 1, iterationCount: 3)]
Expand All @@ -17,7 +17,7 @@ public class ExtractCharWidthsBenchmark
public void Setup()
{
var fontFolders = new List<string> { /* your font paths */ };
var font = OpenTypeFonts.GetFontData(fontFolders, "Calibri", FontSubFamily.Regular);
var font = OpenTypeFonts.LoadFont("Calibri");
_shaper = new TextShaper(font);
_options = ShapingOptions.Default;

Expand Down
13 changes: 7 additions & 6 deletions src/EPPlus.Fonts.OpenType.Benchmarks/FontCacheBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BenchmarkDotNet.Attributes;
using OfficeOpenXml.Interfaces.Fonts;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -30,14 +31,14 @@ public void Setup()

// Pre-load font into cache
OpenTypeFonts.ClearFontCache();
OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
OpenTypeFonts.LoadFont("Roboto");
}

[Benchmark]
public OpenTypeFont Load_FromCache_SingleThread()
{
// This should be extremely fast - just cache lookup
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
return OpenTypeFonts.LoadFont("Roboto");
}

[Benchmark]
Expand All @@ -46,10 +47,10 @@ public OpenTypeFont[] Load_FromCache_MultipleFonts()
// Simulates loading multiple font styles (like for a document)
return new[]
{
OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular),
OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Bold),
OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Italic),
OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.BoldItalic)
OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular),
OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Bold),
OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Italic),
OpenTypeFonts.LoadFont("Roboto", FontSubFamily.BoldItalic)
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType;
using OfficeOpenXml.Interfaces.Fonts;

/// <summary>
/// Benchmarks for repeated cache clearing scenarios
Expand Down Expand Up @@ -28,10 +29,10 @@ public OpenTypeFont Load_Clear_Load_Pattern()
{
// Simulates pattern where cache is cleared between operations
OpenTypeFonts.ClearFontCache();
var font1 = OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
var font1 = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);

OpenTypeFonts.ClearFontCache();
var font2 = OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
var font2 = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);

return font2;
}
Expand All @@ -40,8 +41,8 @@ public OpenTypeFont Load_Clear_Load_Pattern()
public OpenTypeFont Load_Reuse_Pattern()
{
// Simulates pattern where cache is NOT cleared (optimal)
var font1 = OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
var font2 = OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
var font1 = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
var font2 = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);

return font2;
}
Expand Down
11 changes: 6 additions & 5 deletions src/EPPlus.Fonts.OpenType.Benchmarks/FontLoadingBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Date Author Change
*************************************************************************************************/
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType;
using OfficeOpenXml.Interfaces.Fonts;
using System.Collections.Generic;
using System.IO;

Expand Down Expand Up @@ -40,35 +41,35 @@ public void Setup()
public OpenTypeFont Load_Roboto_Regular_ColdCache()
{
OpenTypeFonts.ClearFontCache(); // Clear INNE i benchmark
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
}

[Benchmark]
public OpenTypeFont Load_Roboto_Regular_WarmCache()
{
// Load UTAN att cleara - använder cache från GlobalSetup eller warmup
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
}

[Benchmark]
public OpenTypeFont Load_Roboto_Bold_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Bold);
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Bold);
}

[Benchmark]
public OpenTypeFont Load_Roboto_Italic_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Italic);
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Italic);
}

[Benchmark]
public OpenTypeFont Load_Roboto_BoldItalic_ColdCache()
{
OpenTypeFonts.ClearFontCache();
return OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.BoldItalic);
return OpenTypeFonts.LoadFont("Roboto", FontSubFamily.BoldItalic);
}
}
}
8 changes: 2 additions & 6 deletions src/EPPlus.Fonts.OpenType.Benchmarks/RichTextBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Date Author Change
using EPPlus.Fonts.OpenType.Integration;
using EPPlus.Fonts.OpenType.TextShaping;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Interfaces.Fonts;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -61,12 +62,7 @@ public void Setup()
}

Console.WriteLine("\nLoading Roboto Regular...");
var font = OpenTypeFonts.GetFontData(
_fontFolders,
FontFamily,
FontSubFamily.Regular,
searchSystemDirectories: false
);
var font = OpenTypeFonts.LoadFont(FontFamily, FontSubFamily.Regular);

Console.WriteLine(string.Format("Loaded: {0} {1} ({2} glyphs)",
font.FullName, font.SubFamily, font.GlyfTable.Glyphs.Count));
Expand Down
3 changes: 2 additions & 1 deletion src/EPPlus.Fonts.OpenType.Benchmarks/SubsettingBenchmarks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Date Author Change
*************************************************************************************************/
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType;
using OfficeOpenXml.Interfaces.Fonts;
using System.Collections.Generic;
using System.IO;

Expand All @@ -35,7 +36,7 @@ public void Setup()
}

_fontFolders = new List<string> { fontsPath };
_roboto = OpenTypeFonts.GetFontData(_fontFolders, "Roboto", FontSubFamily.Regular);
_roboto = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
}

[Benchmark]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Date Author Change
using EPPlus.Fonts.OpenType.Integration;
using EPPlus.Fonts.OpenType.TextShaping;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Interfaces.Fonts;
using System.Collections.Generic;

namespace EPPlus.Fonts.Benchmarks
Expand Down Expand Up @@ -59,7 +60,7 @@ public void Setup()
var fontFolders = new List<string> { fontsPath };

// Setup new layout engine
var font = OpenTypeFonts.GetFontData(fontFolders, FontFamily, FontSubFamily.Regular, true);
var font = OpenTypeFonts.LoadFont(FontFamily, FontSubFamily.Regular);
var shaper = new TextShaper(font);
_layoutEngine = new TextLayoutEngine(shaper);

Expand Down Expand Up @@ -155,7 +156,7 @@ public List<string> New_Wrap_10Paragraphs_Sequential()
[Benchmark]
public double[] OnlyExtractWidths()
{
var font = OpenTypeFonts.GetFontData(null, FontFamily, FontSubFamily.Regular, true);
var font = OpenTypeFonts.LoadFont(FontFamily, FontSubFamily.Regular);
var shaper = new TextShaper(font);
return shaper.ExtractCharWidths(LoremIpsum20Para, FontSize, ShapingOptions.Default);
}
Expand Down
4 changes: 2 additions & 2 deletions src/EPPlus.Fonts.OpenType.Benchmarks/TextShapingBenchmarks.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using BenchmarkDotNet.Attributes;
using EPPlus.Fonts.OpenType.TextShaping;
using OfficeOpenXml.Interfaces.Drawing.Text;
using OfficeOpenXml.Interfaces.Fonts;

namespace EPPlus.Fonts.OpenType.Benchmarks
{
Expand All @@ -22,7 +22,7 @@ public void Setup()
}

var fontFolders = new List<string> { fontsPath };
_roboto = OpenTypeFonts.GetFontData(fontFolders, "Roboto", FontSubFamily.Regular);
_roboto = OpenTypeFonts.LoadFont("Roboto", FontSubFamily.Regular);
_shaper = new TextShaper(_roboto);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>latest</LangVersion>
Expand Down Expand Up @@ -38,6 +38,9 @@
<None Update="Fonts\NotoEmoji-Regular.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fonts\NotoSansMath-Regular.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Fonts\OpenSans-Regular.ttf">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
Loading