Skip to content
Draft
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
12 changes: 9 additions & 3 deletions src/vaev-engine/dom/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ export struct Window {
Font::Database db;
if (not db.loadSystemFonts())
logWarn("not all fonts were properly loaded into database");
Style::Computer computer{_media, *_document->styleSheets, db};
Style::Computer computer{
_media,
*_document->styleSheets,
std::move(db),
};
computer.build();
computer.styleDocument(*_document);
}
Expand All @@ -96,8 +100,10 @@ export struct Window {
}

[[clang::coro_wrapper]]
Generator<Print::Page> print(Print::Settings const& settings) const {
return Driver::print(_document.upgrade(), settings);
Generator<Print::Page> print(Print::Settings const& settings) {
auto context = Driver::PaginationContext::create(*_document, settings);
for (auto p : context.iterPages())
co_yield p;
}
};

Expand Down
445 changes: 238 additions & 207 deletions src/vaev-engine/driver/print.cpp

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/vaev-engine/driver/render.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,15 @@ export struct RenderResult {
};

export RenderResult render(Gc::Ref<Dom::Document> dom, Style::Media const& media, Layout::Viewport viewport) {
Font::Database db;
if (not db.loadSystemFonts())
Font::Database database;
if (not database.loadSystemFonts())
logWarn("not all fonts were properly loaded into database");

Style::Computer computer{media, *dom->styleSheets, db};
Style::Computer computer{
media,
*dom->styleSheets,
std::move(database),
};
computer.build();
computer.styleDocument(*dom);

Expand Down
23 changes: 18 additions & 5 deletions src/vaev-engine/layout/base/breaks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export struct Breakpoint {
Vec<Opt<Breakpoint>> children = {};
Advance advance;

static Breakpoint const START_OF_DOCUMENT;
static Breakpoint const END_OF_DOCUMENT;

static Breakpoint forced(usize endIdx) {
return {
.endIdx = endIdx,
Expand Down Expand Up @@ -171,19 +174,29 @@ export struct Breakpoint {
}
};

Breakpoint const Breakpoint::START_OF_DOCUMENT = {
Copy link
Member

Choose a reason for hiding this comment

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

YES ! THANK GOD

.endIdx = 0,
.advance = Advance::WITHOUT_CHILDREN
};

Breakpoint const Breakpoint::END_OF_DOCUMENT = {
.endIdx = 1,
.advance = Advance::WITHOUT_CHILDREN
};

export struct BreakpointTraverser {
MutCursor<Breakpoint> prevIteration, currIteration;
Cursor<Breakpoint> prevIteration, currIteration;

BreakpointTraverser(
MutCursor<Breakpoint> prev = nullptr,
MutCursor<Breakpoint> curr = nullptr
Cursor<Breakpoint> prev = nullptr,
Cursor<Breakpoint> curr = nullptr
) : prevIteration(prev), currIteration(curr) {}

bool isDeactivated() {
return prevIteration == nullptr and currIteration == nullptr;
}

MutCursor<Breakpoint> traversePrev(usize i, usize j) {
Cursor<Breakpoint> traversePrev(usize i, usize j) {
if (prevIteration and prevIteration->children.len() > 0 and
(i + 1 == prevIteration->endIdx or
(prevIteration->advance == Breakpoint::Advance::WITH_CHILDREN and i == prevIteration->endIdx))) {
Expand All @@ -193,7 +206,7 @@ export struct BreakpointTraverser {
return nullptr;
}

MutCursor<Breakpoint> traverseCurr(usize i, usize j) {
Cursor<Breakpoint> traverseCurr(usize i, usize j) {
if (currIteration and currIteration->children.len() > 0 and i + 1 == currIteration->endIdx) {
if (currIteration->children[j])
return &currIteration->children[j].unwrap();
Expand Down
4 changes: 2 additions & 2 deletions src/vaev-engine/layout/base/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export struct Input {
Vec2Au position = {};
Vec2Au availableSpace = {};
Vec2Au containingBlock = {};
MutCursor<RunningPositionMap> runningPosition = nullptr;
usize pageNumber = 0;
MutCursor<Runnings> runningPosition = nullptr;
usize pageIndex = 0;

BreakpointTraverser breakpointTraverser = {};

Expand Down
6 changes: 3 additions & 3 deletions src/vaev-engine/layout/base/running-position.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ export struct RunningPositionInfo {
}
};

struct RunningPositionMap {
// Mapping the different Running positions to their respective names and their page.
struct Runnings {
Map<CustomIdent, Vec<RunningPositionInfo>> content;

void add(usize pageNumber, Layout::Box& box) {
void add(usize pageNumber, Box& box) {
auto& style = box.style;

if (auto position = style->position.is<RunningPosition>()) {
Expand Down Expand Up @@ -79,7 +80,6 @@ struct RunningPositionMap {
}

Slice<RunningPositionInfo> _searchPage(Slice<RunningPositionInfo> list, usize page) {
page++; // pages are 1-indexed
// binary search of all running positions that match the page

auto res = search(list, [&](RunningPositionInfo const& info) {
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ struct BlockFormatingContext : FormatingContext {
.availableSpace = {input.availableSpace.x, 0_au},
.containingBlock = {inlineSize, input.knownSize.y.unwrapOr(0_au)},
.runningPosition = input.runningPosition,
.pageNumber = input.pageNumber,
.pageIndex = input.pageIndex,
Copy link
Member

Choose a reason for hiding this comment

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

why pageIndex ?

.breakpointTraverser = input.breakpointTraverser.traverseInsideUsingIthChild(i),
.pendingVerticalSizes = input.pendingVerticalSizes,
};
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/builder/mod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ export Box buildElement(Gc::Ref<Dom::Element> elt) {
return box;
}

export Box buildForPseudoElement(Dom::PseudoElement& el, usize currentPage, RunningPositionMap& runningPos) {
export Box buildForPseudoElement(Dom::PseudoElement& el, usize currentPage, Runnings& runningPos) {
auto proseStyle = _proseStyleFromStyle(*el.specifiedValues(), el.specifiedValues()->fontFace);

if (el.specifiedValues()->content.is<String>()) {
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/flex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ struct FlexFormatingContext : FormatingContext {
.position = flexItem.position,
.availableSpace = availableSpace,
.runningPosition = input.runningPosition,
.pageNumber = input.pageNumber,
.pageIndex = input.pageIndex,
}
);
flexItem.commit(input.fragment);
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ struct InlineFormatingContext : FormatingContext {
input.knownSize.y.unwrapOr(0_au)
},
.runningPosition = input.runningPosition,
.pageNumber = input.pageNumber,
.pageIndex = input.pageIndex,
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vaev-engine/layout/positioned.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export void lookForRunningPosition(Input& input, Box& box) {

if (box.style->position.is<RunningPosition>()) {
auto& runningMap = input.runningPosition.peek();
runningMap.add(input.pageNumber, box);
runningMap.add(input.pageIndex, box);
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/vaev-engine/style/computer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Vaev::Style {
export struct Computer {
Media _media;
StyleSheetList const& _styleBook;
Font::Database& fontBook;
Font::Database _database;
StyleRuleLookup _styleRuleLookup{};

// MARK: Cascading ---------------------------------------------------------
Expand Down Expand Up @@ -304,7 +304,7 @@ export struct Computer {
_evalRule(rule, page, *computed);

for (auto& area : computed->_areas) {
auto font = _lookupFontface(fontBook, *area.specifiedValues());
auto font = _lookupFontface(_database, *area.specifiedValues());
area.specifiedValues()->fontFace = font;
}

Expand All @@ -323,7 +323,7 @@ export struct Computer {
if (not parentSpecifiedValues.font.sameInstance(specifiedValues->font) and
(parentSpecifiedValues.font->families != specifiedValues->font->families or
parentSpecifiedValues.font->weight != specifiedValues->font->weight)) {
auto font = _lookupFontface(fontBook, *specifiedValues);
auto font = _lookupFontface(_database, *specifiedValues);
specifiedValues->fontFace = font;
} else {
specifiedValues->fontFace = parentSpecifiedValues.fontFace;
Expand All @@ -338,7 +338,7 @@ export struct Computer {
void styleDocument(Dom::Document& doc) {
if (auto el = doc.documentElement()) {
auto rootSpecifiedValues = makeRc<SpecifiedValues>(SpecifiedValues::initial());
rootSpecifiedValues->fontFace = _lookupFontface(fontBook, *rootSpecifiedValues);
rootSpecifiedValues->fontFace = _lookupFontface(_database, *rootSpecifiedValues);
styleElement(*rootSpecifiedValues, *el);
}
_propagateBodyBackgroundToHtml(doc);
Expand Down Expand Up @@ -390,13 +390,13 @@ export struct Computer {
}

// FIXME: use attrs from style::FontFace
if (fontBook.load(resolvedUrl.unwrap()))
if (_database.load(resolvedUrl.unwrap()))
Copy link
Member

Choose a reason for hiding this comment

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

idk about "database" it's not clear that we're talking about fonts

break;

logWarn("Failed to load font {}", ff.family);
} else {
if (
fontBook.queryExact(src.identifier.unwrap<FontFamily>().name)
_database.queryExact(src.identifier.unwrap<FontFamily>().name)
)
break;

Expand Down
Loading