|
370 | 370 |
|
371 | 371 | var imagesCSS = GetCSS(cn); |
372 | 372 | var imageX = renderer.x; |
| 373 | + var fontToUnitRatio = 12 / renderer.pdf.internal.scaleFactor; |
| 374 | + |
| 375 | + //define additional paddings, margins which have to be taken into account for margin calculations |
| 376 | + var additionalSpaceLeft = (imagesCSS["margin-left"] + imagesCSS["padding-left"])*fontToUnitRatio; |
| 377 | + var additionalSpaceRight = (imagesCSS["margin-right"] + imagesCSS["padding-right"])*fontToUnitRatio; |
| 378 | + var additionalSpaceTop = (imagesCSS["margin-top"] + imagesCSS["padding-top"])*fontToUnitRatio; |
| 379 | + var additionalSpaceBottom = (imagesCSS["margin-bottom"] + imagesCSS["padding-bottom"])*fontToUnitRatio; |
| 380 | + |
373 | 381 | //if float is set to right, move the image to the right border |
| 382 | + //add space if margin is set |
374 | 383 | if (imagesCSS['float'] !== undefined && imagesCSS['float'] === 'right') { |
375 | | - imageX += renderer.settings.width-cn.width; |
| 384 | + imageX += renderer.settings.width - cn.width - additionalSpaceRight; |
| 385 | + } else { |
| 386 | + imageX += additionalSpaceLeft; |
376 | 387 | } |
377 | 388 |
|
378 | | - renderer.pdf.addImage(images[cn.getAttribute("src")], imageX, renderer.y, cn.width, cn.height); |
| 389 | + renderer.pdf.addImage(images[cn.getAttribute("src")], imageX, renderer.y + additionalSpaceTop, cn.width, cn.height); |
379 | 390 | //if the float prop is specified we have to float the text around the image |
380 | 391 | if (imagesCSS['float'] !== undefined) { |
381 | 392 | if (imagesCSS['float'] === 'right' || imagesCSS['float'] === 'left') { |
|
395 | 406 | } else { |
396 | 407 | return false; |
397 | 408 | } |
398 | | - }).bind(this, (imagesCSS['float'] === 'left') ? -cn.width : 0, renderer.y+cn.height, cn.width)); |
| 409 | + }).bind(this, (imagesCSS['float'] === 'left') ? -cn.width-additionalSpaceLeft-additionalSpaceRight : 0, renderer.y+cn.height+additionalSpaceTop+additionalSpaceBottom, cn.width)); |
399 | 410 |
|
400 | 411 | //reset floating by clear:both divs |
401 | 412 | //just set cursorY after the floating element |
|
413 | 424 | }).bind(this, renderer.y+cn.height, renderer.pdf.internal.getNumberOfPages())); |
414 | 425 |
|
415 | 426 | //if floating is set we decrease the available width by the image width |
416 | | - renderer.settings.width -= cn.width; |
| 427 | + renderer.settings.width -= cn.width+additionalSpaceLeft+additionalSpaceRight; |
417 | 428 | //if left just add the image width to the X coordinate |
418 | 429 | if (imagesCSS['float'] === 'left') { |
419 | | - renderer.x += cn.width; |
| 430 | + renderer.x += cn.width+additionalSpaceLeft+additionalSpaceRight; |
420 | 431 | } |
421 | 432 | } |
422 | 433 | //if no floating is set, move the rendering cursor after the image height |
423 | 434 | } else { |
424 | | - renderer.y += cn.height; |
| 435 | + renderer.y += cn.height + additionalSpaceBottom; |
425 | 436 | } |
426 | 437 |
|
427 | 438 | /*** TABLE RENDERING ***/ |
|
0 commit comments