Skip to content

Specify actual font name in PDF #56

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions pkg/pdf/fonts.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ var AutoFontSelection = true
// SelectedFont is the font to be used during export if AutoSelect is disabled
var SelectedFont = CourierPrime

var LoadedFont Font

func findFont(fonts []string) (string, error) {
for _, font := range fonts {
path, err := findfont.Find(font)
Expand Down Expand Up @@ -116,19 +118,20 @@ func loadFont(font Font) error {
}

// Successfully found the font
thisPDF.AddTTFFont("courier", pathToRegular)
LoadedFont = font
thisPDF.AddTTFFont(LoadedFont.RomanName, pathToRegular)

thisPDF.AddTTFFontWithOption("courier", pathToBold,
thisPDF.AddTTFFontWithOption(LoadedFont.RomanName, pathToBold,
gopdf.TtfOption{
Style: gopdf.Bold,
})

thisPDF.AddTTFFontWithOption("courier", pathToItalic,
thisPDF.AddTTFFontWithOption(LoadedFont.RomanName, pathToItalic,
gopdf.TtfOption{
Style: gopdf.Italic,
})

thisPDF.AddTTFFontWithOption("courier", pathToBoldItalic,
thisPDF.AddTTFFontWithOption(LoadedFont.RomanName, pathToBoldItalic,
gopdf.TtfOption{
Style: gopdf.Italic | gopdf.Bold,
})
Expand Down Expand Up @@ -173,9 +176,9 @@ func loadFonts() {
}

func setDefaultFont() {
thisPDF.SetFont("courier", "", fontSize)
thisPDF.SetFont(LoadedFont.RomanName, "", fontSize)
}

func setStyledFont(style string) {
thisPDF.SetFont("courier", style, fontSize)
thisPDF.SetFont(LoadedFont.RomanName, style, fontSize)
}