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

Pdf creation + small fixes inside SvgSection #916

Merged
merged 12 commits into from
Nov 22, 2022
Merged

Pdf creation + small fixes inside SvgSection #916

merged 12 commits into from
Nov 22, 2022

Conversation

katehryhorenko
Copy link
Contributor

@katehryhorenko katehryhorenko commented Nov 7, 2022

BACKGROUND:
We need to convert svg to pdf

DESCRIPTION:

  1. Svg-net library is replaced with Skia. Skia supports PDF creation
  2. SvgSection is not static anymore. Now it's possible to create SvgSection class instance. It has all required properties by default to generate stocking plan.
  3. New extensions like ToSvgLine and ToSvgPolygon that can use SvgSection to get scene bounds
  4. OnElementDrawing event that allows to customize elements drawing
  5. Draw method was changed a little bit. Just small fixes:
    • document rotation should be around the middle point, otherwise the image is not at the view box. You still can see it if you open svg file, but during conversion to pdf or any other format, image will be lost. Also, ViewBox should be moved a little bit to fit the image size/location
      doc.ViewBox = new SvgViewBox((wOld - ViewBoxWidth) / 2.0f, (ViewBoxHeight - hOld) / 2.0f, ViewBoxWidth, ViewBoxHeight);
      doc.CustomAttributes.Add("transform", $"rotate({rotation} {ViewBoxWidth / 2.0} {ViewBoxHeight / 2.0})");
    • in some reason BaseLineOffset is lost during conversion to pdf, so I replaced it with translate(0, 0.2)

REQUIRED:

  • All changes are up to date in CHANGELOG.md.

This change is Reviewable

Copy link
Contributor

@ikeough ikeough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @katehryhorenko)


Elements.Serialization.SVG/src/Elements.Serialization.SVG.csproj line 21 at r1 (raw file):

    <PackageReference Include="Svg.Skia" Version="0.6.0-preview2"/>
    <PackageReference Include="SkiaSharp" Version="2.88.3"/>
    <PackageReference Include="SkiaSharp.NativeAssets.Linux.NoDependencies" Version="2.88.3"/>

Is this required when you're not running on the lambda? I know that packages can do cool stuff like pull down platform dependencies depending on how they're built. Just wondering if need to always include this.


Elements.Serialization.SVG/src/Elements.Serialization.SVG.csproj line 29 at r1 (raw file):

    <ItemGroup>
    <None Include="libSkiaSharp.so" Link="%(Filename)%(Extension)" CopyToOutputDirectory="PreserveNewest" />

I've never had to do this for a nuget package that targets Linux. Is this required?

I'm getting up to date here: mono/SkiaSharp#312 (comment). But I'm still not 100% sure that this is required.


Elements.Serialization.SVG/src/SvgSection.cs line 38 at r1 (raw file):

    /// <summary>
    ///

Empty docs make me sad. May I suggest. A section of a model serialized to SVG.


Elements.Serialization.SVG/src/SvgSection.cs line 45 at r1 (raw file):

        /// <summary>
        /// This event occurs before element is added to the svg scene.

"...before an element is added..."


Elements.Serialization.SVG/src/SvgSection.cs line 57 at r1 (raw file):

        /// Initializes a new instance of SvgDrawingPlan class
        /// </summary>
        /// <param name="models">A collection of models to include in the plan</param>

"A collection of models to include in the plan." (note the period) All of these doc comments can end in a period.


Elements.Serialization.SVG/src/SvgSection.cs line 88 at r1 (raw file):

        /// <summary>
        /// Gets or sets an svg context which defines settings for grid elements

I usually don't say "Gets or sets" because one day we'll decide we don't want to "set" anymore and we'll forget to update the docs. I recommend "The svg context which defines settings for the grid elements." The developer tooling does a pretty good job of telling the user if you can get and set.


Elements.Serialization.SVG/src/SvgSection.cs line 302 at r1 (raw file):

                    }

Whitespace


Elements.Serialization.SVG/src/SvgSection.cs line 401 at r1 (raw file):

        private static BBox3 ComputeSceneBounds(IList<Model> models)
        {
            var max = new Vector3(double.MinValue, double.MinValue);

I've written this exact same code numerous times. Can we add convenience constructors Vector3.Max and Vector3.Min?


Elements.Serialization.SVG/src/SvgSection.cs line 413 at r1 (raw file):

                        geo.UpdateBoundsAndComputeSolid();

                        if (geo._bounds.Max.X > max.X)

Can we replace this block with geo._bounds.Extend(new[]{max,min})?


Elements.Serialization.SVG/src/SvgSection.cs line 444 at r1 (raw file):

            foreach (var model in models)
            {
                var modelWithoutCusromElements = model;

modelWithoutCustomElements


Elements.Serialization.SVG/src/SvgSection.cs line 600 at r1 (raw file):

        #region Private fields

        private readonly List<Model> models = new List<Model>();

Our general practice is to put private fields at the top of the class and to use C# coding guidelines with camel-cased, prefixed members: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions#camel-case

Copy link
Contributor Author

@katehryhorenko katehryhorenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @ikeough and @katehryhorenko)


Elements.Serialization.SVG/src/Elements.Serialization.SVG.csproj line 21 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

Is this required when you're not running on the lambda? I know that packages can do cool stuff like pull down platform dependencies depending on how they're built. Just wondering if need to always include this.

Yes, it's for lambda


Elements.Serialization.SVG/src/Elements.Serialization.SVG.csproj line 29 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

I've never had to do this for a nuget package that targets Linux. Is this required?

I'm getting up to date here: mono/SkiaSharp#312 (comment). But I'm still not 100% sure that this is required.

Yes, it didn't work without this file


Elements.Serialization.SVG/src/SvgSection.cs line 38 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

Empty docs make me sad. May I suggest. A section of a model serialized to SVG.

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 45 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

"...before an element is added..."

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 88 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

I usually don't say "Gets or sets" because one day we'll decide we don't want to "set" anymore and we'll forget to update the docs. I recommend "The svg context which defines settings for the grid elements." The developer tooling does a pretty good job of telling the user if you can get and set.

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 302 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

Whitespace

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 401 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

I've written this exact same code numerous times. Can we add convenience constructors Vector3.Max and Vector3.Min?

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 413 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

Can we replace this block with geo._bounds.Extend(new[]{max,min})?

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 444 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

modelWithoutCustomElements

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 600 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

Our general practice is to put private fields at the top of the class and to use C# coding guidelines with camel-cased, prefixed members: https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/coding-style/coding-conventions#camel-case

Done.

Copy link
Contributor

@ikeough ikeough left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @katehryhorenko)


Elements/src/Geometry/Vector3.cs line 79 at r2 (raw file):

        /// <summary>
        /// The smallest possible value of a Elements.Vector

Recommend "The smallest possible value of a Vector3."


Elements/src/Geometry/Vector3.cs line 87 at r2 (raw file):

        /// <summary>
        /// The largest possible value of a Elements.Vector

Recommend "The largest possible value of a Vector3."


Elements.Serialization.SVG/src/SvgSection.cs line 112 at r2 (raw file):

        /// <summary>
        /// Gets or sets if gridlines exist, should they be shown in the plan.

Missed one! Recommend "Should grid lines be shown in the section?"

Copy link
Contributor Author

@katehryhorenko katehryhorenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 1 of 1 approvals obtained (waiting on @ikeough)


Elements/src/Geometry/Vector3.cs line 79 at r2 (raw file):

Previously, ikeough (Ian Keough) wrote…

Recommend "The smallest possible value of a Vector3."

Done.


Elements/src/Geometry/Vector3.cs line 87 at r2 (raw file):

Previously, ikeough (Ian Keough) wrote…

Recommend "The largest possible value of a Vector3."

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 57 at r1 (raw file):

Previously, ikeough (Ian Keough) wrote…

"A collection of models to include in the plan." (note the period) All of these doc comments can end in a period.

Done.


Elements.Serialization.SVG/src/SvgSection.cs line 112 at r2 (raw file):

Previously, ikeough (Ian Keough) wrote…

Missed one! Recommend "Should grid lines be shown in the section?"

Done.

@katehryhorenko katehryhorenko merged commit aa61a3a into master Nov 22, 2022
@katehryhorenko katehryhorenko deleted the SVG-PDF branch November 22, 2022 15:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants