0

I create a docker file as below:

FROM mcr.microsoft.com/dotnet/core/aspnet:2.2 AS base
RUN apt-get update \
    && apt-get install -y --allow-unauthenticated \
        libc6-dev \
        libgdiplus \
        libx11-dev \
     && rm -rf /var/lib/apt/lists/*
RUN ln -s /usr/lib/libgdiplus.so /usr/lib/gdiplus.dll
RUN ln -s /usr/lib/libc6-dev.so /usr/lib/libc6-dev.dll
RUN ln -s /usr/lib/libx11-dev.so /usr/lib/libx11-dev.dll

WORKDIR /app
COPY bin/Release/netcoreapp2.2/publish .
FROM base AS final
WORKDIR /app
ENTRYPOINT ["dotnet","MyWebApi.dll"]

When I run the image I get chinese and arabic texts as boxes. I am creating image(tiff) for Chinese and Arabic texts using system.drawing.common in my .Net core API. Do I need any additional font files in my image?

Niranjan NT
  • 165
  • 1
  • 19
  • Yes, you need to add a font that contains the glyphs you want to render. – Bill Jetzer Jun 25 '20 at 15:26
  • Can I get any reference how can I add fonts to my image? – Niranjan NT Jun 25 '20 at 15:36
  • see [this guide](https://help.accusoft.com/PrizmDoc/v12.1/HTML/Installing_Asian_Fonts_on_Ubuntu_and_Debian.html). You can get a list of candidate fonts like this: `apt-cache search fonts | grep -iE '^fonts.*(chinese|arabic)'` – Bill Jetzer Jun 25 '20 at 17:14
  • I am using my custom font file. I copied that file to /usr/share/fonts directory. Strange thing is my custom font file do not have support for Chinese language, but the image is rendered properly in Windows machine(somehow its rendering using system fonts..my guess) but not in linux(I copied MSYH.ttf file to /usr/share/fonts as well). – Niranjan NT Jun 28 '20 at 04:56

1 Answers1

1

I faced the same issue today, Its happens on .net core 2,3 and also 5.

The problem is that libgdiplus by default use engine that not support RTL/Arabic, so these lines are not giving right result:

# install System.Drawing native dependencies
RUN apt-get update \
      && apt-get install -y --allow-unauthenticated \
       libgdiplus \
       libc6-dev \
      && apt-get clean \
      && rm -rf /var/lib/apt/lists/*

The solution, is to build the source code of the libray libgdiplus by yourself and choose the engine that support Arabic/RTL which is Pango.

These lines will solve the problem, by installing the source code and build it and install the library after selecting the right engine (pango engine using --with-pango parameter):

# Build libgdiplus with pango
RUN apt-get update && apt-get install  -y --allow-unauthenticated \
     libgif-dev autoconf libtool automake build-essential gettext libglib2.0-dev libcairo2-dev libtiff-dev libexif-dev
RUN apt-get update && apt-get install -y libpango1.0-dev 

RUN apt-get install -y --allow-unauthenticated git
RUN git clone https://github.com/mono/libgdiplus.git /libgdiplus
WORKDIR /libgdiplus
RUN ./autogen.sh --with-pango --prefix=/usr
RUN make  
RUN make install

Note: This will work on .net core 3 and above, but for 2.1 its not working and showing this error message:

Requested 'pango >= 1.40.14' but version of Pango is 1.40.5

I ended up with migrate the project from version .netcore 2 to 3 and apply the above code and the Arabic/RTL is work fine.

Wajdy Essam
  • 4,280
  • 3
  • 28
  • 33