Skip to content
This repository has been archived by the owner on Nov 13, 2021. It is now read-only.

Commit

Permalink
Merge branch 'joewestcott-graphics-state-checks'
Browse files Browse the repository at this point in the history
  • Loading branch information
jung-kurt committed Mar 9, 2019
2 parents 6b7c17b + 4d91079 commit 028e9cd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
25 changes: 8 additions & 17 deletions fpdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,13 @@ func (f *Fpdf) SetDashPattern(dashArray []float64, dashPhase float64) {
scaled[i] = value * f.k
}
dashPhase *= f.k
if !slicesEqual(scaled, f.dashArray) || dashPhase != f.dashPhase {
f.dashArray = scaled
f.dashPhase = dashPhase
if f.page > 0 {
f.outputDashPattern()
}

f.dashArray = scaled
f.dashPhase = dashPhase
if f.page > 0 {
f.outputDashPattern()
}

}

func (f *Fpdf) outputDashPattern() {
Expand Down Expand Up @@ -1234,7 +1234,7 @@ func (f *Fpdf) GetAlpha() (alpha float64, blendModeStr string) {
// To reset normal rendering after applying a blending mode, call this method
// with alpha set to 1.0 and blendModeStr set to "Normal".
func (f *Fpdf) SetAlpha(alpha float64, blendModeStr string) {
if f.err != nil || (alpha == f.alpha && blendModeStr == f.blendMode) {
if f.err != nil {
return
}
var bl blendModeType
Expand Down Expand Up @@ -1742,10 +1742,7 @@ func (f *Fpdf) SetFont(familyStr, styleStr string, size float64) {
if size == 0.0 {
size = f.fontSizePt
}
// Test if font is already selected
if f.fontFamily == familyStr && f.fontStyle == styleStr && f.fontSizePt == size {
return
}

// Test if font is already loaded
fontkey := familyStr + styleStr
_, ok = f.fonts[fontkey]
Expand Down Expand Up @@ -1793,9 +1790,6 @@ func (f *Fpdf) SetFont(familyStr, styleStr string, size float64) {
// SetFontSize defines the size of the current font. Size is specified in
// points (1/ 72 inch). See also SetFontUnitSize().
func (f *Fpdf) SetFontSize(size float64) {
if f.fontSizePt == size {
return
}
f.fontSizePt = size
f.fontSize = size / f.k
if f.page > 0 {
Expand All @@ -1806,9 +1800,6 @@ func (f *Fpdf) SetFontSize(size float64) {
// SetFontUnitSize defines the size of the current font. Size is specified in
// the unit of measure specified in New(). See also SetFontSize().
func (f *Fpdf) SetFontUnitSize(size float64) {
if f.fontSize == size {
return
}
f.fontSizePt = size * f.k
f.fontSize = size
if f.page > 0 {
Expand Down
10 changes: 10 additions & 0 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2448,14 +2448,20 @@ func ExampleFpdf_SetFillColor() {
pdf := gofpdf.New("P", "mm", "A4", "")

pdf.AddPage()
pdf.SetFont("Arial", "", 12)

pdf.TransformBegin()
pdf.TransformTranslateX(5)
pdf.TransformTranslateY(5)
pdf.SetLineJoinStyle("round")
pdf.SetLineWidth(2)
pdf.SetDrawColor(128, 64, 0)
pdf.SetFillColor(255, 127, 0)
pdf.SetAlpha(0.5, "Normal")
pdf.SetDashPattern([]float64{5, 10}, 0)
pdf.Rect(0, 0, 20, 20, "FD")
pdf.SetFontSize(8)
pdf.Write(10, "Test")
pdf.TransformEnd()

pdf.TransformBegin()
Expand All @@ -2465,7 +2471,11 @@ func ExampleFpdf_SetFillColor() {
pdf.SetLineWidth(2)
pdf.SetDrawColor(128, 64, 0)
pdf.SetFillColor(255, 127, 0)
pdf.SetAlpha(0.5, "Normal")
pdf.SetDashPattern([]float64{5, 10}, 0)
pdf.Rect(0, 0, 20, 20, "FD")
pdf.SetFontSize(8)
pdf.Write(10, "Test")
pdf.TransformEnd()

fileStr := example.Filename("Fpdf_SetFillColor")
Expand Down

0 comments on commit 028e9cd

Please sign in to comment.