Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emoji TTF font setting not working #199

Open
noraj opened this issue Feb 5, 2023 · 22 comments
Open

Emoji TTF font setting not working #199

noraj opened this issue Feb 5, 2023 · 22 comments
Assignees
Labels
bug Something isn't working

Comments

@noraj
Copy link

noraj commented Feb 5, 2023

Describe the bug

Emoji TTF font setting not working.

To Reproduce

Whatever the TTF font I use from the env. var. or with the option, emojis are not displayed.

# set emoji font in env var
export TEXTIMG_EMOJI_FONT_FILE=/usr/share/fonts/noto/NotoColorEmoji.ttf
export TEXTIMG_EMOJI_FONT_FILE=/usr/share/fonts/joypixels/JoyPixels.ttf
# from env var
echo あ😃a👍!👀ん👄 | ./textimg -i -o emoji.png
# explicit option
echo あ😃a👍!👀ん👄 | ./textimg -i -e /usr/share/fonts/joypixels/JoyPixels.ttf -o emoji.png

Output image:

emoji

Expected behavior

Emoji displayed as in the documentation https://github.com/jiro4989/textimg#emoji-font-ttf.

Environment (please complete the following information)

  • OS: ArchLinux
  • Version: textimg 3.1.7
@noraj noraj added the bug Something isn't working label Feb 5, 2023
@noraj
Copy link
Author

noraj commented Feb 5, 2023

Emoji image variant works however.

git clone https://github.com/googlefonts/noto-emoji /tmp/noto-emoji
export TEXTIMG_EMOJI_DIR=/tmp/noto-emoji/png/128
echo あ😃a👍!👀ん👄 | ./textimg -o emoji.png

emoji

@noraj noraj changed the title Emoji font setting not working Emoji TTF font setting not working Feb 5, 2023
@jiro4989
Copy link
Owner

jiro4989 commented Feb 8, 2023

I don't have an Arch Linux environment, so I can't test it. Solve the problem yourself.

Probably, I think that the JoyPixels font does not support Japanese.

/usr/share/fonts/joypixels/JoyPixels.ttf

@jiro4989
Copy link
Owner

jiro4989 commented Feb 8, 2023

You can draw Japanese with these fonts.

textimg/config/config.go

Lines 62 to 69 in 80e940a

const (
defaultWindowsFont = `C:\Windows\Fonts\msgothic.ttc`
defaultDarwinFont = "/System/Library/Fonts/AppleSDGothicNeo.ttc"
defaultIOSFont = "/System/Library/Fonts/Core/AppleSDGothicNeo.ttc"
defaultAndroidFont = "/system/fonts/NotoSansCJK-Regular.ttc"
defaultLinuxFont1 = "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc"
defaultLinuxFont2 = "/usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc"
)

@jiro4989 jiro4989 closed this as completed Feb 8, 2023
@jiro4989 jiro4989 reopened this Feb 8, 2023
@noraj
Copy link
Author

noraj commented Feb 8, 2023

I don't have an Arch Linux environment, so I can't test it. Solve the problem yourself.

I don't think it's related to the OS flavor.

Probably, I think that the JoyPixels font does not support Japanese.

Japanese character not displayed is expected but the emoji should be.

@jiro4989
Copy link
Owner

jiro4989 commented Feb 8, 2023

If you want to draw Japanese, set TEXTIMG_FONT_FILE to a font that supports Japanese.
TEXTIMG_FONT_FILE is used for drawing non-emoticons.

See: https://github.com/jiro4989/textimg#fonts

I don't think it's related to the OS flavor.

I don't know ArchLinux's font folder. I don't even know what fonts will be installed.

@noraj
Copy link
Author

noraj commented Feb 11, 2023

It's not about Japanese chars or ArchLinux. It's a bug in textimg where emoji font option is ignored!

$ wget https://github.com/jiro4989/textimg/releases/download/v3.1.8/textimg-linux-amd64.tar.gz
$ tar xaf textimg-linux-amd64.tar.gz
$ ls /usr/share/fonts/noto/NotoColorEmoji.ttf
/usr/share/fonts/noto/NotoColorEmoji.ttf
$ export TEXTIMG_EMOJI_FONT_FILE=/usr/share/fonts/noto/NotoColorEmoji.ttf
# from env var
$ echo 😃👍👀👄 | ./textimg -i -o emoji.png
2023/02/11 04:07:42 textimg [WARN] /home/runner/work/textimg/textimg/config/face.go:42 /usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc is not found. please set font path with `-f` option

image

# explicit option
$ echo 😃👍👀👄 | ./textimg -i -e /usr/share/fonts/joypixels/JoyPixels.ttf -o emoji.png       
2023/02/11 04:09:38 textimg [WARN] /home/runner/work/textimg/textimg/config/face.go:42 /usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc is not found. please set font path with `-f` option

image

@jiro4989
Copy link
Owner

See WARN message.

2023/02/11 04:07:42 textimg [WARN] /home/runner/work/textimg/textimg/config/face.go:42 /usr/share/fonts/noto-cjk/NotoSansCJK-Regular.ttc is not found. please set font path with -f option

@jiro4989
Copy link
Owner

jiro4989 commented Feb 11, 2023

This is what happens when I run

$ textimg あいうえお😀 -f /usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc -o /images/z.png

image

$ export TEXTIMG_FONT_FILE='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc'
$ textimg あいうえお😀 -o /images/z.png

image

export TEXTIMG_EMOJI_FONT_FILE=/usr/share/fonts/truetype/noto/NotoColorEmoji.ttf
export TEXTIMG_FONT_FILE='/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc'
textimg あいうえお😀 -o /images/z.png

image

$ textimg あいうえお -f zzz.ttf -o /images/z.png
2023/02/11 05:43:36 textimg [WARN] /root/go/pkg/mod/github.com/jiro4989/textimg/[email protected]/config/face.go:42 zzz.ttf is not found. please set font path with `-f` option

image

@jiro4989
Copy link
Owner

textimg uses two fonts to draw characters.

  1. TEXTIMG_FONT_FILE
  2. TEXTIMG_EMOJI_FONT_FILE

In your environment, the font specified by default in TEXTIMG_FONT_FILE does not exist, so Japanese cannot be drawn.

@jiro4989
Copy link
Owner

jiro4989 commented Feb 11, 2023

The default font used by textimg is based on the path installed in Ubuntu.

#199 (comment)

Rendering Japanese has failed because a font (TEXTIMG_FONT_FILE) that does not exist in your environment is used.

@jiro4989 jiro4989 reopened this Feb 11, 2023
@jiro4989
Copy link
Owner

jiro4989 commented Feb 11, 2023

textimg doesn't support every font path on every OS.
Set a font that can draw Japanese in TEXTIMG_FONT_FILE.

@jiro4989
Copy link
Owner

No, no. I didn't understand the issues.

@jiro4989
Copy link
Owner

jiro4989 commented Feb 11, 2023

I finally understand. Indeed, TEXTIMG_EMOJI_FONT_FILE is not working as you said.

textimg あいうえお😀 -o /images/a.png
export TEXTIMG_EMOJI_FONT_FILE='sushi.ttf'
textimg あいうえお😀 -o /images/b.png

2023/02/11 06:15:30 textimg [WARN] /root/go/pkg/mod/github.com/jiro4989/textimg/[email protected]/config/face.go:42 sushi.ttf is not found. please set font path with -f option

a.png:

image

b.png:

image

It has the wrong warning message and the wrong font priority.
This is a textimg bug.

@jiro4989
Copy link
Owner

Please forgive me for my untruthful reading of the issues.🙇
I will investigate the cause of the bug.

@jiro4989
Copy link
Owner

hmm? The -e option is working.

textimg -e /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf あいうえお😀 -io /images/a.png
textimg -e /usr/share/fonts/truetype/ancient-scripts/Symbola_hint.ttf あいうえお😀 -io /images/b.png

a.png:

image

b.png:

image

textimg -e a.ttf あいうえお😀 -io /images/c.png

2023/02/11 07:02:23 textimg [WARN] /root/go/pkg/mod/github.com/jiro4989/textimg/[email protected]/config/face.go:42 a.ttf is not found. please set font path with -f option

image

@jiro4989
Copy link
Owner

jiro4989 commented Feb 11, 2023

It may be a font reading TTF, TTC or rendering problem. Please give me a few days.

@jiro4989
Copy link
Owner

hmm...

  • Alphabet is OK
  • Emoji is NG
package main

import (
	"fmt"
	"strings"
)

func main() {
	// alphabet
	const startAlphabetCodePoint rune = 'A'
	const endAlphabetCodePoint rune = 'z'
	var sb strings.Builder
	appendRangeStrings(&sb, startAlphabetCodePoint, endAlphabetCodePoint)

	// emoji
	const startEmojiCodePoint rune = 0x1f600
	const endEmojiCodePoint = startEmojiCodePoint + 1000
	appendRangeStrings(&sb, startEmojiCodePoint, endEmojiCodePoint)
	fmt.Println(sb.String())
}

func appendRangeStrings(sb *strings.Builder, s, e rune) {
	counter := 1
	for i := s; i <= e; i++ {
		r := []rune{i}
		s := string(r)
		sb.WriteString(s)
		if counter%50 == 0 {
			sb.WriteString("\n")
		}
		counter++
	}
	sb.WriteString("\n")
}
$ go run main.go
ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqr
stuvwxyz
😀😁😂😃😄😅😆😇😈😉😊😋😌😍😎😏😐😑😒😓😔😕😖😗😘😙😚😛😜😝😞😟😠😡😢😣😤😥😦😧😨😩😪😫😬😭😮😯😰😱
😲😳😴😵😶😷😸😹😺😻😼😽😾😿🙀🙁🙂🙃🙄🙅🙆🙇🙈🙉🙊🙋🙌🙍🙎🙏🙐🙑🙒🙓🙔🙕🙖🙗🙘🙙🙚🙛🙜🙝🙞🙟🙠🙡🙢🙣
🙤🙥🙦🙧🙨🙩🙪🙫🙬🙭🙮🙯🙰🙱🙲🙳🙴🙵🙶🙷🙸🙹🙺🙻🙼🙽🙾🙿🚀🚁🚂🚃🚄🚅🚆🚇🚈🚉🚊🚋🚌🚍🚎🚏🚐🚑🚒🚓🚔🚕
🚖🚗🚘🚙🚚🚛🚜🚝🚞🚟🚠🚡🚢🚣🚤🚥🚦🚧🚨🚩🚪🚫🚬🚭🚮🚯🚰🚱🚲🚳🚴🚵🚶🚷🚸🚹🚺🚻🚼🚽🚾🚿🛀🛁🛂🛃🛄🛅🛆🛇
🛈🛉🛊🛋🛌🛍🛎🛏🛐🛑🛒🛓🛔🛕🛖🛗🛘🛙🛚🛛🛜🛝🛞🛟🛠🛡🛢🛣🛤🛥🛦🛧🛨🛩🛪🛫🛬🛭🛮🛯🛰🛱🛲🛳🛴🛵🛶🛷🛸🛹
🛺🛻🛼🛽🛾🛿🜀🜁🜂🜃🜄🜅🜆🜇🜈🜉🜊🜋🜌🜍🜎🜏🜐🜑🜒🜓🜔🜕🜖🜗🜘🜙🜚🜛🜜🜝🜞🜟🜠🜡🜢🜣🜤🜥🜦🜧🜨🜩🜪🜫
🜬🜭🜮🜯🜰🜱🜲🜳🜴🜵🜶🜷🜸🜹🜺🜻🜼🜽🜾🜿🝀🝁🝂🝃🝄🝅🝆🝇🝈🝉🝊🝋🝌🝍🝎🝏🝐🝑🝒🝓🝔🝕🝖🝗🝘🝙🝚🝛🝜🝝
🝞🝟🝠🝡🝢🝣🝤🝥🝦🝧🝨🝩🝪🝫🝬🝭🝮🝯🝰🝱🝲🝳🝴🝵🝶🝷🝸🝹🝺🝻🝼🝽🝾🝿🞀🞁🞂🞃🞄🞅🞆🞇🞈🞉🞊🞋🞌🞍🞎🞏
🞐🞑🞒🞓🞔🞕🞖🞗🞘🞙🞚🞛🞜🞝🞞🞟🞠🞡🞢🞣🞤🞥🞦🞧🞨🞩🞪🞫🞬🞭🞮🞯🞰🞱🞲🞳🞴🞵🞶🞷🞸🞹🞺🞻🞼🞽🞾🞿🟀🟁
🟂🟃🟄🟅🟆🟇🟈🟉🟊🟋🟌🟍🟎🟏🟐🟑🟒🟓🟔🟕🟖🟗🟘🟙🟚🟛🟜🟝🟞🟟🟠🟡🟢🟣🟤🟥🟦🟧🟨🟩🟪🟫🟬🟭🟮🟯🟰🟱🟲🟳
🟴🟵🟶🟷🟸🟹🟺🟻🟼🟽🟾🟿🠀🠁🠂🠃🠄🠅🠆🠇🠈🠉🠊🠋🠌🠍🠎🠏🠐🠑🠒🠓🠔🠕🠖🠗🠘🠙🠚🠛🠜🠝🠞🠟🠠🠡🠢🠣🠤🠥
🠦🠧🠨🠩🠪🠫🠬🠭🠮🠯🠰🠱🠲🠳🠴🠵🠶🠷🠸🠹🠺🠻🠼🠽🠾🠿🡀🡁🡂🡃🡄🡅🡆🡇🡈🡉🡊🡋🡌🡍🡎🡏🡐🡑🡒🡓🡔🡕🡖🡗
🡘🡙🡚🡛🡜🡝🡞🡟🡠🡡🡢🡣🡤🡥🡦🡧🡨🡩🡪🡫🡬🡭🡮🡯🡰🡱🡲🡳🡴🡵🡶🡷🡸🡹🡺🡻🡼🡽🡾🡿🢀🢁🢂🢃🢄🢅🢆🢇🢈🢉
🢊🢋🢌🢍🢎🢏🢐🢑🢒🢓🢔🢕🢖🢗🢘🢙🢚🢛🢜🢝🢞🢟🢠🢡🢢🢣🢤🢥🢦🢧🢨🢩🢪🢫🢬🢭🢮🢯🢰🢱🢲🢳🢴🢵🢶🢷🢸🢹🢺🢻
🢼🢽🢾🢿🣀🣁🣂🣃🣄🣅🣆🣇🣈🣉🣊🣋🣌🣍🣎🣏🣐🣑🣒🣓🣔🣕🣖🣗🣘🣙🣚🣛🣜🣝🣞🣟🣠🣡🣢🣣🣤🣥🣦🣧🣨🣩🣪🣫🣬🣭
🣮🣯🣰🣱🣲🣳🣴🣵🣶🣷🣸🣹🣺🣻🣼🣽🣾🣿🤀🤁🤂🤃🤄🤅🤆🤇🤈🤉🤊🤋🤌🤍🤎🤏🤐🤑🤒🤓🤔🤕🤖🤗🤘🤙🤚🤛🤜🤝🤞🤟
🤠🤡🤢🤣🤤🤥🤦🤧🤨🤩🤪🤫🤬🤭🤮🤯🤰🤱🤲🤳🤴🤵🤶🤷🤸🤹🤺🤻🤼🤽🤾🤿🥀🥁🥂🥃🥄🥅🥆🥇🥈🥉🥊🥋🥌🥍🥎🥏🥐🥑
🥒🥓🥔🥕🥖🥗🥘🥙🥚🥛🥜🥝🥞🥟🥠🥡🥢🥣🥤🥥🥦🥧🥨🥩🥪🥫🥬🥭🥮🥯🥰🥱🥲🥳🥴🥵🥶🥷🥸🥹🥺🥻🥼🥽🥾🥿🦀🦁🦂🦃
🦄🦅🦆🦇🦈🦉🦊🦋🦌🦍🦎🦏🦐🦑🦒🦓🦔🦕🦖🦗🦘🦙🦚🦛🦜🦝🦞🦟🦠🦡🦢🦣🦤🦥🦦🦧🦨🦩🦪🦫🦬🦭🦮🦯🦰🦱🦲🦳🦴🦵
🦶🦷🦸🦹🦺🦻🦼🦽🦾🦿🧀🧁🧂🧃🧄🧅🧆🧇🧈🧉🧊🧋🧌🧍🧎🧏🧐🧑🧒🧓🧔🧕🧖🧗🧘🧙🧚🧛🧜🧝🧞🧟🧠🧡🧢🧣🧤🧥🧦🧧
🧨
$ go run main.go | textimg -i -e /usr/share/fonts/truetype/noto/NotoColorEmoji.ttf -o ~/Downloads/emoji.png

Result:

emoji

Emoji using TTF files cannot be drawn.

@jiro4989
Copy link
Owner

I can see why this would work.
#199 (comment)

textimg reads the image of emoji codepoint of filename when you set TEXTIMG_EMOJI_DIR.

path := fmt.Sprintf("%s/emoji_u%.4x.png", emojiDir, r)

And writes image pixels to output.

But, textimg use the ttf file when you set TEXTIMG_EMOJI_FONT_FILE.
So, the rendering logic is different.
It's probably a bug in the implementation that uses TEXTIMG_EMOJI_FONT_FILE.

@jiro4989
Copy link
Owner

@noraj This seems to be an issue with the golang/freetype library.
golang/freetype#45 (comment)

When I first implemented textimg, I couldn't draw color emoji, so I implemented it using emoji image files.
(I just remembered. 😅)

And since this issue is still unresolved, textimg cannot support color emoji TTF either. 😓

@noraj
Copy link
Author

noraj commented Feb 20, 2023

Yeah last comment there is 6 years ago and they are talking about unicode v3/4 while we are at Unicode 15 now. This library will not support emoji anytime soon if ever. So either i will stay that way or maybe anoter more modern lib can be used.

@jiro4989
Copy link
Owner

jiro4989 commented Feb 26, 2023

I searched for an alternative library, but it's probably not in Go language.
So this problem can't be solved.

@noraj
Copy link
Author

noraj commented Feb 26, 2023

Sad news.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants