Skip to content

Commit b53e5d1

Browse files
committed
Fix svg2pdf - better bounding box for anchor
1 parent 8af9393 commit b53e5d1

File tree

1 file changed

+81
-81
lines changed

1 file changed

+81
-81
lines changed

modules/base/svg2pdf.mjs

Lines changed: 81 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -26,84 +26,84 @@
2626

2727
import { jsPDF, GState, ShadingPattern, TilingPattern } from './jspdf.mjs';
2828

29-
/******************************************************************************
30-
Copyright (c) Microsoft Corporation.
31-
32-
Permission to use, copy, modify, and/or distribute this software for any
33-
purpose with or without fee is hereby granted.
34-
35-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
36-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
38-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
40-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41-
PERFORMANCE OF THIS SOFTWARE.
42-
***************************************************************************** */
43-
/* global Reflect, Promise */
44-
45-
var extendStatics = function(d, b) {
46-
extendStatics = Object.setPrototypeOf ||
47-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
48-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
49-
return extendStatics(d, b);
50-
};
51-
52-
function __extends(d, b) {
53-
if (typeof b !== "function" && b !== null)
54-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
55-
extendStatics(d, b);
56-
function __() { this.constructor = d; }
57-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
58-
}
59-
60-
var __assign = function() {
61-
__assign = Object.assign || function __assign(t) {
62-
for (var s, i = 1, n = arguments.length; i < n; i++) {
63-
s = arguments[i];
64-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
65-
}
66-
return t;
67-
};
68-
return __assign.apply(this, arguments);
69-
};
70-
71-
function __awaiter(thisArg, _arguments, P, generator) {
72-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
73-
return new (P || (P = Promise))(function (resolve, reject) {
74-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
75-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
76-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
77-
step((generator = generator.apply(thisArg, _arguments || [])).next());
78-
});
79-
}
80-
81-
function __generator(thisArg, body) {
82-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
83-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
84-
function verb(n) { return function (v) { return step([n, v]); }; }
85-
function step(op) {
86-
if (f) throw new TypeError("Generator is already executing.");
87-
while (_) try {
88-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
89-
if (y = 0, t) op = [op[0] & 2, t.value];
90-
switch (op[0]) {
91-
case 0: case 1: t = op; break;
92-
case 4: _.label++; return { value: op[1], done: false };
93-
case 5: _.label++; y = op[1]; op = [0]; continue;
94-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
95-
default:
96-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
97-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
98-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
99-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
100-
if (t[2]) _.ops.pop();
101-
_.trys.pop(); continue;
102-
}
103-
op = body.call(thisArg, _);
104-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
105-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
106-
}
29+
/******************************************************************************
30+
Copyright (c) Microsoft Corporation.
31+
32+
Permission to use, copy, modify, and/or distribute this software for any
33+
purpose with or without fee is hereby granted.
34+
35+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
36+
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37+
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
38+
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
39+
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
40+
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
41+
PERFORMANCE OF THIS SOFTWARE.
42+
***************************************************************************** */
43+
/* global Reflect, Promise */
44+
45+
var extendStatics = function(d, b) {
46+
extendStatics = Object.setPrototypeOf ||
47+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
48+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
49+
return extendStatics(d, b);
50+
};
51+
52+
function __extends(d, b) {
53+
if (typeof b !== "function" && b !== null)
54+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
55+
extendStatics(d, b);
56+
function __() { this.constructor = d; }
57+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
58+
}
59+
60+
var __assign = function() {
61+
__assign = Object.assign || function __assign(t) {
62+
for (var s, i = 1, n = arguments.length; i < n; i++) {
63+
s = arguments[i];
64+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
65+
}
66+
return t;
67+
};
68+
return __assign.apply(this, arguments);
69+
};
70+
71+
function __awaiter(thisArg, _arguments, P, generator) {
72+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
73+
return new (P || (P = Promise))(function (resolve, reject) {
74+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
75+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
76+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
77+
step((generator = generator.apply(thisArg, _arguments || [])).next());
78+
});
79+
}
80+
81+
function __generator(thisArg, body) {
82+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
83+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
84+
function verb(n) { return function (v) { return step([n, v]); }; }
85+
function step(op) {
86+
if (f) throw new TypeError("Generator is already executing.");
87+
while (_) try {
88+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
89+
if (y = 0, t) op = [op[0] & 2, t.value];
90+
switch (op[0]) {
91+
case 0: case 1: t = op; break;
92+
case 4: _.label++; return { value: op[1], done: false };
93+
case 5: _.label++; y = op[1]; op = [0]; continue;
94+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
95+
default:
96+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
97+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
98+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
99+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
100+
if (t[2]) _.ops.pop();
101+
_.trys.pop(); continue;
102+
}
103+
op = body.call(thisArg, _);
104+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
105+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
106+
}
107107
}
108108

109109
/* eslint-disable @typescript-eslint/no-explicit-any,@typescript-eslint/explicit-module-boundary-types */
@@ -2415,7 +2415,7 @@ var GeometryNode = /** @class */ (function (_super) {
24152415
if (prev instanceof MoveTo || prev instanceof LineTo || prev instanceof CurveTo) {
24162416
if (curr instanceof CurveTo) {
24172417
hasStartMarker &&
2418-
markers.addMarker(new Marker(markerStart, [prev.x, prev.y],
2418+
markers.addMarker(new Marker(markerStart, [prev.x, prev.y],
24192419
// @ts-ignore
24202420
getAngle(last_1 ? [last_1.x, last_1.y] : [prev.x, prev.y], [curr.x1, curr.y1]), true));
24212421
hasEndMarker &&
@@ -3133,7 +3133,7 @@ var TextNode = /** @class */ (function (_super) {
31333133
textChunks = [];
31343134
currentTextSegment = new TextChunk(this, context.attributeState.textAnchor, textX + dx, textY + dy);
31353135
textChunks.push({ type: '', chunk: currentTextSegment });
3136-
initialSpace = this.processTSpans(this, this.element, context, textChunks, currentTextSegment,
3136+
initialSpace = this.processTSpans(this, this.element, context, textChunks, currentTextSegment,
31373137
// Set prevText to ' ' so any spaces on left of <text> are trimmed
31383138
{ prevText: ' ', prevContext: context });
31393139
lengthAdjustment = initialSpace ? 0 : 1;
@@ -5415,7 +5415,7 @@ var Anchor = /** @class */ (function (_super) {
54155415
box = this.getBoundingBox(context);
54165416
scale = context.pdf.internal.scaleFactor;
54175417
ph = context.pdf.internal.pageSize.getHeight();
5418-
context.pdf.link(scale * (box[0] * context.transform.sx + context.transform.tx), ph - scale * (box[1] * context.transform.sy + context.transform.ty), scale * box[2], scale * box[3], { url: href });
5418+
context.pdf.link(scale * (box[0] * context.transform.sx + context.transform.tx), scale * (ph - box[1] * context.transform.sy - context.transform.ty), scale * context.transform.sx * box[2], scale * context.transform.sy * box[3], { url: href });
54195419
}
54205420
return [2 /*return*/];
54215421
}

0 commit comments

Comments
 (0)