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

fix: Show composite emojis enlarged, too #3427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

Hocuri
Copy link
Collaborator

@Hocuri Hocuri commented Nov 13, 2024

There are a lot of composite emojis like the flags and the family emojis. Here, the grapheme starts with an emoji, but then come some other characters that modify the first emoji (e.g. all flags start with the flag emoji).

This PR shows those as big, too, by checking whether a grapheme starts with an emoji to determine whether it's an emoji.

if (++graphemeCount > max) break;
String grapheme = text.substring(start, end);
if (!emojiRegex.matcher(grapheme).matches()) return 0;
if (++graphemeCount > max) return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now the returned value is never > max so the if condition checking emojiCount > 8 can be removed, the function doc-string needs also to indicate this. I would prefer returning -1 in this case then we can check for emojiCount > 0

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you test the performance impact of regex over the whole text vs doing it for each grapheme? in theory it should be cheap since we do it at most in 8 graphemes and break the loop otherwise

since now this is more robust and we don't loop over whole text, maybe makes sense to increase the length restriction from 21 to 56

there is another PR modifying this, maybe first merge that one and rebase

Copy link

To test the changes in this pull request, install this apk:
📦 app-preview.apk

There are a lot of composite emojis like the flags and the family emojis.
Here, the grapheme starts with an emoji, but then come some other
characters that modify the first emoji (e.g. all flags start with the
flag emoji).

This PR shows those as big, too, by checking whether a grapheme _starts_
with an emoji to determine whether it's an emoji.
Copy link

To test the changes in this pull request, install this apk:
📦 app-preview.apk

if (++graphemeCount > max) break;
String grapheme = text.substring(start, end);
if (!emojiRegex.matcher(grapheme).matches()) return 0;
if (++graphemeCount > max) return 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (++graphemeCount > max) return 0;
if (++graphemeCount > max) return -1;

int emojiCount = countGraphemes(text, 8);
if (emojiCount > 8) {
int emojiCount = countEmojis(text, 8);
if (emojiCount > 8 || emojiCount == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (emojiCount > 8 || emojiCount == 0) {
if (emojiCount <= 0) {

@@ -50,36 +50,34 @@ private float getTextScale(String text) {
if (text.length() > 21 || text.isEmpty() || Character.isLetter(text.charAt(0))) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (text.length() > 21 || text.isEmpty() || Character.isLetter(text.charAt(0))) {
if (text.length() > 56 || text.isEmpty() || Character.isLetter(text.charAt(0))) {

@adbenitez adbenitez changed the title fix: Show composite emosis enlarged, too fix: Show composite emojis enlarged, too Nov 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants