diff --git a/core/src/html/layout.rs b/core/src/html/layout.rs
index 3bb4265b3df0..a5b7f5046a70 100644
--- a/core/src/html/layout.rs
+++ b/core/src/html/layout.rs
@@ -16,13 +16,23 @@ use swf::{Point, Twips};
/// Draw an underline on a particular drawing.
///
/// This will not draw underlines shorter than a pixel in width.
-fn draw_underline(drawing: &mut Drawing, starting_pos: Position, width: Twips) {
+fn draw_underline(
+ drawing: &mut Drawing,
+ starting_pos: Position,
+ width: Twips,
+ color: swf::Color,
+) {
if width < Twips::from_pixels(1.0) {
return;
}
let ending_pos = starting_pos + Position::from((width, Twips::ZERO));
+ drawing.set_line_style(Some(
+ swf::LineStyle::new()
+ .with_width(Twips::new(1))
+ .with_color(color),
+ ));
drawing.draw_command(DrawCommand::MoveTo(Point::new(
starting_pos.x(),
starting_pos.y(),
@@ -142,29 +152,27 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
fn append_underlines(&mut self) {
let mut starting_pos: Option> = None;
let mut current_width: Option = None;
+ let mut underline_color: Option = None;
let mut line_drawing = Drawing::new();
let mut has_underline: bool = false;
- line_drawing.set_line_style(Some(
- swf::LineStyle::new()
- .with_width(Twips::new(1))
- .with_color(swf::Color::BLACK),
- ));
-
if let Some(linelist) = self.boxes.get(self.current_line..) {
for linebox in linelist {
if linebox.is_text_box() {
- if let Some((_t, tf, font, params, _color)) =
+ if let Some((_t, tf, font, params, color)) =
linebox.as_renderable_text(self.text)
{
let underline_baseline =
font.get_baseline_for_height(params.height()) + Twips::from_pixels(2.0);
let mut line_extended = false;
- if let Some(starting_pos) = starting_pos {
+ if let (Some(starting_pos), Some(underline_color)) =
+ (starting_pos, underline_color)
+ {
if tf.underline.unwrap_or(false)
&& underline_baseline + linebox.bounds().origin().y()
== starting_pos.y()
+ && underline_color == color
{
//Underline is at the same baseline, extend it
current_width =
@@ -178,11 +186,14 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
//For whatever reason, we cannot extend the current underline.
//This can happen if we don't have an underline to extend, the
//underlines don't match, or this span doesn't call for one.
- if let (Some(pos), Some(width)) = (starting_pos, current_width) {
- draw_underline(&mut line_drawing, pos, width);
+ if let (Some(pos), Some(width), Some(color)) =
+ (starting_pos, current_width, underline_color)
+ {
+ draw_underline(&mut line_drawing, pos, width, color);
has_underline = true;
starting_pos = None;
current_width = None;
+ underline_color = None;
}
if tf.underline.unwrap_or(false) {
@@ -191,6 +202,7 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
+ Position::from((Twips::ZERO, underline_baseline)),
);
current_width = Some(linebox.bounds().width());
+ underline_color = Some(color);
}
}
}
@@ -198,8 +210,15 @@ impl<'a, 'gc> LayoutContext<'a, 'gc> {
}
}
- if let (Some(starting_pos), Some(current_width)) = (starting_pos, current_width) {
- draw_underline(&mut line_drawing, starting_pos, current_width);
+ if let (Some(starting_pos), Some(current_width), Some(underline_color)) =
+ (starting_pos, current_width, underline_color)
+ {
+ draw_underline(
+ &mut line_drawing,
+ starting_pos,
+ current_width,
+ underline_color,
+ );
has_underline = true;
}
diff --git a/tests/tests/swfs/visual/text/underline_color/expected.png b/tests/tests/swfs/visual/text/underline_color/expected.png
new file mode 100644
index 000000000000..776371165cff
Binary files /dev/null and b/tests/tests/swfs/visual/text/underline_color/expected.png differ
diff --git a/tests/tests/swfs/visual/text/underline_color/output.txt b/tests/tests/swfs/visual/text/underline_color/output.txt
new file mode 100644
index 000000000000..e69de29bb2d1
diff --git a/tests/tests/swfs/visual/text/underline_color/test.fla b/tests/tests/swfs/visual/text/underline_color/test.fla
new file mode 100644
index 000000000000..caa62c70ce0d
Binary files /dev/null and b/tests/tests/swfs/visual/text/underline_color/test.fla differ
diff --git a/tests/tests/swfs/visual/text/underline_color/test.swf b/tests/tests/swfs/visual/text/underline_color/test.swf
new file mode 100644
index 000000000000..4a3c8a936a9e
Binary files /dev/null and b/tests/tests/swfs/visual/text/underline_color/test.swf differ
diff --git a/tests/tests/swfs/visual/text/underline_color/test.toml b/tests/tests/swfs/visual/text/underline_color/test.toml
new file mode 100644
index 000000000000..857f10c4c762
--- /dev/null
+++ b/tests/tests/swfs/visual/text/underline_color/test.toml
@@ -0,0 +1,8 @@
+num_frames = 1
+
+[image_comparison]
+tolerance = 0
+max_outliers = 12
+
+[player_options]
+with_renderer = { optional = false, sample_count = 1 }