inventree / InvenTree

Open Source Inventory Management System
https://docs.inventree.org
MIT License
4.39k stars 792 forks source link

Chinese font support is missing in Docker containers. #7737

Closed zly20129 closed 3 months ago

zly20129 commented 4 months ago

Please verify that this bug has NOT been raised before.

Describe the bug*

When printing custom labels, Chinese cannot be output, you must manually add Chinese font support to successfully print Chinese labels. Please see Bug Solution Record.

Steps to Reproduce

  1. Creat a Chinese headline part;
  2. Printer part label to pdf with Simple part label template;
  3. You can see no zh_cn text will be printed.

Expected behaviour

Possible problem to be solved: add Chinese font support in the officially given Docker container image. Reason for needing to add font support to official mirrors: The update process given in the official help documentation requires the mirrors to be pulled and downloaded from the server again, and I'm not sure if this overrides the operation of adding font support manually, which would result in the user needing to once again re-add Chinese font support manually.

Deployment Method

Version Information

# Version Information:
InvenTree-Version: 0.15.6
Django Version: 4.2.14
Commit Hash: 23a9485
Commit Date: 2024-07-23

Database: postgresql
Debug-Mode: False
Deployed using Docker: True
Platform: Linux-5.4.0-189-generic-x86_64-with
Installer: DOC

Active plugins: [{'name': 'InvenTreeBarcode', 'slug': 'inventreebarcode', 'version': '2.0.0'}, {'name': 'InvenTreeCoreNotificationsPlugin', 'slug': 'inventreecorenotificationsplugin', 'version': '1.0.0'}, {'name': 'InvenTreeCurrencyExchange', 'slug': 'inventreecurrencyexchange', 'version': '1.0.0'}, {'name': 'InvenTreeLabel', 'slug': 'inventreelabel', 'version': '1.0.0'}, {'name': 'InvenTreeLabelMachine', 'slug': 'inventreelabelmachine', 'version': '1.0.0'}, {'name': 'InvenTreeLabelSheet', 'slug': 'inventreelabelsheet', 'version': '1.0.0'}, {'name': 'DigiKeyPlugin', 'slug': 'digikeyplugin', 'version': '1.0.0'}, {'name': 'LCSCPlugin', 'slug': 'lcscplugin', 'version': '1.0.0'}, {'name': 'MouserPlugin', 'slug': 'mouserplugin', 'version': '1.0.0'}, {'name': 'TMEPlugin', 'slug': 'tmeplugin', 'version': '1.0.0'}, {'name': 'IPNGenerator', 'slug': 'ipngen', 'version': '0.1'}]

Please verify if you can reproduce this bug on the demo site.

Relevant log output

See [Bug Demo](https://github.com/inventree/InvenTree/issues/7735)
SchrodingersGat commented 4 months ago

@zly20129 can you please explain your process of "adding Chinese font support" - what additional packages are required, etc

zly20129 commented 4 months ago

@zly20129 can you please explain your process of "adding Chinese font support" - what additional packages are required, etc

Oh, I apologize, I forgot to put the link to the detailed instructions here.

Please see here

SchrodingersGat commented 4 months ago

There are a few ways we can tackle this:

Add Font Package

For Chinese font support, likely the package we need to add is font-isas-misc - this package adds around ~700KB to the base alpine image, so it not very heavy.

Extend Docker Image

Users can inherit from our base docker image to install whatever extra packages they need. No work required on our end but is on the user end.

Allow Custom Package Installation

There is already a feature request to this end - https://github.com/inventree/InvenTree/issues/5718

zly20129 commented 4 months ago

There are a few ways we can tackle this:

Add Font Package

For Chinese font support, likely the package we need to add is font-isas-misc - this package adds around ~700KB to the base alpine image, so it not very heavy.

Extend Docker Image

Users can inherit from our base docker image to install whatever extra packages they need. No work required on our end but is on the user end.

Allow Custom Package Installation

There is already a feature request to this end - #5718

Okay, I'm very much looking forward to the project team's improvements. Because as a user, having to manually reinstall the fonts all over again with every update and every restart of the server after changing environment variables is really too easy to forget.

SchrodingersGat commented 4 months ago

@zly20129 do you have a setup running using our official docker image where you can run a test?

zly20129 commented 4 months ago

do you have a setup running using our official docker image where you can run a test?

Using the official docker mirror. I ran it the first time after the download and used the command to query the Chinese fonts support list, but the terminal did not output any valid results, which means that there are no Chinese fonts in the official mirrors either. I tried to test the Chinese label output on your demo site too, and the result is the same, it can't output double-width characters like Chinese, it's replaced with double-width blanks.

zly20129 commented 4 months ago

@zly20129 do you have a setup running using our official docker image where you can run a test?

If you happen to have the official image, then I would recommend using docker exec inventree-server fc-list :lang=zh to see if there is any output, if nothing else it is not outputting anything.

SchrodingersGat commented 4 months ago

@zly20129 can you please run the following command:

docker compose exec inventree-server sudo apk add font-isas-misc

This should install the required font sets. Can you confirm if that works as expected?

zly20129 commented 4 months ago

This should install the required font sets. Can you confirm if that works as expected?

I've tried, this font doesn't support double wide character Chinese.

zly@ubuntu20server:~/inventree/contrib/container$ docker compose exec inventree-server apk add font-isas-misc
WARN[0000] /home/zly/inventree/contrib/container/docker-compose.yml: `version` is obsolete 
fetch https://dl-cdn.alpinelinux.org/alpine/v3.18/community/x86_64/APKINDEX.tar.gz
(1/2) Installing font-alias (1.0.5-r0)
(2/2) Installing font-isas-misc (1.0.4-r1)
Executing mkfontscale-1.2.2-r3.trigger
Executing fontconfig-2.14.2-r3.trigger
OK: 232 MiB in 131 packages
zly@ubuntu20server:~/inventree/contrib/container$ docker exec inventree-server fc-list :lang=zh
zly@ubuntu20server:~/inventree/contrib/container$ docker exec inventree-server fc-list :lang=zh
zly@ubuntu20server:~/inventree/contrib/container$ 

This font below is supported in Chinese, I just wish the official image would include the font. Because self-installed fonts need to be re-installed again manually by myself every time I change the configuration or update the pull image, which is really easy to forget and a pain in the ass.

zly@ubuntu20server:~$ docker exec inventree-server fc-list :lang=zh
/usr/share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei,文泉驛正黑,文泉驿正黑:style=Regular
/usr/share/fonts/wqy-microhei.ttc: WenQuanYi Micro Hei,文泉驛微米黑,文泉驿微米黑:style=Regular
/usr/share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei Mono,文泉驛等寬正黑,文泉驿等宽正黑:style=Regular
/usr/share/fonts/wqy-zenhei.ttc: WenQuanYi Zen Hei Sharp,文泉驛點陣正黑,文泉驿点阵正黑:style=Regular
/usr/share/fonts/wqy-microhei.ttc: WenQuanYi Micro Hei Mono,文泉驛等寬微米黑,文泉驿等宽微米黑:style=Regular
zly@ubuntu20server:~$ 
SchrodingersGat commented 4 months ago

What specific font packs have you had to install to get it working?

zly20129 commented 4 months ago

Such as sudo apt-get install ttf-wqy-microhei of sudo apt-get install ttf-wqy-zenhei. Note: I have not actually tested the former, while the latter I have tested in detail that it works. In fact, it will work fine as long as you install any font that supports double-width character Chinese, since the font problem is mainly in the function of label printing. If there are no supported fonts, then unsupported text will be replaced by blanks, which can lead to problems with missing label information. For example, the official label provided by the HTML template, which wrote a few font support list, but these fonts do not support the language I use, want to label normal printing, then you need to install the font, and then add the name of the font to the HTML file, so as to ensure that the full normal work.

zly20129 commented 4 months ago

What specific font packs have you had to install to get it working?

Incidentally, those two fonts were used as examples only because they came up most frequently when I was looking for solutions on Baidu, so I installed them.

matmair commented 4 months ago

If we address this in core I would like to tackle at least most non-latin character sets. Google Fonts Noto might solve this problem. Having one font for all glyphs would also ensure consistency.

zly20129 commented 4 months ago

If we address this in core I would like to tackle at least most non-latin character sets. Google Fonts Noto might solve this problem. Having one font for all glyphs would also ensure consistency.

Good idea!

SchrodingersGat commented 4 months ago

@zly20129 can you please try the following:

docker compose exec inventree-server sudo apk add font-terminus font-inconsolata font-dejavu font-noto font-noto-cjk font-noto-extra

Does this setup provide font support as requested?

zly20129 commented 4 months ago

@zly20129 can you please try the following:

docker compose exec inventree-server sudo apk add font-terminus font-inconsolata font-dejavu font-noto font-noto-cjk font-noto-extra

Does this setup provide font support as requested?

All I can say is that they will appear in the Chinese language support list. I downloaded and installed them using the proxy, then used docker exec inventree-server fc-list :lang=zh to see that Chinese supported fonts did appear in the output. I then cleared my proxy settings for inventree-server and saved the config file. However, after I executed docker compose up -d and docker compose restart, the docker image was restored and these installed fonts disappeared, and I wasn't able to test them to see if they could output labels with Chinese characters properly. From a few hours ago, until now, I've been trying to install these fonts again, but unfortunately, whether using a proxy or not, they download extraordinarily slowly and then get stuck, and I've never been able to successfully download and install them again.

SchrodingersGat commented 4 months ago

@zly20129 can you supply a report template / label template / etc where I can test character support locally? A simple .html template file with some representative chinese characters / text would be sufficient I think

zly20129 commented 4 months ago

@zly20129 can you supply a report template / label template / etc where I can test character support locally? A simple .html template file with some representative chinese characters / text would be sufficient I think

Okay! I will provide all my current custom templates, all temp~ use font is wqy-zenhei.

  1. Part_Label, set paper size to 76*25MM.
    
    {% load l10n %}
    {% load i18n %}
    {% load report %}
    {% load barcode %}
{% block content %} {% trans 'QR Code' %}
{{ part.name }}
{{ part.category }}
{{ part.IPN }}
{{ part.description }}
{% endblock content %}

2. Stockitem_Label, set paper size to 76*25MM.

{% load l10n %} {% load i18n %} {% load report %} {% load barcode %}

{% block content %} {% trans 'QR Code' %}
{{ part.name }}
{{ part.category }}
{{ part.IPN }}
{{ part.description }}
{% endblock content %}

3. Stocklocation_Label,  set paper size to 76*20MM.

{% load l10n %} {% load i18n %} {% load report %} {% load barcode %}

{% block content %} {% trans 'QR Code' %}
{{ location.name }}
{{ location.description }}
{% endblock content %}
zly20129 commented 4 months ago

@SchrodingersGat Stockitem_Label and Part_Label It's almost the same, so I won't write about it separately here.

  1. Part_Label picture.

棕色F6可组装抽屉式收纳盒

商品 收纳盒 抽屉式收纳盒 棕色F6可组装抽屉式收纳盒

棕色F6可组装抽屉式收纳盒;外尺寸24013078MM;内尺寸21511565MM;

labels_5ASgxcU 屏幕截图 2024-08-04 222203

  1. Stocklocation_Label picture.

待入库

等待分类入库的零件总类

labels_1OVvLLc 屏幕截图 2024-08-04 222338

SchrodingersGat commented 3 months ago

@zly20129 OK I think I have this worked out now.

Part setup:

image

Normal docker setup:

image

After installing fonts:

image

Note that the label formatting is not great, but it proves the concept.