-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Preserve fractional values for colors #1432
Comments
I identified the root cause of the issue:
Using At this point, it is unclear whether this behavior is a Chromium bug or the intended behavior as per the specification. For reference: The only workaround I could find is to use
I initially thought that Vivliostyle rounding off fractionals is an intended behavior, but tracing the root cause suggests otherwise. This issue now should be labeled as "bug." |
Related CSS spec: https://drafts.csswg.org/css-color-4/#css-serialization-of-srgb
So the Chromium's behavior in which the values are rounded to eight bit on serialization is not great, but not wrong. Fractional values in
|
Thank you for the clarification! This is exactly the document I was looking for. Then, if we make the following changes for example, is there anything we should consider? diff --git a/packages/core/src/vivliostyle/base.ts b/packages/core/src/vivliostyle/base.ts
index 43722e911..afe1b35d5 100644
--- a/packages/core/src/vivliostyle/base.ts
+++ b/packages/core/src/vivliostyle/base.ts
@@ -384,17 +384,21 @@ export function getPrefixedPropertyNames(prop: string): string[] | null {
return null;
}
+function appendStyleString(elem: Element, prop: string, value: string) {
+ const existingStyle = (elem.getAttribute("style") || "").replace(/;\s*$/, "");
+ elem.setAttribute("style", `${existingStyle}; ${prop}: ${value};`);
+}
+
export function setCSSProperty(
elem: Element,
prop: string,
value: string,
): void {
- const elemStyle = (elem as HTMLElement)?.style;
- if (!elemStyle) {
+ if (!elem) {
return;
}
if (prop.startsWith("--")) {
- elemStyle.setProperty(prop, value || " ");
+ appendStyleString(elem, prop, value || " ");
return;
}
const prefixedPropertyNames = getPrefixedPropertyNames(prop);
@@ -414,12 +418,12 @@ export function setCSSProperty(
switch (value) {
case "all":
// workaround for Chrome 93 bug https://crbug.com/1242755
- elemStyle.setProperty("text-indent", "0");
+ appendStyleString(elem, "text-indent", "0");
break;
}
break;
}
- elemStyle.setProperty(prefixed, value);
+ appendStyleString(elem, prefixed, value);
}
} |
I see. It may work. Could you make a PR? |
調査メモ:
|
調査メモ:CSS変数
|
|
なるほど!
|
PR #1434 のコメント:
CSSWGやChromiumの開発者たちは明らかにこの問題を認識していると思います。CSS Color Level 4 §15.2.2. CSS serialization of sRGB values に、シリアライズの結果が
と書かれています。 Chromiumの開発者がRGB値の精度が失われる問題を認識しているかですが、前のコメントで引用したChromium issueの Implement CSS Color Level 4 にある Chromium のコミットの次の記述や、
ChromiumソースコードにTODOとして書かれている次の記述から、
RGB値の精度が失われる問題を将来的に解決したいのではないかと推測します。 Chromiumでこれが解決されるまでは、精度が重要な色の指定をする場合には |
ありがとうございます。Chromiumのソースコードにも言及があるのですね。
私の目的はこの記法で達成されたため、本件に関してこれ以上PRを提出する予定はありません。 |
Issueのタイトル 問題は legacy syntax になることではなくて、値が整数に丸められて精度が失われることだということを明記するとよいかと思います。 コンマ区切りのレガシー形式にシリアライズされることは CSS Color Level 4 §15.2.2. CSS serialization of sRGB values の仕様どおりです。 求めることは、コンマ区切りの つまり、 |
助言までいただきありがとうございます!Chromium Issue Trackerに慣れておらず操作がよくわからないのですが、編集はできないようなのでまずはコメントで補足しました。 |
Is your feature request related to a problem? Please describe.
In the Chromium used by the latest version of the Vivliostyle CLI, fractional numbers for colors, such as
rgb(0.0 0.1 0.2)
, appear to also influence the color rendering in the PDF output.However, when using Vivliostyle, these fractional values seem to be rounded during processing, resulting in reduced color precision.
Describe the solution you'd like
It would be preferable for Vivliostyle to preserve fractional color values as-is, without rounding, during processing.
This would ensure higher color fidelity in the PDF output, aligning Vivliostyle's behavior with that of Chromium and improving the overall quality of the generated PDFs.
The text was updated successfully, but these errors were encountered: