1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-24 01:15: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

@ -39,6 +39,7 @@
#include <LibGUI/Window.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/Font.h>
#include <LibGfx/FontDatabase.h>
#include <LibGfx/Palette.h>
#include <ctype.h>
#include <fcntl.h>
@ -480,7 +481,7 @@ void TextEditor::paint_event(PaintEvent& event)
Gfx::IntRect character_rect = { visual_line_rect.location(), { 0, line_height() } };
for (size_t i = 0; i < visual_line_text.length(); ++i) {
u32 code_point = visual_line_text.substring_view(i, 1).code_points()[0];
const Gfx::Font* font = &this->font();
RefPtr<Gfx::Font> font = this->font();
Color color;
Optional<Color> background_color;
bool underline = false;
@ -490,8 +491,10 @@ void TextEditor::paint_event(PaintEvent& event)
if (!span.range.contains(physical_position))
continue;
color = span.color;
if (span.font)
font = span.font;
if (span.bold) {
if (auto bold_font = Gfx::FontDatabase::the().get(font->family(), font->presentation_size(), 700))
font = bold_font;
}
background_color = span.background_color;
underline = span.is_underlined;
break;