Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vaev-layout: Refact builder reflecting block/inline outside-display b… #33

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/libs/karm-print/pdf-printer.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ struct PdfPrinter : public FilePrinter {
for (auto& [_, value] : fontManager.mapping._els) {
auto& [id, fontFace] = value;

if (not fontFace.is<Text::TtfFontface>()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback font or panic?

panic("no support for printing fonts other than TrueType");
}

TrueTypeFontAdapter ttfAdapter{
fontFace.cast<Text::TtfFontface>().unwrap(),
alloc
Expand Down
22 changes: 21 additions & 1 deletion src/libs/karm-text/prose.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,28 @@ void Prose::clear() {
_cells.clear();
_blocks.clear();
_blocksMeasured = false;
_beginBlock();
_lines.clear();

_beginBlock();
}

void Prose::copySpanStack(Prose const& prose) {
Vec<Box<Text::Prose::Span>> spans;
auto currSpan = prose._currentSpan;
while (currSpan) {
spans.pushBack(*currSpan);
currSpan = currSpan->parent;
}

reverse(mutSub(spans));
_spans = std::move(spans);

for (usize i = 0; i + 1 < _spans.len(); ++i) {
_spans[i + 1]->parent = &*_spans[i];
}

if (_spans.len())
_currentSpan = &*last(_spans);
}

void Prose::append(Slice<Rune> runes) {
Expand Down
4 changes: 4 additions & 0 deletions src/libs/karm-text/prose.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ struct Prose : public Meta::Pinned {

void pushSpan() {
_spans.pushBack(makeBox<Span>(_currentSpan));
auto parentSpan = _currentSpan;
_currentSpan = &*last(_spans);
_currentSpan->parent = parentSpan;
}

void spanColor(Gfx::Color color) {
Expand All @@ -204,6 +206,8 @@ struct Prose : public Meta::Pinned {
_currentSpan = _currentSpan->parent;
}

void copySpanStack(Prose const& prose);

// MARK: Layout ------------------------------------------------------------

void _measureBlocks();
Expand Down
28 changes: 27 additions & 1 deletion src/web/vaev-dom/html/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,8 +1121,34 @@ void HtmlParser::_handleInBody(HtmlToken const& t) {
}

// TODO: An end tag whose tag name is "br"

// TODO: A start tag whose tag name is one of: "area", "br", "embed", "img", "keygen", "wbr"
else if (
t.name == "br" or
(t.type == HtmlToken::START_TAG and
(t.name == "area" or t.name == "br" or t.name == "embed" or t.name == "img" or t.name == "keygen" or t.name == "wbr")
)
) {
if (t.type == HtmlToken::END_TAG) {
// Parse error.
_raise();

// Drop the attributes from the token, and act as described in the next entry; i.e. act as if
// this was a "br" start tag token with no attributes, rather than the end tag token that it actually is.
// FIXME: cannot drop attributes since token is const
}

// Reconstruct the active formatting elements, if any.
_reconstructActiveFormattingElements();

// Insert an HTML element for the token. Immediately pop the current node off the stack of open elements.
_insertHtmlElement(t);
_openElements.popBack();

// TODO: Acknowledge the token's self-closing flag, if it is set.

// Set the frameset-ok flag to "not ok".
_framesetOk = false;
}

// TODO: A start tag whose tag name is "input"
else if (t.type == HtmlToken::START_TAG and t.name == "input") {
Expand Down
43 changes: 42 additions & 1 deletion src/web/vaev-layout/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,51 @@ export struct BreakpointTraverser {
export struct FormatingContext;
export struct Box;

export struct InlineBox {
/* NOTE:
This is a sketch implementation of the data model for InlineBox. We should be able to:
- add different inline elements to it, from different types (Prose, Image, inline-block)
- retrieve the added data to be displayed in the same Inline Formatting Context (break lines and display
into line boxes)
- respect different styling for the same line (font, fontsize, color, etc)
*/
Text::ProseStyle const _style;
Rc<Text::Prose> prose;

InlineBox(Text::ProseStyle style) : _style(style), prose(makeRc<Text::Prose>(_style)) {}

InlineBox(Rc<Text::Prose> prose) : _style(prose->_style), prose(prose) {}

void startInlineBox(Text::ProseStyle proseStyle) {
// FIXME: ugly workaround while we dont fix the Prose data structure
prose->pushSpan();
if (proseStyle.color)
prose->spanColor(proseStyle.color.unwrap());
}

void endInlineBox() {
prose->popSpan();
}

void add(Box&&) {}

bool active() {
return prose->_runes.len();
}

void clear() {
auto oldProse = prose;

prose = makeRc<Text::Prose>(_style);

prose->copySpanStack(*oldProse);
}
};

export using Content = Union<
None,
Vec<Box>,
Rc<Text::Prose>,
InlineBox,
Karm::Image::Picture>;

export struct Attrs {
Expand Down
Loading