Skip to content

Commit

Permalink
Merge branch 'libsdl-org:main' into gpu-text-engine
Browse files Browse the repository at this point in the history
  • Loading branch information
captain0xff authored Oct 25, 2024
2 parents f993143 + 8a9167d commit d80f917
Show file tree
Hide file tree
Showing 12 changed files with 1,067 additions and 445 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ if(SDLTTF_INSTALL)
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT library
)
install(FILES
"${CMAKE_CURRENT_SOURCE_DIR}/include/SDL3_ttf/SDL_textengine.h"
"${CMAKE_CURRENT_SOURCE_DIR}/include/SDL3_ttf/SDL_ttf.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/SDL3_ttf" COMPONENT devel
)
Expand Down Expand Up @@ -383,6 +384,9 @@ if(SDLTTF_SAMPLES)
sdl_add_warning_options(${prog} WARNING_AS_ERROR ${SDLTTF_WERROR})
target_link_libraries(${prog} PRIVATE SDL3_ttf::${sdl3_ttf_target_name})
target_link_libraries(${prog} PRIVATE ${sdl3_target_name})
if("c_std_99" IN_LIST CMAKE_C_COMPILE_FEATURES)
target_compile_features(${prog} PRIVATE c_std_99)
endif()

if(SDLTTF_SAMPLES_INSTALL)
install(TARGETS ${prog}
Expand Down
5 changes: 5 additions & 0 deletions Xcode/SDL_ttf.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
BE48FD5F07AFA17000BB41DA /* SDL_ttf.h in Headers */ = {isa = PBXBuildFile; fileRef = 1014BAEA010A4B677F000001 /* SDL_ttf.h */; settings = {ATTRIBUTES = (Public, ); }; };
BE48FD6207AFA17000BB41DA /* SDL_ttf.c in Sources */ = {isa = PBXBuildFile; fileRef = F567D67A01CD962A01F3E8B9 /* SDL_ttf.c */; };
F307EE29282738F8003915D7 /* svg.c in Sources */ = {isa = PBXBuildFile; fileRef = F307EE28282738F8003915D7 /* svg.c */; };
F33F083D2CC41C810062C26D /* SDL_textengine.h in Headers */ = {isa = PBXBuildFile; fileRef = F33F083C2CC41C810062C26D /* SDL_textengine.h */; settings = {ATTRIBUTES = (Public, ); }; };
F364A5B82620E1A200325ECE /* FTL.TXT in Resources */ = {isa = PBXBuildFile; fileRef = F364A5B72620E1A200325ECE /* FTL.TXT */; };
F364A5C42620E22400325ECE /* ReadMe.txt in Resources */ = {isa = PBXBuildFile; fileRef = F364A5C32620E22400325ECE /* ReadMe.txt */; };
F3696FE4278F7107003A7F94 /* sdf.c in Sources */ = {isa = PBXBuildFile; fileRef = F3696FE3278F7107003A7F94 /* sdf.c */; };
Expand Down Expand Up @@ -196,6 +197,7 @@
BE48FD6707AFA17000BB41DA /* SDL3_ttf.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SDL3_ttf.framework; sourceTree = BUILT_PRODUCTS_DIR; };
BE48FD8307AFA29000BB41DA /* SDL3.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = SDL3.framework; sourceTree = "<group>"; };
F307EE28282738F8003915D7 /* svg.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = svg.c; path = ../external/freetype/src/svg/svg.c; sourceTree = "<group>"; };
F33F083C2CC41C810062C26D /* SDL_textengine.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SDL_textengine.h; sourceTree = "<group>"; };
F364A5B72620E1A200325ECE /* FTL.TXT */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = FTL.TXT; path = ../../../external/freetype/docs/FTL.TXT; sourceTree = "<group>"; };
F364A5C32620E22400325ECE /* ReadMe.txt */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = ReadMe.txt; sourceTree = "<group>"; };
F3696FE3278F7107003A7F94 /* sdf.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = sdf.c; path = ../external/freetype/src/sdf/sdf.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -298,9 +300,11 @@
0153844A006D81B07F000001 /* Public Headers */ = {
isa = PBXGroup;
children = (
F33F083C2CC41C810062C26D /* SDL_textengine.h */,
1014BAEA010A4B677F000001 /* SDL_ttf.h */,
);
name = "Public Headers";
path = ../include/SDL3_ttf;
sourceTree = "<group>";
};
034768DDFF38A45A11DB9C8B /* Products */ = {
Expand Down Expand Up @@ -542,6 +546,7 @@
F3F7BDF72CB6FD6700C984AF /* SDL_hashtable.h in Headers */,
F3F7BDF82CB6FD6700C984AF /* stb_rect_pack.h in Headers */,
BE48FD5F07AFA17000BB41DA /* SDL_ttf.h in Headers */,
F33F083D2CC41C810062C26D /* SDL_textengine.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
8 changes: 3 additions & 5 deletions docs/README-migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ Several functions have been renamed. We have provided a handy semantic patch to

In general we have switched to using UTF8 in the API. Functions which had 3 variants, for Latin-1, UTF-8, and UCS2, now accept UTF-8 text. In addition, those functions now have an optional length parameter which allows you to render substrings.

The solid color rendering functions have been removed in favor of the higher quality shaded and blended functions.

The alpha in background colors is now transparent if it's equal to 0.

The following functions have been renamed:
Expand All @@ -58,12 +56,15 @@ The following functions have been renamed:
* TTF_RenderGlyph32_Blended() => TTF_RenderGlyph_Blended()
* TTF_RenderGlyph32_LCD() => TTF_RenderGlyph_LCD()
* TTF_RenderGlyph32_Shaded() => TTF_RenderGlyph_Shaded()
* TTF_RenderGlyph32_Solid() => TTF_RenderGlyph_Solid()
* TTF_RenderUTF8_Blended() => TTF_RenderText_Blended()
* TTF_RenderUTF8_Blended_Wrapped() => TTF_RenderText_Blended_Wrapped()
* TTF_RenderUTF8_LCD() => TTF_RenderText_LCD()
* TTF_RenderUTF8_LCD_Wrapped() => TTF_RenderText_LCD_Wrapped()
* TTF_RenderUTF8_Shaded() => TTF_RenderText_Shaded()
* TTF_RenderUTF8_Shaded_Wrapped() => TTF_RenderText_Shaded_Wrapped()
* TTF_RenderUTF8_Solid() => TTF_RenderText_Solid()
* TTF_RenderUTF8_Solid_Wrapped() => TTF_RenderText_Solid_Wrapped()
* TTF_SetFontScriptName() => TTF_SetFontScript()
* TTF_SetFontWrappedAlign() => TTF_SetFontWrapAlignment()
* TTF_SizeText() => TTF_GetTextSize()
Expand All @@ -81,7 +82,6 @@ The following functions have been removed:
* TTF_OpenFontIndexDPI() - replaced with TTF_OpenFontWithProperties()
* TTF_OpenFontIndexDPIIO() - replaced with TTF_OpenFontWithProperties()
* TTF_OpenFontIndexIO() - replaced with TTF_OpenFontWithProperties()
* TTF_RenderGlyph32_Solid()
* TTF_RenderGlyph_Solid()
* TTF_RenderText_Solid()
* TTF_RenderText_Solid_Wrapped()
Expand All @@ -93,8 +93,6 @@ The following functions have been removed:
* TTF_RenderUNICODE_Shaded_Wrapped()
* TTF_RenderUNICODE_Solid()
* TTF_RenderUNICODE_Solid_Wrapped()
* TTF_RenderUTF8_Solid()
* TTF_RenderUTF8_Solid_Wrapped()
* TTF_SizeUNICODE()

The following symbols have been renamed:
Expand Down
14 changes: 11 additions & 3 deletions examples/editbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ static void SaveCandidates(EditBox *edit, const SDL_Event *event)
}
*dst = '\0';

edit->candidates = TTF_CreateText_Wrapped(TTF_GetTextEngine(edit->text), edit->font, candidate_text, 0, 0);
edit->candidates = TTF_CreateText(TTF_GetTextEngine(edit->text), edit->font, candidate_text, 0);
SDL_free(candidate_text);
if (edit->candidates) {
SDL_copyp(&edit->candidates->color, &edit->text->color);
float r, g, b, a;
TTF_GetTextColorFloat(edit->text, &r, &g, &b, &a);
TTF_SetTextColorFloat(edit->candidates, r, g, b, a);
} else {
ClearCandidates(edit);
}
Expand Down Expand Up @@ -333,7 +335,7 @@ EditBox *EditBox_Create(SDL_Window *window, SDL_Renderer *renderer, TTF_TextEngi
edit->window = window;
edit->renderer = renderer;
edit->font = font;
edit->text = TTF_CreateText_Wrapped(engine, font, NULL, 0, (int)SDL_floorf(rect->w));
edit->text = TTF_CreateText(engine, font, NULL, 0);
if (!edit->text) {
EditBox_Destroy(edit);
return NULL;
Expand All @@ -342,6 +344,12 @@ EditBox *EditBox_Create(SDL_Window *window, SDL_Renderer *renderer, TTF_TextEngi
edit->highlight1 = -1;
edit->highlight2 = -1;

/* Wrap the editbox text within the editbox area */
TTF_SetTextWrapWidth(edit->text, (int)SDL_floorf(rect->w));

/* Show the whitespace when wrapping, so it can be edited */
TTF_SetTextWrapWhitespaceVisible(edit->text, true);

#ifdef TEST_SURFACE_ENGINE
/* Grab the window surface if we want to test the surface text engine.
* This isn't strictly necessary, we can still use the renderer if it's
Expand Down
Loading

0 comments on commit d80f917

Please sign in to comment.