unipdf/contentstream/contentstream.go

555 lines
109 KiB
Go
Raw Normal View History

2020-08-27 21:45:09 +00:00
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
// Package contentstream provides functionality for parsing and creating content streams for PDF files.
//
// For processing and manipulating content streams, it allows parse the content stream into a list of
// operands that can then be processed further for rendering or extraction of information.
// The ContentStreamProcessor offers a basic engine for processing the content stream and can be used
// to render or modify the contents.
//
// For creating content streams, see NewContentCreator. It allows adding multiple operands and then can
// be converted to a string for embedding in a PDF file.
//
// The contentstream package uses the core and model packages.
2020-09-07 00:23:12 +00:00
package contentstream ;import (_cg "bufio";_b "bytes";_c "encoding/hex";_f "errors";_de "fmt";_ce "github.com/unidoc/unipdf/v3/common";_fef "github.com/unidoc/unipdf/v3/core";_fc "github.com/unidoc/unipdf/v3/internal/imageutil";_df "github.com/unidoc/unipdf/v3/internal/transform";_g "github.com/unidoc/unipdf/v3/model";_ef "image/color";_cb "image/jpeg";_cd "io";_fe "math";_d "strconv";);
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_y appends 'y' operand to the content stream: Append a Bezier curve to the current path from the
// current point to (x3,y3) with (x1, y1) and (x3,y3) as control points.
//
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_abg *ContentCreator )Add_y (x1 ,y1 ,x3 ,y3 float64 )*ContentCreator {_dec :=ContentStreamOperation {};_dec .Operand ="\u0079";_dec .Params =_ccae ([]float64 {x1 ,y1 ,x3 ,y3 });_abg ._gag =append (_abg ._gag ,&_dec );return _abg ;};type handlerEntry struct{Condition HandlerConditionEnum ;Operand string ;Handler HandlerFunc ;};func (_bed *ContentStreamParser )parseOperand ()(*_fef .PdfObjectString ,error ){var _dbb []byte ;for {_feg ,_aae :=_bed ._edc .Peek (1);if _aae !=nil {return _fef .MakeString (string (_dbb )),_aae ;};if _fef .IsDelimiter (_feg [0]){break ;};if _fef .IsWhiteSpace (_feg [0]){break ;};_bbd ,_ :=_bed ._edc .ReadByte ();_dbb =append (_dbb ,_bbd );};return _fef .MakeString (string (_dbb )),nil ;};func (_bdgg *ContentStreamProcessor )handleCommand_cs (_bacd *ContentStreamOperation ,_bfca *_g .PdfPageResources )error {if len (_bacd .Params )< 1{_ce .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069d\u0020\u0043\u0053\u0020\u0063\u006f\u006d\u006d\u0061\u006e\u0064\u002c\u0020s\u006b\u0069\u0070\u0070\u0069\u006e\u0067 \u006f\u0076\u0065\u0072");return _f .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_bacd .Params )> 1{_ce .Log .Debug ("\u0043\u0053\u0020\u0063\u006f\u006d\u006d\u0061n\u0064\u0020\u0077it\u0068\u0020\u0074\u006f\u006f\u0020m\u0061\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020-\u0020\u0063\u006f\u006e\u0074\u0069\u006e\u0075i\u006e\u0067");return _f .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_afd ,_bded :=_bacd .Params [0].(*_fef .PdfObjectName );if !_bded {_ce .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020C\u0053\u0020\u0063o\u006d\u006d\u0061n\u0064\u0020w\u0069\u0074\u0068\u0020\u0069\u006ev\u0061li\u0064\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u002c\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067\u0020\u006f\u0076\u0065\u0072");return _f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_fdac ,_agd :=_bdgg .getColorspace (string (*_afd ),_bfca );if _agd !=nil {return _agd ;};_bdgg ._bea .ColorspaceNonStroking =_fdac ;_efeac ,_agd :=_bdgg .getInitialColor (_fdac );if _agd !=nil {return _agd ;};_bdgg ._bea .ColorNonStroking =_efeac ;return nil ;};
2020-09-07 00:23:12 +00:00
// ContentStreamProcessor defines a data structure and methods for processing a content stream, keeping track of the
// current graphics state, and allowing external handlers to define their own functions as a part of the processing,
// for example rendering or extracting certain information.
type ContentStreamProcessor struct{_cegc GraphicStateStack ;_fbbd []*ContentStreamOperation ;_bea GraphicsState ;_gcbc []handlerEntry ;_ged int ;};func _ccae (_fcbg []float64 )[]_fef .PdfObject {var _cee []_fef .PdfObject ;for _ ,_ceeb :=range _fcbg {_cee =append (_cee ,_fef .MakeFloat (_ceeb ));};return _cee ;};
2020-09-07 00:23:12 +00:00
// GetEncoder returns the encoder of the inline image.
func (_bcea *ContentStreamInlineImage )GetEncoder ()(_fef .StreamEncoder ,error ){return _bdc (_bcea )};
2020-09-07 00:23:12 +00:00
// Add_K appends 'K' operand to the content stream:
// Set the stroking colorspace to DeviceCMYK and sets the c,m,y,k color (0-1 each component).
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_cbd *ContentCreator )Add_K (c ,m ,y ,k float64 )*ContentCreator {_egaa :=ContentStreamOperation {};_egaa .Operand ="\u004b";_egaa .Params =_ccae ([]float64 {c ,m ,y ,k });_cbd ._gag =append (_cbd ._gag ,&_egaa );return _cbd ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_g appends 'g' operand to the content stream:
// Same as G but used for nonstroking operations.
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_cde *ContentCreator )Add_g (gray float64 )*ContentCreator {_dcc :=ContentStreamOperation {};_dcc .Operand ="\u0067";_dcc .Params =_ccae ([]float64 {gray });_cde ._gag =append (_cde ._gag ,&_dcc );return _cde ;};
// Add_TJ appends 'TJ' operand to the content stream:
// Show one or more text string. Array of numbers (displacement) and strings.
//
// See section 9.4.3 "Text Showing Operators" and
// Table 209 (pp. 258-259 PDF32000_2008).
func (_abb *ContentCreator )Add_TJ (vals ..._fef .PdfObject )*ContentCreator {_gdb :=ContentStreamOperation {};_gdb .Operand ="\u0054\u004a";_gdb .Params =[]_fef .PdfObject {_fef .MakeArray (vals ...)};_abb ._gag =append (_abb ._gag ,&_gdb );return _abb ;};func (_accg *ContentStreamProcessor )handleCommand_scn (_ffaf *ContentStreamOperation ,_afa *_g .PdfPageResources )error {_eecd :=_accg ._bea .ColorspaceNonStroking ;if !_dab (_eecd ){if len (_ffaf .Params )!=_eecd .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_ffaf .Params ),_eecd );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_dfa ,_eecg :=_eecd .ColorFromPdfObjects (_ffaf .Params );if _eecg !=nil {_ce .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0046\u0061\u0069\u006c \u0074\u006f\u0020\u0067\u0065\u0074\u0020\u0063o\u006co\u0072\u0020\u0066\u0072\u006f\u006d\u0020\u0070\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076 \u0028\u0043\u0053\u0020\u0069\u0073\u0020\u0025\u002b\u0076\u0029",_ffaf .Params ,_eecd );return _eecg ;};_accg ._bea .ColorNonStroking =_dfa ;return nil ;};func (_afea *ContentStreamProcessor )getInitialColor (_fefg _g .PdfColorspace )(_g .PdfColor ,error ){switch _aebc :=_fefg .(type ){case *_g .PdfColorspaceDeviceGray :return _g .NewPdfColorDeviceGray (0.0),nil ;case *_g .PdfColorspaceDeviceRGB :return _g .NewPdfColorDeviceRGB (0.0,0.0,0.0),nil ;case *_g .PdfColorspaceDeviceCMYK :return _g .NewPdfColorDeviceCMYK (0.0,0.0,0.0,1.0),nil ;case *_g .PdfColorspaceCalGray :return _g .NewPdfColorCalGray (0.0),nil ;case *_g .PdfColorspaceCalRGB :return _g .NewPdfColorCalRGB (0.0,0.0,0.0),nil ;case *_g .PdfColorspaceLab :_dff :=0.0;_aeg :=0.0;_ecab :=0.0;if _aebc .Range [0]> 0{_dff =_aebc .Range [0];};if _aebc .Range [2]> 0{_aeg =_aebc .Range [2];};return _g .NewPdfColorLab (_dff ,_aeg ,_ecab ),nil ;case *_g .PdfColorspaceICCBased :if _aebc .Alternate ==nil {_ce .Log .Trace ("\u0049\u0043\u0043\u0020\u0042\u0061\u0073\u0065\u0064\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065d\u0020-\u0020\u0061\u0074\u0074\u0065\u006d\u0070\u0074\u0069\u006e\u0067\u0020\u0066\u0061\u006c\u006c\u0020\u0062a\u0063\u006b\u0020\u0028\u004e\u0020\u003d\u0020\u0025\u0064\u0029",_aebc .N );if _aebc .N ==1{_ce .Log .Trace ("\u0046\u0061\u006c\u006c\u0069\u006e\u0067\u0020\u0062\u0061\u0063k\u0020\u0074\u006f\u0020\u0044\u0065\u0076\u0069\u0063\u0065G\u0072\u0061\u0079");return _afea .getInitialColor (_g .NewPdfColorspaceDeviceGray ());}else if _aebc .N ==3{_ce .Log .Trace ("\u0046a\u006c\u006c\u0069\u006eg\u0020\u0062\u0061\u0063\u006b \u0074o\u0020D\u0065\u0076\u0069\u0063\u0065\u0052\u0047B");return _afea .getInitialColor (_g .NewPdfColorspaceDeviceRGB ());}else if _aebc .N ==4{_ce .Log .Trace ("\u0046\u0061\u006c\u006c\u0069\u006e\u0067\u0020\u0062\u0061\u0063k\u0020\u0074\u006f\u0020\u0044\u0065\u0076\u0069\u0063\u0065C\u004d\u0059\u004b");return _afea .getInitialColor (_g .NewPdfColorspaceDeviceCMYK ());}else {return nil ,_f .New ("a\u006c\u0074\u0065\u0072\u006e\u0061t\u0065\u0020\u0073\u0070\u0061\u0063e\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0049C\u0043");};};return _afea .getInitialColor (_aebc .Alternate );case *_g .PdfColorspaceSpecialIndexed :if _aebc .Base ==nil {return nil ,_f .New ("\u0069\u006e\u0064\u0065\u0078\u0065\u0064\u0020\u0062\u0061\u0073e\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069f\u0069\u0065\u0064");};return _afea .getInitialColor (_aebc .Base );case *_g .PdfColorspaceSpecialSeparation :if _aebc .AlternateSpace ==nil {return nil ,_f .New ("\u0061\u006ct\u0
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// Add_d adds 'd' operand to the content stream: Set the line dash pattern.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_fdf *ContentCreator )Add_d (dashArray []int64 ,dashPhase int64 )*ContentCreator {_ag :=ContentStreamOperation {};_ag .Operand ="\u0064";_ag .Params =[]_fef .PdfObject {};_ag .Params =append (_ag .Params ,_fef .MakeArrayFromIntegers64 (dashArray ));_ag .Params =append (_ag .Params ,_fef .MakeInteger (dashPhase ));_fdf ._gag =append (_fdf ._gag ,&_ag );return _fdf ;};func (_dafb *ContentStreamProcessor )handleCommand_RG (_efeaa *ContentStreamOperation ,_adbf *_g .PdfPageResources )error {_abda :=_g .NewPdfColorspaceDeviceRGB ();if len (_efeaa .Params )!=_abda .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020R\u0047");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_efeaa .Params ),_abda );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_fbdec ,_cfe :=_abda .ColorFromPdfObjects (_efeaa .Params );if _cfe !=nil {return _cfe ;};_dafb ._bea .ColorspaceStroking =_abda ;_dafb ._bea .ColorStroking =_fbdec ;return nil ;};func (_eac *ContentStreamInlineImage )toImageBase (_aagf *_g .PdfPageResources )(*_fc .ImageBase ,error ){if _eac ._beef !=nil {return _eac ._beef ,nil ;};_fdc :=_fc .ImageBase {};if _eac .Height ==nil {return nil ,_f .New ("\u0068e\u0069\u0067\u0068\u0074\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_degc ,_dgba :=_eac .Height .(*_fef .PdfObjectInteger );if !_dgba {return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0068e\u0069\u0067\u0068\u0074");};_fdc .Height =int (*_degc );if _eac .Width ==nil {return nil ,_f .New ("\u0077\u0069\u0064th\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_bffc ,_dgba :=_eac .Width .(*_fef .PdfObjectInteger );if !_dgba {return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0069\u0064\u0074\u0068");};_fdc .Width =int (*_bffc );_fbd ,_fff :=_eac .IsMask ();if _fff !=nil {return nil ,_fff ;};if _fbd {_fdc .BitsPerComponent =1;_fdc .ColorComponents =1;}else {if _eac .BitsPerComponent ==nil {_ce .Log .Debug ("\u0049\u006el\u0069\u006e\u0065\u0020\u0042\u0069\u0074\u0073\u0020\u0070\u0065\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u002d\u0020\u0061\u0073\u0073\u0075\u006d\u0069\u006e\u0067\u0020\u0038");_fdc .BitsPerComponent =8;}else {_bcad ,_abc :=_eac .BitsPerComponent .(*_fef .PdfObjectInteger );if !_abc {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u0020\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u0062\u0069\u0074\u0073 p\u0065\u0072\u0020\u0063o\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0020\u0076al\u0075\u0065,\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_eac .BitsPerComponent );return nil ,_f .New ("\u0042\u0050\u0043\u0020\u0054\u0079\u0070\u0065\u0020e\u0072\u0072\u006f\u0072");};_fdc .BitsPerComponent =int (*_bcad );};if _eac .ColorSpace !=nil {_dae ,_fae :=_eac .GetColorSpace (_aagf );if _fae !=nil {return nil ,_fae ;};_fdc .ColorComponents =_dae .GetNumComponents ();}else {_ce .Log .Debug ("\u0049\u006el\u0069\u006e\u0065\u0020\u0049\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063e\u0020\u006e\u006f\u0074\u0020\u0073p\u0065\u0063\u0069\u0066\u0069\u0065\u0064\u0020\u002d\u0020\u0061\u0073\u0073\u0075m\u0069\u006eg\u0020\u0031\u0020\u0063o\u006c\u006f\u0072\u0020\u0063o\u006d\u0070\u006f\u006e\u0065\u006e\u0074");_fdc .ColorComponents =1;};};if _fagf ,_febd :=_fef .GetArray (_eac .Decode );_febd {_fdc .Decode ,_fff =_fagf .ToFloat64Array ();if _fff !=nil {return nil ,_fff ;};};_eac ._beef =&_fdc ;return _eac ._beef ,nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_G appends 'G' operand to the content stream:
// Set the stroking colorspace to DeviceGray and sets the gray level (0-1).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_adb *ContentCreator )Add_G (gray float64 )*ContentCreator {_egdb :=ContentStreamOperation {};_egdb .Operand ="\u0047";_egdb .Params =_ccae ([]float64 {gray });_adb ._gag =append (_adb ._gag ,&_egdb );return _adb ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_EMC appends 'EMC' operand to the content stream:
// Ends a marked-content sequence.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
func (_gfe *ContentCreator )Add_EMC ()*ContentCreator {_ecc :=ContentStreamOperation {};_ecc .Operand ="\u0045\u004d\u0043";_gfe ._gag =append (_gfe ._gag ,&_ecc );return _gfe ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_SCN appends 'SCN' operand to the content stream:
// Same as SC but supports more colorspaces.
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_cce *ContentCreator )Add_SCN (c ...float64 )*ContentCreator {_bgc :=ContentStreamOperation {};_bgc .Operand ="\u0053\u0043\u004e";_bgc .Params =_ccae (c );_cce ._gag =append (_cce ._gag ,&_bgc );return _cce ;};
// String is same as Bytes() except returns as a string for convenience.
func (_ed *ContentCreator )String ()string {return string (_ed ._gag .Bytes ())};
// Add_Tj appends 'Tj' operand to the content stream:
// Show a text string.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 9.4.3 "Text Showing Operators" and
// Table 209 (pp. 258-259 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_eca *ContentCreator )Add_Tj (textstr _fef .PdfObjectString )*ContentCreator {_egg :=ContentStreamOperation {};_egg .Operand ="\u0054\u006a";_egg .Params =_bgaga ([]_fef .PdfObjectString {textstr });_eca ._gag =append (_eca ._gag ,&_egg );return _eca ;};func (_ddc *ContentStreamParser )parseNumber ()(_fef .PdfObject ,error ){return _fef .ParseNumber (_ddc ._edc );};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// HandlerFunc is the function syntax that the ContentStreamProcessor handler must implement.
type HandlerFunc func (_cbc *ContentStreamOperation ,_ggag GraphicsState ,_agfg *_g .PdfPageResources )error ;
// ContentStreamParser represents a content stream parser for parsing content streams in PDFs.
type ContentStreamParser struct{_edc *_cg .Reader };
// Scale applies x-y scaling to the transformation matrix.
func (_fddd *ContentCreator )Scale (sx ,sy float64 )*ContentCreator {return _fddd .Add_cm (sx ,0,0,sy ,0,0);};
// ContentStreamOperation represents an operation in PDF contentstream which consists of
// an operand and parameters.
type ContentStreamOperation struct{Params []_fef .PdfObject ;Operand string ;};func (_aafa *ContentStreamInlineImage )String ()string {_bgad :=_de .Sprintf ("I\u006el\u0069\u006e\u0065\u0049\u006d\u0061\u0067\u0065(\u006c\u0065\u006e\u003d%d\u0029\u000a",len (_aafa ._debc ));if _aafa .BitsPerComponent !=nil {_bgad +="\u002d\u0020\u0042\u0050\u0043\u0020"+_aafa .BitsPerComponent .WriteString ()+"\u000a";};if _aafa .ColorSpace !=nil {_bgad +="\u002d\u0020\u0043S\u0020"+_aafa .ColorSpace .WriteString ()+"\u000a";};if _aafa .Decode !=nil {_bgad +="\u002d\u0020\u0044\u0020"+_aafa .Decode .WriteString ()+"\u000a";};if _aafa .DecodeParms !=nil {_bgad +="\u002d\u0020\u0044P\u0020"+_aafa .DecodeParms .WriteString ()+"\u000a";};if _aafa .Filter !=nil {_bgad +="\u002d\u0020\u0046\u0020"+_aafa .Filter .WriteString ()+"\u000a";};if _aafa .Height !=nil {_bgad +="\u002d\u0020\u0048\u0020"+_aafa .Height .WriteString ()+"\u000a";};if _aafa .ImageMask !=nil {_bgad +="\u002d\u0020\u0049M\u0020"+_aafa .ImageMask .WriteString ()+"\u000a";};if _aafa .Intent !=nil {_bgad +="\u002d \u0049\u006e\u0074\u0065\u006e\u0074 "+_aafa .Intent .WriteString ()+"\u000a";};if _aafa .Interpolate !=nil {_bgad +="\u002d\u0020\u0049\u0020"+_aafa .Interpolate .WriteString ()+"\u000a";};if _aafa .Width !=nil {_bgad +="\u002d\u0020\u0057\u0020"+_aafa .Width .WriteString ()+"\u000a";};return _bgad ;};func _aafe (_cec string )bool {_ ,_gffb :=_cgf [_cec ];return _gffb };
// String returns `ops.Bytes()` as a string.
func (_deg *ContentStreamOperations )String ()string {return string (_deg .Bytes ())};func (_fffd *ContentStreamParser )skipComments ()error {if _ ,_dagf :=_fffd .skipSpaces ();_dagf !=nil {return _dagf ;};_bbe :=true ;for {_cggbf ,_gffdb :=_fffd ._edc .Peek (1);if _gffdb !=nil {_ce .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_gffdb .Error ());return _gffdb ;};if _bbe &&_cggbf [0]!='%'{return nil ;};_bbe =false ;if (_cggbf [0]!='\r')&&(_cggbf [0]!='\n'){_fffd ._edc .ReadByte ();}else {break ;};};return _fffd .skipComments ();};
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// NewContentCreator returns a new initialized ContentCreator.
2020-09-07 00:23:12 +00:00
func NewContentCreator ()*ContentCreator {_bggb :=&ContentCreator {};_bggb ._gag =ContentStreamOperations {};return _bggb ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_CS appends 'CS' operand to the content stream:
// Set the current colorspace for stroking operations.
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_eeff *ContentCreator )Add_CS (name _fef .PdfObjectName )*ContentCreator {_cgd :=ContentStreamOperation {};_cgd .Operand ="\u0043\u0053";_cgd .Params =_febf ([]_fef .PdfObjectName {name });_eeff ._gag =append (_eeff ._gag ,&_cgd );return _eeff ;};func (_gedd *ContentStreamProcessor )handleCommand_cm (_dfae *ContentStreamOperation ,_gdbb *_g .PdfPageResources )error {if len (_dfae .Params )!=6{_ce .Log .Debug ("\u0045\u0052R\u004f\u0052\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020\u0063\u006d\u003a\u0020\u0025\u0064",len (_dfae .Params ));return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_ecbe ,_bgbd :=_fef .GetNumbersAsFloat (_dfae .Params );if _bgbd !=nil {return _bgbd ;};_gggf :=_df .NewMatrix (_ecbe [0],_ecbe [1],_ecbe [2],_ecbe [3],_ecbe [4],_ecbe [5]);_gedd ._bea .CTM .Concat (_gggf );return nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_B appends 'B' operand to the content stream:
// Fill and then stroke the path (nonzero winding number rule).
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_bc *ContentCreator )Add_B ()*ContentCreator {_egd :=ContentStreamOperation {};_egd .Operand ="\u0042";_bc ._gag =append (_bc ._gag ,&_egd );return _bc ;};func (_dbbg *ContentStreamParser )parseObject ()(_bcff _fef .PdfObject ,_caeg bool ,_cbf error ){_dbbg .skipSpaces ();for {_eddf ,_fcff :=_dbbg ._edc .Peek (2);if _fcff !=nil {return nil ,false ,_fcff ;};_ce .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_eddf ));if _eddf [0]=='%'{_dbbg .skipComments ();continue ;}else if _eddf [0]=='/'{_abd ,_bbeb :=_dbbg .parseName ();_ce .Log .Trace ("\u002d\u003e\u004ea\u006d\u0065\u003a\u0020\u0027\u0025\u0073\u0027",_abd );return &_abd ,false ,_bbeb ;}else if _eddf [0]=='('{_ce .Log .Trace ("\u002d>\u0053\u0074\u0072\u0069\u006e\u0067!");_dad ,_gcdb :=_dbbg .parseString ();return _dad ,false ,_gcdb ;}else if _eddf [0]=='<'&&_eddf [1]!='<'{_ce .Log .Trace ("\u002d\u003e\u0048\u0065\u0078\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0021");_daa ,_dcad :=_dbbg .parseHexString ();return _daa ,false ,_dcad ;}else if _eddf [0]=='['{_ce .Log .Trace ("\u002d\u003e\u0041\u0072\u0072\u0061\u0079\u0021");_gcgc ,_gfgf :=_dbbg .parseArray ();return _gcgc ,false ,_gfgf ;}else if _fef .IsFloatDigit (_eddf [0])||(_eddf [0]=='-'&&_fef .IsFloatDigit (_eddf [1])){_ce .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_beb ,_eadb :=_dbbg .parseNumber ();return _beb ,false ,_eadb ;}else if _eddf [0]=='<'&&_eddf [1]=='<'{_dgcd ,_cddc :=_dbbg .parseDict ();return _dgcd ,false ,_cddc ;}else {_ce .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_eddf ,_ =_dbbg ._edc .Peek (5);_gac :=string (_eddf );_ce .Log .Trace ("\u0063\u006f\u006e\u0074\u0020\u0050\u0065\u0065\u006b\u0020\u0073\u0074r\u003a\u0020\u0025\u0073",_gac );if (len (_gac )> 3)&&(_gac [:4]=="\u006e\u0075\u006c\u006c"){_gcfe ,_ddbf :=_dbbg .parseNull ();return &_gcfe ,false ,_ddbf ;}else if (len (_gac )> 4)&&(_gac [:5]=="\u0066\u0061\u006cs\u0065"){_fdag ,_bbag :=_dbbg .parseBool ();return &_fdag ,false ,_bbag ;}else if (len (_gac )> 3)&&(_gac [:4]=="\u0074\u0072\u0075\u0065"){_afeb ,_bdef :=_dbbg .parseBool ();return &_afeb ,false ,_bdef ;};_ecd ,_bbdf :=_dbbg .parseOperand ();if _bbdf !=nil {return _ecd ,false ,_bbdf ;};if len (_ecd .String ())< 1{return _ecd ,false ,ErrInvalidOperand ;};return _ecd ,true ,nil ;};};};func (_ccgf *ContentStreamProcessor )handleCommand_G (_abgb *ContentStreamOperation ,_gaa *_g .PdfPageResources )error {_bda :=_g .NewPdfColorspaceDeviceGray ();if len (_abgb .Params )!=_bda .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_abgb .Params ),_bda );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_adbg ,_bbba :=_bda .ColorFromPdfObjects (_abgb .Params );if _bbba !=nil {return _bbba ;};_ccgf ._bea .ColorspaceStroking =_bda ;_ccgf ._bea .ColorStroking =_adbg ;return nil ;};func (_fdad *ContentStreamParser )parseName ()(_fef .PdfObjectName ,error ){_ffg :="";_afe :=false ;for {_cece ,_dde :=_fdad ._edc .Peek (1);if _dde ==_cd .EOF {break ;};if _dde !=nil {return _fef .PdfObjectName (_ffg ),_dde ;};if !_afe {if _cece [0]=='/'{_afe =true ;_fdad ._edc .ReadByte ();}else {_ce .Log .Error ("N\u0061\u006d\u0065\u0020\u0073\u0074a\u0072\u0074\u0069\u006e\u0067\u0020\u0077\u0069\u0074h\u0020\u0025\u0073 \u0028%\u0020\u0078\u0029",_cece ,_cece );return _fef .PdfObjectName (_ffg ),_de .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006ea\u006d\u0065:\u0020\u0028\u0025\u0063\u0029",_cece [0]);};}else {if _fef .IsWhiteSpace (_cece [0]){break ;}else if (_cece [0]=='/')||(_cece
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_BMC appends 'BMC' operand to the content stream:
// Begins a marked-content sequence terminated by a balancing EMC operator.
// `tag` shall be a name object indicating the role or significance of
// the sequence.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
func (_aff *ContentCreator )Add_BMC (tag _fef .PdfObjectName )*ContentCreator {_gad :=ContentStreamOperation {};_gad .Operand ="\u0042\u004d\u0043";_gad .Params =_febf ([]_fef .PdfObjectName {tag });_aff ._gag =append (_aff ._gag ,&_gad );return _aff ;};
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// Add_ET appends 'ET' operand to the content stream:
// End text.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_ae *ContentCreator )Add_ET ()*ContentCreator {_acb :=ContentStreamOperation {};_acb .Operand ="\u0045\u0054";_ae ._gag =append (_ae ._gag ,&_acb );return _ae ;};func (_dbfg *ContentStreamParser )parseNull ()(_fef .PdfObjectNull ,error ){_ ,_adbba :=_dbfg ._edc .Discard (4);return _fef .PdfObjectNull {},_adbba ;};func (_aegb *ContentStreamProcessor )handleCommand_k (_bcge *ContentStreamOperation ,_ccb *_g .PdfPageResources )error {_dgbb :=_g .NewPdfColorspaceDeviceCMYK ();if len (_bcge .Params )!=_dgbb .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_bcge .Params ),_dgbb );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_abf ,_fgfa :=_dgbb .ColorFromPdfObjects (_bcge .Params );if _fgfa !=nil {return _fgfa ;};_aegb ._bea .ColorspaceNonStroking =_dgbb ;_aegb ._bea .ColorNonStroking =_abf ;return nil ;};func (_acgf *ContentStreamProcessor )handleCommand_K (_aefac *ContentStreamOperation ,_fab *_g .PdfPageResources )error {_bcccg :=_g .NewPdfColorspaceDeviceCMYK ();if len (_aefac .Params )!=_bcccg .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_aefac .Params ),_bcccg );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_gace ,_gadd :=_bcccg .ColorFromPdfObjects (_aefac .Params );if _gadd !=nil {return _gadd ;};_acgf ._bea .ColorspaceStroking =_bcccg ;_acgf ._bea .ColorStroking =_gace ;return nil ;};func _bgaga (_dadd []_fef .PdfObjectString )[]_fef .PdfObject {var _bbda []_fef .PdfObject ;for _ ,_bged :=range _dadd {_bbda =append (_bbda ,_fef .MakeString (_bged .Str ()));};return _bbda ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Tf appends 'Tf' operand to the content stream:
// Set font and font size specified by font resource `fontName` and `fontSize`.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
func (_eaf *ContentCreator )Add_Tf (fontName _fef .PdfObjectName ,fontSize float64 )*ContentCreator {_fefa :=ContentStreamOperation {};_fefa .Operand ="\u0054\u0066";_fefa .Params =_febf ([]_fef .PdfObjectName {fontName });_fefa .Params =append (_fefa .Params ,_ccae ([]float64 {fontSize })...);_eaf ._gag =append (_eaf ._gag ,&_fefa );return _eaf ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_m adds 'm' operand to the content stream: Move the current point to (x,y).
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_bgag *ContentCreator )Add_m (x ,y float64 )*ContentCreator {_eag :=ContentStreamOperation {};_eag .Operand ="\u006d";_eag .Params =_ccae ([]float64 {x ,y });_bgag ._gag =append (_bgag ._gag ,&_eag );return _bgag ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_scn_pattern appends 'scn' operand to the content stream for pattern `name`:
// scn with name attribute (for pattern). Syntax: c1 ... cn name scn.
2020-08-31 21:12:07 +00:00
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_acgb *ContentCreator )Add_scn_pattern (name _fef .PdfObjectName ,c ...float64 )*ContentCreator {_gcd :=ContentStreamOperation {};_gcd .Operand ="\u0073\u0063\u006e";_gcd .Params =_ccae (c );_gcd .Params =append (_gcd .Params ,_fef .MakeName (string (name )));_acgb ._gag =append (_acgb ._gag ,&_gcd );return _acgb ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Tz appends 'Tz' operand to the content stream:
// Set horizontal scaling.
2020-08-27 21:45:09 +00:00
//
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_fdae *ContentCreator )Add_Tz (scale float64 )*ContentCreator {_fdfb :=ContentStreamOperation {};_fdfb .Operand ="\u0054\u007a";_fdfb .Params =_ccae ([]float64 {scale });_fdae ._gag =append (_fdae ._gag ,&_fdfb );return _fdae ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_f_starred appends 'f*' operand to the content stream.
// f*: Fill the path using the even-odd rule to determine fill region.
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
func (_dbc *ContentCreator )Add_f_starred ()*ContentCreator {_gc :=ContentStreamOperation {};_gc .Operand ="\u0066\u002a";_dbc ._gag =append (_dbc ._gag ,&_gc );return _dbc ;};
2020-09-07 00:23:12 +00:00
// IsMask checks 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 (_acf *ContentStreamInlineImage )IsMask ()(bool ,error ){if _acf .ImageMask !=nil {_cdgc ,_cdff :=_acf .ImageMask .(*_fef .PdfObjectBool );if !_cdff {_ce .Log .Debug ("\u0049m\u0061\u0067\u0065\u0020\u006d\u0061\u0073\u006b\u0020\u006e\u006ft\u0020\u0061\u0020\u0062\u006f\u006f\u006c\u0065\u0061\u006e");return false ,_f .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u0079\u0070\u0065");};return bool (*_cdgc ),nil ;};return false ,nil ;};func _aab (_ecce _fef .PdfObject )(_g .PdfColorspace ,error ){_gede ,_eecdg :=_ecce .(*_fef .PdfObjectArray );if !_eecdg {_ce .Log .Debug ("\u0045r\u0072\u006fr\u003a\u0020\u0049\u006ev\u0061\u006c\u0069d\u0020\u0069\u006e\u0064\u0065\u0078\u0065\u0064\u0020cs\u0020\u006e\u006ft\u0020\u0069n\u0020\u0061\u0072\u0072\u0061\u0079 \u0028\u0025#\u0076\u0029",_ecce );return nil ,_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if _gede .Len ()!=4{_ce .Log .Debug ("\u0045\u0072\u0072\u006f\u0072:\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061r\u0072\u0061\u0079\u002c\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u0021\u003d\u0020\u0034\u0020\u0028\u0025\u0064\u0029",_gede .Len ());return nil ,_f .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_aaea ,_eecdg :=_gede .Get (0).(*_fef .PdfObjectName );if !_eecdg {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072\u0072\u0061\u0079\u0020\u0066\u0069\u0072s\u0074 \u0065\u006c\u0065\u006de\u006e\u0074 \u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u0020\u0028\u0061\u0072\u0072\u0061\u0079\u003a\u0020\u0025\u0023\u0076\u0029",*_gede );return nil ,_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_aaea !="\u0049"&&*_aaea !="\u0049n\u0064\u0065\u0078\u0065\u0064"{_ce .Log .Debug ("\u0045\u0072r\u006f\u0072\u003a\u0020\u0049n\u0076\u0061\u006c\u0069\u0064 \u0063\u0073\u0020\u0061\u0072\u0072\u0061\u0079\u0020\u0066\u0069\u0072\u0073\u0074\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u0021\u003d\u0020\u0049\u0020\u0028\u0067\u006f\u0074\u003a\u0020\u0025\u0076\u0029",*_aaea );return nil ,_f .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_aaea ,_eecdg =_gede .Get (1).(*_fef .PdfObjectName );if !_eecdg {_ce .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072r\u0061\u0079\u0020\u0032\u006e\u0064\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u0020\u0028\u0061\u0072\u0072a\u0079\u003a\u0020\u0025\u0023v\u0029",*_gede );return nil ,_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_aaea !="\u0047"&&*_aaea !="\u0052\u0047\u0042"&&*_aaea !="\u0043\u004d\u0059\u004b"&&*_aaea !="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"&&*_aaea !="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"&&*_aaea !="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{_ce .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072r\u0061\u0079\u0020\u0032\u006e\u0064\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u0021\u003d\u0020\u0047\u002f\u0052\u0047\u0042\u002f\u0043\u004d\u0059\u004b\u0020\u0028g\u006f\u0074\u003a\u0020\u0025v\u0029",*_aaea );return nil ,_f .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_aaff :="";switch *_aaea {case "\u0047","\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_aaff ="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079";case "\u0052\u0047\u0042","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_aaff ="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B";case "\u
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// AddHandler adds a new ContentStreamProcessor `handler` of type `condition` for `operand`.
func (_fac *ContentStreamProcessor )AddHandler (condition HandlerConditionEnum ,operand string ,handler HandlerFunc ){_gcbd :=handlerEntry {};_gcbd .Condition =condition ;_gcbd .Operand =operand ;_gcbd .Handler =handler ;_fac ._gcbc =append (_fac ._gcbc ,_gcbd );};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Operations returns the list of operations.
func (_fb *ContentCreator )Operations ()*ContentStreamOperations {return &_fb ._gag };
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_TD appends 'TD' operand to the content stream:
// Move to start of next line with offset (`tx`, `ty`).
//
// See section 9.4.2 "Text Positioning Operators" and
// Table 108 (pp. 257-258 PDF32000_2008).
func (_baeg *ContentCreator )Add_TD (tx ,ty float64 )*ContentCreator {_eaed :=ContentStreamOperation {};_eaed .Operand ="\u0054\u0044";_eaed .Params =_ccae ([]float64 {tx ,ty });_baeg ._gag =append (_baeg ._gag ,&_eaed );return _baeg ;};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// Add_Do adds 'Do' operation to the content stream:
// Displays an XObject (image or form) specified by `name`.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.8 "External Objects" and Table 87 (pp. 209-220 PDF32000_2008).
func (_dfcg *ContentCreator )Add_Do (name _fef .PdfObjectName )*ContentCreator {_eae :=ContentStreamOperation {};_eae .Operand ="\u0044\u006f";_eae .Params =_febf ([]_fef .PdfObjectName {name });_dfcg ._gag =append (_dfcg ._gag ,&_eae );return _dfcg ;};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// Pop pops and returns the topmost GraphicsState off the `gsStack`.
func (_gae *GraphicStateStack )Pop ()GraphicsState {_efeg :=(*_gae )[len (*_gae )-1];*_gae =(*_gae )[:len (*_gae )-1];return _efeg ;};func (_acab *ContentStreamProcessor )handleCommand_SC (_ace *ContentStreamOperation ,_dcb *_g .PdfPageResources )error {_ded :=_acab ._bea .ColorspaceStroking ;if len (_ace .Params )!=_ded .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_ace .Params ),_ded );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_add ,_dgd :=_ded .ColorFromPdfObjects (_ace .Params );if _dgd !=nil {return _dgd ;};_acab ._bea .ColorStroking =_add ;return nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_quote appends "'" operand to the content stream:
// Move to next line and show a string.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.4.3 "Text Showing Operators" and
// Table 209 (pp. 258-259 PDF32000_2008).
func (_gffe *ContentCreator )Add_quote (textstr _fef .PdfObjectString )*ContentCreator {_bfda :=ContentStreamOperation {};_bfda .Operand ="\u0027";_bfda .Params =_bgaga ([]_fef .PdfObjectString {textstr });_gffe ._gag =append (_gffe ._gag ,&_bfda );return _gffe ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Translate applies a simple x-y translation to the transformation matrix.
func (_bgf *ContentCreator )Translate (tx ,ty float64 )*ContentCreator {return _bgf .Add_cm (1,0,0,1,tx ,ty );};func _bdc (_dfda *ContentStreamInlineImage )(_fef .StreamEncoder ,error ){if _dfda .Filter ==nil {return _fef .NewRawEncoder (),nil ;};_bca ,_cdgg :=_dfda .Filter .(*_fef .PdfObjectName );if !_cdgg {_bfc ,_cbbb :=_dfda .Filter .(*_fef .PdfObjectArray );if !_cbbb {return nil ,_de .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072 \u006e\u006f\u0074\u0020\u0061\u0020\u004e\u0061\u006d\u0065\u0020\u006f\u0072 \u0041\u0072\u0072\u0061\u0079\u0020\u006fb\u006a\u0065\u0063\u0074");};if _bfc .Len ()==0{return _fef .NewRawEncoder (),nil ;};if _bfc .Len ()!=1{_aag ,_ebc :=_dcg (_dfda );if _ebc !=nil {_ce .Log .Error ("\u0046\u0061\u0069\u006c\u0065\u0064 \u0063\u0072\u0065\u0061\u0074\u0069\u006e\u0067\u0020\u006d\u0075\u006c\u0074i\u0020\u0065\u006e\u0063\u006f\u0064\u0065r\u003a\u0020\u0025\u0076",_ebc );return nil ,_ebc ;};_ce .Log .Trace ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063:\u0020\u0025\u0073\u000a",_aag );return _aag ,nil ;};_gcb :=_bfc .Get (0);_bca ,_cbbb =_gcb .(*_fef .PdfObjectName );if !_cbbb {return nil ,_de .Errorf ("\u0066\u0069l\u0074\u0065\u0072\u0020a\u0072\u0072a\u0079\u0020\u006d\u0065\u006d\u0062\u0065\u0072 \u006e\u006f\u0074\u0020\u0061\u0020\u004e\u0061\u006d\u0065\u0020\u006fb\u006a\u0065\u0063\u0074");};};switch *_bca {case "\u0041\u0048\u0078","\u0041\u0053\u0043\u0049\u0049\u0048\u0065\u0078\u0044e\u0063\u006f\u0064\u0065":return _fef .NewASCIIHexEncoder (),nil ;case "\u0041\u0038\u0035","\u0041\u0053\u0043\u0049\u0049\u0038\u0035\u0044\u0065\u0063\u006f\u0064\u0065":return _fef .NewASCII85Encoder (),nil ;case "\u0044\u0043\u0054","\u0044C\u0054\u0044\u0065\u0063\u006f\u0064e":return _cdf (_dfda );case "\u0046\u006c","F\u006c\u0061\u0074\u0065\u0044\u0065\u0063\u006f\u0064\u0065":return _dda (_dfda ,nil );case "\u004c\u005a\u0057","\u004cZ\u0057\u0044\u0065\u0063\u006f\u0064e":return _ccc (_dfda ,nil );case "\u0043\u0043\u0046","\u0043\u0043\u0049\u0054\u0054\u0046\u0061\u0078\u0044e\u0063\u006f\u0064\u0065":return _fef .NewCCITTFaxEncoder (),nil ;case "\u0052\u004c","\u0052u\u006eL\u0065\u006e\u0067\u0074\u0068\u0044\u0065\u0063\u006f\u0064\u0065":return _fef .NewRunLengthEncoder (),nil ;default:_ce .Log .Debug ("\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065 \u0069\u006d\u0061\u0067\u0065\u0020\u0065n\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u003a\u0020\u0025\u0073",*_bca );return nil ,_f .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006el\u0069n\u0065 \u0065n\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};};
// Add_ri adds 'ri' operand to the content stream, which sets the color rendering intent.
2020-08-27 21:45:09 +00:00
//
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_cbb *ContentCreator )Add_ri (intent _fef .PdfObjectName )*ContentCreator {_aca :=ContentStreamOperation {};_aca .Operand ="\u0072\u0069";_aca .Params =_febf ([]_fef .PdfObjectName {intent });_cbb ._gag =append (_cbb ._gag ,&_aca );return _cbb ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// AddOperand adds a specified operand.
func (_bdd *ContentCreator )AddOperand (op ContentStreamOperation )*ContentCreator {_bdd ._gag =append (_bdd ._gag ,&op );return _bdd ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_S appends 'S' operand to the content stream: Stroke the path.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
func (_gff *ContentCreator )Add_S ()*ContentCreator {_dbe :=ContentStreamOperation {};_dbe .Operand ="\u0053";_gff ._gag =append (_gff ._gag ,&_dbe );return _gff ;};func _dda (_aecf *ContentStreamInlineImage ,_gdfc *_fef .PdfObjectDictionary )(*_fef .FlateEncoder ,error ){_ca :=_fef .NewFlateEncoder ();if _aecf ._beef !=nil {_ca .SetImage (_aecf ._beef );};if _gdfc ==nil {_gcg :=_aecf .DecodeParms ;if _gcg !=nil {_gbc ,_ddb :=_fef .GetDict (_gcg );if !_ddb {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073\u0020n\u006f\u0074\u0020\u0061\u0020\u0064\u0069\u0063\u0074\u0069on\u0061\u0072\u0079 \u0028%\u0054\u0029",_gcg );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_gdfc =_gbc ;};};if _gdfc ==nil {return _ca ,nil ;};_ce .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_gdfc .String ());_ecb :=_gdfc .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _ecb ==nil {_ce .Log .Debug ("E\u0072\u0072o\u0072\u003a\u0020\u0050\u0072\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067 \u0066\u0072\u006f\u006d\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073 \u002d\u0020\u0043\u006f\u006e\u0074\u0069\u006e\u0075\u0065\u0020\u0077\u0069t\u0068\u0020\u0064\u0065\u0066\u0061\u0075\u006c\u0074\u0020\u00281\u0029");}else {_edf ,_cff :=_ecb .(*_fef .PdfObjectInteger );if !_cff {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0050\u0072\u0065d\u0069\u0063\u0074\u006f\u0072\u0020\u0073pe\u0063\u0069\u0066\u0069e\u0064\u0020\u0062\u0075\u0074\u0020\u006e\u006f\u0074 n\u0075\u006de\u0072\u0069\u0063\u0020\u0028\u0025\u0054\u0029",_ecb );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_ca .Predictor =int (*_edf );};_ecb =_gdfc .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _ecb !=nil {_egb ,_dac :=_ecb .(*_fef .PdfObjectInteger );if !_dac {_ce .Log .Debug ("\u0045\u0052\u0052O\u0052\u003a\u0020\u0049n\u0076\u0061\u006c\u0069\u0064\u0020\u0042i\u0074\u0073\u0050\u0065\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");return nil ,_de .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_ca .BitsPerComponent =int (*_egb );};if _ca .Predictor > 1{_ca .Columns =1;_ecb =_gdfc .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _ecb !=nil {_dbf ,_ggd :=_ecb .(*_fef .PdfObjectInteger );if !_ggd {return nil ,_de .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_ca .Columns =int (*_dbf );};_ca .Colors =1;_gge :=_gdfc .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _gge !=nil {_bcf ,_def :=_gge .(*_fef .PdfObjectInteger );if !_def {return nil ,_de .Errorf ("\u0070\u0072\u0065d\u0069\u0063\u0074\u006fr\u0020\u0063\u006f\u006c\u006f\u0072\u0073 \u006e\u006f\u0074\u0020\u0061\u006e\u0020\u0069\u006e\u0074\u0065\u0067\u0065\u0072");};_ca .Colors =int (*_bcf );};};return _ca ,nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// HandlerConditionEnum represents the type of operand content stream processor (handler).
// The handler may process a single specific named operand or all operands.
type HandlerConditionEnum int ;
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// NewContentStreamParser creates a new instance of the content stream parser from an input content
// stream string.
func NewContentStreamParser (contentStr string )*ContentStreamParser {_dbfb :=ContentStreamParser {};_fee :=_b .NewBufferString (contentStr +"\u000a");_dbfb ._edc =_cg .NewReader (_fee );return &_dbfb ;};func (_defg *ContentStreamParser )parseString ()(*_fef .PdfObjectString ,error ){_defg ._edc .ReadByte ();var _agge []byte ;_beeb :=1;for {_adbd ,_eadf :=_defg ._edc .Peek (1);if _eadf !=nil {return _fef .MakeString (string (_agge )),_eadf ;};if _adbd [0]=='\\'{_defg ._edc .ReadByte ();_cgcd ,_dbda :=_defg ._edc .ReadByte ();if _dbda !=nil {return _fef .MakeString (string (_agge )),_dbda ;};if _fef .IsOctalDigit (_cgcd ){_gea ,_cfae :=_defg ._edc .Peek (2);if _cfae !=nil {return _fef .MakeString (string (_agge )),_cfae ;};var _ccf []byte ;_ccf =append (_ccf ,_cgcd );for _ ,_fced :=range _gea {if _fef .IsOctalDigit (_fced ){_ccf =append (_ccf ,_fced );}else {break ;};};_defg ._edc .Discard (len (_ccf )-1);_ce .Log .Trace ("\u004e\u0075\u006d\u0065ri\u0063\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u0020\u0022\u0025\u0073\u0022",_ccf );_gdge ,_cfae :=_d .ParseUint (string (_ccf ),8,32);if _cfae !=nil {return _fef .MakeString (string (_agge )),_cfae ;};_agge =append (_agge ,byte (_gdge ));continue ;};switch _cgcd {case 'n':_agge =append (_agge ,'\n');case 'r':_agge =append (_agge ,'\r');case 't':_agge =append (_agge ,'\t');case 'b':_agge =append (_agge ,'\b');case 'f':_agge =append (_agge ,'\f');case '(':_agge =append (_agge ,'(');case ')':_agge =append (_agge ,')');case '\\':_agge =append (_agge ,'\\');};continue ;}else if _adbd [0]=='('{_beeb ++;}else if _adbd [0]==')'{_beeb --;if _beeb ==0{_defg ._edc .ReadByte ();break ;};};_ddad ,_ :=_defg ._edc .ReadByte ();_agge =append (_agge ,_ddad );};return _fef .MakeString (string (_agge )),nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Tc appends 'Tc' operand to the content stream:
// Set character spacing.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
func (_age *ContentCreator )Add_Tc (charSpace float64 )*ContentCreator {_af :=ContentStreamOperation {};_af .Operand ="\u0054\u0063";_af .Params =_ccae ([]float64 {charSpace });_age ._gag =append (_age ._gag ,&_af );return _age ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_cm adds 'cm' operation to the content stream: Modifies the current transformation matrix (ctm)
// of the graphics state.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
func (_dc *ContentCreator )Add_cm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_bbg :=ContentStreamOperation {};_bbg .Operand ="\u0063\u006d";_bbg .Params =_ccae ([]float64 {a ,b ,c ,d ,e ,f });_dc ._gag =append (_dc ._gag ,&_bbg );return _dc ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// ContentStreamOperations is a slice of ContentStreamOperations.
type ContentStreamOperations []*ContentStreamOperation ;
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_W appends 'W' operand to the content stream:
// Modify the current clipping path by intersecting with the current path (nonzero winding rule).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
func (_gbe *ContentCreator )Add_W ()*ContentCreator {_eef :=ContentStreamOperation {};_eef .Operand ="\u0057";_gbe ._gag =append (_gbe ._gag ,&_eef );return _gbe ;};func (_egcc *ContentStreamParser )parseHexString ()(*_fef .PdfObjectString ,error ){_egcc ._edc .ReadByte ();_dceg :=[]byte ("\u0030\u0031\u0032\u003345\u0036\u0037\u0038\u0039\u0061\u0062\u0063\u0064\u0065\u0066\u0041\u0042\u0043\u0044E\u0046");var _abbg []byte ;for {_egcc .skipSpaces ();_cac ,_ebbd :=_egcc ._edc .Peek (1);if _ebbd !=nil {return _fef .MakeString (""),_ebbd ;};if _cac [0]=='>'{_egcc ._edc .ReadByte ();break ;};_bgdd ,_ :=_egcc ._edc .ReadByte ();if _b .IndexByte (_dceg ,_bgdd )>=0{_abbg =append (_abbg ,_bgdd );};};if len (_abbg )%2==1{_abbg =append (_abbg ,'0');};_gdba ,_ :=_c .DecodeString (string (_abbg ));return _fef .MakeHexString (string (_gdba )),nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_rg appends 'rg' operand to the content stream:
// Same as RG but used for nonstroking operations.
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_bfd *ContentCreator )Add_rg (r ,g ,b float64 )*ContentCreator {_gdg :=ContentStreamOperation {};_gdg .Operand ="\u0072\u0067";_gdg .Params =_ccae ([]float64 {r ,g ,b });_bfd ._gag =append (_bfd ._gag ,&_gdg );return _bfd ;};
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// GetColorSpace returns the colorspace of the inline image.
2020-09-07 00:23:12 +00:00
func (_aee *ContentStreamInlineImage )GetColorSpace (resources *_g .PdfPageResources )(_g .PdfColorspace ,error ){if _aee .ColorSpace ==nil {_ce .Log .Debug ("\u0049\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076i\u006e\u0067\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u002c\u0020\u0061\u0073\u0073\u0075\u006di\u006e\u0067\u0020\u0047\u0072a\u0079");return _g .NewPdfColorspaceDeviceGray (),nil ;};if _cfgb ,_bcg :=_aee .ColorSpace .(*_fef .PdfObjectArray );_bcg {return _aab (_cfgb );};_bef ,_bce :=_aee .ColorSpace .(*_fef .PdfObjectName );if !_bce {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020I\u006e\u0076\u0061\u006c\u0069\u0064 \u006f\u0062\u006a\u0065\u0063\u0074\u0020t\u0079\u0070\u0065\u0020\u0028\u0025\u0054\u003b\u0025\u002bv\u0029",_aee .ColorSpace ,_aee .ColorSpace );return nil ,_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_bef =="\u0047"||*_bef =="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"{return _g .NewPdfColorspaceDeviceGray (),nil ;}else if *_bef =="\u0052\u0047\u0042"||*_bef =="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"{return _g .NewPdfColorspaceDeviceRGB (),nil ;}else if *_bef =="\u0043\u004d\u0059\u004b"||*_bef =="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{return _g .NewPdfColorspaceDeviceCMYK (),nil ;}else if *_bef =="\u0049"||*_bef =="\u0049n\u0064\u0065\u0078\u0065\u0064"{return nil ,_f .New ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0049\u006e\u0064e\u0078 \u0063\u006f\u006c\u006f\u0072\u0073\u0070a\u0063\u0065");}else {if resources .ColorSpace ==nil {_ce .Log .Debug ("\u0045\u0072r\u006f\u0072\u002c\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u003a\u0020\u0025\u0073",*_bef );return nil ,_f .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};_gfaf ,_cbac :=resources .GetColorspaceByName (*_bef );if !_cbac {_ce .Log .Debug ("\u0045\u0072r\u006f\u0072\u002c\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u003a\u0020\u0025\u0073",*_bef );return nil ,_f .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};return _gfaf ,nil ;};};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_b_starred appends 'b*' operand to the content stream:
// Close, fill and then stroke the path (even-odd winding number rule).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
func (_aaa *ContentCreator )Add_b_starred ()*ContentCreator {_ad :=ContentStreamOperation {};_ad .Operand ="\u0062\u002a";_aaa ._gag =append (_aaa ._gag ,&_ad );return _aaa ;};
// Bytes converts a set of content stream operations to a content stream byte presentation,
// i.e. the kind that can be stored as a PDF stream or string format.
func (_be *ContentStreamOperations )Bytes ()[]byte {var _bd _b .Buffer ;for _ ,_fg :=range *_be {if _fg ==nil {continue ;};if _fg .Operand =="\u0042\u0049"{_bd .WriteString (_fg .Operand +"\u000a");_bd .WriteString (_fg .Params [0].WriteString ());}else {for _ ,_ge :=range _fg .Params {_bd .WriteString (_ge .WriteString ());_bd .WriteString ("\u0020");};_bd .WriteString (_fg .Operand +"\u000a");};};return _bd .Bytes ();};
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// Add_gs adds 'gs' operand to the content stream: Set the graphics state.
//
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_da *ContentCreator )Add_gs (dictName _fef .PdfObjectName )*ContentCreator {_ead :=ContentStreamOperation {};_ead .Operand ="\u0067\u0073";_ead .Params =_febf ([]_fef .PdfObjectName {dictName });_da ._gag =append (_da ._gag ,&_ead );return _da ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// All returns true if `hce` is equivalent to HandlerConditionEnumAllOperands.
func (_bdgd HandlerConditionEnum )All ()bool {return _bdgd ==HandlerConditionEnumAllOperands };
// Add_cs appends 'cs' operand to the content stream:
// Same as CS but for non-stroking operations.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_cef *ContentCreator )Add_cs (name _fef .PdfObjectName )*ContentCreator {_abed :=ContentStreamOperation {};_abed .Operand ="\u0063\u0073";_abed .Params =_febf ([]_fef .PdfObjectName {name });_cef ._gag =append (_cef ._gag ,&_abed );return _cef ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_l adds 'l' operand to the content stream:
// Append a straight line segment from the current point to (x,y).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_fgc *ContentCreator )Add_l (x ,y float64 )*ContentCreator {_dg :=ContentStreamOperation {};_dg .Operand ="\u006c";_dg .Params =_ccae ([]float64 {x ,y });_fgc ._gag =append (_fgc ._gag ,&_dg );return _fgc ;};func _dab (_ggab _g .PdfColorspace )bool {_ ,_ggfg :=_ggab .(*_g .PdfColorspaceSpecialPattern );return _ggfg ;};func (_fcfa *ContentStreamProcessor )handleCommand_g (_fdcc *ContentStreamOperation ,_fbge *_g .PdfPageResources )error {_bfa :=_g .NewPdfColorspaceDeviceGray ();if len (_fdcc .Params )!=_bfa .GetNumComponents (){_ce .Log .Debug ("\u0049\u006e\u0076al\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072 \u006ff\u0020p\u0061r\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020\u0067");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_fdcc .Params ),_bfa );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_ffad ,_gagf :=_bfa .ColorFromPdfObjects (_fdcc .Params );if _gagf !=nil {_ce .Log .Debug ("\u0045\u0052\u0052\u004fR\u003a\u0020\u0068\u0061\u006e\u0064\u006c\u0065\u0043o\u006d\u006d\u0061\u006e\u0064\u005f\u0067\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061r\u0061\u006d\u0073\u002e\u0020c\u0073\u003d\u0025\u0054\u0020\u006f\u0070\u003d\u0025\u0073\u0020\u0065\u0072\u0072\u003d\u0025\u0076",_bfa ,_fdcc ,_gagf );return _gagf ;};_fcfa ._bea .ColorspaceNonStroking =_bfa ;_fcfa ._bea .ColorNonStroking =_ffad ;return nil ;};func _dcg (_ggdfa *ContentStreamInlineImage )(*_fef .MultiEncoder ,error ){_dea :=_fef .NewMultiEncoder ();var _dfb *_fef .PdfObjectDictionary ;var _fga []_fef .PdfObject ;if _afc :=_ggdfa .DecodeParms ;_afc !=nil {_afcf ,_agc :=_afc .(*_fef .PdfObjectDictionary );if _agc {_dfb =_afcf ;};_becb ,_gdfe :=_afc .(*_fef .PdfObjectArray );if _gdfe {for _ ,_ggg :=range _becb .Elements (){if _gcf ,_gef :=_ggg .(*_fef .PdfObjectDictionary );_gef {_fga =append (_fga ,_gcf );}else {_fga =append (_fga ,nil );};};};};_geba :=_ggdfa .Filter ;if _geba ==nil {return nil ,_de .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006d\u0069s\u0073\u0069\u006e\u0067");};_dgf ,_agf :=_geba .(*_fef .PdfObjectArray );if !_agf {return nil ,_de .Errorf ("m\u0075\u006c\u0074\u0069\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u0063\u0061\u006e\u0020\u006f\u006el\u0079\u0020\u0062\u0065\u0020\u006d\u0061\u0064\u0065\u0020fr\u006f\u006d\u0020a\u0072r\u0061\u0079");};for _bbb ,_cfb :=range _dgf .Elements (){_deb ,_ebg :=_cfb .(*_fef .PdfObjectName );if !_ebg {return nil ,_de .Errorf ("\u006d\u0075l\u0074\u0069\u0020\u0066i\u006c\u0074e\u0072\u0020\u0061\u0072\u0072\u0061\u0079\u0020e\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u006e\u006f\u0074\u0020\u0061 \u006e\u0061\u006d\u0065");};var _dce _fef .PdfObject ;if _dfb !=nil {_dce =_dfb ;}else {if len (_fga )> 0{if _bbb >=len (_fga ){return nil ,_de .Errorf ("\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0065\u006c\u0065\u006d\u0065n\u0074\u0073\u0020\u0069\u006e\u0020d\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006d\u0073\u0020a\u0072\u0072\u0061\u0079");};_dce =_fga [_bbb ];};};var _cfa *_fef .PdfObjectDictionary ;if _ebb ,_bcd :=_dce .(*_fef .PdfObjectDictionary );_bcd {_cfa =_ebb ;};if *_deb ==_fef .StreamEncodingFilterNameFlate ||*_deb =="\u0046\u006c"{_cfd ,_efc :=_dda (_ggdfa ,_cfa );if _efc !=nil {return nil ,_efc ;};_dea .AddEncoder (_cfd );}else if *_deb ==_fef .StreamEncodingFilterNameLZW {_bff ,_fcf :=_ccc (_ggdfa ,_cfa );if _fcf !=nil {return nil ,_fcf ;};_dea .AddEncoder (_bff );}else if *_deb ==_fef .StreamEncodingFilterNameASCIIHex {_cfc :=_fef .NewASCIIHexEncoder ();_dea .AddEncoder (_cfc );}else if *_deb ==_fef .StreamEncodingFilterNameASCII85 ||*_deb =="\u0041\u0038\u0035"{_bfb :=_fef .NewASCII85Encoder ();_dea .AddEncoder (_bfb );}else {_ce .Log .Error ("U\u006e\u0073\u0075\u0070po\u0072t\u0065\u0064\u0020\u0066\u0069l\u0074\u006
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// RotateDeg applies a rotation to the transformation matrix.
func (_cggb *ContentCreator )RotateDeg (angle float64 )*ContentCreator {_ceg :=_fe .Cos (angle *_fe .Pi /180.0);_gdf :=_fe .Sin (angle *_fe .Pi /180.0);_ffce :=-_fe .Sin (angle *_fe .Pi /180.0);_ea :=_fe .Cos (angle *_fe .Pi /180.0);return _cggb .Add_cm (_ceg ,_gdf ,_ffce ,_ea ,0,0);};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_M adds 'M' operand to the content stream: Set the miter limit (graphics state).
2020-08-31 21:12:07 +00:00
//
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_dfd *ContentCreator )Add_M (miterlimit float64 )*ContentCreator {_gf :=ContentStreamOperation {};_gf .Operand ="\u004d";_gf .Params =_ccae ([]float64 {miterlimit });_dfd ._gag =append (_dfd ._gag ,&_gf );return _dfd ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Operand returns true if `hce` is equivalent to HandlerConditionEnumOperand.
func (_gbce HandlerConditionEnum )Operand ()bool {return _gbce ==HandlerConditionEnumOperand };var (ErrInvalidOperand =_f .New ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064"););
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Process processes the entire list of operations. Maintains the graphics state that is passed to any
// handlers that are triggered during processing (either on specific operators or all).
func (_gdc *ContentStreamProcessor )Process (resources *_g .PdfPageResources )error {_gdc ._bea .ColorspaceStroking =_g .NewPdfColorspaceDeviceGray ();_gdc ._bea .ColorspaceNonStroking =_g .NewPdfColorspaceDeviceGray ();_gdc ._bea .ColorStroking =_g .NewPdfColorDeviceGray (0);_gdc ._bea .ColorNonStroking =_g .NewPdfColorDeviceGray (0);_gdc ._bea .CTM =_df .IdentityMatrix ();for _ ,_fba :=range _gdc ._fbbd {var _ccg error ;switch _fba .Operand {case "\u0071":_gdc ._cegc .Push (_gdc ._bea );case "\u0051":if len (_gdc ._cegc )==0{_ce .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0060\u0051\u0060\u0020\u006f\u0070e\u0072\u0061\u0074\u006f\u0072\u002e\u0020\u0047\u0072\u0061\u0070\u0068\u0069\u0063\u0073\u0020\u0073\u0074\u0061\u0074\u0065 \u0073\u0074\u0061\u0063\u006b\u0020\u0069\u0073\u0020\u0065\u006d\u0070\u0074\u0079.\u0020\u0053\u006bi\u0070\u0070\u0069\u006e\u0067\u002e");continue ;};_gdc ._bea =_gdc ._cegc .Pop ();case "\u0043\u0053":_ccg =_gdc .handleCommand_CS (_fba ,resources );case "\u0063\u0073":_ccg =_gdc .handleCommand_cs (_fba ,resources );case "\u0053\u0043":_ccg =_gdc .handleCommand_SC (_fba ,resources );case "\u0053\u0043\u004e":_ccg =_gdc .handleCommand_SCN (_fba ,resources );case "\u0073\u0063":_ccg =_gdc .handleCommand_sc (_fba ,resources );case "\u0073\u0063\u006e":_ccg =_gdc .handleCommand_scn (_fba ,resources );case "\u0047":_ccg =_gdc .handleCommand_G (_fba ,resources );case "\u0067":_ccg =_gdc .handleCommand_g (_fba ,resources );case "\u0052\u0047":_ccg =_gdc .handleCommand_RG (_fba ,resources );case "\u0072\u0067":_ccg =_gdc .handleCommand_rg (_fba ,resources );case "\u004b":_ccg =_gdc .handleCommand_K (_fba ,resources );case "\u006b":_ccg =_gdc .handleCommand_k (_fba ,resources );case "\u0063\u006d":_ccg =_gdc .handleCommand_cm (_fba ,resources );};if _ccg !=nil {_ce .Log .Debug ("\u0050\u0072\u006f\u0063\u0065\u0073s\u006f\u0072\u0020\u0068\u0061\u006e\u0064\u006c\u0069\u006e\u0067\u0020\u0065r\u0072\u006f\u0072\u0020\u0028\u0025\u0073)\u003a\u0020\u0025\u0076",_fba .Operand ,_ccg );_ce .Log .Debug ("\u004f\u0070\u0065r\u0061\u006e\u0064\u003a\u0020\u0025\u0023\u0076",_fba .Operand );return _ccg ;};for _ ,_fdeg :=range _gdc ._gcbc {var _acfb error ;if _fdeg .Condition .All (){_acfb =_fdeg .Handler (_fba ,_gdc ._bea ,resources );}else if _fdeg .Condition .Operand ()&&_fba .Operand ==_fdeg .Operand {_acfb =_fdeg .Handler (_fba ,_gdc ._bea ,resources );};if _acfb !=nil {_ce .Log .Debug ("P\u0072\u006f\u0063\u0065\u0073\u0073o\u0072\u0020\u0068\u0061\u006e\u0064\u006c\u0065\u0072 \u0065\u0072\u0072o\u0072:\u0020\u0025\u0076",_acfb );return _acfb ;};};};return nil ;};func (_cddg *ContentStreamProcessor )handleCommand_SCN (_cafa *ContentStreamOperation ,_cgea *_g .PdfPageResources )error {_aaga :=_cddg ._bea .ColorspaceStroking ;if !_dab (_aaga ){if len (_cafa .Params )!=_aaga .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_cafa .Params ),_aaga );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_fcfg ,_edfa :=_aaga .ColorFromPdfObjects (_cafa .Params );if _edfa !=nil {return _edfa ;};_cddg ._bea .ColorStroking =_fcfg ;return nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Parse parses all commands in content stream, returning a list of operation data.
func (_ecf *ContentStreamParser )Parse ()(*ContentStreamOperations ,error ){_gbef :=ContentStreamOperations {};for {_gdda :=ContentStreamOperation {};for {_fgec ,_eagb ,_cbgc :=_ecf .parseObject ();if _cbgc !=nil {if _cbgc ==_cd .EOF {return &_gbef ,nil ;};return &_gbef ,_cbgc ;};if _eagb {_gdda .Operand ,_ =_fef .GetStringVal (_fgec );_gbef =append (_gbef ,&_gdda );break ;}else {_gdda .Params =append (_gdda .Params ,_fgec );};};if _gdda .Operand =="\u0042\u0049"{_cdb ,_fbg :=_ecf .ParseInlineImage ();if _fbg !=nil {return &_gbef ,_fbg ;};_gdda .Params =append (_gdda .Params ,_cdb );};};};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// ToImage exports the inline image to Image which can be transformed or exported easily.
// Page resources are needed to look up colorspace information.
func (_cag *ContentStreamInlineImage )ToImage (resources *_g .PdfPageResources )(*_g .Image ,error ){_aadf ,_abeg :=_cag .toImageBase (resources );if _abeg !=nil {return nil ,_abeg ;};_eabf ,_abeg :=_bdc (_cag );if _abeg !=nil {return nil ,_abeg ;};_ce .Log .Trace ("\u0065n\u0063o\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076\u0020\u0025\u0054",_eabf ,_eabf );_ce .Log .Trace ("\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065:\u0020\u0025\u002b\u0076",_cag );_bcb ,_abeg :=_eabf .DecodeBytes (_cag ._debc );if _abeg !=nil {return nil ,_abeg ;};_dbd :=&_g .Image {Width :int64 (_aadf .Width ),Height :int64 (_aadf .Height ),BitsPerComponent :int64 (_aadf .BitsPerComponent ),ColorComponents :_aadf .ColorComponents ,Data :_bcb };if len (_aadf .Decode )> 0{for _cae :=0;_cae < len (_aadf .Decode );_cae ++{_aadf .Decode [_cae ]*=float64 ((int (1)<<uint (_aadf .BitsPerComponent ))-1);};_dbd .SetDecode (_aadf .Decode );};return _dbd ,nil ;};
2020-08-27 21:45:09 +00:00
2020-08-31 21:12:07 +00:00
// SetNonStrokingColor sets the non-stroking `color` where color can be one of
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
2020-09-07 00:23:12 +00:00
func (_adc *ContentCreator )SetNonStrokingColor (color _g .PdfColor )*ContentCreator {switch _geb :=color .(type ){case *_g .PdfColorDeviceGray :_adc .Add_g (_geb .Val ());case *_g .PdfColorDeviceRGB :_adc .Add_rg (_geb .R (),_geb .G (),_geb .B ());case *_g .PdfColorDeviceCMYK :_adc .Add_k (_geb .C (),_geb .M (),_geb .Y (),_geb .K ());default:_ce .Log .Debug ("\u0053\u0065\u0074N\u006f\u006e\u0053\u0074\u0072\u006f\u006b\u0069\u006e\u0067\u0043\u006f\u006c\u006f\u0072\u003a\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020c\u006f\u006c\u006f\u0072\u003a\u0020\u0025\u0054",_geb );};return _adc ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Ts appends 'Ts' operand to the content stream:
// Set text rise.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_cdeg *ContentCreator )Add_Ts (rise float64 )*ContentCreator {_adba :=ContentStreamOperation {};_adba .Operand ="\u0054\u0073";_adba .Params =_ccae ([]float64 {rise });_cdeg ._gag =append (_cdeg ._gag ,&_adba );return _cdeg ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Push pushes `gs` on the `gsStack`.
func (_ecfb *GraphicStateStack )Push (gs GraphicsState ){*_ecfb =append (*_ecfb ,gs )};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_B_starred appends 'B*' operand to the content stream:
// Fill and then stroke the path (even-odd rule).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
func (_bde *ContentCreator )Add_B_starred ()*ContentCreator {_efd :=ContentStreamOperation {};_efd .Operand ="\u0042\u002a";_bde ._gag =append (_bde ._gag ,&_efd );return _bde ;};func (_bfdab *ContentStreamProcessor )handleCommand_rg (_dagc *ContentStreamOperation ,_dfg *_g .PdfPageResources )error {_aafb :=_g .NewPdfColorspaceDeviceRGB ();if len (_dagc .Params )!=_aafb .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_dagc .Params ),_aafb );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_bfcfd ,_baac :=_aafb .ColorFromPdfObjects (_dagc .Params );if _baac !=nil {return _baac ;};_bfdab ._bea .ColorspaceNonStroking =_aafb ;_bfdab ._bea .ColorNonStroking =_bfcfd ;return nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_TL appends 'TL' operand to the content stream:
// Set leading.
2020-08-27 21:45:09 +00:00
//
2020-08-31 21:12:07 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_efb *ContentCreator )Add_TL (leading float64 )*ContentCreator {_dbeb :=ContentStreamOperation {};_dbeb .Operand ="\u0054\u004c";_dbeb .Params =_ccae ([]float64 {leading });_efb ._gag =append (_efb ._gag ,&_dbeb );return _efb ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_c adds 'c' operand to the content stream: Append a Bezier curve to the current path from
// the current point to (x3,y3) with (x1,x1) and (x2,y2) as control points.
2020-08-31 21:12:07 +00:00
//
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_abe *ContentCreator )Add_c (x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_gfc :=ContentStreamOperation {};_gfc .Operand ="\u0063";_gfc .Params =_ccae ([]float64 {x1 ,y1 ,x2 ,y2 ,x3 ,y3 });_abe ._gag =append (_abe ._gag ,&_gfc );return _abe ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Tw appends 'Tw' operand to the content stream:
// Set word spacing.
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
func (_gffd *ContentCreator )Add_Tw (wordSpace float64 )*ContentCreator {_egaab :=ContentStreamOperation {};_egaab .Operand ="\u0054\u0077";_egaab .Params =_ccae ([]float64 {wordSpace });_gffd ._gag =append (_gffd ._gag ,&_egaab );return _gffd ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// SetStrokingColor sets the stroking `color` where color can be one of
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
func (_cggd *ContentCreator )SetStrokingColor (color _g .PdfColor )*ContentCreator {switch _cdg :=color .(type ){case *_g .PdfColorDeviceGray :_cggd .Add_G (_cdg .Val ());case *_g .PdfColorDeviceRGB :_cggd .Add_RG (_cdg .R (),_cdg .G (),_cdg .B ());case *_g .PdfColorDeviceCMYK :_cggd .Add_K (_cdg .C (),_cdg .M (),_cdg .Y (),_cdg .K ());default:_ce .Log .Debug ("\u0053\u0065\u0074\u0053\u0074\u0072\u006f\u006b\u0069\u006e\u0067\u0043\u006fl\u006f\u0072\u003a\u0020\u0075\u006es\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006fr\u003a\u0020\u0025\u0054",_cdg );};return _cggd ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// WriteString outputs the object as it is to be written to file.
func (_fbc *ContentStreamInlineImage )WriteString ()string {var _eab _b .Buffer ;_cbg :="";if _fbc .BitsPerComponent !=nil {_cbg +="\u002f\u0042\u0050C\u0020"+_fbc .BitsPerComponent .WriteString ()+"\u000a";};if _fbc .ColorSpace !=nil {_cbg +="\u002f\u0043\u0053\u0020"+_fbc .ColorSpace .WriteString ()+"\u000a";};if _fbc .Decode !=nil {_cbg +="\u002f\u0044\u0020"+_fbc .Decode .WriteString ()+"\u000a";};if _fbc .DecodeParms !=nil {_cbg +="\u002f\u0044\u0050\u0020"+_fbc .DecodeParms .WriteString ()+"\u000a";};if _fbc .Filter !=nil {_cbg +="\u002f\u0046\u0020"+_fbc .Filter .WriteString ()+"\u000a";};if _fbc .Height !=nil {_cbg +="\u002f\u0048\u0020"+_fbc .Height .WriteString ()+"\u000a";};if _fbc .ImageMask !=nil {_cbg +="\u002f\u0049\u004d\u0020"+_fbc .ImageMask .WriteString ()+"\u000a";};if _fbc .Intent !=nil {_cbg +="\u002f\u0049\u006e\u0074\u0065\u006e\u0074\u0020"+_fbc .Intent .WriteString ()+"\u000a";};if _fbc .Interpolate !=nil {_cbg +="\u002f\u0049\u0020"+_fbc .Interpolate .WriteString ()+"\u000a";};if _fbc .Width !=nil {_cbg +="\u002f\u0057\u0020"+_fbc .Width .WriteString ()+"\u000a";};_eab .WriteString (_cbg );_eab .WriteString ("\u0049\u0044\u0020");_eab .Write (_fbc ._debc );_eab .WriteString ("\u000a\u0045\u0049\u000a");return _eab .String ();};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// NewContentStreamProcessor returns a new ContentStreamProcessor for operations `ops`.
func NewContentStreamProcessor (ops []*ContentStreamOperation )*ContentStreamProcessor {_gfac :=ContentStreamProcessor {};_gfac ._cegc =GraphicStateStack {};_ggc :=GraphicsState {};_gfac ._bea =_ggc ;_gfac ._gcbc =[]handlerEntry {};_gfac ._ged =0;_gfac ._fbbd =ops ;return &_gfac ;};
// Add_k appends 'k' operand to the content stream:
// Same as K but used for nonstroking operations.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_egc *ContentCreator )Add_k (c ,m ,y ,k float64 )*ContentCreator {_fcb :=ContentStreamOperation {};_fcb .Operand ="\u006b";_fcb .Params =_ccae ([]float64 {c ,m ,y ,k });_egc ._gag =append (_egc ._gag ,&_fcb );return _egc ;};const (HandlerConditionEnumOperand HandlerConditionEnum =iota ;HandlerConditionEnumAllOperands ;);func (_dbed *ContentStreamProcessor )handleCommand_sc (_eaea *ContentStreamOperation ,_gadg *_g .PdfPageResources )error {_bccc :=_dbed ._bea .ColorspaceNonStroking ;if !_dab (_bccc ){if len (_eaea .Params )!=_bccc .GetNumComponents (){_ce .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_ce .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_eaea .Params ),_bccc );return _f .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_eed ,_fdea :=_bccc .ColorFromPdfObjects (_eaea .Params );if _fdea !=nil {return _fdea ;};_dbed ._bea .ColorNonStroking =_eed ;return nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_RG appends 'RG' operand to the content stream:
// Set the stroking colorspace to DeviceRGB and sets the r,g,b colors (0-1 each).
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_feb *ContentCreator )Add_RG (r ,g ,b float64 )*ContentCreator {_fddc :=ContentStreamOperation {};_fddc .Operand ="\u0052\u0047";_fddc .Params =_ccae ([]float64 {r ,g ,b });_feb ._gag =append (_feb ._gag ,&_fddc );return _feb ;};
2020-08-31 21:12:07 +00:00
// Add_b appends 'b' operand to the content stream:
// Close, fill and then stroke the path (nonzero winding number rule).
2020-08-27 21:45:09 +00:00
//
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_gfg *ContentCreator )Add_b ()*ContentCreator {_fbb :=ContentStreamOperation {};_fbb .Operand ="\u0062";_gfg ._gag =append (_gfg ._gag ,&_fbb );return _gfg ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_f appends 'f' operand to the content stream:
// Fill the path using the nonzero winding number rule to determine fill region.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
func (_cca *ContentCreator )Add_f ()*ContentCreator {_ebf :=ContentStreamOperation {};_ebf .Operand ="\u0066";_cca ._gag =append (_cca ._gag ,&_ebf );return _cca ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_h appends 'h' operand to the content stream:
// Close the current subpath by adding a line between the current position and the starting position.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_baa *ContentCreator )Add_h ()*ContentCreator {_becd :=ContentStreamOperation {};_becd .Operand ="\u0068";_baa ._gag =append (_baa ._gag ,&_becd );return _baa ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_q adds 'q' operand to the content stream: Pushes the current graphics state on the stack.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
func (_egf *ContentCreator )Add_q ()*ContentCreator {_cgg :=ContentStreamOperation {};_cgg .Operand ="\u0071";_egf ._gag =append (_egf ._gag ,&_cgg );return _egf ;};
2020-09-07 00:23:12 +00:00
// GraphicStateStack represents a stack of GraphicsState.
type GraphicStateStack []GraphicsState ;
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Wrap ensures that the contentstream is wrapped within a balanced q ... Q expression.
func (_db *ContentCreator )Wrap (){_db ._gag .WrapIfNeeded ()};
// Add_W_starred appends 'W*' operand to the content stream:
// Modify the current clipping path by intersecting with the current path (even odd rule).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
func (_eefa *ContentCreator )Add_W_starred ()*ContentCreator {_ddf :=ContentStreamOperation {};_ddf .Operand ="\u0057\u002a";_eefa ._gag =append (_eefa ._gag ,&_ddf );return _eefa ;};
2020-09-07 00:23:12 +00:00
// ContentCreator is a builder for PDF content streams.
type ContentCreator struct{_gag ContentStreamOperations };
2020-09-07 00:23:12 +00:00
// Add_v appends 'v' operand to the content stream: Append a Bezier curve to the current path from the
// current point to (x3,y3) with the current point and (x2,y2) as control points.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_gec *ContentCreator )Add_v (x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_fge :=ContentStreamOperation {};_fge .Operand ="\u0076";_fge .Params =_ccae ([]float64 {x2 ,y2 ,x3 ,y3 });_gec ._gag =append (_gec ._gag ,&_fge );return _gec ;};
2020-09-07 00:23:12 +00:00
// Add_i adds 'i' operand to the content stream: Set the flatness tolerance in the graphics state.
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
func (_gdd *ContentCreator )Add_i (flatness float64 )*ContentCreator {_bec :=ContentStreamOperation {};_bec .Operand ="\u0069";_bec .Params =_ccae ([]float64 {flatness });_gdd ._gag =append (_gdd ._gag ,&_bec );return _gdd ;};
2020-09-07 00:23:12 +00:00
// Bytes converts the content stream operations to a content stream byte presentation, i.e. the kind that can be
// stored as a PDF stream or string format.
func (_ac *ContentCreator )Bytes ()[]byte {return _ac ._gag .Bytes ()};
2020-09-07 00:23:12 +00:00
// Add_Q adds 'Q' operand to the content stream: Pops the most recently stored state from the stack.
2020-08-31 21:12:07 +00:00
//
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_ega *ContentCreator )Add_Q ()*ContentCreator {_aad :=ContentStreamOperation {};_aad .Operand ="\u0051";_ega ._gag =append (_ega ._gag ,&_aad );return _ega ;};
2020-08-27 21:45:09 +00:00
// Add_BT appends 'BT' operand to the content stream:
// Begin text.
//
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_gg *ContentCreator )Add_BT ()*ContentCreator {_acc :=ContentStreamOperation {};_acc .Operand ="\u0042\u0054";_gg ._gag =append (_gg ._gag ,&_acc );return _gg ;};func _ccc (_cga *ContentStreamInlineImage ,_gbd *_fef .PdfObjectDictionary )(*_fef .LZWEncoder ,error ){_ggdf :=_fef .NewLZWEncoder ();if _gbd ==nil {if _cga .DecodeParms !=nil {_gbeb ,_gfa :=_fef .GetDict (_cga .DecodeParms );if !_gfa {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073\u0020n\u006f\u0074\u0020\u0061\u0020\u0064\u0069\u0063\u0074\u0069on\u0061\u0072\u0079 \u0028%\u0054\u0029",_cga .DecodeParms );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_gbd =_gbeb ;};};if _gbd ==nil {return _ggdf ,nil ;};_aeb :=_gbd .Get ("E\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");if _aeb !=nil {_bge ,_dgb :=_aeb .(*_fef .PdfObjectInteger );if !_dgb {_ce .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a \u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065d\u0020\u0062\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u006e\u0075\u006d\u0065\u0072i\u0063 \u0028\u0025\u0054\u0029",_aeb );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");};if *_bge !=0&&*_bge !=1{return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065\u0020\u0076\u0061\u006c\u0075e\u0020\u0028\u006e\u006f\u0074 \u0030\u0020o\u0072\u0020\u0031\u0029");};_ggdf .EarlyChange =int (*_bge );}else {_ggdf .EarlyChange =1;};_aeb =_gbd .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _aeb !=nil {_fca ,_bgb :=_aeb .(*_fef .PdfObjectInteger );if !_bgb {_ce .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0050\u0072\u0065d\u0069\u0063\u0074\u006f\u0072\u0020\u0073pe\u0063\u0069\u0066\u0069e\u0064\u0020\u0062\u0075\u0074\u0020\u006e\u006f\u0074 n\u0075\u006de\u0072\u0069\u0063\u0020\u0028\u0025\u0054\u0029",_aeb );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_ggdf .Predictor =int (*_fca );};_aeb =_gbd .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _aeb !=nil {_caf ,_aba :=_aeb .(*_fef .PdfObjectInteger );if !_aba {_ce .Log .Debug ("\u0045\u0052\u0052O\u0052\u003a\u0020\u0049n\u0076\u0061\u006c\u0069\u0064\u0020\u0042i\u0074\u0073\u0050\u0065\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");return nil ,_de .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_ggdf .BitsPerComponent =int (*_caf );};if _ggdf .Predictor > 1{_ggdf .Columns =1;_aeb =_gbd .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _aeb !=nil {_aef ,_ggf :=_aeb .(*_fef .PdfObjectInteger );if !_ggf {return nil ,_de .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_ggdf .Columns =int (*_aef );};_ggdf .Colors =1;_aeb =_gbd .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _aeb !=nil {_adcf ,_acaa :=_aeb .(*_fef .PdfObjectInteger );if !_acaa {return nil ,_de .Errorf ("\u0070\u0072\u0065d\u0069\u0063\u0074\u006fr\u0020\u0063\u006f\u006c\u006f\u0072\u0073 \u006e\u006f\u0074\u0020\u0061\u006e\u0020\u0069\u006e\u0074\u0065\u0067\u0065\u0072");};_ggdf .Colors =int (*_adcf );};};_ce .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_gbd .String ());return _ggdf ,nil ;};
2020-09-07 00:23:12 +00:00
// Add_Td appends 'Td' operand to the content stream:
// Move to start of next line with offset (`tx`, `ty`).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.4.2 "Text Positioning Operators" and
// Table 108 (pp. 257-258 PDF32000_2008).
func (_aec *ContentCreator )Add_Td (tx ,ty float64 )*ContentCreator {_eaff :=ContentStreamOperation {};_eaff .Operand ="\u0054\u0064";_eaff .Params =_ccae ([]float64 {tx ,ty });_aec ._gag =append (_aec ._gag ,&_eaff );return _aec ;};
2020-09-07 00:23:12 +00:00
// GraphicsState is a basic graphics state implementation for PDF processing.
// Initially only implementing and tracking a portion of the information specified. Easy to add more.
type GraphicsState struct{ColorspaceStroking _g .PdfColorspace ;ColorspaceNonStroking _g .PdfColorspace ;ColorStroking _g .PdfColor ;ColorNonStroking _g .PdfColor ;CTM _df .Matrix ;};
// Add_j adds 'j' operand to the content stream: Set the line join style (graphics state).
//
2020-08-27 21:45:09 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_gab *ContentCreator )Add_j (lineJoinStyle string )*ContentCreator {_bgfa :=ContentStreamOperation {};_bgfa .Operand ="\u006a";_bgfa .Params =_febf ([]_fef .PdfObjectName {_fef .PdfObjectName (lineJoinStyle )});_gab ._gag =append (_gab ._gag ,&_bgfa );return _gab ;};func (_dgbag *ContentStreamParser )parseBool ()(_fef .PdfObjectBool ,error ){_gddd ,_gcbe :=_dgbag ._edc .Peek (4);if _gcbe !=nil {return _fef .PdfObjectBool (false ),_gcbe ;};if (len (_gddd )>=4)&&(string (_gddd [:4])=="\u0074\u0072\u0075\u0065"){_dgbag ._edc .Discard (4);return _fef .PdfObjectBool (true ),nil ;};_gddd ,_gcbe =_dgbag ._edc .Peek (5);if _gcbe !=nil {return _fef .PdfObjectBool (false ),_gcbe ;};if (len (_gddd )>=5)&&(string (_gddd [:5])=="\u0066\u0061\u006cs\u0065"){_dgbag ._edc .Discard (5);return _fef .PdfObjectBool (false ),nil ;};return _fef .PdfObjectBool (false ),_f .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_w adds 'w' operand to the content stream, which sets the line width.
//
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
func (_ebe *ContentCreator )Add_w (lineWidth float64 )*ContentCreator {_ebed :=ContentStreamOperation {};_ebed .Operand ="\u0077";_ebed .Params =_ccae ([]float64 {lineWidth });_ebe ._gag =append (_ebe ._gag ,&_ebed );return _ebe ;};
// Add_s appends 's' operand to the content stream: Close and stroke the path.
2020-08-27 21:45:09 +00:00
//
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_eda *ContentCreator )Add_s ()*ContentCreator {_dge :=ContentStreamOperation {};_dge .Operand ="\u0073";_eda ._gag =append (_eda ._gag ,&_dge );return _eda ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_scn appends 'scn' operand to the content stream:
// Same as SC but for nonstroking operations.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_acg *ContentCreator )Add_scn (c ...float64 )*ContentCreator {_cbe :=ContentStreamOperation {};_cbe .Operand ="\u0073\u0063\u006e";_cbe .Params =_ccae (c );_acg ._gag =append (_acg ._gag ,&_cbe );return _acg ;};func _efbd (_eefc []int64 )[]_fef .PdfObject {var _bbge []_fef .PdfObject ;for _ ,_fbdg :=range _eefc {_bbge =append (_bbge ,_fef .MakeInteger (_fbdg ));};return _bbge ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_SC appends 'SC' operand to the content stream:
// Set color for stroking operations. Input: c1, ..., cn.
//
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_gdfb *ContentCreator )Add_SC (c ...float64 )*ContentCreator {_faa :=ContentStreamOperation {};_faa .Operand ="\u0053\u0043";_faa .Params =_ccae (c );_gdfb ._gag =append (_gdfb ._gag ,&_faa );return _gdfb ;};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// 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 _fef .PdfObject ;ColorSpace _fef .PdfObject ;Decode _fef .PdfObject ;DecodeParms _fef .PdfObject ;Filter _fef .PdfObject ;Height _fef .PdfObject ;ImageMask _fef .PdfObject ;Intent _fef .PdfObject ;Interpolate _fef .PdfObject ;Width _fef .PdfObject ;_debc []byte ;_beef *_fc .ImageBase ;};
// Add_Tr appends 'Tr' operand to the content stream:
// Set text rendering mode.
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.3 "Text State Parameters and Operators" and
// Table 105 (pp. 251-252 PDF32000_2008).
func (_cf *ContentCreator )Add_Tr (render int64 )*ContentCreator {_efde :=ContentStreamOperation {};_efde .Operand ="\u0054\u0072";_efde .Params =_efbd ([]int64 {render });_cf ._gag =append (_cf ._gag ,&_efde );return _cf ;};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// ParseInlineImage parses an inline image from a content stream, both reading 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 (_dag *ContentStreamParser )ParseInlineImage ()(*ContentStreamInlineImage ,error ){_edad :=ContentStreamInlineImage {};for {_dag .skipSpaces ();_aeed ,_eaeb ,_afg :=_dag .parseObject ();if _afg !=nil {return nil ,_afg ;};if !_eaeb {_fefb ,_cafc :=_fef .GetName (_aeed );if !_cafc {_ce .Log .Debug ("\u0049\u006e\u0076\u0061\u006ci\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067e\u0020\u0070\u0072\u006f\u0070\u0065\u0072\u0074\u0079\u0020\u0028\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067\u0020\u006e\u0061\u006d\u0065\u0029\u0020\u002d\u0020\u0025T",_aeed );return nil ,_de .Errorf ("\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067e\u0020\u0070\u0072\u006f\u0070\u0065\u0072\u0074\u0079\u0020\u0028\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067\u0020\u006e\u0061\u006d\u0065\u0029\u0020\u002d\u0020\u0025T",_aeed );};_aga ,_ccag ,_efe :=_dag .parseObject ();if _efe !=nil {return nil ,_efe ;};if _ccag {return nil ,_de .Errorf ("\u006eo\u0074\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067 \u0061\u006e\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};switch *_fefb {case "\u0042\u0050\u0043","\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074":_edad .BitsPerComponent =_aga ;case "\u0043\u0053","\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065":_edad .ColorSpace =_aga ;case "\u0044","\u0044\u0065\u0063\u006f\u0064\u0065":_edad .Decode =_aga ;case "\u0044\u0050","D\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073":_edad .DecodeParms =_aga ;case "\u0046","\u0046\u0069\u006c\u0074\u0065\u0072":_edad .Filter =_aga ;case "\u0048","\u0048\u0065\u0069\u0067\u0068\u0074":_edad .Height =_aga ;case "\u0049\u004d","\u0049m\u0061\u0067\u0065\u004d\u0061\u0073k":_edad .ImageMask =_aga ;case "\u0049\u006e\u0074\u0065\u006e\u0074":_edad .Intent =_aga ;case "\u0049","I\u006e\u0074\u0065\u0072\u0070\u006f\u006c\u0061\u0074\u0065":_edad .Interpolate =_aga ;case "\u0057","\u0057\u0069\u0064t\u0068":_edad .Width =_aga ;case "\u004c\u0065\u006e\u0067\u0074\u0068","\u0053u\u0062\u0074\u0079\u0070\u0065","\u0054\u0079\u0070\u0065":_ce .Log .Debug ("\u0049\u0067\u006e\u006fr\u0069\u006e\u0067\u0020\u0069\u006e\u006c\u0069\u006e\u0065 \u0070a\u0072\u0061\u006d\u0065\u0074\u0065\u0072 \u0025\u0073",*_fefb );default:return nil ,_de .Errorf ("\u0075\u006e\u006b\u006e\u006f\u0077n\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0020\u0025\u0073",*_fefb );};};if _eaeb {_fbdc ,_agb :=_aeed .(*_fef .PdfObjectString );if !_agb {return nil ,_de .Errorf ("\u0066a\u0069\u006ce\u0064\u0020\u0074o\u0020\u0072\u0065\u0061\u0064\u0020\u0069n\u006c\u0069\u006e\u0065\u0020\u0069m\u0061\u0067\u0065\u0020\u002d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};if _fbdc .Str ()=="\u0045\u0049"{_ce .Log .Trace ("\u0049n\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020f\u0069\u006e\u0069\u0073\u0068\u0065\u0064\u002e\u002e\u002e");return &_edad ,nil ;}else if _fbdc .Str ()=="\u0049\u0044"{_ce .Log .Trace ("\u0049\u0044\u0020\u0073\u0074\u0061\u0072\u0074");_dba ,_gbdb :=_dag ._edc .Peek (1);if _gbdb !=nil {return nil ,_gbdb ;};if _fef .IsWhiteSpace (_dba [0]){_dag ._edc .Discard (1);};_edad ._debc =[]byte {};_cdc :=0;var _bgd []byte ;for {_ebgf ,_adbb :=_dag ._edc .ReadByte ();if _adbb !=nil {_ce .Log .Debug ("\u0055\u006e\u0061\u0062\u006ce\u0020\u0074\u006f\u0020\u0066\u0069\u006e\u0064\u0020\u0065\u006e\u0064\u0020o\u0066\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0045\u0049\u0020\u0069\u006e\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0064\u0061\u0074a");return nil ,_adbb ;};if _cdc ==0{if _fef .IsWhiteSpace (_ebgf ){_bgd =[]byte {};_bgd =append (_bgd ,_ebgf );_cdc =1;}else if _ebgf =='E'{_bgd =append (_bgd ,_ebgf );_cdc =2;}else {_edad ._debc =append (_edad ._debc ,_ebgf );};}else if _cdc ==1{_bgd =append (_b
// Add_SCN_pattern appends 'SCN' operand to the content stream for pattern `name`:
// SCN with name attribute (for pattern). Syntax: c1 ... cn name SCN.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
func (_bab *ContentCreator )Add_SCN_pattern (name _fef .PdfObjectName ,c ...float64 )*ContentCreator {_fdg :=ContentStreamOperation {};_fdg .Operand ="\u0053\u0043\u004e";_fdg .Params =_ccae (c );_fdg .Params =append (_fdg .Params ,_fef .MakeName (string (name )));_bab ._gag =append (_bab ._gag ,&_fdg );return _bab ;};
2020-08-31 21:12:07 +00:00
// Add_Tstar appends 'T*' operand to the content stream:
// Move to the start of next line.
//
// See section 9.4.2 "Text Positioning Operators" and
// Table 108 (pp. 257-258 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_dfce *ContentCreator )Add_Tstar ()*ContentCreator {_dga :=ContentStreamOperation {};_dga .Operand ="\u0054\u002a";_dfce ._gag =append (_dfce ._gag ,&_dga );return _dfce ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_re appends 're' operand to the content stream:
// Append a rectangle to the current path as a complete subpath, with lower left corner (x,y).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
func (_cc *ContentCreator )Add_re (x ,y ,width ,height float64 )*ContentCreator {_fgfd :=ContentStreamOperation {};_fgfd .Operand ="\u0072\u0065";_fgfd .Params =_ccae ([]float64 {x ,y ,width ,height });_cc ._gag =append (_cc ._gag ,&_fgfd );return _cc ;};func (_bg *ContentStreamOperations )isWrapped ()bool {if len (*_bg )< 2{return false ;};_a :=0;for _ ,_ee :=range *_bg {if _ee .Operand =="\u0071"{_a ++;}else if _ee .Operand =="\u0051"{_a --;}else {if _a < 1{return false ;};};};return _a ==0;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// WrapIfNeeded wraps the entire contents within q ... Q. If unbalanced, then adds extra Qs at the end.
// Only does if needed. Ensures that when adding new content, one start with all states
// in the default condition.
func (_fa *ContentStreamOperations )WrapIfNeeded ()*ContentStreamOperations {if len (*_fa )==0{return _fa ;};if _fa .isWrapped (){return _fa ;};*_fa =append ([]*ContentStreamOperation {{Operand :"\u0071"}},*_fa ...);_ffc :=0;for _ ,_ba :=range *_fa {if _ba .Operand =="\u0071"{_ffc ++;}else if _ba .Operand =="\u0051"{_ffc --;};};for _ffc > 0{*_fa =append (*_fa ,&ContentStreamOperation {Operand :"\u0051"});_ffc --;};return _fa ;};var _cgf =map[string ]struct{}{"\u0062":struct{}{},"\u0042":struct{}{},"\u0062\u002a":struct{}{},"\u0042\u002a":struct{}{},"\u0042\u0044\u0043":struct{}{},"\u0042\u0049":struct{}{},"\u0042\u004d\u0043":struct{}{},"\u0042\u0054":struct{}{},"\u0042\u0058":struct{}{},"\u0063":struct{}{},"\u0063\u006d":struct{}{},"\u0043\u0053":struct{}{},"\u0063\u0073":struct{}{},"\u0064":struct{}{},"\u0064\u0030":struct{}{},"\u0064\u0031":struct{}{},"\u0044\u006f":struct{}{},"\u0044\u0050":struct{}{},"\u0045\u0049":struct{}{},"\u0045\u004d\u0043":struct{}{},"\u0045\u0054":struct{}{},"\u0045\u0058":struct{}{},"\u0066":struct{}{},"\u0046":struct{}{},"\u0066\u002a":struct{}{},"\u0047":struct{}{},"\u0067":struct{}{},"\u0067\u0073":struct{}{},"\u0068":struct{}{},"\u0069":struct{}{},"\u0049\u0044":struct{}{},"\u006a":struct{}{},"\u004a":struct{}{},"\u004b":struct{}{},"\u006b":struct{}{},"\u006c":struct{}{},"\u006d":struct{}{},"\u004d":struct{}{},"\u004d\u0050":struct{}{},"\u006e":struct{}{},"\u0071":struct{}{},"\u0051":struct{}{},"\u0072\u0065":struct{}{},"\u0052\u0047":struct{}{},"\u0072\u0067":struct{}{},"\u0072\u0069":struct{}{},"\u0073":struct{}{},"\u0053":struct{}{},"\u0053\u0043":struct{}{},"\u0073\u0063":struct{}{},"\u0053\u0043\u004e":struct{}{},"\u0073\u0063\u006e":struct{}{},"\u0073\u0068":struct{}{},"\u0054\u002a":struct{}{},"\u0054\u0063":struct{}{},"\u0054\u0064":struct{}{},"\u0054\u0044":struct{}{},"\u0054\u0066":struct{}{},"\u0054\u006a":struct{}{},"\u0054\u004a":struct{}{},"\u0054\u004c":struct{}{},"\u0054\u006d":struct{}{},"\u0054\u0072":struct{}{},"\u0054\u0073":struct{}{},"\u0054\u0077":struct{}{},"\u0054\u007a":struct{}{},"\u0076":struct{}{},"\u0077":struct{}{},"\u0057":struct{}{},"\u0057\u002a":struct{}{},"\u0079":struct{}{},"\u0027":struct{}{},"\u0022":struct{}{}};func (_ddcc *ContentStreamParser )parseDict ()(*_fef .PdfObjectDictionary ,error ){_ce .Log .Trace ("\u0052\u0065\u0061\u0064i\u006e\u0067\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074 \u0073t\u0072\u0065\u0061\u006d\u0020\u0064\u0069c\u0074\u0021");_ebbdc :=_fef .MakeDict ();_cge ,_ :=_ddcc ._edc .ReadByte ();if _cge !='<'{return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};_cge ,_ =_ddcc ._edc .ReadByte ();if _cge !='<'{return nil ,_f .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};for {_ddcc .skipSpaces ();_bcgg ,_daea :=_ddcc ._edc .Peek (2);if _daea !=nil {return nil ,_daea ;};_ce .Log .Trace ("D\u0069c\u0074\u0020\u0070\u0065\u0065\u006b\u003a\u0020%\u0073\u0020\u0028\u0025 x\u0029\u0021",string (_bcgg ),string (_bcgg ));if (_bcgg [0]=='>')&&(_bcgg [1]=='>'){_ce .Log .Trace ("\u0045\u004f\u0046\u0020\u0064\u0069\u0063\u0074\u0069o\u006e\u0061\u0072\u0079");_ddcc ._edc .ReadByte ();_ddcc ._edc .ReadByte ();break ;};_ce .Log .Trace ("\u0050a\u0072s\u0065\u0020\u0074\u0068\u0065\u0020\u006e\u0061\u006d\u0065\u0021");_bdg ,_daea :=_ddcc .parseName ();_ce .Log .Trace ("\u004be\u0079\u003a\u0020\u0025\u0073",_bdg );if _daea !=nil {_ce .Log .Debug ("E\u0052\u0052\u004f\u0052\u0020\u0052e\u0074\u0075\u0072\u006e\u0069\u006e\u0067\u0020\u006ea\u006d\u0065\u0020e\u0072r\u0020\u0025\u0073",_daea );return nil ,_daea ;};if len (_bdg )> 4&&_bdg [len (_bdg )-4:]=="\u006e\u0075\u006c\u006c"{_ade :=_bdg [0:len (_bdg )-4];_ce .Log .Trace ("\u0054\u0061\u006b\u0069n\u0067\u0020\u0063\u0061\u0072\u0065\u0020\u006f\u0066\u0020n\u0075l\u006c\u0020\u0062\u0075\u0067\u0020\u0028%\u0073\u0029",_bdg );_ce .Log .Trace ("\u004e\u0065\u0077\u0020ke\u0079\u0020\u0022\u0025\u0073\u0022\u0020\u003d\u0020\u006e\u0075\u006c\u006c",_ade );_ddcc .skipSpaces ();_eecb ,_ :=_ddcc ._edc .Peek (1);if
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_Tm appends 'Tm' operand to the content stream:
// Set the text line matrix.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.4.2 "Text Positioning Operators" and
// Table 108 (pp. 257-258 PDF32000_2008).
func (_cbbc *ContentCreator )Add_Tm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_ffb :=ContentStreamOperation {};_ffb .Operand ="\u0054\u006d";_ffb .Params =_ccae ([]float64 {a ,b ,c ,d ,e ,f });_cbbc ._gag =append (_cbbc ._gag ,&_ffb );return _cbbc ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// ExtractText parses and extracts all text data in content streams and returns as a string.
// Does not take into account Encoding table, the output is simply the character codes.
2020-08-31 21:12:07 +00:00
//
2020-09-07 00:23:12 +00:00
// Deprecated: More advanced text extraction is offered in package extractor with character encoding support.
func (_fgd *ContentStreamParser )ExtractText ()(string ,error ){_dfc ,_fad :=_fgd .Parse ();if _fad !=nil {return "",_fad ;};_ec :=false ;_aa ,_bga :=float64 (-1),float64 (-1);_aaf :="";for _ ,_gd :=range *_dfc {if _gd .Operand =="\u0042\u0054"{_ec =true ;}else if _gd .Operand =="\u0045\u0054"{_ec =false ;};if _gd .Operand =="\u0054\u0064"||_gd .Operand =="\u0054\u0044"||_gd .Operand =="\u0054\u002a"{_aaf +="\u000a";};if _gd .Operand =="\u0054\u006d"{if len (_gd .Params )!=6{continue ;};_bgg ,_eg :=_gd .Params [4].(*_fef .PdfObjectFloat );if !_eg {_efa ,_bae :=_gd .Params [4].(*_fef .PdfObjectInteger );if !_bae {continue ;};_bgg =_fef .MakeFloat (float64 (*_efa ));};_bb ,_eg :=_gd .Params [5].(*_fef .PdfObjectFloat );if !_eg {_ga ,_fgf :=_gd .Params [5].(*_fef .PdfObjectInteger );if !_fgf {continue ;};_bb =_fef .MakeFloat (float64 (*_ga ));};if _bga ==-1{_bga =float64 (*_bb );}else if _bga > float64 (*_bb ){_aaf +="\u000a";_aa =float64 (*_bgg );_bga =float64 (*_bb );continue ;};if _aa ==-1{_aa =float64 (*_bgg );}else if _aa < float64 (*_bgg ){_aaf +="\u0009";_aa =float64 (*_bgg );};};if _ec &&_gd .Operand =="\u0054\u004a"{if len (_gd .Params )< 1{continue ;};_eb ,_ab :=_gd .Params [0].(*_fef .PdfObjectArray );if !_ab {return "",_de .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064 \u0070\u0061r\u0061\u006d\u0065\u0074\u0065\u0072\u0020\u0074y\u0070\u0065\u002c\u0020\u006e\u006f\u0020\u0061\u0072\u0072\u0061\u0079 \u0028\u0025\u0054\u0029",_gd .Params [0]);};for _ ,_gde :=range _eb .Elements (){switch _cba :=_gde .(type ){case *_fef .PdfObjectString :_aaf +=_cba .Str ();case *_fef .PdfObjectFloat :if *_cba < -100{_aaf +="\u0020";};case *_fef .PdfObjectInteger :if *_cba < -100{_aaf +="\u0020";};};};}else if _ec &&_gd .Operand =="\u0054\u006a"{if len (_gd .Params )< 1{continue ;};_gb ,_bf :=_gd .Params [0].(*_fef .PdfObjectString );if !_bf {return "",_de .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0072\u0061\u006de\u0074\u0065\u0072\u0020\u0074\u0079p\u0065\u002c\u0020\u006e\u006f\u0074\u0020\u0073\u0074\u0072\u0069\u006e\u0067 \u0028\u0025\u0054\u0029",_gd .Params [0]);};_aaf +=_gb .Str ();};};return _aaf ,nil ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_quotes appends `"` operand to the content stream:
// Move to next line and show a string, using `aw` and `ac` as word
// and character spacing respectively.
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 9.4.3 "Text Showing Operators" and
// Table 209 (pp. 258-259 PDF32000_2008).
func (_bfe *ContentCreator )Add_quotes (textstr _fef .PdfObjectString ,aw ,ac float64 )*ContentCreator {_cfg :=ContentStreamOperation {};_cfg .Operand ="\u0022";_cfg .Params =_ccae ([]float64 {aw ,ac });_cfg .Params =append (_cfg .Params ,_bgaga ([]_fef .PdfObjectString {textstr })...);_bfe ._gag =append (_bfe ._gag ,&_cfg );return _bfe ;};func (_efea *ContentStreamParser )skipSpaces ()(int ,error ){_defc :=0;for {_fbca ,_bag :=_efea ._edc .Peek (1);if _bag !=nil {return 0,_bag ;};if _fef .IsWhiteSpace (_fbca [0]){_efea ._edc .ReadByte ();_defc ++;}else {break ;};};return _defc ,nil ;};func (_gagd *ContentStreamProcessor )getColorspace (_cbce string ,_dafc *_g .PdfPageResources )(_g .PdfColorspace ,error ){switch _cbce {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":return _g .NewPdfColorspaceDeviceGray (),nil ;case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":return _g .NewPdfColorspaceDeviceRGB (),nil ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return _g .NewPdfColorspaceDeviceCMYK (),nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return _g .NewPdfColorspaceSpecialPattern (),nil ;};_afff ,_bcadb :=_dafc .GetColorspaceByName (_fef .PdfObjectName (_cbce ));if _bcadb {return _afff ,nil ;};switch _cbce {case "\u0043a\u006c\u0047\u0072\u0061\u0079":return _g .NewPdfColorspaceCalGray (),nil ;case "\u0043\u0061\u006c\u0052\u0047\u0042":return _g .NewPdfColorspaceCalRGB (),nil ;case "\u004c\u0061\u0062":return _g .NewPdfColorspaceLab (),nil ;};_ce .Log .Debug ("\u0055\u006e\u006b\u006e\u006f\u0077\u006e\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070a\u0063e\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0065\u0064\u003a\u0020\u0025\u0073",_cbce );return nil ,_de .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064 \u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065:\u0020\u0025\u0073",_cbce );};func _febf (_cfdb []_fef .PdfObjectName )[]_fef .PdfObject {var _acff []_fef .PdfObject ;for _ ,_gaced :=range _cfdb {_acff =append (_acff ,_fef .MakeName (string (_gaced )));};return _acff ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Transform returns coordinates x, y transformed by the CTM.
func (_gga *GraphicsState )Transform (x ,y float64 )(float64 ,float64 ){return _gga .CTM .Transform (x ,y );};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_n appends 'n' operand to the content stream:
// End the path without filling or stroking.
2020-08-31 21:12:07 +00:00
//
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
2020-09-07 00:23:12 +00:00
func (_fda *ContentCreator )Add_n ()*ContentCreator {_eba :=ContentStreamOperation {};_eba .Operand ="\u006e";_fda ._gag =append (_fda ._gag ,&_eba );return _fda ;};
2020-08-31 21:12:07 +00:00
2020-09-07 00:23:12 +00:00
// Add_J adds 'J' operand to the content stream: Set the line cap style (graphics state).
2020-08-27 21:45:09 +00:00
//
2020-09-07 00:23:12 +00:00
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
func (_fce *ContentCreator )Add_J (lineCapStyle string )*ContentCreator {_edd :=ContentStreamOperation {};_edd .Operand ="\u004a";_edd .Params =_febf ([]_fef .PdfObjectName {_fef .PdfObjectName (lineCapStyle )});_fce ._gag =append (_fce ._gag ,&_edd );return _fce ;};
2020-08-27 21:45:09 +00:00
2020-09-07 00:23:12 +00:00
// Add_sh appends 'sh' operand to the content stream:
// Paints the shape and colour shading described by a shading dictionary specified by `name`,
// subject to the current clipping path
//
// See section 8.7.4 "Shading Patterns" and Table 77 (p. 190 PDF32000_2008).
func (_gbb *ContentCreator )Add_sh (name _fef .PdfObjectName )*ContentCreator {_fag :=ContentStreamOperation {};_fag .Operand ="\u0073\u0068";_fag .Params =_febf ([]_fef .PdfObjectName {name });_gbb ._gag =append (_gbb ._gag ,&_fag );return _gbb ;};
// NewInlineImageFromImage makes a new content stream inline image object from an image.
func NewInlineImageFromImage (img _g .Image ,encoder _fef .StreamEncoder )(*ContentStreamInlineImage ,error ){if encoder ==nil {encoder =_fef .NewRawEncoder ();};encoder .UpdateParams (img .GetParamsDict ());_ege :=ContentStreamInlineImage {};if img .ColorComponents ==1{_ege .ColorSpace =_fef .MakeName ("\u0047");}else if img .ColorComponents ==3{_ege .ColorSpace =_fef .MakeName ("\u0052\u0047\u0042");}else if img .ColorComponents ==4{_ege .ColorSpace =_fef .MakeName ("\u0043\u004d\u0059\u004b");}else {_ce .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006db\u0065\u0072\u0020o\u0066\u0020c\u006f\u006c\u006f\u0072\u0020\u0063o\u006dpo\u006e\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0072\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0064",img .ColorComponents );return nil ,_f .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072 \u006ff\u0020c\u006fl\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073");};_ege .BitsPerComponent =_fef .MakeInteger (img .BitsPerComponent );_ege .Width =_fef .MakeInteger (img .Width );_ege .Height =_fef .MakeInteger (img .Height );_ebef ,_fgb :=encoder .EncodeBytes (img .Data );if _fgb !=nil {return nil ,_fgb ;};_ege ._debc =_ebef ;_bad :=encoder .GetFilterName ();if _bad !=_fef .StreamEncodingFilterNameRaw {_ege .Filter =_fef .MakeName (_bad );};return &_ege ,nil ;};func _cdf (_edg *ContentStreamInlineImage )(*_fef .DCTEncoder ,error ){_eec :=_fef .NewDCTEncoder ();_bee :=_b .NewReader (_edg ._debc );_gdgd ,_acag :=_cb .DecodeConfig (_bee );if _acag !=nil {_ce .Log .Debug ("\u0045\u0072\u0072or\u0020\u0064\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0065\u003a\u0020\u0025\u0073",_acag );return nil ,_acag ;};switch _gdgd .ColorModel {case _ef .RGBAModel :_eec .BitsPerComponent =8;_eec .ColorComponents =3;case _ef .RGBA64Model :_eec .BitsPerComponent =16;_eec .ColorComponents =3;case _ef .GrayModel :_eec .BitsPerComponent =8;_eec .ColorComponents =1;case _ef .Gray16Model :_eec .BitsPerComponent =16;_eec .ColorComponents =1;case _ef .CMYKModel :_eec .BitsPerComponent =8;_eec .ColorComponents =4;case _ef .YCbCrModel :_eec .BitsPerComponent =8;_eec .ColorComponents =3;default:return nil ,_f .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u006d\u006f\u0064\u0065\u006c");};_eec .Width =_gdgd .Width ;_eec .Height =_gdgd .Height ;_ce .Log .Trace ("\u0044\u0043T\u0020\u0045\u006ec\u006f\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076",_eec );return _eec ,nil ;};