]> git.sesse.net Git - vlc/commitdiff
text_style/text_renderer: add support for halfwidth font
authorNaohiro KORIYAMA <nkoriyama@gmail.com>
Sun, 10 Jun 2012 01:50:50 +0000 (10:50 +0900)
committerFrancois Cartegnie <fcvlcdev@free.fr>
Tue, 5 Aug 2014 05:36:40 +0000 (14:36 +0900)
Fixed-by: Francois Cartegnie <fcvlcdev@free.fr>
Signed-off-by: Francois Cartegnie <fcvlcdev@free.fr>
include/vlc_text_style.h
modules/text_renderer/freetype.c
modules/text_renderer/quartztext.c

index 51677243e472c3e7712f1a0b168a647433f7470b..d0a112efb5584361dd470249f0bedeceed3d4603 100644 (file)
@@ -76,6 +76,7 @@ typedef struct
 #define STYLE_BACKGROUND  16
 #define STYLE_UNDERLINE   32
 #define STYLE_STRIKEOUT   64
+#define STYLE_HALFWIDTH   128
 
 #define STYLE_DEFAULT_FONT_SIZE 22
 
index f7fcd80f34338d9c1dbc569f997904ed4a8d0f30..55b85a557c05454c2130bd3a2a1ed75a4f9121b0 100644 (file)
@@ -1331,9 +1331,16 @@ static int ProcessLines( filter_t *p_filter,
                 p_face = LoadFace( p_filter, p_current_style );
             }
             FT_Face p_current_face = p_face ? p_face : p_sys->p_face;
-            if( !p_previous_style || p_previous_style->i_font_size != p_current_style->i_font_size )
+            if( !p_previous_style || p_previous_style->i_font_size != p_current_style->i_font_size ||
+                ((p_previous_style->i_style_flags ^ p_current_style->i_style_flags) & STYLE_HALFWIDTH) )
+
             {
-                if( FT_Set_Pixel_Sizes( p_current_face, 0, p_current_style->i_font_size ) )
+                int i_font_width = ( p_current_style->i_style_flags & STYLE_HALFWIDTH )
+                                    ? p_current_style->i_font_size / 2
+                                    : p_current_style->i_font_size;
+                if( FT_Set_Pixel_Sizes( p_current_face,
+                                        i_font_width,
+                                        p_current_style->i_font_size ) )
                     msg_Err( p_filter, "Failed to set font size to %d", p_current_style->i_font_size );
                 if( p_sys->p_stroker )
                 {
@@ -1370,10 +1377,15 @@ static int ProcessLines( filter_t *p_filter,
                     .x = pen.x + kerning.x,
                     .y = pen.y + kerning.y,
                 };
+
+                int i_font_width = ( p_current_style->i_style_flags & STYLE_HALFWIDTH )
+                                    ? p_current_style->i_font_size / 2
+                                    : p_current_style->i_font_size;
                 FT_Vector pen_shadow_new = {
-                    .x = pen_new.x + p_sys->f_shadow_vector_x * (p_current_style->i_font_size << 6),
+                    .x = pen_new.x + p_sys->f_shadow_vector_x * (i_font_width << 6),
                     .y = pen_new.y + p_sys->f_shadow_vector_y * (p_current_style->i_font_size << 6),
                 };
+
                 FT_Glyph glyph;
                 FT_BBox  glyph_bbox;
                 FT_Glyph outline;
@@ -1693,7 +1705,8 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out,
                                    p_region_in->p_style->i_style_flags & (STYLE_BOLD |
                                                                           STYLE_ITALIC |
                                                                           STYLE_UNDERLINE |
-                                                                          STYLE_STRIKEOUT) );
+                                                                          STYLE_STRIKEOUT |
+                                                                          STYLE_HALFWIDTH) );
         else
         {
             uint32_t i_font_color = var_InheritInteger( p_filter, "freetype-color" );
index 8de10818f21591f2d8160082799fa405590c4e52..ceb97a67beabd168a8e2cd77589bc147eef900e1 100644 (file)
@@ -79,7 +79,7 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region,
                        CFMutableAttributedStringRef p_attrString);
 
 static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_font_color,
-                              bool b_bold, bool b_italic, bool b_underline,
+                              bool b_bold, bool b_italic, bool b_underline, bool b_halfwidth,
                               CFRange p_range, CFMutableAttributedStringRef p_attrString);
 
 /*****************************************************************************
@@ -312,9 +312,9 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
     char         *psz_string;
     int           i_font_size;
     uint32_t      i_font_color;
-    bool          b_bold, b_uline, b_italic;
+    bool          b_bold, b_uline, b_italic, b_halfwidth;
     vlc_value_t val;
-    b_bold = b_uline = b_italic = FALSE;
+    b_bold = b_uline = b_italic = b_halfwidth = FALSE;
     VLC_UNUSED(p_chroma_list);
 
     p_sys->i_font_size = GetFontSize(p_filter);
@@ -337,6 +337,8 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
                 b_italic = TRUE;
             if (p_region_in->p_style->i_style_flags & STYLE_UNDERLINE)
                 b_uline = TRUE;
+            if (p_region_in->p_style->i_style_flags & STYLE_HALFWIDTH)
+                b_halfwidth = TRUE;
         }
     } else {
         i_font_color = p_sys->i_font_color;
@@ -366,7 +368,7 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
         CFRelease(p_cfString);
         len = CFAttributedStringGetLength(p_attrString);
 
-        setFontAttibutes(p_sys->psz_font_name, i_font_size, i_font_color, b_bold, b_italic, b_uline,
+        setFontAttibutes(p_sys->psz_font_name, i_font_size, i_font_color, b_bold, b_italic, b_uline, b_halfwidth,
                                              CFRangeMake(0, len), p_attrString);
 
         RenderYUVA(p_filter, p_region_out, p_attrString);
@@ -523,12 +525,16 @@ static int HandleFontAttributes(xml_reader_t *p_xml_reader,
 }
 
 static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_font_color,
-        bool b_bold, bool b_italic, bool b_underline,
+        bool b_bold, bool b_italic, bool b_underline, bool b_halfwidth,
         CFRange p_range, CFMutableAttributedStringRef p_attrString)
 {
     CFStringRef p_cfString;
     CTFontRef   p_font;
 
+    int i_font_width = b_halfwidth ? i_font_size / 2 : i_font_size;
+    CGAffineTransform trans = CGAffineTransformMakeScale((float)i_font_width
+                                                         / i_font_size, 1.0);
+
     // fallback on default
     if (!psz_fontname)
         psz_fontname = (char *)DEFAULT_FONT;
@@ -538,7 +544,7 @@ static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_fon
                                             kCFStringEncodingUTF8);
     p_font     = CTFontCreateWithName(p_cfString,
                                        (float)i_font_size,
-                                       NULL);
+                                       &trans);
     CFRelease(p_cfString);
     CFAttributedStringSetAttribute(p_attrString,
                                     p_range,
@@ -622,7 +628,7 @@ static void GetAttrStrFromFontStack(font_stack_t **p_fonts,
         setFontAttibutes(psz_fontname,
                          i_font_size,
                          i_font_color,
-                         b_bold, b_italic, b_uline,
+                         b_bold, b_italic, b_uline, FALSE,
                          p_range,
                          p_attrString);
     }
@@ -861,7 +867,7 @@ static CGContextRef CreateOffScreenContext(int i_width, int i_height,
     return p_context;
 }
 
-static offscreen_bitmap_t *Compose(int i_text_align,
+static offscreen_bitmap_t *Compose( subpicture_region_t *p_region,
                                     CFMutableAttributedStringRef p_attrString,
                                     unsigned i_width,
                                     unsigned i_height,
@@ -879,9 +885,9 @@ static offscreen_bitmap_t *Compose(int i_text_align,
 
         CGContextSetTextMatrix(p_context, CGAffineTransformIdentity);
 
-        if (i_text_align == SUBPICTURE_ALIGN_RIGHT)
+        if (p_region->i_align & SUBPICTURE_ALIGN_RIGHT)
             horiz_flush = 1.0;
-        else if (i_text_align != SUBPICTURE_ALIGN_LEFT)
+        else if ((p_region->i_align & SUBPICTURE_ALIGN_LEFT) == 0)
             horiz_flush = 0.5;
         else
             horiz_flush = 0.0;
@@ -925,6 +931,8 @@ static offscreen_bitmap_t *Compose(int i_text_align,
 
                     double penOffset = CTLineGetPenOffsetForFlush(line, horiz_flush, (i_width  - HORIZONTAL_MARGIN*2));
                     penPosition.x = HORIZONTAL_MARGIN + penOffset;
+                    if (horiz_flush == 0.0)
+                        penPosition.x = p_region->i_x;
                     penPosition.y -= ascent;
                     CGContextSetTextPosition(p_context, penPosition.x, penPosition.y);
                     CTLineDraw(line, p_context);
@@ -969,14 +977,13 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region,
 
     unsigned i_width = p_filter->fmt_out.video.i_visible_width;
     unsigned i_height = p_filter->fmt_out.video.i_visible_height;
-    unsigned i_text_align = p_region->i_align & 0x3;
 
     if (!p_attrString) {
         msg_Err(p_filter, "Invalid argument to RenderYUVA");
         return VLC_EGENERIC;
     }
 
-    p_offScreen = Compose(i_text_align, p_attrString,
+    p_offScreen = Compose( p_region, p_attrString,
                            i_width, i_height, &i_textblock_height);
 
     if (!p_offScreen) {