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

How to get the type of knot in subpath of shape layer? #402

Open
Tunanzzz opened this issue May 6, 2024 · 3 comments
Open

How to get the type of knot in subpath of shape layer? #402

Tunanzzz opened this issue May 6, 2024 · 3 comments

Comments

@Tunanzzz
Copy link

Tunanzzz commented May 6, 2024

now, i can get the type of subpath, and the number of subpath in a shape layer by this code.
for subpath in paths: anchors = [(knot.anchor[1] * layer.width, knot.anchor[0] * layer.height) for knot in subpath]
By this way, I can the all the knot's anchor, but I don't know the type of knot.
from GPT, svg's knot has these types:
In SVG (Scalable Vector Graphics), the element is used to define shapes. The element contains a d attribute, which defines the shape of the path. The shape of the path is composed of a series of commands and parameters.
The commands can be one of the following:

  1. M/m (moveto): Move the pen to the specified coordinates.
  2. L/l (lineto): Draw a straight line from the current coordinates to the specified coordinates.
  3. H/h (horizontal lineto): Draw a horizontal line from the current coordinates to the specified x-coordinate.
  4. V/v (vertical lineto): Draw a vertical line from the current coordinates to the specified y-coordinate.
  5. C/c (curveto): Draw a cubic Bézier curve.
  6. S/s (smooth curveto): Smooth cubic Bézier curve.
  7. Q/q (quadratic Belzier curve): Draw a quadratic Bézier curve.
  8. T/t (smooth quadratic Belzier curveto): Smooth quadratic Bézier curve.
  9. A/a (elliptical Arc): Draw an elliptical arc.
  10. Z/z (closepath): Close the path.

I read the code of ShapeLayer.vector_mask.paths, but can't find this info, could you help me?
Thanks for your wonderful work !!!

@Tunanzzz
Copy link
Author

Tunanzzz commented May 6, 2024

I can get the type of shape from
`def origination(self):
"""
Property for a list of live shapes or a line.

    Some of the vector masks have associated live shape properties, that
    are Photoshop feature to handle primitive shapes such as a rectangle,
    an ellipse, or a line. Vector masks without live shape properties are
    plain path objects.

    See :py:mod:`psd_tools.api.shape`.

    :return: List of :py:class:`~psd_tools.api.shape.Invalidated`,
        :py:class:`~psd_tools.api.shape.Rectangle`,
        :py:class:`~psd_tools.api.shape.RoundedRectangle`,
        :py:class:`~psd_tools.api.shape.Ellipse`, or
        :py:class:`~psd_tools.api.shape.Line`.
    """`

but if it's a just a Invalidated curve, the knots have its own type, how can i get it?

@kyamagu
Copy link
Contributor

kyamagu commented May 6, 2024

Check this document. psd-tools follows this spec to parse information
https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/

@Tunanzzz
Copy link
Author

Tunanzzz commented May 7, 2024

Check this document. psd-tools follows this spec to parse information https://www.adobe.com/devnet-apps/photoshop/fileformatashtml/

Thanks for your answer, i get the path by
`def _generate_symbol(path, width, height, command="C"):
"""Sequence generator for SVG path."""
if len(path) == 0:
return

# Initial point.
yield "M"
yield path[0].anchor[1] * width
yield path[0].anchor[0] * height
yield command

# Closed path or open path
points = (
    zip(path, path[1:] + path[0:1]) if path.is_closed() else zip(path, path[1:])
)

# Rest of the points.
for p1, p2 in points:
    yield p1.leaving[1] * width
    yield p1.leaving[0] * height
    yield p2.preceding[1] * width
    yield p2.preceding[0] * height
    yield p2.anchor[1] * width
    yield p2.anchor[0] * height

if path.is_closed():
    yield "Z"`

but i cant get the fill color of the shape layer, how can i get it?

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

No branches or pull requests

2 participants