mirror of
https://github.com/RGBCube/serenity
synced 2025-05-15 03:04:59 +00:00

Previously, we determined the positions of glyphs for each text run at the time of painting, which constituted a significant portion of the painting process according to profiles. However, since we already go through each glyph to figure out the width of each fragment during layout, we can simultaneously gather data about the position of each glyph in the layout phase and utilize this information in the painting phase. I had to update expectations for a couple of reference tests. These updates are due to the fact that we now measure glyph positions during layout using a 1x font, and then linearly scale each glyph's position to device pixels during painting. This approach should be acceptable, considering we measure a fragment's width and height with an unscaled font during layout.
58 lines
1.9 KiB
C++
58 lines
1.9 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, Span<Gfx::DrawGlyphOrEmoji const> = {});
|
|
|
|
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; }
|
|
|
|
CSSPixelRect const& absolute_rect() const { return m_absolute_rect; }
|
|
void set_absolute_rect(CSSPixelRect const& rect) { m_absolute_rect = rect; }
|
|
|
|
private:
|
|
friend class BlockContainer;
|
|
friend class InlineFormattingContext;
|
|
friend class LineBuilder;
|
|
|
|
CSSPixelRect m_absolute_rect;
|
|
|
|
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 };
|
|
};
|
|
|
|
}
|