Skip to content

Chinese font support is missing in Docker containers. #7737

Closed

Description

@zly20129

Please verify that this bug has NOT been raised before.

  • I checked and didn't find a similar issue

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

  • Docker
  • Package
  • Bare metal
  • Other - added info in Steps to Reproduce

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.

  • I can reproduce this bug on the demo site.

Relevant log output

See [Bug Demo](https://github.com/inventree/InvenTree/issues/7735)

Activity

  1. added
    bug
    question
    triage:not-checked
    on Jul 25, 2024
  2. SchrodingersGat commented on Jul 26, 2024

    @SchrodingersGat
    Member

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

  3. added
    dependency
    docker
    and removed
    bug
    triage:not-checked
    on Jul 26, 2024
  4. zly20129 commented on Jul 26, 2024

    @zly20129
    Author

    @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

  5. SchrodingersGat commented on Jul 27, 2024

    @SchrodingersGat
    Member

    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

  6. zly20129 commented on Jul 27, 2024

    @zly20129
    Author

    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.

  7. added
    setup
    on Jul 27, 2024
  8. SchrodingersGat commented on Jul 27, 2024

    @SchrodingersGat
    Member

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

  9. zly20129 commented on Jul 27, 2024

    @zly20129
    Author

    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.

  10. zly20129 commented on Jul 27, 2024

    @zly20129
    Author

    @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.

  11. 4 remaining items

  12. zly20129 commented on Jul 29, 2024

    @zly20129
    Author

    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.

  13. matmair commented on Jul 29, 2024

    @matmair
    Member

    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.

  14. zly20129 commented on Jul 30, 2024

    @zly20129
    Author

    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!

  15. SchrodingersGat commented on Jul 30, 2024

    @SchrodingersGat
    Member

    @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?

  16. zly20129 commented on Jul 30, 2024

    @zly20129
    Author

    @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.

  17. SchrodingersGat commented on Aug 4, 2024

    @SchrodingersGat
    Member

    @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

  18. zly20129 commented on Aug 4, 2024

    @zly20129
    Author

    @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 %}
    
    <head>
        <style>
    
            {% block page_style %}
            {% if page_style %}
            /* @page styling */
            {% localize off %}
            {{ page_style }}
            {% endlocalize %}
            {% endif %}
            {% endblock page_style %}
    
            {% block body_style %}
            /* body styling */
            body {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                margin: 0mm;
                color: #000;
                background-color: #FFF;
                page-break-before: always;
                page-break-after: always;
            }
            {% endblock body_style %}
    
            img {
                display: inline-block;
                image-rendering: pixelated;
            }
    
            /* Global content wrapper div which takes up entire page area */
            .content {
                {% localize off %}
                width: {{ width }}mm;
                height: {{ height }}mm;
                {% endlocalize %}
                break-after: always;
                position: relative;
                left: 0mm;
                top: 0mm;
                margin-bottom: 0mm;
            }
    
            {% block style %}
            /* User-defined styles can go here, and override any styles defined above */
            .qr {
                position: absolute;
                left: -1mm;
                top: -1mm;
                height: 20mm;
                width: 20mm;
            }
    
            .part {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                /*flex-direction: column;*/
                position: absolute;
                width: 45.5mm;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                left: 18.5mm;
                top: -0.5mm;
            }
    
            .description {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                position: absolute;
                width: 62mm;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                left: 0mm;
                top: 19.3mm;
            }
            {% endblock style %}
    
        </style>
    </head>
    
    <body>
        <div class='content'>
            {% block content %}
            <!-- Label data rendered here! -->
            <img class='qr' alt="{% trans 'QR Code' %}" src='{% qrcode qr_data %}'>
    
            <div class='part'>
                <span style="color: red; font-size: 5.5mm;">{{ part.name }}</span><br>
                <span style="color: red;">{{ part.category }}</span><br>
                <span style="text-decoration: overline">{{ part.IPN }}</span>
            </div>
    
            <div class='description'>
                <span style="text-decoration: overline">{{ part.description }}</span>
            </div>
            {% endblock content %}
        </div>
    </body>
    
    1. Stockitem_Label, set paper size to 76*25MM.
    {% load l10n %}
    {% load i18n %}
    {% load report %}
    {% load barcode %}
    
    <head>
        <style>
    
            {% block page_style %}
            {% if page_style %}
            /* @page styling */
            {% localize off %}
            {{ page_style }}
            {% endlocalize %}
            {% endif %}
            {% endblock page_style %}
    
            {% block body_style %}
            /* body styling */
            body {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                margin: 0mm;
                color: #000;
                background-color: #FFF;
                page-break-before: always;
                page-break-after: always;
            }
            {% endblock body_style %}
    
            img {
                display: inline-block;
                image-rendering: pixelated;
            }
    
            /* Global content wrapper div which takes up entire page area */
            .content {
                {% localize off %}
                width: {{ width }}mm;
                height: {{ height }}mm;
                {% endlocalize %}
                break-after: always;
                position: relative;
                left: 0mm;
                top: 0mm;
                margin-bottom: 0mm;
            }
    
            {% block style %}
            /* User-defined styles can go here, and override any styles defined above */
            .qr {
                position: absolute;
                left: -1mm;
                top: -1mm;
                height: 20mm;
                width: 20mm;
            }
    
            .part {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                /*flex-direction: column;*/
                position: absolute;
                width: 44mm;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                left: 18.5mm;
                top: -0.5mm;
            }
    
            .description {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                position: absolute;
                width: 62mm;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                left: 0mm;
                top: 19.3mm;
            }
            {% endblock style %}
    
        </style>
    </head>
    
    <body>
        <div class='content'>
            {% block content %}
            <!-- Label data rendered here! -->
            <img class='qr' alt="{% trans 'QR Code' %}" src='{% qrcode qr_data %}'>
    
            <div class='part'>
                <span style="color: red; font-size: 5.5mm;">{{ part.name }}</span><br>
                <span style="color: red;">{{ part.category }}</span><br>
                <span style="text-decoration: overline">{{ part.IPN }}</span>
            </div>
    
            <div class='description'>
                <span style="text-decoration: overline">{{ part.description }}</span>
            </div>
            {% endblock content %}
        </div>
    </body>
    
    1. Stocklocation_Label, set paper size to 76*20MM.
    {% load l10n %}
    {% load i18n %}
    {% load report %}
    {% load barcode %}
    
    <head>
        <style>
    
            {% block page_style %}
            {% if page_style %}
            /* @page styling */
            {% localize off %}
            {{ page_style }}
            {% endlocalize %}
            {% endif %}
            {% endblock page_style %}
    
            {% block body_style %}
            /* body styling */
            body {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                margin: 0mm;
                color: #000;
                background-color: #FFF;
                page-break-before: always;
                page-break-after: always;
            }
            {% endblock body_style %}
    
            img {
                display: inline-block;
                image-rendering: pixelated;
            }
    
            /* Global content wrapper div which takes up entire page area */
            .content {
                {% localize off %}
                width: {{ width }}mm;
                height: {{ height }}mm;
                {% endlocalize %}
                break-after: always;
                position: relative;
                left: 0mm;
                top: 0mm;
                margin-bottom: 0mm;
            }
    
            {% block style %}
            /* User-defined styles can go here, and override any styles defined above */
            .qr {
                position: absolute;
                left: -1mm;
                top: -1mm;
                height: 22mm;
                width: 22mm;
            }
    
            .loc {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                /*flex-direction: column;*/
                position: absolute;
                width: 42mm;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
                left: 21mm;
                top: -0.5mm;
            }
    
            .desc {
                font-family: wqy-zenhei, Arial, Helvetica, sans-serif;
                display: inline-block;
                position: absolute;
                word-wrap: break-word;
                word-break: break-all;
                margin-right: 15mm;
                left: 21mm;
                top: 7.3mm;
                border-top: 2px solid #000; 
            }
            {% endblock style %}
    
        </style>
    </head>
    
    <body>
        <div class='content'>
            {% block content %}
            <!-- Label data rendered here! -->
            <img class='qr' alt="{% trans 'QR Code' %}" src='{% qrcode qr_data %}'>
    
            <div class='loc'>
                <span style="color: red; font-size: 5.5mm;">{{ location.name }}</span><br>
            </div>
    
            <div class='desc'>
                {{ location.description }}
            </div>
            {% endblock content %}
        </div>
    </body>
    
  19. zly20129 commented on Aug 4, 2024

    @zly20129
    Author

    @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

  20. SchrodingersGat commented on Aug 14, 2024

    @SchrodingersGat
    Member

    @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.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    dependencydockerquestionsetuptranslation

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions