From 964a79020b02ccd60381413790f05adccd162580 Mon Sep 17 00:00:00 2001 From: Ed Date: Tue, 24 Dec 2024 14:32:22 +0000 Subject: [PATCH] gofumpt: Run on all --- attachments.go | 6 ++-- def.go | 12 ++++--- fpdf_test.go | 4 +-- fpdftrans.go | 6 ++-- go.work.sum | 5 +++ grid.go | 1 - htmlbasic.go | 2 +- internal/example/example.go | 2 +- internal/files/files.go | 6 ++-- layer.go | 1 - subwrite.go | 2 +- template.go | 10 ++++-- utf8fontfile.go | 64 +++++++++++++++++++++++++++---------- util.go | 16 +++++----- 14 files changed, 93 insertions(+), 44 deletions(-) create mode 100644 go.work.sum diff --git a/attachments.go b/attachments.go index 6e397b73..b5262ce6 100644 --- a/attachments.go +++ b/attachments.go @@ -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 @@ -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) diff --git a/def.go b/def.go index 6a7030f9..015d0aae 100644 --- a/def.go +++ b/def.go @@ -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++ { @@ -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++ { diff --git a/fpdf_test.go b/fpdf_test.go index 856b937e..fcd89624 100644 --- a/fpdf_test.go +++ b/fpdf_test.go @@ -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", "") diff --git a/fpdftrans.go b/fpdftrans.go index 9cda3977..452a3cbd 100644 --- a/fpdftrans.go +++ b/fpdftrans.go @@ -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 diff --git a/go.work.sum b/go.work.sum new file mode 100644 index 00000000..ae166fbd --- /dev/null +++ b/go.work.sum @@ -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= diff --git a/grid.go b/grid.go index aca8508c..f55f62d1 100644 --- a/grid.go +++ b/grid.go @@ -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 diff --git a/htmlbasic.go b/htmlbasic.go index 9e4eca4e..1b99003e 100644 --- a/htmlbasic.go +++ b/htmlbasic.go @@ -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 diff --git a/internal/example/example.go b/internal/example/example.go index 285790d0..cfca2cc4 100644 --- a/internal/example/example.go +++ b/internal/example/example.go @@ -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) diff --git a/internal/files/files.go b/internal/files/files.go index 7f734131..f9320218 100644 --- a/internal/files/files.go +++ b/internal/files/files.go @@ -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{ @@ -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, +} diff --git a/layer.go b/layer.go index bca364f9..df261702 100644 --- a/layer.go +++ b/layer.go @@ -100,7 +100,6 @@ func (f *Fpdf) layerPutResourceDict() { } f.out(">>") } - } func (f *Fpdf) layerPutCatalog() { diff --git a/subwrite.go b/subwrite.go index e7ebd774..a4c0db17 100644 --- a/subwrite.go +++ b/subwrite.go @@ -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 diff --git a/template.go b/template.go index c0d3933b..8e9f0ed8 100644 --- a/template.go +++ b/template.go @@ -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) } @@ -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) diff --git a/utf8fontfile.go b/utf8fontfile.go index 0e1a17a7..72993fb7 100644 --- a/utf8fontfile.go +++ b/utf8fontfile.go @@ -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<> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> \nendcodespacerange\n1 beginbfrange\n<0000> <0000>\nendbfrange\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend" @@ -117,7 +119,6 @@ func (utf *utf8FontFile) parseFile() error { } func (utf *utf8FontFile) generateTableDescriptions() { - tablesCount := utf.readUint16() _ = utf.readUint16() _ = utf.readUint16() @@ -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) } @@ -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() @@ -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 @@ -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 { @@ -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) @@ -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) @@ -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 { @@ -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 { @@ -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) @@ -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() diff --git a/util.go b/util.go index 351d3192..e3a9da2b 100644 --- a/util.go +++ b/util.go @@ -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 { @@ -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 @@ -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 @@ -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 { @@ -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 {