FreeTypeAbstraction.jl icon indicating copy to clipboard operation
FreeTypeAbstraction.jl copied to clipboard

Emoji support?

Open behinger opened this issue 9 months ago • 1 comments

I get an error when I run the following code

using FreeTypeAbstraction
face = findfont("noto color emoji")
renderface(face, '🎈', 100)

results in

Couldn't set pixelsize with error: 23

Image


I looked into it a little bit, one possible reason could be, that there is simply no support for colored glyphs within FreeTypeAbstraction.jl / FreeType.jl right now?But then, '♡' also doesnt work for me. I dont know much about FreeType :/

I raised this originally in makie.jl: https://github.com/MakieOrg/Makie.jl/issues/4901

behinger avatar Apr 04 '25 11:04 behinger

With "noto color emoji", there seems to be a funny issue regarding pixel size. At least for the version installed on my system, it should be 109, see https://github.com/python-pillow/Pillow/issues/6166

With "correct" pixe size, there is a new error:

ERROR: Could not load glyph '🎈' from FTFont (family = Noto Color Emoji, style = Regular) to render. with error: 7

This likely indicates that FreeType2_jll is compiled with features missing. I have managed to compile it locally with png support. More specifically, libpng_jll is a new dependency in in the build script, and I have

script = raw"""
cd $WORKSPACE/srcdir/freetype-*
cmake -B build -DCMAKE_INSTALL_PREFIX=${prefix} -DBUILD_SHARED_LIBS=TRUE -DFT_REQUIRE_PNG=TRUE -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} -DCMAKE_BUILD_TYPE=Release
cmake --build build --parallel ${nproc}
cmake --install build"""

Now renderface returns an UInt8 matrix, representing a gray-scale image (I guess) of the balloon. To get color, I think in load_glyph we could need something different from FT_LOAD_RENDER.

Edit Likely, modifications to the script are not necessary, because the option seems to be enabled by default, and it could be sufficient to just add libpng_jll as a dependency. If we were to modify the script, instead of switching to (unsupported) cmake, we could instead use sed maybe:

script = raw"""
cd $WORKSPACE/srcdir/freetype-*
# Locate original options file:
OPT_FILE="${PWD}/include/freetype/config/ftoption.h"
# In-place search and replace:
sed -i -E 's/\/\*\s*(#define\s*FT_CONFIG_OPTION_USE_PNG)\s*\*\//\1/' ${OPT_FILE}
sed -i -E 's/\/\*\s*(#define\s*TT_CONFIG_OPTION_COLOR_LAYERS)\s*\*\//\1/' ${OPT_FILE}
# build:
./configure --prefix=${prefix} --build=${MACHTYPE} --host=${target} --enable-shared --disable-static
make -j${nproc}
make install
install_license docs/{FTL,GPLv2}.TXT
"""

manuelbb-upb avatar Aug 28 '25 10:08 manuelbb-upb