public static VectorMaskSetting GetVectorMaskSetting(this Layer layer) { foreach (var layerInfo in layer.AdditionalInfo) { VectorMaskSetting vectorMaskSetting = layerInfo as VectorMaskSetting; if (vectorMaskSetting != null) { return(vectorMaskSetting); } } return(null); }
public static PsdShape[] GetShapes(this Layer layer) { VectorMaskSetting setting = layer.GetVectorMaskSetting(); if (setting == null) { return(null); } List <PsdShape> result = new List <PsdShape>(); Vector2[] points = null; int pointIndex = 0; bool isClosed = false; foreach (var record in setting.PathDataRecords) { if (record is SubpathLengthRecord) { SubpathLengthRecord lengthRecord = record as SubpathLengthRecord; if (points != null) { throw new PsdInvalidException("Duplicate subpath length record"); } points = new Vector2[lengthRecord.BezierKnotCount]; pointIndex = 0; isClosed = lengthRecord.IsClosed; } else if (record is BezierKnotRecord) { BezierKnotRecord knowRecord = record as BezierKnotRecord; points[pointIndex++] = new Vector2(knowRecord.AnchorPoint.Horizontal, knowRecord.AnchorPoint.Vertical); if (pointIndex == points.Length) { result.Add(new PsdShape(points, isClosed)); points = null; pointIndex = 0; } } } return(result.ToArray()); }