[vlc-commits] [Git][videolan/vlc][master] freetype: use UCS-4 encoding on OS/2, too

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Sun Aug 8 20:20:01 UTC 2021



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
89b561ea by KO Myung-Hun at 2021-08-08T18:45:52+00:00
freetype: use UCS-4 encoding on OS/2, too

This fixes subtitle texts are not shown correctly on OS/2.

Freetype module expects UCS-4 string. However, OS/2 iconv() does not
support UCS-4 encoding, so UCS-2 encoding is used on OS/2. Because of
this mis-match, subtitle texts on OS/2 are mis-interpreted. As a result,
subtitle texts are not shown correctly.

- - - - -


3 changed files:

- modules/text_renderer/freetype/freetype.c
- modules/text_renderer/freetype/freetype.h
- modules/text_renderer/freetype/text_layout.c


Changes:

=====================================
modules/text_renderer/freetype/freetype.c
=====================================
@@ -814,6 +814,40 @@ static void FreeStylesArray( text_style_t **pp_styles, size_t i_styles )
     free( pp_styles );
 }
 
+#ifdef __OS2__
+static void *ToUCS4( const char *in, size_t *outsize )
+{
+    uint16_t *psz_ucs2;
+    uint32_t *psz_ucs4;
+    size_t i_bytes;
+
+    psz_ucs2 = ToCharset("UCS-2LE", in, &i_bytes );
+    if( unlikely( !psz_ucs2 ) )
+        return NULL;
+
+    i_bytes <<= 1;
+    /* Realloc including NULL-terminator */
+    psz_ucs4 = realloc( psz_ucs2, i_bytes + sizeof( *psz_ucs4 ));
+    if( unlikely( !psz_ucs4 ) )
+    {
+        free( psz_ucs2 );
+
+        return NULL;
+    }
+
+    psz_ucs2 = ( uint16_t * )psz_ucs4;
+    /* Copy including NULL-terminator */
+    for( int i = i_bytes / sizeof( *psz_ucs4 ); i >= 0; --i )
+        psz_ucs4[ i ] = psz_ucs2[ i ];
+
+    *outsize = i_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,
@@ -821,7 +855,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;
 
@@ -877,7 +911,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));


=====================================
modules/text_renderer/freetype/freetype.h
=====================================
@@ -56,16 +56,11 @@
 # define FT_MulFix(v, s) (((v)*(s))>>16)
 #endif
 
-#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
-#  define FREETYPE_TO_UCS   "UCS-4LE"
-# endif
+#if defined(WORDS_BIGENDIAN)
+# define FREETYPE_TO_UCS   "UCS-4BE"
+#else
+# define FREETYPE_TO_UCS   "UCS-4LE"
 #endif
 
 #if FREETYPE_VERSION < MAKE_VERSION(2,1,5)


=====================================
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 );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/89b561eaa213582fff9625541edb5d7dbb299fb6

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/89b561eaa213582fff9625541edb5d7dbb299fb6
You're receiving this email because of your account on code.videolan.org.




More information about the vlc-commits mailing list