| | @@ -305,13 +305,13 @@ |
| 305 | 305 | |
| 306 | 306 | /** |
| 307 | 307 | Event handler for 'pikchr' messages from the Worker thread. |
| 308 | 308 | */ |
| 309 | 309 | PS.addMsgHandler('pikchr', function(ev){ |
| 310 | | - const m = ev.data; |
| 311 | | - this.e.pikOut.classList[m.isError ? 'add' : 'remove']('error'); |
| 312 | | - this.e.pikOut.dataset.pikchr = m.pikchr; |
| 310 | + const m = ev.data, pikOut = this.e.pikOut; |
| 311 | + pikOut.classList[m.isError ? 'add' : 'remove']('error'); |
| 312 | + pikOut.dataset.pikchr = m.pikchr; |
| 313 | 313 | const mode = this.renderModes[this.renderModes.selectedIndex]; |
| 314 | 314 | switch(mode){ |
| 315 | 315 | case 'text': case 'markdown': case 'wiki': { |
| 316 | 316 | let body; |
| 317 | 317 | switch(mode){ |
| | @@ -324,31 +324,39 @@ |
| 324 | 324 | default: |
| 325 | 325 | body = m.result; |
| 326 | 326 | } |
| 327 | 327 | this.e.outText.value = body; |
| 328 | 328 | this.e.outText.classList.remove('hidden'); |
| 329 | | - this.e.pikOut.classList.add('hidden'); |
| 329 | + pikOut.classList.add('hidden'); |
| 330 | 330 | this.e.pikOutWrapper.classList.add('text'); |
| 331 | 331 | break; |
| 332 | 332 | } |
| 333 | 333 | case 'svg': |
| 334 | 334 | this.e.outText.classList.add('hidden'); |
| 335 | | - this.e.pikOut.classList.remove('hidden'); |
| 335 | + pikOut.classList.remove('hidden'); |
| 336 | 336 | this.e.pikOutWrapper.classList.remove('text'); |
| 337 | | - this.e.pikOut.innerHTML = m.result; |
| 337 | + pikOut.innerHTML = m.result; |
| 338 | 338 | this.e.outText.value = m.result/*for clipboard copy*/; |
| 339 | 339 | break; |
| 340 | 340 | default: throw new Error("Unhandled render mode: "+mode); |
| 341 | 341 | } |
| 342 | 342 | let vw = null, vh = null; |
| 343 | | - if('svg'===mode && !this.config.renderAutofit && !m.isError){ |
| 344 | | - vw = m.width+1; vh = m.height+1; |
| 345 | | - /* +1 is b/c the SVG uses floating point sizes but pikchr() returns |
| 346 | | - truncated integers. */ |
| 343 | + if('svg'===mode){ |
| 344 | + if(m.isError){ |
| 345 | + vw = vh = '100%'; |
| 346 | + }else if(this.config.renderAutofit){ |
| 347 | + /* FIXME: current behavior doesn't work as desired when width>height |
| 348 | + (e.g. non-side-by-side mode).*/ |
| 349 | + vw = vh = '98%'; |
| 350 | + }else{ |
| 351 | + vw = m.width+1+'px'; vh = m.height+1+'px'; |
| 352 | + /* +1 is b/c the SVG uses floating point sizes but pikchr() |
| 353 | + returns truncated integers. */ |
| 354 | + } |
| 355 | + pikOut.style.width = vw; |
| 356 | + pikOut.style.height = vh; |
| 347 | 357 | } |
| 348 | | - this.e.pikOut.style.width = vw && vw+'px'; |
| 349 | | - this.e.pikOut.style.height = vh && vh+'px'; |
| 350 | 358 | }.bind(PS))/*'pikchr' msg handler*/; |
| 351 | 359 | |
| 352 | 360 | E('#btn-render-mode').addEventListener('click',function(){ |
| 353 | 361 | const modes = this.renderModes; |
| 354 | 362 | modes.selectedIndex = (modes.selectedIndex + 1) % modes.length; |
| 355 | 363 | |