mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-08-20 09:37:44 +08:00
Assess if transformedGlyphBounds and use transformedPdfBounds as fallback and fix #987
This commit is contained in:
parent
1298356f10
commit
5a06e1e1cc
@ -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()
|
||||
{
|
||||
|
||||
Binary file not shown.
@ -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);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user