objection_engine icon indicating copy to clipboard operation
objection_engine copied to clipboard

It doesn't render certain characters

Open LuisMayo opened this issue 4 years ago • 14 comments

Reported by an user Original report

Hi. I would like to report an issue on ace attorney bot. When rendering threads in Ukrainian, it skips Cyrillic letters і and ї. I think this has something to do with encoding which is not utf-8. I know you may not have time to fix this, but if someday you would like to improve your bot somehow, that is a great thing to do! Love your bot.

Added report for Chinese

Please see https://twitter.com/aceCourtBot/status/1462362972450340864

Some simplified Chinese characters are rendered as solid dot (·)

Same with Emoji

LuisMayo avatar Oct 27 '21 12:10 LuisMayo

Same as some Turkish letters e.g. Ğ/ğ

adeep avatar Nov 08 '21 15:11 adeep

Where is font asset, used for render text, is actually hosted?

~~Is it pixelmap font asset or is it generated in some way directly from code during render?~~

UPD: Just found font assets used to render text:

  • https://github.com/LuisMayo/objection_engine/blob/d66a47ca54005478859541a5e53ad6cfc76d0614/beans/text.py#L5-L20
class AnimText:
    font_array = [
        # AA-Like > Pixel > Generic
        # AA-like, Latin, hiragana, katakana, (part of) cyrillic
        {'path': './assets/igiari/Igiari.ttf'},
        # Pixel, Kanji, Hiragana, Katakana
        {'path':'./assets/igiari/jackeyfont.ttf'},
        # Arabic
        {'path':'./assets/igiari/arabic-1.ttf', 'size': 12},
        # Pixel-font, Hebrew
        {'path':'./assets/igiari/STANRG__.ttf'},
        # Generic
        {'path':'./assets/igiari/NotoSans-Regular.ttf'},
        # Pixel font, Arabic
        {'path':'./assets/igiari/bitsy-font-with-arabic.ttf', 'size': 10},
    ]

~~BUT, How to edit those font TTF-files? Are them on GitHub?~~

UPD2: @LuisMayo, as I see Igiari.ttf is freeware for non-commercial, but proprietary font:

  • https://www.dafont.com/igiari.font

What about to replace this font with similar, but open-source alternative font instead? (I could help to find such alternative)

ghost avatar Jan 14 '22 14:01 ghost

Hi

As you have already discovered, the font used is in the assets folder. About changing the font, it wouldn't do harm to change it. As long as the new font supports the same number of languages/glyphs the old one did.

The thing is, it's not really that important. This project is not and it's not willing to be commercial. And about licensing, this project is already in a weird place for the copyright law. Take into consideration that Phoenix & Co. are protected until copyright, which cannot be used even in free projects. So I doubt a font for non-comercial usages (which again, this project doesn't have) is the biggest of our problems.

An improvement is an improvement though, so I may accept another font with a better license.

BTW I have to change Igiari, some user sent me via Telegram a modified Igiari.ttf with better support from turkish that I haven't added yet.

LuisMayo avatar Jan 14 '22 15:01 LuisMayo

Unicode Text Pixel Font

An improvement is an improvement though, so I may accept another font with a better license.

BTW I have to change Igiari, some user sent me via Telegram a modified Igiari.ttf with better support from turkish that I haven't added yet.

What about to replace ~~"Igiari"~~ with "Galmuri" font? It has almost all needed characters:

  • https://github.com/quiple/galmuri (could be also added as sub-module to repo)
    • Galmuri 11 (preview): https://quiple.github.io/galmuri/galmuri11
      • TTF: https://github.com/quiple/galmuri/raw/main/dist/Galmuri11.ttf
    • Galmuri 11 Bold (preview): https://quiple.github.io/galmuri/galmuri11-bold
      • TTF: https://github.com/quiple/galmuri/raw/main/dist/Galmuri11-Bold.ttf
    • Galmuri 9 (preview): https://quiple.github.io/galmuri/galmuri9
      • TTF: https://github.com/quiple/galmuri/raw/main/dist/Galmuri9.ttf

Any missed character/glyph would be easily added to "Galmuri", as it is open-source font ;)

Emoji Pixel Font

Additionally, for pixel emoji fonts are few fonts too:

  1. https://meowni.ca/posts/og-emoji-font/
    • TTF: https://meowni.ca/fonts/og-dcm-emoji.ttf
  2. https://projects.metafilter.com/5642/Unicode-emoji-pixel-fonts
    • https://github.com/byackley/pixelfonts
  3. https://github.com/AmberWat/TinyEmojiFontResource
  4. https://github.com/zerosonesfun/BittyKitty
  5. https://github.com/tentacode/lyonmoji

N.B. I would search a little bit and will add few more links especially for pixel emoji fonts

ghost avatar Jan 14 '22 15:01 ghost

@LuisMayo, how to create pull with font replacement changes?

ghost avatar Jan 17 '22 08:01 ghost

Just drop the zip here, fonts are outside Git control. Unless you're adding new fonts, in that case you should make changes in text.py so drop the zip file in the Pull Request that has the text.py change

LuisMayo avatar Jan 17 '22 09:01 LuisMayo

Just drop the zip here, fonts are outside Git control.

OK, Here is Galmuri 11 font (see: https://github.com/LuisMayo/objection_engine/issues/53#issuecomment-1013235784) TTF-file:

  • https://github.com/quiple/galmuri/raw/main/dist/Galmuri11.ttf

May you try it?

ghost avatar Jan 17 '22 09:01 ghost

I've now tried it. The problem is it's not exactly the Ace Attorney font, which I enjoy more.

However it's a really good pixel font, with more charsets support than Igiari, so it's now the second font in the priority check (fonts get checked one by one until one perfect font has been found, Galmuri is the second to be texted, after Igiari). Thanks for the font.

And talking about the issue at hand Ukranian should be a bit better now

LuisMayo avatar Jan 25 '22 11:01 LuisMayo

And talking about the issue at hand Ukranian should be a bit better now

Great news! Thanks.

JFTR, Does @aceCourtBot does not work at this time/today again?

  • https://twitter.com/aceCourtBot/status/1485919939101970432

Because I just tried and there are no render yet:

  • https://twitter.com/app4soft/status/1485944166861479936

UPD: Got it in 15 minutes

  • https://twitter.com/aceCourtBot/status/1485947965063766018

ghost avatar Jan 25 '22 12:01 ghost

You're just in queue, I'm doing some experiments with the queue so it may be longer than expected!

LuisMayo avatar Jan 25 '22 12:01 LuisMayo

I tried the new Noto Emoji and it kinda works, except it overflows from the line:

image

Edit: The AnimText class should also be tweaked to allow using emoji font with others.

saschanaz avatar May 01 '22 09:05 saschanaz

Yes, you're right, that way we can set an specific size for the emoji font so it doesn't overflow while the rest of the text is in another font

LuisMayo avatar May 01 '22 09:05 LuisMayo

So I found two issues for emojis so far.

  1. [:frame] does not work for emojis as an emoji includes several unicode characters. Some library like https://pypi.org/project/grapheme/ should be used to properly render an emoji without breaking it down, but even that library does not support the latest emojis as it's not being maintained well.
  2. Pillow does not support font fallback. There could be a handwritten way specifically for emojis where the library would put emojis in separate AnimText objects ~~as it already does for newlines~~ (Edit: I misunderstood the code, boo). (An emoji character can be detected by checking it against Noto Emoji)

saschanaz avatar May 01 '22 10:05 saschanaz

Yah, I'm afraid about the non fallback from pillow. That's thy I had to create the "compute best font" by myself.

Maybe a PR to the Pillow is warranted

LuisMayo avatar May 01 '22 18:05 LuisMayo