diff options
author | Kurt Jung <kurt.w.jung@code.google.com> | 2013-08-06 12:05:03 -0400 |
---|---|---|
committer | Kurt Jung <kurt.w.jung@code.google.com> | 2013-08-06 12:05:03 -0400 |
commit | 99805031b12f1084dd10b4a7d131bae00d8d05ad (patch) | |
tree | c4da318404acd0f14aa33f797714462920c56a8e | |
parent | 5e0bd6c7adc32e5e1d332f4a9218a9bc26b7e936 (diff) |
Tutorial 10 exercises some uncommon functions as reported by gocov.
-rw-r--r-- | fpdf.go | 14 | ||||
-rw-r--r-- | fpdf_test.go | 25 | ||||
-rw-r--r-- | ttfparser_test.go | 2 |
3 files changed, 23 insertions, 18 deletions
@@ -1040,10 +1040,16 @@ func (f *Fpdf) CellFormat(w, h float64, txtStr string, borderStr string, ln int, // A simpler version of CellFormat with no fill, border, links or special // alignment. func (f *Fpdf) Cell(w, h float64, txtStr string) { - // dbg("Cell. h is %.2f", h) f.CellFormat(w, h, txtStr, "", 0, "L", false, 0, "") } +// A simpler printf-style version of CellFormat with no fill, border, links or +// special alignment. See documentation for the fmt package for details on +// fmtStr and args. +func (f *Fpdf) Cellf(w, h float64, fmtStr string, args ...interface{}) { + f.CellFormat(w, h, sprintf(fmtStr, args...), "", 0, "L", false, 0, "") +} + // This method allows printing text with line breaks. They can be automatic (as // soon as the text reaches the right border of the cell) or explicit (via the // \n character). As many cells as necessary are output, one below the other. @@ -1263,6 +1269,12 @@ func (f *Fpdf) Write(h float64, txtStr string) { f.write(h, txtStr, 0, "") } +// Like Write but uses printf-style formatting. See the documentation for +// pckage fmt for mor details on fmtStr and args. +func (f *Fpdf) Writef(h float64, fmtStr string, args ...interface{}) { + f.write(h, sprintf(fmtStr, args...), 0, "") +} + // Write text that when clicked launches an external URL. See Write() for // argument details. func (f *Fpdf) WriteLinkString(h float64, displayStr, targetStr string) { diff --git a/fpdf_test.go b/fpdf_test.go index 9b57776..8f32da3 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -22,7 +22,6 @@ import ( "io/ioutil" "os" "strings" - "testing" ) // Absolute path needed for gocov tool; relative OK for test @@ -598,10 +597,8 @@ func ExampleFpdf_tutorial09() { } // Test the corner cases as reported by the gocov tool -func TestFpdf(t *testing.T) { - var nw nullWriter - tmpDirStr := os.TempDir() - MakeFont(FONT_DIR+"/calliga.ttf", FONT_DIR+"/cp1252.map", tmpDirStr, nil, true) +func ExampleFpdf_tutorial10() { + MakeFont(FONT_DIR+"/calligra.ttf", FONT_DIR+"/cp1252.map", FONT_DIR, nil, true) pdf := New("", "", "", "") pdf.SetFontLocation(FONT_DIR) pdf.SetTitle("世界", true) @@ -609,15 +606,11 @@ func TestFpdf(t *testing.T) { pdf.SetSubject("世界", true) pdf.SetCreator("世界", true) pdf.SetKeywords("世界", true) - pdf.Output(&nw) - if len(pdf.String()) < 1 { - t.Fatalf("Trouble with pdf.String()") - } - err := pdf.Error() - if err != nil { - t.Fatal(err) - } - if pdf.Err() { - t.Fatal(pdf.Error()) - } + pdf.AddFont("Calligrapher", "", "calligra.json") + pdf.AddPage() + pdf.SetFont("Calligrapher", "", 16) + pdf.Writef(5, "\x95 %s \x95", pdf) + pdf.Output(docWriter(pdf, 10)) + // Output: + // Successfully generated pdf/tutorial10.pdf } diff --git a/ttfparser_test.go b/ttfparser_test.go index dcdab4e..c856ec5 100644 --- a/ttfparser_test.go +++ b/ttfparser_test.go @@ -22,7 +22,7 @@ import ( ) func ExampleTtfParse() { - ttf, err := TtfParse(GOFPDF_DIR + "/font/calligra.ttf") + ttf, err := TtfParse(FONT_DIR + "/calligra.ttf") if err == nil { fmt.Printf("Postscript name: %s\n", ttf.PostScriptName) fmt.Printf("unitsPerEm: %8d\n", ttf.UnitsPerEm) |