Commit 72059224 authored by Naohiro KORIYAMA's avatar Naohiro KORIYAMA Committed by Francois Cartegnie

text_style/text_renderer: add support for halfwidth font

Fixed-by: default avatarFrancois Cartegnie <fcvlcdev@free.fr>
Signed-off-by: default avatarFrancois Cartegnie <fcvlcdev@free.fr>
parent 2da69726
...@@ -76,6 +76,7 @@ typedef struct ...@@ -76,6 +76,7 @@ typedef struct
#define STYLE_BACKGROUND 16 #define STYLE_BACKGROUND 16
#define STYLE_UNDERLINE 32 #define STYLE_UNDERLINE 32
#define STYLE_STRIKEOUT 64 #define STYLE_STRIKEOUT 64
#define STYLE_HALFWIDTH 128
#define STYLE_DEFAULT_FONT_SIZE 22 #define STYLE_DEFAULT_FONT_SIZE 22
......
...@@ -1331,9 +1331,16 @@ static int ProcessLines( filter_t *p_filter, ...@@ -1331,9 +1331,16 @@ static int ProcessLines( filter_t *p_filter,
p_face = LoadFace( p_filter, p_current_style ); p_face = LoadFace( p_filter, p_current_style );
} }
FT_Face p_current_face = p_face ? p_face : p_sys->p_face; 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 ); msg_Err( p_filter, "Failed to set font size to %d", p_current_style->i_font_size );
if( p_sys->p_stroker ) if( p_sys->p_stroker )
{ {
...@@ -1370,10 +1377,15 @@ static int ProcessLines( filter_t *p_filter, ...@@ -1370,10 +1377,15 @@ static int ProcessLines( filter_t *p_filter,
.x = pen.x + kerning.x, .x = pen.x + kerning.x,
.y = pen.y + kerning.y, .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 = { 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), .y = pen_new.y + p_sys->f_shadow_vector_y * (p_current_style->i_font_size << 6),
}; };
FT_Glyph glyph; FT_Glyph glyph;
FT_BBox glyph_bbox; FT_BBox glyph_bbox;
FT_Glyph outline; FT_Glyph outline;
...@@ -1693,7 +1705,8 @@ static int RenderCommon( filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -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 | p_region_in->p_style->i_style_flags & (STYLE_BOLD |
STYLE_ITALIC | STYLE_ITALIC |
STYLE_UNDERLINE | STYLE_UNDERLINE |
STYLE_STRIKEOUT) ); STYLE_STRIKEOUT |
STYLE_HALFWIDTH) );
else else
{ {
uint32_t i_font_color = var_InheritInteger( p_filter, "freetype-color" ); uint32_t i_font_color = var_InheritInteger( p_filter, "freetype-color" );
......
...@@ -79,7 +79,7 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region, ...@@ -79,7 +79,7 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region,
CFMutableAttributedStringRef p_attrString); CFMutableAttributedStringRef p_attrString);
static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_font_color, 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); CFRange p_range, CFMutableAttributedStringRef p_attrString);
/***************************************************************************** /*****************************************************************************
...@@ -312,9 +312,9 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out, ...@@ -312,9 +312,9 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
char *psz_string; char *psz_string;
int i_font_size; int i_font_size;
uint32_t i_font_color; 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; 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); VLC_UNUSED(p_chroma_list);
p_sys->i_font_size = GetFontSize(p_filter); 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, ...@@ -337,6 +337,8 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
b_italic = TRUE; b_italic = TRUE;
if (p_region_in->p_style->i_style_flags & STYLE_UNDERLINE) if (p_region_in->p_style->i_style_flags & STYLE_UNDERLINE)
b_uline = TRUE; b_uline = TRUE;
if (p_region_in->p_style->i_style_flags & STYLE_HALFWIDTH)
b_halfwidth = TRUE;
} }
} else { } else {
i_font_color = p_sys->i_font_color; 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, ...@@ -366,7 +368,7 @@ static int RenderText(filter_t *p_filter, subpicture_region_t *p_region_out,
CFRelease(p_cfString); CFRelease(p_cfString);
len = CFAttributedStringGetLength(p_attrString); 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); CFRangeMake(0, len), p_attrString);
RenderYUVA(p_filter, p_region_out, p_attrString); RenderYUVA(p_filter, p_region_out, p_attrString);
...@@ -523,12 +525,16 @@ static int HandleFontAttributes(xml_reader_t *p_xml_reader, ...@@ -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, 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) CFRange p_range, CFMutableAttributedStringRef p_attrString)
{ {
CFStringRef p_cfString; CFStringRef p_cfString;
CTFontRef p_font; 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 // fallback on default
if (!psz_fontname) if (!psz_fontname)
psz_fontname = (char *)DEFAULT_FONT; psz_fontname = (char *)DEFAULT_FONT;
...@@ -538,7 +544,7 @@ static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_fon ...@@ -538,7 +544,7 @@ static void setFontAttibutes(char *psz_fontname, int i_font_size, uint32_t i_fon
kCFStringEncodingUTF8); kCFStringEncodingUTF8);
p_font = CTFontCreateWithName(p_cfString, p_font = CTFontCreateWithName(p_cfString,
(float)i_font_size, (float)i_font_size,
NULL); &trans);
CFRelease(p_cfString); CFRelease(p_cfString);
CFAttributedStringSetAttribute(p_attrString, CFAttributedStringSetAttribute(p_attrString,
p_range, p_range,
...@@ -622,7 +628,7 @@ static void GetAttrStrFromFontStack(font_stack_t **p_fonts, ...@@ -622,7 +628,7 @@ static void GetAttrStrFromFontStack(font_stack_t **p_fonts,
setFontAttibutes(psz_fontname, setFontAttibutes(psz_fontname,
i_font_size, i_font_size,
i_font_color, i_font_color,
b_bold, b_italic, b_uline, b_bold, b_italic, b_uline, FALSE,
p_range, p_range,
p_attrString); p_attrString);
} }
...@@ -861,7 +867,7 @@ static CGContextRef CreateOffScreenContext(int i_width, int i_height, ...@@ -861,7 +867,7 @@ static CGContextRef CreateOffScreenContext(int i_width, int i_height,
return p_context; 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, CFMutableAttributedStringRef p_attrString,
unsigned i_width, unsigned i_width,
unsigned i_height, unsigned i_height,
...@@ -879,9 +885,9 @@ static offscreen_bitmap_t *Compose(int i_text_align, ...@@ -879,9 +885,9 @@ static offscreen_bitmap_t *Compose(int i_text_align,
CGContextSetTextMatrix(p_context, CGAffineTransformIdentity); CGContextSetTextMatrix(p_context, CGAffineTransformIdentity);
if (i_text_align == SUBPICTURE_ALIGN_RIGHT) if (p_region->i_align & SUBPICTURE_ALIGN_RIGHT)
horiz_flush = 1.0; 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; horiz_flush = 0.5;
else else
horiz_flush = 0.0; horiz_flush = 0.0;
...@@ -925,6 +931,8 @@ static offscreen_bitmap_t *Compose(int i_text_align, ...@@ -925,6 +931,8 @@ static offscreen_bitmap_t *Compose(int i_text_align,
double penOffset = CTLineGetPenOffsetForFlush(line, horiz_flush, (i_width - HORIZONTAL_MARGIN*2)); double penOffset = CTLineGetPenOffsetForFlush(line, horiz_flush, (i_width - HORIZONTAL_MARGIN*2));
penPosition.x = HORIZONTAL_MARGIN + penOffset; penPosition.x = HORIZONTAL_MARGIN + penOffset;
if (horiz_flush == 0.0)
penPosition.x = p_region->i_x;
penPosition.y -= ascent; penPosition.y -= ascent;
CGContextSetTextPosition(p_context, penPosition.x, penPosition.y); CGContextSetTextPosition(p_context, penPosition.x, penPosition.y);
CTLineDraw(line, p_context); CTLineDraw(line, p_context);
...@@ -969,14 +977,13 @@ static int RenderYUVA(filter_t *p_filter, subpicture_region_t *p_region, ...@@ -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_width = p_filter->fmt_out.video.i_visible_width;
unsigned i_height = p_filter->fmt_out.video.i_visible_height; unsigned i_height = p_filter->fmt_out.video.i_visible_height;
unsigned i_text_align = p_region->i_align & 0x3;
if (!p_attrString) { if (!p_attrString) {
msg_Err(p_filter, "Invalid argument to RenderYUVA"); msg_Err(p_filter, "Invalid argument to RenderYUVA");
return VLC_EGENERIC; 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); i_width, i_height, &i_textblock_height);
if (!p_offScreen) { if (!p_offScreen) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment