Skip to content

Conversation

@thorwebdev
Copy link

@thorwebdev thorwebdev commented Oct 28, 2025

fixes #29

Copilot AI review requested due to automatic review settings October 28, 2025 23:24
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for rendering Chinese characters in GitHub usernames by using Cloudinary's text rendering service as an image when the device's native font doesn't support Chinese characters.

Key changes:

  • Added Cloudinary cloud name configuration to secrets.py with a default "demo" value
  • Implemented Chinese character detection and image-based rendering for names containing Chinese characters
  • Modified the badge display logic to use image rendering for Chinese names and fallback to text for non-Chinese names

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
badge/secrets.py Added CLOUDINARY_CLOUD_NAME configuration with documentation
badge/apps/badge/init.py Added Chinese character detection, Cloudinary URL generation, image fetching, and conditional rendering logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +332 to +333
if not self._task:
self._task = get_user_data(self, self._force_update)
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

This condition calls get_user_data() again which will re-fetch user data unnecessarily. The Chinese image should already be fetched within get_user_data() (lines 182-192). This condition appears to be unreachable in normal flow since chinese_name_img is set during the initial get_user_data() call when self.name is populated.

Suggested change
if not self._task:
self._task = get_user_data(self, self._force_update)

Copilot uses AI. Check for mistakes.
if self.chinese_name_img:
# Display Chinese name as image, centered
img_w = self.chinese_name_img.width
screen.blit(self.chinese_name_img, 80 - (img_w / 2), 16)
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

Integer division should be used for pixel positioning. Using float division may cause rendering issues. Change to 80 - (img_w // 2) for consistent behavior with the text centering logic on line 369.

Suggested change
screen.blit(self.chinese_name_img, 80 - (img_w / 2), 16)
screen.blit(self.chinese_name_img, 80 - (img_w // 2), 16)

Copilot uses AI. Check for mistakes.
if self.chinese_name_img:
# Display Chinese name as image, centered
img_w = self.chinese_name_img.width
screen.blit(self.chinese_name_img, 80 - (img_w / 2), 16)
Copy link

Copilot AI Oct 28, 2025

Choose a reason for hiding this comment

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

[nitpick] The Y-coordinate 16 is hardcoded here and on line 369. Consider extracting this as a constant like NAME_Y_POSITION = 16 to improve maintainability and ensure consistency.

Copilot uses AI. Check for mistakes.
@martinwoodward martinwoodward marked this pull request as draft November 2, 2025 16:09
@martinwoodward
Copy link
Contributor

I love this approach, although I'd hesitate to publish usernames to a 3rd party service without updating appropriate privacy statements etc. Might see if it's possible to do something similar but with a GitHub hosted service or something on GitHub Pages. Alternatively investigate full unicode font support and how compressed we can make those font files.

@thorwebdev
Copy link
Author

@martinwoodward ah yah, good point on privacy. Any thoughts on a better approach? The chinese character alphabet is just so large it wouldn't fit on the device I think :(

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.

Font for the name does not support chinese characters

2 participants