[vlc-devel] [PATCH 1/2] freetype: fix subtitle text does not show correctly on OS/2

KO Myung-Hun komh78 at gmail.com
Sun Feb 28 15:11:59 UTC 2021


---
 modules/text_renderer/freetype/freetype.c    | 42 +++++++++++++++++++-
 modules/text_renderer/freetype/freetype.h    |  3 +-
 modules/text_renderer/freetype/text_layout.c |  7 ----
 3 files changed, 41 insertions(+), 11 deletions(-)

diff --git a/modules/text_renderer/freetype/freetype.c b/modules/text_renderer/freetype/freetype.c
index 3303e46000..15c62e05a7 100644
--- a/modules/text_renderer/freetype/freetype.c
+++ b/modules/text_renderer/freetype/freetype.c
@@ -815,6 +815,44 @@ static void FreeStylesArray( text_style_t **pp_styles, size_t i_styles )
     free( pp_styles );
 }
 
+#ifdef __OS2__
+# define ToUCS4( in, outsize ) ToUCS4(( in ), ( outsize ))
+
+static void *( ToUCS4 )( const char *in, size_t *outsize )
+{
+    uint16_t *psz_ucs2;
+    size_t i_ucs4_bytes;
+    uni_char_t *psz_ucs4;
+    int i_len;
+
+    psz_ucs2 = ToCharset( FREETYPE_TO_UCS, in, outsize );
+    if( !psz_ucs2 )
+        return NULL;
+
+    i_ucs4_bytes = *outsize * 2;
+    /* Realloc including NULL-terminator */
+    psz_ucs4 = realloc( psz_ucs2, i_ucs4_bytes + sizeof( *psz_ucs4 ));
+    if( unlikely( !psz_ucs4 ) )
+    {
+        free( psz_ucs2 );
+
+        return NULL;
+    }
+
+    psz_ucs2 = ( uint16_t * )psz_ucs4;
+    i_len = i_ucs4_bytes / sizeof( *psz_ucs4 );
+    /* Copy including NULL-terminator */
+    for( int i = i_len; i >= 0; --i )
+        psz_ucs4[ i ] = psz_ucs2[ i ];
+
+    *outsize = i_ucs4_bytes;
+
+    return psz_ucs4;
+}
+#else
+# define ToUCS4( in, outsize ) ToCharset( FREETYPE_TO_UCS, ( in ), ( outsize ))
+#endif
+
 static size_t AddTextAndStyles( filter_sys_t *p_sys,
                                 const char *psz_text, const char *psz_rt,
                                 const text_style_t *p_style,
@@ -822,7 +860,7 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
 {
     /* Convert chars to unicode */
     size_t i_bytes;
-    uni_char_t *p_ucs4 = ToCharset( FREETYPE_TO_UCS, psz_text, &i_bytes );
+    uni_char_t *p_ucs4 = ToUCS4( psz_text, &i_bytes );
     if( !p_ucs4 )
         return 0;
 
@@ -878,7 +916,7 @@ static size_t AddTextAndStyles( filter_sys_t *p_sys,
     ruby_block_t *p_rubyblock = NULL;
     if( psz_rt )
     {
-        p_ucs4 = ToCharset( FREETYPE_TO_UCS, psz_rt, &i_bytes );
+        p_ucs4 = ToUCS4( psz_rt, &i_bytes );
         if( !p_ucs4 )
             return 0;
         p_rubyblock = malloc(sizeof(ruby_block_t));
diff --git a/modules/text_renderer/freetype/freetype.h b/modules/text_renderer/freetype/freetype.h
index ee69304ab9..d41acabc21 100644
--- a/modules/text_renderer/freetype/freetype.h
+++ b/modules/text_renderer/freetype/freetype.h
@@ -56,11 +56,10 @@
 # define FT_MulFix(v, s) (((v)*(s))>>16)
 #endif
 
+typedef uint32_t uni_char_t;
 #ifdef __OS2__
-typedef uint16_t uni_char_t;
 # define FREETYPE_TO_UCS    "UCS-2LE"
 #else
-typedef uint32_t uni_char_t;
 # if defined(WORDS_BIGENDIAN)
 #  define FREETYPE_TO_UCS   "UCS-4BE"
 # else
diff --git a/modules/text_renderer/freetype/text_layout.c b/modules/text_renderer/freetype/text_layout.c
index baee972832..fe60784da9 100644
--- a/modules/text_renderer/freetype/text_layout.c
+++ b/modules/text_renderer/freetype/text_layout.c
@@ -760,17 +760,10 @@ static int ShapeParagraphHarfBuzz( filter_t *p_filter,
 
         hb_buffer_set_direction( p_run->p_buffer, p_run->direction );
         hb_buffer_set_script( p_run->p_buffer, p_run->script );
-#ifdef __OS2__
-        hb_buffer_add_utf16( p_run->p_buffer,
-                             p_paragraph->p_code_points + p_run->i_start_offset,
-                             p_run->i_end_offset - p_run->i_start_offset, 0,
-                             p_run->i_end_offset - p_run->i_start_offset );
-#else
         hb_buffer_add_utf32( p_run->p_buffer,
                              p_paragraph->p_code_points + p_run->i_start_offset,
                              p_run->i_end_offset - p_run->i_start_offset, 0,
                              p_run->i_end_offset - p_run->i_start_offset );
-#endif
         hb_shape( p_hb_font, p_run->p_buffer, 0, 0 );
 
         hb_font_destroy( p_hb_font );
-- 
2.30.0



More information about the vlc-devel mailing list