File tree Expand file tree Collapse file tree 1 file changed +17
-4
lines changed
Expand file tree Collapse file tree 1 file changed +17
-4
lines changed Original file line number Diff line number Diff line change @@ -237,13 +237,26 @@ export class SvgDrawController implements DrawController {
237237 ctx . drawImage ( imageElement , 0 , 0 ) ;
238238 const dataUri = canvas . toDataURL ( ) ; // Convert the image to Base64
239239
240- const transform = angle
241- ? `transform="rotate(${ angle } , ${ xMin + width / 2 } , ${ yMin + height / 2 } )"`
242- : '' ;
240+ const svgWidth = width * this . getScreenScale ( ) ;
241+ const svgHeight = height * this . getScreenScale ( ) ;
242+
243+ const worldCenterX = xMin + width / 2 ;
244+ const worldCenterY = yMin + height / 2 ;
245+
246+ const targetCenter = this . worldToTarget ( new Point ( worldCenterX , worldCenterY ) ) ;
247+
248+ const svgX = targetCenter . x - svgWidth / 2 ;
249+ const svgY = targetCenter . y - svgHeight / 2 ;
250+
251+ let transformAttribute = '' ;
252+ if ( angle !== 0 ) {
253+ const svgAngleDegrees = angle * ( 180 / Math . PI ) ;
254+ transformAttribute = `transform="rotate(${ svgAngleDegrees } , ${ targetCenter . x } , ${ targetCenter . y } )"` ;
255+ }
243256
244257 // noinspection HtmlUnknownAttribute
245258 this . svgStrings . push (
246- `<image href="${ dataUri } " x="${ xMin } " y="${ yMin } " width="${ width } " height="${ height } " ${ transform } />`
259+ `<image href="${ dataUri } " x="${ svgX } " y="${ svgY } " width="${ svgWidth } " height="${ svgHeight } " ${ transformAttribute } />`
247260 ) ;
248261 }
249262
You can’t perform that action at this time.
0 commit comments