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

bug fix: solve the problem of incomplete svg rendering content #3048

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 19 additions & 9 deletions src/dom/replaced-elements/svg-element-container.ts
Expand Up @@ -8,16 +8,26 @@ export class SVGElementContainer extends ElementContainer {
intrinsicHeight: number;

constructor(context: Context, img: SVGSVGElement) {
super(context, img);
const s = new XMLSerializer();
const bounds = parseBounds(context, img);
img.setAttribute('width', `${bounds.width}px`);
img.setAttribute('height', `${bounds.height}px`);
super(context, img)
const s = new XMLSerializer()
const bounds = parseBounds(context, img)
let originPosition: string = img.style.position
img.setAttribute('width', `${bounds.width}px`)
img.setAttribute('height', `${bounds.height}px`)

// fix: resolve missing svg serialized content
// if svg's tag has absolute position, when converting through serializeToString, it will result in missing SVG content.
// so, it is necessary to eliminate positioning before serialization.
img.style.position = 'initial'

this.svg = `data:image/svg+xml,${encodeURIComponent(s.serializeToString(img))}`;
this.intrinsicWidth = img.width.baseVal.value;
this.intrinsicHeight = img.height.baseVal.value;
this.svg = `data:image/svg+xml,${encodeURIComponent(s.serializeToString(img))}`

// reset position
img.style.position = originPosition

this.intrinsicWidth = img.width.baseVal.value
this.intrinsicHeight = img.height.baseVal.value

this.context.cache.addImage(this.svg);
this.context.cache.addImage(this.svg)
}
}