Skip to content

Commit 9301b3a

Browse files
authored
Merge pull request #55 from synercoder/features/refactor-everything
Refactor everything
2 parents 490bdde + 9c15069 commit 9301b3a

File tree

115 files changed

+5547
-6298
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

115 files changed

+5547
-6298
lines changed

.editorconfig

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ charset = utf-8
1313
end_of_line = crlf
1414
indent_style = space
1515
indent_size = 4
16-
insert_final_newline = false
16+
tab_width = 4
17+
insert_final_newline = true
1718
trim_trailing_whitespace = true
1819

1920
#########################
@@ -43,7 +44,6 @@ trim_trailing_whitespace = false
4344
# Web Files
4445
[*.{htm,html,js,ts,tsx,css,sass,scss,less,svg,vue}]
4546
indent_size = 2
46-
insert_final_newline = true
4747

4848
###########################
4949
# C# code style settings
@@ -72,6 +72,9 @@ csharp_style_expression_bodied_local_functions = false:silent
7272
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#pattern-matching
7373
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
7474
csharp_style_pattern_matching_over_as_with_null_check = true:warning
75+
csharp_style_prefer_pattern_matching = true:silent
76+
csharp_style_prefer_not_pattern = true:suggestion
77+
csharp_style_prefer_extended_property_pattern = true:suggestion
7578

7679
# Inlined variable declarations
7780
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#inlined-variable-declarations
@@ -104,6 +107,20 @@ csharp_style_prefer_range_operator = true:suggestion
104107
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#miscellaneous-preferences
105108
csharp_style_deconstructed_variable_declaration = true:warning
106109
csharp_style_pattern_local_over_anonymous_function = true:none
110+
csharp_prefer_simple_using_statement = false:suggestion
111+
csharp_prefer_static_local_function = true:suggestion
112+
csharp_using_directive_placement = outside_namespace:silent
113+
csharp_style_namespace_declarations = file_scoped:suggestion
114+
csharp_style_prefer_method_group_conversion = true:silent
115+
csharp_style_prefer_null_check_over_type_check = true:suggestion
116+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
117+
csharp_style_implicit_object_creation_when_type_is_apparent = false:suggestion
118+
csharp_style_prefer_tuple_swap = true:suggestion
119+
csharp_style_allow_embedded_statements_on_same_line_experimental = true:silent
120+
csharp_style_allow_blank_lines_between_consecutive_braces_experimental = true:silent
121+
csharp_style_allow_blank_line_after_colon_in_constructor_initializer_experimental = true:silent
122+
csharp_style_prefer_parameter_null_checking = true:suggestion
123+
csharp_style_prefer_switch_expression = true:suggestion
107124

108125
###########################
109126
# .NET code style settings
@@ -147,15 +164,23 @@ dotnet_style_prefer_inferred_tuple_names = true:warning
147164
dotnet_style_prefer_inferred_anonymous_type_member_names = false:suggestion
148165
dotnet_style_prefer_auto_properties = true:warning
149166
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
150-
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
151-
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
167+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
168+
dotnet_style_prefer_conditional_expression_over_return = true:silent
152169
dotnet_style_prefer_compound_assignment = true:suggestion
153170

154171
# Null-checking preferences
155172
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#null-checking-preferences
156173
dotnet_style_coalesce_expression = true:warning
157174
dotnet_style_null_propagation = true:warning
158175

176+
# Miscellaneous preferences
177+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
178+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
179+
dotnet_style_prefer_simplified_interpolation = true:suggestion
180+
dotnet_style_namespace_match_folder = true:suggestion
181+
dotnet_style_allow_multiple_blank_lines_experimental = true:suggestion
182+
dotnet_style_allow_statement_immediately_after_block_experimental = true:silent
183+
159184
#############################
160185
# .NET code quality settings
161186
# https://docs.microsoft.com/en-us/visualstudio/ide/editorconfig-language-conventions?view=vs-2019#net-code-quality-settings
@@ -249,8 +274,13 @@ dotnet_naming_symbols.private_static_readonly_fields.applicable_accessibilities
249274
dotnet_naming_symbols.private_static_readonly_fields.applicable_kinds = field
250275
dotnet_naming_symbols.private_static_readonly_fields.required_modifiers = static, readonly
251276

277+
# public_static_readonly_fields - Define static and readonly fields
278+
dotnet_naming_symbols.public_static_readonly_fields.applicable_accessibilities = public
279+
dotnet_naming_symbols.public_static_readonly_fields.applicable_kinds = field
280+
dotnet_naming_symbols.public_static_readonly_fields.required_modifiers = static, readonly
281+
252282
# non_private_static_readonly_fields - Define static and readonly fields
253-
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_accessibilities = public, internal, protected
283+
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_accessibilities = internal, protected
254284
dotnet_naming_symbols.non_private_static_readonly_fields.applicable_kinds = field
255285
dotnet_naming_symbols.non_private_static_readonly_fields.required_modifiers = static, readonly
256286

@@ -317,7 +347,12 @@ dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.severi
317347
dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.symbols = non_private_static_readonly_fields
318348
dotnet_naming_rule.non_private_static_readonly_fields_must_be_pascal_case.style = pascal_case
319349

320-
# Public, internal and protected readonly fields must be PascalCase
350+
# Public static readonly fields must be ALL_UPPER_CASE
351+
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.severity = warning
352+
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.symbols = public_static_readonly_fields
353+
dotnet_naming_rule.public_static_readonly_fields_must_be_all_upper.style = all_upper_with_underscore
354+
355+
# Internal and protected readonly fields must be PascalCase
321356
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.severity = warning
322357
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.symbols = non_private_readonly_fields
323358
dotnet_naming_rule.non_private_readonly_fields_must_be_pascal_case.style = pascal_case
@@ -365,4 +400,4 @@ dotnet_naming_rule.non_interface_types_must_be_pascal_case.style = pascal_case
365400
# Interfaces must be PascalCase and start with an 'I'
366401
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.severity = warning
367402
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.symbols = interface_types
368-
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i
403+
dotnet_naming_rule.interface_types_must_be_prefixed_with_i.style = prefix_interface_interface_with_i

Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
<PropertyGroup Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)','net5.0'))">
5151
<DefineConstants>$(DefineConstants);SUPPORTS_MEMBERNOTNULL</DefineConstants>
5252
<DefineConstants>$(DefineConstants);SUPPORTS_INIT</DefineConstants>
53+
<DefineConstants>$(DefineConstants);SUPPORTS_TYPED_ENUM_ISDEFINED</DefineConstants>
5354
</PropertyGroup>
5455

55-
</Project>
56+
</Project>

Directory.Build.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<ItemGroup>
1010
<PackageReference Update="SixLabors.ImageSharp" Version="2.1.*" />
11-
<PackageReference Update="Synercoding.Primitives" Version="1.0.0-rc08" />
11+
<PackageReference Update="Synercoding.Primitives" Version="1.0.0-rc09" />
1212
</ItemGroup>
1313

14-
</Project>
14+
</Project>

README.md

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[nuget-badge]: https://img.shields.io/nuget/v/Synercoding.FileFormats.Pdf.svg?label=Synercoding.FileFormats.Pdf
66

77

8-
This project was created to enable PDF creation on .NETStandard. This because multiple libraries did not suit my purpose of working on .NET Core & .NET Framework the same way. Some alternatives supported settings the different boxes (Media, Crop, Bleed & Trim) but did not fully supported images on all platforms. Others supported images but not the different boxes, and again others did not work at all on .NET Core.
8+
This project was created to enable PDF creation on .NETStandard 2.1, .NET 6 & .NET 7. This because multiple libraries did not suit my purpose of working on .NET Core & .NET Framework the same way. Some alternatives supported settings the different boxes (Media, Crop, Bleed & Trim) but did not fully supported images on all platforms. Others supported images but not the different boxes, and again others did not work at all on .NET Core.
99

1010
Because of those reasons this libary was created.
1111

@@ -15,16 +15,30 @@ This project is licensed under MIT license.
1515
## Specifications used
1616
This library was created using the specifications lay out in ["PDF 32000-1:2008, Document management – Portable document format – Part 1: PDF 1.7"](https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf).
1717

18-
The full specifications are not implemented. This library currently only supports placements of images, drawing of vector shapes (CMYK, RGB & gray scale), and setting the different boxes.
18+
The full specifications are not implemented.
19+
This library currently only supports:
20+
- Images
21+
- *No transparency support at the moment*
22+
- Text
23+
- *Only the 14 standard fonts are available*
24+
- *See "9.6.2.2 Standard Type 1 Fonts (Standard 14 Fonts)" in the specifications.*
25+
- Shapes
26+
- Setting page boxes (Media, Crop, Bleed, Trim & Art)
27+
- Color model limited to:
28+
- DeviceGray
29+
- DeviceRGB
30+
- DeviceCMYK
31+
- Separations/Spotcolor (with a linearized type 2 method to portay the tint)
1932

2033
## Remarks
2134
Unlike most PDF libraries this library does not create the entire PDF model in memory before writing the PDF to a (file)stream. Most libaries support editing capabilities, because this libary only supports creating files, it was not necessary to keep the PDF model in memory. This results in less memory usage.
2235

2336
To place the images this library makes use of [SixLabors/ImageSharp](https://github.com/SixLabors/ImageSharp). All images that are placed in the PDF will be saved internally as a JPG file. This means that this library currently does **NOT** support transparency.
2437

2538
### Output pdfs
26-
The PDF files created in this library are PDF 1.7 compliant.
39+
The PDF files created in this library are not fully PDF 1.7 compliant, because the standard 14 fonts are partially written to the Font Dictionary, The **FirstChar**, **LastChar**. **Widths** and **FontDescriptor** values are omitted, which is was acceptable prior to PDF 1.5. This special treatment of the 14 standard fonts was deprecated in PDF 1.5. The PDF's that are generated will work in conforming readers because as the specification states: *"For backwards capability, conforming readers shall still provide the special treatment identified for the standard 14 fonts."*.
2740

41+
This shortcoming shall be remedied when broader font support is implemented.
2842

2943
### Sample program images
3044
The sample project called *Synercoding.FileFormats.Pdf.ConsoleTester* uses multiple images. Those images were taken from [Pexels.com](https://www.pexels.com/royalty-free-images/) and are licensed under the [Pexels License](https://www.pexels.com/photo-license/).
@@ -35,21 +49,18 @@ The sample project called *Synercoding.FileFormats.Pdf.ConsoleTester* uses multi
3549
using (var writer = new PdfWriter(fs))
3650
{
3751
writer
38-
.AddPage(page =&gt;
52+
.AddPage(page =>
3953
{
40-
var bleed = new Spacing(3, Unit.Millimeters);
41-
page.MediaBox = Sizes.A4Portrait.Expand(bleed).AsRectangle();
54+
var bleed = Mm(3);
55+
page.MediaBox = Sizes.A4.Expand(bleed).AsRectangle();
4256
page.TrimBox = page.MediaBox.Contract(bleed);
43-
44-
using (var eyeStream = File.OpenRead("Pexels_com/adult-blue-blue-eyes-865711.jpg"))
57+
58+
using (var barrenStream = File.OpenRead("Pexels_com/arid-barren-desert-1975514.jpg"))
59+
using (var barrenImage = SixLabors.ImageSharp.Image.Load(barrenStream))
4560
{
46-
var scale = 3456d / 5184;
47-
48-
var width = 100;
49-
var height = 100 * scale;
61+
var scale = (double)barrenImage.Width / barrenImage.Height;
5062

51-
var offSet = 6;
52-
page.AddImage(eyeStream, new Rectangle(offSet, offSet, width + offSet, height + offSet, Unit.Millimeters));
63+
page.Content.AddImage(barrenImage, new Rectangle(0, 0, scale * 303, 303, Unit.Millimeters));
5364
}
54-
});
55-
}</code></pre>
65+
})
66+
}</code></pre>

0 commit comments

Comments
 (0)