baskerville / plato

Document reader
Other
1.23k stars 102 forks source link

Properly deal with Furigana #360

Open BMagnu opened 3 months ago

BMagnu commented 3 months ago

Closes #283.

Properly handles <ruby> and underlying <rt> tags. This is accomplished by putting parsed overset data into the rendering style of the main text. When splitting the main text into individual boxes, ruby characters are distributed as well as possible. The boxes being rendered can potentially expand in width if the overset text is wider as the main text.

Example:

ksnip_20240417-161255

Of which, for the first phase, the epub looked as follows:

<p> <ruby>空<rt>そら</rt></ruby>は<ruby>青<rt>あお</rt></ruby>くて、<ruby>太<rt>たい</rt>陽<rt>よう</rt></ruby>がじりじりと<ruby>照<rt>て</rt></ruby>りつける。</p>
baskerville commented 2 months ago

Also, it would seem that you don't have to do the splitting, because it shouldn't occur. You just have to prevent the splitting of the base characters.

BMagnu commented 2 months ago

Yes, the ideal solution would be to push everything in the ruby block (which should be always the entirety of the InlineMaterial::Text) into a single ParagraphElement::Text. I wasn't entirely sure how the renderer deals with that though, in case that this element gets too wide for the remaining line, or in the worst case, wider than an entire line. Is it sensible to have an if at the start of the InlineMaterial::Text handler, and say that if it has ruby, then just ignore everything and push the entirety of the text as a ParagraphElement::Text?

Edit: Testing it, this seems to work. If you agree that this is the way to do it, I'll push that change