-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
[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
base: master
Are you sure you want to change the base?
Conversation
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) |
There was a problem hiding this comment.
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) {
// ...
}
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
// 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; | ||
} |
There was a problem hiding this comment.
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
@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. |
A review of the code is required. Since I'm not sure what's written correctly at all.