mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-05 19:30:30 +08:00
Merge branch 'v2' of https://github.com/unidoc/unidoc into up_v2_dev
* 'v2' of https://github.com/unidoc/unidoc: Coordinate system fix for line annotation (global vs local Form vs Page)
This commit is contained in:
commit
38d9bd73ef
@ -39,7 +39,7 @@ func makeLineAnnotationAppearanceStream(lineDef LineAnnotationDef) (*pdfcore.Pdf
|
|||||||
gsName = "gs1"
|
gsName = "gs1"
|
||||||
}
|
}
|
||||||
|
|
||||||
content, linebbox, err := drawPdfLine(lineDef, gsName)
|
content, localBbox, globalBbox, err := drawPdfLine(lineDef, gsName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
@ -49,16 +49,18 @@ func makeLineAnnotationAppearanceStream(lineDef LineAnnotationDef) (*pdfcore.Pdf
|
|||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
form.BBox = linebbox.ToPdfObject()
|
// Local bounding box for the XObject Form.
|
||||||
|
form.BBox = localBbox.ToPdfObject()
|
||||||
|
|
||||||
apDict := &pdfcore.PdfObjectDictionary{}
|
apDict := &pdfcore.PdfObjectDictionary{}
|
||||||
apDict.Set("N", form.ToPdfObject())
|
apDict.Set("N", form.ToPdfObject())
|
||||||
|
|
||||||
return apDict, linebbox, nil
|
return apDict, globalBbox, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Draw a line in PDF. Generates the content stream which can be used in page contents or appearance stream of annotation.
|
// Draw a line in PDF. Generates the content stream which can be used in page contents or appearance stream of annotation.
|
||||||
func drawPdfLine(lineDef LineAnnotationDef, gsName string) ([]byte, *pdf.PdfRectangle, error) {
|
// Returns the stream content, XForm bounding box (local), Rect bounding box (global/page) and an error if one occurred.
|
||||||
|
func drawPdfLine(lineDef LineAnnotationDef, gsName string) ([]byte, *pdf.PdfRectangle, *pdf.PdfRectangle, error) {
|
||||||
x1, x2 := lineDef.X1, lineDef.X2
|
x1, x2 := lineDef.X1, lineDef.X2
|
||||||
y1, y2 := lineDef.Y1, lineDef.Y2
|
y1, y2 := lineDef.Y1, lineDef.Y2
|
||||||
|
|
||||||
@ -184,6 +186,7 @@ func drawPdfLine(lineDef LineAnnotationDef, gsName string) ([]byte, *pdf.PdfRect
|
|||||||
}
|
}
|
||||||
|
|
||||||
pathBbox := path.GetBoundingBox()
|
pathBbox := path.GetBoundingBox()
|
||||||
|
|
||||||
creator := pdfcontent.NewContentCreator()
|
creator := pdfcontent.NewContentCreator()
|
||||||
|
|
||||||
// Draw line with arrow
|
// Draw line with arrow
|
||||||
@ -199,11 +202,23 @@ func drawPdfLine(lineDef LineAnnotationDef, gsName string) ([]byte, *pdf.PdfRect
|
|||||||
//creator.Add_S().
|
//creator.Add_S().
|
||||||
Add_Q()
|
Add_Q()
|
||||||
|
|
||||||
bbox := &pdf.PdfRectangle{}
|
// Offsets (needed for placement of annotations bbox).
|
||||||
bbox.Llx = pathBbox.X
|
offX := x1 - VsX
|
||||||
bbox.Lly = pathBbox.Y
|
offY := y1 - VsY
|
||||||
bbox.Urx = pathBbox.X + pathBbox.Width
|
|
||||||
bbox.Ury = pathBbox.Y + pathBbox.Height
|
|
||||||
|
|
||||||
return creator.Bytes(), bbox, nil
|
// Bounding box - local coordinate system (without offset).
|
||||||
|
localBbox := &pdf.PdfRectangle{}
|
||||||
|
localBbox.Llx = pathBbox.X
|
||||||
|
localBbox.Lly = pathBbox.Y
|
||||||
|
localBbox.Urx = pathBbox.X + pathBbox.Width
|
||||||
|
localBbox.Ury = pathBbox.Y + pathBbox.Height
|
||||||
|
|
||||||
|
// Bounding box - global page coordinate system (with offset).
|
||||||
|
globalBbox := &pdf.PdfRectangle{}
|
||||||
|
globalBbox.Llx = offX + pathBbox.X
|
||||||
|
globalBbox.Lly = offY + pathBbox.Y
|
||||||
|
globalBbox.Urx = offX + pathBbox.X + pathBbox.Width
|
||||||
|
globalBbox.Ury = offY + pathBbox.Y + pathBbox.Height
|
||||||
|
|
||||||
|
return creator.Bytes(), localBbox, globalBbox, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user