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

Improve Code Quality #818

Merged
merged 21 commits into from
Apr 18, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
b918ab3
Make AdobeFontMetricsLigature a struct
iamcarbon Apr 12, 2024
8604cc3
Make AdobeFontMetricsCharacterSize a struct
iamcarbon Apr 12, 2024
99213b5
Eliminate allocation in CompactFontFormatData
iamcarbon Apr 12, 2024
55bb43f
Pass TransformationMatrix by reference
iamcarbon Apr 12, 2024
23a62fc
Seal Encoding classes
iamcarbon Apr 12, 2024
6cd09bc
Make SubTableHeaderEntry a readonly struct
iamcarbon Apr 12, 2024
9586b90
Introduce StringSplitter and eliminate various allocations in GlyphLi…
iamcarbon Apr 12, 2024
f990c3b
Eliminate a few substring allocations
iamcarbon Apr 12, 2024
de82ed6
Use char overload on StringBuilder
iamcarbon Apr 12, 2024
d1597b9
Eliminate virtual calls on stringIndex
iamcarbon Apr 12, 2024
58e6498
Optimize ReadHelper ReadLong and ReadInt methods
iamcarbon Apr 12, 2024
b6f87c4
Add additional readonly annotations to PdfRectangle
iamcarbon Apr 12, 2024
0b427b8
Optimize NameTokenizer
iamcarbon Apr 12, 2024
639d20d
Eliminate allocation in TrueTypeGlyphTableSubsetter
iamcarbon Apr 12, 2024
a2a9be2
Use empty arrays
iamcarbon Apr 12, 2024
fd3c6dd
Eliminate allocations in OperationWriteHelper.WriteHex
iamcarbon Apr 13, 2024
7c36e20
Use simplified DecryptCbc method on .NET 6+
iamcarbon Apr 13, 2024
ec720b1
Fix windows-1252 encoding not working on net6.0 and 8.0
iamcarbon Apr 15, 2024
36d1093
Update int buffers to exact unsigned max length and eliminate additio…
iamcarbon Apr 15, 2024
c3e993f
Fix typo
iamcarbon Apr 15, 2024
7faa3ae
Remove unused constant
iamcarbon Apr 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Pass TransformationMatrix by reference
iamcarbon committed Apr 12, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 55bb43f40b222c0eb422cdd919871ed1c09b8c93
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig.Tests/Integration/StreamProcessorTests.cs
Original file line number Diff line number Diff line change
@@ -148,9 +148,9 @@ public override void RenderGlyph(IFont font,
int code,
string unicode,
long currentOffset,
TransformationMatrix renderingMatrix,
TransformationMatrix textMatrix,
TransformationMatrix transformationMatrix,
in TransformationMatrix renderingMatrix,
in TransformationMatrix textMatrix,
in TransformationMatrix transformationMatrix,
CharacterBoundingBox characterBoundingBox)
{
_letters.Add(unicode);
Original file line number Diff line number Diff line change
@@ -69,9 +69,9 @@ public override void RenderGlyph(IFont font,
int code,
string unicode,
long currentOffset,
TransformationMatrix renderingMatrix,
TransformationMatrix textMatrix,
TransformationMatrix transformationMatrix,
in TransformationMatrix renderingMatrix,
in TransformationMatrix textMatrix,
in TransformationMatrix transformationMatrix,
CharacterBoundingBox characterBoundingBox)
{
if (textRenderingMode == TextRenderingMode.Neither)
@@ -98,9 +98,9 @@ private void ShowVectorFontGlyph(SKPath path,
IColor strokingColor,
IColor nonStrokingColor,
TextRenderingMode textRenderingMode,
TransformationMatrix renderingMatrix,
TransformationMatrix textMatrix,
TransformationMatrix transformationMatrix)
in TransformationMatrix renderingMatrix,
in TransformationMatrix textMatrix,
in TransformationMatrix transformationMatrix)
{
var transformMatrix = renderingMatrix.ToSKMatrix()
.PostConcat(textMatrix.ToSKMatrix())
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig/Content/BasePageFactory.cs
Original file line number Diff line number Diff line change
@@ -176,7 +176,7 @@ private TPage ProcessPageInternal(
CropBox cropBox,
UserSpaceUnit userSpaceUnit,
PageRotationDegrees rotation,
TransformationMatrix initialMatrix,
in TransformationMatrix initialMatrix,
ReadOnlyMemory<byte> contentBytes)
{
IReadOnlyList<IGraphicsStateOperation> operations;
@@ -315,7 +315,7 @@ protected MediaBox GetMediaBox(int number, DictionaryToken dictionary, PageTreeM
/// <param name="transformationMatrix"></param>
/// <param name="mediaBox"></param>
/// <param name="cropBox"></param>
protected static void ApplyTransformNormalise(TransformationMatrix transformationMatrix, ref MediaBox mediaBox, ref CropBox cropBox)
protected static void ApplyTransformNormalise(in TransformationMatrix transformationMatrix, ref MediaBox mediaBox, ref CropBox cropBox)
{
if (transformationMatrix != TransformationMatrix.Identity)
{
8 changes: 4 additions & 4 deletions src/UglyToad.PdfPig/Graphics/BaseStreamProcessor.cs
Original file line number Diff line number Diff line change
@@ -120,7 +120,7 @@ protected BaseStreamProcessor(
CropBox cropBox,
UserSpaceUnit userSpaceUnit,
PageRotationDegrees rotation,
TransformationMatrix initialMatrix,
in TransformationMatrix initialMatrix,
ParsingOptions parsingOptions)
{
this.PageNumber = pageNumber;
@@ -325,9 +325,9 @@ public abstract void RenderGlyph(IFont font,
int code,
string unicode,
long currentOffset,
TransformationMatrix renderingMatrix,
TransformationMatrix textMatrix,
TransformationMatrix transformationMatrix,
in TransformationMatrix renderingMatrix,
in TransformationMatrix textMatrix,
in TransformationMatrix transformationMatrix,
CharacterBoundingBox characterBoundingBox);

/// <inheritdoc/>
6 changes: 3 additions & 3 deletions src/UglyToad.PdfPig/Graphics/ContentStreamProcessor.cs
Original file line number Diff line number Diff line change
@@ -95,9 +95,9 @@ public override void RenderGlyph(IFont font,
int code,
string unicode,
long currentOffset,
TransformationMatrix renderingMatrix,
TransformationMatrix textMatrix,
TransformationMatrix transformationMatrix,
in TransformationMatrix renderingMatrix,
in TransformationMatrix textMatrix,
in TransformationMatrix transformationMatrix,
CharacterBoundingBox characterBoundingBox)
{
var transformedGlyphBounds = PerformantRectangleTransformer
3 changes: 2 additions & 1 deletion src/UglyToad.PdfPig/Graphics/InlineImageBuilder.cs
Original file line number Diff line number Diff line change
@@ -25,7 +25,8 @@ public sealed class InlineImageBuilder
/// </summary>
public ReadOnlyMemory<byte> Bytes { get; internal set; }

internal InlineImage CreateInlineImage(TransformationMatrix transformationMatrix,
internal InlineImage CreateInlineImage(
in TransformationMatrix transformationMatrix,
ILookupFilterProvider filterProvider,
IPdfTokenScanner tokenScanner,
RenderingIntent defaultRenderingIntent,
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ public static class PerformantRectangleTransformer
/// <summary>
/// Transform the rectangle using the matrices.
/// </summary>
public static PdfRectangle Transform(TransformationMatrix first, TransformationMatrix second, TransformationMatrix third, PdfRectangle rectangle)
public static PdfRectangle Transform(in TransformationMatrix first, in TransformationMatrix second, in TransformationMatrix third, PdfRectangle rectangle)
{
var tl = rectangle.TopLeft;
var tr = rectangle.TopRight;
4 changes: 2 additions & 2 deletions src/UglyToad.PdfPig/Util/PatternParser.cs
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ public static PatternColor Create(IToken pattern, IPdfTokenScanner scanner, IRes
}

private static PatternColor CreateTilingPattern(StreamToken patternStream, DictionaryToken patternExtGState,
TransformationMatrix matrix, IPdfTokenScanner scanner)
in TransformationMatrix matrix, IPdfTokenScanner scanner)
{
if (!patternStream.StreamDictionary.TryGet<NumericToken>(NameToken.PaintType, scanner, out var paintTypeToken))
{
@@ -113,7 +113,7 @@ private static PatternColor CreateTilingPattern(StreamToken patternStream, Dicti
}

private static PatternColor CreateShadingPattern(DictionaryToken patternDictionary, DictionaryToken? patternExtGState,
TransformationMatrix matrix, IPdfTokenScanner scanner, IResourceStore resourceStore,
in TransformationMatrix matrix, IPdfTokenScanner scanner, IResourceStore resourceStore,
ILookupFilterProvider filterProvider)
{
IToken shadingToken = patternDictionary.Data[NameToken.Shading];
2 changes: 1 addition & 1 deletion src/UglyToad.PdfPig/Writer/PdfPageBuilder.cs
Original file line number Diff line number Diff line change
@@ -989,7 +989,7 @@ public PdfPageBuilder CopyFrom(Page srcPage)
return this;
}

private List<Letter> DrawLetters(NameToken? name, string text, IWritingFont font, TransformationMatrix fontMatrix, double fontSize, TransformationMatrix textMatrix)
private List<Letter> DrawLetters(NameToken? name, string text, IWritingFont font, in TransformationMatrix fontMatrix, double fontSize, TransformationMatrix textMatrix)
{
var horizontalScaling = 1;
var rise = 0;