Skip to content

Commit

Permalink
Merge pull request #1254 from vivliostyle/fix/remove-ruby-font-size-w…
Browse files Browse the repository at this point in the history
…orkaround

fix: remove ruby font-size workaround no longer necessary
  • Loading branch information
MurakamiShinyu authored Jan 28, 2024
2 parents 4427101 + 3138fda commit 46f46f5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 55 deletions.
6 changes: 0 additions & 6 deletions packages/core/src/vivliostyle/layout-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export function calculateEdge(

const element = node.nodeType === 1 ? (node as Element) : node.parentElement;
if (element && element.namespaceURI === Base.NS.XHTML) {
if (element.localName === "rt" && (element as HTMLElement).style["zoom"]) {
// "zoom" is set in fixRubyTextFontSize() to fix the issue #673 for Chrome.
// when zoom is set, it is hard to get the edge value, so return NaN.
// (Fix for issues #804 and #808)
return NaN;
}
if (
/^([\d\.]|super|(text-)?top)/.test(
(element as HTMLElement).style.verticalAlign,
Expand Down
49 changes: 0 additions & 49 deletions packages/core/src/vivliostyle/vgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2230,12 +2230,6 @@ export class ViewFactory
);
continue;
}
if (target.localName === "rt" && propName === "font-size") {
// Fix for Issue #673
if (this.fixRubyTextFontSize(target, value)) {
continue;
}
}
if (
isRoot &&
this.page.pageAreaElement &&
Expand Down Expand Up @@ -2340,49 +2334,6 @@ export class ViewFactory
return parentLineHeight;
}

/**
* Fix ruby text font size.
* Issue #673: Minimum font size setting in Chrome causes ruby font size problem
* @param target the rt element
* @param value the font-size value
* @returns true if the font-size fix is done
*/
fixRubyTextFontSize(target: Element, value: Css.Val): boolean {
if (!/Chrome/.test(navigator.userAgent)) {
// Do nothing if the browser engine is not "Chrome"
return false;
}
if (!value.isNumeric()) {
return false;
}
const numeric = value as Css.Numeric;
let fontSizeInPx: number;
if (numeric.unit === "%" || numeric.unit === "em") {
const parentElem = this.nodeContext?.parent?.viewNode as Element;
const parentFontSize =
parentElem &&
parseFloat(this.viewport.window.getComputedStyle(parentElem).fontSize);
fontSizeInPx =
(parentFontSize * numeric.num) / (numeric.unit === "%" ? 100 : 1);
} else {
fontSizeInPx = Css.convertNumericToPx(numeric, this.context).num;
}
if (!fontSizeInPx) {
return false;
}
const minFontSizeInPx = 10; // Default minimum font size setting in Chrome
if (fontSizeInPx >= minFontSizeInPx) {
return false;
}
if ((target as HTMLElement).style?.["zoom"] === undefined) {
return false;
}
const zoom = fontSizeInPx / minFontSizeInPx;
Base.setCSSProperty(target, "font-size", `${minFontSizeInPx}px`);
Base.setCSSProperty(target, "zoom", `${zoom}`);
return true;
}

/** @override */
applyPseudoelementStyle(
nodeContext: Vtree.NodeContext,
Expand Down

1 comment on commit 46f46f5

@vercel
Copy link

@vercel vercel bot commented on 46f46f5 Jan 28, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

vivliostyle – ./

vivliostyle-git-master-vivliostyle.vercel.app
vivliostyle.vercel.app
vivliostyle-vivliostyle.vercel.app

Please sign in to comment.