-
Notifications
You must be signed in to change notification settings - Fork 55
Add ege_setfont support for GDI+ font usage with floating-point sizes #358
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
Copilot
wants to merge
20
commits into
master
Choose a base branch
from
copilot/add-egesetfont-support
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2babfb4
Initial plan
Copilot 29d4aaf
Add ege_setfont implementation with GDI+ Font support
Copilot ee4b9e0
Address code review feedback: improve font fallback and fix sprintf
Copilot 08f0374
Fix demo to use proper GDI+ constants and improve font fallback
Copilot 88bb75c
Fix FontFamily handling to use proper lifetime management
Copilot dbefef3
Use safer swprintf_s and optimize GenericSansSerif usage
Copilot 7d2bf54
Code quality improvements: simplify array size and null checks
Copilot 558aacd
Add input validation for typeface and size parameters
Copilot 3f7585b
Fix const parameter modification and add final fallback validation
Copilot ddfd070
修复了编译错误
FeJS8888 3024259
Fix documentation and use UnitPixel for size consistency with GDI
Copilot adabb6d
Fix GDI+ font size to match GDI by using Font(HDC, HFONT) conversion
Copilot b4a768d
Fix measuretext to match ege_drawtext_p StringFormat flags
Copilot fa9fd88
Use MeasureString instead of MeasureCharacterRanges for accurate bounds
Copilot c0569ac
Fix floating-point font size precision by scaling from rounded LOGFONT
Copilot d84cb5e
Simplify ege_setfont to use direct Font creation with UnitPixel
Copilot cbabbe7
修复了 GDI+ 绘制文字和 GDI 绘制大小不匹配的问题
FeJS8888 11bc687
移除了无用代码
FeJS8888 7802c19
Add NULL checks to ANSI ege_setfont functions for security
Copilot 4b34902
Update documentation to clarify size adjustment for GDI compatibility
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| /* | ||
| * Test demo for ege_setfont function | ||
| * This demo demonstrates the use of floating-point font sizes with GDI+ | ||
| * Font sizes are in pixels to match the existing setfont() behavior | ||
| */ | ||
|
|
||
| #include <graphics.h> | ||
| #include <stdio.h> | ||
|
|
||
| int main() | ||
| { | ||
| // Initialize graphics window | ||
| initgraph(800, 600); | ||
| setbkcolor(WHITE); | ||
| cleardevice(); | ||
|
|
||
| // Test 1: Basic ege_setfont with floating-point size | ||
| settextcolor(BLACK); | ||
| ege_setfont(24.5f, L"Arial"); | ||
| ege_drawtext(L"24.5px Arial font (floating-point size)", 50.0f, 50.0f); | ||
|
|
||
| // Test 2: Different sizes to show precision | ||
| ege_setfont(12.0f, L"Times New Roman"); | ||
| ege_drawtext(L"12.0px Times New Roman", 50.0f, 100.0f); | ||
|
|
||
| ege_setfont(12.5f, L"Times New Roman"); | ||
| ege_drawtext(L"12.5px Times New Roman", 50.0f, 120.0f); | ||
|
|
||
| ege_setfont(13.0f, L"Times New Roman"); | ||
| ege_drawtext(L"13.0px Times New Roman", 50.0f, 140.0f); | ||
|
|
||
| // Test 3: With font styles | ||
| ege_setfont(20.0f, L"Arial", Gdiplus::FontStyleBold); | ||
| ege_drawtext(L"20px Arial Bold", 50.0f, 200.0f); | ||
|
|
||
| ege_setfont(18.0f, L"Arial", Gdiplus::FontStyleItalic); | ||
| ege_drawtext(L"18px Arial Italic", 50.0f, 240.0f); | ||
|
|
||
| ege_setfont(16.0f, L"Arial", Gdiplus::FontStyleBold | Gdiplus::FontStyleItalic); | ||
| ege_drawtext(L"16px Arial Bold Italic", 50.0f, 280.0f); | ||
|
|
||
| ege_setfont(14.0f, L"Arial", Gdiplus::FontStyleUnderline); | ||
| ege_drawtext(L"14px Arial Underline", 50.0f, 320.0f); | ||
FeJS8888 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Test 4: Very precise sizes | ||
| ege_setfont(15.25f, L"Courier New"); | ||
| ege_drawtext(L"15.25px Courier New (very precise)", 50.0f, 380.0f); | ||
|
|
||
| // Test 5: Chinese characters with floating-point size | ||
| ege_setfont(22.5f, L"SimSun"); | ||
| ege_drawtext(L"22.5像素宋体 - 中文测试", 50.0f, 430.0f); | ||
|
|
||
| // Test 6: Compare with measuretext | ||
| float width, height; | ||
| const wchar_t* testText = L"Test measuretext with GDI+ Font"; | ||
| ege_setfont(18.0f, L"Arial"); | ||
| measuretext(testText, &width, &height); | ||
|
|
||
| const size_t INFO_BUFFER_SIZE = 256; | ||
| wchar_t info[INFO_BUFFER_SIZE]; | ||
| #if defined(_MSC_VER) && (_MSC_VER >= 1400) | ||
| swprintf_s(info, INFO_BUFFER_SIZE, L"Width: %.2f, Height: %.2f", width, height); | ||
| #else | ||
| swprintf(info, INFO_BUFFER_SIZE, L"Width: %.2f, Height: %.2f", width, height); | ||
| #endif | ||
| ege_drawtext(testText, 50.0f, 480.0f); | ||
| ege_setfont(12.0f, L"Arial"); | ||
| ege_drawtext(info, 50.0f, 510.0f); | ||
|
|
||
| // Instructions | ||
| ege_setfont(14.0f, L"Arial"); | ||
| settextcolor(BLUE); | ||
| ege_drawtext(L"Press any key to exit...", 50.0f, 550.0f); | ||
|
|
||
| // Wait for key press | ||
| getch(); | ||
| closegraph(); | ||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.