Skip to content

Commit

Permalink
Cover image size inside table (#2669)
Browse files Browse the repository at this point in the history
* Fixed cover image size in measureImageWithDimensions.

* Add table example with image cell.

* add fit images example on table
  • Loading branch information
isamu authored and liborm85 committed Dec 21, 2023
1 parent f5e9cdd commit ad62103
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 1 deletion.
70 changes: 69 additions & 1 deletion examples/tables.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ var docDefinition = {
['Sample value 1', 'Sample value 2', 'Sample value 3']
]
},
},
},
{ text: '... using a custom styler and overriding it in the second row', margin: [0, 20, 0, 8] },
{
style: 'tableOpacityExample',
Expand Down Expand Up @@ -685,6 +685,74 @@ var docDefinition = {
],
},
},
{ text: 'Image on table', pageBreak: 'before', style: 'subheader' },
{
style: 'tableExample',
color: '#444',
table: {
widths: [200, 'auto', 'auto'],
headerRows: 2,
// keepWithHeaderRows: 1,
body: [
[
{
text: 'Header with Colspan = 3',
style: 'tableHeader',
colSpan: 3,
borderColor: ['#ff00ff', '#00ffff', '#ff00ff', '#00ffff'],
alignment: 'center',
},
{},
{},
],
[
{
text: 'Header 1',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 2',
style: 'tableHeader',
alignment: 'center',
},
{
text: 'Header 3',
style: 'tableHeader',
alignment: 'center',
},
],
[
{
image: 'fonts/sampleImage.jpg',
cover: { width: 100, height: 100 },
},
{
image: 'fonts/sampleImage.jpg',
cover: { width: 100, height: 100 },
},
{
image: 'fonts/sampleImage.jpg',
cover: { width: 100, height: 100 },
},
],
[
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
{
image: 'fonts/sampleImage.jpg',
fit: [100, 100],
},
],
],
},
},
],
styles: {
header: {
Expand Down
3 changes: 3 additions & 0 deletions src/docMeasure.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ DocMeasure.prototype.measureImageWithDimensions = function (node, dimensions) {
var factor = (dimensions.width / dimensions.height > node.fit[0] / node.fit[1]) ? node.fit[0] / dimensions.width : node.fit[1] / dimensions.height;
node._width = node._minWidth = node._maxWidth = dimensions.width * factor;
node._height = dimensions.height * factor;
} else if (node.cover) {
node._width = node._minWidth = node._maxWidth = node.cover.width;
node._height = node._minHeight = node._maxHeight = node.cover.height;
} else {
node._width = node._minWidth = node._maxWidth = node.width || dimensions.width;
node._height = node.height || (dimensions.height * node._width / dimensions.width);
Expand Down

0 comments on commit ad62103

Please sign in to comment.