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

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Aug 12 14:05:05 UTC 2021



Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC


Commits:
10e0c8e1 by KO Myung-Hun at 2021-08-09T22:24:17+09: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.

(cherry picked from commit 89b561eaa213582fff9625541edb5d7dbb299fb6)

  Conflicts:
    modules/text_renderer/freetype/freetype.c
    modules/text_renderer/freetype/text_layout.c

- - - - -


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
=====================================
@@ -1049,6 +1049,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 uni_char_t* SegmentsToTextAndStyles( filter_t *p_filter, const text_segment_t *p_segment, size_t *pi_string_length,
                                             text_style_t ***ppp_styles, size_t *pi_styles )
 {
@@ -1062,7 +1096,7 @@ static uni_char_t* SegmentsToTextAndStyles( filter_t *p_filter, const text_segme
         if( !s->psz_text || !s->psz_text[0] )
             continue;
         size_t i_string_bytes = 0;
-        uni_char_t *psz_tmp = ToCharset( FREETYPE_TO_UCS, s->psz_text, &i_string_bytes );
+        uni_char_t *psz_tmp = ToUCS4( s->psz_text, &i_string_bytes );
         if( !psz_tmp )
         {
             free( psz_uni );


=====================================
modules/text_renderer/freetype/freetype.h
=====================================
@@ -54,16 +54,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
 
 /*****************************************************************************


=====================================
modules/text_renderer/freetype/text_layout.c
=====================================
@@ -735,17 +735,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_run->p_hb_font, p_run->p_buffer, 0, 0 );
         p_run->p_glyph_infos =
             hb_buffer_get_glyph_infos( p_run->p_buffer, &p_run->i_glyph_count );



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/10e0c8e1cb643198d229df0f86680c9e7d8bc50b

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




More information about the vlc-commits mailing list