Skip to content

Commit

Permalink
Improve the code quality
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Jan 1, 2025
1 parent 62ab073 commit f568abf
Show file tree
Hide file tree
Showing 15 changed files with 163 additions and 134 deletions.
1 change: 1 addition & 0 deletions src/iTextSharp.LGPLv2.Core/BannedSymbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ T:System.Collections.ArrayList;Don't use a non-generic data structure.
T:System.Collections.SortedList;Don't use a non-generic data structure.
T:System.Collections.Stack;Don't use a non-generic data structure.
T:System.Collections.Queue;Don't use a non-generic data structure.
T:System.Console;Libraries should not use STDIO streams. Leave that to the application.
26 changes: 18 additions & 8 deletions src/iTextSharp.LGPLv2.Core/iTextSharp.LGPLv2.Core.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>iTextSharp.LGPLv2.Core is an unofficial port of the last LGPL version of the iTextSharp (V4.1.6) to .NET Core.</Description>
<VersionPrefix>3.5.0</VersionPrefix>
<LangVersion>latest</LangVersion>
<VersionPrefix>3.5.1</VersionPrefix>
<Authors>Vahid Nasiri</Authors>
<TargetFrameworks>net9.0;net8.0;net7.0;net6.0;netstandard2.0;net462;</TargetFrameworks>
<NoWarn>$(NoWarn);1591</NoWarn>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<AssemblyName>iTextSharp.LGPLv2.Core</AssemblyName>
<PackageId>iTextSharp.LGPLv2.Core</PackageId>
Expand All @@ -20,15 +18,26 @@
<DebugType>embedded</DebugType>
<PublishRepositoryUrl>true</PublishRepositoryUrl>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<ImplicitUsings>enable</ImplicitUsings>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<PackageReadmeFile>README.md</PackageReadmeFile>
</PropertyGroup>
<PropertyGroup>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<NoWarn>$(NoWarn);1591</NoWarn>
<AnalysisLevel>latest-all</AnalysisLevel>
<Features>strict</Features>
<Deterministic>true</Deterministic>
<AnalysisMode>All</AnalysisMode>
<CodeAnalysisTreatWarningsAsErrors>true</CodeAnalysisTreatWarningsAsErrors>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PackageReadmeFile>README.md</PackageReadmeFile>
<Deterministic>true</Deterministic>
<Features>strict</Features>
<ReportAnalyzer>true</ReportAnalyzer>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzers>true</RunAnalyzers>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
Expand Down Expand Up @@ -70,6 +79,7 @@
<Using Include="System.IO"/>
<Using Remove="System.Net.Http"/> <!-- for .NET Framework 4.x -->
</ItemGroup>

<ItemGroup>
<PackageReference Include="SkiaSharp" Version="3.116.1"/>
<PackageReference Include="BouncyCastle.Cryptography" Version="2.5.0"/>
Expand Down
4 changes: 1 addition & 3 deletions src/iTextSharp.LGPLv2.Core/iTextSharp/text/Anchor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ public Anchor(float leading, string str, Font font) : base(leading, str, font)
/// <param name="phrase">a Phrase </param>
public Anchor(Phrase phrase) : base(phrase)
{
var anchor = phrase as Anchor;

if (anchor != null)
if (phrase is Anchor anchor)
{
var a = anchor;
Name = a.name;
Expand Down
41 changes: 23 additions & 18 deletions src/iTextSharp.LGPLv2.Core/iTextSharp/text/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ public Document() : this(text.PageSize.A4)
/// Constructs a new Document-object.
/// </summary>
/// <param name="pageSize">the pageSize</param>
public Document(Rectangle pageSize) : this(pageSize, 36, 36, 36, 36)
public Document(Rectangle pageSize) : this(pageSize, marginLeft: 36, marginRight: 36, marginTop: 36,
marginBottom: 36)
{
}

Expand Down Expand Up @@ -227,6 +228,7 @@ public virtual HeaderFooter Footer
set
{
footer = value;

foreach (var listener in _listeners)
{
listener.Footer = value;
Expand All @@ -243,6 +245,7 @@ public virtual HeaderFooter Header
set
{
header = value;

foreach (var listener in _listeners)
{
listener.Header = value;
Expand All @@ -259,6 +262,7 @@ public virtual int PageCount
set
{
PageNumber = value;

foreach (var listener in _listeners)
{
listener.PageCount = value;
Expand All @@ -280,17 +284,17 @@ public virtual bool Add(IElement element)

if (IsDocumentClose)
{
throw new DocumentException("The document has been closed. You can't add any Elements.");
throw new DocumentException(message: "The document has been closed. You can't add any Elements.");
}

if (!IsDocumentOpen && element.IsContent())
{
throw new DocumentException("The document is not open yet; you can only add Meta information.");
throw new DocumentException(message: "The document is not open yet; you can only add Meta information.");
}

var success = false;
var number = element as ChapterAutoNumber;
if (number != null)

if (element is ChapterAutoNumber number)
{
Chapternumber = number.SetAutomaticNumber(Chapternumber);
}
Expand All @@ -300,10 +304,10 @@ public virtual bool Add(IElement element)
success |= listener.Add(element);
}

var largeElement = element as ILargeElement;
if (largeElement != null)
if (element is ILargeElement largeElement)
{
var e = largeElement;

if (!e.ElementComplete)
{
e.FlushContent();
Expand Down Expand Up @@ -385,6 +389,7 @@ public virtual void Open()
public virtual void ResetFooter()
{
footer = null;

foreach (var listener in _listeners)
{
listener.ResetFooter();
Expand All @@ -397,6 +402,7 @@ public virtual void ResetFooter()
public virtual void ResetHeader()
{
header = null;

foreach (var listener in _listeners)
{
listener.ResetHeader();
Expand All @@ -409,6 +415,7 @@ public virtual void ResetHeader()
public virtual void ResetPageCount()
{
PageNumber = 0;

foreach (var listener in _listeners)
{
listener.ResetPageCount();
Expand All @@ -425,6 +432,7 @@ public virtual void ResetPageCount()
public virtual bool SetMarginMirroring(bool marginMirroring)
{
MarginMirroring = marginMirroring;

foreach (var listener in _listeners)
{
listener.SetMarginMirroring(marginMirroring);
Expand All @@ -444,6 +452,7 @@ public virtual bool SetMarginMirroring(bool marginMirroring)
public virtual bool SetMarginMirroringTopBottom(bool marginMirroringTopBottom)
{
MarginMirroringTopBottom = marginMirroringTopBottom;

foreach (var listener in _listeners)
{
listener.SetMarginMirroringTopBottom(marginMirroringTopBottom);
Expand All @@ -466,6 +475,7 @@ public virtual bool SetMargins(float marginLeft, float marginRight, float margin
RightMargin = marginRight;
TopMargin = marginTop;
BottomMargin = marginBottom;

foreach (var listener in _listeners)
{
listener.SetMargins(marginLeft, marginRight, marginTop, marginBottom);
Expand All @@ -482,6 +492,7 @@ public virtual bool SetMargins(float marginLeft, float marginRight, float margin
public virtual bool SetPageSize(Rectangle pageSize)
{
PageSize = pageSize;

foreach (var listener in _listeners)
{
listener.SetPageSize(pageSize);
Expand Down Expand Up @@ -509,9 +520,9 @@ public void Dispose()
/// Adds the current date and time to a Document.
/// </summary>
/// <returns>true if successful, false otherwise</returns>
public bool AddCreationDate() =>
Add(new Meta(Element.CREATIONDATE,
DateTime.Now.ToString("ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture)));
public bool AddCreationDate()
=> Add(new Meta(Element.CREATIONDATE,
DateTime.Now.ToString(format: "ddd MMM dd HH:mm:ss zzz yyyy", CultureInfo.InvariantCulture)));

/// <summary>
/// Adds the creator to a Document.
Expand All @@ -524,10 +535,7 @@ public bool AddCreationDate() =>
/// Adds a IDocListener to the Document.
/// </summary>
/// <param name="listener">the new IDocListener</param>
public void AddDocListener(IDocListener listener)
{
_listeners.Add(listener);
}
public void AddDocListener(IDocListener listener) => _listeners.Add(listener);

/// <summary>
/// Adds a user defined header to the document.
Expand Down Expand Up @@ -611,8 +619,5 @@ public void AddDocListener(IDocListener listener)
/// Removes a IDocListener from the Document.
/// </summary>
/// <param name="listener">the IDocListener that has to be removed.</param>
public void RemoveIDocListener(IDocListener listener)
{
_listeners.Remove(listener);
}
public void RemoveIDocListener(IDocListener listener) => _listeners.Remove(listener);
}
Original file line number Diff line number Diff line change
Expand Up @@ -1298,8 +1298,6 @@ protected void DumpList()
c[j] = '\n';
}
}

Console.WriteLine("" + v.Type + new string(c));
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/iTextSharp.LGPLv2.Core/iTextSharp/text/pdf/GlyphList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ static GlyphList()

if (resourceStream == null)
{
Console.Error.WriteLine(value: "glyphlist.txt not found as resource.");

return;
}

Expand Down Expand Up @@ -76,9 +74,9 @@ static GlyphList()
};
}
}
catch (Exception e)
catch (Exception)
{
Console.Error.WriteLine($"glyphlist.txt loading error: {e.Message}");
// ...
}
}

Expand Down
Loading

0 comments on commit f568abf

Please sign in to comment.