diff options
author | Kurt <kurt.w.jung@gmail.com> | 2019-03-06 15:18:01 -0500 |
---|---|---|
committer | Kurt <kurt.w.jung@gmail.com> | 2019-03-06 15:18:01 -0500 |
commit | 6b7c17b5b904039a423e8df6e51875702bae5763 (patch) | |
tree | 5202cba8e8b0bb020c3e1440c8ac1c5e6e962ba2 | |
parent | a80b38af5767fdc558bed247f31aa45a0f5150c5 (diff) |
Unconditionally assign colors (fill, text and draw) and line width, cap style and line join style so that the manipulation of these properties in transformations, which begin with default values, will work as intended. Add example to demonstrate expected results.
-rw-r--r-- | fpdf.go | 32 | ||||
-rw-r--r-- | fpdf_test.go | 33 |
2 files changed, 43 insertions, 22 deletions
@@ -838,9 +838,7 @@ func rgbColorValue(r, g, b int, grayStr, fullStr string) (clr colorType) { // The method can be called before the first page is created. The value is // retained from page to page. func (f *Fpdf) SetDrawColor(r, g, b int) { - if r != f.color.draw.ir || g != f.color.draw.ig || b != f.color.draw.ib { - f.setDrawColor(r, g, b) - } + f.setDrawColor(r, g, b) } func (f *Fpdf) setDrawColor(r, g, b int) { @@ -862,9 +860,7 @@ func (f *Fpdf) GetDrawColor() (int, int, int) { // -255). The method can be called before the first page is created and the // value is retained from page to page. func (f *Fpdf) SetFillColor(r, g, b int) { - if r != f.color.fill.ir || g != f.color.fill.ig || b != f.color.fill.ib { - f.setFillColor(r, g, b) - } + f.setFillColor(r, g, b) } func (f *Fpdf) setFillColor(r, g, b int) { @@ -886,9 +882,7 @@ func (f *Fpdf) GetFillColor() (int, int, int) { // components (0 - 255). The method can be called before the first page is // created. The value is retained from page to page. func (f *Fpdf) SetTextColor(r, g, b int) { - if r != f.color.text.ir || g != f.color.text.ig || b != f.color.text.ib { - f.setTextColor(r, g, b) - } + f.setTextColor(r, g, b) } func (f *Fpdf) setTextColor(r, g, b int) { @@ -923,9 +917,7 @@ func (f *Fpdf) GetStringWidth(s string) float64 { // The method can be called before the first page is created. The value is // retained from page to page. func (f *Fpdf) SetLineWidth(width float64) { - if f.lineWidth != width { - f.setLineWidth(width) - } + f.setLineWidth(width) } func (f *Fpdf) setLineWidth(width float64) { @@ -954,11 +946,9 @@ func (f *Fpdf) SetLineCapStyle(styleStr string) { default: capStyle = 0 } - if capStyle != f.capStyle { - f.capStyle = capStyle - if f.page > 0 { - f.outf("%d J", f.capStyle) - } + f.capStyle = capStyle + if f.page > 0 { + f.outf("%d J", f.capStyle) } } @@ -975,11 +965,9 @@ func (f *Fpdf) SetLineJoinStyle(styleStr string) { default: joinStyle = 0 } - if joinStyle != f.joinStyle { - f.joinStyle = joinStyle - if f.page > 0 { - f.outf("%d j", f.joinStyle) - } + f.joinStyle = joinStyle + if f.page > 0 { + f.outf("%d j", f.joinStyle) } } diff --git a/fpdf_test.go b/fpdf_test.go index 707339f..34b824c 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -2441,3 +2441,36 @@ func ExampleFpdf_SetPage() { // Output: // Successfully generated pdf/Fpdf_SetPage.pdf } + +// ExampleFpdf_SetFillColor demonstrates how graphic attributes are properly +// assigned within multiple transformations. See issue #234. +func ExampleFpdf_SetFillColor() { + pdf := gofpdf.New("P", "mm", "A4", "") + + pdf.AddPage() + 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.Rect(0, 0, 20, 20, "FD") + pdf.TransformEnd() + + pdf.TransformBegin() + pdf.TransformTranslateX(35) + pdf.TransformTranslateY(35) + pdf.SetLineJoinStyle("round") + pdf.SetLineWidth(2) + pdf.SetDrawColor(128, 64, 0) + pdf.SetFillColor(255, 127, 0) + pdf.Rect(0, 0, 20, 20, "FD") + pdf.TransformEnd() + + fileStr := example.Filename("Fpdf_SetFillColor") + err := pdf.OutputFileAndClose(fileStr) + example.Summary(err, fileStr) + // Output: + // Successfully generated pdf/Fpdf_SetFillColor.pdf +} |