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

Make karaskel aware of style change when templating syllables #313

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

red5h4d0w
Copy link

For #312 with current caveat that it works only if the reset style tag is placed after the \k (ex: {\k20\rStyle Name}.

If the tags are placed in the other order (\rStyle Name\k20), then the reset style tag goes into the syl.text of the syllable preceding the style change, therefore giving incorrect style to the previous syllable.

@red5h4d0w
Copy link
Author

not sure if I should workaround the fact that the style change tag doesn't end up in the syllable where it happens at the karaskel level, or if I should move the style change tag to the syllable where it happens when parsing at the cpp level

@red5h4d0w
Copy link
Author

red5h4d0w commented Feb 2, 2025

other caveat, it doesn't work for furi styles at the moment since furi.text does not contain tag info

edit: now it uses parent syllable style. Don't think I can do much better from the lua side

@petzku
Copy link
Contributor

petzku commented Feb 2, 2025

note that this would not be entirely sufficient to make karaskel "aware" of style changes. line.* properties, such as line.width and line.left are still computed without considering the inline override.

with current caveat that it works only if the reset style tag is placed after the \k (ex: {\k20\rStyle Name}.

arguably, this is "sensible" behavior: \k20 means "everything from here onwards is part of a syl with duration 20cs". while i definitely agree it's not useful, aegisub does actually reformat \k tags into their own separate tag blocks in this case, which i would consider sufficiently clearly signaling "this applies to the previous syl (even though it has no text), not the next one".

{\k167}foo {\k166}bar {\rfoo\k167}zsdf

the above becomes the following if committing any changes (including no changes, just pressing the commit button) to ktiming:

{\k167}foo {\k166}bar {\rfoo}{\k167}zsdf

I wrote all that before realizing I had misunderstood you somewhat. karaskel's behavior on splitting syls like this is fairly reasonable, but it should be fairly simple to check if the reset tag is actually at the end of the syl as well to work around this:

		syl.style = cur_style

		local _, reset_end, style_reset_name = syl.text:find("%{.*\\%r([^}\\]+)")
		if style_reset_name and styles[style_reset_name] then
			cur_style = styles[style_reset_name]
			-- match does not include final }
			if reset_end + 1 < #syl.text then
				syl.style = cur.style
			end
		end

@red5h4d0w
Copy link
Author

note that this would not be entirely sufficient to make karaskel "aware" of style changes. line.* properties, such as line.width and line.left are still computed without considering the inline override.
Yes this is the case. Computing line properties with style changes is not something I am aiming for. I should probably rename this PR.

Thanks for the code block. It does exactly what I meant by working around the "style change tag belonging to previous syllable" issue from the lua side.

The other solution would have been to change the way syl are split (from the c++ side) but maybe it's less reasonable to flip around blocks during the parsing...

@red5h4d0w red5h4d0w changed the title Draft: Make karaskel aware of style change Make karaskel aware of style change when templating syllables Feb 2, 2025
with caveat that it works only if the reset style tag is placed after the \k (ex: {\k20\rStyle Name}
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