Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4e6fe31e
authored
Jan 30, 2020
by
Oliver Woodman
Committed by
Andrew Lewis
May 29, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Merge pull request #6724 from nnoury:fix/subtitles-outline-color
PiperOrigin-RevId: 292316767
parent
d162c07e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
11 deletions
RELEASENOTES.md
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
RELEASENOTES.md
View file @
4e6fe31e
...
...
@@ -35,8 +35,11 @@
*
Add
`showScrubber`
and
`hideScrubber`
methods to
`DefaultTimeBar`
.
*
Update
`TrackSelectionDialogBuilder`
to use AndroidX Compat Dialog
(
[
#7357
](
https://github.com/google/ExoPlayer/issues/7357
)
).
*
Text: Use anti-aliasing and bitmap filtering when displaying bitmap
subtitles.
*
Text:
*
Use anti-aliasing and bitmap filtering when displaying bitmap
subtitles.
*
Fix
`SubtitlePainter`
to render
`EDGE_TYPE_OUTLINE`
using the correct
color.
*
Cronet extension: Default to using the Cronet implementation in Google Play
Services rather than Cronet Embedded. This allows Cronet to be used with a
negligible increase in application size, compared to approximately 8MB when
...
...
library/ui/src/main/java/com/google/android/exoplayer2/ui/SubtitlePainter.java
View file @
4e6fe31e
...
...
@@ -33,6 +33,7 @@ import android.text.TextPaint;
import
android.text.TextUtils
;
import
android.text.style.AbsoluteSizeSpan
;
import
android.text.style.BackgroundColorSpan
;
import
android.text.style.ForegroundColorSpan
;
import
android.text.style.RelativeSizeSpan
;
import
android.util.DisplayMetrics
;
import
androidx.annotation.Nullable
;
...
...
@@ -99,6 +100,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// Derived drawing variables.
private
@MonotonicNonNull
StaticLayout
textLayout
;
private
@MonotonicNonNull
StaticLayout
edgeLayout
;
private
int
textLeft
;
private
int
textTop
;
private
int
textPaddingX
;
...
...
@@ -291,11 +293,38 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
}
// Remove embedded font color to not destroy edges, otherwise it overrides edge color.
SpannableStringBuilder
cueTextEdge
=
new
SpannableStringBuilder
(
cueText
);
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_OUTLINE
)
{
int
cueLength
=
cueTextEdge
.
length
();
ForegroundColorSpan
[]
foregroundColorSpans
=
cueTextEdge
.
getSpans
(
0
,
cueLength
,
ForegroundColorSpan
.
class
);
for
(
ForegroundColorSpan
foregroundColorSpan
:
foregroundColorSpans
)
{
cueTextEdge
.
removeSpan
(
foregroundColorSpan
);
}
}
// EDGE_TYPE_NONE & EDGE_TYPE_DROP_SHADOW both paint in one pass, they ignore cueTextEdge.
// In other cases we use two painters and we need to apply the background in the first one only,
// otherwise the background color gets drawn in front of the edge color
// (https://github.com/google/ExoPlayer/pull/6724#issuecomment-564650572).
if
(
Color
.
alpha
(
backgroundColor
)
>
0
)
{
SpannableStringBuilder
newCueText
=
new
SpannableStringBuilder
(
cueText
);
newCueText
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
0
,
newCueText
.
length
(),
Spanned
.
SPAN_PRIORITY
);
cueText
=
newCueText
;
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_NONE
||
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_DROP_SHADOW
)
{
SpannableStringBuilder
newCueText
=
new
SpannableStringBuilder
(
cueText
);
newCueText
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
0
,
newCueText
.
length
(),
Spanned
.
SPAN_PRIORITY
);
cueText
=
newCueText
;
}
else
{
cueTextEdge
.
setSpan
(
new
BackgroundColorSpan
(
backgroundColor
),
0
,
cueTextEdge
.
length
(),
Spanned
.
SPAN_PRIORITY
);
}
}
Alignment
textAlignment
=
cueTextAlignment
==
null
?
Alignment
.
ALIGN_CENTER
:
cueTextAlignment
;
...
...
@@ -371,6 +400,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
// Update the derived drawing variables.
this
.
textLayout
=
new
StaticLayout
(
cueText
,
textPaint
,
textWidth
,
textAlignment
,
spacingMult
,
spacingAdd
,
true
);
this
.
edgeLayout
=
new
StaticLayout
(
cueTextEdge
,
textPaint
,
textWidth
,
textAlignment
,
spacingMult
,
spacingAdd
,
true
);
this
.
textLeft
=
textLeft
;
this
.
textTop
=
textTop
;
this
.
textPaddingX
=
textPaddingX
;
...
...
@@ -410,8 +442,9 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
}
private
void
drawTextLayout
(
Canvas
canvas
)
{
StaticLayout
layout
=
textLayout
;
if
(
layout
==
null
)
{
StaticLayout
textLayout
=
this
.
textLayout
;
StaticLayout
edgeLayout
=
this
.
edgeLayout
;
if
(
textLayout
==
null
||
edgeLayout
==
null
)
{
// Nothing to draw.
return
;
}
...
...
@@ -434,7 +467,7 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
textPaint
.
setStrokeWidth
(
outlineWidth
);
textPaint
.
setColor
(
edgeColor
);
textPaint
.
setStyle
(
Style
.
FILL_AND_STROKE
);
l
ayout
.
draw
(
canvas
);
edgeL
ayout
.
draw
(
canvas
);
}
else
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_DROP_SHADOW
)
{
textPaint
.
setShadowLayer
(
shadowRadius
,
shadowOffset
,
shadowOffset
,
edgeColor
);
}
else
if
(
edgeType
==
CaptionStyleCompat
.
EDGE_TYPE_RAISED
...
...
@@ -446,13 +479,13 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
textPaint
.
setColor
(
foregroundColor
);
textPaint
.
setStyle
(
Style
.
FILL
);
textPaint
.
setShadowLayer
(
shadowRadius
,
-
offset
,
-
offset
,
colorUp
);
l
ayout
.
draw
(
canvas
);
edgeL
ayout
.
draw
(
canvas
);
textPaint
.
setShadowLayer
(
shadowRadius
,
offset
,
offset
,
colorDown
);
}
textPaint
.
setColor
(
foregroundColor
);
textPaint
.
setStyle
(
Style
.
FILL
);
l
ayout
.
draw
(
canvas
);
textL
ayout
.
draw
(
canvas
);
textPaint
.
setShadowLayer
(
0
,
0
,
0
,
0
);
canvas
.
restoreToCount
(
saveCount
);
...
...
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