Assess if transformedGlyphBounds and use transformedPdfBounds as fallback and fix #987
Some checks are pending
Build and test / build (push) Waiting to run
Run Integration Tests / build (push) Waiting to run

This commit is contained in:
BobLd 2025-02-18 20:04:33 +00:00
parent 1298356f10
commit 5a06e1e1cc
3 changed files with 31 additions and 6 deletions

View File

@ -7,6 +7,23 @@
public class GithubIssuesTests
{
[Fact]
public void Issue987()
{
var path = IntegrationHelpers.GetSpecificTestDocumentPath("zeroheightdemo.pdf");
using (var document = PdfDocument.Open(path))
{
var page = document.GetPage(1);
var words = page.GetWords().ToArray();
foreach (var word in words)
{
Assert.True(word.BoundingBox.Width > 0);
Assert.True(word.BoundingBox.Height > 0);
}
}
}
[Fact]
public void Issue982()
{

View File

@ -100,18 +100,20 @@ namespace UglyToad.PdfPig.Graphics
{
var transformedGlyphBounds = PerformantRectangleTransformer
.Transform(renderingMatrix, textMatrix, transformationMatrix, characterBoundingBox.GlyphBounds);
var transformedPdfBounds = PerformantRectangleTransformer
.Transform(renderingMatrix,
textMatrix,
transformationMatrix,
new PdfRectangle(0, 0, characterBoundingBox.Width, 0));
new PdfRectangle(0, 0, characterBoundingBox.Width, UserSpaceUnit.PointMultiples));
if (ParsingOptions.ClipPaths)
{
var currentClipping = currentState.CurrentClippingPath;
if (currentClipping?.IntersectsWith(transformedGlyphBounds) == false)
{
return;
}
}
Letter letter = null;
@ -141,20 +143,26 @@ namespace UglyToad.PdfPig.Graphics
}
}
// The bbox is assumed to be valid if the width or the height is greater than 0.
// The whitespace letter can have a 0 height and still be a valid bbox.
// This could change in the future (i.e. AND instead of OR).
bool isBboxValid = transformedGlyphBounds.Width > double.Epsilon ||
transformedGlyphBounds.Height > double.Epsilon;
// If we did not create a letter for a combined diacritic, create one here.
if (letter is null)
{
letter = new Letter(
unicode,
transformedGlyphBounds,
isBboxValid ? transformedGlyphBounds : transformedPdfBounds,
transformedPdfBounds.BottomLeft,
transformedPdfBounds.BottomRight,
transformedPdfBounds.Width,
fontSize,
font.Details,
currentState.FontState.TextRenderingMode,
currentState.CurrentStrokingColor!,
currentState.CurrentNonStrokingColor!,
currentState.FontState.TextRenderingMode,
currentState.CurrentStrokingColor!,
currentState.CurrentNonStrokingColor!,
pointSize,
TextSequence);
}