Skip to content

[example] Unicode codepoints loading #4886

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

GuvaCode
Copy link
Contributor

A review of the code is required. Since I'm not sure what's written correctly at all.

A review of the code is required.  Since I'm not sure what's written correctly at all.
if (!cp) return GetFontDefault();

// Helper function to add a range of Unicode codepoints
void AddRange(int start, int stop)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nested functions are a GCC extension, so this should probably be moved out to a function like

// Return non-zero on error, maybe?
int AddCodeRange(int **codes, int *capacity, int *count, int start, int stop) {
   // ...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nested functions are a GCC extension, so this should probably be moved out to a function like

// Return non-zero on error, maybe?
int AddCodeRange(int **codes, int *capacity, int *count, int start, int stop) {
   // ...
}

Well, I don't know C well, and I didn't even know that.


Font LoadUnicodeFont(const char* fileName, int fontSize, int textureFilter)
{
int* cp = NULL; // Array to store Unicode codepoints
Copy link
Contributor

Choose a reason for hiding this comment

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

I think a better name might be codes or codePoints.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, you're right, we need to give names more understandable meanings.

Comment on lines 23 to 34
// Expand array if needed
if (count >= capacity)
{
capacity += 1024;
int* newCp = (int*)realloc(cp, capacity * sizeof(int));
if (!newCp)
{
free(cp);
return GetFontDefault();
}
cp = newCp;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

At a glance, I think the initial capacity of 65536 = 2^16 is big enough without resizing, since you're only adding code points smaller than 0xFFFF?

The creation of the array has been rewritten, the size of the example has been reduced
@raysan5
Copy link
Owner

raysan5 commented Apr 12, 2025

@GuvaCode thanks for the example, there is already a similar example, maybe some parts of this one can be moved to the existing one.

I'll keep this PR open to check the parts that can be ported.

@raysan5 raysan5 changed the title example unicode font [example] Unicode codepoints loading Apr 12, 2025
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.

3 participants