Add default link style to paragraph

This commit is contained in:
Adrian-George Bostan 2018-11-30 18:45:48 +02:00
parent 9ac309464a
commit 4a6d5da26c
2 changed files with 27 additions and 15 deletions

View File

@ -26,6 +26,9 @@ type StyledParagraph struct {
// Style used for the paragraph for spacing and offsets.
defaultStyle TextStyle
// Style used for the paragraph link annotations.
defaultLinkStyle TextStyle
// Text alignment: Align left/right/center/justify.
alignment TextAlignment
@ -68,20 +71,19 @@ type StyledParagraph struct {
// newStyledParagraph creates a new styled paragraph.
func newStyledParagraph(style TextStyle) *StyledParagraph {
// TODO: Can we wrap intellectually, only if given width is known?
p := &StyledParagraph{
chunks: []*TextChunk{},
defaultStyle: style,
lineHeight: 1.0,
alignment: TextAlignmentLeft,
enableWrap: true,
defaultWrap: true,
angle: 0,
scaleX: 1,
scaleY: 1,
positioning: positionRelative,
return &StyledParagraph{
chunks: []*TextChunk{},
defaultStyle: style,
defaultLinkStyle: newLinkStyle(style.Font),
lineHeight: 1.0,
alignment: TextAlignmentLeft,
enableWrap: true,
defaultWrap: true,
angle: 0,
scaleX: 1,
scaleY: 1,
positioning: positionRelative,
}
return p
}
// Append adds a new text chunk to the paragraph.
@ -108,7 +110,7 @@ func (p *StyledParagraph) Insert(index uint, text string) *TextChunk {
// The text parameter represents the text that is displayed and the url
// parameter sets the destionation of the link.
func (p *StyledParagraph) AddExternalLink(text, url string) *TextChunk {
chunk := newTextChunk(text, p.defaultStyle)
chunk := newTextChunk(text, p.defaultLinkStyle)
chunk.annotation = newExternalLinkAnnotation(url)
return p.appendChunk(chunk)
}
@ -120,7 +122,7 @@ func (p *StyledParagraph) AddExternalLink(text, url string) *TextChunk {
// The zoom of the destination page is controlled with the zoom
// parameter. Pass in 0 to keep the current zoom value.
func (p *StyledParagraph) AddInternalLink(text string, page int64, x, y, zoom float64) *TextChunk {
chunk := newTextChunk(text, p.defaultStyle)
chunk := newTextChunk(text, p.defaultLinkStyle)
chunk.annotation = newInternalLinkAnnotation(page-1, x, y, zoom)
return p.appendChunk(chunk)
}

View File

@ -29,3 +29,13 @@ func newTextStyle(font *model.PdfFont) TextStyle {
FontSize: 10,
}
}
// newLinkStyle creates a new text style object which can be
// used for link annotations.
func newLinkStyle(font *model.PdfFont) TextStyle {
return TextStyle{
Color: ColorRGBFrom8bit(0, 0, 238),
Font: font,
FontSize: 10,
}
}