Files
serenity/Userland/Libraries/LibWeb/Layout/LineBox.h
Aliaksandr Kalenik b01060c7d8 Everywhere: Limit layout text fragments to use one font for all glyphs
The ChunkIterator now limits a chunk to using only one font (before, it
was possible to have a chunk with >1 font, when `unicode-range` CSS
property is used).

This change allows us to reduce some complexity in the text shaping and
painting code and makes us compatible with the APIs in Skia and
HarfBuzz.

(cherry picked from commit 7181c3f2ea5fba73e77d98acbf9e46640b4a9015,
minorly amended to fix conflicts caused by:
* Our VectorFont not being renamed to Typeface
* Us cherry-picking https://github.com/LadybirdBrowser/ladybird/pull/502
  first
* Us still having bitmap fonts, and hence needing glyph_spacing()

Also amended for:
* AffineDisplayListPlayerCPU changes
* Removing pure virtuals for glyph_id_for_code_point and
  glyph_id_for_code_point in Font.h again since we still have BitmapFont
  which can't implement them
* Updating more Painter methods that we still had
  (Painter::draw_glyph_or_emoji(), Painter::draw_text_run())
)
2024-10-09 20:12:39 -04:00

54 lines
1.7 KiB
C++

/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Vector.h>
#include <LibWeb/Layout/LineBoxFragment.h>
namespace Web::Layout {
class LineBox {
public:
LineBox() = default;
CSSPixels width() const { return m_width; }
CSSPixels height() const { return m_height; }
CSSPixels bottom() const { return m_bottom; }
CSSPixels baseline() const { return m_baseline; }
void add_fragment(Node const& layout_node, int start, int length, CSSPixels leading_size, CSSPixels trailing_size, CSSPixels leading_margin, CSSPixels trailing_margin, CSSPixels content_width, CSSPixels content_height, CSSPixels border_box_top, CSSPixels border_box_bottom, RefPtr<Gfx::GlyphRun> glyph_run = {});
Vector<LineBoxFragment> const& fragments() const { return m_fragments; }
Vector<LineBoxFragment>& fragments() { return m_fragments; }
void trim_trailing_whitespace();
bool is_empty_or_ends_in_whitespace() const;
bool is_empty() const { return m_fragments.is_empty() && !m_has_break; }
AvailableSize original_available_width() const { return m_original_available_width; }
private:
friend class BlockContainer;
friend class InlineFormattingContext;
friend class LineBuilder;
Vector<LineBoxFragment> m_fragments;
CSSPixels m_width { 0 };
CSSPixels m_height { 0 };
CSSPixels m_bottom { 0 };
CSSPixels m_baseline { 0 };
// The amount of available width that was originally available when creating this line box. Used for text justification.
AvailableSize m_original_available_width { AvailableSize::make_indefinite() };
bool m_has_break { false };
bool m_has_forced_break { false };
};
}