Skip to content

layer.boundingBox() ignores references (Python) #4151

Closed

Description

@ctrlcctrlv

There's no good reason I can think of why this should happen.

The docs clearly state:

Returns a tuple representing a rectangle (xmin,ymin, xmax,ymax) into which the layer fits. It is not guaranteed to be the smallest such rectangle, but it will often be.

"Into which the layer fits" being the operative clause here.

By the way, this whole "will often be" cop-out makes no sense either and should be removed, both on the layer and contour levels.

Another blocker on #703. I will be fixing this one too....

Activity

  1. skef commented on Feb 11, 2020

    @skef
    Contributor

    I don't think this can be fixed reliably. A layer doesn't have any information about the glyph that contains it, and it may not be part of any glyph.

    In your shoes I would add an optional parameter to glyph.boundingBox to restrict the output to a given layer, which then calls SplineCharLayerFindBounds() directly.

  2. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    The references should be part of the PyFF_Layer object...I can see that they aren't...PyFF_RefArray somehow works? Or something...it's returned by PyFF_Glyph_get_layerrefs...

    Either way, references are part of layers, not part of glyphs, so... 😞

  3. skef commented on Feb 11, 2020

    @skef
    Contributor

    One could quibble about the API choices on a number of levels, but I think it's simplest to accept that the term layer in the python interface, when referring to the object type, is a misnomer. "contourSet" would be more accurate. Accepting the name problem makes the issues a lot more clear.

    References are still represented as per-layer, just not per layer.

  4. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    By the way @skef, I haven't worn shoes since I was 14 years old. 😹

    At some point you ask, "who am I kidding?"

    I get weirdly judgy when I see other people with my condition (& subtype) wearing shoes. Like, it's never going to look like I'm just a regular dwarf who happens to be sitting down. I think it's weird to have shoes that last 20 years.

    Yes I realize that was an expression but just some personal trivia. 🍸

  5. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    OK I understand I'll do it your way. Thanks for the advice, and the quick reply.

  6. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    By the way, it's bizarre that there's no glyph.xBoundsAtY and glyph.yBoundsAtX, right? Why is that stuff only on the layer and contour? It's just as relevant on the glyph!

  7. skef commented on Feb 11, 2020

    @skef
    Contributor

    Yeah ... that idiom just passed through my brain without reflection. The @ctrlcctrlv in my head is a weird amalgam of my contextless imagination from my earlier days here and a few videos and stills I've seen. I have a better grasp on your voice.

  8. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    😂 The @skef in my head is an orb of light that makes me a better C programmer through intense debates about side effects and stale pointers.

  9. skef commented on Feb 11, 2020

    @skef
    Contributor

    @ctrlcctrlv Yes, looking at the interface I agree it's strange those are omitted at the glyph level.

    The @skef in my head is an orb of light that makes me a better C programmer through intense debates about side effects and stale pointers.

    It's not a bad look -- I'll take it.

  10. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    It's not a bad look -- I'll take it.

    Now I'm wondering what you look like. Guess I'll have to ask @davelab6 😂

  11. skef commented on Feb 11, 2020

    @skef
    Contributor

    Now I'm wondering what you look like.

    I try not to think about it too much.

  12. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    @skef Do you have an idea for how to implement a reference-aware XBoundsAtY / YBoundsAtX at the glyph level (but which can also be constrained to a layer)? I'm all out of ideas so am coming to you. Making the bounding box work is done already.

  13. skef commented on Feb 11, 2020

    @skef
    Contributor

    Given that those two functions are currently only implemented for python it's going to be a little tricky.

    _SplineCharLayerFindBounds() is a good model for the basic process: Go through the references, then the splines (it uses _SplineSetFindClippedBounds() for that). Then it adjusts for a stroked layer, and then there is some post-processing. For the non-reference stuff you can call SSBoundsWithin() to get the bounds on the spline and then do the post-processing on the relevant dimension (x or y).

    The references are the more challenging part. Note struct refchar in splinefont.h: that's the structure you'll need to iterate through. Make a copy of the splines in the reference, transform them with transform in the structure, then process them with SSBoundsWithin like you would a normal SplineSet. Don't forget to delete your copies.

    I think copying and transforming the splines is the only safe way, given that the shape might be rotated or sheared. Note that if there are recursively defined references you'll have to unpack them. The model function for this is SCRefToSplines(). However, that function "unlinks" a reference and you just want to make a temporary transformed copy for processing.

    An alternative approach is to try to make a dummy char copy of the character of interest, call SCRefToSplines() on the references to do the work for you, process its splines with SSBoundsWithin(), and delete the dummy.

  14. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    Right...I basically came to that conclusion but was worried about SCRefToSplines...the way it works is mystifying, especially sigh once again vis à vis #4078, because its behavior is completely different on "multilayer" fonts which all COLR/CPAL fonts will be.

    I feel like everything we talk about comes back to the same few issues, time and time again. Not your fault, it's just that there are a few things really wrong with the codebase, and "multilayer" is sadly one of them.

  15. ctrlcctrlv commented on Feb 11, 2020

    @ctrlcctrlv
    MemberAuthor

    And like, why does SCRefToSplines only consider RefChar.layers[0]? Am I overthinking this or is this a huge problem in and of itself? But then again, when would a RefChar even have more than one layer? Why aren't those layers just regular SplineChar layers? struct reflayer has no associated documentation, and RefCharCreate only creates a single layer...and all the code seems to assume it'll only have one...which again...why have it at all then...

    And the thing is, I actually think that the non-multilayer part of SCRefToSplines would work fine on a multilayer font! So why are there two paths then? And so on.

  16. skef commented on Feb 11, 2020

    @skef
    Contributor

    And like, why does SCRefToSplines only consider RefChar.layers[0]?

    I think that's handling the potential special case of a reference to the other glyph's background layer. The actual "work" for non-multilayer glyphs seems to be done in SCRemoveDependent. But that's based only a glance.

    This is probably one of those cases where one needs to stare at the code a while to figure out what is doing what.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions