Skip to content

Commit

Permalink
Merge pull request #1267 from vivliostyle/fix/issue1264
Browse files Browse the repository at this point in the history
fix: vertical-in-horizontal block height and horizontal-in-vertical block width not computed properly
  • Loading branch information
MurakamiShinyu authored Feb 8, 2024
2 parents 099e404 + 0f7d45e commit 9835998
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 7 deletions.
2 changes: 2 additions & 0 deletions packages/core/src/vivliostyle/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,8 @@ export const ident: { [key: string]: Ident } = {
list_item: getName("list-item"),
ltr: getName("ltr"),
manual: getName("manual"),
max_content: getName("max-content"),
min_content: getName("min-content"),
none: getName("none"),
normal: getName("normal"),
oeb_page_foot: getName("oeb-page-foot"),
Expand Down
61 changes: 54 additions & 7 deletions packages/core/src/vivliostyle/vgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -439,22 +439,69 @@ export class ViewFactory
this.isFootnote,
this.nodeContext,
);
const isRoot = this.nodeContext.parent == null;
if (isRoot) {
// Ensure that writing-mode and direction are set on the root element.
if (!cascMap["writing-mode"] && this.styler.rootStyle["writing-mode"]) {
cascMap["writing-mode"] = this.styler.rootStyle[
"writing-mode"
] as CssCascade.CascadeValue;
}
if (!cascMap["direction"] && this.styler.rootStyle["direction"]) {
cascMap["direction"] = this.styler.rootStyle[
"direction"
] as CssCascade.CascadeValue;
}
}
const verticalParent = vertical;
vertical = CssCascade.isVertical(cascMap, context, vertical);
const verticalChanged = !isRoot && vertical !== verticalParent;
rtl = CssCascade.isRtl(cascMap, context, rtl);

const transform = (
name: string,
cascVal: CssCascade.CascadeValue,
): Css.Val => {
// The percent value of inline-size on vertical-in-horizontal or
// horizontal-in-vertical block needs to be resolved against the
// page area height or width. (Fix for issue #1264)
let percentRef: number;
if (verticalChanged) {
if (vertical) {
if (/^(min-|max-)?(height|inline-size)$/.test(name)) {
percentRef = context.pageAreaHeight;
}
} else {
if (/^(min-|max-)?(width|inline-size)$/.test(name)) {
percentRef = context.pageAreaWidth;
}
}
}
let value = cascVal.evaluate(context, name, percentRef, vertical);
if (name == "font-family") {
value = this.docFaces.filterFontFamily(value);
}
return value;
};

CssCascade.convertToPhysical(
cascMap,
computedStyle,
vertical,
rtl,
(name, cascVal) => {
let value = cascVal.evaluate(context, name, undefined, vertical);
if (name == "font-family") {
value = this.docFaces.filterFontFamily(value);
}
return value;
},
transform,
);

if (verticalChanged) {
// The auto value of inline-size on vertical-in-horizontal or
// horizontal-in-vertical block is changed to max-content.
// (Fix for issue #1264)
const inlineSize = computedStyle[vertical ? "height" : "width"];
if (!inlineSize || inlineSize === Css.ident.auto) {
computedStyle[vertical ? "height" : "width"] = Css.ident.max_content;
}
}

if (Display.isRunning(computedStyle["position"])) {
// Running elements
computedStyle["position"] = Css.ident.fixed;
Expand Down

0 comments on commit 9835998

Please sign in to comment.