mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
Fix mermaid display problem in the editing state. (#2334)
This commit is contained in:
parent
d664c5a1c6
commit
9353c9ef40
@ -188,7 +188,7 @@ class GraphPreviewer {
|
||||
|
||||
if (p_svgNode.getAttribute('width').indexOf('%') != -1) {
|
||||
// Try maxWidth.
|
||||
if (p_svgNode.style.maxWidth && p_svgNode.style.maxWidth.endsWith('px')) {
|
||||
if (p_svgNode.style.maxWidth && p_svgNode.style.maxWidth.endsWith('px') && p_svgNode.style.maxWidth != "0px") {
|
||||
p_svgNode.setAttribute('width', p_svgNode.style.maxWidth);
|
||||
} else {
|
||||
// Set as window width.
|
||||
@ -220,10 +220,12 @@ class GraphPreviewer {
|
||||
return;
|
||||
}
|
||||
|
||||
if (p_svgNode.getAttribute('width').indexOf('%') == -1) {
|
||||
let width = p_svgNode.getAttribute('width')
|
||||
if (width && width.indexOf('%') == -1) {
|
||||
p_svgNode.width.baseVal.valueInSpecifiedUnits *= scaleFactor;
|
||||
}
|
||||
if (p_svgNode.getAttribute('height').indexOf('%') == -1) {
|
||||
let height = p_svgNode.getAttribute('height')
|
||||
if (height && height.indexOf('%') == -1) {
|
||||
p_svgNode.height.baseVal.valueInSpecifiedUnits *= scaleFactor;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ class SvgToImage {
|
||||
let url = domUrl.createObjectURL(blob);
|
||||
this.loadImage(url, p_opt, function(err, img) {
|
||||
domUrl.revokeObjectURL(url);
|
||||
if (err) {
|
||||
if (err || SvgToImage.checkCanvasToDataURL(img) === null) {
|
||||
// try again for Safari 8.0, using simple encodeURIComponent
|
||||
// this will fail with DOM content but at least it works with SVG.
|
||||
let url2 = 'data:image/svg+xml,' + encodeURIComponent(p_svg.join(''));
|
||||
@ -74,4 +74,19 @@ class SvgToImage {
|
||||
static getUrl() {
|
||||
return window.URL || window.webkitURL || window.mozURL || window.msURL;
|
||||
}
|
||||
|
||||
static checkCanvasToDataURL(p_image) {
|
||||
let canvas = document.createElement('canvas');
|
||||
let ctx = canvas.getContext('2d');
|
||||
canvas.height = p_image.height;
|
||||
canvas.width = p_image.width;
|
||||
ctx.drawImage(p_image, 0, 0);
|
||||
let dataUrl = null;
|
||||
try {
|
||||
dataUrl = canvas.toDataURL();
|
||||
} catch (err) {
|
||||
|
||||
}
|
||||
return dataUrl
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user