diff --git a/common/license/util.go b/common/license/util.go index 9ddba152..c40e22ef 100644 --- a/common/license/util.go +++ b/common/license/util.go @@ -14,7 +14,7 @@ import ( // Defaults to the open source license. var licenseKey = MakeUnlicensedKey() -// Sets and validates the license key. +// SetLicenseKey sets and validates the license key. func SetLicenseKey(content string, customerName string) error { lk, err := licenseKeyDecode(content) if err != nil { diff --git a/common/logging.go b/common/logging.go index ae374229..87dc3efc 100644 --- a/common/logging.go +++ b/common/logging.go @@ -21,7 +21,7 @@ type Logger interface { Trace(format string, args ...interface{}) } -// Dummy Logger does nothing. +// DummyLogger does nothing. type DummyLogger struct{} func (this DummyLogger) Error(format string, args ...interface{}) { @@ -42,7 +42,7 @@ func (this DummyLogger) Debug(format string, args ...interface{}) { func (this DummyLogger) Trace(format string, args ...interface{}) { } -// Simple Console Logger that the tests use. +// LogLevel is the verbosity level for logging. type LogLevel int const ( diff --git a/common/version.go b/common/version.go index ce5fa222..1c0fa11e 100644 --- a/common/version.go +++ b/common/version.go @@ -16,7 +16,7 @@ const releaseDay = 14 const releaseHour = 19 const releaseMin = 40 -// Holds version information, when bumping this make sure to bump the released at stamp also. +// Version holds version information, when bumping this make sure to bump the released at stamp also. const Version = "2.1.1" var ReleasedAt = time.Date(releaseYear, releaseMonth, releaseDay, releaseHour, releaseMin, 0, 0, time.UTC) diff --git a/doc.go b/doc.go index edb7870a..c881630f 100644 --- a/doc.go +++ b/doc.go @@ -3,7 +3,7 @@ * file 'LICENSE.md', which is part of this source code package. */ -// UniDoc is a comprehensive PDF library for Go (golang). The library has advanced capabilities for generating, +// Package unidoc is a comprehensive PDF library for Go (golang). The library has advanced capabilities for generating, // processing and modifying PDFs. UniDoc is written and supported by the owners of the // FoxyUtils.com website, where the library is used to power many of the PDF services offered. // diff --git a/pdf/annotator/circle.go b/pdf/annotator/circle.go index 47681a12..59deeca3 100644 --- a/pdf/annotator/circle.go +++ b/pdf/annotator/circle.go @@ -26,7 +26,8 @@ type CircleAnnotationDef struct { Opacity float64 // Alpha value (0-1). } -// Creates a circle/ellipse annotation object with appearance stream that can be added to page PDF annotations. +// CreateCircleAnnotation creates a circle/ellipse annotation object with appearance stream that can be added to +// page PDF annotations. func CreateCircleAnnotation(circDef CircleAnnotationDef) (*pdf.PdfAnnotation, error) { circAnnotation := pdf.NewPdfAnnotationCircle() diff --git a/pdf/annotator/line.go b/pdf/annotator/line.go index cea9f60f..5d33b77b 100644 --- a/pdf/annotator/line.go +++ b/pdf/annotator/line.go @@ -12,8 +12,8 @@ import ( pdf "github.com/unidoc/unidoc/pdf/model" ) -// Defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line), -// or arrows at either end. The line also has a specified width, color and opacity. +// LineAnnotationDef defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none +// (regular line), or arrows at either end. The line also has a specified width, color and opacity. type LineAnnotationDef struct { X1 float64 Y1 float64 @@ -26,7 +26,7 @@ type LineAnnotationDef struct { LineEndingStyle2 draw.LineEndingStyle // Line ending style of point 2. } -// Creates a line annotation object that can be added to page PDF annotations. +// CreateLineAnnotation creates a line annotation object that can be added to page PDF annotations. func CreateLineAnnotation(lineDef LineAnnotationDef) (*pdf.PdfAnnotation, error) { // Line annotation. lineAnnotation := pdf.NewPdfAnnotationLine() diff --git a/pdf/annotator/rectangle.go b/pdf/annotator/rectangle.go index 2c6943c5..2d8798f4 100644 --- a/pdf/annotator/rectangle.go +++ b/pdf/annotator/rectangle.go @@ -13,8 +13,8 @@ import ( pdf "github.com/unidoc/unidoc/pdf/model" ) -// A rectangle defined with a specified Width and Height and a lower left corner at (X,Y). The rectangle can -// optionally have a border and a filling color. +// RectangleAnnotationDef is a rectangle defined with a specified Width and Height and a lower left corner at (X,Y). +// The rectangle can optionally have a border and a filling color. // The Width/Height includes the border (if any specified). type RectangleAnnotationDef struct { X float64 @@ -29,7 +29,7 @@ type RectangleAnnotationDef struct { Opacity float64 // Alpha value (0-1). } -// Creates a rectangle annotation object that can be added to page PDF annotations. +// CreateRectangleAnnotation creates a rectangle annotation object that can be added to page PDF annotations. func CreateRectangleAnnotation(rectDef RectangleAnnotationDef) (*pdf.PdfAnnotation, error) { rectAnnotation := pdf.NewPdfAnnotationSquare() diff --git a/pdf/contentstream/draw/bezier_curve.go b/pdf/contentstream/draw/bezier_curve.go index a32f89d6..b319bc4c 100644 --- a/pdf/contentstream/draw/bezier_curve.go +++ b/pdf/contentstream/draw/bezier_curve.go @@ -11,7 +11,7 @@ import ( "github.com/unidoc/unidoc/pdf/model" ) -// Cubic bezier curves are defined by: +// CubicBezierCurve is defined by: // R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3 // where P0 is the current point, P1, P2 control points and P3 the final point. type CubicBezierCurve struct { @@ -30,7 +30,7 @@ func NewCubicBezierCurve(x0, y0, x1, y1, x2, y2, x3, y3 float64) CubicBezierCurv return curve } -// Add X,Y offset to all points on a curve. +// AddOffsetXY adds X,Y offset to all points on a curve. func (curve CubicBezierCurve) AddOffsetXY(offX, offY float64) CubicBezierCurve { curve.P0.X += offX curve.P1.X += offX diff --git a/pdf/contentstream/draw/path.go b/pdf/contentstream/draw/path.go index c0f1dacf..b82d3a99 100644 --- a/pdf/contentstream/draw/path.go +++ b/pdf/contentstream/draw/path.go @@ -5,7 +5,7 @@ package draw -// A path consists of straight line connections between each point defined in an array of points. +// Path consists of straight line connections between each point defined in an array of points. type Path struct { Points []Point } diff --git a/pdf/contentstream/draw/point.go b/pdf/contentstream/draw/point.go index eb5265c3..b7bd03a5 100644 --- a/pdf/contentstream/draw/point.go +++ b/pdf/contentstream/draw/point.go @@ -25,7 +25,7 @@ func (p Point) Add(dx, dy float64) Point { return p } -// Add vector to a point. +// AddVector adds vector to a point. func (this Point) AddVector(v Vector) Point { this.X += v.Dx this.Y += v.Dy diff --git a/pdf/contentstream/draw/utils.go b/pdf/contentstream/draw/utils.go index c54ae18e..56b426f0 100644 --- a/pdf/contentstream/draw/utils.go +++ b/pdf/contentstream/draw/utils.go @@ -4,7 +4,7 @@ import ( pdfcontent "github.com/unidoc/unidoc/pdf/contentstream" ) -// Make the path with the content creator. +// DrawPathWithCreator makes the path with the content creator. // Adds the PDF commands to draw the path to the creator instance. func DrawPathWithCreator(path Path, creator *pdfcontent.ContentCreator) { for idx, p := range path.Points { @@ -16,7 +16,7 @@ func DrawPathWithCreator(path Path, creator *pdfcontent.ContentCreator) { } } -// Make the bezier path with the content creator. +// DrawBezierPathWithCreator makes the bezier path with the content creator. // Adds the PDF commands to draw the path to the creator instance. func DrawBezierPathWithCreator(bpath CubicBezierPath, creator *pdfcontent.ContentCreator) { for idx, c := range bpath.Curves { diff --git a/pdf/contentstream/draw/vector.go b/pdf/contentstream/draw/vector.go index b8afc699..c97bc41c 100644 --- a/pdf/contentstream/draw/vector.go +++ b/pdf/contentstream/draw/vector.go @@ -47,7 +47,7 @@ func (v Vector) Rotate(phi float64) Vector { return NewVectorPolar(mag, angle+phi) } -// Change the sign of the vector: -vector. +// Flip changes the sign of the vector: -vector. func (this Vector) Flip() Vector { mag := this.Magnitude() theta := this.GetPolarAngle() diff --git a/pdf/contentstream/inline-image.go b/pdf/contentstream/inline-image.go index f778e4de..47d4d6b2 100644 --- a/pdf/contentstream/inline-image.go +++ b/pdf/contentstream/inline-image.go @@ -15,7 +15,7 @@ import ( "github.com/unidoc/unidoc/pdf/model" ) -// A representation of an inline image in a Content stream. Everything between the BI and EI operands. +// ContentStreamInlineImage is a representation of an inline image in a Content stream. Everything between the BI and EI operands. // ContentStreamInlineImage implements the core.PdfObject interface although strictly it is not a PDF object. type ContentStreamInlineImage struct { BitsPerComponent core.PdfObject @@ -31,7 +31,7 @@ type ContentStreamInlineImage struct { stream []byte } -// Make a new content stream inline image object from an image. +// NewInlineImageFromImage makes a new content stream inline image object from an image. func NewInlineImageFromImage(img model.Image, encoder core.StreamEncoder) (*ContentStreamInlineImage, error) { if encoder == nil { encoder = core.NewRawEncoder() @@ -198,7 +198,7 @@ func (img *ContentStreamInlineImage) GetEncoder() (core.StreamEncoder, error) { return newEncoderFromInlineImage(img) } -// Is a mask ? +// IsMask check if an image is a mask. // The image mask entry in the image dictionary specifies that the image data shall be used as a stencil // mask for painting in the current color. The mask data is 1bpc, grayscale. func (img *ContentStreamInlineImage) IsMask() (bool, error) { @@ -216,7 +216,7 @@ func (img *ContentStreamInlineImage) IsMask() (bool, error) { } -// Export the inline image to Image which can be transformed or exported easily. +// ToImage export the inline image to Image which can be transformed or exported easily. // Page resources are needed to look up colorspace information. func (img *ContentStreamInlineImage) ToImage(resources *model.PdfPageResources) (*model.Image, error) { // Decode the imaging data if encoded. @@ -297,7 +297,7 @@ func (img *ContentStreamInlineImage) ToImage(resources *model.PdfPageResources) return image, nil } -// Parse an inline image from a content stream, both read its properties and binary data. +// ParseInlineImage parses an inline image from a content stream, both read its properties and binary data. // When called, "BI" has already been read from the stream. This function // finishes reading through "EI" and then returns the ContentStreamInlineImage. func (csp *ContentStreamParser) ParseInlineImage() (*ContentStreamInlineImage, error) { diff --git a/pdf/contentstream/processor.go b/pdf/contentstream/processor.go index e10b8ca1..8bce425c 100644 --- a/pdf/contentstream/processor.go +++ b/pdf/contentstream/processor.go @@ -13,7 +13,7 @@ import ( "github.com/unidoc/unidoc/pdf/model" ) -// Basic graphics state implementation. +// GraphicsState is a basic graphics state implementation. // Initially only implementing and tracking a portion of the information specified. Easy to add more. type GraphicsState struct { ColorspaceStroking model.PdfColorspace diff --git a/pdf/core/encoding.go b/pdf/core/encoding.go index 377a0c99..151c19e6 100644 --- a/pdf/core/encoding.go +++ b/pdf/core/encoding.go @@ -63,7 +63,7 @@ type StreamEncoder interface { DecodeStream(streamObj *PdfObjectStream) ([]byte, error) } -// Flate encoding. +// FlateEncoder represents Flate encoding. type FlateEncoder struct { Predictor int BitsPerComponent int @@ -72,7 +72,7 @@ type FlateEncoder struct { Colors int } -// Make a new flate encoder with default parameters, predictor 1 and bits per component 8. +// NewFlateEncoder makes a new flate encoder with default parameters, predictor 1 and bits per component 8. func NewFlateEncoder() *FlateEncoder { encoder := &FlateEncoder{} @@ -88,7 +88,7 @@ func NewFlateEncoder() *FlateEncoder { return encoder } -// Set the predictor function. Specify the number of columns per row. +// SetPredictor sets the predictor function. Specify the number of columns per row. // The columns indicates the number of samples per row. // Used for grouping data together for compression. func (this *FlateEncoder) SetPredictor(columns int) { @@ -122,7 +122,7 @@ func (this *FlateEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. // Has the Filter set and the DecodeParms. func (this *FlateEncoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() @@ -246,7 +246,7 @@ func (this *FlateEncoder) DecodeBytes(encoded []byte) ([]byte, error) { return outBuf.Bytes(), nil } -// Decode a FlateEncoded stream object and give back decoded bytes. +// DecodeStream decodes a FlateEncoded stream object and give back decoded bytes. func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) { // TODO: Handle more filter bytes and support more values of BitsPerComponent. @@ -398,7 +398,7 @@ func (this *FlateEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, erro return outData, nil } -// Encode a bytes array and return the encoded value based on the encoder parameters. +// EncodeBytes encodes a bytes array and return the encoded value based on the encoder parameters. func (this *FlateEncoder) EncodeBytes(data []byte) ([]byte, error) { if this.Predictor != 1 && this.Predictor != 11 { common.Log.Debug("Encoding error: FlateEncoder Predictor = 1, 11 only supported") @@ -445,7 +445,7 @@ func (this *FlateEncoder) EncodeBytes(data []byte) ([]byte, error) { return b.Bytes(), nil } -// LZW encoding/decoding functionality. +// LZWEncoder provides LZW encoding/decoding functionality. type LZWEncoder struct { Predictor int BitsPerComponent int @@ -456,7 +456,7 @@ type LZWEncoder struct { EarlyChange int } -// Make a new LZW encoder with default parameters. +// NewLZWEncoder makes a new LZW encoder with default parameters. func NewLZWEncoder() *LZWEncoder { encoder := &LZWEncoder{} @@ -497,7 +497,7 @@ func (this *LZWEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. // Has the Filter set and the DecodeParms. func (this *LZWEncoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() @@ -770,7 +770,7 @@ func (this *LZWEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) return outData, nil } -// Support for encoding LZW. Currently not supporting predictors (raw compressed data only). +// EncodeBytes implements support for LZW encoding. Currently not supporting predictors (raw compressed data only). // Only supports the Early change = 1 algorithm (compress/lzw) as the other implementation // does not have a write method. // TODO: Consider refactoring compress/lzw to allow both. @@ -791,8 +791,7 @@ func (this *LZWEncoder) EncodeBytes(data []byte) ([]byte, error) { return b.Bytes(), nil } -// -// DCT (JPG) encoding/decoding functionality for images. +// DCTEncoder provides a DCT (JPG) encoding/decoding functionality for images. type DCTEncoder struct { ColorComponents int // 1 (gray), 3 (rgb), 4 (cmyk) BitsPerComponent int // 8 or 16 bit @@ -801,7 +800,7 @@ type DCTEncoder struct { Quality int } -// Make a new DCT encoder with default parameters. +// NewDCTEncoder makes a new DCT encoder with default parameters. func NewDCTEncoder() *DCTEncoder { encoder := &DCTEncoder{} @@ -822,7 +821,7 @@ func (this *DCTEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. // Has the Filter set. Some other parameters are generated elsewhere. func (this *DCTEncoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() @@ -1102,11 +1101,11 @@ func (this *DCTEncoder) EncodeBytes(data []byte) ([]byte, error) { return buf.Bytes(), nil } -// Run length encoding. +// RunLengthEncoder represents Run length encoding. type RunLengthEncoder struct { } -// Make a new run length encoder +// NewRunLengthEncoder makes a new run length encoder func NewRunLengthEncoder() *RunLengthEncoder { return &RunLengthEncoder{} } @@ -1117,19 +1116,20 @@ func (this *RunLengthEncoder) GetFilterName() string { // Create a new run length decoder from a stream object. func newRunLengthEncoderFromStream(streamObj *PdfObjectStream, decodeParams *PdfObjectDictionary) (*RunLengthEncoder, error) { - // TODO(dennwc): unused paramaters + // TODO(dennwc): unused paramaters; should verify that they are empty? return NewRunLengthEncoder(), nil } -/* - 7.4.5 RunLengthDecode Filter - The RunLengthDecode filter decodes data that has been encoded in a simple byte-oriented format based on run length. - The encoded data shall be a sequence of runs, where each run shall consist of a length byte followed by 1 to 128 - bytes of data. If the length byte is in the range 0 to 127, the following length + 1 (1 to 128) bytes shall be - copied literally during decompression. If length is in the range 129 to 255, the following single byte shall be - copied 257 - length (2 to 128) times during decompression. A length value of 128 shall denote EOD. -*/ +// DecodeBytes decodes a byte slice from Run length encoding. +// +// 7.4.5 RunLengthDecode Filter +// The RunLengthDecode filter decodes data that has been encoded in a simple byte-oriented format based on run length. +// The encoded data shall be a sequence of runs, where each run shall consist of a length byte followed by 1 to 128 +// bytes of data. If the length byte is in the range 0 to 127, the following length + 1 (1 to 128) bytes shall be +// copied literally during decompression. If length is in the range 129 to 255, the following single byte shall be +// copied 257 - length (2 to 128) times during decompression. A length value of 128 shall denote EOD. func (this *RunLengthEncoder) DecodeBytes(encoded []byte) ([]byte, error) { + // TODO(dennwc): use encoded slice directly, instead of wrapping it into a Reader bufReader := bytes.NewReader(encoded) var inb []byte for { @@ -1161,12 +1161,12 @@ func (this *RunLengthEncoder) DecodeBytes(encoded []byte) ([]byte, error) { return inb, nil } -// Decode RunLengthEncoded stream object and give back decoded bytes. +// DecodeStream decodes RunLengthEncoded stream object and give back decoded bytes. func (this *RunLengthEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) { return this.DecodeBytes(streamObj.Stream) } -// Encode a bytes array and return the encoded value based on the encoder parameters. +// EncodeBytes encodes a bytes array and return the encoded value based on the encoder parameters. func (this *RunLengthEncoder) EncodeBytes(data []byte) ([]byte, error) { bufReader := bytes.NewReader(data) var inb []byte @@ -1238,19 +1238,18 @@ func (this *RunLengthEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *RunLengthEncoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() dict.Set("Filter", MakeName(this.GetFilterName())) return dict } -///// -// ASCII hex encoder/decoder. +// ASCIIHexEncoder implements ASCII hex encoder/decoder. type ASCIIHexEncoder struct { } -// Make a new ASCII hex encoder. +// NewASCIIHexEncoder makes a new ASCII hex encoder. func NewASCIIHexEncoder() *ASCIIHexEncoder { encoder := &ASCIIHexEncoder{} return encoder @@ -1264,7 +1263,7 @@ func (this *ASCIIHexEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *ASCIIHexEncoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() dict.Set("Filter", MakeName(this.GetFilterName())) @@ -1304,7 +1303,7 @@ func (this *ASCIIHexEncoder) DecodeBytes(encoded []byte) ([]byte, error) { return outb, nil } -// ASCII hex decoding. +// DecodeStream implements ASCII hex decoding. func (this *ASCIIHexEncoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) { return this.DecodeBytes(streamObj.Stream) } @@ -1320,13 +1319,11 @@ func (this *ASCIIHexEncoder) EncodeBytes(data []byte) ([]byte, error) { return encoded.Bytes(), nil } -// -// ASCII85 encoder/decoder. -// +// ASCII85Encoder implements ASCII85 encoder/decoder. type ASCII85Encoder struct { } -// Make a new ASCII85 encoder. +// NewASCII85Encoder makes a new ASCII85 encoder. func NewASCII85Encoder() *ASCII85Encoder { encoder := &ASCII85Encoder{} return encoder @@ -1340,14 +1337,14 @@ func (this *ASCII85Encoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict make a new instance of an encoding dictionary for a stream object. func (this *ASCII85Encoder) MakeStreamDict() *PdfObjectDictionary { dict := MakeDict() dict.Set("Filter", MakeName(this.GetFilterName())) return dict } -// 5 ASCII characters -> 4 raw binary bytes +// DecodeBytes decodes byte array with ASCII85. 5 ASCII characters -> 4 raw binary bytes func (this *ASCII85Encoder) DecodeBytes(encoded []byte) ([]byte, error) { var decoded []byte @@ -1425,7 +1422,7 @@ func (this *ASCII85Encoder) DecodeBytes(encoded []byte) ([]byte, error) { return decoded, nil } -// ASCII85 stream decoding. +// DecodeStream implements ASCII85 stream decoding. func (this *ASCII85Encoder) DecodeStream(streamObj *PdfObjectStream) ([]byte, error) { return this.DecodeBytes(streamObj.Stream) } @@ -1449,7 +1446,7 @@ func (this *ASCII85Encoder) base256Tobase85(base256val uint32) [5]byte { return base85 } -// Encode data into ASCII85 encoded format. +// EncodeBytes encodes data into ASCII85 encoded format. func (this *ASCII85Encoder) EncodeBytes(data []byte) ([]byte, error) { var encoded bytes.Buffer @@ -1492,9 +1489,7 @@ func (this *ASCII85Encoder) EncodeBytes(data []byte) ([]byte, error) { return encoded.Bytes(), nil } -// -// Raw encoder/decoder (no encoding, pass through) -// +// RawEncoder implements Raw encoder/decoder (no encoding, pass through) type RawEncoder struct{} func NewRawEncoder() *RawEncoder { @@ -1509,7 +1504,7 @@ func (this *RawEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *RawEncoder) MakeStreamDict() *PdfObjectDictionary { return MakeDict() } @@ -1526,9 +1521,8 @@ func (this *RawEncoder) EncodeBytes(data []byte) ([]byte, error) { return data, nil } -// -// CCITTFax encoder/decoder (dummy, for now) -// +// CCITTFaxEncoder implements CCITTFax encoder/decoder (dummy, for now) +// FIXME: implement type CCITTFaxEncoder struct{} func NewCCITTFaxEncoder() *CCITTFaxEncoder { @@ -1543,7 +1537,7 @@ func (this *CCITTFaxEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *CCITTFaxEncoder) MakeStreamDict() *PdfObjectDictionary { return MakeDict() } @@ -1563,9 +1557,8 @@ func (this *CCITTFaxEncoder) EncodeBytes(data []byte) ([]byte, error) { return data, ErrNoCCITTFaxDecode } -// -// JBIG2 encoder/decoder (dummy, for now) -// +// JBIG2Encoder implements JBIG2 encoder/decoder (dummy, for now) +// FIXME: implement type JBIG2Encoder struct{} func NewJBIG2Encoder() *JBIG2Encoder { @@ -1580,7 +1573,7 @@ func (this *JBIG2Encoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *JBIG2Encoder) MakeStreamDict() *PdfObjectDictionary { return MakeDict() } @@ -1600,9 +1593,8 @@ func (this *JBIG2Encoder) EncodeBytes(data []byte) ([]byte, error) { return data, ErrNoJBIG2Decode } -// -// JPX encoder/decoder (dummy, for now) -// +// JPXEncoder implements JPX encoder/decoder (dummy, for now) +// FIXME: implement type JPXEncoder struct{} func NewJPXEncoder() *JPXEncoder { @@ -1617,7 +1609,7 @@ func (this *JPXEncoder) MakeDecodeParams() PdfObject { return nil } -// Make a new instance of an encoding dictionary for a stream object. +// MakeStreamDict makes a new instance of an encoding dictionary for a stream object. func (this *JPXEncoder) MakeStreamDict() *PdfObjectDictionary { return MakeDict() } @@ -1637,9 +1629,7 @@ func (this *JPXEncoder) EncodeBytes(data []byte) ([]byte, error) { return data, ErrNoJPXDecode } -// -// Multi encoder: support serial encoding. -// +// MultiEncoder supports serial encoding. type MultiEncoder struct { // Encoders in the order that they are to be applied. encoders []StreamEncoder diff --git a/pdf/core/parser.go b/pdf/core/parser.go index f8418bba..109016ec 100755 --- a/pdf/core/parser.go +++ b/pdf/core/parser.go @@ -589,7 +589,7 @@ func (parser *PdfParser) parseObject() (PdfObject, error) { } } -// Reads and parses a PDF dictionary object enclosed with '<<' and '>>' +// ParseDict reads and parses a PDF dictionary object enclosed with '<<' and '>>' // TODO: Unexport (v3). func (parser *PdfParser) ParseDict() (*PdfObjectDictionary, error) { common.Log.Trace("Reading PDF Dict!") @@ -1325,7 +1325,7 @@ func (parser *PdfParser) traceStreamLength(lengthObj PdfObject) (PdfObject, erro return slo, nil } -// Parse an indirect object from the input stream. Can also be an object stream. +// ParseIndirectObject parses an indirect object from the input stream. Can also be an object stream. // Returns the indirect object (*PdfIndirectObject) or the stream object (*PdfObjectStream). // TODO: Unexport (v3). func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) { @@ -1504,7 +1504,7 @@ func (parser *PdfParser) ParseIndirectObject() (PdfObject, error) { return &indirect, nil } -// For testing purposes. +// NewParserFromString is used for testing purposes. // TODO: Unexport (v3) or move to test files, if needed by external test cases. func NewParserFromString(txt string) *PdfParser { parser := PdfParser{} diff --git a/pdf/core/primitives.go b/pdf/core/primitives.go index 3daae1d2..80366915 100644 --- a/pdf/core/primitives.go +++ b/pdf/core/primitives.go @@ -17,10 +17,10 @@ import ( // PdfObject is an interface which all primitive PDF objects must implement. type PdfObject interface { - // Output a string representation of the primitive (for debugging). + // String outputs a string representation of the primitive (for debugging). String() string - // Output the PDF primitive as written to file as expected by the standard. + // DefaultWriteString outputs the PDF primitive as written to file as expected by the standard. DefaultWriteString() string } @@ -869,7 +869,7 @@ func GetStringVal(obj PdfObject) (val string, found bool) { return } -// GetStringVal is like GetStringVal except that it returns the string as a []byte. +// GetStringBytes is like GetStringVal except that it returns the string as a []byte. // It is for convenience. func GetStringBytes(obj PdfObject) (val []byte, found bool) { so, found := TraceToDirectObject(obj).(*PdfObjectString) diff --git a/pdf/creator/drawable.go b/pdf/creator/drawable.go index 1243a8c6..9812300b 100644 --- a/pdf/creator/drawable.go +++ b/pdf/creator/drawable.go @@ -7,7 +7,7 @@ package creator // Drawable is a widget that can be used to draw with the Creator. type Drawable interface { - // Draw onto blocks representing Page contents. As the content can wrap over many pages, multiple + // GeneratePageBlocks draw onto blocks representing Page contents. As the content can wrap over many pages, multiple // templates are returned, one per Page. The function also takes a draw context containing information // where to draw (if relative positioning) and the available height to draw on accounting for Margins etc. GeneratePageBlocks(ctx DrawContext) ([]*Block, DrawContext, error) diff --git a/pdf/creator/table.go b/pdf/creator/table.go index cc32c8f0..238d491c 100644 --- a/pdf/creator/table.go +++ b/pdf/creator/table.go @@ -468,10 +468,10 @@ type CellBorderStyle int // Currently supported table styles are: None (no border) and boxed (line along each side). const ( - // No border - CellBorderStyleNone CellBorderStyle = iota + CellBorderStyleNone CellBorderStyle = iota // no border // Borders along all sides (boxed). + CellBorderStyleSingle CellBorderStyleDouble ) @@ -501,13 +501,13 @@ type CellHorizontalAlignment int // Table cells have three horizontal alignment modes: left, center and right. const ( - // Align cell content on the left (with specified indent); unused space on the right. + // CellHorizontalAlignmentLeft aligns cell content on the left (with specified indent); unused space on the right. CellHorizontalAlignmentLeft CellHorizontalAlignment = iota - // Align cell content in the middle (unused space divided equally on the left/right). + // CellHorizontalAlignmentCenter aligns cell content in the middle (unused space divided equally on the left/right). CellHorizontalAlignmentCenter - // Align the cell content on the right; unsued space on the left. + // CellHorizontalAlignmentRight aligns the cell content on the right; unsued space on the left. CellHorizontalAlignmentRight ) @@ -516,13 +516,13 @@ type CellVerticalAlignment int // Table cells have three vertical alignment modes: top, middle and bottom. const ( - // Align cell content vertically to the top; unused space below. + // CellVerticalAlignmentTop aligns cell content vertically to the top; unused space below. CellVerticalAlignmentTop CellVerticalAlignment = iota - // Align cell content in the middle; unused space divided equally above and below. + // CellVerticalAlignmentMiddle aligns cell content in the middle; unused space divided equally above and below. CellVerticalAlignmentMiddle - // Align cell content on the bottom; unused space above. + // CellVerticalAlignmentBottom aligns cell content on the bottom; unused space above. CellVerticalAlignmentBottom ) diff --git a/pdf/internal/sampling/resample.go b/pdf/internal/sampling/resample.go index e9447f88..c4d2247e 100644 --- a/pdf/internal/sampling/resample.go +++ b/pdf/internal/sampling/resample.go @@ -5,7 +5,7 @@ package sampling -// Resample the raw data which is in 8-bit (byte) format as a different +// ResampleBytes resamples the raw data which is in 8-bit (byte) format as a different // bit count per sample, up to 32 bits (uint32). func ResampleBytes(data []byte, bitsPerSample int) []uint32 { var samples []uint32 @@ -96,7 +96,7 @@ func ResampleBytes(data []byte, bitsPerSample int) []uint32 { return samples } -// Resample the raw data which is in <=32-bit (uint32) format as a different +// ResampleUint32 resamples the raw data which is in <=32-bit (uint32) format as a different // bit count per sample, up to 32 bits (uint32). // // bitsPerOutputSample is the number of bits for each output sample (up to 32) diff --git a/pdf/model/colorspace.go b/pdf/model/colorspace.go index 9b908976..a0c1c690 100644 --- a/pdf/model/colorspace.go +++ b/pdf/model/colorspace.go @@ -219,7 +219,7 @@ func (this *PdfColorDeviceGray) Val() float64 { return float64(*this) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorDeviceGray) ToInteger(bits int) uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return uint32(maxVal * this.Val()) @@ -282,7 +282,7 @@ func (this *PdfColorspaceDeviceGray) ColorFromPdfObjects(objects []PdfObject) (P return this.ColorFromFloats(floats) } -// Convert gray -> rgb for a single color component. +// ColorToRGB converts gray -> rgb for a single color component. func (this *PdfColorspaceDeviceGray) ColorToRGB(color PdfColor) (PdfColor, error) { gray, ok := color.(*PdfColorDeviceGray) if !ok { @@ -293,7 +293,7 @@ func (this *PdfColorspaceDeviceGray) ColorToRGB(color PdfColor) (PdfColor, error return NewPdfColorDeviceRGB(float64(*gray), float64(*gray), float64(*gray)), nil } -// Convert 1-component grayscale data to 3-component RGB. +// ImageToRGB convert 1-component grayscale data to 3-component RGB. func (this *PdfColorspaceDeviceGray) ImageToRGB(img Image) (Image, error) { rgbImage := img @@ -343,7 +343,7 @@ func (this *PdfColorDeviceRGB) B() float64 { return float64(this[2]) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorDeviceRGB) ToInteger(bits int) [3]uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return [3]uint32{uint32(maxVal * this.R()), uint32(maxVal * this.G()), uint32(maxVal * this.B())} @@ -412,7 +412,7 @@ func (this *PdfColorspaceDeviceRGB) ColorFromFloats(vals []float64) (PdfColor, e } -// Get the color from a series of pdf objects (3 for rgb). +// ColorFromPdfObjects gets the color from a series of pdf objects (3 for rgb). func (this *PdfColorspaceDeviceRGB) ColorFromPdfObjects(objects []PdfObject) (PdfColor, error) { if len(objects) != 3 { return nil, errors.New("Range check") @@ -473,7 +473,7 @@ func (this *PdfColorspaceDeviceRGB) ImageToGray(img Image) (Image, error) { // C, M, Y, K components. // No other parameters. -// Each component is defined in the range 0.0 - 1.0 where 1.0 is the primary intensity. +// PdfColorDeviceCMYK is a CMYK color, where each component is defined in the range 0.0 - 1.0 where 1.0 is the primary intensity. type PdfColorDeviceCMYK [4]float64 func NewPdfColorDeviceCMYK(c, m, y, k float64) *PdfColorDeviceCMYK { @@ -501,7 +501,7 @@ func (this *PdfColorDeviceCMYK) K() float64 { return float64(this[3]) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorDeviceCMYK) ToInteger(bits int) [4]uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return [4]uint32{uint32(maxVal * this.C()), uint32(maxVal * this.M()), uint32(maxVal * this.Y()), uint32(maxVal * this.K())} @@ -563,7 +563,7 @@ func (this *PdfColorspaceDeviceCMYK) ColorFromFloats(vals []float64) (PdfColor, return color, nil } -// Get the color from a series of pdf objects (4 for cmyk). +// ColorFromPdfObjects gets the color from a series of pdf objects (4 for cmyk). func (this *PdfColorspaceDeviceCMYK) ColorFromPdfObjects(objects []PdfObject) (PdfColor, error) { if len(objects) != 4 { return nil, errors.New("Range check") @@ -679,13 +679,13 @@ func (this *PdfColorCalGray) Val() float64 { return float64(*this) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorCalGray) ToInteger(bits int) uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return uint32(maxVal * this.Val()) } -// CalGray color space. +// PdfColorspaceCalGray represents CalGray color space. type PdfColorspaceCalGray struct { WhitePoint []float64 // [XW, YW, ZW]: Required BlackPoint []float64 // [XB, YB, ZB] @@ -886,7 +886,7 @@ func (this *PdfColorspaceCalGray) ColorToRGB(color PdfColor) (PdfColor, error) { return NewPdfColorDeviceRGB(r, g, b), nil } -// A, B, C -> X, Y, Z +// ImageToRGB converts image in CalGray color space to RGB (A, B, C -> X, Y, Z). func (this *PdfColorspaceCalGray) ImageToRGB(img Image) (Image, error) { rgbImage := img @@ -956,13 +956,13 @@ func (this *PdfColorCalRGB) C() float64 { return float64(this[2]) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorCalRGB) ToInteger(bits int) [3]uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return [3]uint32{uint32(maxVal * this.A()), uint32(maxVal * this.B()), uint32(maxVal * this.C())} } -// A, B, C components +// PdfColorspaceCalRGB stores A, B, C components type PdfColorspaceCalRGB struct { WhitePoint []float64 BlackPoint []float64 @@ -973,8 +973,8 @@ type PdfColorspaceCalRGB struct { container *PdfIndirectObject } -// require parameters? func NewPdfColorspaceCalRGB() *PdfColorspaceCalRGB { + // TODO: require parameters? cs := &PdfColorspaceCalRGB{} // Set optional parameters to default values. @@ -1106,7 +1106,7 @@ func newPdfColorspaceCalRGBFromPdfObject(obj PdfObject) (*PdfColorspaceCalRGB, e return cs, nil } -// Return as PDF object format [name dictionary] +// ToPdfObject returns colorspace in a PDF object format [name dictionary] func (this *PdfColorspaceCalRGB) ToPdfObject() PdfObject { // CalRGB color space dictionary.. cspace := &PdfObjectArray{} @@ -1289,13 +1289,13 @@ func (this *PdfColorLab) B() float64 { return float64(this[2]) } -// Convert to an integer format. +// ToInteger convert to an integer format. func (this *PdfColorLab) ToInteger(bits int) [3]uint32 { maxVal := math.Pow(2, float64(bits)) - 1 return [3]uint32{uint32(maxVal * this.L()), uint32(maxVal * this.A()), uint32(maxVal * this.B())} } -// L*, a*, b* 3 component colorspace. +// PdfColorspaceLab is a L*, a*, b* 3 component colorspace. type PdfColorspaceLab struct { WhitePoint []float64 // Required. BlackPoint []float64 @@ -1327,8 +1327,8 @@ func (this *PdfColorspaceLab) DecodeArray() []float64 { return decode } -// require parameters? func NewPdfColorspaceLab() *PdfColorspaceLab { + // TODO: require parameters? cs := &PdfColorspaceLab{} // Set optional parameters to default values. @@ -1429,7 +1429,7 @@ func newPdfColorspaceLabFromPdfObject(obj PdfObject) (*PdfColorspaceLab, error) return cs, nil } -// Return as PDF object format [name dictionary] +// ToPdfObject returns colorspace in a PDF object format [name dictionary] func (this *PdfColorspaceLab) ToPdfObject() PdfObject { // CalRGB color space dictionary.. csObj := MakeArray() @@ -1668,7 +1668,7 @@ func (this *PdfColorICCBased) ToInteger(bits int) []uint32 { */ // See p. 157 for calculations... -// format [/ICCBased stream] +// PdfColorspaceICCBased format [/ICCBased stream] // // The stream shall contain the ICC profile. // A conforming reader shall support ICC.1:2004:10 as required by PDF 1.7, which will enable it @@ -1801,7 +1801,7 @@ func newPdfColorspaceICCBasedFromPdfObject(obj PdfObject) (*PdfColorspaceICCBase return cs, nil } -// Return as PDF object format [name stream] +// ToPdfObject returns colorspace in a PDF object format [name stream] func (this *PdfColorspaceICCBased) ToPdfObject() PdfObject { csObj := &PdfObjectArray{} @@ -1955,7 +1955,7 @@ type PdfColorPattern struct { PatternName PdfObjectName // Name of the pattern (reference via resource dicts). } -// Pattern colorspace. +// PdfColorspaceSpecialPattern is a Pattern colorspace. // Can be defined either as /Pattern or with an underlying colorspace [/Pattern cs]. type PdfColorspaceSpecialPattern struct { UnderlyingCS PdfColorspace @@ -2053,6 +2053,7 @@ func (this *PdfColorspaceSpecialPattern) ColorFromFloats(vals []float64) (PdfCol return this.UnderlyingCS.ColorFromFloats(vals) } +// ColorFromPdfObjects loads the color from PDF objects. // The first objects (if present) represent the color in underlying colorspace. The last one represents // the name of the pattern. func (this *PdfColorspaceSpecialPattern) ColorFromPdfObjects(objects []PdfObject) (PdfColor, error) { @@ -2087,7 +2088,7 @@ func (this *PdfColorspaceSpecialPattern) ColorFromPdfObjects(objects []PdfObject return patternColor, nil } -// Only converts color used with uncolored patterns (defined in underlying colorspace). Does not go into the +// ColorToRGB only converts color used with uncolored patterns (defined in underlying colorspace). Does not go into the // pattern objects and convert those. If that is desired, needs to be done separately. See for example // grayscale conversion example in unidoc-examples repo. func (this *PdfColorspaceSpecialPattern) ColorToRGB(color PdfColor) (PdfColor, error) { @@ -2109,15 +2110,14 @@ func (this *PdfColorspaceSpecialPattern) ColorToRGB(color PdfColor) (PdfColor, e return this.UnderlyingCS.ColorToRGB(patternColor.Color) } -// An image cannot be defined in a pattern colorspace, returns an error. +// ImageToRGB returns an error since an image cannot be defined in a pattern colorspace. func (this *PdfColorspaceSpecialPattern) ImageToRGB(img Image) (Image, error) { common.Log.Debug("Error: Image cannot be specified in Pattern colorspace") return img, errors.New("Invalid colorspace for image (pattern)") } -////////////////////// -// Indexed colorspace. An indexed color space is a lookup table, where the input element is an index to the lookup -// table and the output is a color defined in the lookup table in the Base colorspace. +// PdfColorspaceSpecialIndexed is an indexed color space is a lookup table, where the input element is an index to the +// lookup table and the output is a color defined in the lookup table in the Base colorspace. // [/Indexed base hival lookup] type PdfColorspaceSpecialIndexed struct { Base PdfColorspace @@ -2284,7 +2284,7 @@ func (this *PdfColorspaceSpecialIndexed) ColorToRGB(color PdfColor) (PdfColor, e return this.Base.ColorToRGB(color) } -// Convert an indexed image to RGB. +// ImageToRGB convert an indexed image to RGB. func (this *PdfColorspaceSpecialIndexed) ImageToRGB(img Image) (Image, error) { //baseImage := img // Make a new representation of the image to be converted with the base colorspace. @@ -2329,7 +2329,7 @@ func (this *PdfColorspaceSpecialIndexed) ImageToRGB(img Image) (Image, error) { return this.Base.ImageToRGB(baseImage) } -// [/Indexed base hival lookup] +// ToPdfObject converts colorspace to a PDF object. [/Indexed base hival lookup] func (this *PdfColorspaceSpecialIndexed) ToPdfObject() PdfObject { csObj := MakeArray(MakeName("Indexed")) csObj.Append(this.Base.ToPdfObject()) @@ -2344,8 +2344,7 @@ func (this *PdfColorspaceSpecialIndexed) ToPdfObject() PdfObject { return csObj } -////////////////////// -// Separation colorspace. +// PdfColorspaceSpecialSeparation is a Separation colorspace. // At the moment the colour space is set to a Separation space, the conforming reader shall determine whether the // device has an available colorant (e.g. dye) corresponding to the name of the requested space. If so, the conforming // reader shall ignore the alternateSpace and tintTransform parameters; subsequent painting operations within the diff --git a/pdf/model/fields.go b/pdf/model/fields.go index dee44309..678e6a67 100644 --- a/pdf/model/fields.go +++ b/pdf/model/fields.go @@ -25,17 +25,20 @@ const ( FieldFlagClear FieldFlag = 0 // Flags for all field types. + FieldFlagReadOnly FieldFlag = 1 FieldFlagRequired FieldFlag = (1 << 1) FieldFlagNoExport FieldFlag = (2 << 1) // Flags for button fields only. + FieldFlagNoToggleToOff FieldFlag = (1 << 14) FieldFlagRadio FieldFlag = (1 << 15) FieldFlagPushbutton FieldFlag = (1 << 16) FieldFlagRadiosInUnision FieldFlag = (1 << 25) // Flags for text fields only. + FieldFlagMultiline FieldFlag = (1 << 12) FieldFlagPassword FieldFlag = (1 << 13) FieldFlagFileSelect FieldFlag = (1 << 20) @@ -44,9 +47,11 @@ const ( FieldFlagRichText FieldFlag = (1 << 25) // Flags for text and choice fields. + FieldFlagDoNotSpellCheck FieldFlag = (1 << 22) // Flags for choice fields only. + FieldFlagCombo FieldFlag = (1 << 17) FieldFlagEdit FieldFlag = (1 << 18) FieldFlagSort FieldFlag = (1 << 19) diff --git a/pdf/model/fonts/ttfparser.go b/pdf/model/fonts/ttfparser.go index 0c86cf5d..303348ca 100644 --- a/pdf/model/fonts/ttfparser.go +++ b/pdf/model/fonts/ttfparser.go @@ -157,7 +157,7 @@ func NewFontFile2FromPdfObject(obj core.PdfObject) (TtfType, error) { return t.Parse() } -// NewFontFile2FromPdfObject returns a TtfType describing the TrueType font file in disk file `fileStr`. +// TtfParse returns a TtfType describing the TrueType font file in disk file `fileStr`. func TtfParse(fileStr string) (TtfType, error) { f, err := os.Open(fileStr) if err != nil { @@ -169,7 +169,7 @@ func TtfParse(fileStr string) (TtfType, error) { return t.Parse() } -// NewFontFile2FromPdfObject returns a TtfType describing the TrueType font file in io.Reader `t`.f. +// Parse returns a TtfType describing the TrueType font file in io.Reader `t`.f. func (t *ttfParser) Parse() (TtfType, error) { version, err := t.ReadStr(4) @@ -813,7 +813,7 @@ func (t *ttfParser) ReadULong() (val uint32) { return val } -// ReadULong reads 4 bytes and returns them as a float, the first 2 bytes for the whole number and +// Read32Fixed reads 4 bytes and returns them as a float, the first 2 bytes for the whole number and // the second 2 bytes for the fraction. func (t *ttfParser) Read32Fixed() float64 { whole := float64(t.ReadShort()) diff --git a/pdf/model/functions.go b/pdf/model/functions.go index 96e3afe3..2d39b65d 100644 --- a/pdf/model/functions.go +++ b/pdf/model/functions.go @@ -95,11 +95,9 @@ func interpolate(x, xmin, xmax, ymin, ymax float64) float64 { return y } -// -// Type 0 functions use a sequence of sample values (contained in a stream) to provide an approximation +// PdfFunctionType0 uses a sequence of sample values (contained in a stream) to provide an approximation // for functions whose domains and ranges are bounded. The samples are organized as an m-dimensional // table in which each entry has n components -// type PdfFunctionType0 struct { Domain []float64 // required; 2*m length; where m is the number of input values Range []float64 // required (type 0); 2*n length; where n is the number of output values @@ -360,13 +358,11 @@ func (this *PdfFunctionType0) processSamples() error { return nil } -// -// Type 2 functions define an exponential interpolation of one input value and n +// PdfFunctionType2 defines an exponential interpolation of one input value and n // output values: // f(x) = y_0, ..., y_(n-1) // y_j = C0_j + x^N * (C1_j - C0_j); for 0 <= j < n // When N=1 ; linear interpolation between C0 and C1. -// type PdfFunctionType2 struct { Domain []float64 Range []float64 @@ -543,10 +539,8 @@ func (this *PdfFunctionType2) Evaluate(x []float64) ([]float64, error) { return y, nil } -// -// Type 3 functions define stitching of the subdomains of serveral 1-input functions to produce +// PdfFunctionType3 defines stitching of the subdomains of serveral 1-input functions to produce // a single new 1-input function. -// type PdfFunctionType3 struct { Domain []float64 Range []float64 @@ -724,9 +718,7 @@ func (this *PdfFunctionType3) ToPdfObject() PdfObject { } } -// -// Type 4. Postscript calculator functions. -// +// PdfFunctionType4 is a Postscript calculator functions. type PdfFunctionType4 struct { Domain []float64 Range []float64 @@ -738,7 +730,7 @@ type PdfFunctionType4 struct { container *PdfObjectStream } -// Input [x1 x2 x3] +// Evaluate runs the function. Input is [x1 x2 x3]. func (this *PdfFunctionType4) Evaluate(xVec []float64) ([]float64, error) { if this.executor == nil { this.executor = ps.NewPSExecutor(this.Program) diff --git a/pdf/model/image.go b/pdf/model/image.go index 0cf2f1bb..0d5ba0ed 100644 --- a/pdf/model/image.go +++ b/pdf/model/image.go @@ -221,7 +221,7 @@ type ImageHandler interface { // Read any image type and load into a new Image object. Read(r io.Reader) (*Image, error) - // Load a unidoc Image from a standard Go image structure. + // NewImageFromGoImage load a unidoc Image from a standard Go image structure. NewImageFromGoImage(goimg goimage.Image) (*Image, error) // Compress an image. @@ -231,7 +231,7 @@ type ImageHandler interface { // DefaultImageHandler is the default implementation of the ImageHandler using the standard go library. type DefaultImageHandler struct{} -// Create a unidoc Image from a golang Image. +// NewImageFromGoImage creates a unidoc Image from a golang Image. func (ih DefaultImageHandler) NewImageFromGoImage(goimg goimage.Image) (*Image, error) { // Speed up jpeg encoding by converting to RGBA first. // Will not be required once the golang image/jpeg package is optimized. @@ -289,7 +289,7 @@ func (ih DefaultImageHandler) Compress(input *Image, quality int64) (*Image, err return input, nil } -// ImageHandler is used for handling images. +// ImageHandling is used for handling images. var ImageHandling ImageHandler = DefaultImageHandler{} // SetImageHandler sets the image handler used by the package. diff --git a/pdf/model/outlines.go b/pdf/model/outlines.go index 6f43e95c..0deb28cb 100644 --- a/pdf/model/outlines.go +++ b/pdf/model/outlines.go @@ -233,7 +233,7 @@ func (this *PdfOutline) GetContainingPdfObject() PdfObject { return this.primitive } -// Recursively build the Outline tree PDF object. +// ToPdfObject recursively builds the Outline tree PDF object. func (this *PdfOutline) ToPdfObject() PdfObject { container := this.primitive dict := container.PdfObject.(*PdfObjectDictionary) @@ -260,8 +260,7 @@ func (this *PdfOutlineItem) GetContainingPdfObject() PdfObject { return this.primitive } -// Outline item. -// Recursively build the Outline tree PDF object. +// ToPdfObject recursively builds the Outline tree PDF object. func (this *PdfOutlineItem) ToPdfObject() PdfObject { container := this.primitive dict := container.PdfObject.(*PdfObjectDictionary) diff --git a/pdf/model/page.go b/pdf/model/page.go index 834b7918..d73526bb 100644 --- a/pdf/model/page.go +++ b/pdf/model/page.go @@ -362,7 +362,7 @@ func (reader *PdfReader) LoadAnnotations(d *PdfObjectDictionary) ([]*PdfAnnotati return annotations, nil } -// Get the inheritable media box value, either from the page +// GetMediaBox gets the inheritable media box value, either from the page // or a higher up page/pages struct. func (this *PdfPage) GetMediaBox() (*PdfRectangle, error) { if this.MediaBox != nil { @@ -441,7 +441,7 @@ func (this *PdfPage) getResources() (*PdfPageResources, error) { return nil, nil } -// Convert the Page to a PDF object dictionary. +// GetPageDict convert the Page to a PDF object dictionary. func (this *PdfPage) GetPageDict() *PdfObjectDictionary { p := this.pageDict p.Clear() @@ -547,7 +547,7 @@ func (this *PdfPage) AddImageResource(name PdfObjectName, ximg *XObjectImage) er return nil } -// Check if has XObject resource by name. +// HasXObjectByName checks if has XObject resource by name. func (this *PdfPage) HasXObjectByName(name PdfObjectName) bool { xresDict, has := this.Resources.XObject.(*PdfObjectDictionary) if !has { @@ -561,7 +561,7 @@ func (this *PdfPage) HasXObjectByName(name PdfObjectName) bool { } } -// Get XObject by name. +// GetXObjectByName get XObject by name. func (this *PdfPage) GetXObjectByName(name PdfObjectName) (PdfObject, bool) { xresDict, has := this.Resources.XObject.(*PdfObjectDictionary) if !has { @@ -575,7 +575,7 @@ func (this *PdfPage) GetXObjectByName(name PdfObjectName) (PdfObject, bool) { } } -// Check if has font resource by name. +// HasFontByName checks if has font resource by name. func (this *PdfPage) HasFontByName(name PdfObjectName) bool { fontDict, has := this.Resources.Font.(*PdfObjectDictionary) if !has { @@ -589,7 +589,7 @@ func (this *PdfPage) HasFontByName(name PdfObjectName) bool { } } -// Check if ExtGState name is available. +// HasExtGState checks if ExtGState name is available. func (this *PdfPage) HasExtGState(name PdfObjectName) bool { if this.Resources == nil { return false @@ -612,7 +612,7 @@ func (this *PdfPage) HasExtGState(name PdfObjectName) bool { return has } -// Add a graphics state to the XObject resources. +// AddExtGState adds a graphics state to the XObject resources. func (this *PdfPage) AddExtGState(name PdfObjectName, egs *PdfObjectDictionary) error { if this.Resources == nil { //this.Resources = &PdfPageResources{} @@ -633,7 +633,7 @@ func (this *PdfPage) AddExtGState(name PdfObjectName, egs *PdfObjectDictionary) return nil } -// Add a font dictionary to the Font resources. +// AddFont adds a font dictionary to the Font resources. func (this *PdfPage) AddFont(name PdfObjectName, font PdfObject) error { if this.Resources == nil { this.Resources = NewPdfPageResources() @@ -661,7 +661,7 @@ type WatermarkImageOptions struct { PreserveAspectRatio bool } -// Add a watermark to the page. +// AddWatermarkImage add a watermark to the page. func (this *PdfPage) AddWatermarkImage(ximg *XObjectImage, opt WatermarkImageOptions) error { // Page dimensions. bbox, err := this.GetMediaBox() @@ -865,7 +865,7 @@ func (this *PdfPage) GetContentStreams() ([]string, error) { } } -// Get all the content streams for a page as one string. +// GetAllContentStreams gets all the content streams for a page as one string. func (this *PdfPage) GetAllContentStreams() (string, error) { cstreams, err := this.GetContentStreams() if err != nil { diff --git a/pdf/model/pattern.go b/pdf/model/pattern.go index c55ab90e..a9847569 100644 --- a/pdf/model/pattern.go +++ b/pdf/model/pattern.go @@ -30,12 +30,12 @@ func (this *PdfPattern) GetContainingPdfObject() PdfObject { return this.container } -// Context in this case is a reference to the subpattern entry: either PdfTilingPattern or PdfShadingPattern. +// GetContext returns a reference to the subpattern entry: either PdfTilingPattern or PdfShadingPattern. func (this *PdfPattern) GetContext() PdfModel { return this.context } -// Set the sub pattern (context). Either PdfTilingPattern or PdfShadingPattern. +// SetContext sets the sub pattern (context). Either PdfTilingPattern or PdfShadingPattern. func (this *PdfPattern) SetContext(ctx PdfModel) { this.context = ctx } @@ -48,17 +48,17 @@ func (this *PdfPattern) IsShading() bool { return this.PatternType == 2 } -// Check with IsTiling() prior to using this to ensure is a tiling pattern. +// GetAsTilingPattern returns a tiling pattern. Check with IsTiling() prior to using this. func (this *PdfPattern) GetAsTilingPattern() *PdfTilingPattern { return this.context.(*PdfTilingPattern) } -// Check with IsShading() prior to using this, to ensure is a shading pattern. +// GetAsShadingPattern returns a shading pattern. Check with IsShading() prior to using this. func (this *PdfPattern) GetAsShadingPattern() *PdfShadingPattern { return this.context.(*PdfShadingPattern) } -// A Tiling pattern consists of repetitions of a pattern cell with defined intervals. +// PdfTilingPattern is a Tiling pattern that consists of repetitions of a pattern cell with defined intervals. // It is a type 1 pattern. (PatternType = 1). // A tiling pattern is represented by a stream object, where the stream content is // a content stream that describes the pattern cell. @@ -111,7 +111,7 @@ func (this *PdfTilingPattern) GetContentStreamWithEncoder() ([]byte, StreamEncod return decoded, encoder, nil } -// Set the pattern cell's content stream. +// SetContentStream sets the pattern cell's content stream. func (this *PdfTilingPattern) SetContentStream(content []byte, encoder StreamEncoder) error { streamObj, ok := this.container.(*PdfObjectStream) if !ok { @@ -144,8 +144,8 @@ func (this *PdfTilingPattern) SetContentStream(content []byte, encoder StreamEnc return nil } -// Shading patterns provide a smooth transition between colors across an area to be painted, i.e. -// color(x,y) = f(x,y) at each point. +// PdfShadingPattern is a Shading patterns that provide a smooth transition between colors across an area to be painted, +// i.e. color(x,y) = f(x,y) at each point. // It is a type 2 pattern (PatternType = 2). type PdfShadingPattern struct { *PdfPattern diff --git a/pdf/model/resources.go b/pdf/model/resources.go index a0941489..4f936a84 100644 --- a/pdf/model/resources.go +++ b/pdf/model/resources.go @@ -13,7 +13,7 @@ import ( . "github.com/unidoc/unidoc/pdf/core" ) -// Page resources model. +// PdfPageResources is a Page resources model. // Implements PdfModel. type PdfPageResources struct { ExtGState PdfObject @@ -89,8 +89,8 @@ func (r *PdfPageResources) ToPdfObject() PdfObject { return d } -// Add External Graphics State (GState). The gsDict can be specified either directly as a dictionary or an indirect -// object containing a dictionary. +// AddExtGState add External Graphics State (GState). The gsDict can be specified either directly as a dictionary or an +// indirect object containing a dictionary. func (r *PdfPageResources) AddExtGState(gsName PdfObjectName, gsDict PdfObject) error { if r.ExtGState == nil { r.ExtGState = MakeDict() @@ -107,7 +107,7 @@ func (r *PdfPageResources) AddExtGState(gsName PdfObjectName, gsDict PdfObject) return nil } -// Get the ExtGState specified by keyName. Returns a bool indicating whether it was found or not. +// GetExtGState gets the ExtGState specified by keyName. Returns a bool indicating whether it was found or not. func (r *PdfPageResources) GetExtGState(keyName PdfObjectName) (PdfObject, bool) { if r.ExtGState == nil { return nil, false @@ -126,14 +126,14 @@ func (r *PdfPageResources) GetExtGState(keyName PdfObjectName) (PdfObject, bool) } } -// Check whether a font is defined by the specified keyName. +// HasExtGState checks whether a font is defined by the specified keyName. func (r *PdfPageResources) HasExtGState(keyName PdfObjectName) bool { _, has := r.GetFontByName(keyName) return has } -// Get the shading specified by keyName. Returns nil if not existing. The bool flag indicated whether it was found -// or not. +// GetShadingByName gets the shading specified by keyName. Returns nil if not existing. The bool flag indicated whether +// it was found or not. func (r *PdfPageResources) GetShadingByName(keyName PdfObjectName) (*PdfShading, bool) { if r.Shading == nil { return nil, false @@ -157,7 +157,7 @@ func (r *PdfPageResources) GetShadingByName(keyName PdfObjectName) (*PdfShading, } } -// Set a shading resource specified by keyName. +// SetShadingByName sets a shading resource specified by keyName. func (r *PdfPageResources) SetShadingByName(keyName PdfObjectName, shadingObj PdfObject) error { if r.Shading == nil { r.Shading = MakeDict() @@ -172,8 +172,8 @@ func (r *PdfPageResources) SetShadingByName(keyName PdfObjectName, shadingObj Pd return nil } -// Get the pattern specified by keyName. Returns nil if not existing. The bool flag indicated whether it was found -// or not. +// GetPatternByName gets the pattern specified by keyName. Returns nil if not existing. The bool flag indicated whether +// it was found or not. func (r *PdfPageResources) GetPatternByName(keyName PdfObjectName) (*PdfPattern, bool) { if r.Pattern == nil { return nil, false @@ -198,7 +198,7 @@ func (r *PdfPageResources) GetPatternByName(keyName PdfObjectName) (*PdfPattern, } } -// Set a pattern resource specified by keyName. +// SetPatternByName sets a pattern resource specified by keyName. func (r *PdfPageResources) SetPatternByName(keyName PdfObjectName, pattern PdfObject) error { if r.Pattern == nil { r.Pattern = MakeDict() @@ -213,7 +213,7 @@ func (r *PdfPageResources) SetPatternByName(keyName PdfObjectName, pattern PdfOb return nil } -// Get the font specified by keyName. Returns the PdfObject which the entry refers to. +// GetFontByName gets the font specified by keyName. Returns the PdfObject which the entry refers to. // Returns a bool value indicating whether or not the entry was found. func (r *PdfPageResources) GetFontByName(keyName PdfObjectName) (PdfObject, bool) { if r.Font == nil { @@ -233,13 +233,13 @@ func (r *PdfPageResources) GetFontByName(keyName PdfObjectName) (PdfObject, bool } } -// Check whether a font is defined by the specified keyName. +// HasFontByName checks whether a font is defined by the specified keyName. func (r *PdfPageResources) HasFontByName(keyName PdfObjectName) bool { _, has := r.GetFontByName(keyName) return has } -// Set the font specified by keyName to the given object. +// SetFontByName sets the font specified by keyName to the given object. func (r *PdfPageResources) SetFontByName(keyName PdfObjectName, obj PdfObject) error { if r.Font == nil { // Create if not existing. @@ -287,7 +287,7 @@ func (r *PdfPageResources) SetColorspaceByName(keyName PdfObjectName, cs PdfColo return nil } -// Check if an XObject with a specified keyName is defined. +// HasXObjectByName checks if an XObject with a specified keyName is defined. func (r *PdfPageResources) HasXObjectByName(keyName PdfObjectName) bool { obj, _ := r.GetXObjectByName(keyName) if obj != nil { @@ -321,7 +321,7 @@ const ( XObjectTypeUnknown XObjectType = iota ) -// Returns the XObject with the specified keyName and the object type. +// GetXObjectByName returns the XObject with the specified keyName and the object type. func (r *PdfPageResources) GetXObjectByName(keyName PdfObjectName) (*PdfObjectStream, XObjectType) { if r.XObject == nil { return nil, XObjectTypeUndefined diff --git a/pdf/model/shading.go b/pdf/model/shading.go index 3a6d708a..ba71320b 100644 --- a/pdf/model/shading.go +++ b/pdf/model/shading.go @@ -37,12 +37,12 @@ func (this *PdfShading) GetContainingPdfObject() PdfObject { return this.container } -// Context in this case is a reference to the subshading entry as represented by PdfShadingType1-7. +// GetContext returns a reference to the subshading entry as represented by PdfShadingType1-7. func (this *PdfShading) GetContext() PdfModel { return this.context } -// Set the sub annotation (context). +// SetContext set the sub annotation (context). func (this *PdfShading) SetContext(ctx PdfModel) { this.context = ctx } @@ -67,7 +67,7 @@ func (this *PdfShading) getShadingDict() (*PdfObjectDictionary, error) { } } -// Shading type 1: Function-based shading. +// PdfShadingType1 is a Function-based shading. type PdfShadingType1 struct { *PdfShading Domain *PdfObjectArray @@ -75,7 +75,7 @@ type PdfShadingType1 struct { Function []PdfFunction } -// Shading type 2: Axial shading. +// PdfShadingType2 is a Axial shading. type PdfShadingType2 struct { *PdfShading Coords *PdfObjectArray @@ -84,7 +84,7 @@ type PdfShadingType2 struct { Extend *PdfObjectArray } -// Shading type 3: Radial shading. +// PdfShadingType3 is a Radial shading. type PdfShadingType3 struct { *PdfShading Coords *PdfObjectArray @@ -93,7 +93,7 @@ type PdfShadingType3 struct { Extend *PdfObjectArray } -// Shading type 4: Free-form Gouraud-shaded triangle mesh. +// PdfShadingType4 is a Free-form Gouraud-shaded triangle mesh. type PdfShadingType4 struct { *PdfShading BitsPerCoordinate *PdfObjectInteger @@ -103,7 +103,7 @@ type PdfShadingType4 struct { Function []PdfFunction } -// Shading type 5: Lattice-form Gouraud-shaded triangle mesh. +// PdfShadingType5 is a Lattice-form Gouraud-shaded triangle mesh. type PdfShadingType5 struct { *PdfShading BitsPerCoordinate *PdfObjectInteger @@ -113,7 +113,7 @@ type PdfShadingType5 struct { Function []PdfFunction } -// Shading type 6: Coons patch mesh. +// PdfShadingType6 is a Coons patch mesh. type PdfShadingType6 struct { *PdfShading BitsPerCoordinate *PdfObjectInteger @@ -123,7 +123,7 @@ type PdfShadingType6 struct { Function []PdfFunction } -// Shading type 7: Tensor-product patch mesh. +// PdfShadingType7 is a Tensor-product patch mesh. type PdfShadingType7 struct { *PdfShading BitsPerCoordinate *PdfObjectInteger diff --git a/pdf/model/structures.go b/pdf/model/structures.go index 9bac263a..4fdbffe7 100644 --- a/pdf/model/structures.go +++ b/pdf/model/structures.go @@ -17,7 +17,7 @@ import ( . "github.com/unidoc/unidoc/pdf/core" ) -// Definition of a rectangle. +// PdfRectangle is a definition of a rectangle. type PdfRectangle struct { Llx float64 // Lower left corner (ll). Lly float64 @@ -58,7 +58,7 @@ func NewPdfRectangle(arr PdfObjectArray) (*PdfRectangle, error) { return &rect, nil } -// Convert to a PDF object. +// ToPdfObject convert rectangle to a PDF object. func (rect *PdfRectangle) ToPdfObject() PdfObject { arr := MakeArray(MakeFloat(rect.Llx), MakeFloat(rect.Lly), MakeFloat(rect.Urx), MakeFloat(rect.Ury)) return arr @@ -120,7 +120,7 @@ func NewPdfDate(dateStr string) (PdfDate, error) { return d, nil } -// Convert to a PDF string object. +// ToPdfObject converts date to a PDF string object. func (date *PdfDate) ToPdfObject() PdfObject { str := fmt.Sprintf("D:%.4d%.2d%.2d%.2d%.2d%.2d%c%.2d'%.2d'", date.year, date.month, date.day, date.hour, date.minute, date.second, diff --git a/pdf/model/writer.go b/pdf/model/writer.go index 21fce00c..7ff19b5e 100644 --- a/pdf/model/writer.go +++ b/pdf/model/writer.go @@ -250,7 +250,7 @@ func (this *PdfWriter) copyObjects() { } } -// Set the PDF version of the output file. +// SetVersion sets the PDF version of the output file. func (this *PdfWriter) SetVersion(majorVersion, minorVersion int) { this.majorVersion = majorVersion this.minorVersion = minorVersion diff --git a/pdf/model/xobject.go b/pdf/model/xobject.go index e0143320..8e96d820 100644 --- a/pdf/model/xobject.go +++ b/pdf/model/xobject.go @@ -37,7 +37,7 @@ type XObjectForm struct { primitive *PdfObjectStream } -// Create a brand new XObject Form. Creates a new underlying PDF object stream primitive. +// NewXObjectForm creates a brand new XObject Form. Creates a new underlying PDF object stream primitive. func NewXObjectForm() *XObjectForm { xobj := &XObjectForm{} stream := &PdfObjectStream{} @@ -46,8 +46,8 @@ func NewXObjectForm() *XObjectForm { return xobj } -// Build the Form XObject from a stream object. -// XXX: Should this be exposed? Consider different access points. +// NewXObjectFormFromStream builds the Form XObject from a stream object. +// TODO: Should this be exposed? Consider different access points. func NewXObjectFormFromStream(stream *PdfObjectStream) (*XObjectForm, error) { form := &XObjectForm{} form.primitive = stream @@ -127,8 +127,8 @@ func (xform *XObjectForm) GetContentStream() ([]byte, error) { return decoded, nil } -// Update the content stream with specified encoding. If encoding is null, will use the xform.Filter object -// or Raw encoding if not set. +// SetContentStream updates the content stream with specified encoding. If encoding is null, will use the xform.Filter +// object or Raw encoding if not set. func (xform *XObjectForm) SetContentStream(content []byte, encoder StreamEncoder) error { encoded := content @@ -152,7 +152,7 @@ func (xform *XObjectForm) SetContentStream(content []byte, encoder StreamEncoder return nil } -// Return a stream object. +// ToPdfObject return a stream object. func (xform *XObjectForm) ToPdfObject() PdfObject { stream := xform.primitive @@ -226,7 +226,7 @@ func NewXObjectImage() *XObjectImage { return xobj } -// Creates a new XObject Image from an image object with default options. +// NewXObjectImageFromImage creates a new XObject Image from an image object with default options. // If encoder is nil, uses raw encoding (none). func NewXObjectImageFromImage(img *Image, cs PdfColorspace, encoder StreamEncoder) (*XObjectImage, error) { xobj := NewXObjectImage() @@ -367,7 +367,7 @@ func toGray(matte *PdfObjectArray) (float64, error) { return 0.0, err } -// Build the image xobject from a stream object. +// NewXObjectImageFromStream build the image xobject from a stream object. // An image dictionary is the dictionary portion of a stream object representing an image XObject. func NewXObjectImageFromStream(stream *PdfObjectStream) (*XObjectImage, error) { img := &XObjectImage{} @@ -445,7 +445,7 @@ func NewXObjectImageFromStream(stream *PdfObjectStream) (*XObjectImage, error) { return img, nil } -// Update XObject Image with new image data. +// SetImage update XObject Image with new image data. func (ximg *XObjectImage) SetImage(img *Image, cs PdfColorspace) error { encoded, err := ximg.Filter.EncodeBytes(img.Data) if err != nil { @@ -477,7 +477,7 @@ func (ximg *XObjectImage) SetImage(img *Image, cs PdfColorspace) error { return nil } -// Set compression filter. Decodes with current filter sets and encodes the data with the new filter. +// SetFilter sets compression filter. Decodes with current filter sets and encodes the data with the new filter. func (ximg *XObjectImage) SetFilter(encoder StreamEncoder) error { encoded := ximg.Stream decoded, err := ximg.Filter.DecodeBytes(encoded) @@ -495,7 +495,7 @@ func (ximg *XObjectImage) SetFilter(encoder StreamEncoder) error { return nil } -// This will convert to an Image which can be transformed or saved out. +// ToImage converts an object to an Image which can be transformed or saved out. // The image data is decoded and the Image returned. func (ximg *XObjectImage) ToImage() (*Image, error) { image := &Image{} @@ -543,7 +543,7 @@ func (ximg *XObjectImage) GetContainingPdfObject() PdfObject { return ximg.primitive } -// Return a stream object. +// ToPdfObject return a stream object. func (ximg *XObjectImage) ToPdfObject() PdfObject { stream := ximg.primitive