codeberg.org/go-pdf/fpdf@v0.11.1/makefont/makefont.go (about)

     1  package main
     2  
     3  import (
     4  	"flag"
     5  	"fmt"
     6  	"os"
     7  
     8  	"codeberg.org/go-pdf/fpdf"
     9  )
    10  
    11  func errPrintf(fmtStr string, args ...interface{}) {
    12  	fmt.Fprintf(os.Stderr, fmtStr, args...)
    13  }
    14  
    15  func showHelp() {
    16  	errPrintf("Usage: %s [options] font_file [font_file...]\n", os.Args[0])
    17  	flag.PrintDefaults()
    18  	fmt.Fprintln(os.Stderr, "\n"+
    19  		"font_file is the name of the TrueType file (extension .ttf), OpenType file\n"+
    20  		"(extension .otf) or binary Type1 file (extension .pfb) from which to\n"+
    21  		"generate a definition file. If an OpenType file is specified, it must be one\n"+
    22  		"that is based on TrueType outlines, not PostScript outlines; this cannot be\n"+
    23  		"determined from the file extension alone. If a Type1 file is specified, a\n"+
    24  		"metric file with the same pathname except with the extension .afm must be\n"+
    25  		"present.")
    26  	errPrintf("\nExample: %s --embed --enc=../font/cp1252.map --dst=../font calligra.ttf /opt/font/symbol.pfb\n", os.Args[0])
    27  }
    28  
    29  func main() {
    30  	var dstDirStr, encodingFileStr string
    31  	var err error
    32  	var help, embed bool
    33  	flag.StringVar(&dstDirStr, "dst", ".", "directory for output files (*.z, *.json)")
    34  	flag.StringVar(&encodingFileStr, "enc", "cp1252.map", "code page file")
    35  	flag.BoolVar(&embed, "embed", false, "embed font into PDF")
    36  	flag.BoolVar(&help, "help", false, "command line usage")
    37  	flag.Parse()
    38  	if help {
    39  		showHelp()
    40  	} else {
    41  		args := flag.Args()
    42  		if len(args) > 0 {
    43  			for _, fileStr := range args {
    44  				err = fpdf.MakeFont(fileStr, encodingFileStr, dstDirStr, os.Stderr, embed)
    45  				if err != nil {
    46  					errPrintf("%s\n", err)
    47  				}
    48  				// errPrintf("Font file [%s], Encoding file [%s], Embed [%v]\n", fileStr, encodingFileStr, embed)
    49  			}
    50  		} else {
    51  			errPrintf("At least one Type1 or TrueType font must be specified\n")
    52  			showHelp()
    53  		}
    54  	}
    55  }