From 6ccf41f36cecd26adde4e5fcc8fb7a963743b81d Mon Sep 17 00:00:00 2001 From: BobLD Date: Sun, 19 Feb 2023 22:26:26 +0000 Subject: [PATCH] Rebase --- .../Tokens/DictionaryTokenTests.cs | 3 +- .../Graphics/ContentStreamProcessor.cs | 73 ++++++++++--------- 2 files changed, 39 insertions(+), 37 deletions(-) diff --git a/src/UglyToad.PdfPig.Tests/Tokens/DictionaryTokenTests.cs b/src/UglyToad.PdfPig.Tests/Tokens/DictionaryTokenTests.cs index 20542694..c7156151 100644 --- a/src/UglyToad.PdfPig.Tests/Tokens/DictionaryTokenTests.cs +++ b/src/UglyToad.PdfPig.Tests/Tokens/DictionaryTokenTests.cs @@ -12,7 +12,8 @@ namespace UglyToad.PdfPig.Tests.Tokens [Fact] public void NullDictionaryThrows() { - Action action = () => new DictionaryToken(null); + IReadOnlyDictionary dictionary = null; + Action action = () => new DictionaryToken(dictionary); Assert.Throws(action); } diff --git a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs index 7f271fa0..da7581c8 100644 --- a/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs +++ b/src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs @@ -75,11 +75,10 @@ var transformedPdfBounds = PerformantRectangleTransformer .Transform(renderingMatrix, textMatrix, transformationMatrix, new PdfRectangle(0, 0, characterBoundingBox.Width, 0)); - - Letter letter = null; - if (Diacritics.IsInCombiningDiacriticRange(unicode) && bytes.CurrentOffset > 0 && letters.Count > 0) - { - var attachTo = letters[letters.Count - 1]; + Letter letter = null; + if (Diacritics.IsInCombiningDiacriticRange(unicode) && currentOffset > 0 && letters.Count > 0) + { + var attachTo = letters[letters.Count - 1]; if (attachTo.TextSequence == TextSequence && Diacritics.TryCombineDiacriticWithPreviousLetter(unicode, attachTo.Value, out var newLetter)) @@ -87,39 +86,41 @@ // TODO: union of bounding boxes. letters.Remove(attachTo); - letter = new Letter( - newLetter, - attachTo.GlyphRectangle, - attachTo.StartBaseLine, - attachTo.EndBaseLine, - attachTo.Width, - attachTo.FontSize, - attachTo.Font, - attachTo.RenderingMode, - attachTo.StrokeColor, - attachTo.FillColor, - attachTo.PointSize, - attachTo.TextSequence); - } - } - - // If we did not create a letter for a combined diacritic, create one here. - if (letter == null) - { letter = new Letter( - unicode, - transformedGlyphBounds, - transformedPdfBounds.BottomLeft, - transformedPdfBounds.BottomRight, - transformedPdfBounds.Width, - fontSize, - font.Details, - currentState.FontState.TextRenderingMode, - currentState.CurrentStrokingColor, - currentState.CurrentNonStrokingColor, - pointSize, - textSequence); + newLetter, + attachTo.GlyphRectangle, + attachTo.StartBaseLine, + attachTo.EndBaseLine, + attachTo.Width, + attachTo.FontSize, + attachTo.Font, + attachTo.RenderingMode, + attachTo.StrokeColor, + attachTo.FillColor, + attachTo.PointSize, + attachTo.TextSequence); } + } + + var currentState = GetCurrentState(); // TODO - pass stroking and text rendering mode + + // If we did not create a letter for a combined diacritic, create one here. + if (letter == null) + { + letter = new Letter( + unicode, + transformedGlyphBounds, + transformedPdfBounds.BottomLeft, + transformedPdfBounds.BottomRight, + transformedPdfBounds.Width, + fontSize, + font.Details, + currentState.FontState.TextRenderingMode, + currentState.CurrentStrokingColor, + currentState.CurrentNonStrokingColor, + pointSize, + TextSequence); + } letters.Add(letter); markedContentStack.AddLetter(letter);