2021-07-26 00:20:11 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* Copyright (c) 2021, sin-ack <sin-ack@protonmail.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-04 21:02:33 +03:00
|
|
|
#include <AK/DeprecatedString.h>
|
2022-09-14 01:56:13 +03:00
|
|
|
#include <AK/Forward.h>
|
2021-07-26 00:20:11 +03:00
|
|
|
#include <AK/Utf32View.h>
|
|
|
|
#include <AK/Utf8View.h>
|
|
|
|
#include <AK/Vector.h>
|
2022-04-09 10:28:38 +03:00
|
|
|
#include <LibGfx/Font/Font.h>
|
2022-09-14 01:56:13 +03:00
|
|
|
#include <LibGfx/Forward.h>
|
2021-07-26 00:20:11 +03:00
|
|
|
#include <LibGfx/Rect.h>
|
|
|
|
#include <LibGfx/TextElision.h>
|
|
|
|
#include <LibGfx/TextWrapping.h>
|
|
|
|
|
|
|
|
namespace Gfx {
|
|
|
|
|
|
|
|
// FIXME: This currently isn't an ideal way of doing things; ideally, TextLayout
|
|
|
|
// would be doing the rendering by painting individual glyphs. However, this
|
|
|
|
// would regress our Unicode bidirectional text support. Therefore, fixing this
|
|
|
|
// requires:
|
|
|
|
// - Moving the bidirectional algorithm either here, or some place TextLayout
|
|
|
|
// can access;
|
|
|
|
// - Making TextLayout render the given text into something like a Vector<Line>
|
|
|
|
// where:
|
|
|
|
// using Line = Vector<DirectionalRun>;
|
|
|
|
// struct DirectionalRun {
|
|
|
|
// Utf32View glyphs;
|
|
|
|
// Vector<int> advance;
|
|
|
|
// TextDirection direction;
|
|
|
|
// };
|
|
|
|
// - Either;
|
|
|
|
// a) Making TextLayout output these Lines directly using a given Painter, or
|
|
|
|
// b) Taking the Lines from TextLayout and painting each glyph.
|
|
|
|
class TextLayout {
|
|
|
|
public:
|
2023-01-05 22:41:19 +03:00
|
|
|
TextLayout(Gfx::Font const& font, Utf8View const& text, FloatRect const& rect)
|
2021-07-26 00:20:11 +03:00
|
|
|
: m_font(font)
|
2023-01-06 13:55:23 +03:00
|
|
|
, m_font_metrics(font.pixel_metrics())
|
2021-07-26 00:20:11 +03:00
|
|
|
, m_text(text)
|
|
|
|
, m_rect(rect)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2023-01-06 13:55:23 +03:00
|
|
|
Vector<DeprecatedString, 32> lines(TextElision elision, TextWrapping wrapping) const
|
2021-07-26 00:20:11 +03:00
|
|
|
{
|
2023-01-06 13:55:23 +03:00
|
|
|
return wrap_lines(elision, wrapping);
|
2021-07-26 00:20:11 +03:00
|
|
|
}
|
|
|
|
|
2023-01-06 13:55:23 +03:00
|
|
|
FloatRect bounding_rect(TextWrapping) const;
|
2021-07-26 00:20:11 +03:00
|
|
|
|
|
|
|
private:
|
2023-01-06 13:55:23 +03:00
|
|
|
Vector<DeprecatedString, 32> wrap_lines(TextElision, TextWrapping) const;
|
|
|
|
DeprecatedString elide_text_from_right(Utf8View) const;
|
2021-07-26 00:20:11 +03:00
|
|
|
|
2023-01-05 22:41:19 +03:00
|
|
|
Font const& m_font;
|
2023-01-06 13:55:23 +03:00
|
|
|
FontPixelMetrics m_font_metrics;
|
2021-07-26 00:20:11 +03:00
|
|
|
Utf8View m_text;
|
2023-01-01 21:42:00 +03:00
|
|
|
FloatRect m_rect;
|
2021-07-26 00:20:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|