-
Notifications
You must be signed in to change notification settings - Fork 143
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
Add functions to detect and configure Subpixel rendering mode #302
Conversation
8824323
to
feaf420
Compare
@1bsyl, can you rename the functions using "LCD" instead of "Lcd" and resolve the merge conflicts if you think this is still valuable? |
TTF_GetSubpixelMode() TTF_SetLCDFilter() TTF_SetLCDFilterWeights() TTF_SetLCDGeometry()
a6883d3
to
1779061
Compare
@slouken updated! |
I'm wondering now if instead of adding these APIs, we should expose the underlying FreeType library as an SDL3 property, so people can extend the font rendering however they like? |
I wonder if we can simplify the API more by having properties for font shaping, etc.? |
yes, it's would be better to give the FreeType handle to the user, so that he can do whatever he wants. Especially because the current functions of this PR are only 1to1 mapping with FreeType. On the other hand, I am not sure if exposing |
Okay, let's hold off merging while we consider this. |
We shouldn't expose the FreeType library handle, because there's no guarantee that the version of FreeType used by the application matches the one built into SDL_ttf. |
It also looks like FT_Library_SetLcdGeometry() is unimplemented in all builds of FreeType. Am I missing something? |
FYI, here's an attempt to update the header for these API functions to the new SDL 3.0 conventions: diff --git a/include/SDL3_ttf/SDL_ttf.h b/include/SDL3_ttf/SDL_ttf.h
index af278ff..c6e58c3 100644
--- a/include/SDL3_ttf/SDL_ttf.h
+++ b/include/SDL3_ttf/SDL_ttf.h
@@ -1382,6 +1384,100 @@ extern SDL_DECLSPEC bool SDLCALL TTF_GetGlyphScript(Uint32 ch, char *script, siz
*/
extern SDL_DECLSPEC bool TTF_SetFontLanguage(TTF_Font *font, const char *language_bcp47);
+/**
+ * Subpixel rendering mode
+ *
+ * \since This enum is available since SDL_ttf 3.0.0.
+ *
+ * \sa TTF_GetSubpixelMode
+ * \sa TTF_SetLCDGeometry
+ * \sa TTF_SetLCDFilter
+ * \sa TTF_SetLCDFilterWeights
+ */
+typedef enum
+{
+ TTF_SUBPIXEL_MODE_UNKNOWN, /**< Unknown */
+ TTF_SUBPIXEL_MODE_HARMONY, /**< Harmony LCD rendering */
+ TTF_SUBPIXEL_MODE_CLEARTYPE, /**< ClearType-style LCD rendering */
+} TTF_SubpixelMode;
+
+/**
+ * LCD filter, for ClearType-style LCD rendering mapping to FreeType FT_LcdFilter
+ *
+ * \since This enum is available since SDL_ttf 3.0.0.
+ */
+typedef enum
+{
+ TTF_LCD_FILTER_NONE,
+ TTF_LCD_FILTER_DEFAULT,
+ TTF_LCD_FILTER_LIGHT,
+ TTF_LCD_FILTER_LEGACY,
+} TTF_LCDFilter;
+
+/**
+ * Detect which subpixel rendering mode FreeType uses internally when LCD functions are used.
+ *
+ * \returns subpixel rendering mode
+ *
+ * \since This function is available since SDL_ttf 3.0.0
+ *
+ * \sa TTF_SetLCDGeometry
+ * \sa TTF_SetLCDFilter
+ * \sa TTF_SetLCDFilterWeights
+ */
+extern DECLSPEC TTF_SubpixelMode SDLCALL TTF_GetSubpixelMode(void);
+
+/**
+ * Set parameters for Harmony LCD rendering.
+ *
+ * See FreeType function FT_Library_SetLcdGeometry for more details
+ * Remark: FT_Library_SetLcdGeometry's y coordinates are in reverse from the usual SDL notation (larger = upper as opposed to larger = lower).
+ *
+ * \param font the font to configure
+ * \param pixel_coordinates an array of 6 positions of color subpixels
+ * \returns true on success or false on failure; call SDL_GetError()
+ * for more information.
+ *
+ * \since This function is available since SDL_ttf 3.0.0
+ *
+ * \sa TTF_GetSubpixelMode
+ */
+extern DECLSPEC int SDLCALL TTF_SetLCDGeometry(TTF_Font *font, const int *pixel_coordinates);
+
+/**
+ * Set a filter for ClearType-style LCD rendering.
+ *
+ * See FreeType function FT_Library_SetLcdFilter for more details
+ *
+ * \param font the font to configure
+ * \param filter filter to use
+ * \returns true on success or false on failure; call SDL_GetError()
+ * for more information.
+ *
+ * \since This function is available since SDL_ttf 3.0.0
+ *
+ * \sa TTF_GetSubpixelMode
+ * \sa TTF_SetLCDFilterWeights
+ */
+extern DECLSPEC bool SDLCALL TTF_SetLCDFilter(TTF_Font *font, TTF_LCDFilter filter);
+
+/**
+ * Set a custom filter for ClearType-style LCD rendering.
+ *
+ * See FreeType function FT_Library_SetLcdFilterWeights for more details
+ *
+ * \param font the font to configure
+ * \param weights an array of five bytes used as the filter weights in 1/256 units.
+ * \returns true on success or false on failure; call SDL_GetError()
+ * for more information.
+ *
+ * \since This function is available since SDL_ttf 3.0.0
+ *
+ * \sa TTF_GetSubpixelMode
+ * \sa TTF_SetLCDFilter
+ */
+extern DECLSPEC bool SDLCALL TTF_SetLCDFilterWeights(TTF_Font *font, const Uint8 *weights);
+
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
|
@slouken do you want this PR ? if so I can update to latest version |
I'm just confused because it looks like the functions we're calling/exposing just aren't available in default builds of FreeType. If that's true, then we probably shouldn't add them. |
Anyway, I wonder if people really needs this ... Current FreeType version 2.13.3 FT_Library_SetLcdFilter and FT_Library_SetLcdFilterWeights, same, but since 2.4.0 |
Yeah, let's not add this for now. Nice work on the patch though! |
Add functions to detect and configure Subpixel rendering mode
TTF_GetSubpixelMode()
TTF_SetLcdFilter()
TTF_SetLcdFilterWeights()
TTF_SetLcdGeometry()
see #296