nextcloud / server

☁️ Nextcloud server, a safe home for all your data
https://nextcloud.com
GNU Affero General Public License v3.0
27.33k stars 4.06k forks source link

Characters from Korean, Chinese, etc don’t show in txt/md file previews #4198

Open HuidaeCho opened 7 years ago

HuidaeCho commented 7 years ago
### Steps to reproduce 1. Create a text file in Korean 2. Preview image has broken fonts because the default OpenSans-Regular.ttf has no Korean fonts ### Expected behaviour There should be a way to specify a user font file for TXT preview in config.php. Something like $CONFIG['fontFile'] ### Actual behaviour Broken text in preview or I have to modify lib/private/Preview/TXT.php to point $fontFile to a user font file.
MorrisJobke commented 7 years ago

I would vote for no config option, but a font that actually support Korean and Latin characters.

cc @georgehrke @jancborchardt

jancborchardt commented 7 years ago

Can we add a fallback font to the preview generator? In case characters don't exist, it should simply use Liberation Sans for example.

cc @georgehrke @rullzer @icewind1991

skjnldsv commented 5 years ago

Similar of #13377

jancborchardt commented 5 years ago

It’s not similar, as #13377 is about the interface fonts, and there it uses fallback fonts which are perfectly readable – just not as nice.

But for the previews, it shows no fallback font, but rectangle boxes. (Just like for emojis etc.)

Here is the file in the text editor, perfectly fine:

special characters file

And here its preview, broken: special characters file preview

skjnldsv commented 5 years ago

Well, adding more compatible fonts to the system like #13377 suggest and to the preview generator will fix it, so yes, this is similar.

The text editor uses your own system font as a fallback.

skjnldsv commented 5 years ago

@jancborchardt Shall we add this into the todo of the other issue?

jancborchardt commented 5 years ago

@skjnldsv ok, if you say it’s heavily related we can add it as todo of the other issue.

skjnldsv commented 5 years ago

@jancborchardt Well, it make sense to me, but I might be missing some keys here :wink: :see_no_evil: Let's leave this one opened as even if one is also the solution to the other, we'll not forget there are two parts to the problem! :smile_cat:

jancborchardt commented 5 years ago

Just as a note, this is not fixed by using a native font stack as per https://github.com/nextcloud/server/pull/16055 as this is only for the interface fonts.

For the preview generator we would need TTF files for all the different fonts (as I guess WOFF2 is not supported by the preview generator?) And that means loading a lot of files for Korean, Chinese and Japanese:

These would be the woff2 files, 184 for both regular and bold: https://fonts.googleapis.com/css?family=Noto+Sans+KR:400,700&display=swap

@rullzer is this doable somehow?

Kellermaan commented 3 years ago

Hi, I'm not sure this issue have been fixed. I'm using the latest container version of nextcloud(Nextcloud 20.0.1)and I find out the preview of markdown file got no Chinese character. really strange. The picture 1 is the real content and the picture 2 is the preview. 微信截图_20201210001507 微信截图_20201210001500

Hope someone can tell me how to fix it, thank very much. @jancborchardt

Kellermaan commented 3 years ago

can anyone help me on this? @rullzer @MorrisJobke @jancborchardt @HuidaeCho

HuidaeCho commented 3 years ago

can anyone help me on this? @rullzer @MorrisJobke @jancborchardt @HuidaeCho

It may have changed now, but for version 13.0.12, I added one line after line 72 in lib/private/Preview/TXT.php:

$fontFile  = __DIR__;
$fontFile .= '/../../../core';
$fontFile .= '/fonts/OpenSans-Regular.ttf'; # line 72
# by Huidae Cho
$fontFile = '/usr/local/share/fonts/TTF/UnDotum.ttf'; # here, specify your own font path
huww98 commented 3 years ago

Fonts that support CJK characters can be 20MB each. Is it acceptable to add these fonts to /core/fonts in this repo? If so, I can try to fix this, (also #13376). If not, we may need to add a config that allows us to choose our own font file.

ludishur commented 3 years ago

Thank you @HuidaeCho. In my case version 20.0.2, I changed more.

lib/private/Avatar/Avatar.php:152:          $font = __DIR__ . '/../../core/fonts/NotoSans-Regular.ttf';
lib/private/Avatar/Avatar.php:187:      $font = __DIR__ . '/../../../core/fonts/NotoSans-Regular.ttf';
Kellermaan commented 3 years ago

@HuidaeCho @ludishur Hi, I'm not so familiar with php program. when you said change the code. and then what? just restart the nextcloud container?

Kellermaan commented 3 years ago

@HuidaeCho @ludishur I changed the code and restart the container, It seems didn't work. I also copied the ttf file into the dir the code mention。

ludishur commented 3 years ago

@Kellermaan There is no need to restart container after modifying the code. You need to change username to see the code in action. User can change user name in settings menu. Admin can be renamed in the user/group menu. The avatar png file seems to be recreated when the username is changed. The browser cache may remain, so it is recommended to open the secret mode browser and check it. I hope it goes well.

Kellermaan commented 3 years ago

@ludishur For me, the problem is the preview of md file can now show the chinese character. And I tried your method, it didn't work, am I missing some configuration? Thanks for your reply!!

Kellermaan commented 3 years ago

@ludishur I fixed the issue, it turnes out that the default noto font doesn't include Chinese character. So I downloaded one include Chinese Japaness. Now it worked, thanks anyway.

szaimen commented 1 year ago

Hi, please update to at least 23.0.12 and report back if it fixes the issue. Thank you!

joshtrichards commented 2 months ago

Re-opened because as far as I can tell CJK support was never added for MD/TXT previews/thumbnails. Triggered by a post on the forum and some code review on my part.

There was discussion about it in #16040 and #25529 and elsewhere, but the bundled fonts in core/fonts don't include the CJK (and other) variants of Noto as far as I can tell.

jancborchardt commented 2 months ago

@joshtrichards good catch. Do you know what needs to be done and/or could submit a pull request?

jancborchardt commented 2 months ago

(Also cc @juliushaertl regarding the previews)

jancborchardt commented 2 weeks ago

It’s probably best if we switch to Noto for this as it has the broadest support for various alphabets: https://fonts.google.com/noto/fonts?query=noto

jancborchardt commented 2 weeks ago

FYI @sorbaugh for planning