<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[207002] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/207002">207002</a></dd>
<dt>Author</dt> <dd>bfulgham@apple.com</dd>
<dt>Date</dt> <dd>2016-10-10 10:02:52 -0700 (Mon, 10 Oct 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Reduce code duplication between CG, Cairo, and Direct2D
https://bugs.webkit.org/show_bug.cgi?id=163157
Reviewed by Darin Adler.
Move a number of routines that have been copied-and-pasted to different
platform files into the main GraphicsContext.cpp file.
No new tests because there is no change in behavior.
* platform/graphics/GraphicsContext.cpp:
(WebCore::GraphicsContext::dashedLineCornerWidthForStrokeWidth): Added.
(WebCore::GraphicsContext::dashedLinePatternWidthForStrokeWidth): Added.
(WebCore::GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth): Added.
(WebCore::GraphicsContext::centerLineAndCutOffCorners): Added.
* platform/graphics/GraphicsContext.h:
* platform/graphics/cairo/GraphicsContextCairo.cpp:
(WebCore::GraphicsContext::drawLine): Call new helper function.
* platform/graphics/cg/GraphicsContextCG.cpp:
(WebCore::GraphicsContext::drawLine): Ditto.
* platform/graphics/win/GraphicsContextDirect2D.cpp:
(WebCore::GraphicsContext::drawLine): Ditto.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContextcpp">trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsGraphicsContexth">trunk/Source/WebCore/platform/graphics/GraphicsContext.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicsPatternh">trunk/Source/WebCore/platform/graphics/Pattern.h</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscairoGraphicsContextCairocpp">trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicscgGraphicsContextCGcpp">trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp">trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/ChangeLog        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -1,3 +1,28 @@
</span><ins>+2016-10-10 Brent Fulgham <bfulgham@apple.com>
+
+ Reduce code duplication between CG, Cairo, and Direct2D
+ https://bugs.webkit.org/show_bug.cgi?id=163157
+
+ Reviewed by Darin Adler.
+
+ Move a number of routines that have been copied-and-pasted to different
+ platform files into the main GraphicsContext.cpp file.
+
+ No new tests because there is no change in behavior.
+
+ * platform/graphics/GraphicsContext.cpp:
+ (WebCore::GraphicsContext::dashedLineCornerWidthForStrokeWidth): Added.
+ (WebCore::GraphicsContext::dashedLinePatternWidthForStrokeWidth): Added.
+ (WebCore::GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth): Added.
+ (WebCore::GraphicsContext::centerLineAndCutOffCorners): Added.
+ * platform/graphics/GraphicsContext.h:
+ * platform/graphics/cairo/GraphicsContextCairo.cpp:
+ (WebCore::GraphicsContext::drawLine): Call new helper function.
+ * platform/graphics/cg/GraphicsContextCG.cpp:
+ (WebCore::GraphicsContext::drawLine): Ditto.
+ * platform/graphics/win/GraphicsContextDirect2D.cpp:
+ (WebCore::GraphicsContext::drawLine): Ditto.
+
</ins><span class="cx"> 2016-10-10 Carlos Garcia Campos <cgarcia@igalia.com>
</span><span class="cx">
</span><span class="cx"> REGRESSION(r206731): [SOUP] Network process crash in gotHeadersCallback
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContextcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.cpp        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -1126,4 +1126,55 @@
</span><span class="cx"> setPlatformShouldSmoothFonts(state.shouldSmoothFonts);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+float GraphicsContext::dashedLineCornerWidthForStrokeWidth(float strokeWidth) const
+{
+ float thickness = strokeThickness();
+ return strokeStyle() == DottedStroke ? thickness : std::min(2.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
</ins><span class="cx"> }
</span><ins>+
+float GraphicsContext::dashedLinePatternWidthForStrokeWidth(float strokeWidth) const
+{
+ float thickness = strokeThickness();
+ return strokeStyle() == DottedStroke ? thickness : std::min(3.0f * thickness, std::max(thickness, strokeWidth / 3.0f));
+}
+
+float GraphicsContext::dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth) const
+{
+ // Pattern starts with full fill and ends with the empty fill.
+ // 1. Let's start with the empty phase after the corner.
+ // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
+ // 3. In case of even number of patterns and/or remainder, move the pattern start position
+ // so that the pattern is balanced between the corners.
+ float patternOffset = patternWidth;
+ int numberOfSegments = std::floor(strokeWidth / patternWidth);
+ bool oddNumberOfSegments = numberOfSegments % 2;
+ float remainder = strokeWidth - (numberOfSegments * patternWidth);
+ if (oddNumberOfSegments && remainder)
+ patternOffset -= remainder / 2.0f;
+ else if (!oddNumberOfSegments) {
+ if (remainder)
+ patternOffset += patternOffset - (patternWidth + remainder) / 2.0f;
+ else
+ patternOffset += patternWidth / 2.0f;
+ }
+
+ return patternOffset;
+}
+
+Vector<FloatPoint> GraphicsContext::centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2) const
+{
+ // Center line and cut off corners for pattern patining.
+ if (isVerticalLine) {
+ float centerOffset = (point2.x() - point1.x()) / 2.0f;
+ point1.move(centerOffset, cornerWidth);
+ point2.move(-centerOffset, -cornerWidth);
+ } else {
+ float centerOffset = (point2.y() - point1.y()) / 2.0f;
+ point1.move(cornerWidth, centerOffset);
+ point2.move(-cornerWidth, -centerOffset);
+ }
+
+ return { point1, point2 };
+}
+
+}
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsGraphicsContexth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext.h (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext.h        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -618,6 +618,11 @@
</span><span class="cx">
</span><span class="cx"> FloatRect computeLineBoundsAndAntialiasingModeForText(const FloatPoint&, float width, bool printing, Color&);
</span><span class="cx">
</span><ins>+ float dashedLineCornerWidthForStrokeWidth(float) const;
+ float dashedLinePatternWidthForStrokeWidth(float) const;
+ float dashedLinePatternOffsetForPatternAndStrokeWidth(float patternWidth, float strokeWidth) const;
+ Vector<FloatPoint> centerLineAndCutOffCorners(bool isVerticalLine, float cornerWidth, FloatPoint point1, FloatPoint point2) const;
+
</ins><span class="cx"> GraphicsContextPlatformPrivate* m_data { nullptr };
</span><span class="cx"> DisplayList::Recorder* m_displayListRecorder { nullptr };
</span><span class="cx">
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicsPatternh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/Pattern.h (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/Pattern.h        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/Pattern.h        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -37,6 +37,8 @@
</span><span class="cx"> #if USE(CG)
</span><span class="cx"> typedef struct CGPattern* CGPatternRef;
</span><span class="cx"> typedef CGPatternRef PlatformPatternPtr;
</span><ins>+#elif USE(DIRECT2D)
+typedef void* PlatformPatternPtr;
</ins><span class="cx"> #elif USE(CAIRO)
</span><span class="cx"> #include <cairo.h>
</span><span class="cx"> typedef cairo_pattern_t* PlatformPatternPtr;
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscairoGraphicsContextCairocpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/cairo/GraphicsContextCairo.cpp        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -324,7 +324,7 @@
</span><span class="cx"> if (drawsDashedLine) {
</span><span class="cx"> cairo_save(cairoContext);
</span><span class="cx"> // Figure out end points to ensure we always paint corners.
</span><del>- cornerWidth = strokeStyle == DottedStroke ? thickness : std::min(2 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ cornerWidth = dashedLineCornerWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> if (isVerticalLine) {
</span><span class="cx"> fillRectWithColor(cairoContext, FloatRect(point1.x(), point1.y(), thickness, cornerWidth), strokeColor);
</span><span class="cx"> fillRectWithColor(cairoContext, FloatRect(point1.x(), point2.y() - cornerWidth, thickness, cornerWidth), strokeColor);
</span><span class="lines">@@ -333,7 +333,7 @@
</span><span class="cx"> fillRectWithColor(cairoContext, FloatRect(point2.x() - cornerWidth, point1.y(), cornerWidth, thickness), strokeColor);
</span><span class="cx"> }
</span><span class="cx"> strokeWidth -= 2 * cornerWidth;
</span><del>- float patternWidth = strokeStyle == DottedStroke ? thickness : std::min(3 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ float patternWidth = dashedLinePatternWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> // Check if corner drawing sufficiently covers the line.
</span><span class="cx"> if (strokeWidth <= patternWidth + 1) {
</span><span class="cx"> cairo_restore(cairoContext);
</span><span class="lines">@@ -340,23 +340,7 @@
</span><span class="cx"> return;
</span><span class="cx"> }
</span><span class="cx">
</span><del>- // Pattern starts with full fill and ends with the empty fill.
- // 1. Let's start with the empty phase after the corner.
- // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
- // 3. In case of even number of patterns and/or remainder, move the pattern start position
- // so that the pattern is balanced between the corners.
- float patternOffset = patternWidth;
- int numberOfSegments = std::floor(strokeWidth / patternWidth);
- bool oddNumberOfSegments = numberOfSegments % 2;
- float remainder = strokeWidth - (numberOfSegments * patternWidth);
- if (oddNumberOfSegments && remainder)
- patternOffset -= remainder / 2.f;
- else if (!oddNumberOfSegments) {
- if (remainder)
- patternOffset += patternOffset - (patternWidth + remainder) / 2.f;
- else
- patternOffset += patternWidth / 2.f;
- }
</del><ins>+ float patternOffset = dashedLinePatternOffsetForPatternAndStrokeWidth(patternWidth, strokeWidth);
</ins><span class="cx"> const double dashedLine[2] = { static_cast<double>(patternWidth), static_cast<double>(patternWidth) };
</span><span class="cx"> cairo_set_dash(cairoContext, dashedLine, 2, patternOffset);
</span><span class="cx"> } else {
</span><span class="lines">@@ -366,18 +350,9 @@
</span><span class="cx"> }
</span><span class="cx">
</span><span class="cx">
</span><del>- FloatPoint p1 = point1;
- FloatPoint p2 = point2;
- // Center line and cut off corners for pattern patining.
- if (isVerticalLine) {
- float centerOffset = (p2.x() - p1.x()) / 2;
- p1.move(centerOffset, cornerWidth);
- p2.move(-centerOffset, -cornerWidth);
- } else {
- float centerOffset = (p2.y() - p1.y()) / 2;
- p1.move(cornerWidth, centerOffset);
- p2.move(-cornerWidth, -centerOffset);
- }
</del><ins>+ auto centeredPoints = centerLineAndCutOffCorners(isVerticalLine, cornerWidth, point1, point2);
+ auto p1 = centeredPoints[0];
+ auto p2 = centeredPoints[1];
</ins><span class="cx">
</span><span class="cx"> if (shouldAntialias())
</span><span class="cx"> cairo_set_antialias(cairoContext, CAIRO_ANTIALIAS_NONE);
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicscgGraphicsContextCGcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/cg/GraphicsContextCG.cpp        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -470,7 +470,7 @@
</span><span class="cx"> CGContextStateSaver stateSaver(context, drawsDashedLine);
</span><span class="cx"> if (drawsDashedLine) {
</span><span class="cx"> // Figure out end points to ensure we always paint corners.
</span><del>- cornerWidth = strokeStyle == DottedStroke ? thickness : std::min(2 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ cornerWidth = dashedLineCornerWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> setCGFillColor(context, strokeColor());
</span><span class="cx"> if (isVerticalLine) {
</span><span class="cx"> CGContextFillRect(context, FloatRect(point1.x(), point1.y(), thickness, cornerWidth));
</span><span class="lines">@@ -480,44 +480,19 @@
</span><span class="cx"> CGContextFillRect(context, FloatRect(point2.x() - cornerWidth, point1.y(), cornerWidth, thickness));
</span><span class="cx"> }
</span><span class="cx"> strokeWidth -= 2 * cornerWidth;
</span><del>- float patternWidth = strokeStyle == DottedStroke ? thickness : std::min(3 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ float patternWidth = dashedLinePatternWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> // Check if corner drawing sufficiently covers the line.
</span><span class="cx"> if (strokeWidth <= patternWidth + 1)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- // Pattern starts with full fill and ends with the empty fill.
- // 1. Let's start with the empty phase after the corner.
- // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
- // 3. In case of even number of patterns and/or remainder, move the pattern start position
- // so that the pattern is balanced between the corners.
- float patternOffset = patternWidth;
- int numberOfSegments = floorf(strokeWidth / patternWidth);
- bool oddNumberOfSegments = numberOfSegments % 2;
- float remainder = strokeWidth - (numberOfSegments * patternWidth);
- if (oddNumberOfSegments && remainder)
- patternOffset -= remainder / 2;
- else if (!oddNumberOfSegments) {
- if (remainder)
- patternOffset += patternOffset - (patternWidth + remainder) / 2;
- else
- patternOffset += patternWidth / 2;
- }
</del><ins>+ float patternOffset = dashedLinePatternOffsetForPatternAndStrokeWidth(patternWidth, strokeWidth);
</ins><span class="cx"> const CGFloat dashedLine[2] = { static_cast<CGFloat>(patternWidth), static_cast<CGFloat>(patternWidth) };
</span><span class="cx"> CGContextSetLineDash(context, patternOffset, dashedLine, 2);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- FloatPoint p1 = point1;
- FloatPoint p2 = point2;
- // Center line and cut off corners for pattern patining.
- if (isVerticalLine) {
- float centerOffset = (p2.x() - p1.x()) / 2;
- p1.move(centerOffset, cornerWidth);
- p2.move(-centerOffset, -cornerWidth);
- } else {
- float centerOffset = (p2.y() - p1.y()) / 2;
- p1.move(cornerWidth, centerOffset);
- p2.move(-cornerWidth, -centerOffset);
- }
</del><ins>+ auto centeredPoints = centerLineAndCutOffCorners(isVerticalLine, cornerWidth, point1, point2);
+ auto p1 = centeredPoints[0];
+ auto p2 = centeredPoints[1];
</ins><span class="cx">
</span><span class="cx"> if (shouldAntialias()) {
</span><span class="cx"> #if PLATFORM(IOS)
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformgraphicswinGraphicsContextDirect2Dcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (207001 => 207002)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-10 17:00:15 UTC (rev 207001)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp        2016-10-10 17:02:52 UTC (rev 207002)
</span><span class="lines">@@ -502,49 +502,22 @@
</span><span class="cx"> D2DContextStateSaver stateSaver(*m_data, drawsDashedLine);
</span><span class="cx"> if (drawsDashedLine) {
</span><span class="cx"> // Figure out end points to ensure we always paint corners.
</span><del>- cornerWidth = strokeStyle == DottedStroke ? thickness : std::min(2 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ cornerWidth = dashedLineCornerWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> strokeWidth -= 2 * cornerWidth;
</span><del>- float patternWidth = strokeStyle == DottedStroke ? thickness : std::min(3 * thickness, std::max(thickness, strokeWidth / 3));
</del><ins>+ float patternWidth = dashedLinePatternWidthForStrokeWidth(strokeWidth);
</ins><span class="cx"> // Check if corner drawing sufficiently covers the line.
</span><span class="cx"> if (strokeWidth <= patternWidth + 1)
</span><span class="cx"> return;
</span><span class="cx">
</span><del>- // Pattern starts with full fill and ends with the empty fill.
- // 1. Let's start with the empty phase after the corner.
- // 2. Check if we've got odd or even number of patterns and whether they fully cover the line.
- // 3. In case of even number of patterns and/or remainder, move the pattern start position
- // so that the pattern is balanced between the corners.
- float patternOffset = patternWidth;
- int numberOfSegments = floorf(strokeWidth / patternWidth);
- bool oddNumberOfSegments = numberOfSegments % 2;
- float remainder = strokeWidth - (numberOfSegments * patternWidth);
- if (oddNumberOfSegments && remainder)
- patternOffset -= remainder / 2;
- else if (!oddNumberOfSegments) {
- if (remainder)
- patternOffset += patternOffset - (patternWidth + remainder) / 2;
- else
- patternOffset += patternWidth / 2;
- }
</del><ins>+ float patternOffset = dashedLinePatternOffsetForPatternAndStrokeWidth(patternWidth, strokeWidth);
</ins><span class="cx"> const float dashes[2] = { patternWidth, patternWidth };
</span><del>-
</del><span class="cx"> auto strokeStyleProperties = D2D1::StrokeStyleProperties();
</span><del>-
</del><span class="cx"> GraphicsContext::systemFactory()->CreateStrokeStyle(&strokeStyleProperties, dashes, ARRAYSIZE(dashes), &d2dStrokeStyle);
</span><span class="cx"> }
</span><span class="cx">
</span><del>- FloatPoint p1 = point1;
- FloatPoint p2 = point2;
- // Center line and cut off corners for pattern patining.
- if (isVerticalLine) {
- float centerOffset = (p2.x() - p1.x()) / 2;
- p1.move(centerOffset, cornerWidth);
- p2.move(-centerOffset, -cornerWidth);
- } else {
- float centerOffset = (p2.y() - p1.y()) / 2;
- p1.move(cornerWidth, centerOffset);
- p2.move(-cornerWidth, -centerOffset);
- }
</del><ins>+ auto centeredPoints = centerLineAndCutOffCorners(isVerticalLine, cornerWidth, point1, point2);
+ auto p1 = centeredPoints[0];
+ auto p2 = centeredPoints[1];
</ins><span class="cx">
</span><span class="cx"> context->SetTags(1, __LINE__);
</span><span class="cx">
</span></span></pre>
</div>
</div>
</body>
</html>