moolekkari / unipdf

Other
2 stars 1 forks source link

[BUG] .SetPos(x,y) on a StyledParagraph makes the text disappear #2

Open ErikTMA opened 1 year ago

ErikTMA commented 1 year ago

Description

running .SetPos(x,y) on a StyledParagraph makes the text disappear.

code example:

c := creator.New()

img, err := c.NewImageFromFile(art.Images[0].Path)
if err != nil {
    common.Log.Debug("Error loading image: %v", err)
    return err
}
img.ScaleToWidth(612.0)

// Use page width of 612 points, and calculate the height proportionally based on the image.
// Standard PPI is 72 points per inch, thus a width of 8.5"
width := 612.0
height := width * img.Height() / img.Width()
c.SetPageSize(creator.PageSize{612, height})
c.NewPage()
img.SetPos(0, 0)
_ = c.Draw(img)
p := c.NewStyledParagraph()
p.SetEnableWrap(false)
p.SetLineHeight(2)
p.SetMargins(0, 0, 0, 0)
p.SetTextAlignment(creator.TextAlignmentCenter)

style := &p.AddExternalLink("Download "+art.Name, art.ShareLink).Style
font, err := model.NewStandard14Font(model.HelveticaBoldName)
if err != nil {
    return err
}
style.Font = font
style.FontSize = 25
style.Color = creator.ColorRGBFrom8bit(35, 35, 35)
posX := (width - p.Width()) / 2
posY := (height - p.Height()) / 4

p.SetPos(posX, posY)
rect := c.NewRectangle(posX, posY, p.Width(), p.Height())
rect.SetBorderWidth(0)
rect.SetFillColor(creator.ColorRGBFrom8bit(200, 200, 200))

c.Draw(rect)
c.Draw(p)

Removing the p.SetPos() line, makes the text appear.

The rect is printed fine. The order of c.Draw doesn't change anything, neither does simply not drawing the rect, so it is not because it is behind it.

Expected Behavior

The paragraph should be at the absolute position equal to the rect.

Actual Behavior

Steps to reproduce the behavior:

  1. simply run the code. Add picture, text and link yourself. :)

Attachments

none

github-actions[bot] commented 1 year ago

Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. If you need to get this done, consider buying a license which also enables you to use it in your commercial products. More information can be found on https://unidoc.io/