Skip to content

Commit

Permalink
Merge pull request #144 from vsimakhin/fix/long-comments-for-a4-export
Browse files Browse the repository at this point in the history
Fix/long comments for a4 export
  • Loading branch information
vsimakhin authored Jul 1, 2023
2 parents 21f5c66 + c45f0bf commit b45aa9b
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [Unreleased]

- Fix: set smaller font size or even truncate the remarks for PDF exports in case they are too long

## [2.22.0]

- New: Dark mode.
Expand Down
25 changes: 25 additions & 0 deletions internal/pdfexport/pdfexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,31 @@ func formatLandings(landing int) string {
}
}

func printBodyRemarksCell(w float64, value string, fill bool) {

wFactored := int(w * 0.9)
vL := len(value)
longCut := int(1.75 * float64(wFactored))

if vL > longCut {
// too long remark, cut it and set font 5
pdf.SetFont(fontRegular, "", 5)
value = value[:longCut-3] + "..."

} else if vL > wFactored*3/2 {
// slightly long remark
pdf.SetFont(fontRegular, "", 5)

} else if vL > wFactored {
// long remark
pdf.SetFont(fontRegular, "", 6)

}

pdf.CellFormat(w, bodyRowHeight, value, "1", 0, "L", fill, 0, "")
pdf.SetFont(fontRegular, "", 8)
}

func isFillLine(rowCounter int, fill int) bool {
if (rowCounter)%fill == 0 { // fill every "fill" row only
return true
Expand Down
2 changes: 1 addition & 1 deletion internal/pdfexport/pdfexport_a4.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func printA4LogbookBody(record models.FlightRecord, fill bool) {
printBodyTimeCell(w3[19], record.Time.Instructor, fill)
printBodyTimeCell(w3[20], record.SIM.Type, fill)
printBodyTimeCell(w3[21], record.SIM.Time, fill)
printBodyTextCell(w3[22], record.Remarks, fill)
printBodyRemarksCell(w3[22], record.Remarks, fill)

pdf.Ln(-1)

Expand Down
2 changes: 1 addition & 1 deletion internal/pdfexport/pdfexport_a5.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func printA5LogbookBodyB(record models.FlightRecord, fill bool) {
}
printBodyTimeCell(w3[20], record.SIM.Type, fill)
printBodyTimeCell(w3[21], record.SIM.Time, fill)
printBodyTextCell(w3[22], record.Remarks, fill)
printBodyRemarksCell(w3[22], record.Remarks, fill)

pdf.Ln(-1)

Expand Down

0 comments on commit b45aa9b

Please sign in to comment.