Skip to content

Commit f568abf

Browse files
committed
Improve the code quality
1 parent 62ab073 commit f568abf

File tree

15 files changed

+163
-134
lines changed

15 files changed

+163
-134
lines changed

src/iTextSharp.LGPLv2.Core/BannedSymbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ T:System.Collections.ArrayList;Don't use a non-generic data structure.
55
T:System.Collections.SortedList;Don't use a non-generic data structure.
66
T:System.Collections.Stack;Don't use a non-generic data structure.
77
T:System.Collections.Queue;Don't use a non-generic data structure.
8+
T:System.Console;Libraries should not use STDIO streams. Leave that to the application.

src/iTextSharp.LGPLv2.Core/iTextSharp.LGPLv2.Core.csproj

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
33
<Description>iTextSharp.LGPLv2.Core is an unofficial port of the last LGPL version of the iTextSharp (V4.1.6) to .NET Core.</Description>
4-
<VersionPrefix>3.5.0</VersionPrefix>
5-
<LangVersion>latest</LangVersion>
4+
<VersionPrefix>3.5.1</VersionPrefix>
65
<Authors>Vahid Nasiri</Authors>
76
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.0;net462;</TargetFrameworks>
8-
<NoWarn>$(NoWarn);1591</NoWarn>
97
<GenerateDocumentationFile>true</GenerateDocumentationFile>
108
<AssemblyName>iTextSharp.LGPLv2.Core</AssemblyName>
119
<PackageId>iTextSharp.LGPLv2.Core</PackageId>
@@ -20,15 +18,26 @@
2018
<DebugType>embedded</DebugType>
2119
<PublishRepositoryUrl>true</PublishRepositoryUrl>
2220
<EmbedUntrackedSources>true</EmbedUntrackedSources>
23-
<ImplicitUsings>enable</ImplicitUsings>
2421
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
2522
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
26-
<EnableNETAnalyzers>true</EnableNETAnalyzers>
23+
<PackageReadmeFile>README.md</PackageReadmeFile>
24+
</PropertyGroup>
25+
<PropertyGroup>
26+
<LangVersion>latest</LangVersion>
27+
<ImplicitUsings>enable</ImplicitUsings>
28+
<NoWarn>$(NoWarn);1591</NoWarn>
2729
<AnalysisLevel>latest-all</AnalysisLevel>
28-
<Features>strict</Features>
29-
<Deterministic>true</Deterministic>
30+
<AnalysisMode>All</AnalysisMode>
31+
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
32+
<EnableNETAnalyzers>true</EnableNETAnalyzers>
33+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
3034
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
31-
<PackageReadmeFile>README.md</PackageReadmeFile>
35+
<Deterministic>true</Deterministic>
36+
<Features>strict</Features>
37+
<ReportAnalyzer>true</ReportAnalyzer>
38+
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
39+
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
40+
<RunAnalyzers>true</RunAnalyzers>
3241
</PropertyGroup>
3342
<PropertyGroup>
3443
<SignAssembly>true</SignAssembly>
@@ -70,6 +79,7 @@
7079
<Using Include="System.IO"/>
7180
<Using Remove="System.Net.Http"/> <!-- for .NET Framework 4.x -->
7281
</ItemGroup>
82+
7383
<ItemGroup>
7484
<PackageReference Include="SkiaSharp" Version="3.116.1"/>
7585
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0"/>

src/iTextSharp.LGPLv2.Core/iTextSharp/text/Anchor.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ public Anchor(float leading, string str, Font font) : base(leading, str, font)
103103
/// <param name="phrase">a Phrase </param>
104104
public Anchor(Phrase phrase) : base(phrase)
105105
{
106-
var anchor = phrase as Anchor;
107-
108-
if (anchor != null)
106+
if (phrase is Anchor anchor)
109107
{
110108
var a = anchor;
111109
Name = a.name;

src/iTextSharp.LGPLv2.Core/iTextSharp/text/Document.cs

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ public Document() : this(text.PageSize.A4)
9797
/// Constructs a new Document-object.
9898
/// </summary>
9999
/// <param name="pageSize">the pageSize</param>
100-
public Document(Rectangle pageSize) : this(pageSize, 36, 36, 36, 36)
100+
public Document(Rectangle pageSize) : this(pageSize, marginLeft: 36, marginRight: 36, marginTop: 36,
101+
marginBottom: 36)
101102
{
102103
}
103104

@@ -227,6 +228,7 @@ public virtual HeaderFooter Footer
227228
set
228229
{
229230
footer = value;
231+
230232
foreach (var listener in _listeners)
231233
{
232234
listener.Footer = value;
@@ -243,6 +245,7 @@ public virtual HeaderFooter Header
243245
set
244246
{
245247
header = value;
248+
246249
foreach (var listener in _listeners)
247250
{
248251
listener.Header = value;
@@ -259,6 +262,7 @@ public virtual int PageCount
259262
set
260263
{
261264
PageNumber = value;
265+
262266
foreach (var listener in _listeners)
263267
{
264268
listener.PageCount = value;
@@ -280,17 +284,17 @@ public virtual bool Add(IElement element)
280284

281285
if (IsDocumentClose)
282286
{
283-
throw new DocumentException("The document has been closed. You can't add any Elements.");
287+
throw new DocumentException(message: "The document has been closed. You can't add any Elements.");
284288
}
285289

286290
if (!IsDocumentOpen && element.IsContent())
287291
{
288-
throw new DocumentException("The document is not open yet; you can only add Meta information.");
292+
throw new DocumentException(message: "The document is not open yet; you can only add Meta information.");
289293
}
290294

291295
var success = false;
292-
var number = element as ChapterAutoNumber;
293-
if (number != null)
296+
297+
if (element is ChapterAutoNumber number)
294298
{
295299
Chapternumber = number.SetAutomaticNumber(Chapternumber);
296300
}
@@ -300,10 +304,10 @@ public virtual bool Add(IElement element)
300304
success |= listener.Add(element);
301305
}
302306

303-
var largeElement = element as ILargeElement;
304-
if (largeElement != null)
307+
if (element is ILargeElement largeElement)
305308
{
306309
var e = largeElement;
310+
307311
if (!e.ElementComplete)
308312
{
309313
e.FlushContent();
@@ -385,6 +389,7 @@ public virtual void Open()
385389
public virtual void ResetFooter()
386390
{
387391
footer = null;
392+
388393
foreach (var listener in _listeners)
389394
{
390395
listener.ResetFooter();
@@ -397,6 +402,7 @@ public virtual void ResetFooter()
397402
public virtual void ResetHeader()
398403
{
399404
header = null;
405+
400406
foreach (var listener in _listeners)
401407
{
402408
listener.ResetHeader();
@@ -409,6 +415,7 @@ public virtual void ResetHeader()
409415
public virtual void ResetPageCount()
410416
{
411417
PageNumber = 0;
418+
412419
foreach (var listener in _listeners)
413420
{
414421
listener.ResetPageCount();
@@ -425,6 +432,7 @@ public virtual void ResetPageCount()
425432
public virtual bool SetMarginMirroring(bool marginMirroring)
426433
{
427434
MarginMirroring = marginMirroring;
435+
428436
foreach (var listener in _listeners)
429437
{
430438
listener.SetMarginMirroring(marginMirroring);
@@ -444,6 +452,7 @@ public virtual bool SetMarginMirroring(bool marginMirroring)
444452
public virtual bool SetMarginMirroringTopBottom(bool marginMirroringTopBottom)
445453
{
446454
MarginMirroringTopBottom = marginMirroringTopBottom;
455+
447456
foreach (var listener in _listeners)
448457
{
449458
listener.SetMarginMirroringTopBottom(marginMirroringTopBottom);
@@ -466,6 +475,7 @@ public virtual bool SetMargins(float marginLeft, float marginRight, float margin
466475
RightMargin = marginRight;
467476
TopMargin = marginTop;
468477
BottomMargin = marginBottom;
478+
469479
foreach (var listener in _listeners)
470480
{
471481
listener.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
@@ -482,6 +492,7 @@ public virtual bool SetMargins(float marginLeft, float marginRight, float margin
482492
public virtual bool SetPageSize(Rectangle pageSize)
483493
{
484494
PageSize = pageSize;
495+
485496
foreach (var listener in _listeners)
486497
{
487498
listener.SetPageSize(pageSize);
@@ -509,9 +520,9 @@ public void Dispose()
509520
/// Adds the current date and time to a Document.
510521
/// </summary>
511522
/// <returns>true if successful, false otherwise</returns>
512-
public bool AddCreationDate() =>
513-
Add(new Meta(Element.CREATIONDATE,
514-
DateTime.Now.ToString("ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture)));
523+
public bool AddCreationDate()
524+
=> Add(new Meta(Element.CREATIONDATE,
525+
DateTime.Now.ToString(format: "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture)));
515526

516527
/// <summary>
517528
/// Adds the creator to a Document.
@@ -524,10 +535,7 @@ public bool AddCreationDate() =>
524535
/// Adds a IDocListener to the Document.
525536
/// </summary>
526537
/// <param name="listener">the new IDocListener</param>
527-
public void AddDocListener(IDocListener listener)
528-
{
529-
_listeners.Add(listener);
530-
}
538+
public void AddDocListener(IDocListener listener) => _listeners.Add(listener);
531539

532540
/// <summary>
533541
/// Adds a user defined header to the document.
@@ -611,8 +619,5 @@ public void AddDocListener(IDocListener listener)
611619
/// Removes a IDocListener from the Document.
612620
/// </summary>
613621
/// <param name="listener">the IDocListener that has to be removed.</param>
614-
public void RemoveIDocListener(IDocListener listener)
615-
{
616-
_listeners.Remove(listener);
617-
}
622+
public void RemoveIDocListener(IDocListener listener) => _listeners.Remove(listener);
618623
}

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/BarcodePDF417.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,8 +1298,6 @@ protected void DumpList()
12981298
c[j] = '\n';
12991299
}
13001300
}
1301-
1302-
Console.WriteLine("" + v.Type + new string(c));
13031301
}
13041302
}
13051303

src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/GlyphList.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ static GlyphList()
1818

1919
if (resourceStream == null)
2020
{
21-
Console.Error.WriteLine(value: "glyphlist.txt not found as resource.");
22-
2321
return;
2422
}
2523

@@ -76,9 +74,9 @@ static GlyphList()
7674
};
7775
}
7876
}
79-
catch (Exception e)
77+
catch (Exception)
8078
{
81-
Console.Error.WriteLine($"glyphlist.txt loading error: {e.Message}");
79+
// ...
8280
}
8381
}
8482

0 commit comments

Comments
 (0)