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

font: add is_char_defined method in Font and Freetype #2178

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

dr0id
Copy link
Contributor

@dr0id dr0id commented May 18, 2023

partial PR as requested in this PR #2132

@dr0id dr0id requested a review from a team as a code owner May 18, 2023 18:37
@yunline
Copy link
Contributor

yunline commented May 23, 2023

import pygame
import pygame.font

pygame.font.init()

font=pygame.font.Font(size=30)
is_defined=lambda char:print("%s:"%repr(char),font.is_char_defined(char))

is_defined("a")
is_defined("\n")
is_defined("锟")
is_defined("斤")
is_defined("拷")
is_defined(chr(0x20001))
'a': True
'\n': False
'锟': False
'斤': False
'拷': False
Traceback (most recent call last):
  File "x:\python\pygame_test\is_char_defined.py", line 14, in <module>
    is_defined(chr(0x20001))
  File "x:\python\pygame_test\is_char_defined.py", line 7, in <lambda>
    is_defined=lambda char:print("%s:"%repr(char),font.is_char_defined(char))
ValueError: Too long, only 1 char supported.

I passed only one char but got a "Too long, only 1 char supported."
It seems that characters above 0xffff is not handled correctly.
TTF_GlyphIsProvided32 is recommended except SDL_ttf<2.0.18, TTF_GlyphIsProvided can be a fall back.

@yunline yunline added enhancement font pygame.font freetype pygame.freetype labels May 23, 2023
@yunline yunline added this to the 2.3 milestone May 23, 2023
@ankith26 ankith26 added the New API This pull request may need extra debate as it adds a new class or function to pygame label May 25, 2023
@Starbuck5 Starbuck5 modified the milestones: 2.3, 2.3.1 May 31, 2023
@dr0id dr0id marked this pull request as draft July 29, 2023 05:40
@Starbuck5 Starbuck5 modified the milestones: 2.3.1, 2.4.0 Jul 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement font pygame.font freetype pygame.freetype New API This pull request may need extra debate as it adds a new class or function to pygame
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants