repo
stringlengths
5
67
sha
stringlengths
40
40
path
stringlengths
4
234
url
stringlengths
85
339
language
stringclasses
6 values
split
stringclasses
3 values
doc
stringlengths
3
51.2k
sign
stringlengths
5
8.01k
problem
stringlengths
13
51.2k
output
stringlengths
0
3.87M
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2737-L2739
go
train
// GetImageInfo returns information about the registered image specified by // imageStr. If the image has not been registered, nil is returned. The // internal error is not modified by this method.
func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType)
// GetImageInfo returns information about the registered image specified by // imageStr. If the image has not been registered, nil is returned. The // internal error is not modified by this method. func (f *Fpdf) GetImageInfo(imageStr string) (info *ImageInfoType)
{ return f.images[imageStr] }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2768-L2774
go
train
// SetX defines the abscissa of the current position. If the passed value is // negative, it is relative to the right of the page.
func (f *Fpdf) SetX(x float64)
// SetX defines the abscissa of the current position. If the passed value is // negative, it is relative to the right of the page. func (f *Fpdf) SetX(x float64)
{ if x >= 0 { f.x = x } else { f.x = f.w + x } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2784-L2792
go
train
// SetY moves the current abscissa back to the left margin and sets the // ordinate. If the passed value is negative, it is relative to the bottom of // the page.
func (f *Fpdf) SetY(y float64)
// SetY moves the current abscissa back to the left margin and sets the // ordinate. If the passed value is negative, it is relative to the bottom of // the page. func (f *Fpdf) SetY(y float64)
{ // dbg("SetY x %.2f, lMargin %.2f", f.x, f.lMargin) f.x = f.lMargin if y >= 0 { f.y = y } else { f.y = f.h + y } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2796-L2799
go
train
// SetHomeXY is a convenience method that sets the current position to the left // and top margins.
func (f *Fpdf) SetHomeXY()
// SetHomeXY is a convenience method that sets the current position to the left // and top margins. func (f *Fpdf) SetHomeXY()
{ f.SetY(f.tMargin) f.SetX(f.lMargin) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2804-L2807
go
train
// SetXY defines the abscissa and ordinate of the current position. If the // passed values are negative, they are relative respectively to the right and // bottom of the page.
func (f *Fpdf) SetXY(x, y float64)
// SetXY defines the abscissa and ordinate of the current position. If the // passed values are negative, they are relative respectively to the right and // bottom of the page. func (f *Fpdf) SetXY(x, y float64)
{ f.SetY(y) f.SetX(x) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2827-L2832
go
train
// SetProtection applies certain constraints on the finished PDF document. // // actionFlag is a bitflag that controls various document operations. // CnProtectPrint allows the document to be printed. CnProtectModify allows a // document to be modified by a PDF editor. CnProtectCopy allows text and // images to be copied into the system clipboard. CnProtectAnnotForms allows // annotations and forms to be added by a PDF editor. These values can be // combined by or-ing them together, for example, // CnProtectCopy|CnProtectModify. This flag is advisory; not all PDF readers // implement the constraints that this argument attempts to control. // // userPassStr specifies the password that will need to be provided to view the // contents of the PDF. The permissions specified by actionFlag will apply. // // ownerPassStr specifies the password that will need to be provided to gain // full access to the document regardless of the actionFlag value. An empty // string for this argument will be replaced with a random value, effectively // prohibiting full access to the document.
func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string)
// SetProtection applies certain constraints on the finished PDF document. // // actionFlag is a bitflag that controls various document operations. // CnProtectPrint allows the document to be printed. CnProtectModify allows a // document to be modified by a PDF editor. CnProtectCopy allows text and // images to be copied into the system clipboard. CnProtectAnnotForms allows // annotations and forms to be added by a PDF editor. These values can be // combined by or-ing them together, for example, // CnProtectCopy|CnProtectModify. This flag is advisory; not all PDF readers // implement the constraints that this argument attempts to control. // // userPassStr specifies the password that will need to be provided to view the // contents of the PDF. The permissions specified by actionFlag will apply. // // ownerPassStr specifies the password that will need to be provided to gain // full access to the document regardless of the actionFlag value. An empty // string for this argument will be replaced with a random value, effectively // prohibiting full access to the document. func (f *Fpdf) SetProtection(actionFlag byte, userPassStr, ownerPassStr string)
{ if f.err != nil { return } f.protect.setProtection(actionFlag, userPassStr, ownerPassStr) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2837-L2841
go
train
// OutputAndClose sends the PDF document to the writer specified by w. This // method will close both f and w, even if an error is detected and no document // is produced.
func (f *Fpdf) OutputAndClose(w io.WriteCloser) error
// OutputAndClose sends the PDF document to the writer specified by w. This // method will close both f and w, even if an error is detected and no document // is produced. func (f *Fpdf) OutputAndClose(w io.WriteCloser) error
{ f.Output(w) w.Close() return f.err }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2848-L2859
go
train
// OutputFileAndClose creates or truncates the file specified by fileStr and // writes the PDF document to it. This method will close f and the newly // written file, even if an error is detected and no document is produced. // // Most examples demonstrate the use of this method.
func (f *Fpdf) OutputFileAndClose(fileStr string) error
// OutputFileAndClose creates or truncates the file specified by fileStr and // writes the PDF document to it. This method will close f and the newly // written file, even if an error is detected and no document is produced. // // Most examples demonstrate the use of this method. func (f *Fpdf) OutputFileAndClose(fileStr string) error
{ if f.err == nil { pdfFile, err := os.Create(fileStr) if err == nil { f.Output(pdfFile) pdfFile.Close() } else { f.err = err } } return f.err }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2865-L2878
go
train
// Output sends the PDF document to the writer specified by w. No output will // take place if an error has occurred in the document generation process. w // remains open after this function returns. After returning, f is in a closed // state and its methods should not be called.
func (f *Fpdf) Output(w io.Writer) error
// Output sends the PDF document to the writer specified by w. No output will // take place if an error has occurred in the document generation process. w // remains open after this function returns. After returning, f is in a closed // state and its methods should not be called. func (f *Fpdf) Output(w io.Writer) error
{ if f.err != nil { return f.err } // dbg("Output") if f.state < 3 { f.Close() } _, err := f.buffer.WriteTo(w) if err != nil { f.err = err } return f.err }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2900-L2902
go
train
// GetPageSizeStr returns the SizeType for the given sizeStr (that is A4, A3, etc..)
func (f *Fpdf) GetPageSizeStr(sizeStr string) (size SizeType)
// GetPageSizeStr returns the SizeType for the given sizeStr (that is A4, A3, etc..) func (f *Fpdf) GetPageSizeStr(sizeStr string) (size SizeType)
{ return f.getpagesizestr(sizeStr) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2960-L2982
go
train
// Load a font definition file from the given Reader
func (f *Fpdf) loadfont(r io.Reader) (def fontDefType)
// Load a font definition file from the given Reader func (f *Fpdf) loadfont(r io.Reader) (def fontDefType)
{ if f.err != nil { return } // dbg("Loading font [%s]", fontStr) var buf bytes.Buffer _, err := buf.ReadFrom(r) if err != nil { f.err = err return } err = json.Unmarshal(buf.Bytes(), &def) if err != nil { f.err = err return } if def.i, err = generateFontID(def); err != nil { f.err = err } // dump(def) return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2985-L2991
go
train
// Escape special characters in strings
func (f *Fpdf) escape(s string) string
// Escape special characters in strings func (f *Fpdf) escape(s string) string
{ s = strings.Replace(s, "\\", "\\\\", -1) s = strings.Replace(s, "(", "\\(", -1) s = strings.Replace(s, ")", "\\)", -1) s = strings.Replace(s, "\r", "\\r", -1) return s }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L2994-L3001
go
train
// textstring formats a text string
func (f *Fpdf) textstring(s string) string
// textstring formats a text string func (f *Fpdf) textstring(s string) string
{ if f.protect.encrypted { b := []byte(s) f.protect.rc4(uint32(f.n), &b) s = string(b) } return "(" + f.escape(s) + ")" }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3014-L3020
go
train
// Underline text
func (f *Fpdf) dounderline(x, y float64, txt string) string
// Underline text func (f *Fpdf) dounderline(x, y float64, txt string) string
{ up := float64(f.currentFont.Up) ut := float64(f.currentFont.Ut) w := f.GetStringWidth(txt) + f.ws*float64(blankCount(txt)) return sprintf("%.2f %.2f %.2f %.2f re f", x*f.k, (f.h-(y-up/1000*f.fontSize))*f.k, w*f.k, -ut/1000*f.fontSizePt) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3037-L3071
go
train
// parsejpg extracts info from io.Reader with JPEG data // Thank you, Bruno Michel, for providing this code.
func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType)
// parsejpg extracts info from io.Reader with JPEG data // Thank you, Bruno Michel, for providing this code. func (f *Fpdf) parsejpg(r io.Reader) (info *ImageInfoType)
{ info = f.newImageInfo() var ( data bytes.Buffer err error ) _, err = data.ReadFrom(r) if err != nil { f.err = err return } info.data = data.Bytes() config, err := jpeg.DecodeConfig(bytes.NewReader(info.data)) if err != nil { f.err = err return } info.w = float64(config.Width) info.h = float64(config.Height) info.f = "DCTDecode" info.bpc = 8 switch config.ColorModel { case color.GrayModel: info.cs = "DeviceGray" case color.YCbCrModel: info.cs = "DeviceRGB" case color.CMYKModel: info.cs = "DeviceCMYK" default: f.err = fmt.Errorf("image JPEG buffer has unsupported color space (%v)", config.ColorModel) return } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3074-L3081
go
train
// parsepng extracts info from a PNG data
func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType)
// parsepng extracts info from a PNG data func (f *Fpdf) parsepng(r io.Reader, readdpi bool) (info *ImageInfoType)
{ buf, err := bufferFromReader(r) if err != nil { f.err = err return } return f.parsepngstream(buf, readdpi) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3100-L3119
go
train
// parsegif extracts info from a GIF data (via PNG conversion)
func (f *Fpdf) parsegif(r io.Reader) (info *ImageInfoType)
// parsegif extracts info from a GIF data (via PNG conversion) func (f *Fpdf) parsegif(r io.Reader) (info *ImageInfoType)
{ data, err := bufferFromReader(r) if err != nil { f.err = err return } var img image.Image img, err = gif.Decode(data) if err != nil { f.err = err return } pngBuf := new(bytes.Buffer) err = png.Encode(pngBuf, img) if err != nil { f.err = err return } return f.parsepngstream(pngBuf, false) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3122-L3130
go
train
// newobj begins a new object
func (f *Fpdf) newobj()
// newobj begins a new object func (f *Fpdf) newobj()
{ // dbg("newobj") f.n++ for j := len(f.offsets); j <= f.n; j++ { f.offsets = append(f.offsets, 0) } f.offsets[f.n] = f.buffer.Len() f.outf("%d 0 obj", f.n) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3143-L3151
go
train
// out; Add a line to the document
func (f *Fpdf) out(s string)
// out; Add a line to the document func (f *Fpdf) out(s string)
{ if f.state == 2 { f.pages[f.page].WriteString(s) f.pages[f.page].WriteString("\n") } else { f.buffer.WriteString(s) f.buffer.WriteString("\n") } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3154-L3162
go
train
// outbuf adds a buffered line to the document
func (f *Fpdf) outbuf(r io.Reader)
// outbuf adds a buffered line to the document func (f *Fpdf) outbuf(r io.Reader)
{ if f.state == 2 { f.pages[f.page].ReadFrom(r) f.pages[f.page].WriteString("\n") } else { f.buffer.ReadFrom(r) f.buffer.WriteString("\n") } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3181-L3183
go
train
// outf adds a formatted line to the document
func (f *Fpdf) outf(fmtStr string, args ...interface{})
// outf adds a formatted line to the document func (f *Fpdf) outf(fmtStr string, args ...interface{})
{ f.out(sprintf(fmtStr, args...)) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3222-L3224
go
train
// RegisterAlias adds an (alias, replacement) pair to the document so we can // replace all occurrences of that alias after writing but before the // document is closed.
func (f *Fpdf) RegisterAlias(alias, replacement string)
// RegisterAlias adds an (alias, replacement) pair to the document so we can // replace all occurrences of that alias after writing but before the // document is closed. func (f *Fpdf) RegisterAlias(alias, replacement string)
{ f.aliasMap[alias] = replacement }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3944-L3947
go
train
// Path Drawing // MoveTo moves the stylus to (x, y) without drawing the path from the // previous point. Paths must start with a MoveTo to set the original // stylus location or the result is undefined. // // Create a "path" by moving a virtual stylus around the page (with // MoveTo, LineTo, CurveTo, CurveBezierCubicTo, ArcTo & ClosePath) // then draw it or fill it in (with DrawPath). The main advantage of // using the path drawing routines rather than multiple Fpdf.Line is // that PDF creates nice line joins at the angles, rather than just // overlaying the lines.
func (f *Fpdf) MoveTo(x, y float64)
// Path Drawing // MoveTo moves the stylus to (x, y) without drawing the path from the // previous point. Paths must start with a MoveTo to set the original // stylus location or the result is undefined. // // Create a "path" by moving a virtual stylus around the page (with // MoveTo, LineTo, CurveTo, CurveBezierCubicTo, ArcTo & ClosePath) // then draw it or fill it in (with DrawPath). The main advantage of // using the path drawing routines rather than multiple Fpdf.Line is // that PDF creates nice line joins at the angles, rather than just // overlaying the lines. func (f *Fpdf) MoveTo(x, y float64)
{ f.point(x, y) f.x, f.y = x, y }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3954-L3957
go
train
// LineTo creates a line from the current stylus location to (x, y), which // becomes the new stylus location. Note that this only creates the line in // the path; it does not actually draw the line on the page. // // The MoveTo() example demonstrates this method.
func (f *Fpdf) LineTo(x, y float64)
// LineTo creates a line from the current stylus location to (x, y), which // becomes the new stylus location. Note that this only creates the line in // the path; it does not actually draw the line on the page. // // The MoveTo() example demonstrates this method. func (f *Fpdf) LineTo(x, y float64)
{ f.outf("%.2f %.2f l", x*f.k, (f.h-y)*f.k) f.x, f.y = x, y }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3967-L3970
go
train
// CurveTo creates a single-segment quadratic Bézier curve. The curve starts at // the current stylus location and ends at the point (x, y). The control point // (cx, cy) specifies the curvature. At the start point, the curve is tangent // to the straight line between the current stylus location and the control // point. At the end point, the curve is tangent to the straight line between // the end point and the control point. // // The MoveTo() example demonstrates this method.
func (f *Fpdf) CurveTo(cx, cy, x, y float64)
// CurveTo creates a single-segment quadratic Bézier curve. The curve starts at // the current stylus location and ends at the point (x, y). The control point // (cx, cy) specifies the curvature. At the start point, the curve is tangent // to the straight line between the current stylus location and the control // point. At the end point, the curve is tangent to the straight line between // the end point and the control point. // // The MoveTo() example demonstrates this method. func (f *Fpdf) CurveTo(cx, cy, x, y float64)
{ f.outf("%.5f %.5f %.5f %.5f v", cx*f.k, (f.h-cy)*f.k, x*f.k, (f.h-y)*f.k) f.x, f.y = x, y }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L3981-L3984
go
train
// CurveBezierCubicTo creates a single-segment cubic Bézier curve. The curve // starts at the current stylus location and ends at the point (x, y). The // control points (cx0, cy0) and (cx1, cy1) specify the curvature. At the // current stylus, the curve is tangent to the straight line between the // current stylus location and the control point (cx0, cy0). At the end point, // the curve is tangent to the straight line between the end point and the // control point (cx1, cy1). // // The MoveTo() example demonstrates this method.
func (f *Fpdf) CurveBezierCubicTo(cx0, cy0, cx1, cy1, x, y float64)
// CurveBezierCubicTo creates a single-segment cubic Bézier curve. The curve // starts at the current stylus location and ends at the point (x, y). The // control points (cx0, cy0) and (cx1, cy1) specify the curvature. At the // current stylus, the curve is tangent to the straight line between the // current stylus location and the control point (cx0, cy0). At the end point, // the curve is tangent to the straight line between the end point and the // control point (cx1, cy1). // // The MoveTo() example demonstrates this method. func (f *Fpdf) CurveBezierCubicTo(cx0, cy0, cx1, cy1, x, y float64)
{ f.curve(cx0, cy0, cx1, cy1, x, y) f.x, f.y = x, y }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
fpdf.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/fpdf.go#L4032-L4034
go
train
// ArcTo draws an elliptical arc centered at point (x, y). rx and ry specify its // horizontal and vertical radii. If the start of the arc is not at // the current position, a connecting line will be drawn. // // degRotate specifies the angle that the arc will be rotated. degStart and // degEnd specify the starting and ending angle of the arc. All angles are // specified in degrees and measured counter-clockwise from the 3 o'clock // position. // // styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for // outlined and filled. An empty string will be replaced with "D". Drawing uses // the current draw color, line width, and cap style centered on the arc's // path. Filling uses the current fill color. // // The MoveTo() example demonstrates this method.
func (f *Fpdf) ArcTo(x, y, rx, ry, degRotate, degStart, degEnd float64)
// ArcTo draws an elliptical arc centered at point (x, y). rx and ry specify its // horizontal and vertical radii. If the start of the arc is not at // the current position, a connecting line will be drawn. // // degRotate specifies the angle that the arc will be rotated. degStart and // degEnd specify the starting and ending angle of the arc. All angles are // specified in degrees and measured counter-clockwise from the 3 o'clock // position. // // styleStr can be "F" for filled, "D" for outlined only, or "DF" or "FD" for // outlined and filled. An empty string will be replaced with "D". Drawing uses // the current draw color, line width, and cap style centered on the arc's // path. Filling uses the current fill color. // // The MoveTo() example demonstrates this method. func (f *Fpdf) ArcTo(x, y, rx, ry, degRotate, degStart, degEnd float64)
{ f.arc(x, y, rx, ry, degRotate, degStart, degEnd, "", true) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
subwrite.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/subwrite.go#L15-L35
go
train
// Adapted from http://www.fpdf.org/en/script/script61.php by Wirus and released with the FPDF license. // SubWrite prints text from the current position in the same way as Write(). // ht is the line height in the unit of measure specified in New(). str // specifies the text to write. subFontSize is the size of the font in points. // subOffset is the vertical offset of the text in points; a positive value // indicates a superscript, a negative value indicates a subscript. link is the // identifier returned by AddLink() or 0 for no internal link. linkStr is a // target URL or empty for no external link. A non--zero value for link takes // precedence over linkStr. // // The SubWrite example demonstrates this method.
func (f *Fpdf) SubWrite(ht float64, str string, subFontSize, subOffset float64, link int, linkStr string)
// Adapted from http://www.fpdf.org/en/script/script61.php by Wirus and released with the FPDF license. // SubWrite prints text from the current position in the same way as Write(). // ht is the line height in the unit of measure specified in New(). str // specifies the text to write. subFontSize is the size of the font in points. // subOffset is the vertical offset of the text in points; a positive value // indicates a superscript, a negative value indicates a subscript. link is the // identifier returned by AddLink() or 0 for no internal link. linkStr is a // target URL or empty for no external link. A non--zero value for link takes // precedence over linkStr. // // The SubWrite example demonstrates this method. func (f *Fpdf) SubWrite(ht float64, str string, subFontSize, subOffset float64, link int, linkStr string)
{ if f.err != nil { return } // resize font subFontSizeOld := f.fontSizePt f.SetFontSize(subFontSize) // reposition y subOffset = (((subFontSize - subFontSizeOld) / f.k) * 0.3) + (subOffset / f.k) subX := f.x subY := f.y f.SetXY(subX, subY-subOffset) //Output text f.write(ht, str, link, linkStr) // restore y position subX = f.x subY = f.y f.SetXY(subX, subY+subOffset) // restore font size f.SetFontSize(subFontSizeOld) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
svgwrite.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/svgwrite.go#L26-L60
go
train
// SVGBasicWrite renders the paths encoded in the basic SVG image specified by // sb. The scale value is used to convert the coordinates in the path to the // unit of measure specified in New(). The current position (as set with a call // to SetXY()) is used as the origin of the image. The current line cap style // (as set with SetLineCapStyle()), line width (as set with SetLineWidth()), // and draw color (as set with SetDrawColor()) are used in drawing the image // paths.
func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64)
// SVGBasicWrite renders the paths encoded in the basic SVG image specified by // sb. The scale value is used to convert the coordinates in the path to the // unit of measure specified in New(). The current position (as set with a call // to SetXY()) is used as the origin of the image. The current line cap style // (as set with SetLineCapStyle()), line width (as set with SetLineWidth()), // and draw color (as set with SetDrawColor()) are used in drawing the image // paths. func (f *Fpdf) SVGBasicWrite(sb *SVGBasicType, scale float64)
{ originX, originY := f.GetXY() var x, y, newX, newY float64 var cx0, cy0, cx1, cy1 float64 var path []SVGBasicSegmentType var seg SVGBasicSegmentType val := func(arg int) (float64, float64) { return originX + scale*seg.Arg[arg], originY + scale*seg.Arg[arg+1] } for j := 0; j < len(sb.Segments) && f.Ok(); j++ { path = sb.Segments[j] for k := 0; k < len(path) && f.Ok(); k++ { seg = path[k] switch seg.Cmd { case 'M': x, y = val(0) f.SetXY(x, y) case 'L': newX, newY = val(0) f.Line(x, y, newX, newY) x, y = newX, newY case 'C': cx0, cy0 = val(0) cx1, cy1 = val(2) newX, newY = val(4) f.CurveCubic(x, y, cx0, cy0, newX, newY, cx1, cy1, "D") x, y = newX, newY case 'Z': f.Line(x, y, originX, originY) default: f.SetErrorf("Unexpected path command '%c'", seg.Cmd) } } } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L43-L51
go
train
// fileExist returns true if the specified normal file exists
func fileExist(filename string) (ok bool)
// fileExist returns true if the specified normal file exists func fileExist(filename string) (ok bool)
{ info, err := os.Stat(filename) if err == nil { if ^os.ModePerm&info.Mode() == 0 { ok = true } } return ok }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L55-L62
go
train
// fileSize returns the size of the specified file; ok will be false // if the file does not exist or is not an ordinary file
func fileSize(filename string) (size int64, ok bool)
// fileSize returns the size of the specified file; ok will be false // if the file does not exist or is not an ordinary file func fileSize(filename string) (size int64, ok bool)
{ info, err := os.Stat(filename) ok = err == nil if ok { size = info.Size() } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L65-L69
go
train
// bufferFromReader returns a new buffer populated with the contents of the specified Reader
func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error)
// bufferFromReader returns a new buffer populated with the contents of the specified Reader func bufferFromReader(r io.Reader) (b *bytes.Buffer, err error)
{ b = new(bytes.Buffer) _, err = b.ReadFrom(r) return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L72-L82
go
train
// slicesEqual returns true if the two specified float slices are equal
func slicesEqual(a, b []float64) bool
// slicesEqual returns true if the two specified float slices are equal func slicesEqual(a, b []float64) bool
{ if len(a) != len(b) { return false } for i := range a { if a[i] != b[i] { return false } } return true }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L85-L91
go
train
// sliceCompress returns a zlib-compressed copy of the specified byte array
func sliceCompress(data []byte) []byte
// sliceCompress returns a zlib-compressed copy of the specified byte array func sliceCompress(data []byte) []byte
{ var buf bytes.Buffer cmp, _ := zlib.NewWriterLevel(&buf, zlib.BestSpeed) cmp.Write(data) cmp.Close() return buf.Bytes() }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L94-L106
go
train
// sliceUncompress returns an uncompressed copy of the specified zlib-compressed byte array
func sliceUncompress(data []byte) (outData []byte, err error)
// sliceUncompress returns an uncompressed copy of the specified zlib-compressed byte array func sliceUncompress(data []byte) (outData []byte, err error)
{ inBuf := bytes.NewReader(data) r, err := zlib.NewReader(inBuf) defer r.Close() if err == nil { var outBuf bytes.Buffer _, err = outBuf.ReadFrom(r) if err == nil { outData = outBuf.Bytes() } } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L109-L138
go
train
// utf8toutf16 converts UTF-8 to UTF-16BE with BOM; from http://www.fpdf.org/
func utf8toutf16(s string) string
// utf8toutf16 converts UTF-8 to UTF-16BE with BOM; from http://www.fpdf.org/ func utf8toutf16(s string) string
{ res := make([]byte, 0, 8) res = append(res, 0xFE, 0xFF) nb := len(s) i := 0 for i < nb { c1 := byte(s[i]) i++ switch { case c1 >= 224: // 3-byte character c2 := byte(s[i]) i++ c3 := byte(s[i]) i++ res = append(res, ((c1&0x0F)<<4)+((c2&0x3C)>>2), ((c2&0x03)<<6)+(c3&0x3F)) case c1 >= 192: // 2-byte character c2 := byte(s[i]) i++ res = append(res, ((c1 & 0x1C) >> 2), ((c1&0x03)<<6)+(c2&0x3F)) default: // Single-byte character res = append(res, 0, c1) } } return string(res) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L141-L146
go
train
// intIf returns a if cnd is true, otherwise b
func intIf(cnd bool, a, b int) int
// intIf returns a if cnd is true, otherwise b func intIf(cnd bool, a, b int) int
{ if cnd { return a } return b }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L149-L154
go
train
// strIf returns aStr if cnd is true, otherwise bStr
func strIf(cnd bool, aStr, bStr string) string
// strIf returns aStr if cnd is true, otherwise bStr func strIf(cnd bool, aStr, bStr string) string
{ if cnd { return aStr } return bStr }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L171-L190
go
train
// Dump the internals of the specified values // func dump(fileStr string, a ...interface{}) { // fl, err := os.OpenFile(fileStr, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) // if err == nil { // fmt.Fprintf(fl, "----------------\n") // spew.Fdump(fl, a...) // fl.Close() // } // }
func repClosure(m map[rune]byte) func(string) string
// Dump the internals of the specified values // func dump(fileStr string, a ...interface{}) { // fl, err := os.OpenFile(fileStr, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) // if err == nil { // fmt.Fprintf(fl, "----------------\n") // spew.Fdump(fl, a...) // fl.Close() // } // } func repClosure(m map[rune]byte) func(string) string
{ var buf bytes.Buffer return func(str string) string { var ch byte var ok bool buf.Truncate(0) for _, r := range str { if r < 0x80 { ch = byte(r) } else { ch, ok = m[r] if !ok { ch = byte('.') } } buf.WriteByte(ch) } return buf.String() } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L207-L230
go
train
// UnicodeTranslator returns a function that can be used to translate, where // possible, utf-8 strings to a form that is compatible with the specified code // page. The returned function accepts a string and returns a string. // // r is a reader that should read a buffer made up of content lines that // pertain to the code page of interest. Each line is made up of three // whitespace separated fields. The first begins with "!" and is followed by // two hexadecimal digits that identify the glyph position in the code page of // interest. The second field begins with "U+" and is followed by the unicode // code point value. The third is the glyph name. A number of these code page // map files are packaged with the gfpdf library in the font directory. // // An error occurs only if a line is read that does not conform to the expected // format. In this case, the returned function is valid but does not perform // any rune translation.
func UnicodeTranslator(r io.Reader) (f func(string) string, err error)
// UnicodeTranslator returns a function that can be used to translate, where // possible, utf-8 strings to a form that is compatible with the specified code // page. The returned function accepts a string and returns a string. // // r is a reader that should read a buffer made up of content lines that // pertain to the code page of interest. Each line is made up of three // whitespace separated fields. The first begins with "!" and is followed by // two hexadecimal digits that identify the glyph position in the code page of // interest. The second field begins with "U+" and is followed by the unicode // code point value. The third is the glyph name. A number of these code page // map files are packaged with the gfpdf library in the font directory. // // An error occurs only if a line is read that does not conform to the expected // format. In this case, the returned function is valid but does not perform // any rune translation. func UnicodeTranslator(r io.Reader) (f func(string) string, err error)
{ m := make(map[rune]byte) var uPos, cPos uint32 var lineStr, nameStr string sc := bufio.NewScanner(r) for sc.Scan() { lineStr = sc.Text() lineStr = strings.TrimSpace(lineStr) if len(lineStr) > 0 { _, err = fmt.Sscanf(lineStr, "!%2X U+%4X %s", &cPos, &uPos, &nameStr) if err == nil { if cPos >= 0x80 { m[rune(uPos)] = byte(cPos) } } } } if err == nil { f = repClosure(m) } else { f = doNothing } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L240-L250
go
train
// UnicodeTranslatorFromFile returns a function that can be used to translate, // where possible, utf-8 strings to a form that is compatible with the // specified code page. See UnicodeTranslator for more details. // // fileStr identifies a font descriptor file that maps glyph positions to names. // // If an error occurs reading the file, the returned function is valid but does // not perform any rune translation.
func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error)
// UnicodeTranslatorFromFile returns a function that can be used to translate, // where possible, utf-8 strings to a form that is compatible with the // specified code page. See UnicodeTranslator for more details. // // fileStr identifies a font descriptor file that maps glyph positions to names. // // If an error occurs reading the file, the returned function is valid but does // not perform any rune translation. func UnicodeTranslatorFromFile(fileStr string) (f func(string) string, err error)
{ var fl *os.File fl, err = os.Open(fileStr) if err == nil { f, err = UnicodeTranslator(fl) fl.Close() } else { f = doNothing } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L265-L282
go
train
// UnicodeTranslatorFromDescriptor returns a function that can be used to // translate, where possible, utf-8 strings to a form that is compatible with // the specified code page. See UnicodeTranslator for more details. // // cpStr identifies a code page. A descriptor file in the font directory, set // with the fontDirStr argument in the call to New(), should have this name // plus the extension ".map". If cpStr is empty, it will be replaced with // "cp1252", the gofpdf code page default. // // If an error occurs reading the descriptor, the returned function is valid // but does not perform any rune translation. // // The CellFormat_codepage example demonstrates this method.
func (f *Fpdf) UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) string)
// UnicodeTranslatorFromDescriptor returns a function that can be used to // translate, where possible, utf-8 strings to a form that is compatible with // the specified code page. See UnicodeTranslator for more details. // // cpStr identifies a code page. A descriptor file in the font directory, set // with the fontDirStr argument in the call to New(), should have this name // plus the extension ".map". If cpStr is empty, it will be replaced with // "cp1252", the gofpdf code page default. // // If an error occurs reading the descriptor, the returned function is valid // but does not perform any rune translation. // // The CellFormat_codepage example demonstrates this method. func (f *Fpdf) UnicodeTranslatorFromDescriptor(cpStr string) (rep func(string) string)
{ var str string var ok bool if f.err == nil { if len(cpStr) == 0 { cpStr = "cp1252" } str, ok = embeddedMapList[cpStr] if ok { rep, f.err = UnicodeTranslator(strings.NewReader(str)) } else { rep, f.err = UnicodeTranslatorFromFile(filepath.Join(f.fontpath, cpStr) + ".map") } } else { rep = doNothing } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L285-L287
go
train
// Transform moves a point by given X, Y offset
func (p *PointType) Transform(x, y float64) PointType
// Transform moves a point by given X, Y offset func (p *PointType) Transform(x, y float64) PointType
{ return PointType{p.X + x, p.Y + y} }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L291-L299
go
train
// Orientation returns the orientation of a given size: // "P" for portrait, "L" for landscape
func (s *SizeType) Orientation() string
// Orientation returns the orientation of a given size: // "P" for portrait, "L" for landscape func (s *SizeType) Orientation() string
{ if s == nil || s.Ht == s.Wd { return "" } if s.Wd > s.Ht { return "L" } return "P" }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L302-L304
go
train
// ScaleBy expands a size by a certain factor
func (s *SizeType) ScaleBy(factor float64) SizeType
// ScaleBy expands a size by a certain factor func (s *SizeType) ScaleBy(factor float64) SizeType
{ return SizeType{s.Wd * factor, s.Ht * factor} }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L307-L310
go
train
// ScaleToWidth adjusts the height of a size to match the given width
func (s *SizeType) ScaleToWidth(width float64) SizeType
// ScaleToWidth adjusts the height of a size to match the given width func (s *SizeType) ScaleToWidth(width float64) SizeType
{ height := s.Ht * width / s.Wd return SizeType{width, height} }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
util.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/util.go#L313-L316
go
train
// ScaleToHeight adjusts the width of a size to match the given height
func (s *SizeType) ScaleToHeight(height float64) SizeType
// ScaleToHeight adjusts the width of a size to match the given height func (s *SizeType) ScaleToHeight(height float64) SizeType
{ width := s.Wd * height / s.Ht return SizeType{width, height} }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L26-L28
go
train
// CreateTemplate defines a new template using the current page size.
func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template
// CreateTemplate defines a new template using the current page size. func (f *Fpdf) CreateTemplate(fn func(*Tpl)) Template
{ return newTpl(PointType{0, 0}, f.curPageSize, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L31-L33
go
train
// CreateTemplateCustom starts a template, using the given bounds.
func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template
// CreateTemplateCustom starts a template, using the given bounds. func (f *Fpdf) CreateTemplateCustom(corner PointType, size SizeType, fn func(*Tpl)) Template
{ return newTpl(corner, size, f.defOrientation, f.unitStr, f.fontDirStr, fn, f) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L42-L49
go
train
// CreateTemplate creates a template that is not attached to any document. // // This function is deprecated; it incorrectly assumes that a page with a width // smaller than its height is oriented in portrait mode, otherwise it assumes // landscape mode. This causes problems when placing the template in a master // document where this condition does not apply. CreateTpl() is a similar // function that lets you specify the orientation to avoid this problem.
func CreateTemplate(corner PointType, size SizeType, unitStr, fontDirStr string, fn func(*Tpl)) Template
// CreateTemplate creates a template that is not attached to any document. // // This function is deprecated; it incorrectly assumes that a page with a width // smaller than its height is oriented in portrait mode, otherwise it assumes // landscape mode. This causes problems when placing the template in a master // document where this condition does not apply. CreateTpl() is a similar // function that lets you specify the orientation to avoid this problem. func CreateTemplate(corner PointType, size SizeType, unitStr, fontDirStr string, fn func(*Tpl)) Template
{ orientationStr := "p" if size.Wd > size.Ht { orientationStr = "l" } return CreateTpl(corner, size, orientationStr, unitStr, fontDirStr, fn) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L52-L54
go
train
// CreateTpl creates a template not attached to any document
func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template
// CreateTpl creates a template not attached to any document func CreateTpl(corner PointType, size SizeType, orientationStr, unitStr, fontDirStr string, fn func(*Tpl)) Template
{ return newTpl(corner, size, orientationStr, unitStr, fontDirStr, fn, nil) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L58-L65
go
train
// UseTemplate adds a template to the current page or another template, // using the size and position at which it was originally written.
func (f *Fpdf) UseTemplate(t Template)
// UseTemplate adds a template to the current page or another template, // using the size and position at which it was originally written. func (f *Fpdf) UseTemplate(t Template)
{ if t == nil { f.SetErrorf("template is nil") return } corner, size := t.Size() f.UseTemplateScaled(t, corner, size) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L69-L101
go
train
// UseTemplateScaled adds a template to the current page or another template, // using the given page coordinates.
func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType)
// UseTemplateScaled adds a template to the current page or another template, // using the given page coordinates. func (f *Fpdf) UseTemplateScaled(t Template, corner PointType, size SizeType)
{ if t == nil { f.SetErrorf("template is nil") return } // You have to add at least a page first if f.page <= 0 { f.SetErrorf("cannot use a template without first adding a page") return } // make a note of the fact that we actually use this template, as well as any other templates, // images or fonts it uses f.templates[t.ID()] = t for _, tt := range t.Templates() { f.templates[tt.ID()] = tt } for name, ti := range t.Images() { name = sprintf("t%s-%s", t.ID(), name) f.images[name] = ti } // template data _, templateSize := t.Size() scaleX := size.Wd / templateSize.Wd scaleY := size.Ht / templateSize.Ht tx := corner.X * f.k ty := (f.curPageSize.Ht - corner.Y - size.Ht) * f.k f.outf("q %.4f 0 0 %.4f %.4f %.4f cm", scaleX, scaleY, tx, ty) // Translate f.outf("/TPL%s Do Q", t.ID()) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L137-L205
go
train
// putTemplates writes the templates to the PDF
func (f *Fpdf) putTemplates()
// putTemplates writes the templates to the PDF func (f *Fpdf) putTemplates()
{ filter := "" if f.compress { filter = "/Filter /FlateDecode " } templates := sortTemplates(f.templates, f.catalogSort) var t Template for _, t = range templates { corner, size := t.Size() f.newobj() f.templateObjects[t.ID()] = f.n 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) 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) } // Template's resource dictionary f.out("/Resources ") f.out("<</ProcSet [/PDF /Text /ImageB /ImageC /ImageI]") f.templateFontCatalog() tImages := t.Images() tTemplates := t.Templates() if len(tImages) > 0 || len(tTemplates) > 0 { f.out("/XObject <<") { var key string var keyList []string var ti *ImageInfoType for key = range tImages { keyList = append(keyList, key) } if gl.catalogSort { sort.Strings(keyList) } for _, key = range keyList { // for _, ti := range tImages { ti = tImages[key] f.outf("/I%s %d 0 R", ti.i, ti.n) } } for _, tt := range tTemplates { id := tt.ID() if objID, ok := f.templateObjects[id]; ok { f.outf("/TPL%s %d 0 R", id, objID) } } f.out(">>") } f.out(">>") // Write the template's byte stream buffer := t.Bytes() // fmt.Println("Put template bytes", string(buffer[:])) if f.compress { buffer = sliceCompress(buffer) } f.outf("/Length %d >>", len(buffer)) f.putstream(buffer) f.out("endobj") } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L225-L256
go
train
// sortTemplates puts templates in a suitable order based on dependices
func sortTemplates(templates map[string]Template, catalogSort bool) []Template
// sortTemplates puts templates in a suitable order based on dependices func sortTemplates(templates map[string]Template, catalogSort bool) []Template
{ chain := make([]Template, 0, len(templates)*2) // build a full set of dependency chains var keyList []string var key string var t Template keyList = templateKeyList(templates, catalogSort) for _, key = range keyList { t = templates[key] tlist := templateChainDependencies(t) for _, tt := range tlist { if tt != nil { chain = append(chain, tt) } } } // reduce that to make a simple list sorted := make([]Template, 0, len(templates)) chain: for _, t := range chain { for _, already := range sorted { if t == already { continue chain } } sorted = append(sorted, t) } return sorted }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
template.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/template.go#L259-L267
go
train
// templateChainDependencies is a recursive function for determining the full chain of template dependencies
func templateChainDependencies(template Template) []Template
// 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) for _, req := range requires { chain = append(chain, templateChainDependencies(req)...) } chain = append(chain, template) return chain }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L36-L54
go
train
// AddSpotColor adds an ink-based CMYK color to the gofpdf instance and // associates it with the specified name. The individual components specify // percentages ranging from 0 to 100. Values above this are quietly capped to // 100. An error occurs if the specified name is already associated with a // color.
func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte)
// AddSpotColor adds an ink-based CMYK color to the gofpdf instance and // associates it with the specified name. The individual components specify // percentages ranging from 0 to 100. Values above this are quietly capped to // 100. An error occurs if the specified name is already associated with a // color. func (f *Fpdf) AddSpotColor(nameStr string, c, m, y, k byte)
{ if f.err == nil { _, ok := f.spotColorMap[nameStr] if !ok { id := len(f.spotColorMap) + 1 f.spotColorMap[nameStr] = spotColorType{ id: id, val: cmykColorType{ c: byteBound(c), m: byteBound(m), y: byteBound(y), k: byteBound(k), }, } } else { f.err = fmt.Errorf("name \"%s\" is already associated with a spot color", nameStr) } } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L70-L83
go
train
// SetDrawSpotColor sets the current draw color to the spot color associated // with nameStr. An error occurs if the name is not associated with a color. // The value for tint ranges from 0 (no intensity) to 100 (full intensity). It // is quietly bounded to this range.
func (f *Fpdf) SetDrawSpotColor(nameStr string, tint byte)
// SetDrawSpotColor sets the current draw color to the spot color associated // with nameStr. An error occurs if the name is not associated with a color. // The value for tint ranges from 0 (no intensity) to 100 (full intensity). It // is quietly bounded to this range. func (f *Fpdf) SetDrawSpotColor(nameStr string, tint byte)
{ var clr spotColorType var ok bool clr, ok = f.getSpotColor(nameStr) if ok { f.color.draw.mode = colorModeSpot f.color.draw.spotStr = nameStr f.color.draw.str = sprintf("/CS%d CS %.3f SCN", clr.id, float64(byteBound(tint))/100) if f.page > 0 { f.out(f.color.draw.str) } } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L89-L103
go
train
// SetFillSpotColor sets the current fill color to the spot color associated // with nameStr. An error occurs if the name is not associated with a color. // The value for tint ranges from 0 (no intensity) to 100 (full intensity). It // is quietly bounded to this range.
func (f *Fpdf) SetFillSpotColor(nameStr string, tint byte)
// SetFillSpotColor sets the current fill color to the spot color associated // with nameStr. An error occurs if the name is not associated with a color. // The value for tint ranges from 0 (no intensity) to 100 (full intensity). It // is quietly bounded to this range. func (f *Fpdf) SetFillSpotColor(nameStr string, tint byte)
{ var clr spotColorType var ok bool clr, ok = f.getSpotColor(nameStr) if ok { f.color.fill.mode = colorModeSpot f.color.fill.spotStr = nameStr f.color.fill.str = sprintf("/CS%d cs %.3f scn", clr.id, float64(byteBound(tint))/100) f.colorFlag = f.color.fill.str != f.color.text.str if f.page > 0 { f.out(f.color.fill.str) } } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L143-L145
go
train
// GetDrawSpotColor returns the most recently used spot color information for // drawing. This will not be the current drawing color if some other color type // such as RGB is active. If no spot color has been set for drawing, zero // values are returned.
func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte)
// GetDrawSpotColor returns the most recently used spot color information for // drawing. This will not be the current drawing color if some other color type // such as RGB is active. If no spot color has been set for drawing, zero // values are returned. func (f *Fpdf) GetDrawSpotColor() (name string, c, m, y, k byte)
{ return f.returnSpotColor(f.color.draw) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L151-L153
go
train
// GetTextSpotColor returns the most recently used spot color information for // text output. This will not be the current text color if some other color // type such as RGB is active. If no spot color has been set for text, zero // values are returned.
func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte)
// GetTextSpotColor returns the most recently used spot color information for // text output. This will not be the current text color if some other color // type such as RGB is active. If no spot color has been set for text, zero // values are returned. func (f *Fpdf) GetTextSpotColor() (name string, c, m, y, k byte)
{ return f.returnSpotColor(f.color.text) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
spotcolor.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/spotcolor.go#L159-L161
go
train
// GetFillSpotColor returns the most recently used spot color information for // fill output. This will not be the current fill color if some other color // type such as RGB is active. If no fill spot color has been set, zero values // are returned.
func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte)
// GetFillSpotColor returns the most recently used spot color information for // fill output. This will not be the current fill color if some other color // type such as RGB is active. If no fill spot color has been set, zero values // are returned. func (f *Fpdf) GetFillSpotColor() (name string, c, m, y, k byte)
{ return f.returnSpotColor(f.color.fill) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
layer.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L45-L49
go
train
// AddLayer defines a layer that can be shown or hidden when the document is // displayed. name specifies the layer name that the document reader will // display in the layer list. visible specifies whether the layer will be // initially visible. The return value is an integer ID that is used in a call // to BeginLayer().
func (f *Fpdf) AddLayer(name string, visible bool) (layerID int)
// AddLayer defines a layer that can be shown or hidden when the document is // displayed. name specifies the layer name that the document reader will // display in the layer list. visible specifies whether the layer will be // initially visible. The return value is an integer ID that is used in a call // to BeginLayer(). func (f *Fpdf) AddLayer(name string, visible bool) (layerID int)
{ layerID = len(f.layer.list) f.layer.list = append(f.layer.list, layerType{name: name, visible: visible}) return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
layer.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L55-L61
go
train
// BeginLayer is called to begin adding content to the specified layer. All // content added to the page between a call to BeginLayer and a call to // EndLayer is added to the layer specified by id. See AddLayer for more // details.
func (f *Fpdf) BeginLayer(id int)
// BeginLayer is called to begin adding content to the specified layer. All // content added to the page between a call to BeginLayer and a call to // EndLayer is added to the layer specified by id. See AddLayer for more // details. func (f *Fpdf) BeginLayer(id int)
{ f.EndLayer() if id >= 0 && id < len(f.layer.list) { f.outf("/OC /OC%d BDC", id) f.layer.currentLayer = id } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
layer.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/layer.go#L65-L70
go
train
// EndLayer is called to stop adding content to the currently active layer. See // BeginLayer for more details.
func (f *Fpdf) EndLayer()
// EndLayer is called to stop adding content to the currently active layer. See // BeginLayer for more details. func (f *Fpdf) EndLayer()
{ if f.layer.currentLayer >= 0 { f.out("EMC") f.layer.currentLayer = -1 } }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L61-L104
go
train
// printBarcode internally prints the scaled or unscaled barcode to the PDF. Used by both // Barcode() and BarcodeUnscalable().
func printBarcode(pdf barcodePdf, code string, x, y float64, w, h *float64, flow bool)
// printBarcode internally prints the scaled or unscaled barcode to the PDF. Used by both // Barcode() and BarcodeUnscalable(). func printBarcode(pdf barcodePdf, code string, x, y float64, w, h *float64, flow bool)
{ barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } bname := uniqueBarcodeName(code, x, y) info := pdf.GetImageInfo(bname) scaleToWidth := unscaled.Bounds().Dx() scaleToHeight := unscaled.Bounds().Dy() if info == nil { bcode, err := barcode.Scale( unscaled, scaleToWidth, scaleToHeight, ) if err != nil { pdf.SetError(err) return } err = registerScaledBarcode(pdf, bname, bcode) if err != nil { pdf.SetError(err) return } } if w != nil { scaleToWidth = int(*w) } if h != nil { scaleToHeight = int(*h) } pdf.Image(bname, x, y, float64(scaleToWidth), float64(scaleToHeight), flow, "jpg", 0, "") }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L111-L113
go
train
// BarcodeUnscalable puts a registered barcode in the current page. // // Its arguments work in the same way as that of Barcode(). However, it allows for an unscaled // barcode in the width and/or height dimensions. This can be useful if you want to prevent // side effects of upscaling.
func BarcodeUnscalable(pdf barcodePdf, code string, x, y float64, w, h *float64, flow bool)
// BarcodeUnscalable puts a registered barcode in the current page. // // Its arguments work in the same way as that of Barcode(). However, it allows for an unscaled // barcode in the width and/or height dimensions. This can be useful if you want to prevent // side effects of upscaling. func BarcodeUnscalable(pdf barcodePdf, code string, x, y float64, w, h *float64, flow bool)
{ printBarcode(pdf, code, x, y, w, h, flow) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L127-L140
go
train
// GetUnscaledBarcodeDimensions returns the width and height of the // unscaled barcode associated with the given code.
func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64)
// GetUnscaledBarcodeDimensions returns the width and height of the // unscaled barcode associated with the given code. func GetUnscaledBarcodeDimensions(pdf barcodePdf, code string) (w, h float64)
{ barcodes.Lock() unscaled, ok := barcodes.cache[code] barcodes.Unlock() if !ok { err := errors.New("Barcode not found") pdf.SetError(err) return } return convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dx())), convertFrom96Dpi(pdf, float64(unscaled.Bounds().Dy())) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L144-L155
go
train
// Register registers a barcode but does not put it on the page. Use Barcode() // with the same code to put the barcode on the PDF page.
func Register(bcode barcode.Barcode) string
// Register registers a barcode but does not put it on the page. Use Barcode() // with the same code to put the barcode on the PDF page. func Register(bcode barcode.Barcode) string
{ barcodes.Lock() if len(barcodes.cache) == 0 { barcodes.cache = make(map[string]barcode.Barcode) } key := barcodeKey(bcode) barcodes.cache[key] = bcode barcodes.Unlock() return key }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L161-L164
go
train
// RegisterAztec registers a barcode of type Aztec to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. // code is the string to be encoded. minECCPercent is the error correction percentage. 33 is the default. // userSpecifiedLayers can be a value between -4 and 32 inclusive.
func RegisterAztec(pdf barcodePdf, code string, minECCPercent int, userSpecifiedLayers int) string
// RegisterAztec registers a barcode of type Aztec to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. // code is the string to be encoded. minECCPercent is the error correction percentage. 33 is the default. // userSpecifiedLayers can be a value between -4 and 32 inclusive. func RegisterAztec(pdf barcodePdf, code string, minECCPercent int, userSpecifiedLayers int) string
{ bcode, err := aztec.Encode([]byte(code), minECCPercent, userSpecifiedLayers) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L168-L171
go
train
// RegisterCodabar registers a barcode of type Codabar to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page.
func RegisterCodabar(pdf barcodePdf, code string) string
// RegisterCodabar registers a barcode of type Codabar to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. func RegisterCodabar(pdf barcodePdf, code string) string
{ bcode, err := codabar.Encode(code) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L175-L178
go
train
// RegisterCode128 registers a barcode of type Code128 to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page.
func RegisterCode128(pdf barcodePdf, code string) string
// RegisterCode128 registers a barcode of type Code128 to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. func RegisterCode128(pdf barcodePdf, code string) string
{ bcode, err := code128.Encode(code) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L184-L187
go
train
// RegisterCode39 registers a barcode of type Code39 to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. // // includeChecksum and fullASCIIMode are inherited from code39.Encode().
func RegisterCode39(pdf barcodePdf, code string, includeChecksum, fullASCIIMode bool) string
// RegisterCode39 registers a barcode of type Code39 to the PDF, but not to // the page. Use Barcode() with the return value to put the barcode on the page. // // includeChecksum and fullASCIIMode are inherited from code39.Encode(). func RegisterCode39(pdf barcodePdf, code string, includeChecksum, fullASCIIMode bool) string
{ bcode, err := code39.Encode(code, includeChecksum, fullASCIIMode) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L192-L195
go
train
// RegisterDataMatrix registers a barcode of type DataMatrix to the PDF, but not // to the page. Use Barcode() with the return value to put the barcode on the // page.
func RegisterDataMatrix(pdf barcodePdf, code string) string
// RegisterDataMatrix registers a barcode of type DataMatrix to the PDF, but not // to the page. Use Barcode() with the return value to put the barcode on the // page. func RegisterDataMatrix(pdf barcodePdf, code string) string
{ bcode, err := datamatrix.Encode(code) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L204-L207
go
train
// RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not to the // page. code is the string to be encoded. columns specifies the number of // barcode columns; this should be a value between 1 and 30 inclusive. // securityLevel specifies an error correction level between zero and 8 // inclusive. Barcodes for use with FedEx must set columns to 10 and // securityLevel to 5. Use Barcode() with the return value to put the barcode // on the page.
func RegisterPdf417(pdf barcodePdf, code string, columns int, securityLevel int) string
// RegisterPdf417 registers a barcode of type Pdf417 to the PDF, but not to the // page. code is the string to be encoded. columns specifies the number of // barcode columns; this should be a value between 1 and 30 inclusive. // securityLevel specifies an error correction level between zero and 8 // inclusive. Barcodes for use with FedEx must set columns to 10 and // securityLevel to 5. Use Barcode() with the return value to put the barcode // on the page. func RegisterPdf417(pdf barcodePdf, code string, columns int, securityLevel int) string
{ bcode := pdf417.Encode(code, columns, securityLevel) return registerBarcode(pdf, bcode, nil) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L212-L215
go
train
// RegisterEAN registers a barcode of type EAN to the PDF, but not to the page. // It will automatically detect if the barcode is EAN8 or EAN13. Use Barcode() // with the return value to put the barcode on the page.
func RegisterEAN(pdf barcodePdf, code string) string
// RegisterEAN registers a barcode of type EAN to the PDF, but not to the page. // It will automatically detect if the barcode is EAN8 or EAN13. Use Barcode() // with the return value to put the barcode on the page. func RegisterEAN(pdf barcodePdf, code string) string
{ bcode, err := ean.Encode(code) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L221-L224
go
train
// RegisterQR registers a barcode of type QR to the PDF, but not to the page. // Use Barcode() with the return value to put the barcode on the page. // // The ErrorCorrectionLevel and Encoding mode are inherited from qr.Encode().
func RegisterQR(pdf barcodePdf, code string, ecl qr.ErrorCorrectionLevel, mode qr.Encoding) string
// RegisterQR registers a barcode of type QR to the PDF, but not to the page. // Use Barcode() with the return value to put the barcode on the page. // // The ErrorCorrectionLevel and Encoding mode are inherited from qr.Encode(). func RegisterQR(pdf barcodePdf, code string, ecl qr.ErrorCorrectionLevel, mode qr.Encoding) string
{ bcode, err := qr.Encode(code, ecl, mode) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L231-L234
go
train
// RegisterTwoOfFive registers a barcode of type TwoOfFive to the PDF, but not // to the page. Use Barcode() with the return value to put the barcode on the // page. // // The interleaved bool is inherited from twooffive.Encode().
func RegisterTwoOfFive(pdf barcodePdf, code string, interleaved bool) string
// RegisterTwoOfFive registers a barcode of type TwoOfFive to the PDF, but not // to the page. Use Barcode() with the return value to put the barcode on the // page. // // The interleaved bool is inherited from twooffive.Encode(). func RegisterTwoOfFive(pdf barcodePdf, code string, interleaved bool) string
{ bcode, err := twooffive.Encode(code, interleaved) return registerBarcode(pdf, bcode, err) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L240-L247
go
train
// registerBarcode registers a barcode internally using the Register() function. // In case of an error generating the barcode it will not be registered and will // set an error on the PDF. It will return a unique key for the barcode type and // content that can be used to put the barcode on the page.
func registerBarcode(pdf barcodePdf, bcode barcode.Barcode, err error) string
// registerBarcode registers a barcode internally using the Register() function. // In case of an error generating the barcode it will not be registered and will // set an error on the PDF. It will return a unique key for the barcode type and // content that can be used to put the barcode on the page. func registerBarcode(pdf barcodePdf, bcode barcode.Barcode, err error) string
{ if err != nil { pdf.SetError(err) return "" } return Register(bcode) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L252-L257
go
train
// uniqueBarcodeName makes sure every barcode has a unique name for its // dimensions. Scaling a barcode image results in quality loss, which could be // a problem for barcode readers.
func uniqueBarcodeName(code string, x, y float64) string
// uniqueBarcodeName makes sure every barcode has a unique name for its // dimensions. Scaling a barcode image results in quality loss, which could be // a problem for barcode readers. func uniqueBarcodeName(code string, x, y float64) string
{ xStr := strconv.FormatFloat(x, 'E', -1, 64) yStr := strconv.FormatFloat(y, 'E', -1, 64) return "barcode-" + code + "-" + xStr + yStr }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L262-L264
go
train
// barcodeKey combines the code type and code value into a unique identifier for // a barcode type. This is so that we can store several barcodes with the same // code but different type in the barcodes map.
func barcodeKey(bcode barcode.Barcode) string
// barcodeKey combines the code type and code value into a unique identifier for // a barcode type. This is so that we can store several barcodes with the same // code but different type in the barcodes map. func barcodeKey(bcode barcode.Barcode) string
{ return bcode.Metadata().CodeKind + bcode.Content() }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
contrib/barcode/barcode.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/contrib/barcode/barcode.go#L269-L281
go
train
// registerScaledBarcode registers a barcode with its exact dimensions to the // PDF but does not put it on the page. Use Fpdf.Image() with the same code to // add the barcode to the page.
func registerScaledBarcode(pdf barcodePdf, code string, bcode barcode.Barcode) error
// registerScaledBarcode registers a barcode with its exact dimensions to the // PDF but does not put it on the page. Use Fpdf.Image() with the same code to // add the barcode to the page. func registerScaledBarcode(pdf barcodePdf, code string, bcode barcode.Barcode) error
{ buf := new(bytes.Buffer) err := jpeg.Encode(buf, bcode, nil) if err != nil { return err } reader := bytes.NewReader(buf.Bytes()) pdf.RegisterImageReader(code, "jpg", reader) return nil }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L35-L44
go
train
// StateGet returns a variable that contains common state values.
func StateGet(pdf *Fpdf) (st StateType)
// StateGet returns a variable that contains common state values. func StateGet(pdf *Fpdf) (st StateType)
{ st.clrDraw.R, st.clrDraw.G, st.clrDraw.B = pdf.GetDrawColor() st.clrFill.R, st.clrFill.G, st.clrFill.B = pdf.GetFillColor() st.clrText.R, st.clrText.G, st.clrText.B = pdf.GetTextColor() st.lineWd = pdf.GetLineWidth() _, st.fontSize = pdf.GetFontSize() st.alpha, st.blendStr = pdf.GetAlpha() st.cellMargin = pdf.GetCellMargin() return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L48-L56
go
train
// Put sets the common state values contained in the state structure // specified by st.
func (st StateType) Put(pdf *Fpdf)
// Put sets the common state values contained in the state structure // specified by st. func (st StateType) Put(pdf *Fpdf)
{ pdf.SetDrawColor(st.clrDraw.R, st.clrDraw.G, st.clrDraw.B) pdf.SetFillColor(st.clrFill.R, st.clrFill.G, st.clrFill.B) pdf.SetTextColor(st.clrText.R, st.clrText.G, st.clrText.B) pdf.SetLineWidth(st.lineWd) pdf.SetFontUnitSize(st.fontSize) pdf.SetAlpha(st.alpha, st.blendStr) pdf.SetCellMargin(st.cellMargin) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L62-L64
go
train
// defaultFormatter returns the string form of val with precision decimal places.
func defaultFormatter(val float64, precision int) string
// defaultFormatter returns the string form of val with precision decimal places. func defaultFormatter(val float64, precision int) string
{ return strconv.FormatFloat(val, 'f', precision, 64) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L99-L105
go
train
// linear returns the slope and y-intercept of the straight line joining the // two specified points. For scaling purposes, associate the arguments as // follows: x1: observed low value, y1: desired low value, x2: observed high // value, y2: desired high value.
func linear(x1, y1, x2, y2 float64) (slope, intercept float64)
// linear returns the slope and y-intercept of the straight line joining the // two specified points. For scaling purposes, associate the arguments as // follows: x1: observed low value, y1: desired low value, x2: observed high // value, y2: desired high value. func linear(x1, y1, x2, y2 float64) (slope, intercept float64)
{ if x2 != x1 { slope = (y2 - y1) / (x2 - x1) intercept = y2 - x2*slope } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L110-L116
go
train
// linearTickmark returns the slope and intercept that will linearly map data // values (the range of which is specified by the tickmark slice tm) to page // values (the range of which is specified by lo and hi).
func linearTickmark(tm []float64, lo, hi float64) (slope, intercept float64)
// linearTickmark returns the slope and intercept that will linearly map data // values (the range of which is specified by the tickmark slice tm) to page // values (the range of which is specified by lo and hi). func linearTickmark(tm []float64, lo, hi float64) (slope, intercept float64)
{ ln := len(tm) if ln > 0 { slope, intercept = linear(tm[0], lo, tm[ln-1], hi) } return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L130-L151
go
train
// NewGrid returns a variable of type GridType that is initialized to draw on a // rectangle of width w and height h with the upper left corner positioned at // point (x, y). The coordinates are in page units, that is, the same as those // specified in New(). // // The returned variable is initialized with a very simple default tickmark // layout that ranges from 0 to 1 in both axes. Prior to calling Grid(), the // application may establish a more suitable tickmark layout by calling the // methods TickmarksContainX() and TickmarksContainY(). These methods bound the // data range with appropriate boundaries and divisions. Alternatively, if the // exact extent and divisions of the tickmark layout are known, the methods // TickmarksExtentX() and TickmarksExtentY may be called instead.
func NewGrid(x, y, w, h float64) (grid GridType)
// NewGrid returns a variable of type GridType that is initialized to draw on a // rectangle of width w and height h with the upper left corner positioned at // point (x, y). The coordinates are in page units, that is, the same as those // specified in New(). // // The returned variable is initialized with a very simple default tickmark // layout that ranges from 0 to 1 in both axes. Prior to calling Grid(), the // application may establish a more suitable tickmark layout by calling the // methods TickmarksContainX() and TickmarksContainY(). These methods bound the // data range with appropriate boundaries and divisions. Alternatively, if the // exact extent and divisions of the tickmark layout are known, the methods // TickmarksExtentX() and TickmarksExtentY may be called instead. func NewGrid(x, y, w, h float64) (grid GridType)
{ grid.x = x grid.y = y grid.w = w grid.h = h grid.TextSize = 7 // Points grid.TickmarksExtentX(0, 1, 1) grid.TickmarksExtentY(0, 1, 1) grid.XLabelIn = false grid.YLabelIn = false grid.XLabelRotate = false grid.XDiv = 10 grid.YDiv = 10 grid.ClrText = RGBAType{R: 0, G: 0, B: 0, Alpha: 1} grid.ClrMain = RGBAType{R: 128, G: 160, B: 128, Alpha: 1} grid.ClrSub = RGBAType{R: 192, G: 224, B: 192, Alpha: 1} grid.WdMain = 0.1 grid.WdSub = 0.1 grid.YTickStr = defaultFormatter grid.XTickStr = defaultFormatter return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L155-L157
go
train
// WdAbs returns the absolute value of dataWd, specified in logical data units, // that has been converted to the unit of measure specified in New().
func (g GridType) WdAbs(dataWd float64) float64
// WdAbs returns the absolute value of dataWd, specified in logical data units, // that has been converted to the unit of measure specified in New(). func (g GridType) WdAbs(dataWd float64) float64
{ return math.Abs(g.xm * dataWd) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L167-L169
go
train
// XY converts dataX and dataY, specified in logical data units, to the X and Y // position on the current page.
func (g GridType) XY(dataX, dataY float64) (x, y float64)
// XY converts dataX and dataY, specified in logical data units, to the X and Y // position on the current page. func (g GridType) XY(dataX, dataY float64) (x, y float64)
{ return g.xm*dataX + g.xb, g.ym*dataY + g.yb }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L175-L179
go
train
// Pos returns the point, in page units, indicated by the relative positions // xRel and yRel. These are values between 0 and 1. xRel specifies the relative // position between the grid's left and right edges. yRel specifies the // relative position between the grid's bottom and top edges.
func (g GridType) Pos(xRel, yRel float64) (x, y float64)
// Pos returns the point, in page units, indicated by the relative positions // xRel and yRel. These are values between 0 and 1. xRel specifies the relative // position between the grid's left and right edges. yRel specifies the // relative position between the grid's bottom and top edges. func (g GridType) Pos(xRel, yRel float64) (x, y float64)
{ x = g.w*xRel + g.x y = g.h*(1-yRel) + g.y return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L183-L185
go
train
// X converts dataX, specified in logical data units, to the X position on the // current page.
func (g GridType) X(dataX float64) float64
// X converts dataX, specified in logical data units, to the X position on the // current page. func (g GridType) X(dataX float64) float64
{ return g.xm*dataX + g.xb }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L189-L191
go
train
// HtAbs returns the absolute value of dataHt, specified in logical data units, // that has been converted to the unit of measure specified in New().
func (g GridType) HtAbs(dataHt float64) float64
// HtAbs returns the absolute value of dataHt, specified in logical data units, // that has been converted to the unit of measure specified in New(). func (g GridType) HtAbs(dataHt float64) float64
{ return math.Abs(g.ym * dataHt) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L201-L203
go
train
// Y converts dataY, specified in logical data units, to the Y position on the // current page.
func (g GridType) Y(dataY float64) float64
// Y converts dataY, specified in logical data units, to the Y position on the // current page. func (g GridType) Y(dataY float64) float64
{ return g.ym*dataY + g.yb }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L208-L212
go
train
// XRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's left and right // edges.
func (g GridType) XRange() (min, max float64)
// XRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's left and right // edges. func (g GridType) XRange() (min, max float64)
{ min = g.xTicks[0] max = g.xTicks[len(g.xTicks)-1] return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L217-L221
go
train
// YRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's bottom and top // edges.
func (g GridType) YRange() (min, max float64)
// YRange returns the minimum and maximum values for the current tickmark // sequence. These correspond to the data values of the graph's bottom and top // edges. func (g GridType) YRange() (min, max float64)
{ min = g.yTicks[0] max = g.yTicks[len(g.yTicks)-1] return }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L230-L233
go
train
// TickmarksContainX sets the tickmarks to be shown by Grid() in the horizontal // dimension. The argument min and max specify the minimum and maximum values // to be contained within the grid. The tickmark values that are generated are // suitable for general purpose graphs. // // See TickmarkExtentX() for an alternative to this method to be used when the // exact values of the tickmarks are to be set by the application.
func (g *GridType) TickmarksContainX(min, max float64)
// TickmarksContainX sets the tickmarks to be shown by Grid() in the horizontal // dimension. The argument min and max specify the minimum and maximum values // to be contained within the grid. The tickmark values that are generated are // suitable for general purpose graphs. // // See TickmarkExtentX() for an alternative to this method to be used when the // exact values of the tickmarks are to be set by the application. func (g *GridType) TickmarksContainX(min, max float64)
{ g.xTicks, g.xPrecision = Tickmarks(min, max) g.xm, g.xb = linearTickmark(g.xTicks, g.x, g.x+g.w) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L242-L245
go
train
// TickmarksContainY sets the tickmarks to be shown by Grid() in the vertical // dimension. The argument min and max specify the minimum and maximum values // to be contained within the grid. The tickmark values that are generated are // suitable for general purpose graphs. // // See TickmarkExtentY() for an alternative to this method to be used when the // exact values of the tickmarks are to be set by the application.
func (g *GridType) TickmarksContainY(min, max float64)
// TickmarksContainY sets the tickmarks to be shown by Grid() in the vertical // dimension. The argument min and max specify the minimum and maximum values // to be contained within the grid. The tickmark values that are generated are // suitable for general purpose graphs. // // See TickmarkExtentY() for an alternative to this method to be used when the // exact values of the tickmarks are to be set by the application. func (g *GridType) TickmarksContainY(min, max float64)
{ g.yTicks, g.yPrecision = Tickmarks(min, max) g.ym, g.yb = linearTickmark(g.yTicks, g.y+g.h, g.y) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L264-L267
go
train
// TickmarksExtentX sets the tickmarks to be shown by Grid() in the horizontal // dimension. count specifies number of major tickmark subdivisions to be // graphed. min specifies the leftmost data value. div specifies, in data // units, the extent of each major tickmark subdivision. // // See TickmarkContainX() for an alternative to this method to be used when // viewer-friendly tickmarks are to be determined automatically.
func (g *GridType) TickmarksExtentX(min, div float64, count int)
// TickmarksExtentX sets the tickmarks to be shown by Grid() in the horizontal // dimension. count specifies number of major tickmark subdivisions to be // graphed. min specifies the leftmost data value. div specifies, in data // units, the extent of each major tickmark subdivision. // // See TickmarkContainX() for an alternative to this method to be used when // viewer-friendly tickmarks are to be determined automatically. func (g *GridType) TickmarksExtentX(min, div float64, count int)
{ g.xTicks, g.xPrecision = extent(min, div, count) g.xm, g.xb = linearTickmark(g.xTicks, g.x, g.x+g.w) }
jung-kurt/gofpdf
8b09ffb30d9a8716107d250631b3c580aa54ba04
grid.go
https://github.com/jung-kurt/gofpdf/blob/8b09ffb30d9a8716107d250631b3c580aa54ba04/grid.go#L276-L279
go
train
// TickmarksExtentY sets the tickmarks to be shown by Grid() in the vertical // dimension. count specifies number of major tickmark subdivisions to be // graphed. min specifies the bottommost data value. div specifies, in data // units, the extent of each major tickmark subdivision. // // See TickmarkContainY() for an alternative to this method to be used when // viewer-friendly tickmarks are to be determined automatically.
func (g *GridType) TickmarksExtentY(min, div float64, count int)
// TickmarksExtentY sets the tickmarks to be shown by Grid() in the vertical // dimension. count specifies number of major tickmark subdivisions to be // graphed. min specifies the bottommost data value. div specifies, in data // units, the extent of each major tickmark subdivision. // // See TickmarkContainY() for an alternative to this method to be used when // viewer-friendly tickmarks are to be determined automatically. func (g *GridType) TickmarksExtentY(min, div float64, count int)
{ g.yTicks, g.yPrecision = extent(min, div, count) g.ym, g.yb = linearTickmark(g.yTicks, g.y+g.h, g.y) }