|
1 | 1 | #include "Painter.h"
|
| 2 | +#include "Emoji.h" |
2 | 3 | #include "Font.h"
|
3 | 4 | #include "GraphicsBitmap.h"
|
4 |
| -#include "Emoji.h" |
5 | 5 | #include <AK/Assertions.h>
|
6 | 6 | #include <AK/StdLibExtras.h>
|
7 | 7 | #include <AK/StringBuilder.h>
|
| 8 | +#include <AK/Utf8View.h> |
8 | 9 | #include <LibDraw/CharacterBitmap.h>
|
9 | 10 | #include <math.h>
|
10 | 11 | #include <stdio.h>
|
11 | 12 | #include <unistd.h>
|
12 |
| -#include <AK/Utf8View.h> |
13 | 13 |
|
14 | 14 | #pragma GCC optimize("O3")
|
15 | 15 |
|
@@ -623,18 +623,22 @@ void Painter::draw_text_line(const Rect& a_rect, const Utf8View& text, const Fon
|
623 | 623 | }
|
624 | 624 | }
|
625 | 625 |
|
626 |
| - if (alignment == TextAlignment::TopLeft) { |
627 |
| - // No-op. |
628 |
| - } else if (alignment == TextAlignment::CenterLeft) { |
629 |
| - // No-op. |
630 |
| - } else if (alignment == TextAlignment::CenterRight) { |
| 626 | + switch (alignment) { |
| 627 | + case TextAlignment::TopLeft: |
| 628 | + case TextAlignment::CenterLeft: |
| 629 | + break; |
| 630 | + case TextAlignment::TopRight: |
| 631 | + case TextAlignment::CenterRight: |
631 | 632 | rect.set_x(rect.right() - font.width(final_text));
|
632 |
| - } else if (alignment == TextAlignment::Center) { |
| 633 | + break; |
| 634 | + case TextAlignment::Center: { |
633 | 635 | auto shrunken_rect = rect;
|
634 | 636 | shrunken_rect.set_width(font.width(final_text));
|
635 | 637 | shrunken_rect.center_within(rect);
|
636 | 638 | rect = shrunken_rect;
|
637 |
| - } else { |
| 639 | + break; |
| 640 | + } |
| 641 | + default: |
638 | 642 | ASSERT_NOT_REACHED();
|
639 | 643 | }
|
640 | 644 |
|
@@ -687,15 +691,23 @@ void Painter::draw_text(const Rect& rect, const StringView& raw_text, const Font
|
687 | 691 | bounding_rect.set_width(line_width);
|
688 | 692 | }
|
689 | 693 |
|
690 |
| - if (alignment == TextAlignment::TopLeft) { |
| 694 | + switch (alignment) { |
| 695 | + case TextAlignment::TopLeft: |
691 | 696 | bounding_rect.set_location(rect.location());
|
692 |
| - } else if (alignment == TextAlignment::CenterLeft) { |
| 697 | + break; |
| 698 | + case TextAlignment::TopRight: |
| 699 | + bounding_rect.set_location({ (rect.right() + 1) - bounding_rect.width(), rect.y() }); |
| 700 | + break; |
| 701 | + case TextAlignment::CenterLeft: |
693 | 702 | bounding_rect.set_location({ rect.x(), rect.center().y() - (bounding_rect.height() / 2) });
|
694 |
| - } else if (alignment == TextAlignment::CenterRight) { |
| 703 | + break; |
| 704 | + case TextAlignment::CenterRight: |
695 | 705 | bounding_rect.set_location({ (rect.right() + 1) - bounding_rect.width(), rect.center().y() - (bounding_rect.height() / 2) });
|
696 |
| - } else if (alignment == TextAlignment::Center) { |
| 706 | + break; |
| 707 | + case TextAlignment::Center: |
697 | 708 | bounding_rect.center_within(rect);
|
698 |
| - } else { |
| 709 | + break; |
| 710 | + default: |
699 | 711 | ASSERT_NOT_REACHED();
|
700 | 712 | }
|
701 | 713 |
|
|
0 commit comments