Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gofumpt: Run on all #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (

// Attachment defines a content to be included in the pdf, in one
// of the following ways :
// - associated with the document as a whole : see SetAttachments()
// - accessible via a link localized on a page : see AddAttachmentAnnotation()
// - associated with the document as a whole : see SetAttachments()
// - accessible via a link localized on a page : see AddAttachmentAnnotation()
type Attachment struct {
Content []byte

Expand All @@ -34,7 +34,7 @@ func checksum(data []byte) string {
return hex.EncodeToString(sl)
}

// Writes a compressed file like object as ``/EmbeddedFile``. Compressing is
// Writes a compressed file like object as /EmbeddedFile. Compressing is
// done with deflate. Includes length, compressed length and MD5 checksum.
func (f *Fpdf) writeCompressedFileObject(content []byte) {
lenUncompressed := len(content)
Expand Down
12 changes: 8 additions & 4 deletions def.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,10 @@ func generateImageID(info *ImageInfoType) (string, error) {

// GobEncode encodes the receiving image to a byte slice.
func (info *ImageInfoType) GobEncode() (buf []byte, err error) {
fields := []interface{}{info.data, info.smask, info.n, info.w, info.h, info.cs,
info.pal, info.bpc, info.f, info.dp, info.trns, info.scale, info.dpi}
fields := []interface{}{
info.data, info.smask, info.n, info.w, info.h, info.cs,
info.pal, info.bpc, info.f, info.dp, info.trns, info.scale, info.dpi,
}
w := new(bytes.Buffer)
encoder := gob.NewEncoder(w)
for j := 0; j < len(fields) && err == nil; j++ {
Expand All @@ -204,8 +206,10 @@ func (info *ImageInfoType) GobEncode() (buf []byte, err error) {
// GobDecode decodes the specified byte buffer (generated by GobEncode) into
// the receiving image.
func (info *ImageInfoType) GobDecode(buf []byte) (err error) {
fields := []interface{}{&info.data, &info.smask, &info.n, &info.w, &info.h,
&info.cs, &info.pal, &info.bpc, &info.f, &info.dp, &info.trns, &info.scale, &info.dpi}
fields := []interface{}{
&info.data, &info.smask, &info.n, &info.w, &info.h,
&info.cs, &info.pal, &info.bpc, &info.f, &info.dp, &info.trns, &info.scale, &info.dpi,
}
r := bytes.NewBuffer(buf)
decoder := gob.NewDecoder(r)
for j := 0; j < len(fields) && err == nil; j++ {
Expand Down
4 changes: 2 additions & 2 deletions fpdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2641,11 +2641,11 @@ func ExampleUTF8CutFont() {

pdfFileStr = example.Filename("Fpdf_UTF8CutFont")
fullFontFileStr = example.FontFile("calligra.ttf")
fullFont, err = ioutil.ReadFile(fullFontFileStr)
fullFont, err = os.ReadFile(fullFontFileStr)
if err == nil {
subFontFileStr = "calligra_abcde.ttf"
subFont = gofpdf.UTF8CutFont(fullFont, "abcde")
err = ioutil.WriteFile(subFontFileStr, subFont, 0600)
err = os.WriteFile(subFontFileStr, subFont, 0o600)
if err == nil {
y := 24.0
pdf := gofpdf.New("P", "mm", "A4", "")
Expand Down
6 changes: 4 additions & 2 deletions fpdftrans.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ func (f *Fpdf) TransformScale(scaleWd, scaleHt, x, y float64) {
x *= f.k
scaleWd /= 100
scaleHt /= 100
f.Transform(TransformMatrix{scaleWd, 0, 0,
scaleHt, x * (1 - scaleWd), y * (1 - scaleHt)})
f.Transform(TransformMatrix{
scaleWd, 0, 0,
scaleHt, x * (1 - scaleWd), y * (1 - scaleHt),
})
}

// TransformMirrorHorizontal horizontally mirrors the following text, drawings
Expand Down
5 changes: 5 additions & 0 deletions go.work.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
github.com/jung-kurt/gofpdf v1.0.0 h1:EroSdlP9BOoL5ssLYf3uLJXhCQMMM2fFxCJDKA3RhnA=
github.com/phpdave11/gofpdf v1.4.2 h1:KPKiIbfwbvC/wOncwhrpRdXVj2CZTCFlw4wnoyjtHfQ=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo=
golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ=
1 change: 0 additions & 1 deletion grid.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ func (g GridType) Grid(pdf *Fpdf) {
st.Put(pdf)

}

}

// Plot plots a series of count line segments from xMin to xMax. It repeatedly
Expand Down
2 changes: 1 addition & 1 deletion htmlbasic.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (f *Fpdf) HTMLBasicNew() (html HTMLBasicType) {
// lineHt indicates the line height in the unit of measure specified in New().
func (html *HTMLBasicType) Write(lineHt float64, htmlStr string) {
var boldLvl, italicLvl, underscoreLvl, linkBold, linkItalic, linkUnderscore int
var textR, textG, textB = html.pdf.GetTextColor()
textR, textG, textB := html.pdf.GetTextColor()
var hrefStr string
if html.Link.Bold {
linkBold = 1
Expand Down
2 changes: 1 addition & 1 deletion internal/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func referenceCompare(fileStr string) (err error) {
var refFileStr, refDirStr, dirStr, baseFileStr string
dirStr, baseFileStr = filepath.Split(fileStr)
refDirStr = filepath.Join(dirStr, "reference")
err = os.MkdirAll(refDirStr, 0755)
err = os.MkdirAll(refDirStr, 0o755)
if err == nil {
refFileStr = filepath.Join(refDirStr, baseFileStr)
err = gofpdf.ComparePDFFiles(fileStr, refFileStr, false)
Expand Down
6 changes: 4 additions & 2 deletions internal/files/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ var CalligraJson = []byte{
0x65, 0x32, 0x22, 0x3A, 0x30, 0x2C, 0x22, 0x4F, 0x72, 0x69, 0x67, 0x69, 0x6E, 0x61, 0x6C, 0x53,
0x69, 0x7A, 0x65, 0x22, 0x3A, 0x34, 0x30, 0x31, 0x32, 0x30, 0x2C, 0x22, 0x49, 0x22, 0x3A, 0x30,
0x2C, 0x22, 0x4E, 0x22, 0x3A, 0x30, 0x2C, 0x22, 0x44, 0x69, 0x66, 0x66, 0x4E, 0x22, 0x3A, 0x30,
0x7D}
0x7D,
}

// CalligraZ is embedded byte slice for calligra.z
var CalligraZ = []byte{
Expand Down Expand Up @@ -1688,4 +1689,5 @@ var CalligraZ = []byte{
0x54, 0x75, 0x39, 0x2C, 0xCD, 0x40, 0xC8, 0x95, 0x6F, 0xE8, 0x78, 0x59, 0x09, 0x07, 0x5D, 0xCD,
0x38, 0x25, 0x10, 0x2C, 0xA1, 0xC7, 0xE3, 0x61, 0x36, 0x91, 0xC7, 0x9E, 0xF0, 0xE2, 0x25, 0xD8,
0xE3, 0xB8, 0xC1, 0x8F, 0xB0, 0x27, 0x24, 0x76, 0x71, 0xC9, 0xEE, 0x82, 0xBE, 0x3F, 0xEC, 0xFF,
0x27, 0x00, 0x00, 0xFF, 0xFF, 0xA4, 0xB4, 0xB8, 0xA4}
0x27, 0x00, 0x00, 0xFF, 0xFF, 0xA4, 0xB4, 0xB8, 0xA4,
}
1 change: 0 additions & 1 deletion layer.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ func (f *Fpdf) layerPutResourceDict() {
}
f.out(">>")
}

}

func (f *Fpdf) layerPutCatalog() {
Expand Down
2 changes: 1 addition & 1 deletion subwrite.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func (f *Fpdf) SubWrite(ht float64, str string, subFontSize, subOffset float64,
subX := f.x
subY := f.y
f.SetXY(subX, subY-subOffset)
//Output text
// Output text
f.write(ht, str, link, linkStr)
// restore y position
subX = f.x
Expand Down
10 changes: 8 additions & 2 deletions template.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,13 @@ func (f *Fpdf) putTemplates() {
f.outf("<<%s/Type /XObject", filter)
f.out("/Subtype /Form")
f.out("/Formtype 1")
f.outf("/BBox [%.2f %.2f %.2f %.2f]", corner.X*f.k, corner.Y*f.k, (corner.X+size.Wd)*f.k, (corner.Y+size.Ht)*f.k)
f.outf(
"/BBox [%.2f %.2f %.2f %.2f]",
corner.X*f.k,
corner.Y*f.k,
(corner.X+size.Wd)*f.k,
(corner.Y+size.Ht)*f.k,
)
if corner.X != 0 || corner.Y != 0 {
f.outf("/Matrix [1 0 0 1 %.5f %.5f]", -corner.X*f.k*2, corner.Y*f.k*2)
}
Expand Down Expand Up @@ -266,7 +272,7 @@ chain:
return sorted
}

// templateChainDependencies is a recursive function for determining the full chain of template dependencies
// templateChainDependencies is a recursive function for determining the full chain of template dependencies
func templateChainDependencies(template Template) []Template {
requires := template.Templates()
chain := make([]Template, len(requires)*2)
Expand Down
64 changes: 48 additions & 16 deletions utf8fontfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ import (
)

// flags
const symbolWords = 1 << 0
const symbolScale = 1 << 3
const symbolContinue = 1 << 5
const symbolAllScale = 1 << 6
const symbol2x2 = 1 << 7
const (
symbolWords = 1 << 0
symbolScale = 1 << 3
symbolContinue = 1 << 5
symbolAllScale = 1 << 6
symbol2x2 = 1 << 7
)

// CID map Init
const toUnicode = "/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo\n<</Registry (Adobe)\n/Ordering (UCS)\n/Supplement 0\n>> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n1 beginbfrange\n<0000> <FFFF> <0000>\nendbfrange\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend"
Expand Down Expand Up @@ -117,7 +119,6 @@ func (utf *utf8FontFile) parseFile() error {
}

func (utf *utf8FontFile) generateTableDescriptions() {

tablesCount := utf.readUint16()
_ = utf.readUint16()
_ = utf.readUint16()
Expand Down Expand Up @@ -189,7 +190,7 @@ func (utf *utf8FontFile) skip(delta int) {
_, _ = utf.fileReader.seek(int64(delta), 1)
}

//SeekTable position
// SeekTable position
func (utf *utf8FontFile) SeekTable(name string) int {
return utf.seekTable(name, 0)
}
Expand Down Expand Up @@ -342,7 +343,12 @@ func (utf *utf8FontFile) parseHEADTable() {
yMin := utf.readInt16()
xMax := utf.readInt16()
yMax := utf.readInt16()
utf.Bbox = fontBoxType{int(float64(xMin) * scale), int(float64(yMin) * scale), int(float64(xMax) * scale), int(float64(yMax) * scale)}
utf.Bbox = fontBoxType{
int(float64(xMin) * scale),
int(float64(yMin) * scale),
int(float64(xMax) * scale),
int(float64(yMax) * scale),
}
utf.skip(3 * 2)
_ = utf.readUint16()
symbolDataFormat := utf.readUint16()
Expand Down Expand Up @@ -561,7 +567,13 @@ func (utf *utf8FontFile) parseSymbols(usedRunes map[int]int) (map[int]int, map[i

symbolCollectionKeys = keySortInt(symbolCollection)
for _, oldSymbolIndex := range symbolCollectionKeys {
_, symbolArray, symbolCollection, symbolCollectionKeys = utf.getSymbols(oldSymbolIndex, &begin, symbolArray, symbolCollection, symbolCollectionKeys)
_, symbolArray, symbolCollection, symbolCollectionKeys = utf.getSymbols(
oldSymbolIndex,
&begin,
symbolArray,
symbolCollection,
symbolCollectionKeys,
)
}

return runeSymbolPairCollection, symbolArray, symbolCollection, symbolCollectionKeys
Expand Down Expand Up @@ -619,7 +631,6 @@ func (utf *utf8FontFile) generateCMAPTable(cidSymbolPairCollection map[int]int,
cmap = append(cmap, 1)
for range cidArray {
cmap = append(cmap, 0)

}
cmap = append(cmap, 0)
for _, start := range cidArrayKeys {
Expand All @@ -635,7 +646,7 @@ func (utf *utf8FontFile) generateCMAPTable(cidSymbolPairCollection map[int]int,
return cmapstr
}

//GenerateCutFont fill utf8FontFile from .utf file, only with runes from usedRunes
// GenerateCutFont fill utf8FontFile from .utf file, only with runes from usedRunes
func (utf *utf8FontFile) GenerateCutFont(usedRunes map[int]int) []byte {
utf.fileReader.readerPosition = 0
utf.symbolPosition = make([]int, 0)
Expand Down Expand Up @@ -682,7 +693,9 @@ func (utf *utf8FontFile) GenerateCutFont(usedRunes map[int]int) []byte {
utf.setOutTable("gasp", utf.getTableData("gasp"))

postTable := utf.getTableData("post")
postTable = append(append([]byte{0x00, 0x03, 0x00, 0x00}, postTable[4:16]...), []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}...)
postTable = append(
append([]byte{0x00, 0x03, 0x00, 0x00}, postTable[4:16]...),
[]byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}...)
utf.setOutTable("post", postTable)

delete(cidSymbolPairCollection, 0)
Expand Down Expand Up @@ -726,7 +739,10 @@ func (utf *utf8FontFile) GenerateCutFont(usedRunes map[int]int) []byte {
if _, OK := utf.symbolData[originalSymbolIdx]["compSymbols"]; !OK {
utf.symbolData[originalSymbolIdx]["compSymbols"] = make([]int, 0)
}
utf.symbolData[originalSymbolIdx]["compSymbols"] = append(utf.symbolData[originalSymbolIdx]["compSymbols"], symbolIdx)
utf.symbolData[originalSymbolIdx]["compSymbols"] = append(
utf.symbolData[originalSymbolIdx]["compSymbols"],
symbolIdx,
)
data = utf.insertUint16(data, posInSymbol+2, symbolArray[symbolIdx])
posInSymbol += 4
if (flags & symbolWords) != 0 {
Expand Down Expand Up @@ -790,7 +806,13 @@ func (utf *utf8FontFile) GenerateCutFont(usedRunes map[int]int) []byte {
return utf.assembleTables()
}

func (utf *utf8FontFile) getSymbols(originalSymbolIdx int, start *int, symbolSet map[int]int, SymbolsCollection map[int]int, SymbolsCollectionKeys []int) (*int, map[int]int, map[int]int, []int) {
func (utf *utf8FontFile) getSymbols(
originalSymbolIdx int,
start *int,
symbolSet map[int]int,
SymbolsCollection map[int]int,
SymbolsCollectionKeys []int,
) (*int, map[int]int, map[int]int, []int) {
symbolPos := utf.symbolPosition[originalSymbolIdx]
symbolSize := utf.symbolPosition[originalSymbolIdx+1] - symbolPos
if symbolSize == 0 {
Expand All @@ -812,7 +834,13 @@ func (utf *utf8FontFile) getSymbols(originalSymbolIdx int, start *int, symbolSet
SymbolsCollectionKeys = append(SymbolsCollectionKeys, symbolIndex)
}
oldPosition, _ := utf.fileReader.seek(0, 1)
_, _, _, SymbolsCollectionKeys = utf.getSymbols(symbolIndex, start, symbolSet, SymbolsCollection, SymbolsCollectionKeys)
_, _, _, SymbolsCollectionKeys = utf.getSymbols(
symbolIndex,
start,
symbolSet,
SymbolsCollection,
SymbolsCollectionKeys,
)
utf.seek(int(oldPosition))
if flags&symbolWords != 0 {
utf.skip(4)
Expand Down Expand Up @@ -921,7 +949,11 @@ func (utf *utf8FontFile) parseLOCATable(format, numSymbols int) {
}
}

func (utf *utf8FontFile) generateSCCSDictionaries(runeCmapPosition int, symbolCharDictionary map[int][]int, charSymbolDictionary map[int]int) {
func (utf *utf8FontFile) generateSCCSDictionaries(
runeCmapPosition int,
symbolCharDictionary map[int][]int,
charSymbolDictionary map[int]int,
) {
maxRune := 0
utf.seek(runeCmapPosition + 2)
size := utf.readUint16()
Expand Down
16 changes: 8 additions & 8 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,14 @@ func (s *SizeType) ScaleToHeight(height float64) SizeType {
return SizeType{width, height}
}

//The untypedKeyMap structure and its methods are copyrighted 2019 by Arteom Korotkiy (Gmail: arteomkorotkiy).
//Imitation of untyped Map Array
// The untypedKeyMap structure and its methods are copyrighted 2019 by Arteom Korotkiy (Gmail: arteomkorotkiy).
// Imitation of untyped Map Array
type untypedKeyMap struct {
keySet []interface{}
valueSet []int
}

//Get position of key=>value in PHP Array
// Get position of key=>value in PHP Array
func (pa *untypedKeyMap) getIndex(key interface{}) int {
if key != nil {
for i, mKey := range pa.keySet {
Expand All @@ -341,7 +341,7 @@ func (pa *untypedKeyMap) getIndex(key interface{}) int {
return -1
}

//Put key=>value in PHP Array
// Put key=>value in PHP Array
func (pa *untypedKeyMap) put(key interface{}, value int) {
if key == nil {
var i int
Expand All @@ -365,7 +365,7 @@ func (pa *untypedKeyMap) put(key interface{}, value int) {
}
}

//Delete value in PHP Array
// Delete value in PHP Array
func (pa *untypedKeyMap) delete(key interface{}) {
if pa == nil || pa.keySet == nil || pa.valueSet == nil {
return
Expand All @@ -385,7 +385,7 @@ func (pa *untypedKeyMap) delete(key interface{}) {
}
}

//Get value from PHP Array
// Get value from PHP Array
func (pa *untypedKeyMap) get(key interface{}) int {
i := pa.getIndex(key)
if i >= 0 {
Expand All @@ -394,13 +394,13 @@ func (pa *untypedKeyMap) get(key interface{}) int {
return 0
}

//Imitation of PHP function pop()
// Imitation of PHP function pop()
func (pa *untypedKeyMap) pop() {
pa.keySet = pa.keySet[:len(pa.keySet)-1]
pa.valueSet = pa.valueSet[:len(pa.valueSet)-1]
}

//Imitation of PHP function array_merge()
// Imitation of PHP function array_merge()
func arrayMerge(arr1, arr2 *untypedKeyMap) *untypedKeyMap {
answer := untypedKeyMap{}
if arr1 == nil && arr2 == nil {
Expand Down
Loading