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

FR: Japanese vertical formatting (tategaki) support #11469

Open
spoisseroux opened this issue Feb 17, 2024 · 35 comments
Open

FR: Japanese vertical formatting (tategaki) support #11469

spoisseroux opened this issue Feb 17, 2024 · 35 comments

Comments

@spoisseroux
Copy link

As far as I'm aware of KoReader does not yet have tategaki (縦書き) support for Japanese texts. Tategaki is vertical formatting for Japanese texts.

A toggle to enable tategaki for Japanese texts would be amazing, filling a gap that is really only filled by ttu reader w/ yomichan at the moment. It would be a really nice as koreader already has great Japanese dictionary ability similar to yomichan.

Reading Japanese texts in a horizontal layout can become very tiring, so I think this feature would help make koreader's Japanese even more comprehensive.

@Frenzie
Copy link
Member

Frenzie commented Feb 17, 2024

Support for vertical text is unfortunately unlikely to show up soon. You might be able to use a program like calibre to convert such EPUBs to PDF if desired.

Not sure we'll ever support that (unless we include a 3rd epub engine :)

crengine is really from the core made to handle horizontal text in the left to right direction: paragraph splitting, line layout, hyphenation, vertical stacking of rectangles and splitting to make pages, screen coordinate to HTML node (for text selection/link hitting) is scanning from left to right of these rectangles... that I don't even see how vertical text layout could fit in, without implications everywhere... (and even right-to-left text layout seem complicated).

As for the MuPDF epub engine: https://bugs.ghostscript.com/show_bug.cgi?id=695924#c16 : We are not likely to ever support vertical writing in the EPUB viewer.
#4353 (comment)

@Bluemoondragon07
Copy link

Bluemoondragon07 commented Feb 27, 2024

Perhaps the paragraphs wouldn't even need to be render vertically with css/html. Maybe, we could just have the engine rotate the font, so that it is sideways. Then, we could rotate the entire view and—viola, vertical text.

We might need to rotate the UI as well to maintain the illusion of the correct orientation, though.

To see what I mean, pay attention to how Moon+ Reader on Android handles vertical text. Change the app language to Japanese and turn on vertical text. It just rotates the font, basically. The only thing the app forgets to do is rotate the UI.

@Frenzie
Copy link
Member

Frenzie commented Feb 28, 2024

It just rotates the font, basically.

And it doesn't look completely horrible? You can probably experiment with some custom font in that case. Chances are they already exist.

@poire-z
Copy link
Contributor

poire-z commented Feb 28, 2024

That's what I was going to suggest: making your own custom font.
Given that we won't support vertical text, and we won't go with such hacks in our code who would just render half bad, you are left with having the font do that hackish work without us needing to know :)

OpenType fonts are very powerful, they can have some rules (and code maybe) to do stuff to their glyphs.
ie. pick a font feature rarely used, ie "UNIC", that maps to font-variant: unicase - so you can use a style tweak * {font-variant: unicase]. Pick your favorite CJK font, and modify it so when requesting the UNIC feature, it does that glyph rotation (+ glyph positionning if needed).

I have no idea how this works in OpenType and what tools to use - but I would definitely find that investigation fun if I wanted to get vertical text for me :)
Didn't find much with https://www.google.com/search?hl=en&num=25&q=opentype+rotate+glyphs+vertical+text.

@Bluemoondragon07
Copy link

I never considered using that method for Opentype fonts. I did manually rotate glyphs in ttf fonts with Fontforge a while back. And then I just rotate the screen when I use the rotated font in KOreader.

The problem, though, is that I can't rotate the UI as well, and I have to keep turning my device this way and that when I use the dictionary.

Some readers, like Librera, with custom CSS applied, writing-mode: vertical-rl; text-orientation: upright; will rotate the glyphs automatically, even if the vertical display does not work.

If KOreader can use this CSS to just rotate the glyphs, I don't think the result would be more "bad" or "horrible" than Librera's, which looked standard to me.

And then, maybe the UI can be rotated without rotating the view with the text, or the view with the text can be rotated by itself. I'm not sure how KOreader's whole layout works, but maybe it is possible?

Otherwise, is there some sort of User Tweak that can rotate the UI? It's gotta be possible, right? Or at least to rotate the modals to make the dictionaries and highlighting useful in this mode?

@poire-z
Copy link
Contributor

poire-z commented Feb 28, 2024

Some readers, like Librera, with custom CSS applied, writing-mode: vertical-rl; text-orientation: upright; will rotate the glyphs automatically, even if the vertical display does not work.
If KOreader can use this CSS to just rotate the glyphs, I don't think the result would be more "bad" or "horrible" than Librera's, which looked standard to me.

I don't know how other softwares do that, may be they use real web browser web rendering engines, that can do proper vertical text.
We don't and we won't, and all we could do would just be a hack, nothing proper, nothing to be proud of.

But you could :)

And then, maybe the UI can be rotated without rotating the view with the text, or the view with the text can be rotated by itself. I'm not sure how KOreader's whole layout works, but maybe it is possible?
Otherwise, is there some sort of User Tweak that can rotate the UI? It's gotta be possible, right? Or at least to rotate the modals to make the dictionaries and highlighting useful in this mode?

I looked if it would be possible to rotate some widgets, but no, it would be complicated and kludgy.
But it felt it would be a lot easier to just rotate the page, and keep the UI as-is.
Felt challenging, so I had a try.
Here's a user-patch, to be dropped in your koreader/patches/ (to be created if it doesn't exist):
2-cre-rotate-japanese-book.lua.txt

If the book is set to Typography rules: Japanese, it hacks a few credocument methods to pretend we draw on HxW instead of WxH, and convert x/y coordinates in a few getSomethingFromScreenPosition methods, so at least work lookup, highlighting and following links work (some other stuff like marks in the margins aren't updated). It also switches "invert reading order" so tap on the left side goes forward - some side effects in the ToC at it is made RTL :/) (Feel free to read the code and comment out stuff or add new stuff.)
But enough to test how this would look with your twisted font .

I have no idea how natural it will feel to Japanese readers (with rotated glyphs), but it looks quite neat in 2-columns 2-rows mode :):

image

The nice thing with this trick is that all the vertical lines stuff feel proper: justification, underlining, line-heights ensured...
Dunno about how numbers and English text not being rotated back would feel.
Images are also not rotated.
And all the CSS left/right/top/bottom margin/padding stuff is then messed up. Quite curious how this would do on some real publisher vertical-text book with some fancy formatting :)

As it had been previously the case when I worked on having RTL for Arabic and Hebrew, my mind is totally twisted after seeing highlights made top to bottom and page turning the other way around - I will need a few hours to recover and be able to read again my horizontal books :)

@Frenzie
Copy link
Member

Frenzie commented Feb 28, 2024

I have no idea how natural it will feel to Japanese readers (with rotated glyphs), but it looks quite neat in 2-columns 2-rows mode :):

What underlines should look like (if like anything at all) is one of the things I actually wondered about.

@Bluemoondragon07
Copy link

@poire-z, the patch works great! I don't know Lua, but looking at the code and reading your explanation makes it sound complicated. And you did all of that fast. Like, woah.

20240228195000

Finally, I can read comfortably with my messily rotated fonts in my favorite reader! I didn't think it was possible—thank you so much.

@MyK00L
Copy link

MyK00L commented Mar 12, 2024

@Bluemoondragon07
If you want rotated fonts that are not messy, I made a script for it 😄

@Bluemoondragon07
Copy link

@MyK00L

Wow, thank you so much. I will be using this script a lot! Now I don't have to click random options in FontForge :)

@smarliecy
Copy link

@Bluemoondragon07
If you want rotated fonts that are not messy, I made a script for it 😄

Thank you for the script!

@offset-torque
Copy link

If there is a usable solution coming out of this discussion, I can add it to the user guide so other users can benefit too. But I need someone (developer or user) to write step-by-step instructions because this is all...how to say... Japanese to me.

@Bluemoondragon07
Copy link

@offset-torque

Basically, to achieve tategaki (vertical Japanese), one must follow these steps:

  1. Rotate a font or find a rotated font. This can easily be done with FontForge, especially with the help of @MyK00L' s script.
  2. Apply @poire-z's user patch to fix the orientation for vertical text.

The same can be done for vertical Chinese with a rotated Chinese font and modifications to the user patch to change the criteria for the document language to be set to Chinese instead of Japanese.

@poire-z
Copy link
Contributor

poire-z commented Mar 19, 2024

@offset-torque : depends if you are writting a User Guide - or the Hitchhacker Guide to KOReader ? :)
(I would personally not mention it: it's a hack, it can cause disapointment, or bring more comments and requests to hack more stuff, ie non-rotated images. You don't mention (I hope) the flat library patch :))

@Frenzie
Copy link
Member

Frenzie commented Mar 19, 2024

[*] By the application of this patch on ancient and powerful eldritch software you accept that you may become perpetually doomed to be dissatisfied by non-rotated images.

@offset-torque
Copy link

Ok then, keep your secrets @poire-z :)

I agree, in this case adding it to the user guide might make it look kinda "official" and open the door to more requests and fixes. We can skip this.

@poire-z
Copy link
Contributor

poire-z commented Mar 22, 2024

Ok then, keep your secrets

I'll keep mine, but I'm curious about others' :)
I have a few questions for vertical text readers, some for my culture, others for technical thoughts.

I have read https://www.learnwitholiver.com/japanese/blog-post-2.
I don't need any explanations about how it is supposed to look, this is quite well documented, ie. https://fantasai.inkedblade.net/style/discuss/vertical-text/paper.
I'd just like to know how not doing it well with this patch put us on a scale of 1 to 10 (1 being KOReader classic, 10 being super proper vertical text) :)

My questions:

A1 Can Japanese or Chinese readers read any text horizontal or vertical with the same ease ? Can some people just not adapt to one or the other?
A2 Would you read any CJ (Chinese or Japanese) document vertically if possible, ie. Wikipedia articles as shown in a screenshot above ?
A3 Would you then switch to horizontal if the book contains code or math formulas, or many English snippets?

Publishers can specify in an EPUB that this EPUB book is to be rendered vertical.
B1 Is this really a publisher decision for some specific books, but not others ? Or does it feel more like just a suggestion ?
B2 Or should it somehow be a reader decision, to prefer reading a same book with horizontal or vertical text?
B3 How do other reading softwares doing good vertical layout do: just following the publisher specifications, or allowing the user to switch between horizontal or vertical mode ?

With the above patch and your font with rotated glyphs (CJ glyphs only I assume):
C1 How are you bothered with the puncuation glyph squares width (or "height" when vertical) reduction, and is there some issues with their rotation and the way KOReader "cuts" the squared glyph to make it a narrower rectangle? (cf. all the things mentionned in #6162 (comment) and followup per-language posts).
C2 How it is with latin/western text and numbers not being rotated ? The "specs" mentions that abbreviations should have glyph upright (like the CJK glyphs), but largers bit of text like words or quotes can/should be laid dows as they are now, so one has to tilt his head or her device to read the words.
C3 How does ruby look and feel? (I haven't look how it's supposed to look when vertical, but probably not how we have it look :))
C4 How do in-page footnotes look and feel (as a vertical column on the right :) it feels like it would look super odd).
C5 How do popup footnotes look and feel (popping at bottom with horizontal text) ?

If you have seen any fancy vertical text EPUB, with images, blocks of text with different font size and indentation/side-margins, alignment, epigraphs...
D1 How is it when read with a normal KOReader, so with horizontal text ? Is it normally readable ? Or are there a lot of blank and too many rendering issues for it to be comfortable to read?
D2 How is it with KOReader, this patch and a rotated font ? I expect none of the previous issues are fixed, but I'd like to know how much % of the unconfortableness is gone with it, and how much % are left and bearable.
D3 Do such books use margin/padding-left/right/top/bottom, or the newest margin-block-start/end and margin-inline-start/end (that KOReader/crengine does not support) ?
D4 Do you have to enable some specific style tweaks (ie. Ignore horizontal/vertical padding/margin or Left aligned most text) to get things better?

Thank you for your answers :)

@rukit24
Copy link

rukit24 commented Mar 23, 2024

@offset-torque

Basically, to achieve tategaki (vertical Japanese), one must follow these steps:

  1. Rotate a font or find a rotated font. This can easily be done with FontForge, especially with the help of @MyK00L' s script.
  2. Apply @poire-z's user patch to fix the orientation for vertical text.

The same can be done for vertical Chinese with a rotated Chinese font and modifications to the user patch to change the criteria for the document language to be set to Chinese instead of Japanese.

Can you explain detail for me how to rotation with this scripts in Font Forge. I install fontforge and choosing my Tff Kyokasho and the click Execute scrips and then go to github link of scrips and paste the scrips in main.py to execute box in fontforge. Then it crash.

@MyK00L
Copy link

MyK00L commented Mar 25, 2024

@rukit24 my script is a python script using the fontforge library, not a fontforge script.
If you have issues with it, please post on its issues page, and not here unless it's relevant.
p.s. A bug that would cause some glyphs, like fullwidth latin letters, not to be rotated, is now fixed.

@MyK00L
Copy link

MyK00L commented Mar 26, 2024

@poire-z

I have a few questions for vertical text readers

Note:
I'm talking about japanese since it's the only language I can read with vertical text.
Also, I'm not from Japan, so I'm not sure how accurate I can be in regards to culture.

  • A1: I've never heard of anyone having difficulties with one or the other.
  • A2: I would not mind either direction, but I'd rather read it the way it was written in.
  • A3: Horizontal would be better.
  • B1: I think it's mostly a publisher decision
  • B2: If it's doable, I don't see why not make the user choose
  • B3: I don't know many, but the reader in Aozora Bunko gives you the option to switch.
  • C1: It looks fine
  • C2: I think text that should be upright is usually written in fullwidth characters, so it should be upright in rotated fonts, but sometimes it's made to be upright with css. When text is not upright I find it hard to read.
  • C3: ruby is good (or as good as it is in horizontal).
  • C4: I see them as a vertical column on the left, which I think is good.
  • C5: idk how to make/find one. According to your description, it should be fine.
  • D: I haven't seen epubs with fancy spacing.

Some other notes:

  • With rotated fonts the characters are not rendered in a grid-like manner anymore, but it's probably because of how I rotate the fonts, so I'll have to look into that.
  • Aside from that, the sideways images, and the occasional sideways english text or numbers, I think it's pretty much how you would expect good vertical text.

ps I think the progress bar going from left to right, when the pages go from right to left, is weird.

@plateaukao
Copy link

@poire-z

As a Chinese native speaker who happens to read Japanese and Korean novels, I'll also add my replies too to your questions:

A1 Can Japanese or Chinese readers read any text horizontal or vertical with the same ease ? Can some people just not adapt to one or the other?

Yes, we could read text in either horizontal or vertical way; however, users have preference to read in vertical or horizontal. In Japan, most novels are published (digital or physical) in vertical reading way. So it's common that people used to read books in vertical. And for Chinese, it depends since there are a lot of books published in horizontal too. Young people are used to horizontal reading because of the nature of internet. However, as a pretty old-fashion reader, since most old novels were also published in vertical reading, I tend to read Chinese content in vertical too. That's more of a habit instead of a hard requirement for most people.

So, being able to read epub from horizontal to vertical is a big sale point (or a must have feature) for Eink device manufacturers (at least in Taiwan).

A2 Would you read any CJ (Chinese or Japanese) document vertically if possible, ie. Wikipedia articles as shown in a screenshot above ?

For novels, it's better to read in vertical; however, for books like, programming books, technology books, or books involved with more western content inside, it's better to read in horizontal.

A3 Would you then switch to horizontal if the book contains code or math formulas, or many English snippets?

Yes. For this kind of books, we read by default in horizontal; and I think no one will try reading in vertical in this scenario.


Publishers can specify in an EPUB that this EPUB book is to be rendered vertical.
B1 Is this really a publisher decision for some specific books, but not others ? Or does it feel more like just a suggestion ?

Yes, I guess it's publishers' decision. It's usually not only configuring in CSS, but also considering how the content layout should be done when it contains images.

B2 Or should it somehow be a reader decision, to prefer reading a same book with horizontal or vertical text?

it's also reader's decision too. when publisher did not generate their books in vertical, it's always good to allow users being able to make it vertical in reader apps.

B3 How do other reading softwares doing good vertical layout do: just following the publisher specifications, or allowing the user to switch between horizontal or vertical mode ?

In Taiwan, most Eink devices we sell here supports reading epubs in vertical, no matter the original settings (four local Eink device brands, all of them have its own online bookstores).


With the above patch and your font with rotated glyphs (CJ glyphs only I assume):
C1 How are you bothered with the puncuation glyph squares width (or "height" when vertical) reduction, and is there some issues with their rotation and the way KOReader "cuts" the squared glyph to make it a narrower rectangle?

It bothers a lot; but the system rotation bothers more. With your patch, it's much better now. :) As for the rotated glyphs, some fonts are better converted, so the punction can be still in the middle of the glyph.

C2 How it is with latin/western text and numbers not being rotated ? The "specs" mentions that abbreviations should have glyph upright (like the CJK glyphs), but largers bit of text like words or quotes can/should be laid dows as they are now, so one has to tilt his head or her device to read the words.

latin/western text, usually we leave them as what they are (no matter they are long or short). But for some delicated-handled epub files, the number-bulleted numbers can also be shown in vertical too.

C3 How does ruby look and feel? (I haven't look how it's supposed to look when vertical, but probably not how we have it look :))

ruby looks great.

C4 How do in-page footnotes look and feel (as a vertical column on the right :) it feels like it would look super odd).

how to show them?

C5 How do popup footnotes look and feel (popping at bottom with horizontal text) ?

popup footnotes looks fine at the bottom of the screen. :)


If you have seen any fancy vertical text EPUB, with images, blocks of text with different font size and indentation/side-margins, alignment, epigraphs...
D1 How is it when read with a normal KOReader, so with horizontal text ? Is it normally readable ? Or are there a lot of blank and too many rendering issues for it to be comfortable to read?

hmm.. in fact, I haven't seen fancy vertical text EPUBs with images; most of my Japanese or Chinese books are novels. If they come with images, although the image is not rotated, I think it's bearable. :)

S__6340623

D2 How is it with KOReader, this patch and a rotated font ? I expect none of the previous issues are fixed, but I'd like to know how much % of the unconfortableness is gone with it, and how much % are left and bearable.

10% unconfortableness, if the 90-degree font is not handling punction position well

D3 Do such books use margin/padding-left/right/top/bottom, or the newest margin-block-start/end and margin-inline-start/end (that KOReader/crengine does not support) ?

not sure. usually I prefer setting margins myself (no matter the text is in horizontal or vertical).

D4 Do you have to enable some specific style tweaks (ie. Ignore horizontal/vertical padding/margin or Left aligned most text) to get things better?

no. I don't have to. :)

@poire-z
Copy link
Contributor

poire-z commented Apr 21, 2024

Thanks for the feedback!

It bothers a lot; but the system rotation bothers more.

Not sure I understand what you mean by "system rotation". Do you mean that without that patch, you had to rotate the device (and so, menu and other popup were rotated and you have to rotate back the device to use them) ?

the number-bulleted numbers can also be shown in vertical too.

Didn't think about them :) Indeed, these numbers could look odd and bothering:
image

C4 How do in-page footnotes look and feel (as a vertical column on the right :) it feels like it would look super odd).

how to show them?

Via Style tweaks> In-page footnotes> - depends on the EPUB having footnotes and proper HTML/EPUB attributes annoucing bits of text are footnotes - not all EPUBs have that.
At least, on our Wikipedia Save as EPUB EPUBs, the "In-page Wikipedia footnotes" tweak should work:

image

hmm.. in fact, I haven't seen fancy vertical text EPUBs with images

Not only images, but any fancy spacing, ie. at the start of a chapter, with a title centered with various amount of spacing above and below, and some epigraph right aligned taking 30% of the screen width... could look odd if made vertical while the CSS mentions stuff like margin-top: 2em actually working as margin-right, stuff like that.

not sure. usually I prefer setting margins myself (no matter the text is in horizontal or vertical).

That's for the outer margins. What I mentionned in the previous paragraph are margin/padding set by the publisher for cosmetic reasons.

The punctuations looks quite alright on the single line of your screenshot :)
image
Btw, you may be the first Taiwanese reader I've seen commenting here since I made improved CJK typography, where I have to improvise a bit on the Traditional Chinese part :)
Curious how that does work for you, and it it improved things. (I hope it is well, not keen on having to dive into all that again :))

@plateaukao
Copy link

@poire-z

Thanks for your quick reply.

Here's screenshot showing how I rotated screen after applying 90-degree-rotated font (before I found your patch).
It's much pain when I try use dictionary and translate feature. I even implemented a feature in EinkBro (a browser for Eink device) to rotate the translation dialog, particularly for this scenario. :p
I found that it's possible to define multiple actions for touch system area; so, I configured bottom right area action to change 90-degree font and rotate the screen 90 degree at the same time. (and long press to rollback the effect)
image

Yes, the numbers are not looking good for in-page footnote, but that's how most reader apps support if they offer "vertical reading" feature for original horizontal layout books. So, it's acceptable.

image

you mean indentation like this in front of each paragraph? it looks just fine.


As for the punctuation in my screenshot, those fonts are especially taken care of commas and period, that's why they look good. People who prefer vertical readings did some effort to make sure any workaround is utilized. :) (I have some 90-degree rotated fonts that does not show punctuations in the middle; I seldom use them though).

Thanks for showing me more info related to CJK typography, I'll have a look at the links, and feedback to you later.


By the way, currently, the only issue I found with your patch is that, when setting highlight style to underline, it will only show underline for the lowest single character. I guess it also need to override some functions to provide rotated coordinate so that it could be correctly drawn. However, it's an easily avoidable issue since I can just use Lighten or Invert style instead. Thanks for the patch again. It really makes Koreader more useful for me (and many other CJK readers. :) )

@poire-z
Copy link
Contributor

poire-z commented Apr 21, 2024

you mean indentation like this in front of each paragraph? it looks just fine.

No, I meant layout like this in horizontal books (the spaces in yellow are publisher's margins/paddings)
image
when rotated with the patch, all is fine because we actually keep rendering it horizontally:
image
(I'd like to see a vertical EPUB that does this kind of simple first-page-of-a-chapter layout.)

But an original vertical layout book, when wanting to ensure these spacing, may use margin-right (in which case, we'll consider it as real margin-right and the title will be pushed to the side) or margin-block-start (which means top in LTR or right in vertical RTL) that we don't support. I just don't know how they are made as I have no such book :)

So, you mean we're not the only software that would be using this trick of just rotating the buffer? Do other softwares (not using real web engine) do more than that, by rotating & fine positionning the glyphs themselves, without needed tweaked fonts?

By the way, currently, the only issue I found with your patch is that, when setting highlight style to underline, it will only show underline for the lowest single character. I guess it also need to override some functions to provide rotated coordinate so that it could be correctly drawn.

Indeed :
image

This is drawn by the frontend code, so indeed it would need some patching. I think it would be the same function I tweaked for #11581 (comment) .
As you can code, I let you have fun :)

@plateaukao
Copy link

@poire-z
After second look, I guess the rect is correct for highlight; just the drawing way should be overrided from horizontal to vertical in following funciton for style underscore and strikeout.

function ReaderView:drawHighlightRect(bb, _x, _y, rect, drawer, draw_note_mark)

@plateaukao
Copy link

plateaukao commented Apr 21, 2024

@poire-z
Thanks for the link, I'll work on the highlight part.

The margins are gone from what I tested (see figure below).
left is koreader with patch, and right is a book on Kindle Oasis. Although the filed is converted from azw3 to epub. When it's displayed in horizontal in epub format, the margin is already gone. The output is not exactly the same as kindle's azw file, but it's acceptable.
image


Other reader apps I know, they just use web engine, so they can support css vertical style easily. for the punctuation, I guess people just replace half-width ones with full-width one, so they are always in middle.

@plateaukao
Copy link

DONE~

In case anyone need the patch that supports underscore style of highlight feature, here's the gist for it: https://gist.github.com/plateaukao/e546f8226727acb3a25597e572ef39fc

screenshot:
image

@equwal
Copy link

equwal commented May 3, 2024

For anyone wondering why that excellent patch isn't working, it's because the file needs to be renamed from .lua.txt to .lua.

@yuanshuai0217
Copy link

@poire-z

A1 Can Japanese or Chinese readers read any text horizontal or vertical with the same ease ? Can some people just not adapt to one or the other?

Nowadays everyone should be used to horizontal texts. Those not familiar with vertical texts may find it slightly difficult to read.

A2 Would you read any CJ (Chinese or Japanese) document vertically if possible, ie. Wikipedia articles as shown in a screenshot above ?

I prefer to read Traditional Chinese and Japanese literatures or sociology books in vertical mode.

A3 Would you then switch to horizontal if the book contains code or math formulas, or many English snippets?

Math books and books with much English are usually horizontal. MathML used in epub doesn't seem to have support for vertical typesetting. I think even nerd guys from (La)TeX don't have a proper solution for this.

Publishers can specify in an EPUB that this EPUB book is to be rendered vertical.

B1 Is this really a publisher decision for some specific books, but not others ? Or does it feel more like just a suggestion ?

As it is defined by the publisher in CSS (e.g. writing-mode: vertical-rl;), it shall be a publisher decision. Many books also use CSS styles (as mentioned later) that will not be displayed well in horizontal mode.

B2 Or should it somehow be a reader decision, to prefer reading a same book with horizontal or vertical text?

This is a consideration for ebook readers: to obey the styles defined by publisher and display them as-is, or to modify them for consistency and customization? I have to say, KOreader is good at both.

B3 How do other reading softwares doing good vertical layout do: just following the publisher specifications, or allowing the user to switch between horizontal or vertical mode ?

Kindle will follow the specifications in book and not allow user to set them. Vertical-lovers have to edit book file if possible.

With the above patch and your font with rotated glyphs (CJ glyphs only I assume):
C1 How are you bothered with the puncuation glyph squares width (or "height" when vertical) reduction, and is there some issues with their rotation and the way KOReader "cuts" the squared glyph to make it a narrower rectangle? (cf. all the things mentionned in #6162 (comment) and followup per-language posts).

It looks fine for me. And I think this is what JLREQ perfers.

C2 How it is with latin/western text and numbers not being rotated ? The "specs" mentions that abbreviations should have glyph upright (like the CJK glyphs), but largers bit of text like words or quotes can/should be laid dows as they are now, so one has to tilt his head or her device to read the words.

Reading rotated Latin words can be difficult, but with some experience this won't matter much.

Full-width numbers and letters (Unicode FF00-FFEF) should be used if they are expected to be upright. However, this can be problematic for other scripts like Cyrillic and Greek (In many Japanese fonts, these letters are always full-width version).

Plateaukao mentioned that counters in lists should be shown in vertical, which can be implemented through counter-style: fullwidth-decimal in css.

C3 How does ruby look and feel? (I haven't look how it's supposed to look when vertical, but probably not how we have it look :))

I've found a bug that effect both horizontal and vertical mode: Alignment of ruby text is affected by -epub-text-align-last · Issue #11771. Besides that, everything looks fine for me.

C4 How do in-page footnotes look and feel (as a vertical column on the right :) it feels like it would look super odd).

It looks fine for me.

Some printed books put footnotes at the bottom of page (like sidenotes in horizontal books after rotated), but as literature books generally have few notes, this could be space-wasting.

C5 How do popup footnotes look and feel (popping at bottom with horizontal text) ?

It looks fine for me.

If you have seen any fancy vertical text EPUB, with images, blocks of text with different font size and indentation/side-margins, alignment, epigraphs...

Due to software restriction, in Kindle, many vertical-typesetting books with complicated layout may just display pages as pictures. The book I'm using as example is 変な家 (Hen na Ie; A Strange House) by 雨穴 (Uketsu), which can be found at……uh, you know where.

D1 How is it when read with a normal KOReader, so with horizontal text ? Is it normally readable ? Or are there a lot of blank and too many rendering issues for it to be comfortable to read?

For hanging indent, the book use a combination of text-indent and padding-top, like (a better implementation may be text-indent: 4em hanging):

text-indent: -4em;
padding-top: 4em;

Which works well in vertical mode of modern browser (they will counteract each other). However, in horizotal mode of KOreader, it will become blank area on the top, and texts going out of left bound. Other paddings and margins also have similar problem.

What's more, the publisher adds blank area to top and bottom of pictures to make them all have identical height. When displayed horizontally, this will become redundant.

There's another trivial problem: the book uses -epub-text-emphasis-style: filled sesame, which will display a dot on top (or right) of every kanji and kana (reference: JLREQ 3.3.9). it seems to be not supported yet.

D2 How is it with KOReader, this patch and a rotated font ? I expect none of the previous issues are fixed, but I'd like to know how much % of the unconfortableness is gone with it, and how much % are left and bearable.

Same as above-mentioned problems, just rotated.

Those out-of-bound texts are detrimental to reading, while it affect both vertical and horizontal mode.

Some part of the book have bar over top (as border-style: solid none none none), which is displayed on right with the patch.

D3 Do such books use margin/padding-left/right/top/bottom, or the newest margin-block-start/end and margin-inline-start/end (that KOReader/crengine does not support) ?

Every book I've seen uses margin/padding-top/bottom.

D4 Do you have to enable some specific style tweaks (ie. Ignore horizontal/vertical padding/margin or Left aligned most text) to get things better?

I have to ignore paddings and text indents to avoid those blanks and out-of-bound texts.

@poire-z
Copy link
Contributor

poire-z commented May 8, 2024

Thanks for the detailed feedback and insights.

Every book I've seen uses margin/padding-top/bottom.

Then, I guess that if we later go on at making all this better, and let crengine know that we are in this "vertical formatting hack mode", it could somehow translate margin/padding/border-top to ...-left & similar... and maybe this only for publisher stylesheets, and only when writing-mode: vertical-rl...

Plateaukao mentioned that counters in lists should be shown in vertical, which can be implemented through counter-style: fullwidth-decimal in css.

We don't support CSS counter-*.
But we currently tweak a little the font requested for list items - so if this gets to be really needed, depending on crengine know about that "vertical formatting hack mode", we could request the font to use fullwidth opentype features:

--- a/crengine/src/lvfntman.cpp
+++ b/crengine/src/lvfntman.cpp
@@ -1598,29 +1598,29 @@ public:
     virtual LVFontRef getDecimalListItemFont() {
         if ( !_DecimalListItemFont.isNull() )
             return _DecimalListItemFont;
         if ( _kerningMode == KERNING_MODE_HARFBUZZ && !(getFeatures() & LFNT_OT_FEATURES_P_TNUM) ) {
             // We can request the same font with OpenType feature "tabular nums", for fixed width
             // digits and better alignment of decimal list items (no need to do it if this feature
             // has already been enabled for this font). If the font does not support the feature,
             // we'll just have another useless instance of the font.
             _DecimalListItemFont = fontMan->GetFont(
                 getSize(),
                 getWeight(),
                 getItalic(),
                 getFontFamily(),
                 getTypeFace(),
-                getFeatures() | LFNT_OT_FEATURES_P_TNUM,
+                getFeatures() | LFNT_OT_FEATURES_P_TNUM | LFNT_OT_FEATURES_P_FWID,
                 -1, false);
             if ( _DecimalListItemFont.isNull() ) // shouldn't happen
                 _DecimalListItemFont = LVFontRef(this);
         }
         else {
             // LFNT_OT_FEATURES_P_TNUM won't be used with other kerning modes, so use this same font
             _DecimalListItemFont = LVFontRef(this);
         }
         return _DecimalListItemFont;
     }

A quick try with @Bluemoondragon07 's fonts shows:
image
All the ASCII chars are rotated in these fonts, so it doesnt really show how it could behave. I wanted to see if ASCII digits => opentype feature fullwidth => fullwidth glyphs would give us the rotated glyphs.
Anyway, that's for later fun if one day I'm bored enough to make all that better - just wanted to have a quick try.
(I think I've seen recently some other site with such rotated fonts, may be for Chinese - but can't find again where I did see that - dunno if it was linked to in one of our github issue.)

There's another trivial problem: the book uses -epub-text-emphasis-style: filled sesame, which will display a dot on top (or right) of every kanji and kana (reference: JLREQ 3.3.9). it seems to be not supported yet.

https://drafts.csswg.org/css-text-decor/#emphasis-marks
Not trivial to implement :), with all the various styling possiblities. So, this will probably never happen.
Even with horizontal writing. Even the most simple one would be hard. It feels it's like text-decoration, but it's quite more than just the single solid line we have to draw with text-decoration: it's supposed to use a glyph from a font, and to position it precisely, above or around each original glyphs... so (the way crengine works) would need to wrap each letter into some <table> (like we do for ruby), which is not in the original HTML, which will never happen.
Dunno if there are OpenType features to get Harfbuzz to draw these glyphs above/around the original glyph, but it would need font support, which, if the feature exists, may be rare.
If it would really be needed to have something/anything to show when text-emphasis is set (no matter the styling/position), we could hack another "text decoration" similar to "overline", where instead of drawing a long line above the run of text, we would somehow draw a dashed line, with just a little segment taking 30% or 50% of the glyph width, centered above each (or just a full dashed line).

Just some thoughts, not planning going there soon :)

@rukit24
Copy link

rukit24 commented May 17, 2024

We don't support CSS counter-*. But we currently tweak a little the font requested for list items - so if this gets to be really needed, depending on crengine know about that "vertical formatting hack mode", we could request the font to use fullwidth opentype features:

--- a/crengine/src/lvfntman.cpp
+++ b/crengine/src/lvfntman.cpp
@@ -1598,29 +1598,29 @@ public:
     virtual LVFontRef getDecimalListItemFont() {
         if ( !_DecimalListItemFont.isNull() )
             return _DecimalListItemFont;
         if ( _kerningMode == KERNING_MODE_HARFBUZZ && !(getFeatures() & LFNT_OT_FEATURES_P_TNUM) ) {
             // We can request the same font with OpenType feature "tabular nums", for fixed width
             // digits and better alignment of decimal list items (no need to do it if this feature
             // has already been enabled for this font). If the font does not support the feature,
             // we'll just have another useless instance of the font.
             _DecimalListItemFont = fontMan->GetFont(
                 getSize(),
                 getWeight(),
                 getItalic(),
                 getFontFamily(),
                 getTypeFace(),
-                getFeatures() | LFNT_OT_FEATURES_P_TNUM,
+                getFeatures() | LFNT_OT_FEATURES_P_TNUM | LFNT_OT_FEATURES_P_FWID,
                 -1, false);
             if ( _DecimalListItemFont.isNull() ) // shouldn't happen
                 _DecimalListItemFont = LVFontRef(this);
         }
         else {
             // LFNT_OT_FEATURES_P_TNUM won't be used with other kerning modes, so use this same font
             _DecimalListItemFont = LVFontRef(this);
         }
         return _DecimalListItemFont;
     }

A quick try with @Bluemoondragon07 's fonts shows:

May i ask what code have you tweaked to get that result

@Frenzie
Copy link
Member

Frenzie commented May 17, 2024

That one line is in https://github.com/koreader/crengine/

But you can't test it without compiling the program.

@KonstantinDjairo
Copy link

KonstantinDjairo commented May 30, 2024

That one line is in https://github.com/koreader/crengine/

But you can't test it without compiling the program.

is it possible to patch crengine to make it display vertical text?

@Bluemoondragon07
Copy link

@MyK00L Thank you for your script! I finally figured out how to get it working.

If any of you are interested, I just updated my repo of rotated Japanese fonts specifically for this purpose. The fonts are much more accurate now--except for IBM Plex and Shippori Mincho; they are still outdated. But everything else will appear much more accurately to how it should look in tategaki.

@KonstantinDjairo
Copy link

@Bluemoondragon07 you could provide images in the Readme too, as previews

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

No branches or pull requests