mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 17:47:44 +00:00
LibHTML: Implement "text-align: justify"
In order for this to work nicely, I made the line box classes use float instead of int for its geometry information. Justification works by distributing all of the whitespace on the line (including the trailing whitespace before the line break) evenly across the spaces in-between words. We should probably use floating point (or maybe fixed point?) for all the layout metrics stuff. But one thing at a time. :^)
This commit is contained in:
parent
ea5da0f9b5
commit
eb77e680ed
9 changed files with 72 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
|||
#pragma once
|
||||
|
||||
#include <LibDraw/Rect.h>
|
||||
#include <LibDraw/FloatRect.h>
|
||||
|
||||
class LayoutNode;
|
||||
class RenderingContext;
|
||||
|
@ -8,7 +8,7 @@ class RenderingContext;
|
|||
class LineBoxFragment {
|
||||
friend class LineBox;
|
||||
public:
|
||||
LineBoxFragment(const LayoutNode& layout_node, int start, int length, const Rect& rect)
|
||||
LineBoxFragment(const LayoutNode& layout_node, int start, int length, const FloatRect& rect)
|
||||
: m_layout_node(layout_node)
|
||||
, m_start(start)
|
||||
, m_length(length)
|
||||
|
@ -19,14 +19,16 @@ public:
|
|||
const LayoutNode& layout_node() const { return m_layout_node; }
|
||||
int start() const { return m_start; }
|
||||
int length() const { return m_length; }
|
||||
const Rect& rect() const { return m_rect; }
|
||||
Rect& rect() { return m_rect; }
|
||||
const FloatRect& rect() const { return m_rect; }
|
||||
FloatRect& rect() { return m_rect; }
|
||||
|
||||
void render(RenderingContext&);
|
||||
|
||||
bool is_justifiable_whitespace() const;
|
||||
|
||||
private:
|
||||
const LayoutNode& m_layout_node;
|
||||
int m_start { 0 };
|
||||
int m_length { 0 };
|
||||
Rect m_rect;
|
||||
FloatRect m_rect;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue