mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-28 23:28:16 +02:00
XFA - Convert some template properties into CSS ones (#13082)
- implement few positioning properties: position, width, height, anchor; - implement font element; - implement fill element (used by font) and its children (linear, radial, ...); - font property is inherited from ancestor container (see https://www.pdfa.org/wp-content/uploads/2020/07/XFA-3_3.pdf#page=43) so let CSS handles that stuff; - in order to reduce the number of properties to set, only set non default properties and put the default in CSS; - set a background to some containers to be able to see them (will be removed in a future commit).
This commit is contained in:
parent
9d0ce6e79f
commit
63471bcbbe
10 changed files with 549 additions and 93 deletions
|
@ -13,7 +13,13 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
const measurementPattern = /([+-]?)([0-9]+\.?[0-9]*)(.*)/;
|
||||
const dimConverters = {
|
||||
pt: x => x,
|
||||
cm: x => (x / 2.54) * 72,
|
||||
mm: x => (x / (10 * 2.54)) * 72,
|
||||
in: x => x * 72,
|
||||
};
|
||||
const measurementPattern = /([+-]?[0-9]+\.?[0-9]*)(.*)/;
|
||||
|
||||
function getInteger({ data, defaultValue, validate }) {
|
||||
if (!data) {
|
||||
|
@ -67,15 +73,22 @@ function getMeasurement(str, def = "0") {
|
|||
if (!match) {
|
||||
return getMeasurement(def);
|
||||
}
|
||||
const [, sign, valueStr, unit] = match;
|
||||
const [, valueStr, unit] = match;
|
||||
const value = parseFloat(valueStr);
|
||||
if (isNaN(value)) {
|
||||
return getMeasurement(def);
|
||||
}
|
||||
return {
|
||||
value: sign === "-" ? -value : value,
|
||||
unit: unit || "pt",
|
||||
};
|
||||
|
||||
if (value === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const conv = dimConverters[unit];
|
||||
if (conv) {
|
||||
return conv(value);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
function getRatio(data) {
|
||||
|
@ -134,7 +147,7 @@ function getColor(data, def = [0, 0, 0]) {
|
|||
}
|
||||
|
||||
function getBBox(data) {
|
||||
const def = getMeasurement("-1");
|
||||
const def = -1;
|
||||
if (!data) {
|
||||
return { x: def, y: def, width: def, height: def };
|
||||
}
|
||||
|
@ -142,7 +155,7 @@ function getBBox(data) {
|
|||
.trim()
|
||||
.split(/\s*,\s*/)
|
||||
.map(m => getMeasurement(m, "-1"));
|
||||
if (bbox.length < 4 || bbox[2].value < 0 || bbox[3].value < 0) {
|
||||
if (bbox.length < 4 || bbox[2] < 0 || bbox[3] < 0) {
|
||||
return { x: def, y: def, width: def, height: def };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue