Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Render hyperlinks with a dashed underline #7419

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/renderer/base/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,11 @@ IRenderEngine::GridLines Renderer::s_GetGridlines(const TextAttribute& textAttri
{
lines |= IRenderEngine::GridLines::DoubleUnderline;
}

if (textAttribute.IsHyperlink())
{
lines |= IRenderEngine::GridLines::DashedUnderline;
}
return lines;
}

Expand Down
28 changes: 26 additions & 2 deletions src/renderer/dx/DxRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,17 @@ static constexpr D2D1_ALPHA_MODE _dxgiAlphaToD2d1Alpha(DXGI_ALPHA_MODE mode) noe
};
RETURN_IF_FAILED(_d2dFactory->CreateStrokeStyle(&strokeStyleProperties, nullptr, 0, &_strokeStyle));

const D2D1_STROKE_STYLE_PROPERTIES dashStrokeStyleProperties{
D2D1_CAP_STYLE_SQUARE, // startCap
D2D1_CAP_STYLE_SQUARE, // endCap
D2D1_CAP_STYLE_SQUARE, // dashCap
D2D1_LINE_JOIN_MITER, // lineJoin
0.f, // miterLimit
D2D1_DASH_STYLE_DASH, // dashStyle
0.f, // dashOffset
};
RETURN_IF_FAILED(_d2dFactory->CreateStrokeStyle(&dashStrokeStyleProperties, nullptr, 0, &_dashStrokeStyle));

// If in composition mode, apply scaling factor matrix
if (_chainMode == SwapChainMode::ForComposition)
{
Expand Down Expand Up @@ -1493,6 +1504,11 @@ try
_d2dDeviceContext->DrawLine({ x0, y0 }, { x1, y1 }, _d2dBrushForeground.Get(), strokeWidth, _strokeStyle.Get());
};

const auto DrawDashLine = [=](const auto x0, const auto y0, const auto x1, const auto y1, const auto strokeWidth) noexcept
{
_d2dDeviceContext->DrawLine({ x0, y0 }, { x1, y1 }, _d2dBrushForeground.Get(), strokeWidth, _dashStrokeStyle.Get());
};

// NOTE: Line coordinates are centered within the line, so they need to be
// offset by half the stroke width. For the start coordinate we add half
// the stroke width, and for the end coordinate we subtract half the width.
Expand Down Expand Up @@ -1544,14 +1560,22 @@ try
// In the case of the underline and strikethrough offsets, the stroke width
// is already accounted for, so they don't require further adjustments.

if (lines & (GridLines::Underline | GridLines::DoubleUnderline))
if (lines & (GridLines::Underline | GridLines::DoubleUnderline | GridLines::DashedUnderline))
{
const auto halfUnderlineWidth = _lineMetrics.underlineWidth / 2.0f;
const auto startX = target.x + halfUnderlineWidth;
const auto endX = target.x + fullRunWidth - halfUnderlineWidth;
const auto y = target.y + _lineMetrics.underlineOffset;

DrawLine(startX, y, endX, y, _lineMetrics.underlineWidth);
if (lines & GridLines::Underline)
{
DrawLine(startX, y, endX, y, _lineMetrics.underlineWidth);
}

if (lines & GridLines::DashedUnderline)
{
DrawDashLine(startX, y, endX, y, _lineMetrics.underlineWidth);
}

if (lines & GridLines::DoubleUnderline)
{
Expand Down
1 change: 1 addition & 0 deletions src/renderer/dx/DxRenderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ namespace Microsoft::Console::Render
::Microsoft::WRL::ComPtr<CustomTextLayout> _customLayout;
::Microsoft::WRL::ComPtr<CustomTextRenderer> _customRenderer;
::Microsoft::WRL::ComPtr<ID2D1StrokeStyle> _strokeStyle;
::Microsoft::WRL::ComPtr<ID2D1StrokeStyle> _dashStrokeStyle;

// Device-Dependent Resources
bool _recreateDeviceRequested;
Expand Down
3 changes: 2 additions & 1 deletion src/renderer/inc/IRenderEngine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ namespace Microsoft::Console::Render
Right = 0x8,
Underline = 0x10,
DoubleUnderline = 0x20,
Strikethrough = 0x40
Strikethrough = 0x40,
DashedUnderline = 0x80
};

virtual ~IRenderEngine() = 0;
Expand Down