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

Save range of original text in glyph #110

Closed
wants to merge 2 commits into from
Closed

Conversation

LaurenzV
Copy link

@LaurenzV LaurenzV commented Aug 30, 2024

Okay, so I tried to look into #109 myself, and it actually was very straighforward (I tested it and it seems to work for my purpose), however:

  • I had to make Glyph not implement copy, since Range doesn't.
  • I'm a bit unsure why I had to add the text range in two places instead of one and I'm not sure it's 100% correct, so I would appreciate if someone could check this in detail to make sure I didn't mess up anything (assuming that you are okay with this change in the first place). :p

@dfrg
Copy link
Collaborator

dfrg commented Aug 30, 2024

Parley goes to great lengths to keep compact data structures in layout so I’d strongly prefer to not double the size of Glyph.

Given what you’ve done here, I wonder if something like this might work for you:

for run in line.runs() {
    for cluster in run.visual_clusters() {
        let range = cluster.text_range();
        for glyph in cluster.glyphs() {
            // here we have glyph and source range
            // but have to handle styles manually
        }
    }
}

This basically avoids GlyphRun entirely so you’d need to handle intra cluster style changes yourself. Each glyph has a style_index which refers to the slice returned by layout.styles().

@LaurenzV
Copy link
Author

Totally understandable, I'll give this a try later, thanks!

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.

2 participants