mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-29 13:48:54 +08:00
Fix StyledParagraph wrapping issue when used inside table cell
This commit is contained in:
parent
9ffcdf7698
commit
3885bb9e20
@ -238,6 +238,19 @@ func (p *StyledParagraph) getTextWidth() float64 {
|
||||
return width
|
||||
}
|
||||
|
||||
// getTextHeight calculates the text height as if all in one line (not taking wrapping into account).
|
||||
func (p *StyledParagraph) getTextHeight() float64 {
|
||||
var height float64
|
||||
for _, chunk := range p.chunks {
|
||||
h := chunk.Style.FontSize * p.lineHeight
|
||||
if h > height {
|
||||
height = h
|
||||
}
|
||||
}
|
||||
|
||||
return height
|
||||
}
|
||||
|
||||
// wrapText splits text into lines. It uses a simple greedy algorithm to wrap
|
||||
// fill the lines.
|
||||
// XXX/TODO: Consider the Knuth/Plass algorithm or an alternative.
|
||||
|
@ -210,6 +210,19 @@ func (table *Table) GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext,
|
||||
// Add diff to last row.
|
||||
table.rowHeights[cell.row+cell.rowspan-2] += diffh
|
||||
}
|
||||
case *StyledParagraph:
|
||||
sp := t
|
||||
if sp.enableWrap {
|
||||
sp.SetWidth(w - cell.indent)
|
||||
}
|
||||
|
||||
newh := sp.Height() + sp.margins.bottom + sp.margins.bottom
|
||||
newh += 0.5 * sp.getTextHeight() // TODO: Make the top margin configurable?
|
||||
if newh > h {
|
||||
diffh := newh - h
|
||||
// Add diff to last row.
|
||||
table.rowHeights[cell.row+cell.rowspan-2] += diffh
|
||||
}
|
||||
case *Image:
|
||||
img := t
|
||||
newh := img.Height() + img.margins.top + img.margins.bottom
|
||||
|
Loading…
x
Reference in New Issue
Block a user