Skip to content

Commit

Permalink
Don't enforce end points for dotted line on text
Browse files Browse the repository at this point in the history
Sometimes the first or the last dot of dotted line for text
is too heavy and long. We should improve this.

Bug: 807368
Change-Id: I2851c964892b145154514c6f38e8025a8c29a7b6
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2319501
Commit-Queue: Sang Woo Ko <sangwoo108@chromium.org>
Reviewed-by: Philip Rogers <pdr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795789}
  • Loading branch information
sangwoo108 authored and Commit Bot committed Aug 7, 2020
1 parent 7888f7d commit d8031b1
Show file tree
Hide file tree
Showing 23 changed files with 69 additions and 12 deletions.
26 changes: 15 additions & 11 deletions third_party/blink/renderer/platform/graphics/graphics_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,8 @@ static void EnforceDotsAtEndpoints(GraphicsContext& context,

void GraphicsContext::DrawLine(const IntPoint& point1,
const IntPoint& point2,
const DarkModeFilter::ElementRole role) {
const DarkModeFilter::ElementRole role,
bool is_text_line) {
DCHECK(canvas_);

StrokeStyle pen_style = GetStrokeStyle();
Expand All @@ -668,18 +669,21 @@ void GraphicsContext::DrawLine(const IntPoint& point1,
// probably worth the speed up of no square root, which also won't be exact.
FloatSize disp = p2 - p1;
int length = SkScalarRoundToInt(disp.Width() + disp.Height());
const DarkModeFlags flags(this, ImmutableState()->StrokeFlags(length), role);
const DarkModeFlags flags(this, ImmutableState()->StrokeFlags(length, width),
role);

if (pen_style == kDottedStroke) {
if (StrokeData::StrokeIsDashed(width, pen_style)) {
// We draw thin dotted lines as dashes and gaps that are always
// exactly the size of the width. When the length of the line is
// an odd multiple of the width, things work well because we get
// dots at each end of the line, but if the length is anything else,
// we get gaps or partial dots at the end of the line. Fix that by
// explicitly enforcing full dots at the ends of lines.
EnforceDotsAtEndpoints(*this, p1, p2, length, width, flags,
is_vertical_line);
// When the length of the line is an odd multiple of the width, things
// work well because we get dots at each end of the line, but if the
// length is anything else, we get gaps or partial dots at the end of the
// line. Fix that by explicitly enforcing full dots at the ends of lines.
// Note that we don't enforce end points when it's text line as enforcing
// is to improve border line quality.
if (!is_text_line) {
EnforceDotsAtEndpoints(*this, p1, p2, length, width, flags,
is_vertical_line);
}
} else {
// We draw thick dotted lines with 0 length dash strokes and round
// endcaps, producing circles. The endcaps extend beyond the line's
Expand Down Expand Up @@ -725,7 +729,7 @@ void GraphicsContext::DrawLineForText(const FloatPoint& pt, float width) {
case kDashedStroke: {
int y = floorf(pt.Y() + std::max<float>(StrokeThickness() / 2.0f, 0.5f));
DrawLine(IntPoint(pt.X(), y), IntPoint(pt.X() + width, y),
DarkModeFilter::ElementRole::kText);
DarkModeFilter::ElementRole::kText, true);
return;
}
case kWavyStroke:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class PLATFORM_EXPORT GraphicsContext {
void DrawLine(const IntPoint&,
const IntPoint&,
const DarkModeFilter::ElementRole role =
DarkModeFilter::ElementRole::kBackground);
DarkModeFilter::ElementRole::kBackground,
bool is_text_line = false);

void FillPath(const Path&);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<title>CSS Test: CSS3 text-decoration dotted line for text test</title>
<link rel="help" href="http://http://dev.w3.org/csswg/css3-text/#text-decoration-style"/>
<meta name="flags" content="ahem"/>
<style>
.overline {
text-decoration: overline;
text-decoration-skip-ink: auto;
text-decoration-style: dotted;
text-decoration-skip-ink: none;
text-decoration-color: red;
}

.line-through {
text-decoration: line-through;
text-decoration-skip-ink: auto;
text-decoration-style: dotted;
text-decoration-skip-ink: none;
text-decoration-color: red;
}

.underline {
text-decoration: underline;
text-decoration-skip-ink: auto;
text-decoration-style: dotted;
text-decoration-skip-ink: none;
text-decoration-color: red;
}
</style>
</head>
<body>
<div class="overline">Lorem ipsum dolor sit amet</div>
<div class="overline">Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a.</div>
<div class="overline">Quisque velit nisi, pretium ut lacinia in, elementum id enim.</div>
<div class="overline">Nulla porttitor accumsan tincidunt.</div>
<div class="overline">Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.</div>

<div class="line-through">Lorem ipsum dolor sit amet</div>
<div class="line-through">Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a.</div>
<div class="line-through">Quisque velit nisi, pretium ut lacinia in, elementum id enim.</div>
<div class="line-through">Nulla porttitor accumsan tincidunt.</div>
<div class="line-through">Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.</div>

<div class="underline">Lorem ipsum dolor sit amet</div>
<div class="underline">Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a.</div>
<div class="underline">Quisque velit nisi, pretium ut lacinia in, elementum id enim.</div>
<div class="underline">Nulla porttitor accumsan tincidunt.</div>
<div class="underline">Curabitur non nulla sit amet nisl tempus convallis quis ac lectus.</div>
</body>
</html>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d8031b1

Please sign in to comment.