Skip to content

Commit

Permalink
Merge pull request microsoft#4 from acoates-ms/text_wincomp_color
Browse files Browse the repository at this point in the history
Implement color on fragments
  • Loading branch information
rurikoaraki authored Mar 22, 2022
2 parents 79764fd + 52a76f5 commit b463b39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
17 changes: 17 additions & 0 deletions vnext/Microsoft.ReactNative/Fabric/CompParagraphComponentView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,23 @@ void CompParagraphComponentView::DrawText() noexcept {
d2dDeviceContext->CreateSolidColorBrush(D2D1::ColorF(D2D1::ColorF::Black, 1.0f), brush.put()));
}

// Create color effects for individual text fragments.
unsigned int position = 0;
unsigned int length = 0;
for (auto fragment : m_attributedStringBox.getValue().getFragments()) {
length = static_cast<UINT32>(fragment.string.length());
DWRITE_TEXT_RANGE range = {position, length};
if (fragment.textAttributes.foregroundColor) {
winrt::com_ptr<ID2D1SolidColorBrush> brush;
auto winColor = fragment.textAttributes.foregroundColor.AsWindowsColor();
D2D1::ColorF color{winColor.R / 255.0f, winColor.G / 255.0f, winColor.B / 255.0f, winColor.A / 255.0f};
winrt::check_hresult(d2dDeviceContext->CreateSolidColorBrush(color, brush.put()));
m_textLayout->SetDrawingEffect(brush.get(), range);
}

position += length;
}

d2dDeviceContext->Clear(D2D1::ColorF(D2D1::ColorF::Black, 0.0f));

// Draw the line of text at the specified offset, which corresponds to the top-left
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void TextLayoutManager::GetTextLayout(
range);
spTextLayout->SetFontStyle(fragmentStyle, range);
spTextLayout->SetFontSize(attributes.fontSize, range);
// ugh color stuff

position += length;
}
Expand Down

0 comments on commit b463b39

Please sign in to comment.