johnfercher / maroto

A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple.
https://maroto.io
MIT License
1.51k stars 173 forks source link

Text and Line get overlapped #454

Open lordofscripts opened 1 month ago

lordofscripts commented 1 month ago

The sample document It simply outputs a document first-level heading in black followed by a purple Horizontal line. It appears and the line component is not quite aware of the text component; although they are injected as two separate rows of row-height 6.

Secondary question: it is still not clear what is the unit of row height is. My experiments appear to indicate it is not related to the units of font size. Why? I tried computing a row height by adding a few units to the font-size used in that row but the results were disproportionate. It remains a guessing value.

func GetPoroto() *Poroto {
    return &Poroto{ GetMaroto(), getStyleManager(), getAutoNumber()  }
}

func main() 
    dm := GetPoroto()
    dm.Heading1("First Level")
    dm.HorizontalLine()
}

Describe the bug

The output PDF turns out the proper heading in its large font, but with the horizontal line across its middle (and no, I did not use a strikeout font!). The horizontal line, outputed after the heading, should appear below the 1st level heading.

To Reproduce

See sample above for main workflow. You already know the GetMaroto() which simply initializes a Maroto/v2 and returns the instance without outputing anything. The code outputs the Heading1()followed by a HorizontalLine().

Related code:

func (p *Poroto) Heading1(title string) {
    sch := p.autonumber.AtLevel(0)
    hdg := fmt.Sprintf("%s %s", sch.Render(), title)
    pty := p.styler.getTextPropertiesFor(DocStyleH1)
    row := text.NewRow(6, hdg, *pty)
    p.maroto.AddRows(row)
}

func (p *Poroto) HorizontalLine() {
    opts := props.Line{
        Color: &ColorIndigo,
        Thickness: 0.4,
        SizePercent: 90.0,
    }
    p.maroto.AddRows(line.NewRow(6, opts))
}

// relevant part of style manager which is a container of Document Styles. A document
// style has an ID (DocStyle type), a *props.Font, *props.Cell and align.Type.
func (sm *styleManager) getTextPropertiesFor(name DocStyle) *props.Text {
    fontS := sm.GetStyle(name)

    pty := &props.Text{
        Top: 2.0,
        Left: 1.0,
        Family: fontS.Family,
        Style: fontS.Style,
        Size: fontS.Size,
        Align: align.Left,
        Color: fontS.Color,
    }

    return pty
}

Expected behavior

The horizontal line should appear below the first-level heading text.

Stacktrace

N.A.

Additional context

I am trying to use Maroto/v2 (2.0.7) to output normal documents (not forms). In forms most (all) items are basically single-lined so to speak. In a document it may overflow to several lines, for example a paragraph. My document library wrapper is called Poroto.

lordofscripts commented 1 month ago

I got the text & underline better but not quite there yet. There is still a lot of guess work for the heading, plain text and horizontal line's row height value. That's not efficient when one should be developing, not guessing values ☹️.

I was missing the underestimated text.MakeValid() call in getTextProperties() and line.MakeValid() call in HorizontalLine(). Those were required because I was not fully initializing props.Text and props.Line objects!

However, my secondary question is still unresolved. Therefore I am not closing it yet.