1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:35:07 +00:00

LibGUI: Make syntax highlighter communicate boldness instead of font

Now that fonts know their own weight, we no longer need highlighters to
tell us which font to use. Instead, they can just say "this should be
bold" and we'll find the right font ourselves.
This commit is contained in:
Andreas Kling 2020-12-28 15:51:43 +01:00
parent 105eb8e1bc
commit a35693915e
9 changed files with 37 additions and 34 deletions

View file

@ -36,29 +36,29 @@ static TextStyle style_for_token_type(Gfx::Palette palette, Cpp::Token::Type typ
{
switch (type) {
case Cpp::Token::Type::Keyword:
return { palette.syntax_keyword(), &Gfx::Font::default_bold_fixed_width_font() };
return { palette.syntax_keyword(), true };
case Cpp::Token::Type::KnownType:
return { palette.syntax_type(), &Gfx::Font::default_bold_fixed_width_font() };
return { palette.syntax_type(), true };
case Cpp::Token::Type::Identifier:
return { palette.syntax_identifier() };
return { palette.syntax_identifier(), false };
case Cpp::Token::Type::DoubleQuotedString:
case Cpp::Token::Type::SingleQuotedString:
case Cpp::Token::Type::RawString:
return { palette.syntax_string() };
return { palette.syntax_string(), false };
case Cpp::Token::Type::Integer:
case Cpp::Token::Type::Float:
return { palette.syntax_number() };
return { palette.syntax_number(), false };
case Cpp::Token::Type::IncludePath:
return { palette.syntax_preprocessor_value() };
return { palette.syntax_preprocessor_value(), false };
case Cpp::Token::Type::EscapeSequence:
return { palette.syntax_keyword(), &Gfx::Font::default_bold_fixed_width_font() };
return { palette.syntax_keyword(), true };
case Cpp::Token::Type::PreprocessorStatement:
case Cpp::Token::Type::IncludeStatement:
return { palette.syntax_preprocessor_statement() };
return { palette.syntax_preprocessor_statement(), false };
case Cpp::Token::Type::Comment:
return { palette.syntax_comment() };
return { palette.syntax_comment(), false };
default:
return { palette.base_text() };
return { palette.base_text(), false };
}
}
@ -91,7 +91,7 @@ void CppSyntaxHighlighter::rehighlight(Gfx::Palette palette)
span.range.set_end({ token.m_end.line, token.m_end.column });
auto style = style_for_token_type(palette, token.m_type);
span.color = style.color;
span.font = style.font;
span.bold = style.bold;
span.is_skippable = token.m_type == Cpp::Token::Type::Whitespace;
span.data = reinterpret_cast<void*>(token.m_type);
spans.append(span);