Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
videolan
vlc
Commits
df0d3087
Commit
df0d3087
authored
Aug 12, 2015
by
Francois Cartegnie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
text_renderer: win32text: correctly handle text_segment and style inheritance
parent
2f3d0d19
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
35 deletions
+55
-35
modules/text_renderer/win32text.c
modules/text_renderer/win32text.c
+55
-35
No files found.
modules/text_renderer/win32text.c
View file @
df0d3087
...
@@ -122,11 +122,8 @@ vlc_module_end ()
...
@@ -122,11 +122,8 @@ vlc_module_end ()
*****************************************************************************/
*****************************************************************************/
struct
filter_sys_t
struct
filter_sys_t
{
{
uint8_t
i_font_opacity
;
text_style_t
*
p_default_style
;
int
i_font_color
;
int
i_font_size
;
int
i_default_font_size
;
int
i_display_height
;
int
i_display_height
;
HDC
hcdc
;
HDC
hcdc
;
...
@@ -154,7 +151,13 @@ static int Create( vlc_object_t *p_this )
...
@@ -154,7 +151,13 @@ static int Create( vlc_object_t *p_this )
p_filter
->
p_sys
=
p_sys
=
malloc
(
sizeof
(
filter_sys_t
)
);
p_filter
->
p_sys
=
p_sys
=
malloc
(
sizeof
(
filter_sys_t
)
);
if
(
!
p_sys
)
if
(
!
p_sys
)
return
VLC_ENOMEM
;
return
VLC_ENOMEM
;
p_sys
->
i_font_size
=
0
;
p_sys
->
p_default_style
=
text_style_Create
(
STYLE_FULLY_SET
);
if
(
unlikely
(
!
p_sys
->
p_default_style
)
)
{
free
(
p_sys
);
return
VLC_ENOMEM
;
}
p_sys
->
i_display_height
=
0
;
p_sys
->
i_display_height
=
0
;
var_Create
(
p_filter
,
"win32text-font"
,
var_Create
(
p_filter
,
"win32text-font"
,
...
@@ -163,14 +166,16 @@ static int Create( vlc_object_t *p_this )
...
@@ -163,14 +166,16 @@ static int Create( vlc_object_t *p_this )
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
var_Create
(
p_filter
,
"win32text-rel-fontsize"
,
var_Create
(
p_filter
,
"win32text-rel-fontsize"
,
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
var_Create
(
p_filter
,
"win32text-opacity"
,
var_Create
(
p_filter
,
"win32text-opacity"
,
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
var_Get
(
p_filter
,
"win32text-opacity"
,
&
val
);
var_Get
(
p_filter
,
"win32text-opacity"
,
&
val
);
p_sys
->
i_font_opacity
=
VLC_CLIP
(
val
.
i_int
,
0
,
255
);
p_sys
->
p_default_style
->
i_font_alpha
=
VLC_CLIP
(
val
.
i_int
,
0
,
255
);
var_Create
(
p_filter
,
"win32text-color"
,
var_Create
(
p_filter
,
"win32text-color"
,
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
VLC_VAR_INTEGER
|
VLC_VAR_DOINHERIT
);
var_Get
(
p_filter
,
"win32text-color"
,
&
val
);
var_Get
(
p_filter
,
"win32text-color"
,
&
val
);
p_sys
->
i_font_color
=
VLC_CLIP
(
val
.
i_int
,
0
,
0xFFFFFF
);
p_sys
->
p_default_style
->
i_font_color
=
VLC_CLIP
(
val
.
i_int
,
0
,
0xFFFFFF
);
p_sys
->
hfont
=
p_sys
->
hfont_bak
=
0
;
p_sys
->
hfont
=
p_sys
->
hfont_bak
=
0
;
hdc
=
GetDC
(
NULL
);
hdc
=
GetDC
(
NULL
);
...
@@ -180,7 +185,8 @@ static int Create( vlc_object_t *p_this )
...
@@ -180,7 +185,8 @@ static int Create( vlc_object_t *p_this )
SetBkMode
(
p_sys
->
hcdc
,
TRANSPARENT
);
SetBkMode
(
p_sys
->
hcdc
,
TRANSPARENT
);
var_Get
(
p_filter
,
"win32text-fontsize"
,
&
val
);
var_Get
(
p_filter
,
"win32text-fontsize"
,
&
val
);
p_sys
->
i_default_font_size
=
val
.
i_int
;
if
(
val
.
i_int
)
p_sys
->
p_default_style
->
i_font_size
=
val
.
i_int
;
if
(
SetFont
(
p_filter
,
0
)
!=
VLC_SUCCESS
)
goto
error
;
if
(
SetFont
(
p_filter
,
0
)
!=
VLC_SUCCESS
)
goto
error
;
free
(
psz_fontfile
);
free
(
psz_fontfile
);
...
@@ -188,6 +194,7 @@ static int Create( vlc_object_t *p_this )
...
@@ -188,6 +194,7 @@ static int Create( vlc_object_t *p_this )
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
error:
error:
text_style_Delete
(
p_sys
->
p_default_style
);
free
(
psz_fontfile
);
free
(
psz_fontfile
);
free
(
p_sys
);
free
(
p_sys
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
...
@@ -204,6 +211,7 @@ static void Destroy( vlc_object_t *p_this )
...
@@ -204,6 +211,7 @@ static void Destroy( vlc_object_t *p_this )
if
(
p_sys
->
hfont_bak
)
SelectObject
(
p_sys
->
hcdc
,
p_sys
->
hfont_bak
);
if
(
p_sys
->
hfont_bak
)
SelectObject
(
p_sys
->
hcdc
,
p_sys
->
hfont_bak
);
if
(
p_sys
->
hfont
)
DeleteObject
(
p_sys
->
hfont
);
if
(
p_sys
->
hfont
)
DeleteObject
(
p_sys
->
hfont
);
DeleteDC
(
p_sys
->
hcdc
);
DeleteDC
(
p_sys
->
hcdc
);
text_style_Delete
(
p_sys
->
p_default_style
);
free
(
p_sys
);
free
(
p_sys
);
}
}
...
@@ -300,7 +308,6 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
...
@@ -300,7 +308,6 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
const
vlc_fourcc_t
*
p_chroma_list
)
const
vlc_fourcc_t
*
p_chroma_list
)
{
{
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
int
i_font_color
,
i_font_alpha
,
i_font_size
;
uint8_t
*
p_bitmap
;
uint8_t
*
p_bitmap
;
TCHAR
*
psz_string
;
TCHAR
*
psz_string
;
int
i
,
i_width
,
i_height
;
int
i
,
i_width
,
i_height
;
...
@@ -309,43 +316,53 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
...
@@ -309,43 +316,53 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
RECT
rect
=
{
0
,
0
,
0
,
0
};
RECT
rect
=
{
0
,
0
,
0
,
0
};
/* Sanity check */
/* Sanity check */
if
(
!
p_region_in
||
!
p_region_out
)
return
VLC_EGENERIC
;
if
(
!
p_region_in
||
!
p_region_out
||
!
p_region_in
->
p_text
)
return
VLC_EGENERIC
;
if
(
!
p_region_in
->
p_text
)
return
VLC_EGENERIC
;
if
(
!
p_region_in
->
p_text
->
psz_text
||
!*
p_region_in
->
p_text
->
psz_text
)
return
VLC_EGENERIC
;
psz_string
=
ToT
(
p_region_in
->
p_text
->
psz_text
);
/* Convert to segments to single raw text */
if
(
psz_string
==
NULL
)
/* FIXME: render split segment/style */
return
VLC_EGENERIC
;
size_t
i_len
=
0
;
if
(
!*
psz_string
)
for
(
const
text_segment_t
*
p_text
=
p_region_in
->
p_text
;
p_text
!=
NULL
;
p_text
=
p_text
->
p_next
)
{
{
free
(
psz_string
);
i_len
+=
(
p_text
->
psz_text
)
?
strlen
(
p_text
->
psz_text
)
:
0
;
return
VLC_EGENERIC
;
}
}
if
(
i_len
==
0
)
return
VLC_EGENERIC
;
if
(
p_region_in
->
p_text
->
style
)
char
*
psz
=
psz_render_string
=
malloc
(
i_len
+
1
);
if
(
!
psz_render_string
)
return
VLC_EGENERIC
;
*
psz
=
0
;
for
(
const
text_segment_t
*
p_text
=
p_region_in
->
p_text
;
p_text
!=
NULL
;
p_text
=
p_text
->
p_next
)
{
{
i_font_color
=
VLC_CLIP
(
p_region_in
->
p_text
->
style
->
i_font_color
,
0
,
0xFFFFFF
);
if
(
p_text
->
psz_text
)
i_font_alpha
=
VLC_CLIP
(
p_region_in
->
p_text
->
style
->
i_font_alpha
,
0
,
255
);
strcat
(
psz
,
p_text
->
psz_text
);
i_font_size
=
VLC_CLIP
(
p_region_in
->
p_text
->
style
->
i_font_size
,
0
,
255
);
}
}
else
psz_string
=
ToT
(
psz_render_string
);
free
(
psz_render_string
);
if
(
!
psz_string
||
!*
psz_string
)
{
{
i_font_color
=
p_sys
->
i_font_color
;
free
(
psz_string
);
i_font_alpha
=
255
-
p_sys
->
i_font_opacity
;
return
VLC_EGENERIC
;
i_font_size
=
p_sys
->
i_default_font_size
;
}
}
SetFont
(
p_filter
,
i_font_size
);
SetFont
(
p_filter
,
p_sys
->
p_default_style
->
i_font_size
);
SetTextColor
(
p_sys
->
hcdc
,
RGB
(
(
i_font_color
>>
16
)
&
0xff
,
SetTextColor
(
p_sys
->
hcdc
,
RGB
(
(
p_sys
->
p_default_style
->
i_font_color
>>
16
)
&
0xff
,
(
i_font_color
>>
8
)
&
0xff
,
i_font_color
&
0xff
)
);
(
p_sys
->
p_default_style
->
i_font_color
>>
8
)
&
0xff
,
p_sys
->
p_default_style
->
i_font_color
&
0xff
)
);
DrawText
(
p_sys
->
hcdc
,
psz_string
,
-
1
,
&
rect
,
DrawText
(
p_sys
->
hcdc
,
psz_string
,
-
1
,
&
rect
,
DT_CALCRECT
|
DT_CENTER
|
DT_NOPREFIX
);
DT_CALCRECT
|
DT_CENTER
|
DT_NOPREFIX
);
i_width
=
rect
.
right
;
i_height
=
rect
.
bottom
;
i_width
=
rect
.
right
;
i_height
=
rect
.
bottom
;
p_bmi
=
malloc
(
sizeof
(
BITMAPINFOHEADER
)
+
sizeof
(
RGBQUAD
)
*
16
);
p_bmi
=
malloc
(
sizeof
(
BITMAPINFOHEADER
)
+
sizeof
(
RGBQUAD
)
*
16
);
if
(
!
p_bmi
)
{
free
(
psz_string
);
return
VLC_ENOMEM
;
}
memset
(
p_bmi
,
0
,
sizeof
(
BITMAPINFOHEADER
)
);
memset
(
p_bmi
,
0
,
sizeof
(
BITMAPINFOHEADER
)
);
p_bmi
->
bmiHeader
.
biSize
=
sizeof
(
BITMAPINFOHEADER
);
p_bmi
->
bmiHeader
.
biSize
=
sizeof
(
BITMAPINFOHEADER
);
p_bmi
->
bmiHeader
.
biWidth
=
(
i_width
+
3
)
&
~
3
;
p_bmi
->
bmiHeader
.
biWidth
=
(
i_width
+
3
)
&
~
3
;
...
@@ -368,6 +385,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
...
@@ -368,6 +385,7 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
{
{
msg_Err
(
p_filter
,
"could not create bitmap"
);
msg_Err
(
p_filter
,
"could not create bitmap"
);
free
(
psz_string
);
free
(
psz_string
);
free
(
p_bmi
);
return
VLC_EGENERIC
;
return
VLC_EGENERIC
;
}
}
...
@@ -387,6 +405,8 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
...
@@ -387,6 +405,8 @@ static int RenderText( filter_t *p_filter, subpicture_region_t *p_region_out,
SelectObject
(
p_sys
->
hcdc
,
bitmap_bak
);
SelectObject
(
p_sys
->
hcdc
,
bitmap_bak
);
DeleteObject
(
bitmap
);
DeleteObject
(
bitmap
);
free
(
psz_string
);
free
(
psz_string
);
free
(
p_bmi
);
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
}
}
...
@@ -395,19 +415,19 @@ static int SetFont( filter_t *p_filter, int i_size )
...
@@ -395,19 +415,19 @@ static int SetFont( filter_t *p_filter, int i_size )
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
filter_sys_t
*
p_sys
=
p_filter
->
p_sys
;
LOGFONT
logfont
;
LOGFONT
logfont
;
if
(
i_size
&&
i_size
==
p_sys
->
i_font_size
)
return
VLC_SUCCESS
;
if
(
i_size
&&
i_size
==
p_sys
->
p_default_style
->
i_font_size
)
return
VLC_SUCCESS
;
if
(
!
i_size
)
if
(
!
i_size
)
{
{
vlc_value_t
val
;
vlc_value_t
val
;
if
(
!
p_sys
->
i_default
_font_size
&&
if
(
!
p_sys
->
p_default_style
->
i
_font_size
&&
p_sys
->
i_display_height
==
(
int
)
p_filter
->
fmt_out
.
video
.
i_height
)
p_sys
->
i_display_height
==
(
int
)
p_filter
->
fmt_out
.
video
.
i_height
)
return
VLC_SUCCESS
;
return
VLC_SUCCESS
;
if
(
p_sys
->
i_default
_font_size
)
if
(
p_sys
->
p_default_style
->
i
_font_size
)
{
{
i_size
=
p_sys
->
i_default
_font_size
;
i_size
=
p_sys
->
p_default_style
->
i
_font_size
;
}
}
else
else
{
{
...
@@ -425,7 +445,7 @@ static int SetFont( filter_t *p_filter, int i_size )
...
@@ -425,7 +445,7 @@ static int SetFont( filter_t *p_filter, int i_size )
msg_Dbg
(
p_filter
,
"using fontsize: %i"
,
i_size
);
msg_Dbg
(
p_filter
,
"using fontsize: %i"
,
i_size
);
}
}
p_sys
->
i_font_size
=
i_size
;
p_sys
->
p_default_style
->
i_font_size
=
i_size
;
if
(
p_sys
->
hfont_bak
)
SelectObject
(
p_sys
->
hcdc
,
p_sys
->
hfont_bak
);
if
(
p_sys
->
hfont_bak
)
SelectObject
(
p_sys
->
hcdc
,
p_sys
->
hfont_bak
);
if
(
p_sys
->
hfont
)
DeleteObject
(
p_sys
->
hfont
);
if
(
p_sys
->
hfont
)
DeleteObject
(
p_sys
->
hfont
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment