From 6d3753730cb9184a9c80d710f7b8784b8539733e Mon Sep 17 00:00:00 2001 From: Ali Bala Date: Tue, 8 Jun 2021 15:19:36 +0100 Subject: [PATCH] Rename receiver of pdfTTFont from 'ob' to 'f' --- pdf_ttfont.go | 130 +++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 65 deletions(-) diff --git a/pdf_ttfont.go b/pdf_ttfont.go index 5b6bbc1..c49b423 100644 --- a/pdf_ttfont.go +++ b/pdf_ttfont.go @@ -12,7 +12,7 @@ // # Module Initialization // init() // -// # pdfFontHandler Interface (ob *pdfTTFont) +// # pdfFontHandler Interface (f *pdfTTFont) // readFont(owner *PDF, font interface{}) bool // textWidthPt(s string) float64 // writeText(s string) @@ -80,12 +80,12 @@ func init() { } // init // ----------------------------------------------------------------------------- -// # pdfFontHandler Interface (ob *pdfTTFont) +// # pdfFontHandler Interface (f *pdfTTFont) // readFont loads a font from a file name, slice of bytes, or io.Reader -func (ob *pdfTTFont) readFont(owner *PDF, font interface{}) bool { - ob.Err = nil - ob.pdf = owner +func (f *pdfTTFont) readFont(owner *PDF, font interface{}) bool { + f.Err = nil + f.pdf = owner var ( src string rd io.Reader @@ -96,7 +96,7 @@ func (ob *pdfTTFont) readFont(owner *PDF, font interface{}) bool { src = arg data, err := os.ReadFile(arg) if err != nil { - ob.pdf.putError(0xE5445B, "Failed reading font file", src) + f.pdf.putError(0xE5445B, "Failed reading font file", src) return false } rd = bytes.NewReader(data) @@ -112,17 +112,17 @@ func (ob *pdfTTFont) readFont(owner *PDF, font interface{}) bool { rd = arg } default: - ob.pdf.putError(0xECEB7B, "Invalid type in arg", + f.pdf.putError(0xECEB7B, "Invalid type in arg", reflect.TypeOf(font).String()) return false } _ = rd // TODO: remove when reader is used - return ob.Err == nil + return f.Err == nil } // readFont // textWidthPt returns the width of text 's' in points -func (ob *pdfTTFont) textWidthPt(s string) float64 { - ob.Err = nil +func (f *pdfTTFont) textWidthPt(s string) float64 { + f.Err = nil var ret float64 for _, r := range s { _ = r @@ -131,24 +131,24 @@ func (ob *pdfTTFont) textWidthPt(s string) float64 { // TODO: 0xE0074A: error continue } - w := float64(ob.HMTX.Widths[glyph]) - if ob.HEAD.UnitsPerEm != 1000 { - w = w * 1000.0 / float64(ob.HEAD.UnitsPerEm) + w := float64(f.HMTX.Widths[glyph]) + if f.HEAD.UnitsPerEm != 1000 { + w = w * 1000.0 / float64(f.HEAD.UnitsPerEm) } - ret += w / 1000.0 * ob.pdf.fontSizePt + ret += w / 1000.0 * f.pdf.fontSizePt } return ret } // textWidthPt // writeText encodes text in the string 's' -func (ob *pdfTTFont) writeText(s string) { - ob.Err = nil - ob.pdf.write("BT ", ob.pdf.page.x, " ", ob.pdf.page.y, " Td ") +func (f *pdfTTFont) writeText(s string) { + f.Err = nil + f.pdf.write("BT ", f.pdf.page.x, " ", f.pdf.page.y, " Td ") // // TODO: add each rune of s, to determine glyphs to embed // // write hex encoded text to PDF - ob.pdf.write("[<") + f.pdf.write("[<") for _, r := range s { _ = r glyph, found := 0, false // TODO: find out glyph entry @@ -156,44 +156,44 @@ func (ob *pdfTTFont) writeText(s string) { // TODO: 0xE1DC96: error return } - ob.pdf.write(fmt.Sprintf("%04X", glyph)) + f.pdf.write(fmt.Sprintf("%04X", glyph)) } - ob.pdf.write(">] TJ ET\n") + f.pdf.write(">] TJ ET\n") } // writeText // writeFontObjects writes the PDF objects that define the embedded font -func (ob *pdfTTFont) writeFontObjects(font *pdfFont) { - ob.Err = nil +func (f *pdfTTFont) writeFontObjects(font *pdfFont) { + f.Err = nil // TODO: write font-related objects here (call writer methods) - if ob.Err != nil { - ob.pdf.putError(0xED2CDF, ob.Err.Error(), "") + if f.Err != nil { + f.pdf.putError(0xED2CDF, f.Err.Error(), "") } } // writeFontObjects // ----------------------------------------------------------------------------- -// # TTF Parsing Methods (ob *pdfTTFont) +// # TTF Parsing Methods (f *pdfTTFont) // readTTF __ -func (ob *pdfTTFont) readTTF(reader io.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readTTF(reader io.Reader) { + if f.Err != nil { return } var err error - ob.Data, err = io.ReadAll(reader) + f.Data, err = io.ReadAll(reader) if err != nil { - ob.Err = err + f.Err = err return } - rd := bytes.NewReader(ob.Data) - ver := ob.read(rd, 4) + rd := bytes.NewReader(f.Data) + ver := f.read(rd, 4) if !bytes.Equal(ver, []byte{0, 1, 0, 0}) { // TODO: 0xE0E9AE: error return } for _, fn := range []func(*bytes.Reader){ - ob.readHEAD, ob.readHHEA, ob.readMAXP, ob.readHMTX, ob.readCMAP, - ob.readNAME, ob.readOS2, ob.readPOST, ob.readLOCA} { - if ob.Err != nil { + f.readHEAD, f.readHHEA, f.readMAXP, f.readHMTX, f.readCMAP, + f.readNAME, f.readOS2, f.readPOST, f.readLOCA} { + if f.Err != nil { /// 0xE2257E: log error break } @@ -202,93 +202,93 @@ func (ob *pdfTTFont) readTTF(reader io.Reader) { } // readTTF // readHEAD __ -func (ob *pdfTTFont) readHEAD(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readHEAD(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readHEAD // readHHEA __ -func (ob *pdfTTFont) readHHEA(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readHHEA(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readHHEA // readMAXP __ -func (ob *pdfTTFont) readMAXP(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readMAXP(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readMAXP // readHMTX __ -func (ob *pdfTTFont) readHMTX(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readHMTX(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readHMTX // readCMAP __ -func (ob *pdfTTFont) readCMAP(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readCMAP(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readCMAP // readNAME __ -func (ob *pdfTTFont) readNAME(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readNAME(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readNAME // readOS2 __ -func (ob *pdfTTFont) readOS2(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readOS2(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readOS2 // readPOST __ -func (ob *pdfTTFont) readPOST(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readPOST(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readPOST // readLOCA __ -func (ob *pdfTTFont) readLOCA(rd *bytes.Reader) { - if ob.Err != nil { +func (f *pdfTTFont) readLOCA(rd *bytes.Reader) { + if f.Err != nil { return } // TODO: implement } // readLOCA // read __ -func (ob *pdfTTFont) read(rd *bytes.Reader, size int, useData ...bool) []byte { - if ob.Err != nil { +func (f *pdfTTFont) read(rd *bytes.Reader, size int, useData ...bool) []byte { + if f.Err != nil { return nil } if len(useData) > 0 && useData[0] == false { _, err := rd.Seek(int64(size), 1) if err != nil { - ob.Err = err + f.Err = err } return nil } ret := make([]byte, size) n, err := rd.Read(ret) if err != nil { - ob.Err = err + f.Err = err return nil } if n != size { @@ -299,9 +299,9 @@ func (ob *pdfTTFont) read(rd *bytes.Reader, size int, useData ...bool) []byte { } // read // readI16 __ -func (ob *pdfTTFont) readI16(rd *bytes.Reader) int16 { - ar := ob.read(rd, 2) - if ob.Err != nil { +func (f *pdfTTFont) readI16(rd *bytes.Reader) int16 { + ar := f.read(rd, 2) + if f.Err != nil { return 0 } ret := int(uint16(ar[0])<<8 | uint16(ar[1])) @@ -312,18 +312,18 @@ func (ob *pdfTTFont) readI16(rd *bytes.Reader) int16 { } // readI16 // readUI16 __ -func (ob *pdfTTFont) readUI16(rd *bytes.Reader) uint16 { - ar := ob.read(rd, 2) - if ob.Err != nil { +func (f *pdfTTFont) readUI16(rd *bytes.Reader) uint16 { + ar := f.read(rd, 2) + if f.Err != nil { return 0 } return uint16(ar[0])<<8 | uint16(ar[1]) } // readUI16 // readUI32 __ -func (ob *pdfTTFont) readUI32(rd *bytes.Reader) uint32 { - ar := ob.read(rd, 4) - if ob.Err != nil { +func (f *pdfTTFont) readUI32(rd *bytes.Reader) uint32 { + ar := f.read(rd, 4) + if f.Err != nil { return 0 } return uint32(ar[0])<<24 | uint32(ar[1])<<16 |