LuisMayo / objection_engine

Library that turns comment chains into ace attorney scenes, used in several bots
MIT License
105 stars 20 forks source link

It doesn't render certain characters #53

Open LuisMayo opened 2 years ago

LuisMayo commented 2 years ago

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

adeep commented 2 years ago

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

ghost commented 2 years ago

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:

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:

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

LuisMayo commented 2 years ago

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.

ghost commented 2 years ago

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:

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/
  2. https://projects.metafilter.com/5642/Unicode-emoji-pixel-fonts
  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 commented 2 years ago

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

LuisMayo commented 2 years ago

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

ghost commented 2 years ago

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:

May you try it?

LuisMayo commented 2 years ago

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

ghost commented 2 years ago

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?

Because I just tried and there are no render yet:

UPD: Got it in 15 minutes

LuisMayo commented 2 years ago

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

saschanaz commented 2 years ago

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.

LuisMayo commented 2 years ago

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

saschanaz commented 2 years ago

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)
LuisMayo commented 2 years ago

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