Kurt Jungs Auslieferungszustand

This commit is contained in:
2021-03-02 13:27:45 +01:00
commit 5afea81825
156 changed files with 30287 additions and 0 deletions

23
makefont/doc.go Normal file
View File

@@ -0,0 +1,23 @@
/*
* Copyright (c) 2013 Kurt Jung
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/*
Command makefont generates a font definition file.
This utility is used to generate a font definition file that allows TrueType
and Type1 fonts to be used in PDFs produced with the fpdf package.
*/
package main

71
makefont/makefont.go Normal file
View File

@@ -0,0 +1,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()
}
}
}

26
makefont/makefont_test.go Normal file
View File

@@ -0,0 +1,26 @@
package main
import (
"os/exec"
"strings"
"testing"
)
func TestMakefont(t *testing.T) {
var out []byte
var err error
const expect = "Font definition file successfully generated"
// Make sure makefont utility has been built before generating font definition file
err = exec.Command("go", "build").Run()
if err != nil {
t.Fatal(err)
}
out, err = exec.Command("./makefont", "--dst=../font", "--embed",
"--enc=../font/cp1252.map", "../font/calligra.ttf").CombinedOutput()
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(out), expect) {
t.Fatalf("Unexpected output from makefont")
}
}