2018-09-27 20:55:58 +03:00
|
|
|
/*
|
|
|
|
* This file is subject to the terms and conditions defined in
|
|
|
|
* file 'LICENSE.md', which is part of this source code package.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package creator
|
|
|
|
|
2018-11-28 21:28:27 +02:00
|
|
|
import (
|
2019-05-16 23:44:51 +03:00
|
|
|
"github.com/unidoc/unipdf/v3/core"
|
|
|
|
"github.com/unidoc/unipdf/v3/model"
|
2018-11-28 21:28:27 +02:00
|
|
|
)
|
|
|
|
|
2018-09-27 20:55:58 +03:00
|
|
|
// TextChunk represents a chunk of text along with a particular style.
|
|
|
|
type TextChunk struct {
|
|
|
|
// The text that is being rendered in the PDF.
|
|
|
|
Text string
|
|
|
|
|
|
|
|
// The style of the text being rendered.
|
|
|
|
Style TextStyle
|
2018-11-28 21:28:27 +02:00
|
|
|
|
2018-11-30 18:09:05 +02:00
|
|
|
// Text chunk annotation.
|
2018-11-28 21:28:27 +02:00
|
|
|
annotation *model.PdfAnnotation
|
2018-11-30 18:09:05 +02:00
|
|
|
|
|
|
|
// Internally used in order to skip processing the annotation
|
|
|
|
// if it has already been processed by the parent component.
|
|
|
|
annotationProcessed bool
|
2018-11-28 21:28:27 +02:00
|
|
|
}
|
|
|
|
|
2018-11-30 18:09:05 +02:00
|
|
|
// newTextChunk returns a new text chunk instance.
|
2018-11-28 21:28:27 +02:00
|
|
|
func newTextChunk(text string, style TextStyle) *TextChunk {
|
|
|
|
return &TextChunk{
|
|
|
|
Text: text,
|
|
|
|
Style: style,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-30 18:09:05 +02:00
|
|
|
// newExternalLinkAnnotation returns a new external link annotation.
|
|
|
|
func newExternalLinkAnnotation(url string) *model.PdfAnnotation {
|
2018-11-28 21:28:27 +02:00
|
|
|
annotation := model.NewPdfAnnotationLink()
|
|
|
|
|
|
|
|
// Set border style.
|
|
|
|
bs := model.NewBorderStyle()
|
|
|
|
bs.SetBorderWidth(0)
|
|
|
|
annotation.BS = bs.ToPdfObject()
|
|
|
|
|
|
|
|
// Set link destination.
|
2019-08-30 08:50:30 +00:00
|
|
|
action := model.NewPdfActionURI()
|
|
|
|
action.URI = core.MakeString(url)
|
|
|
|
annotation.SetAction(action.PdfAction)
|
2018-11-28 21:28:27 +02:00
|
|
|
|
|
|
|
return annotation.PdfAnnotation
|
2018-09-27 20:55:58 +03:00
|
|
|
}
|
2018-11-28 22:19:30 +02:00
|
|
|
|
2018-11-30 18:09:05 +02:00
|
|
|
// newExternalLinkAnnotation returns a new internal link annotation.
|
2018-11-28 22:19:30 +02:00
|
|
|
func newInternalLinkAnnotation(page int64, x, y, zoom float64) *model.PdfAnnotation {
|
|
|
|
annotation := model.NewPdfAnnotationLink()
|
|
|
|
|
|
|
|
// Set border style.
|
|
|
|
bs := model.NewBorderStyle()
|
|
|
|
bs.SetBorderWidth(0)
|
|
|
|
annotation.BS = bs.ToPdfObject()
|
|
|
|
|
|
|
|
// Set link destination.
|
|
|
|
if page < 0 {
|
|
|
|
page = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
annotation.Dest = core.MakeArray(
|
|
|
|
core.MakeInteger(page),
|
|
|
|
core.MakeName("XYZ"),
|
|
|
|
core.MakeFloat(x),
|
|
|
|
core.MakeFloat(y),
|
|
|
|
core.MakeFloat(zoom),
|
|
|
|
)
|
|
|
|
|
|
|
|
return annotation.PdfAnnotation
|
|
|
|
}
|
2019-01-11 19:19:31 +02:00
|
|
|
|
|
|
|
// copyLinkAnnotation returns a new link annotation based on an existing one.
|
|
|
|
func copyLinkAnnotation(link *model.PdfAnnotationLink) *model.PdfAnnotationLink {
|
|
|
|
if link == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
annotation := model.NewPdfAnnotationLink()
|
|
|
|
annotation.BS = link.BS
|
|
|
|
annotation.A = link.A
|
|
|
|
|
|
|
|
if annotDest, ok := link.Dest.(*core.PdfObjectArray); ok {
|
|
|
|
annotation.Dest = core.MakeArray(annotDest.Elements()...)
|
|
|
|
}
|
|
|
|
|
|
|
|
return annotation
|
|
|
|
}
|