mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
Add getMaxLineWidth method on StyledParagraph
This commit is contained in:
parent
fb41824815
commit
db93b6e873
@ -264,10 +264,10 @@ func (p *StyledParagraph) getTextLineWidth(line []TextChunk) float64 {
|
||||
for _, chunk := range line {
|
||||
style := &chunk.Style
|
||||
|
||||
for _, rune := range chunk.Text {
|
||||
glyph, found := p.encoder.RuneToGlyph(rune)
|
||||
for _, r := range chunk.Text {
|
||||
glyph, found := p.encoder.RuneToGlyph(r)
|
||||
if !found {
|
||||
common.Log.Debug("Error! Glyph not found for rune: %s\n", rune)
|
||||
common.Log.Debug("Error! Glyph not found for rune: %s\n", r)
|
||||
|
||||
// XXX/FIXME: return error.
|
||||
return -1
|
||||
@ -293,6 +293,23 @@ func (p *StyledParagraph) getTextLineWidth(line []TextChunk) float64 {
|
||||
return width
|
||||
}
|
||||
|
||||
// getMaxLineWidth returns the width of the longest line of text in the paragraph.
|
||||
func (p *StyledParagraph) getMaxLineWidth() float64 {
|
||||
if p.lines == nil || len(p.lines) == 0 {
|
||||
p.wrapText()
|
||||
}
|
||||
|
||||
var width float64
|
||||
for _, line := range p.lines {
|
||||
w := p.getTextLineWidth(line)
|
||||
if w > width {
|
||||
width = w
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user