Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update SixLabors.Fonts dependency to version 1.0.0 #2149

Merged
merged 2 commits into from Aug 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ClosedXML/ClosedXML.csproj
Expand Up @@ -40,7 +40,7 @@
</PackageReference>
<PackageReference Include="Janitor.Fody" Version="1.8.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-beta19" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0" />
<!-- Pre-6.0.0 System.IO.Packaging has a race condition https://github.com/dotnet/runtime/issues/43012 -->
<PackageReference Include="System.IO.Packaging" Version="6.0.0" />
<PackageReference Include="XLParser" Version="1.5.2" />
Expand Down
33 changes: 26 additions & 7 deletions ClosedXML/Graphics/DefaultGraphicEngine.cs
Expand Up @@ -158,7 +158,7 @@ public double GetDescent(IXLFontBase font, double dpiY)

private double GetDescent(IXLFontBase font, double dpiY, FontMetrics metrics)
{
return PointsToPixels(-metrics.Descender * font.FontSize / metrics.UnitsPerEm, dpiY);
return PointsToPixels(-metrics.VerticalMetrics.Descender * font.FontSize / metrics.UnitsPerEm, dpiY);
}

public double GetMaxDigitWidth(IXLFontBase fontBase, double dpiX)
Expand All @@ -171,13 +171,13 @@ public double GetMaxDigitWidth(IXLFontBase fontBase, double dpiX)
public double GetTextHeight(IXLFontBase font, double dpiY)
{
var metrics = GetMetrics(font);
return PointsToPixels((metrics.Ascender - 2 * metrics.Descender) * font.FontSize / metrics.UnitsPerEm, dpiY);
return PointsToPixels((metrics.VerticalMetrics.Ascender - 2 * metrics.VerticalMetrics.Descender) * font.FontSize / metrics.UnitsPerEm, dpiY);
}

public double GetTextWidth(string text, IXLFontBase fontBase, double dpiX)
{
var font = GetFont(fontBase);
var dimensionsPx = TextMeasurer.Measure(text, new TextOptions(font)
var dimensionsPx = TextMeasurer.MeasureAdvance(text, new TextOptions(font)
{
Dpi = 72, // Normalize DPI, so 1px is 1pt
KerningMode = KerningMode.None
Expand All @@ -194,11 +194,21 @@ public GlyphBox GetGlyphBox(ReadOnlySpan<int> graphemeCluster, IXLFontBase font,
var advanceFu = 0;
for (var i = 0; i < graphemeCluster.Length; ++i)
{
var glyphs = metric.GetGlyphMetrics(new CodePoint(graphemeCluster[i]), ColorFontSupport.None);
var containsMetrics = metric.TryGetGlyphMetrics(
new CodePoint(graphemeCluster[i]),
TextAttributes.None,
TextDecorations.None,
LayoutMode.HorizontalTopBottom,
ColorFontSupport.None,
out var glyphs);

// As of SixLabors.Fonts 1.0.0, the TryGetGlyphMetrics method never fails. It returns .notdef glyph 0
// as a fallback glyph, but it might change in the future.
if (!containsMetrics)
continue;

foreach (var glyph in glyphs)
{
advanceFu += glyph.AdvanceWidth;
}
}

var emInPx = font.FontSize / 72d * dpi.X;
Expand Down Expand Up @@ -264,7 +274,16 @@ private double CalculateMaxDigitWidth(MetricId metricId)
var maxWidth = int.MinValue;
for (var c = '0'; c <= '9'; ++c)
{
var glyphMetrics = metrics.GetGlyphMetrics(new CodePoint(c), ColorFontSupport.None);
var containsMetrics = metrics.TryGetGlyphMetrics(
new CodePoint(c),
TextAttributes.None,
TextDecorations.None,
LayoutMode.HorizontalTopBottom,
ColorFontSupport.None,
out var glyphMetrics);
if (!containsMetrics)
continue;

var glyphAdvance = 0;
foreach (var glyphMetric in glyphMetrics)
glyphAdvance += glyphMetric.AdvanceWidth;
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Expand Up @@ -5,7 +5,7 @@
</PropertyGroup>

<PropertyGroup>
<Version>0.102.0</Version>
<Version>0.102.1</Version>
</PropertyGroup>

<!-- Set common properties regarding assembly information and nuget packages -->
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
@@ -1,4 +1,4 @@
version: 0.102.0.{build}
version: 0.102.1.{build}

os: Visual Studio 2019
image: Visual Studio 2019
Expand Down