Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Work for #271: use shadow dom for rendering html as image #272

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/helper_survey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,12 @@ export class SurveyHelper {
return (new XMLSerializer()).serializeToString(htmlDoc.body).replace(/%23/g, '#');
}
public static createSvgContent(html: string, width: number, controller: DocController) {
const container = document.createElement('div');
document.body.appendChild(container);
const shadow = container.attachShadow ? container.attachShadow({ mode: 'closed' }) : container;
const style: HTMLStyleElement = document.createElement('style');
style.innerHTML = '.__surveypdf_html p { margin: unset; line-height: 22px; } body { margin: unset; }';
document.body.appendChild(style);
shadow.appendChild(style);
const div: HTMLDivElement = document.createElement('div');
div.className = '__surveypdf_html';
div.style.display = 'block';
Expand All @@ -276,11 +279,10 @@ export class SurveyHelper {
div.style.font = 'initial';
div.style.lineHeight = 'initial';
div.insertAdjacentHTML('beforeend', html);
document.body.appendChild(div);
shadow.appendChild(div);
const divWidth: number = div.offsetWidth;
const divHeight: number = div.offsetHeight;
div.remove();
style.remove();
container.remove();
let defs: string = '';
if (controller.useCustomFontInHtml) {
defs = `<defs><style>${this.generateFontFace(controller.fontName, controller.base64Normal, 'normal')}` +
Expand Down