示例#1
0
func main() {
	f, err := os.Create(name)
	if err != nil {
		panic(err)
	}
	doc := pdf.NewDocWriter()
	afmfc, err := afm_fonts.New("../../afm/data/fonts/*.afm")
	if err != nil {
		panic(err)
	}
	doc.AddFontSource(afmfc)

	doc.SetUnits("in")
	doc.SetLineSpacing(1.5)
	doc.MoveTo(1, 1)

	for _, info := range afmfc.FontInfos {
		if doc.Y() > 10 {
			doc.NewPage()
			doc.MoveTo(1, 1)
		}
		_, err = doc.SetFont(info.PostScriptName(), 12, options.Options{})
		if err != nil {
			panic(err)
		}
		fmt.Fprintln(doc, info.FullName())
	}
	doc.WriteTo(f)
	f.Close()
	exec.Command("open", name).Start()
}
示例#2
0
func NewDocWriter() *DocWriter {
	dw := pdf.NewDocWriter()
	ttFonts, err := ttf_fonts.New("/Library/Fonts/*.ttf")
	if err != nil {
		panic(err)
	}
	dw.AddFontSource(ttFonts)

	afmFonts, err := afm_fonts.New("../afm/data/fonts/*.afm")
	if err != nil {
		panic(err)
	}
	dw.AddFontSource(afmFonts)

	return &DocWriter{dw}
}
示例#3
0
func TestPageWriter_FontStyle(t *testing.T) {
	dw := NewDocWriter()

	ttfc, err := ttf_fonts.New("/Library/Fonts/*.ttf")
	if err != nil {
		t.Fatal(err)
	}
	dw.AddFontSource(ttfc)

	afmfc, err := afm_fonts.New("../afm/data/fonts/*.afm")
	if err != nil {
		t.Fatal(err)
	}
	dw.AddFontSource(afmfc)

	pw := dw.NewPage()

	check(t, pw.Fonts() == nil, "Page font list should be empty by default")
	check(t, pw.FontStyle() == "", "Should default to empty string")

	prev, err := pw.SetFontStyle("Italic")
	expectS(t, "No current font to apply style Italic to.", err.Error())
	check(t, prev == "", "Should return empty string when no font is set")

	_, err = pw.AddFont("Arial", options.Options{})
	check(t, err == nil, "Failed to add Arial")
	_, err = pw.AddFont("Helvetica", options.Options{})
	check(t, err == nil, "Failed to add Helvetica")

	fonts := pw.Fonts()
	checkFatal(t, len(fonts) == 2, "length of fonts should be 2")
	expectS(t, "", fonts[0].Style())
	expectS(t, "", fonts[1].Style())

	prev, err = pw.SetFontStyle("Italic")
	check(t, err == nil, "Error setting style to Italic.")
	check(t, pw.FontStyle() == "Italic", "FontStyle should now be Italic")
	fonts = pw.Fonts()
	checkFatal(t, len(fonts) == 2, "length of fonts should be 2")

	expectS(t, "Italic", fonts[0].Style())
	expectS(t, "Italic", fonts[1].Style())
}
示例#4
0
func main() {
	doc := pdf.NewDocWriter()
	afmfc, err := afm_fonts.New("../../afm/data/fonts/*.afm")
	if err != nil {
		panic(err)
	}
	doc.AddFontSource(afmfc)
	doc.SetUnits("in")

	doc.NewPage()
	doc.MoveTo(1, 1)
	_, err = doc.SetFont("Helvetica", 12, options.Options{})
	if err != nil {
		panic(err)
	}
	doc.SetUnderline(true)
	doc.Print("I18N Text\n\n")
	doc.SetUnderline(false)
	doc.SetLineSpacing(1.2)

	for _, k := range i18nKeys {
		// fmt.Println(i18nText[k])
		if doc.Y() > 10 {
			doc.NewPage()
			doc.MoveTo(1, 1)
		}
		fmt.Fprintf(doc, "%s:\n", k)
		doc.PrintWithOptions(i18nText[k], options.Options{"width": 6.5})
		fmt.Fprintln(doc)
	}
	f, err := os.Create(name)
	if err != nil {
		panic(err)
	}
	doc.WriteTo(f)
	f.Close()
	exec.Command("open", name).Start()
}