1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-19 14:48:08 +02:00

Merge pull request #19628 from Snuffleupagus/MathClamp-2

Use the `MathClamp` helper function more (PR 19617 follow-up)
This commit is contained in:
Tim van der Meij 2025-03-09 12:49:53 +01:00 committed by GitHub
commit 66af403f10
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 10 deletions

View file

@ -18,6 +18,7 @@ import {
FormatError,
IDENTITY_MATRIX,
info,
MathClamp,
unreachable,
Util,
warn,
@ -843,17 +844,19 @@ class MeshShading extends BaseShading {
((figureMaxX - figureMinX) * MeshShading.TRIANGLE_DENSITY) /
(this.bounds[2] - this.bounds[0])
);
splitXBy = Math.max(
splitXBy = MathClamp(
splitXBy,
MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitXBy)
MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
);
let splitYBy = Math.ceil(
((figureMaxY - figureMinY) * MeshShading.TRIANGLE_DENSITY) /
(this.bounds[3] - this.bounds[1])
);
splitYBy = Math.max(
splitYBy = MathClamp(
splitYBy,
MeshShading.MIN_SPLIT_PATCH_CHUNKS_AMOUNT,
Math.min(MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT, splitYBy)
MeshShading.MAX_SPLIT_PATCH_CHUNKS_AMOUNT
);
const verticesPerRow = splitXBy + 1;

View file

@ -21,6 +21,7 @@ import {
$isSplittable,
$isThereMoreWidth,
} from "./symbol_utils.js";
import { MathClamp } from "../../shared/util.js";
import { measureToString } from "./html_utils.js";
// Subform and ExclGroup have a layout so they share these functions.
@ -141,7 +142,7 @@ function addHTML(node, html, bbox) {
break;
}
case "table": {
extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
extra.width = MathClamp(w, extra.width, availableSpace.width);
extra.height += h;
extra.children.push(html);
break;
@ -150,7 +151,7 @@ function addHTML(node, html, bbox) {
// Even if the subform can possibly take all the available width,
// we must compute the final width as it is in order to be able
// for example to center the subform within its parent.
extra.width = Math.min(availableSpace.width, Math.max(extra.width, w));
extra.width = MathClamp(w, extra.width, availableSpace.width);
extra.height += h;
extra.children.push(html);
break;

View file

@ -81,13 +81,11 @@ const StyleMapping = new Map([
["kerning-mode", value => (value === "none" ? "none" : "normal")],
[
"xfa-font-horizontal-scale",
value =>
`scaleX(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`,
value => `scaleX(${Math.max(0, parseInt(value) / 100).toFixed(2)})`,
],
[
"xfa-font-vertical-scale",
value =>
`scaleY(${Math.max(0, Math.min(parseInt(value) / 100)).toFixed(2)})`,
value => `scaleY(${Math.max(0, parseInt(value) / 100).toFixed(2)})`,
],
["xfa-spacerun", ""],
["xfa-tab-stops", ""],