qwc-services / qwc-qgis-server

QGIS server Docker image for QWC
2 stars 7 forks source link

Fonts are not loaded correctly with qwc-qgis-server since version 3.28.6 #6

Closed danceb closed 1 year ago

danceb commented 1 year ago

To include additional fonts, change the locale and other things I am building an own qwc-qgis-server image based on yours. Since the Dockerfile and entrypoint.sh files are changed plainly, I had to rewrite our files as well to work with the current versions of qgis server. Unfortunately I don't get the fonts work properly. They are used within GetMap requests and also on the print templates in a correct way. But in the legendGraphics the font is not used and I am getting the following error within the logs:

QFont::fromString: Invalid description '(empty)'
QPainter::scale: Painter not active

Any hints, where this could come from?

My Dockerfile:

FROM sourcepole/qwc-qgis-server:3.28.8

RUN apt-get update \
    && apt-get install --no-install-recommends -y cifs-utils \
    && rm -rf /var/lib/apt/lists/*

ENV LANG de_DE.UTF-8
ENV LANGUAGE de_DE:de
ENV LC_ALL de_DE.UTF-8

# ENV variables that will be used to configure QGIS server FCGI
[...]
# Add apache config for QGIS server
ADD qgis3-server.conf.template /etc/apache2/templates/qgis-server.conf.template

# Add font and plugins folders
ADD fonts /usr/local/share/fonts
ADD plugins /usr/share/qgis/python/plugins

RUN fc-cache -f && fc-list | sort

# Add entrypoint
COPY entrypoint.sh /entrypoint.sh

EXPOSE 80

VOLUME ["/data"]

ENTRYPOINT ["/entrypoint.sh"]

My entrypoint.sh

#!/bin/bash
set -e

echo "Mounting cifs volume QGIS..."
mkdir -p [...]
mount -t cifs [...] -o user=${QGIS_CIFS_USER},password=${QGIS_CIFS_PASSWORD},domain=,uid=0,iocharset=utf8,vers=2.1,noperm,noserverino
echo "QGIS cifs mount successful!"

# Substitute variables from ENV
envsubst < /etc/apache2/templates/qgis-server.conf.template > /etc/apache2/sites-enabled/qgis-server.conf

# Activate the Ubuntu Apache environment
. /etc/apache2/envvars

exec /usr/sbin/apache2 -k start -DFOREGROUND

Any ideas would be very helpful, thanks!

danceb commented 1 year ago

I modified the comment above, because the mounts of the fonts and plugin folders where not correctly. Changed it to the folders mentioned in the readme, but still getting the same errors.

I tried to set the environmental variable FcgidInitialEnv QT_QPA_FONTDIR "/usr/local/share/fonts" within qgis-server.conf.template related to https://github.com/qgis/QGIS/issues/51688, but this doesn't change anything.

How can we detect, if this is a issue which comes from the qgis server itself or from the adjustments made while building a custom image based on it?

manisandro commented 1 year ago

@HusseinKabbout Any ideas?

danceb commented 1 year ago

To simplify the test case more, I left over my own building attempts with a custom Dockerfile and entrypoint.sh and just pulled your image and configured it within the docker-compose.yml and mount the font folder there:

  qwc-qgis-server:
    image: sourcepole/qwc-qgis-server:3.28.6
    restart: unless-stopped
    volumes:
      - ./volumes/qgs-resources/stage:/data:ro
      - ./volumes/geodata/stage:/geodata:ro
      - ./pg_service.stage.conf:/etc/postgresql-common/pg_service.conf:ro
      - ./qwc-qgis-server/fonts:/usr/local/share/fonts
    cap_add:
      - SYS_ADMIN
      - DAC_READ_SEARCH
    security_opt:
      - apparmor=unconfined

until 3.28.5 the legend is generated correctly with the mounted custom font and since 3.28.6 this does not work anymore.

danceb commented 1 year ago

@HusseinKabbout Any (new) thoughts about this?

pka commented 1 year ago

The fonts are listed when starting the container. Are your additional fonts missing in the output? Latest LTR version is 3.28.10.

danceb commented 1 year ago

Yes, the custum font is listed correctly, Arial in my case:

qwc-qgis-server_1              | /usr/local/share/fonts/Arial.ttf: Arial:style=Standard,Normal,obyčejné,Κανονικά,Regular,Normaali,Normál,Normale,Standaard,Normalny,Обычный,Normálne,Navadno,thường,Arrunta

So the mounting seems to work.

But this is a sample legend image with 3.28.5: grafik

And this what it lools like with a newer version (3.28.10 here): grafik

So the custom font is not used for creating the legend image.

pka commented 1 year ago

Could you try to mount the custom fonts in /usr/share/fonts/truetype instead?

pka commented 1 year ago

Looking at the legend output in the given resolution, I can't spot a difference in the font. Are you sure, that not only the font size differs?

danceb commented 1 year ago

Thats exactly the thing I recognized at this moment. I think the standard font size of the getLegendGraphics request from qgis server has changed and this result in confusing me ... So everything should be fine here.

danceb commented 1 year ago

I specified the correct font now via the extraLegendParameters in the config.json and it is loaded correctly.

However I am getting QFont::fromString: Invalid description '(empty)' within the log, but this is not related to this issue here, I guess.