pdf.js.mirror/src/shared/obj_bin_transform_utils.js
Calixte Denizet 3727b7095a Add support for function-based shadings (bug 1254066)
It fixes #5046.
We just generate a mesh for the pattern rectangle where the color of each vertex is computed from the function.
Since the mesh is generated in the worker we don't really take into account the current transform when it's drawn.
That being said, there are maybe some possible improvements in using directly the gpu for the shading creation
which could then take into account the current transform, but it could only work with ps function we can convert
ino wgsl language and simple enough color spaces (gray and rgb).
2026-03-31 20:46:01 +02:00

72 lines
2.0 KiB
JavaScript

/* Copyright 2025 Mozilla Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
class CSS_FONT_INFO {
static strings = ["fontFamily", "fontWeight", "italicAngle"];
}
class SYSTEM_FONT_INFO {
static strings = ["css", "loadedName", "baseFontName", "src"];
}
class FONT_INFO {
static bools = [
"black",
"bold",
"disableFontFace",
"fontExtraProperties",
"isInvalidPDFjsFont",
"isType3Font",
"italic",
"missingFile",
"remeasure",
"vertical",
];
static numbers = ["ascent", "defaultWidth", "descent"];
static strings = ["fallbackName", "loadedName", "mimetype", "name"];
static OFFSET_NUMBERS = Math.ceil((this.bools.length * 2) / 8);
static OFFSET_BBOX = this.OFFSET_NUMBERS + this.numbers.length * 8;
static OFFSET_FONT_MATRIX = this.OFFSET_BBOX + 1 + 2 * 4;
static OFFSET_DEFAULT_VMETRICS = this.OFFSET_FONT_MATRIX + 1 + 8 * 6;
static OFFSET_STRINGS = this.OFFSET_DEFAULT_VMETRICS + 1 + 2 * 3;
}
class PATTERN_INFO {
static KIND = 0; // 1=axial, 2=radial, 3=mesh
static HAS_BBOX = 1; // 0/1
static HAS_BACKGROUND = 2; // 0/1 (background for mesh patterns)
static SHADING_TYPE = 3; // shadingType (only for mesh patterns)
static N_COORD = 4; // number of coordinate pairs
static N_COLOR = 8; // number of RGBA-stride color entries
static N_STOP = 12; // number of gradient stops
static N_FIGURES = 16; // number of figures
}
export { CSS_FONT_INFO, FONT_INFO, PATTERN_INFO, SYSTEM_FONT_INFO };