summaryrefslogtreecommitdiff
path: root/makefont/makefont.go
blob: eb2993ee0fa9c3f6713da85925bfce1a40c4a9b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main

import (
	"flag"
	"fmt"
	"github.com/jung-kurt/gofpdf"
	"os"
)

func errPrintf(fmtStr string, args ...interface{}) {
	fmt.Fprintf(os.Stderr, fmtStr, args...)
}

func showHelp() {
	errPrintf("Usage: %s [options] font_file [font_file...]\n", os.Args[0])
	flag.PrintDefaults()
	fmt.Fprintln(os.Stderr, "\n"+
		"font_file is the name of the TrueType file (extension .ttf), OpenType file\n"+
		"(extension .otf) or binary Type1 file (extension .pfb) from which to\n"+
		"generate a definition file. If an OpenType file is specified, it must be one\n"+
		"that is based on TrueType outlines, not PostScript outlines; this cannot be\n"+
		"determined from the file extension alone. If a Type1 file is specified, a\n"+
		"metric file with the same pathname except with the extension .afm must be\n"+
		"present.")
	errPrintf("\nExample: %s --embed --enc=../font/cp1252.map --dst=../font calligra.ttf /opt/font/symbol.pfb\n", os.Args[0])
}

func tutorialSummary(f *gofpdf.Fpdf, fileStr string) {
	if f.Ok() {
		fl, err := os.Create(fileStr)
		defer fl.Close()
		if err == nil {
			f.Output(fl)
		} else {
			f.SetError(err)
		}
	}
	if f.Ok() {
		fmt.Printf("Successfully generated %s\n", fileStr)
	} else {
		errPrintf("%s\n", f.Error())
	}
}

func main() {
	var dstDirStr, encodingFileStr string
	var err error
	var help, embed bool
	flag.StringVar(&dstDirStr, "dst", ".", "directory for output files (*.z, *.json)")
	flag.StringVar(&encodingFileStr, "enc", "cp1252.map", "code page file")
	flag.BoolVar(&embed, "embed", false, "embed font into PDF")
	flag.BoolVar(&help, "help", false, "command line usage")
	flag.Parse()
	if help {
		showHelp()
	} else {
		args := flag.Args()
		if len(args) > 0 {
			for _, fileStr := range args {
				err = gofpdf.MakeFont(fileStr, encodingFileStr, dstDirStr, os.Stderr, embed)
				if err != nil {
					errPrintf("%s\n", err)
				}
				// errPrintf("Font file [%s], Encoding file [%s], Embed [%v]\n", fileStr, encodingFileStr, embed)
			}
		} else {
			errPrintf("At least one Type1 or TrueType font must be specified\n")
			showHelp()
		}
	}
}