Skip to content

svg 存在 transform="scale(0.18)" 时矩阵运算不符合预期 #789

Answered by YGaurora
0x1306a94 asked this question in General
Discussion options

You must be logged in to vote
auto domSize = svgDom->getContainerSize();

这里不应该直接用getContainerSize作为最终在Canvas上的渲染区域的大小,因为这个接口只是返回出来SVG根节点的width、height或者是viewBox。也就是case中的width="5888" height="5904"
因为根节点的变换矩阵可能存在旋转和平移,渲染区域会是一个矩形区域,而不是只要有Size宽高就行了。接口最初的设计就是返回根节点的属性并不是实际渲染区域。

auto domSize = SVGDom->getContainerSize();
auto rootMatrix = SVGDom->getRoot()->getTransform();
auto renderRect = Rect::MakeSize(domSize);
renderRect = rootMatrix.mapRect(renderRect);
应该用这样计算出来的矩形再根据它计算渲染的矩阵

Replies: 44 comments 12 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
11 replies
@0x1306a94
Comment options

@domchen
Comment options

@0x1306a94
Comment options

@domchen
Comment options

@domchen
Comment options

Answer selected by YGaurora
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants