Add rotation support for checkbox fields

This commit is contained in:
Adrian-George Bostan 2020-06-30 19:19:03 +03:00
parent ac23b65eba
commit 434a93ea2c

View File

@ -686,6 +686,7 @@ func genFieldCheckboxAppearance(wa *model.PdfAnnotationWidget, fbtn *model.PdfFi
return nil, err
}
width, height := rect.Width(), rect.Height()
bboxWidth, bboxHeight := width, height
common.Log.Debug("Checkbox, wa BS: %v", wa.BS)
@ -694,7 +695,8 @@ func genFieldCheckboxAppearance(wa *model.PdfAnnotationWidget, fbtn *model.PdfFi
return nil, err
}
if mkDict, has := core.GetDict(wa.MK); has {
mkDict, has := core.GetDict(wa.MK)
if has {
bsDict, _ := core.GetDict(wa.BS)
err := style.applyAppearanceCharacteristics(mkDict, bsDict, zapfdb)
if err != nil {
@ -716,6 +718,11 @@ func genFieldCheckboxAppearance(wa *model.PdfAnnotationWidget, fbtn *model.PdfFi
drawAlignmentReticle(cc, style2, width, height)
}
// Apply rotation if present.
// Update width and height, as the appearance is generated based on
// the bounding of the annotation with no rotation.
width, height = style.applyRotation(mkDict, width, height, cc)
fontsize := style.AutoFontSizeFraction * height
checkmetrics, ok := zapfdb.GetRuneMetrics(style.CheckmarkRune)
@ -751,7 +758,7 @@ func genFieldCheckboxAppearance(wa *model.PdfAnnotationWidget, fbtn *model.PdfFi
xformOn.Resources = model.NewPdfPageResources()
xformOn.Resources.SetFontByName("ZaDb", zapfdb.ToPdfObject())
xformOn.BBox = core.MakeArrayFromFloats([]float64{0, 0, width, height})
xformOn.BBox = core.MakeArrayFromFloats([]float64{0, 0, bboxWidth, bboxHeight})
xformOn.SetContentStream(cc.Bytes(), defStreamEncoder())
}
@ -761,7 +768,7 @@ func genFieldCheckboxAppearance(wa *model.PdfAnnotationWidget, fbtn *model.PdfFi
if style.BorderSize > 0 {
drawRect(cc, style, width, height)
}
xformOff.BBox = core.MakeArrayFromFloats([]float64{0, 0, width, height})
xformOff.BBox = core.MakeArrayFromFloats([]float64{0, 0, bboxWidth, bboxHeight})
xformOff.SetContentStream(cc.Bytes(), defStreamEncoder())
}