Skip to content

Commit

Permalink
Merge pull request #1736 from xeokit/XEOK-151-fix-labels-text-offset-…
Browse files Browse the repository at this point in the history
…when-html2canvas

XEOK-151 Fix label's text offset in an html2canvas capture
  • Loading branch information
xeolabs authored Nov 14, 2024
2 parents 463e378 + 4ce55ad commit 0c7fcc8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/viewer/Viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ class Viewer {
}
}

// Added to fix label's text offset in an html2canvas capture (See XEOK-151)
// based on https://github.com/niklasvh/html2canvas/issues/2775#issuecomment-1316356991
const style = document.createElement('style');
document.head.appendChild(style);
style.sheet?.insertRule('body > div:last-child img { display: inline-block; }');

for (let i = 0, len = pluginContainerElements.length; i < len; i++) {
const containerElement = pluginContainerElements[i];
await html2canvas(containerElement, {
Expand All @@ -503,6 +509,9 @@ class Viewer {
// (implemented to compensate XCD-153 issue)
snapshotCanvas.getContext("2d").resetTransform();
}

style.remove();

if (!params.includeGizmos) {
this.sendToPlugins("snapshotFinished");
}
Expand Down

0 comments on commit 0c7fcc8

Please sign in to comment.