repairPaperInkExtras function
The Paper & ink repairs (after labels and display texts): the ink re-solved to ≥ 3:1 on every sheet sample (outlines, hatch, shadow), the stamp darkened (light) / lightened (dark) until it stands 3:1 off the digit slips, the operator face moved away from the ink until its hatch shows, and the wash refitted. Null when unreachable.
Implementation
Palette? repairPaperInkExtras(
Palette p,
ThemeSpec spec,
GuardrailLimits lim,
List<int> bgs,
) {
final ink = solveOnAll(p.shadow | 0xFF000000, bgs, ratioLarge);
if (ink == null) return null;
var out = p.copyWith(
digit: p.digit.copyWith(edge: ink),
operator: p.operator.copyWith(edge: ink),
equals: p.equals.copyWith(edge: ink),
function: p.function.copyWith(edge: ink),
shadow: ink,
);
final policy = lim.labelPolicy;
final dark = spec.isDark;
if (contrastRatio(out.equals.face, out.digit.face) < paperStampRatio) {
final face = argbToOklch(out.equals.face);
var l = face.l;
KeyColors? fixed;
for (var i = 0; i < 6 && fixed == null; i++) {
l = clamp01(l + (dark ? 0.04 : -0.04));
final pair = repairPair(
(l: l, c: face.c, h: face.h),
argbToOklch(out.equals.label),
policy: policy,
);
if (contrastRatio(pair.face, out.digit.face) >= paperStampRatio) {
fixed = out.equals.copyWith(face: pair.face, label: pair.label);
}
}
if (fixed == null) return null;
out = out.copyWith(equals: fixed);
}
final shade = spec.keyStyle.edgeShadePermille;
if (paperHatchContrast(out.operator, shade) < paperHatchRatio) {
final face = argbToOklch(out.operator.face);
final inkL = argbToOklch(ink).l;
var l = face.l;
KeyColors? fixed;
for (var i = 0; i < 4 && fixed == null; i++) {
l = clamp01(l + (inkL < face.l ? 0.02 : -0.02));
final k = repairKeyLabel(
out.operator.copyWith(face: oklchToArgb(l, face.c, face.h)),
policy,
bgs,
);
if (k != null && paperHatchContrast(k, shade) >= paperHatchRatio) {
fixed = k;
}
}
if (fixed == null) return null;
out = out.copyWith(operator: fixed);
}
final rimAlpha = (out.highlight >>> 24) & 0xFF;
return out.copyWith(
highlight: fitPaperWash(
out,
withAlpha(
ink,
rimAlpha < paperWashRimMaxAlpha ? rimAlpha : paperWashRimMaxAlpha,
),
lim,
),
);
}