/// <summary>
            /// Updates resources data from <see cref="VectorPath"/> instance.
            /// </summary>
            /// <param name="pathResource">The path resource.</param>
            /// <param name="vogkResource">The vector origination data resource.</param>
            /// <param name="socoResource">The solid color resource.</param>
            /// <param name="vectorPath">The vector path.</param>
            /// <param name="imageSize">The image size to correct converting point coordinates.</param>
            private static void UpdateResources(VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource, VectorPath vectorPath, Size imageSize)
            {
                pathResource.Version     = vectorPath.Version;
                pathResource.IsNotLinked = vectorPath.IsNotLinked;
                pathResource.IsDisabled  = vectorPath.IsDisabled;
                pathResource.IsInverted  = vectorPath.IsInverted;

                List <VectorShapeOriginSettings> originSettings = new List <VectorShapeOriginSettings>();
                List <VectorPathRecord>          path           = new List <VectorPathRecord>();

                path.Add(new PathFillRuleRecord(null));
                path.Add(new InitialFillRuleRecord(vectorPath.IsFillStartsWithAllPixels));
                for (ushort i = 0; i < vectorPath.Shapes.Count; i++)
                {
                    PathShape shape = vectorPath.Shapes[i];
                    shape.ShapeIndex = i;
                    path.AddRange(shape.ToVectorPathRecords(imageSize));
                    originSettings.Add(new VectorShapeOriginSettings()
                    {
                        IsShapeInvalidated = true, OriginIndex = i
                    });
                }

                pathResource.Paths = path.ToArray();
                vogkResource.ShapeOriginSettings = originSettings.ToArray();

                socoResource.Color = vectorPath.FillColor;
            }
            /// <summary>
            /// Updates the input layer resources from <see cref="VectorPath"/> instance, or replace by new path resource and updates.
            /// </summary>
            /// <param name="psdLayer">The psd layer.</param>
            /// <param name="vectorPath">The vector path.</param>
            /// <param name="imageSize">The image size to correct converting point coordinates.</param>
            public static void UpdateLayerFromVectorPath(Layer psdLayer, VectorPath vectorPath, bool createIfNotExist = false)
            {
                ValidateLayer(psdLayer);

                VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, createIfNotExist);
                VogkResource           vogkResource = FindVogkResource(psdLayer, createIfNotExist);
                SoCoResource           socoResource = FindSoCoResource(psdLayer, createIfNotExist);

                Size imageSize = psdLayer.Container.Size;

                UpdateResources(pathResource, vogkResource, socoResource, vectorPath, imageSize);

                ReplaceVectorPathDataResourceInLayer(psdLayer, pathResource, vogkResource, socoResource);
            }
            /// <summary>
            /// Creates the <see cref="VectorPath"/> instance based on resources from input layer.
            /// </summary>
            /// <param name="psdLayer">The psd layer.</param>
            /// <returns>the <see cref="VectorPath"/> instance based on resources from input layer.</returns>
            public static VectorPath CreateVectorPathForLayer(Layer psdLayer)
            {
                ValidateLayer(psdLayer);

                Size imageSize = psdLayer.Container.Size;

                VectorPathDataResource pathResource = FindVectorPathDataResource(psdLayer, true);
                SoCoResource           socoResource = FindSoCoResource(psdLayer, true);
                VectorPath             vectorPath   = new VectorPath(pathResource, imageSize);

                if (socoResource != null)
                {
                    vectorPath.FillColor = socoResource.Color;
                }

                return(vectorPath);
            }
            /// <summary>
            /// Initializes a values based on input <see cref="VectorPathDataResource"/> resource.
            /// </summary>
            /// <param name="resource">The vector path data resource.</param>
            /// <param name="imageSize">The image size to correct converting point coordinates.</param>
            private void InitFromResource(VectorPathDataResource resource, Size imageSize)
            {
                List <PathShape>        newShapes             = new List <PathShape>();
                InitialFillRuleRecord   initialFillRuleRecord = null;
                LengthRecord            lengthRecord          = null;
                List <BezierKnotRecord> bezierKnotRecords     = new List <BezierKnotRecord>();

                foreach (var pathRecord in resource.Paths)
                {
                    if (pathRecord is LengthRecord)
                    {
                        if (bezierKnotRecords.Count > 0)
                        {
                            newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords, imageSize));
                            lengthRecord = null;
                            bezierKnotRecords.Clear();
                        }

                        lengthRecord = (LengthRecord)pathRecord;
                    }
                    else if (pathRecord is BezierKnotRecord)
                    {
                        bezierKnotRecords.Add((BezierKnotRecord)pathRecord);
                    }
                    else if (pathRecord is InitialFillRuleRecord)
                    {
                        initialFillRuleRecord = (InitialFillRuleRecord)pathRecord;
                    }
                }

                if (bezierKnotRecords.Count > 0)
                {
                    newShapes.Add(new PathShape(lengthRecord, bezierKnotRecords, imageSize));
                    lengthRecord = null;
                    bezierKnotRecords.Clear();
                }

                this.IsFillStartsWithAllPixels = initialFillRuleRecord != null ? initialFillRuleRecord.IsFillStartsWithAllPixels : false;
                this.Shapes = newShapes;

                this.Version     = resource.Version;
                this.IsNotLinked = resource.IsNotLinked;
                this.IsDisabled  = resource.IsDisabled;
                this.IsInverted  = resource.IsInverted;
            }
            /// <summary>
            /// Replaces resources in layer by updated or new ones.
            /// </summary>
            /// <param name="psdLayer">The psd layer.</param>
            /// <param name="pathResource">The path resource.</param>
            /// <param name="vogkResource">The vector origination data resource.</param>
            /// <param name="socoResource">The solid color resource.</param>
            private static void ReplaceVectorPathDataResourceInLayer(Layer psdLayer, VectorPathDataResource pathResource, VogkResource vogkResource, SoCoResource socoResource)
            {
                bool pathResourceExist = false;
                bool vogkResourceExist = false;
                bool socoResourceExist = false;

                List <LayerResource> resources = new List <LayerResource>(psdLayer.Resources);

                for (int i = 0; i < resources.Count; i++)
                {
                    LayerResource resource = resources[i];
                    if (resource is VectorPathDataResource)
                    {
                        resources[i]      = pathResource;
                        pathResourceExist = true;
                    }
                    else if (resource is VogkResource)
                    {
                        resources[i]      = vogkResource;
                        vogkResourceExist = true;
                    }
                    else if (resource is SoCoResource)
                    {
                        resources[i]      = socoResource;
                        socoResourceExist = true;
                    }
                }

                if (!pathResourceExist)
                {
                    resources.Add(pathResource);
                }

                if (!vogkResourceExist)
                {
                    resources.Add(vogkResource);
                }

                if (!socoResourceExist)
                {
                    resources.Add(socoResource);
                }

                psdLayer.Resources = resources.ToArray();
            }
            /// <summary>
            /// Finds the <see cref="VectorPathDataResource"/> resource in input layer resources.
            /// </summary>
            /// <param name="psdLayer">The psd layer.</param>
            /// <param name="createIfNotExist">If resource not exists, then for <see cref="true"/> creates a new resource, otherwise return <see cref="null"/>.</param>
            /// <returns>The <see cref="VectorPathDataResource"/> resource.</returns>
            private static VectorPathDataResource FindVectorPathDataResource(Layer psdLayer, bool createIfNotExist = false)
            {
                VectorPathDataResource pathResource = null;

                foreach (var resource in psdLayer.Resources)
                {
                    if (resource is VectorPathDataResource)
                    {
                        pathResource = (VectorPathDataResource)resource;
                        break;
                    }
                }

                if (createIfNotExist && pathResource == null)
                {
                    pathResource = new VmskResource();
                }

                return(pathResource);
            }
 /// <summary>
 /// Initializes a new instance of the <see cref="VectorPath" /> class based on <see cref="VectorPathDataResource"/>.
 /// </summary>
 /// <param name="vectorPathDataResource">The vector path data resource.</param>
 /// <param name="imageSize">The image size to correct converting point coordinates.</param>
 public VectorPath(VectorPathDataResource vectorPathDataResource, Size imageSize)
 {
     this.InitFromResource(vectorPathDataResource, imageSize);
 }