ripose-jp / Memento

An mpv-based video player for studying Japanese
https://ripose-jp.github.io/Memento/
GNU General Public License v2.0
490 stars 21 forks source link

Improve popup dictionary styling #220

Open spacehamster opened 6 months ago

spacehamster commented 6 months ago

I'd like to see make improvements to Memento's dictionary definition display to bring it more in line with Yomitan. More specifically, I would like to see proper support for Yomichan's compact glossaries, compact tags and better support for structured-content dictionary data. This includes quite a few separate changes:

This is partially related to anki styling https://github.com/ripose-jp/Memento/issues/213 as many of these points also apply, but because Qt and Anki html rendering have very different capabilities, it seems appropriate they should be handled separately.

Example of yomitan and memento side by side for JMDict and Jitendex

image

I can have a go at making a pull request if you're interested.

ripose-jp commented 6 months ago

Some dictionaries (such as Jitendex) do not include <rp> tags in the ruby markup. Ruby rendering should be improved. Options include stripping <rt> tags entirely, highlighting ruby kanji and showing kana on hover as a tooltip, or rendering them inline with brackets.

All three of these options are desirable, though I like rendering them inline with brackets the least since it gets in the way of readability. Tooltips can be implemented in a hacky way by making tooltip'd text a link and using linkHovered() to show a tooltip.

Add support for links. Should links open up a new popup or use the existing popup?

By links, do you mean clicking a word opens a sub-search of sorts? I'm not against the idea. Opening it in a new popup would be the easiest thing to do since recursive search is already supported. You'd just have to listen for linkActiviated() and construct a new popup similarly to know recursive search does so. You can also make it work like clicking kanji in glossaries does, but that's probably more trouble than it's worth. Both are valid approaches.

Why is there a separate option for "Bullet Points" and "Line Breaks" in the Separate Glossary Entries setting? Structured Content allows <div> an <br> tags as well as arbitrary Unicode strings for <li> list markers. It seems like that choice should left to the dictionary.

Memento is older than Yomitan by several years. Yomitan has changed Yomichan's dictionaries quite a lot, which Memento hasn't kept up with. Very few of Yomichan's dictionaries used structured content, instead opting for plaintext. Most dictionaries used \n to separate different definitions under the same glossary. Older versions of Memento would turn these into bulleted lists. Calvin didn't like the unused white space to the left of bullets, so he made #64.

I believe the choice is mostly left to the dictionary if it's using structured content. These settings have an outsized effect on plaintext dictionaries.


If I didn't comment on something, it's because I'm okay with the change/improvement. If you want to work on some of them and make PR's, by all means go ahead.

spacehamster commented 6 months ago

By links, do you mean clicking a word opens a sub-search of sorts?

Structured content allows dictionaries to specify \<a> tags which can be either sub-search or links to external websites. Yomitan uses the same popup, but I have no issues with the way Memento currently opens a new popup for recursive search.

The structured content format looks like this

{
  "tag": "a",
  "lang": "ja",
  "href": "?query=日曜&wildcards=off",
  "content": [ <snip> ]
}

image

ripose-jp commented 6 months ago

Makes sense to me. I'd say reuse the code for recursive search since that's going to be really easy.

spacehamster commented 5 months ago

I'm not able to do anymore work on this for the foreseeable future. I'll post what I've done so far in case it's useful.

I've added

image

The approach uses flow layout for most of the changes. There are some layout issues with this method that I don't think can be completely eliminated, so I'm not really satisfied with it.

image

The fundamental problem is that the html subset used by QLabels is extremely limited and makes it difficult to do proper layout. Had time allowed, I had planned to evaluate the feasibility of litehtml (html+css engine with no renderer included) to do all the layout work and render either each term widget as a html document or the entire definition widget as a html document. The main potential issues I foresaw was performance and licensing. Litehtml is BSD-3 and there are qt bindings here licensed under LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0.

ripose-jp commented 4 months ago

Thanks for the work you've done. I'll look into integrating what you have.