mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-11-24 16:53:20 +08:00
Fix glyph bounding box for Type3 font with zero height (#610)
* For Type3 font with a zero width/height bounding box, set it to a sensible default using the font matrix. This ensures the letter bounding boxes will not have height 0. * Also added a test to check for non-zero height in the sample Type3 PDF * Prevent division by zero error --------- Co-authored-by: mvantzet <mark@radialsg.com>
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 70 KiB |
File diff suppressed because one or more lines are too long
24
src/UglyToad.PdfPig.Tests/Integration/Type3FontTests.cs
Normal file
24
src/UglyToad.PdfPig.Tests/Integration/Type3FontTests.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
namespace UglyToad.PdfPig.Tests.Integration
|
||||
{
|
||||
using Xunit;
|
||||
|
||||
public class Type3FontTests
|
||||
{
|
||||
private static string GetFilename()
|
||||
{
|
||||
return IntegrationHelpers.GetDocumentPath("type3-font-zero-height.pdf");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HasLetterWidthsAndHeights()
|
||||
{
|
||||
using (var document = PdfDocument.Open(GetFilename()))
|
||||
{
|
||||
var page = document.GetPage(1);
|
||||
|
||||
Assert.Contains(page.Letters, x => x.GlyphRectangle.Width != 0);
|
||||
Assert.Contains(page.Letters, x => x.GlyphRectangle.Height != 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@
|
||||
private const string SPARCv9ArchitectureManual = "SPARC - v9 Architecture Manual";
|
||||
private const string CroppedAndRotatedFile = "cropped-and-rotated";
|
||||
private const string MOZILLA_10372_2File = "MOZILLA-10372-2";
|
||||
private const string Type3FontZeroHeight = "type3-font-zero-height";
|
||||
|
||||
private static string GetFilename(string name)
|
||||
{
|
||||
@@ -137,6 +138,12 @@
|
||||
Run(MOZILLA_10372_2File, 1584, 7);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Type3FontZeroHeightTest()
|
||||
{
|
||||
Run(Type3FontZeroHeight, 1255);
|
||||
}
|
||||
|
||||
private static void Run(string file, int imageHeight = 792, int pageNo = 1)
|
||||
{
|
||||
var pdfFileName = GetFilename(file);
|
||||
|
||||
@@ -31,6 +31,12 @@
|
||||
|
||||
var fontMatrix = GetFontMatrix(dictionary);
|
||||
|
||||
if (boundingBox.Left == 0 && boundingBox.Bottom == 0 && boundingBox.Height == 0 && boundingBox.Width == 0
|
||||
&& fontMatrix.A != 0 && fontMatrix.D != 0)
|
||||
{
|
||||
boundingBox = new PdfRectangle(0, 0, 1 / fontMatrix.A, 1 / fontMatrix.D);
|
||||
}
|
||||
|
||||
var firstCharacter = FontDictionaryAccessHelper.GetFirstCharacter(dictionary);
|
||||
var lastCharacter = FontDictionaryAccessHelper.GetLastCharacter(dictionary);
|
||||
var widths = FontDictionaryAccessHelper.GetWidths(scanner, dictionary);
|
||||
|
||||
Reference in New Issue
Block a user