@dtducas/wh-forge-viewer 3.0.0-beta.7 → 3.0.0-beta.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -70921,8 +70921,9 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70921
70921
  var _element$textContent,
70922
70922
  _element$getAttribute,
70923
70923
  _element$getAttribute2,
70924
- _this = this;
70925
- var text, style, inlineStyles, x, y, fontSizeStr, fontSize, _this$transformPoint43, _this$transformPoint44, pdfX, pdfY, svgFontScale, fontScale, pdfFontSize, rawBoxH, pdfBoxH, maxPdfFs, textColor, opacity, mb, mapW, mapH, textAnchor, anchorOffsetX, drawLine, tspans, linesDrawn, lineYWorld, _iterator4, _step4, _tspan$textContent$tr, _tspan$textContent, tspan, lineText, tspanXAttr, lineXWorld, tspanYAttr, dyAttr, _this$transformPoint45, _this$transformPoint46, linePdfX, linePdfY, _element$getAttribute3, _t3;
70924
+ _this = this,
70925
+ _options$pageRotation3;
70926
+ var text, style, inlineStyles, x, y, fontSizeStr, fontSize, _this$transformPoint43, _this$transformPoint44, pdfX, pdfY, svgFontScale, fontScale, pdfFontSize, rawBoxH, pdfBoxH, maxPdfFs, textColor, opacity, mb, mapW, mapH, textAnchor, anchorOffsetX, pageRot, rotateOffset, drawLine, tspans, linesDrawn, lineYWorld, _iterator4, _step4, _tspan$textContent$tr, _tspan$textContent, tspan, lineText, tspanXAttr, lineXWorld, tspanYAttr, dyAttr, _this$transformPoint45, _this$transformPoint46, linePdfX, linePdfY, _element$getAttribute3, _t3;
70926
70927
  return _regenerator().w(function (_context3) {
70927
70928
  while (1) switch (_context3.p = _context3.n) {
70928
70929
  case 0:
@@ -70976,9 +70977,25 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70976
70977
  } catch (_unused) {
70977
70978
  return 0;
70978
70979
  }
70980
+ }; // Page /Rotate: glyphs must be rotated to read upright on the displayed page,
70981
+ // and the anchor (text-anchor X) + baseline (down) offsets — which are in the
70982
+ // displayed/text frame — must be rotated into the unrotated mediabox space.
70983
+ pageRot = (((_options$pageRotation3 = options.pageRotation) !== null && _options$pageRotation3 !== void 0 ? _options$pageRotation3 : 0) % 360 + 360) % 360; // Rotate a displayed-frame offset vector into mediabox space (same linear part
70984
+ // as the point mapping in transformPoint).
70985
+ rotateOffset = function rotateOffset(ox, oy) {
70986
+ switch (pageRot) {
70987
+ case 90:
70988
+ return [-oy, ox];
70989
+ case 180:
70990
+ return [-ox, -oy];
70991
+ case 270:
70992
+ return [oy, -ox];
70993
+ default:
70994
+ return [ox, oy];
70995
+ }
70979
70996
  }; // ── Helper: draw one text line with fallback ──────────────────────────────
70997
+ // drawX/drawY is the line anchor already mapped into mediabox space.
70980
70998
  drawLine = function drawLine(lineText, drawX, drawY) {
70981
- var baselinePdfY = drawY - pdfFontSize * 0.8;
70982
70999
  // Try primary font, then Helvetica per-line so export never stops.
70983
71000
  for (var _i3 = 0, _arr = [[_this.currentFont, false], [_this.helveticaFont, true]]; _i3 < _arr.length; _i3++) {
70984
71001
  var _arr$_i = _slicedToArray(_arr[_i3], 2),
@@ -70986,14 +71003,20 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
70986
71003
  isHelvetica = _arr$_i[1];
70987
71004
  var safe = isHelvetica ? _this.safeText(lineText).replace(/[^\x20-\x7E]/g, '?') : _this.safeText(lineText);
70988
71005
  var xOff = anchorOffsetX(safe, font);
71006
+ // Offset in the displayed/text frame: along text (xOff), baseline down (-0.8em).
71007
+ var _rotateOffset = rotateOffset(xOff, -pdfFontSize * 0.8),
71008
+ _rotateOffset2 = _slicedToArray(_rotateOffset, 2),
71009
+ offX = _rotateOffset2[0],
71010
+ offY = _rotateOffset2[1];
70989
71011
  try {
70990
71012
  pdfPage.drawText(safe, {
70991
- x: drawX + xOff,
70992
- y: baselinePdfY,
71013
+ x: drawX + offX,
71014
+ y: drawY + offY,
70993
71015
  size: pdfFontSize,
70994
71016
  font: font,
70995
71017
  color: rgb(textColor.r, textColor.g, textColor.b),
70996
- opacity: opacity
71018
+ opacity: opacity,
71019
+ rotate: degrees(pageRot)
70997
71020
  });
70998
71021
  if (isHelvetica) console.warn('[SvgToPdfConverter] drawText: used Helvetica fallback for line:', lineText);
70999
71022
  return true;
@@ -71560,7 +71583,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
71560
71583
  }, {
71561
71584
  key: "transformPoint",
71562
71585
  value: function transformPoint(x, y, options, svgTransform) {
71563
- var _options$pageRotation3;
71586
+ var _options$pageRotation4;
71564
71587
  // Apply SVG transform (translate, rotate, scale) first
71565
71588
  var svgX = x;
71566
71589
  var svgY = y;
@@ -71593,7 +71616,7 @@ var SvgToPdfConverter = /*#__PURE__*/function () {
71593
71616
  // Raw (unrotated) mediabox dims — pdf-lib draws into this space.
71594
71617
  var rawW = options.pageWidth;
71595
71618
  var rawH = options.pageHeight;
71596
- var rot = (((_options$pageRotation3 = options.pageRotation) !== null && _options$pageRotation3 !== void 0 ? _options$pageRotation3 : 0) % 360 + 360) % 360;
71619
+ var rot = (((_options$pageRotation4 = options.pageRotation) !== null && _options$pageRotation4 !== void 0 ? _options$pageRotation4 : 0) % 360 + 360) % 360;
71597
71620
  var quarter = rot === 90 || rot === 270;
71598
71621
  // Displayed page dims = the orientation the markup was authored in. For a
71599
71622
  // 90/270 rotation the visible page is the mediabox with width/height swapped,