https://git.reactos.org/?p=reactos.git;a=commitdiff;h=bb7cf5a5b7d25308e570e…
commit bb7cf5a5b7d25308e570e6bf22a14957c4384e9c
Author:     Katayama Hirofumi MZ <katayama.hirofumi.mz(a)gmail.com>
AuthorDate: Wed Jan 22 10:57:40 2025 +0900
Commit:     GitHub <noreply(a)github.com>
CommitDate: Wed Jan 22 10:57:40 2025 +0900
    [FREETYPE][FTFD][NTGDI] Split FT_Bitmap_Convert hack (#7628)
    Our FT_Bitmap_Convert function had a hack to make the
    bitmap image compatible to ReactOS. I think the hack on
    FT_Bitmap_Convert should be separated from our font
    engine.
    JIRA issue: CORE-16047
    - Add FT_Bitmap_Convert_ReactOS_Hack function, that is
      based on FT_Bitmap_Convert, and split the hack of
      FT_Bitmap_Convert.
    - Use FT_Bitmap_Convert_ReactOS_Hack in
      IntGetBitmapGlyphWithCache function instead of
      FT_Bitmap_Convert.
    - Modify ftfd.spec to add
      FT_Bitmap_Convert_ReactOS_Hack.
---
 .../3rdparty/freetype/include/freetype/ftbitmap.h  | 35 ++++++++++++++
 sdk/lib/3rdparty/freetype/src/base/ftbitmap.c      | 53 +++++++++++++++++-----
 win32ss/drivers/font/ftfd/ftfd.spec                |  1 +
 win32ss/gdi/ntgdi/freetype.c                       |  3 +-
 4 files changed, 79 insertions(+), 13 deletions(-)
diff --git a/sdk/lib/3rdparty/freetype/include/freetype/ftbitmap.h
b/sdk/lib/3rdparty/freetype/include/freetype/ftbitmap.h
index a43187cad47..0b9f52a619c 100644
--- a/sdk/lib/3rdparty/freetype/include/freetype/ftbitmap.h
+++ b/sdk/lib/3rdparty/freetype/include/freetype/ftbitmap.h
@@ -181,6 +181,41 @@ FT_BEGIN_HEADER
                      FT_Bitmap        *target,
                      FT_Int            alignment );
+#ifdef __REACTOS__
+  /*************************************************************************/
+  /*                                                                       */
+  /* <Function>                                                            */
+  /*    FT_Bitmap_Convert_ReactOS_Hack                                     */
+  /*                                                                       */
+  /* <Description>                                                         */
+  /*    Mainly same as @FT_Bitmap_Convert, but the bitmap will be          */
+  /*    ReactOS compatible when hack parameter is true.                    */
+  /*                                                                       */
+  /* <Input>                                                               */
+  /*    library   :: A handle to a library object.                         */
+  /*                                                                       */
+  /*    source    :: The source bitmap.                                    */
+  /*                                                                       */
+  /*    alignment :: The pitch of the bitmap is a multiple of this         */
+  /*                 parameter.  Common values are 1, 2, or 4.             */
+  /*                                                                       */
+  /*    hack      :: If TRUE, the bitmap will be ReactOS compatible.       */
+  /*                 If FALSE, the bitmap will be same as                  */
+  /*                 FT_Bitmap_Convert returns.                            */
+  /*                                                                       */
+  /* <Output>                                                              */
+  /*    target    :: The target bitmap.                                    */
+  /*                                                                       */
+  /* <Return>                                                              */
+  /*    FreeType error code.  0~means success.                             */
+  /*                                                                       */
+  FT_EXPORT( FT_Error )
+  FT_Bitmap_Convert_ReactOS_Hack( FT_Library        library,
+                                  const FT_Bitmap  *source,
+                                  FT_Bitmap        *target,
+                                  FT_Int            alignment,
+                                  FT_Bool           hack);
+#endif
   /*************************************************************************/
   /*                                                                       */
diff --git a/sdk/lib/3rdparty/freetype/src/base/ftbitmap.c
b/sdk/lib/3rdparty/freetype/src/base/ftbitmap.c
index 5bfc13e2445..696db7368b1 100644
--- a/sdk/lib/3rdparty/freetype/src/base/ftbitmap.c
+++ b/sdk/lib/3rdparty/freetype/src/base/ftbitmap.c
@@ -500,11 +500,20 @@
   /* documentation is in ftbitmap.h */
+#ifdef __REACTOS__
+  FT_EXPORT_DEF( FT_Error )
+  FT_Bitmap_Convert_ReactOS_Hack( FT_Library        library,
+                                  const FT_Bitmap  *source,
+                                  FT_Bitmap        *target,
+                                  FT_Int            alignment,
+                                  FT_Bool           hack )
+#else
   FT_EXPORT_DEF( FT_Error )
   FT_Bitmap_Convert( FT_Library        library,
                      const FT_Bitmap  *source,
                      FT_Bitmap        *target,
                      FT_Int            alignment )
+#endif
   {
     FT_Error   error = FT_Err_Ok;
     FT_Memory  memory;
@@ -602,15 +611,20 @@
             FT_Int  val = ss[0]; /* avoid a byte->int cast on each line */
 #ifdef __REACTOS__
-            tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
-            tt[1] = (FT_Byte)( ( val & 0x40 ) ? 0xff : 0);
-            tt[2] = (FT_Byte)( ( val & 0x20 ) ? 0xff : 0);
-            tt[3] = (FT_Byte)( ( val & 0x10 ) ? 0xff : 0);
-            tt[4] = (FT_Byte)( ( val & 0x08 ) ? 0xff : 0);
-            tt[5] = (FT_Byte)( ( val & 0x04 ) ? 0xff : 0);
-            tt[6] = (FT_Byte)( ( val & 0x02 ) ? 0xff : 0);
-            tt[7] = (FT_Byte)( ( val & 0x01 ) ? 0xff : 0);
-#else
+            if (hack)
+            {
+                tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
+                tt[1] = (FT_Byte)( ( val & 0x40 ) ? 0xff : 0);
+                tt[2] = (FT_Byte)( ( val & 0x20 ) ? 0xff : 0);
+                tt[3] = (FT_Byte)( ( val & 0x10 ) ? 0xff : 0);
+                tt[4] = (FT_Byte)( ( val & 0x08 ) ? 0xff : 0);
+                tt[5] = (FT_Byte)( ( val & 0x04 ) ? 0xff : 0);
+                tt[6] = (FT_Byte)( ( val & 0x02 ) ? 0xff : 0);
+                tt[7] = (FT_Byte)( ( val & 0x01 ) ? 0xff : 0);
+            }
+            else
+            {
+#endif
             tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7 );
             tt[1] = (FT_Byte)( ( val & 0x40 ) >> 6 );
             tt[2] = (FT_Byte)( ( val & 0x20 ) >> 5 );
@@ -619,6 +633,8 @@
             tt[5] = (FT_Byte)( ( val & 0x04 ) >> 2 );
             tt[6] = (FT_Byte)( ( val & 0x02 ) >> 1 );
             tt[7] = (FT_Byte)(   val & 0x01 );
+#ifdef __REACTOS__
+            }
 #endif
             tt += 8;
@@ -635,10 +651,11 @@
             for ( ; j > 0; j-- )
             {
 #ifdef __REACTOS__
-              tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
-#else
-              tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
+              if (hack)
+                tt[0] = (FT_Byte)( ( val & 0x80 ) ? 0xff : 0);
+              else
 #endif
+              tt[0] = (FT_Byte)( ( val & 0x80 ) >> 7);
               val <<= 1;
               tt   += 1;
             }
@@ -794,6 +811,18 @@
     return error;
   }
+#ifdef __REACTOS__
+  /* documentation is in ftbitmap.h */
+
+  FT_EXPORT_DEF( FT_Error )
+  FT_Bitmap_Convert( FT_Library        library,
+                     const FT_Bitmap  *source,
+                     FT_Bitmap        *target,
+                     FT_Int            alignment )
+  {
+    return FT_Bitmap_Convert_ReactOS_Hack(library, source, target, alignment, FALSE);
+  }
+#endif
   /* documentation is in ftbitmap.h */
diff --git a/win32ss/drivers/font/ftfd/ftfd.spec b/win32ss/drivers/font/ftfd/ftfd.spec
index f4178ef7d11..f1b06a86989 100644
--- a/win32ss/drivers/font/ftfd/ftfd.spec
+++ b/win32ss/drivers/font/ftfd/ftfd.spec
@@ -6,6 +6,7 @@
   @ cdecl FT_Attach_File ()
   @ cdecl FT_Attach_Stream ()
   @ cdecl FT_Bitmap_Convert ()
+  @ cdecl FT_Bitmap_Convert_ReactOS_Hack ()
   @ cdecl FT_Bitmap_Copy ()
   @ cdecl FT_Bitmap_Done ()
   @ cdecl FT_Bitmap_Embolden ()
diff --git a/win32ss/gdi/ntgdi/freetype.c b/win32ss/gdi/ntgdi/freetype.c
index 86efc2e2c30..13932681b29 100644
--- a/win32ss/gdi/ntgdi/freetype.c
+++ b/win32ss/gdi/ntgdi/freetype.c
@@ -3852,7 +3852,8 @@ IntGetBitmapGlyphWithCache(
     BitmapGlyph = (FT_BitmapGlyph)GlyphCopy;
     FT_Bitmap_New(&AlignedBitmap);
-    if(FT_Bitmap_Convert(GlyphSlot->library, &BitmapGlyph->bitmap,
&AlignedBitmap, 4))
+    if (FT_Bitmap_Convert_ReactOS_Hack(GlyphSlot->library,
&BitmapGlyph->bitmap,
+                                       &AlignedBitmap, 4, TRUE))
     {
         DPRINT1("Conversion failed\n");
         ExFreePoolWithTag(NewEntry, TAG_FONT);