Skip to content

Commit

Permalink
Merge branch 'nickjwhite-addtextrenderingmode-funconly'
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-kurt committed Nov 2, 2019
2 parents 9b6b7f4 + 465a102 commit 24bd947
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2226,6 +2226,23 @@ func (f *Fpdf) SetWordSpacing(space float64) {
f.out(sprintf("%.5f Tw", space*f.k))
}

// SetTextRenderingMode sets the rendering mode of following text.
// The mode can be as follows:
// 0: Fill text
// 1: Stroke text
// 2: Fill, then stroke text
// 3: Neither fill nor stroke text (invisible)
// 4: Fill text and add to path for clipping
// 5: Stroke text and add to path for clipping
// 6: Fills then stroke text and add to path for clipping
// 7: Add text to path for clipping
// This method is demonstrated in the SetTextRenderingMode example.
func (f *Fpdf) SetTextRenderingMode(mode int) {
if mode >= 0 && mode <= 7 {
f.out(sprintf("%d Tr", mode))
}
}

// SetAcceptPageBreakFunc allows the application to control where page breaks
// occur.
//
Expand Down
35 changes: 35 additions & 0 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2765,3 +2765,38 @@ func ExampleFpdf_Cell_strikeout() {
// Output:
// Successfully generated pdf/Fpdf_Cell_strikeout.pdf
}

// ExampleFpdf_SetTextRenderingMode demonstrates rendering modes in PDFs.
func ExampleFpdf_SetTextRenderingMode() {

pdf := gofpdf.New("P", "mm", "A4", "") // 210mm x 297mm
pdf.AddPage()
fontSz := float64(16)
lineSz := pdf.PointToUnitConvert(fontSz)
pdf.SetFont("Times", "", fontSz)
pdf.Write(lineSz, "This document demonstrates various modes of text rendering. Search for \"Mode 3\" "+
"to locate text that has been rendered invisibly. This selection can be copied "+
"into the clipboard as usual and is useful for overlaying onto non-textual elements such "+
"as images to make them searchable.\n\n")
fontSz = float64(125)
lineSz = pdf.PointToUnitConvert(fontSz)
pdf.SetFontSize(fontSz)
pdf.SetTextColor(170, 170, 190)
pdf.SetDrawColor(50, 60, 90)

write := func(mode int) {
pdf.SetTextRenderingMode(mode)
pdf.CellFormat(210, lineSz, fmt.Sprintf("Mode %d", mode), "", 1, "", false, 0, "")
}

for mode := 0; mode < 4; mode++ {
write(mode)
}
write(0)

fileStr := example.Filename("Fpdf_TextRenderingMode")
err := pdf.OutputFileAndClose(fileStr)
example.Summary(err, fileStr)
// Output:
// Successfully generated pdf/Fpdf_TextRenderingMode.pdf
}

0 comments on commit 24bd947

Please sign in to comment.