mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
555 lines
109 KiB
Go
555 lines
109 KiB
Go
//
|
|
// 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.
|
|
package contentstream ;import (_gg "bufio";_ba "bytes";_e "encoding/hex";_g "errors";_ec "fmt";_ee "github.com/unidoc/unipdf/v3/common";_d "github.com/unidoc/unipdf/v3/core";_gf "github.com/unidoc/unipdf/v3/internal/imageutil";_ggc "github.com/unidoc/unipdf/v3/internal/transform";_bf "github.com/unidoc/unipdf/v3/model";_a "image/color";_cg "image/jpeg";_c "io";_cf "math";_f "strconv";);
|
|
|
|
// Add_Do adds 'Do' operation to the content stream:
|
|
// Displays an XObject (image or form) specified by `name`.
|
|
//
|
|
// See section 8.8 "External Objects" and Table 87 (pp. 209-220 PDF32000_2008).
|
|
func (_ebd *ContentCreator )Add_Do (name _d .PdfObjectName )*ContentCreator {_beb :=ContentStreamOperation {};_beb .Operand ="\u0044\u006f";_beb .Params =_adde ([]_d .PdfObjectName {name });_ebd ._cbc =append (_ebd ._cbc ,&_beb );return _ebd ;};var _bcg =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{}{}};
|
|
|
|
// String is same as Bytes() except returns as a string for convenience.
|
|
func (_gfb *ContentCreator )String ()string {return string (_gfb ._cbc .Bytes ())};
|
|
|
|
// Operand returns true if `hce` is equivalent to HandlerConditionEnumOperand.
|
|
func (_dad HandlerConditionEnum )Operand ()bool {return _dad ==HandlerConditionEnumOperand };
|
|
|
|
// Add_M adds 'M' operand to the content stream: Set the miter limit (graphics state).
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_egd *ContentCreator )Add_M (miterlimit float64 )*ContentCreator {_gfg :=ContentStreamOperation {};_gfg .Operand ="\u004d";_gfg .Params =_ffee ([]float64 {miterlimit });_egd ._cbc =append (_egd ._cbc ,&_gfg );return _egd ;};
|
|
|
|
// Add_Tj appends 'Tj' operand to the content stream:
|
|
// Show a text string.
|
|
//
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
|
func (_dee *ContentCreator )Add_Tj (textstr _d .PdfObjectString )*ContentCreator {_bebd :=ContentStreamOperation {};_bebd .Operand ="\u0054\u006a";_bebd .Params =_gebb ([]_d .PdfObjectString {textstr });_dee ._cbc =append (_dee ._cbc ,&_bebd );return _dee ;};
|
|
|
|
// Add_Tw appends 'Tw' operand to the content stream:
|
|
// Set word spacing.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_fde *ContentCreator )Add_Tw (wordSpace float64 )*ContentCreator {_bfg :=ContentStreamOperation {};_bfg .Operand ="\u0054\u0077";_bfg .Params =_ffee ([]float64 {wordSpace });_fde ._cbc =append (_fde ._cbc ,&_bfg );return _fde ;};
|
|
|
|
// Add_m adds 'm' operand to the content stream: Move the current point to (x,y).
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_bee *ContentCreator )Add_m (x ,y float64 )*ContentCreator {_bbg :=ContentStreamOperation {};_bbg .Operand ="\u006d";_bbg .Params =_ffee ([]float64 {x ,y });_bee ._cbc =append (_bee ._cbc ,&_bbg );return _bee ;};
|
|
|
|
// Add_SCN_pattern appends 'SCN' operand to the content stream for pattern `name`:
|
|
// SCN with name attribute (for pattern). Syntax: c1 ... cn name SCN.
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_ded *ContentCreator )Add_SCN_pattern (name _d .PdfObjectName ,c ...float64 )*ContentCreator {_cee :=ContentStreamOperation {};_cee .Operand ="\u0053\u0043\u004e";_cee .Params =_ffee (c );_cee .Params =append (_cee .Params ,_d .MakeName (string (name )));_ded ._cbc =append (_ded ._cbc ,&_cee );return _ded ;};
|
|
|
|
// 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 _d .PdfObject ;ColorSpace _d .PdfObject ;Decode _d .PdfObject ;DecodeParms _d .PdfObject ;Filter _d .PdfObject ;Height _d .PdfObject ;ImageMask _d .PdfObject ;Intent _d .PdfObject ;Interpolate _d .PdfObject ;Width _d .PdfObject ;_bed []byte ;_abf *_gf .ImageBase ;};
|
|
|
|
// Add_l adds 'l' operand to the content stream:
|
|
// Append a straight line segment from the current point to (x,y).
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_ecd *ContentCreator )Add_l (x ,y float64 )*ContentCreator {_efe :=ContentStreamOperation {};_efe .Operand ="\u006c";_efe .Params =_ffee ([]float64 {x ,y });_ecd ._cbc =append (_ecd ._cbc ,&_efe );return _ecd ;};
|
|
|
|
// Add_Ts appends 'Ts' operand to the content stream:
|
|
// Set text rise.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_gc *ContentCreator )Add_Ts (rise float64 )*ContentCreator {_fdc :=ContentStreamOperation {};_fdc .Operand ="\u0054\u0073";_fdc .Params =_ffee ([]float64 {rise });_gc ._cbc =append (_gc ._cbc ,&_fdc );return _gc ;};func (_bdef *ContentStreamProcessor )handleCommand_CS (_ffc *ContentStreamOperation ,_bbb *_bf .PdfPageResources )error {if len (_ffc .Params )< 1{_ee .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069d\u0020\u0063\u0073\u0020\u0063\u006f\u006d\u006d\u0061\u006e\u0064\u002c\u0020s\u006b\u0069\u0070\u0070\u0069\u006e\u0067 \u006f\u0076\u0065\u0072");return _g .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_ffc .Params )> 1{_ee .Log .Debug ("\u0063\u0073\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 _g .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_ecfc ,_abbe :=_ffc .Params [0].(*_d .PdfObjectName );if !_abbe {_ee .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020c\u0073\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 _g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_dbda ,_dcf :=_bdef .getColorspace (string (*_ecfc ),_bbb );if _dcf !=nil {return _dcf ;};_bdef ._deae .ColorspaceStroking =_dbda ;_ggbd ,_dcf :=_bdef .getInitialColor (_dbda );if _dcf !=nil {return _dcf ;};_bdef ._deae .ColorStroking =_ggbd ;return nil ;};
|
|
|
|
// AddOperand adds a specified operand.
|
|
func (_gb *ContentCreator )AddOperand (op ContentStreamOperation )*ContentCreator {_gb ._cbc =append (_gb ._cbc ,&op );return _gb ;};
|
|
|
|
// NewInlineImageFromImage makes a new content stream inline image object from an image.
|
|
func NewInlineImageFromImage (img _bf .Image ,encoder _d .StreamEncoder )(*ContentStreamInlineImage ,error ){if encoder ==nil {encoder =_d .NewRawEncoder ();};encoder .UpdateParams (img .GetParamsDict ());_bbe :=ContentStreamInlineImage {};if img .ColorComponents ==1{_bbe .ColorSpace =_d .MakeName ("\u0047");}else if img .ColorComponents ==3{_bbe .ColorSpace =_d .MakeName ("\u0052\u0047\u0042");}else if img .ColorComponents ==4{_bbe .ColorSpace =_d .MakeName ("\u0043\u004d\u0059\u004b");}else {_ee .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 ,_g .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");};_bbe .BitsPerComponent =_d .MakeInteger (img .BitsPerComponent );_bbe .Width =_d .MakeInteger (img .Width );_bbe .Height =_d .MakeInteger (img .Height );_fed ,_bfca :=encoder .EncodeBytes (img .Data );if _bfca !=nil {return nil ,_bfca ;};_bbe ._bed =_fed ;_gdf :=encoder .GetFilterName ();if _gdf !=_d .StreamEncodingFilterNameRaw {_bbe .Filter =_d .MakeName (_gdf );};return &_bbe ,nil ;};func (_bcgg *ContentStreamParser )parseDict ()(*_d .PdfObjectDictionary ,error ){_ee .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");_gbaa :=_d .MakeDict ();_ccba ,_ :=_bcgg ._agd .ReadByte ();if _ccba !='<'{return nil ,_g .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};_ccba ,_ =_bcgg ._agd .ReadByte ();if _ccba !='<'{return nil ,_g .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};for {_bcgg .skipSpaces ();_fccb ,_bfd :=_bcgg ._agd .Peek (2);if _bfd !=nil {return nil ,_bfd ;};_ee .Log .Trace ("D\u0069c\u0074\u0020\u0070\u0065\u0065\u006b\u003a\u0020%\u0073\u0020\u0028\u0025 x\u0029\u0021",string (_fccb ),string (_fccb ));if (_fccb [0]=='>')&&(_fccb [1]=='>'){_ee .Log .Trace ("\u0045\u004f\u0046\u0020\u0064\u0069\u0063\u0074\u0069o\u006e\u0061\u0072\u0079");_bcgg ._agd .ReadByte ();_bcgg ._agd .ReadByte ();break ;};_ee .Log .Trace ("\u0050a\u0072s\u0065\u0020\u0074\u0068\u0065\u0020\u006e\u0061\u006d\u0065\u0021");_bca ,_bfd :=_bcgg .parseName ();_ee .Log .Trace ("\u004be\u0079\u003a\u0020\u0025\u0073",_bca );if _bfd !=nil {_ee .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",_bfd );return nil ,_bfd ;};if len (_bca )> 4&&_bca [len (_bca )-4:]=="\u006e\u0075\u006c\u006c"{_edf :=_bca [0:len (_bca )-4];_ee .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",_bca );_ee .Log .Trace ("\u004e\u0065\u0077\u0020ke\u0079\u0020\u0022\u0025\u0073\u0022\u0020\u003d\u0020\u006e\u0075\u006c\u006c",_edf );_bcgg .skipSpaces ();_ddeb ,_ :=_bcgg ._agd .Peek (1);if _ddeb [0]=='/'{_gbaa .Set (_edf ,_d .MakeNull ());continue ;};};_bcgg .skipSpaces ();_dca ,_ ,_bfd :=_bcgg .parseObject ();if _bfd !=nil {return nil ,_bfd ;};_gbaa .Set (_bca ,_dca );_ee .Log .Trace ("\u0064\u0069\u0063\u0074\u005b\u0025\u0073\u005d\u0020\u003d\u0020\u0025\u0073",_bca ,_dca .String ());};return _gbaa ,nil ;};func (_gbbf *ContentStreamParser )parseObject ()(_ccff _d .PdfObject ,_fbe bool ,_efc error ){_gbbf .skipSpaces ();for {_dcb ,_fefc :=_gbbf ._agd .Peek (2);if _fefc !=nil {return nil ,false ,_fefc ;};_ee .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_dcb ));if _dcb [0]=='%'{_gbbf .skipComments ();continue ;}else if _dcb [0]=='/'{_cgdb ,_abc :=_gbbf .parseName ();_ee .Log .Trace ("\u002d\u003e\u004ea\u006d\u0065\u003a\u0020\u0027\u0025\u0073\u0027",_cgdb );return &_cgdb ,false ,_abc ;}else if _dcb [0]=='('{_ee .Log .Trace ("\u002d>\u0053\u0074\u0072\u0069\u006e\u0067!");_cdbe ,_bgf :=_gbbf .parseString ();return _cdbe ,false ,_bgf ;}else if _dcb [0]=='<'&&_dcb [1]!='<'{_ee .Log .Trace ("\u002d\u003e\u0048\u0065\u0078\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0021");_aef ,_bgge :=_gbbf .parseHexString ();return _aef ,false ,_bgge ;}else if _dcb [0]=='['{_ee .Log .Trace ("\u002d\u003e\u0041\u0072\u0072\u0061\u0079\u0021");_gdbf ,_cgbe :=_gbbf .parseArray ();return _gdbf ,false ,_cgbe ;}else if _d .IsFloatDigit (_dcb [0])||(_dcb [0]=='-'&&_d .IsFloatDigit (_dcb [1])){_ee .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_gbaab ,_dgea :=_gbbf .parseNumber ();return _gbaab ,false ,_dgea ;}else if _dcb [0]=='<'&&_dcb [1]=='<'{_abdd ,_ccg :=_gbbf .parseDict ();return _abdd ,false ,_ccg ;}else {_ee .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_dcb ,_ =_gbbf ._agd .Peek (5);_dbd :=string (_dcb );_ee .Log .Trace ("\u0063\u006f\u006e\u0074\u0020\u0050\u0065\u0065\u006b\u0020\u0073\u0074r\u003a\u0020\u0025\u0073",_dbd );if (len (_dbd )> 3)&&(_dbd [:4]=="\u006e\u0075\u006c\u006c"){_bag ,_ddeee :=_gbbf .parseNull ();return &_bag ,false ,_ddeee ;}else if (len (_dbd )> 4)&&(_dbd [:5]=="\u0066\u0061\u006cs\u0065"){_ceeaa ,_geb :=_gbbf .parseBool ();return &_ceeaa ,false ,_geb ;}else if (len (_dbd )> 3)&&(_dbd [:4]=="\u0074\u0072\u0075\u0065"){_bgb ,_efag :=_gbbf .parseBool ();return &_bgb ,false ,_efag ;};_dabb ,_gga :=_gbbf .parseOperand ();if _gga !=nil {return _dabb ,false ,_gga ;};if len (_dabb .String ())< 1{return _dabb ,false ,ErrInvalidOperand ;};return _dabb ,true ,nil ;};};};
|
|
|
|
// 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 (_fef *ContentCreator )Add_sh (name _d .PdfObjectName )*ContentCreator {_faa :=ContentStreamOperation {};_faa .Operand ="\u0073\u0068";_faa .Params =_adde ([]_d .PdfObjectName {name });_fef ._cbc =append (_fef ._cbc ,&_faa );return _fef ;};func (_egfd *ContentStreamParser )parseName ()(_d .PdfObjectName ,error ){_fgaa :="";_ecdg :=false ;for {_efbf ,_ebb :=_egfd ._agd .Peek (1);if _ebb ==_c .EOF {break ;};if _ebb !=nil {return _d .PdfObjectName (_fgaa ),_ebb ;};if !_ecdg {if _efbf [0]=='/'{_ecdg =true ;_egfd ._agd .ReadByte ();}else {_ee .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",_efbf ,_efbf );return _d .PdfObjectName (_fgaa ),_ec .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006ea\u006d\u0065:\u0020\u0028\u0025\u0063\u0029",_efbf [0]);};}else {if _d .IsWhiteSpace (_efbf [0]){break ;}else if (_efbf [0]=='/')||(_efbf [0]=='[')||(_efbf [0]=='(')||(_efbf [0]==']')||(_efbf [0]=='<')||(_efbf [0]=='>'){break ;}else if _efbf [0]=='#'{_ffb ,_ceea :=_egfd ._agd .Peek (3);if _ceea !=nil {return _d .PdfObjectName (_fgaa ),_ceea ;};_egfd ._agd .Discard (3);_agef ,_ceea :=_e .DecodeString (string (_ffb [1:3]));if _ceea !=nil {return _d .PdfObjectName (_fgaa ),_ceea ;};_fgaa +=string (_agef );}else {_gafg ,_ :=_egfd ._agd .ReadByte ();_fgaa +=string (_gafg );};};};return _d .PdfObjectName (_fgaa ),nil ;};
|
|
|
|
// 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 (_bac *ContentCreator )Add_RG (r ,g ,b float64 )*ContentCreator {_dc :=ContentStreamOperation {};_dc .Operand ="\u0052\u0047";_dc .Params =_ffee ([]float64 {r ,g ,b });_bac ._cbc =append (_bac ._cbc ,&_dc );return _bac ;};
|
|
|
|
// 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 (_afd *ContentCreator )Add_w (lineWidth float64 )*ContentCreator {_cea :=ContentStreamOperation {};_cea .Operand ="\u0077";_cea .Params =_ffee ([]float64 {lineWidth });_afd ._cbc =append (_afd ._cbc ,&_cea );return _afd ;};
|
|
|
|
// Add_Q adds 'Q' operand to the content stream: Pops the most recently stored state from the stack.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_caf *ContentCreator )Add_Q ()*ContentCreator {_cae :=ContentStreamOperation {};_cae .Operand ="\u0051";_caf ._cbc =append (_caf ._cbc ,&_cae );return _caf ;};func _ceag (_ggf *ContentStreamInlineImage )(_d .StreamEncoder ,error ){if _ggf .Filter ==nil {return _d .NewRawEncoder (),nil ;};_cda ,_age :=_ggf .Filter .(*_d .PdfObjectName );if !_age {_gdd ,_fgg :=_ggf .Filter .(*_d .PdfObjectArray );if !_fgg {return nil ,_ec .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 _gdd .Len ()==0{return _d .NewRawEncoder (),nil ;};if _gdd .Len ()!=1{_ceb ,_adf :=_fga (_ggf );if _adf !=nil {_ee .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",_adf );return nil ,_adf ;};_ee .Log .Trace ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063:\u0020\u0025\u0073\u000a",_ceb );return _ceb ,nil ;};_dfg :=_gdd .Get (0);_cda ,_fgg =_dfg .(*_d .PdfObjectName );if !_fgg {return nil ,_ec .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 *_cda {case "\u0041\u0048\u0078","\u0041\u0053\u0043\u0049\u0049\u0048\u0065\u0078\u0044e\u0063\u006f\u0064\u0065":return _d .NewASCIIHexEncoder (),nil ;case "\u0041\u0038\u0035","\u0041\u0053\u0043\u0049\u0049\u0038\u0035\u0044\u0065\u0063\u006f\u0064\u0065":return _d .NewASCII85Encoder (),nil ;case "\u0044\u0043\u0054","\u0044C\u0054\u0044\u0065\u0063\u006f\u0064e":return _cbg (_ggf );case "\u0046\u006c","F\u006c\u0061\u0074\u0065\u0044\u0065\u0063\u006f\u0064\u0065":return _dfge (_ggf ,nil );case "\u004c\u005a\u0057","\u004cZ\u0057\u0044\u0065\u0063\u006f\u0064e":return _fdg (_ggf ,nil );case "\u0043\u0043\u0046","\u0043\u0043\u0049\u0054\u0054\u0046\u0061\u0078\u0044e\u0063\u006f\u0064\u0065":return _d .NewCCITTFaxEncoder (),nil ;case "\u0052\u004c","\u0052u\u006eL\u0065\u006e\u0067\u0074\u0068\u0044\u0065\u0063\u006f\u0064\u0065":return _d .NewRunLengthEncoder (),nil ;default:_ee .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",*_cda );return nil ,_g .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");};};
|
|
|
|
// RotateDeg applies a rotation to the transformation matrix.
|
|
func (_ged *ContentCreator )RotateDeg (angle float64 )*ContentCreator {_fdf :=_cf .Cos (angle *_cf .Pi /180.0);_bab :=_cf .Sin (angle *_cf .Pi /180.0);_bg :=-_cf .Sin (angle *_cf .Pi /180.0);_bde :=_cf .Cos (angle *_cf .Pi /180.0);return _ged .Add_cm (_fdf ,_bab ,_bg ,_bde ,0,0);};
|
|
|
|
// Add_s appends 's' operand to the content stream: Close and stroke the path.
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_cgb *ContentCreator )Add_s ()*ContentCreator {_ccf :=ContentStreamOperation {};_ccf .Operand ="\u0073";_cgb ._cbc =append (_cgb ._cbc ,&_ccf );return _cgb ;};
|
|
|
|
// ContentCreator is a builder for PDF content streams.
|
|
type ContentCreator struct{_cbc ContentStreamOperations };
|
|
|
|
// Add_B appends 'B' operand to the content stream:
|
|
// Fill and then stroke the path (nonzero winding number rule).
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_dddd *ContentCreator )Add_B ()*ContentCreator {_aac :=ContentStreamOperation {};_aac .Operand ="\u0042";_dddd ._cbc =append (_dddd ._cbc ,&_aac );return _dddd ;};func _dfge (_fgb *ContentStreamInlineImage ,_gcd *_d .PdfObjectDictionary )(*_d .FlateEncoder ,error ){_gdb :=_d .NewFlateEncoder ();if _fgb ._abf !=nil {_gdb .SetImage (_fgb ._abf );};if _gcd ==nil {_bcb :=_fgb .DecodeParms ;if _bcb !=nil {_ege ,_gba :=_d .GetDict (_bcb );if !_gba {_ee .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",_bcb );return nil ,_ec .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_gcd =_ege ;};};if _gcd ==nil {return _gdb ,nil ;};_ee .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_gcd .String ());_cba :=_gcd .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _cba ==nil {_ee .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 {_ggdd ,_dccb :=_cba .(*_d .PdfObjectInteger );if !_dccb {_ee .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",_cba );return nil ,_ec .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_gdb .Predictor =int (*_ggdd );};_cba =_gcd .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _cba !=nil {_ccb ,_bge :=_cba .(*_d .PdfObjectInteger );if !_bge {_ee .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 ,_ec .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_gdb .BitsPerComponent =int (*_ccb );};if _gdb .Predictor > 1{_gdb .Columns =1;_cba =_gcd .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _cba !=nil {_gae ,_dbgb :=_cba .(*_d .PdfObjectInteger );if !_dbgb {return nil ,_ec .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_gdb .Columns =int (*_gae );};_gdb .Colors =1;_fae :=_gcd .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _fae !=nil {_eag ,_bbge :=_fae .(*_d .PdfObjectInteger );if !_bbge {return nil ,_ec .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");};_gdb .Colors =int (*_eag );};};return _gdb ,nil ;};
|
|
|
|
// Add_Tz appends 'Tz' operand to the content stream:
|
|
// Set horizontal scaling.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_ggd *ContentCreator )Add_Tz (scale float64 )*ContentCreator {_gaf :=ContentStreamOperation {};_gaf .Operand ="\u0054\u007a";_gaf .Params =_ffee ([]float64 {scale });_ggd ._cbc =append (_ggd ._cbc ,&_gaf );return _ggd ;};
|
|
|
|
// 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 (_egb *ContentCreator )Add_SC (c ...float64 )*ContentCreator {_cad :=ContentStreamOperation {};_cad .Operand ="\u0053\u0043";_cad .Params =_ffee (c );_egb ._cbc =append (_egb ._cbc ,&_cad );return _egb ;};func _edfc (_cegb []int64 )[]_d .PdfObject {var _dfb []_d .PdfObject ;for _ ,_afcc :=range _cegb {_dfb =append (_dfb ,_d .MakeInteger (_afcc ));};return _dfb ;};
|
|
|
|
// All returns true if `hce` is equivalent to HandlerConditionEnumAllOperands.
|
|
func (_ffa HandlerConditionEnum )All ()bool {return _ffa ==HandlerConditionEnumAllOperands };func _cca (_cdc string )bool {_ ,_badb :=_bcg [_cdc ];return _badb };
|
|
|
|
// 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 _bf .PdfColorspace ;ColorspaceNonStroking _bf .PdfColorspace ;ColorStroking _bf .PdfColor ;ColorNonStroking _bf .PdfColor ;CTM _ggc .Matrix ;};
|
|
|
|
// ContentStreamParser represents a content stream parser for parsing content streams in PDFs.
|
|
type ContentStreamParser struct{_agd *_gg .Reader };func (_ef *ContentStreamOperations )isWrapped ()bool {if len (*_ef )< 2{return false ;};_be :=0;for _ ,_ca :=range *_ef {if _ca .Operand =="\u0071"{_be ++;}else if _ca .Operand =="\u0051"{_be --;}else {if _be < 1{return false ;};};};return _be ==0;};
|
|
|
|
// 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).
|
|
func (_cfg *ContentCreator )Add_Tstar ()*ContentCreator {_ecdd :=ContentStreamOperation {};_ecdd .Operand ="\u0054\u002a";_cfg ._cbc =append (_cfg ._cbc ,&_ecdd );return _cfg ;};
|
|
|
|
// Add_cs appends 'cs' operand to the content stream:
|
|
// Same as CS but for non-stroking operations.
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_add *ContentCreator )Add_cs (name _d .PdfObjectName )*ContentCreator {_acb :=ContentStreamOperation {};_acb .Operand ="\u0063\u0073";_acb .Params =_adde ([]_d .PdfObjectName {name });_add ._cbc =append (_add ._cbc ,&_acb );return _add ;};func _fga (_ece *ContentStreamInlineImage )(*_d .MultiEncoder ,error ){_eab :=_d .NewMultiEncoder ();var _gfgd *_d .PdfObjectDictionary ;var _gddb []_d .PdfObject ;if _gge :=_ece .DecodeParms ;_gge !=nil {_dfd ,_gbg :=_gge .(*_d .PdfObjectDictionary );if _gbg {_gfgd =_dfd ;};_bafc ,_dgd :=_gge .(*_d .PdfObjectArray );if _dgd {for _ ,_cfee :=range _bafc .Elements (){if _fgab ,_gfe :=_cfee .(*_d .PdfObjectDictionary );_gfe {_gddb =append (_gddb ,_fgab );}else {_gddb =append (_gddb ,nil );};};};};_gda :=_ece .Filter ;if _gda ==nil {return nil ,_ec .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006d\u0069s\u0073\u0069\u006e\u0067");};_ebca ,_aff :=_gda .(*_d .PdfObjectArray );if !_aff {return nil ,_ec .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 _eda ,_cebe :=range _ebca .Elements (){_bgef ,_daf :=_cebe .(*_d .PdfObjectName );if !_daf {return nil ,_ec .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 _cfbb _d .PdfObject ;if _gfgd !=nil {_cfbb =_gfgd ;}else {if len (_gddb )> 0{if _eda >=len (_gddb ){return nil ,_ec .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");};_cfbb =_gddb [_eda ];};};var _gea *_d .PdfObjectDictionary ;if _ggbe ,_dbc :=_cfbb .(*_d .PdfObjectDictionary );_dbc {_gea =_ggbe ;};if *_bgef ==_d .StreamEncodingFilterNameFlate ||*_bgef =="\u0046\u006c"{_abg ,_cddd :=_dfge (_ece ,_gea );if _cddd !=nil {return nil ,_cddd ;};_eab .AddEncoder (_abg );}else if *_bgef ==_d .StreamEncodingFilterNameLZW {_agfc ,_gaa :=_fdg (_ece ,_gea );if _gaa !=nil {return nil ,_gaa ;};_eab .AddEncoder (_agfc );}else if *_bgef ==_d .StreamEncodingFilterNameASCIIHex {_cafa :=_d .NewASCIIHexEncoder ();_eab .AddEncoder (_cafa );}else if *_bgef ==_d .StreamEncodingFilterNameASCII85 ||*_bgef =="\u0041\u0038\u0035"{_cdb :=_d .NewASCII85Encoder ();_eab .AddEncoder (_cdb );}else {_ee .Log .Error ("U\u006e\u0073\u0075\u0070po\u0072t\u0065\u0064\u0020\u0066\u0069l\u0074\u0065\u0072\u0020\u0025\u0073",*_bgef );return nil ,_ec .Errorf ("\u0069\u006eva\u006c\u0069\u0064 \u0066\u0069\u006c\u0074er \u0069n \u006d\u0075\u006c\u0074\u0069\u0020\u0066il\u0074\u0065\u0072\u0020\u0061\u0072\u0072a\u0079");};};return _eab ,nil ;};
|
|
|
|
// Add_Tc appends 'Tc' operand to the content stream:
|
|
// Set character spacing.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_bdgc *ContentCreator )Add_Tc (charSpace float64 )*ContentCreator {_ade :=ContentStreamOperation {};_ade .Operand ="\u0054\u0063";_ade .Params =_ffee ([]float64 {charSpace });_bdgc ._cbc =append (_bdgc ._cbc ,&_ade );return _bdgc ;};
|
|
|
|
// 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 (_fab *ContentStreamInlineImage )IsMask ()(bool ,error ){if _fab .ImageMask !=nil {_afb ,_dge :=_fab .ImageMask .(*_d .PdfObjectBool );if !_dge {_ee .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 ,_g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u0079\u0070\u0065");};return bool (*_afb ),nil ;};return false ,nil ;};
|
|
|
|
// Add_J adds 'J' operand to the content stream: Set the line cap style (graphics state).
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_eaa *ContentCreator )Add_J (lineCapStyle string )*ContentCreator {_bb :=ContentStreamOperation {};_bb .Operand ="\u004a";_bb .Params =_adde ([]_d .PdfObjectName {_d .PdfObjectName (lineCapStyle )});_eaa ._cbc =append (_eaa ._cbc ,&_bb );return _eaa ;};func (_abd *ContentStreamParser )parseOperand ()(*_d .PdfObjectString ,error ){var _gcg []byte ;for {_dbaf ,_eeeb :=_abd ._agd .Peek (1);if _eeeb !=nil {return _d .MakeString (string (_gcg )),_eeeb ;};if _d .IsDelimiter (_dbaf [0]){break ;};if _d .IsWhiteSpace (_dbaf [0]){break ;};_agdg ,_ :=_abd ._agd .ReadByte ();_gcg =append (_gcg ,_agdg );};return _d .MakeString (string (_gcg )),nil ;};
|
|
|
|
// WriteString outputs the object as it is to be written to file.
|
|
func (_ffg *ContentStreamInlineImage )WriteString ()string {var _efb _ba .Buffer ;_eada :="";if _ffg .BitsPerComponent !=nil {_eada +="\u002f\u0042\u0050C\u0020"+_ffg .BitsPerComponent .WriteString ()+"\u000a";};if _ffg .ColorSpace !=nil {_eada +="\u002f\u0043\u0053\u0020"+_ffg .ColorSpace .WriteString ()+"\u000a";};if _ffg .Decode !=nil {_eada +="\u002f\u0044\u0020"+_ffg .Decode .WriteString ()+"\u000a";};if _ffg .DecodeParms !=nil {_eada +="\u002f\u0044\u0050\u0020"+_ffg .DecodeParms .WriteString ()+"\u000a";};if _ffg .Filter !=nil {_eada +="\u002f\u0046\u0020"+_ffg .Filter .WriteString ()+"\u000a";};if _ffg .Height !=nil {_eada +="\u002f\u0048\u0020"+_ffg .Height .WriteString ()+"\u000a";};if _ffg .ImageMask !=nil {_eada +="\u002f\u0049\u004d\u0020"+_ffg .ImageMask .WriteString ()+"\u000a";};if _ffg .Intent !=nil {_eada +="\u002f\u0049\u006e\u0074\u0065\u006e\u0074\u0020"+_ffg .Intent .WriteString ()+"\u000a";};if _ffg .Interpolate !=nil {_eada +="\u002f\u0049\u0020"+_ffg .Interpolate .WriteString ()+"\u000a";};if _ffg .Width !=nil {_eada +="\u002f\u0057\u0020"+_ffg .Width .WriteString ()+"\u000a";};_efb .WriteString (_eada );_efb .WriteString ("\u0049\u0044\u0020");_efb .Write (_ffg ._bed );_efb .WriteString ("\u000a\u0045\u0049\u000a");return _efb .String ();};func (_bcgf *ContentStreamProcessor )handleCommand_rg (_ecg *ContentStreamOperation ,_egaa *_bf .PdfPageResources )error {_gbe :=_bf .NewPdfColorspaceDeviceRGB ();if len (_ecg .Params )!=_gbe .GetNumComponents (){_ee .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");_ee .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 (_ecg .Params ),_gbe );return _g .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");};_ffag ,_gcef :=_gbe .ColorFromPdfObjects (_ecg .Params );if _gcef !=nil {return _gcef ;};_bcgf ._deae .ColorspaceNonStroking =_gbe ;_bcgf ._deae .ColorNonStroking =_ffag ;return nil ;};
|
|
|
|
// Parse parses all commands in content stream, returning a list of operation data.
|
|
func (_afc *ContentStreamParser )Parse ()(*ContentStreamOperations ,error ){_fcad :=ContentStreamOperations {};for {_dddg :=ContentStreamOperation {};for {_fgc ,_fceb ,_aaf :=_afc .parseObject ();if _aaf !=nil {if _aaf ==_c .EOF {return &_fcad ,nil ;};return &_fcad ,_aaf ;};if _fceb {_dddg .Operand ,_ =_d .GetStringVal (_fgc );_fcad =append (_fcad ,&_dddg );break ;}else {_dddg .Params =append (_dddg .Params ,_fgc );};};if _dddg .Operand =="\u0042\u0049"{_gace ,_eefc :=_afc .ParseInlineImage ();if _eefc !=nil {return &_fcad ,_eefc ;};_dddg .Params =append (_dddg .Params ,_gace );};};};
|
|
|
|
// Add_EMC appends 'EMC' operand to the content stream:
|
|
// Ends a marked-content sequence.
|
|
//
|
|
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
|
|
func (_cfb *ContentCreator )Add_EMC ()*ContentCreator {_baa :=ContentStreamOperation {};_baa .Operand ="\u0045\u004d\u0043";_cfb ._cbc =append (_cfb ._cbc ,&_baa );return _cfb ;};
|
|
|
|
// GraphicStateStack represents a stack of GraphicsState.
|
|
type GraphicStateStack []GraphicsState ;func _ffee (_ccbd []float64 )[]_d .PdfObject {var _bgd []_d .PdfObject ;for _ ,_afeb :=range _ccbd {_bgd =append (_bgd ,_d .MakeFloat (_afeb ));};return _bgd ;};
|
|
|
|
// Add_ET appends 'ET' operand to the content stream:
|
|
// End text.
|
|
//
|
|
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
|
|
func (_ced *ContentCreator )Add_ET ()*ContentCreator {_bbd :=ContentStreamOperation {};_bbd .Operand ="\u0045\u0054";_ced ._cbc =append (_ced ._cbc ,&_bbd );return _ced ;};
|
|
|
|
// 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).
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_agge *ContentCreator )Add_re (x ,y ,width ,height float64 )*ContentCreator {_eac :=ContentStreamOperation {};_eac .Operand ="\u0072\u0065";_eac .Params =_ffee ([]float64 {x ,y ,width ,height });_agge ._cbc =append (_agge ._cbc ,&_eac );return _agge ;};
|
|
|
|
// 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 (_aca *ContentCreator )Add_TD (tx ,ty float64 )*ContentCreator {_feb :=ContentStreamOperation {};_feb .Operand ="\u0054\u0044";_feb .Params =_ffee ([]float64 {tx ,ty });_aca ._cbc =append (_aca ._cbc ,&_feb );return _aca ;};
|
|
|
|
// Add_cm adds 'cm' operation to the content stream: Modifies the current transformation matrix (ctm)
|
|
// of the graphics state.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_gbd *ContentCreator )Add_cm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_ab :=ContentStreamOperation {};_ab .Operand ="\u0063\u006d";_ab .Params =_ffee ([]float64 {a ,b ,c ,d ,e ,f });_gbd ._cbc =append (_gbd ._cbc ,&_ab );return _gbd ;};
|
|
|
|
// 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 (_beee *ContentCreator )Add_K (c ,m ,y ,k float64 )*ContentCreator {_bfe :=ContentStreamOperation {};_bfe .Operand ="\u004b";_bfe .Params =_ffee ([]float64 {c ,m ,y ,k });_beee ._cbc =append (_beee ._cbc ,&_bfe );return _beee ;};
|
|
|
|
// Add_G appends 'G' operand to the content stream:
|
|
// Set the stroking colorspace to DeviceGray and sets the gray level (0-1).
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_fcc *ContentCreator )Add_G (gray float64 )*ContentCreator {_cdd :=ContentStreamOperation {};_cdd .Operand ="\u0047";_cdd .Params =_ffee ([]float64 {gray });_fcc ._cbc =append (_fcc ._cbc ,&_cdd );return _fcc ;};
|
|
|
|
// Add_W_starred appends 'W*' operand to the content stream:
|
|
// Modify the current clipping path by intersecting with the current path (even odd rule).
|
|
//
|
|
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
|
|
func (_fcd *ContentCreator )Add_W_starred ()*ContentCreator {_ff :=ContentStreamOperation {};_ff .Operand ="\u0057\u002a";_fcd ._cbc =append (_fcd ._cbc ,&_ff );return _fcd ;};
|
|
|
|
// 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 (_cgc *ContentCreator )Add_SCN (c ...float64 )*ContentCreator {_ebc :=ContentStreamOperation {};_ebc .Operand ="\u0053\u0043\u004e";_ebc .Params =_ffee (c );_cgc ._cbc =append (_cgc ._cbc ,&_ebc );return _cgc ;};
|
|
|
|
// NewContentStreamProcessor returns a new ContentStreamProcessor for operations `ops`.
|
|
func NewContentStreamProcessor (ops []*ContentStreamOperation )*ContentStreamProcessor {_aec :=ContentStreamProcessor {};_aec ._cafe =GraphicStateStack {};_afff :=GraphicsState {};_aec ._deae =_afff ;_aec ._cded =[]handlerEntry {};_aec ._aebf =0;_aec ._cdeb =ops ;return &_aec ;};
|
|
|
|
// GetEncoder returns the encoder of the inline image.
|
|
func (_aacd *ContentStreamInlineImage )GetEncoder ()(_d .StreamEncoder ,error ){return _ceag (_aacd )};
|
|
|
|
// 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 (_gcf *ContentCreator )Add_TJ (vals ..._d .PdfObject )*ContentCreator {_aaab :=ContentStreamOperation {};_aaab .Operand ="\u0054\u004a";_aaab .Params =[]_d .PdfObject {_d .MakeArray (vals ...)};_gcf ._cbc =append (_gcf ._cbc ,&_aaab );return _gcf ;};
|
|
|
|
// Add_B_starred appends 'B*' operand to the content stream:
|
|
// Fill and then stroke the path (even-odd rule).
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_afe *ContentCreator )Add_B_starred ()*ContentCreator {_ae :=ContentStreamOperation {};_ae .Operand ="\u0042\u002a";_afe ._cbc =append (_afe ._cbc ,&_ae );return _afe ;};
|
|
|
|
// 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).
|
|
func (_db *ContentCreator )Add_gs (dictName _d .PdfObjectName )*ContentCreator {_acc :=ContentStreamOperation {};_acc .Operand ="\u0067\u0073";_acc .Params =_adde ([]_d .PdfObjectName {dictName });_db ._cbc =append (_db ._cbc ,&_acc );return _db ;};
|
|
|
|
// ToImage exports the inline image to Image which can be transformed or exported easily.
|
|
// Page resources are needed to look up colorspace information.
|
|
func (_gcb *ContentStreamInlineImage )ToImage (resources *_bf .PdfPageResources )(*_bf .Image ,error ){_fca ,_dba :=_gcb .toImageBase (resources );if _dba !=nil {return nil ,_dba ;};_adfg ,_dba :=_ceag (_gcb );if _dba !=nil {return nil ,_dba ;};_ee .Log .Trace ("\u0065n\u0063o\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076\u0020\u0025\u0054",_adfg ,_adfg );_ee .Log .Trace ("\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065:\u0020\u0025\u002b\u0076",_gcb );_bfeg ,_dba :=_adfg .DecodeBytes (_gcb ._bed );if _dba !=nil {return nil ,_dba ;};_faf :=&_bf .Image {Width :int64 (_fca .Width ),Height :int64 (_fca .Height ),BitsPerComponent :int64 (_fca .BitsPerComponent ),ColorComponents :_fca .ColorComponents ,Data :_bfeg };if len (_fca .Decode )> 0{for _dfdc :=0;_dfdc < len (_fca .Decode );_dfdc ++{_fca .Decode [_dfdc ]*=float64 ((int (1)<<uint (_fca .BitsPerComponent ))-1);};_faf .SetDecode (_fca .Decode );};return _faf ,nil ;};func (_gaag *ContentStreamParser )parseBool ()(_d .PdfObjectBool ,error ){_cbae ,_gbb :=_gaag ._agd .Peek (4);if _gbb !=nil {return _d .PdfObjectBool (false ),_gbb ;};if (len (_cbae )>=4)&&(string (_cbae [:4])=="\u0074\u0072\u0075\u0065"){_gaag ._agd .Discard (4);return _d .PdfObjectBool (true ),nil ;};_cbae ,_gbb =_gaag ._agd .Peek (5);if _gbb !=nil {return _d .PdfObjectBool (false ),_gbb ;};if (len (_cbae )>=5)&&(string (_cbae [:5])=="\u0066\u0061\u006cs\u0065"){_gaag ._agd .Discard (5);return _d .PdfObjectBool (false ),nil ;};return _d .PdfObjectBool (false ),_g .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
|
|
|
|
// 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.
|
|
//
|
|
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
|
|
func (_cega *ContentCreator )Add_BMC (tag _d .PdfObjectName )*ContentCreator {_ace :=ContentStreamOperation {};_ace .Operand ="\u0042\u004d\u0043";_ace .Params =_adde ([]_d .PdfObjectName {tag });_cega ._cbc =append (_cega ._cbc ,&_ace );return _cega ;};
|
|
|
|
// Add_Tm appends 'Tm' operand to the content stream:
|
|
// Set the text line matrix.
|
|
//
|
|
// See section 9.4.2 "Text Positioning Operators" and
|
|
// Table 108 (pp. 257-258 PDF32000_2008).
|
|
func (_eef *ContentCreator )Add_Tm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_dbb :=ContentStreamOperation {};_dbb .Operand ="\u0054\u006d";_dbb .Params =_ffee ([]float64 {a ,b ,c ,d ,e ,f });_eef ._cbc =append (_eef ._cbc ,&_dbb );return _eef ;};
|
|
|
|
// AddHandler adds a new ContentStreamProcessor `handler` of type `condition` for `operand`.
|
|
func (_edac *ContentStreamProcessor )AddHandler (condition HandlerConditionEnum ,operand string ,handler HandlerFunc ){_dafb :=handlerEntry {};_dafb .Condition =condition ;_dafb .Operand =operand ;_dafb .Handler =handler ;_edac ._cded =append (_edac ._cded ,_dafb );};
|
|
|
|
// ContentStreamOperation represents an operation in PDF contentstream which consists of
|
|
// an operand and parameters.
|
|
type ContentStreamOperation struct{Params []_d .PdfObject ;Operand string ;};func (_bdca *ContentStreamParser )skipComments ()error {if _ ,_ccag :=_bdca .skipSpaces ();_ccag !=nil {return _ccag ;};_ggea :=true ;for {_bebc ,_badd :=_bdca ._agd .Peek (1);if _badd !=nil {_ee .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_badd .Error ());return _badd ;};if _ggea &&_bebc [0]!='%'{return nil ;};_ggea =false ;if (_bebc [0]!='\r')&&(_bebc [0]!='\n'){_bdca ._agd .ReadByte ();}else {break ;};};return _bdca .skipComments ();};func (_cfdf *ContentStreamProcessor )handleCommand_cs (_efad *ContentStreamOperation ,_cddf *_bf .PdfPageResources )error {if len (_efad .Params )< 1{_ee .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 _g .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_efad .Params )> 1{_ee .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 _g .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_gcbc ,_afg :=_efad .Params [0].(*_d .PdfObjectName );if !_afg {_ee .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 _g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_dced ,_ddff :=_cfdf .getColorspace (string (*_gcbc ),_cddf );if _ddff !=nil {return _ddff ;};_cfdf ._deae .ColorspaceNonStroking =_dced ;_bcac ,_ddff :=_cfdf .getInitialColor (_dced );if _ddff !=nil {return _ddff ;};_cfdf ._deae .ColorNonStroking =_bcac ;return nil ;};func (_cag *ContentStreamProcessor )handleCommand_k (_gefa *ContentStreamOperation ,_eeab *_bf .PdfPageResources )error {_begd :=_bf .NewPdfColorspaceDeviceCMYK ();if len (_gefa .Params )!=_begd .GetNumComponents (){_ee .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");_ee .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 (_gefa .Params ),_begd );return _g .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");};_bbac ,_ceeac :=_begd .ColorFromPdfObjects (_gefa .Params );if _ceeac !=nil {return _ceeac ;};_cag ._deae .ColorspaceNonStroking =_begd ;_cag ._deae .ColorNonStroking =_bbac ;return nil ;};
|
|
|
|
// Add_scn_pattern appends 'scn' operand to the content stream for pattern `name`:
|
|
// scn with name attribute (for pattern). Syntax: c1 ... cn name scn.
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_gac *ContentCreator )Add_scn_pattern (name _d .PdfObjectName ,c ...float64 )*ContentCreator {_dbg :=ContentStreamOperation {};_dbg .Operand ="\u0073\u0063\u006e";_dbg .Params =_ffee (c );_dbg .Params =append (_dbg .Params ,_d .MakeName (string (name )));_gac ._cbc =append (_gac ._cbc ,&_dbg );return _gac ;};
|
|
|
|
// 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 (_bdc *ContentCreator )Bytes ()[]byte {return _bdc ._cbc .Bytes ()};
|
|
|
|
// Add_j adds 'j' operand to the content stream: Set the line join style (graphics state).
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_ecf *ContentCreator )Add_j (lineJoinStyle string )*ContentCreator {_ddd :=ContentStreamOperation {};_ddd .Operand ="\u006a";_ddd .Params =_adde ([]_d .PdfObjectName {_d .PdfObjectName (lineJoinStyle )});_ecf ._cbc =append (_ecf ._cbc ,&_ddd );return _ecf ;};
|
|
|
|
// Add_n appends 'n' operand to the content stream:
|
|
// End the path without filling or stroking.
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_fdb *ContentCreator )Add_n ()*ContentCreator {_gd :=ContentStreamOperation {};_gd .Operand ="\u006e";_fdb ._cbc =append (_fdb ._cbc ,&_gd );return _fdb ;};
|
|
|
|
// 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 (_de *ContentStreamOperations )Bytes ()[]byte {var _eb _ba .Buffer ;for _ ,_fg :=range *_de {if _fg ==nil {continue ;};if _fg .Operand =="\u0042\u0049"{_eb .WriteString (_fg .Operand +"\u000a");_eb .WriteString (_fg .Params [0].WriteString ());}else {for _ ,_ea :=range _fg .Params {_eb .WriteString (_ea .WriteString ());_eb .WriteString ("\u0020");};_eb .WriteString (_fg .Operand +"\u000a");};};return _eb .Bytes ();};
|
|
|
|
// Add_f_starred appends 'f*' operand to the content stream.
|
|
// f*: Fill the path using the even-odd rule to determine fill region.
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_adc *ContentCreator )Add_f_starred ()*ContentCreator {_aa :=ContentStreamOperation {};_aa .Operand ="\u0066\u002a";_adc ._cbc =append (_adc ._cbc ,&_aa );return _adc ;};
|
|
|
|
// GetColorSpace returns the colorspace of the inline image.
|
|
func (_ebe *ContentStreamInlineImage )GetColorSpace (resources *_bf .PdfPageResources )(_bf .PdfColorspace ,error ){if _ebe .ColorSpace ==nil {_ee .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 _bf .NewPdfColorspaceDeviceGray (),nil ;};if _cebb ,_badg :=_ebe .ColorSpace .(*_d .PdfObjectArray );_badg {return _dfde (_cebb );};_aae ,_cced :=_ebe .ColorSpace .(*_d .PdfObjectName );if !_cced {_ee .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",_ebe .ColorSpace ,_ebe .ColorSpace );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_aae =="\u0047"||*_aae =="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"{return _bf .NewPdfColorspaceDeviceGray (),nil ;}else if *_aae =="\u0052\u0047\u0042"||*_aae =="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"{return _bf .NewPdfColorspaceDeviceRGB (),nil ;}else if *_aae =="\u0043\u004d\u0059\u004b"||*_aae =="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{return _bf .NewPdfColorspaceDeviceCMYK (),nil ;}else if *_aae =="\u0049"||*_aae =="\u0049n\u0064\u0065\u0078\u0065\u0064"{return nil ,_g .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 {_ee .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",*_aae );return nil ,_g .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};_agfg ,_eec :=resources .GetColorspaceByName (*_aae );if !_eec {_ee .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",*_aae );return nil ,_g .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};return _agfg ,nil ;};};const (HandlerConditionEnumOperand HandlerConditionEnum =iota ;HandlerConditionEnumAllOperands ;);
|
|
|
|
// 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.
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_agg *ContentCreator )Add_v (x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_edg :=ContentStreamOperation {};_edg .Operand ="\u0076";_edg .Params =_ffee ([]float64 {x2 ,y2 ,x3 ,y3 });_agg ._cbc =append (_agg ._cbc ,&_edg );return _agg ;};
|
|
|
|
// 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 (_cfa *ContentStreamOperations )WrapIfNeeded ()*ContentStreamOperations {if len (*_cfa )==0{return _cfa ;};if _cfa .isWrapped (){return _cfa ;};*_cfa =append ([]*ContentStreamOperation {{Operand :"\u0071"}},*_cfa ...);_cga :=0;for _ ,_ecb :=range *_cfa {if _ecb .Operand =="\u0071"{_cga ++;}else if _ecb .Operand =="\u0051"{_cga --;};};for _cga > 0{*_cfa =append (*_cfa ,&ContentStreamOperation {Operand :"\u0051"});_cga --;};return _cfa ;};
|
|
|
|
// 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.
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_cbd *ContentCreator )Add_h ()*ContentCreator {_bga :=ContentStreamOperation {};_bga .Operand ="\u0068";_cbd ._cbc =append (_cbd ._cbc ,&_bga );return _cbd ;};func (_cge *ContentStreamParser )parseHexString ()(*_d .PdfObjectString ,error ){_cge ._agd .ReadByte ();_aeg :=[]byte ("\u0030\u0031\u0032\u003345\u0036\u0037\u0038\u0039\u0061\u0062\u0063\u0064\u0065\u0066\u0041\u0042\u0043\u0044E\u0046");var _fcg []byte ;for {_cge .skipSpaces ();_febd ,_ffe :=_cge ._agd .Peek (1);if _ffe !=nil {return _d .MakeString (""),_ffe ;};if _febd [0]=='>'{_cge ._agd .ReadByte ();break ;};_baab ,_ :=_cge ._agd .ReadByte ();if _ba .IndexByte (_aeg ,_baab )>=0{_fcg =append (_fcg ,_baab );};};if len (_fcg )%2==1{_fcg =append (_fcg ,'0');};_bdf ,_ :=_e .DecodeString (string (_fcg ));return _d .MakeHexString (string (_bdf )),nil ;};
|
|
|
|
// Add_d adds 'd' operand to the content stream: Set the line dash pattern.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_fcb *ContentCreator )Add_d (dashArray []int64 ,dashPhase int64 )*ContentCreator {_fdfg :=ContentStreamOperation {};_fdfg .Operand ="\u0064";_fdfg .Params =[]_d .PdfObject {};_fdfg .Params =append (_fdfg .Params ,_d .MakeArrayFromIntegers64 (dashArray ));_fdfg .Params =append (_fdfg .Params ,_d .MakeInteger (dashPhase ));_fcb ._cbc =append (_fcb ._cbc ,&_fdfg );return _fcb ;};func (_fbg *ContentStreamParser )parseNull ()(_d .PdfObjectNull ,error ){_ ,_abe :=_fbg ._agd .Discard (4);return _d .PdfObjectNull {},_abe ;};
|
|
|
|
// Add_k appends 'k' operand to the content stream:
|
|
// Same as K but used for nonstroking operations.
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_deg *ContentCreator )Add_k (c ,m ,y ,k float64 )*ContentCreator {_gff :=ContentStreamOperation {};_gff .Operand ="\u006b";_gff .Params =_ffee ([]float64 {c ,m ,y ,k });_deg ._cbc =append (_deg ._cbc ,&_gff );return _deg ;};func (_edafg *ContentStreamProcessor )handleCommand_RG (_gdgg *ContentStreamOperation ,_fea *_bf .PdfPageResources )error {_dbdag :=_bf .NewPdfColorspaceDeviceRGB ();if len (_gdgg .Params )!=_dbdag .GetNumComponents (){_ee .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");_ee .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 (_gdgg .Params ),_dbdag );return _g .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");};_aeca ,_fbgg :=_dbdag .ColorFromPdfObjects (_gdgg .Params );if _fbgg !=nil {return _fbgg ;};_edafg ._deae .ColorspaceStroking =_dbdag ;_edafg ._deae .ColorStroking =_aeca ;return nil ;};func (_ebg *ContentStreamInlineImage )toImageBase (_efa *_bf .PdfPageResources )(*_gf .ImageBase ,error ){if _ebg ._abf !=nil {return _ebg ._abf ,nil ;};_aeb :=_gf .ImageBase {};if _ebg .Height ==nil {return nil ,_g .New ("\u0068e\u0069\u0067\u0068\u0074\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_geg ,_eacg :=_ebg .Height .(*_d .PdfObjectInteger );if !_eacg {return nil ,_g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0068e\u0069\u0067\u0068\u0074");};_aeb .Height =int (*_geg );if _ebg .Width ==nil {return nil ,_g .New ("\u0077\u0069\u0064th\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_ada ,_eacg :=_ebg .Width .(*_d .PdfObjectInteger );if !_eacg {return nil ,_g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0069\u0064\u0074\u0068");};_aeb .Width =int (*_ada );_cdddg ,_ddbb :=_ebg .IsMask ();if _ddbb !=nil {return nil ,_ddbb ;};if _cdddg {_aeb .BitsPerComponent =1;_aeb .ColorComponents =1;}else {if _ebg .BitsPerComponent ==nil {_ee .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");_aeb .BitsPerComponent =8;}else {_bafd ,_acac :=_ebg .BitsPerComponent .(*_d .PdfObjectInteger );if !_acac {_ee .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",_ebg .BitsPerComponent );return nil ,_g .New ("\u0042\u0050\u0043\u0020\u0054\u0079\u0070\u0065\u0020e\u0072\u0072\u006f\u0072");};_aeb .BitsPerComponent =int (*_bafd );};if _ebg .ColorSpace !=nil {_fba ,_ffgc :=_ebg .GetColorSpace (_efa );if _ffgc !=nil {return nil ,_ffgc ;};_aeb .ColorComponents =_fba .GetNumComponents ();}else {_ee .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");_aeb .ColorComponents =1;};};if _cfba ,_fac :=_d .GetArray (_ebg .Decode );_fac {_aeb .Decode ,_ddbb =_cfba .ToFloat64Array ();if _ddbb !=nil {return nil ,_ddbb ;};};_ebg ._abf =&_aeb ;return _ebg ._abf ,nil ;};func (_bcd *ContentStreamProcessor )handleCommand_sc (_ebbf *ContentStreamOperation ,_gaec *_bf .PdfPageResources )error {_dggf :=_bcd ._deae .ColorspaceNonStroking ;if !_fdbfa (_dggf ){if len (_ebbf .Params )!=_dggf .GetNumComponents (){_ee .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");_ee .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 (_ebbf .Params ),_dggf );return _g .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");};};_dfgf ,_gce :=_dggf .ColorFromPdfObjects (_ebbf .Params );if _gce !=nil {return _gce ;};_bcd ._deae .ColorNonStroking =_dfgf ;return nil ;};
|
|
|
|
// Add_quote appends "'" operand to the content stream:
|
|
// Move to next line and show a string.
|
|
//
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
|
func (_df *ContentCreator )Add_quote (textstr _d .PdfObjectString )*ContentCreator {_gedf :=ContentStreamOperation {};_gedf .Operand ="\u0027";_gedf .Params =_gebb ([]_d .PdfObjectString {textstr });_df ._cbc =append (_df ._cbc ,&_gedf );return _df ;};
|
|
|
|
// 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{_cafe GraphicStateStack ;_cdeb []*ContentStreamOperation ;_deae GraphicsState ;_cded []handlerEntry ;_aebf int ;};
|
|
|
|
// Add_b appends 'b' operand to the content stream:
|
|
// Close, fill and then stroke the path (nonzero winding number rule).
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_fa *ContentCreator )Add_b ()*ContentCreator {_fe :=ContentStreamOperation {};_fe .Operand ="\u0062";_fa ._cbc =append (_fa ._cbc ,&_fe );return _fa ;};func (_gbfg *ContentStreamProcessor )getInitialColor (_ccdb _bf .PdfColorspace )(_bf .PdfColor ,error ){switch _agda :=_ccdb .(type ){case *_bf .PdfColorspaceDeviceGray :return _bf .NewPdfColorDeviceGray (0.0),nil ;case *_bf .PdfColorspaceDeviceRGB :return _bf .NewPdfColorDeviceRGB (0.0,0.0,0.0),nil ;case *_bf .PdfColorspaceDeviceCMYK :return _bf .NewPdfColorDeviceCMYK (0.0,0.0,0.0,1.0),nil ;case *_bf .PdfColorspaceCalGray :return _bf .NewPdfColorCalGray (0.0),nil ;case *_bf .PdfColorspaceCalRGB :return _bf .NewPdfColorCalRGB (0.0,0.0,0.0),nil ;case *_bf .PdfColorspaceLab :_fbab :=0.0;_deef :=0.0;_feff :=0.0;if _agda .Range [0]> 0{_fbab =_agda .Range [0];};if _agda .Range [2]> 0{_deef =_agda .Range [2];};return _bf .NewPdfColorLab (_fbab ,_deef ,_feff ),nil ;case *_bf .PdfColorspaceICCBased :if _agda .Alternate ==nil {_ee .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",_agda .N );if _agda .N ==1{_ee .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 _gbfg .getInitialColor (_bf .NewPdfColorspaceDeviceGray ());}else if _agda .N ==3{_ee .Log .Trace ("\u0046a\u006c\u006c\u0069\u006eg\u0020\u0062\u0061\u0063\u006b \u0074o\u0020D\u0065\u0076\u0069\u0063\u0065\u0052\u0047B");return _gbfg .getInitialColor (_bf .NewPdfColorspaceDeviceRGB ());}else if _agda .N ==4{_ee .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 _gbfg .getInitialColor (_bf .NewPdfColorspaceDeviceCMYK ());}else {return nil ,_g .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 _gbfg .getInitialColor (_agda .Alternate );case *_bf .PdfColorspaceSpecialIndexed :if _agda .Base ==nil {return nil ,_g .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 _gbfg .getInitialColor (_agda .Base );case *_bf .PdfColorspaceSpecialSeparation :if _agda .AlternateSpace ==nil {return nil ,_g .New ("\u0061\u006ct\u0065\u0072\u006e\u0061\u0074\u0065\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069fi\u0065\u0064");};return _gbfg .getInitialColor (_agda .AlternateSpace );case *_bf .PdfColorspaceDeviceN :if _agda .AlternateSpace ==nil {return nil ,_g .New ("\u0061\u006ct\u0065\u0072\u006e\u0061\u0074\u0065\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069fi\u0065\u0064");};return _gbfg .getInitialColor (_agda .AlternateSpace );case *_bf .PdfColorspaceSpecialPattern :return nil ,nil ;};_ee .Log .Debug ("Un\u0061\u0062l\u0065\u0020\u0074\u006f\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0069\u006e\u0069\u0074\u0069\u0061\u006c\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u0066\u006f\u0072\u0020\u0075\u006e\u006b\u006e\u006fw\u006e \u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061c\u0065:\u0020\u0025T",_ccdb );return nil ,_g .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061c\u0065");};func (_bda *ContentStreamInlineImage )String ()string {_dga :=_ec .Sprintf ("I\u006el\u0069\u006e\u0065\u0049\u006d\u0061\u0067\u0065(\u006c\u0065\u006e\u003d%d\u0029\u000a",len (_bda ._bed ));if _bda .BitsPerComponent !=nil {_dga +="\u002d\u0020\u0042\u0050\u0043\u0020"+_bda .BitsPerComponent .WriteString ()+"\u000a";};if _bda .ColorSpace !=nil {_dga +="\u002d\u0020\u0043S\u0020"+_bda .ColorSpace .WriteString ()+"\u000a";};if _bda .Decode !=nil {_dga +="\u002d\u0020\u0044\u0020"+_bda .Decode .WriteString ()+"\u000a";};if _bda .DecodeParms !=nil {_dga +="\u002d\u0020\u0044P\u0020"+_bda .DecodeParms .WriteString ()+"\u000a";};if _bda .Filter !=nil {_dga +="\u002d\u0020\u0046\u0020"+_bda .Filter .WriteString ()+"\u000a";};if _bda .Height !=nil {_dga +="\u002d\u0020\u0048\u0020"+_bda .Height .WriteString ()+"\u000a";};if _bda .ImageMask !=nil {_dga +="\u002d\u0020\u0049M\u0020"+_bda .ImageMask .WriteString ()+"\u000a";};if _bda .Intent !=nil {_dga +="\u002d \u0049\u006e\u0074\u0065\u006e\u0074 "+_bda .Intent .WriteString ()+"\u000a";};if _bda .Interpolate !=nil {_dga +="\u002d\u0020\u0049\u0020"+_bda .Interpolate .WriteString ()+"\u000a";};if _bda .Width !=nil {_dga +="\u002d\u0020\u0057\u0020"+_bda .Width .WriteString ()+"\u000a";};return _dga ;};
|
|
|
|
// Scale applies x-y scaling to the transformation matrix.
|
|
func (_dde *ContentCreator )Scale (sx ,sy float64 )*ContentCreator {return _dde .Add_cm (sx ,0,0,sy ,0,0);};func (_ecfe *ContentStreamParser )parseString ()(*_d .PdfObjectString ,error ){_ecfe ._agd .ReadByte ();var _gfga []byte ;_cdbf :=1;for {_gfbb ,_acea :=_ecfe ._agd .Peek (1);if _acea !=nil {return _d .MakeString (string (_gfga )),_acea ;};if _gfbb [0]=='\\'{_ecfe ._agd .ReadByte ();_bdac ,_aab :=_ecfe ._agd .ReadByte ();if _aab !=nil {return _d .MakeString (string (_gfga )),_aab ;};if _d .IsOctalDigit (_bdac ){_ddc ,_fdfd :=_ecfe ._agd .Peek (2);if _fdfd !=nil {return _d .MakeString (string (_gfga )),_fdfd ;};var _fafb []byte ;_fafb =append (_fafb ,_bdac );for _ ,_cff :=range _ddc {if _d .IsOctalDigit (_cff ){_fafb =append (_fafb ,_cff );}else {break ;};};_ecfe ._agd .Discard (len (_fafb )-1);_ee .Log .Trace ("\u004e\u0075\u006d\u0065ri\u0063\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u0020\u0022\u0025\u0073\u0022",_fafb );_gdag ,_fdfd :=_f .ParseUint (string (_fafb ),8,32);if _fdfd !=nil {return _d .MakeString (string (_gfga )),_fdfd ;};_gfga =append (_gfga ,byte (_gdag ));continue ;};switch _bdac {case 'n':_gfga =append (_gfga ,'\n');case 'r':_gfga =append (_gfga ,'\r');case 't':_gfga =append (_gfga ,'\t');case 'b':_gfga =append (_gfga ,'\b');case 'f':_gfga =append (_gfga ,'\f');case '(':_gfga =append (_gfga ,'(');case ')':_gfga =append (_gfga ,')');case '\\':_gfga =append (_gfga ,'\\');};continue ;}else if _gfbb [0]=='('{_cdbf ++;}else if _gfbb [0]==')'{_cdbf --;if _cdbf ==0{_ecfe ._agd .ReadByte ();break ;};};_cbga ,_ :=_ecfe ._agd .ReadByte ();_gfga =append (_gfga ,_cbga );};return _d .MakeString (string (_gfga )),nil ;};func (_bebe *ContentStreamProcessor )handleCommand_K (_bgac *ContentStreamOperation ,_dcfe *_bf .PdfPageResources )error {_ebcd :=_bf .NewPdfColorspaceDeviceCMYK ();if len (_bgac .Params )!=_ebcd .GetNumComponents (){_ee .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");_ee .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 (_bgac .Params ),_ebcd );return _g .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");};_fbb ,_daa :=_ebcd .ColorFromPdfObjects (_bgac .Params );if _daa !=nil {return _daa ;};_bebe ._deae .ColorspaceStroking =_ebcd ;_bebe ._deae .ColorStroking =_fbb ;return nil ;};func (_dgab *ContentStreamParser )parseArray ()(*_d .PdfObjectArray ,error ){_aag :=_d .MakeArray ();_dgab ._agd .ReadByte ();for {_dgab .skipSpaces ();_dfe ,_bedg :=_dgab ._agd .Peek (1);if _bedg !=nil {return _aag ,_bedg ;};if _dfe [0]==']'{_dgab ._agd .ReadByte ();break ;};_dbgf ,_ ,_bedg :=_dgab .parseObject ();if _bedg !=nil {return _aag ,_bedg ;};_aag .Append (_dbgf );};return _aag ,nil ;};
|
|
|
|
// Add_Tf appends 'Tf' operand to the content stream:
|
|
// Set font and font size specified by font resource `fontName` and `fontSize`.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_aaa *ContentCreator )Add_Tf (fontName _d .PdfObjectName ,fontSize float64 )*ContentCreator {_eeg :=ContentStreamOperation {};_eeg .Operand ="\u0054\u0066";_eeg .Params =_adde ([]_d .PdfObjectName {fontName });_eeg .Params =append (_eeg .Params ,_ffee ([]float64 {fontSize })...);_aaa ._cbc =append (_aaa ._cbc ,&_eeg );return _aaa ;};func (_ccgb *ContentStreamProcessor )handleCommand_scn (_ceae *ContentStreamOperation ,_eeeg *_bf .PdfPageResources )error {_fage :=_ccgb ._deae .ColorspaceNonStroking ;if !_fdbfa (_fage ){if len (_ceae .Params )!=_fage .GetNumComponents (){_ee .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");_ee .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 (_ceae .Params ),_fage );return _g .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");};};_aaec ,_edd :=_fage .ColorFromPdfObjects (_ceae .Params );if _edd !=nil {_ee .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",_ceae .Params ,_fage );return _edd ;};_ccgb ._deae .ColorNonStroking =_aaec ;return nil ;};func (_cfdfe *ContentStreamProcessor )handleCommand_SC (_aacc *ContentStreamOperation ,_cebd *_bf .PdfPageResources )error {_afgc :=_cfdfe ._deae .ColorspaceStroking ;if len (_aacc .Params )!=_afgc .GetNumComponents (){_ee .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");_ee .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 (_aacc .Params ),_afgc );return _g .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");};_gbc ,_ebdg :=_afgc .ColorFromPdfObjects (_aacc .Params );if _ebdg !=nil {return _ebdg ;};_cfdfe ._deae .ColorStroking =_gbc ;return nil ;};var (ErrInvalidOperand =_g .New ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064"););
|
|
|
|
// Add_TL appends 'TL' operand to the content stream:
|
|
// Set leading.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_fdbf *ContentCreator )Add_TL (leading float64 )*ContentCreator {_gbf :=ContentStreamOperation {};_gbf .Operand ="\u0054\u004c";_gbf .Params =_ffee ([]float64 {leading });_fdbf ._cbc =append (_fdbf ._cbc ,&_gbf );return _fdbf ;};func _fdg (_bebg *ContentStreamInlineImage ,_ceaf *_d .PdfObjectDictionary )(*_d .LZWEncoder ,error ){_degc :=_d .NewLZWEncoder ();if _ceaf ==nil {if _bebg .DecodeParms !=nil {_egef ,_gde :=_d .GetDict (_bebg .DecodeParms );if !_gde {_ee .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",_bebg .DecodeParms );return nil ,_ec .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_ceaf =_egef ;};};if _ceaf ==nil {return _degc ,nil ;};_bba :=_ceaf .Get ("E\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");if _bba !=nil {_bgg ,_acd :=_bba .(*_d .PdfObjectInteger );if !_acd {_ee .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",_bba );return nil ,_ec .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");};if *_bgg !=0&&*_bgg !=1{return nil ,_ec .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");};_degc .EarlyChange =int (*_bgg );}else {_degc .EarlyChange =1;};_bba =_ceaf .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _bba !=nil {_eee ,_bae :=_bba .(*_d .PdfObjectInteger );if !_bae {_ee .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",_bba );return nil ,_ec .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_degc .Predictor =int (*_eee );};_bba =_ceaf .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _bba !=nil {_abb ,_bcca :=_bba .(*_d .PdfObjectInteger );if !_bcca {_ee .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 ,_ec .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_degc .BitsPerComponent =int (*_abb );};if _degc .Predictor > 1{_degc .Columns =1;_bba =_ceaf .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _bba !=nil {_bdee ,_dddc :=_bba .(*_d .PdfObjectInteger );if !_dddc {return nil ,_ec .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_degc .Columns =int (*_bdee );};_degc .Colors =1;_bba =_ceaf .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _bba !=nil {_ecdde ,_dff :=_bba .(*_d .PdfObjectInteger );if !_dff {return nil ,_ec .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");};_degc .Colors =int (*_ecdde );};};_ee .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_ceaf .String ());return _degc ,nil ;};
|
|
|
|
// Add_S appends 'S' operand to the content stream: Stroke the path.
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_cgd *ContentCreator )Add_S ()*ContentCreator {_da :=ContentStreamOperation {};_da .Operand ="\u0053";_cgd ._cbc =append (_cgd ._cbc ,&_da );return _cgd ;};func _fdbfa (_cgea _bf .PdfColorspace )bool {_ ,_cgg :=_cgea .(*_bf .PdfColorspaceSpecialPattern );return _cgg ;};
|
|
|
|
// 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 (_ddf *ContentCreator )Add_y (x1 ,y1 ,x3 ,y3 float64 )*ContentCreator {_dec :=ContentStreamOperation {};_dec .Operand ="\u0079";_dec .Params =_ffee ([]float64 {x1 ,y1 ,x3 ,y3 });_ddf ._cbc =append (_ddf ._cbc ,&_dec );return _ddf ;};
|
|
|
|
// Add_ri adds 'ri' operand to the content stream, which sets the color rendering intent.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_ede *ContentCreator )Add_ri (intent _d .PdfObjectName )*ContentCreator {_ggb :=ContentStreamOperation {};_ggb .Operand ="\u0072\u0069";_ggb .Params =_adde ([]_d .PdfObjectName {intent });_ede ._cbc =append (_ede ._cbc ,&_ggb );return _ede ;};func (_adga *ContentStreamProcessor )getColorspace (_bbeb string ,_aaeg *_bf .PdfPageResources )(_bf .PdfColorspace ,error ){switch _bbeb {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":return _bf .NewPdfColorspaceDeviceGray (),nil ;case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":return _bf .NewPdfColorspaceDeviceRGB (),nil ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return _bf .NewPdfColorspaceDeviceCMYK (),nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return _bf .NewPdfColorspaceSpecialPattern (),nil ;};_ega ,_afa :=_aaeg .GetColorspaceByName (_d .PdfObjectName (_bbeb ));if _afa {return _ega ,nil ;};switch _bbeb {case "\u0043a\u006c\u0047\u0072\u0061\u0079":return _bf .NewPdfColorspaceCalGray (),nil ;case "\u0043\u0061\u006c\u0052\u0047\u0042":return _bf .NewPdfColorspaceCalRGB (),nil ;case "\u004c\u0061\u0062":return _bf .NewPdfColorspaceLab (),nil ;};_ee .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",_bbeb );return nil ,_ec .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",_bbeb );};
|
|
|
|
// Push pushes `gs` on the `gsStack`.
|
|
func (_adad *GraphicStateStack )Push (gs GraphicsState ){*_adad =append (*_adad ,gs )};
|
|
|
|
// 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 (_bbf *ContentCreator )Add_g (gray float64 )*ContentCreator {_cce :=ContentStreamOperation {};_cce .Operand ="\u0067";_cce .Params =_ffee ([]float64 {gray });_bbf ._cbc =append (_bbf ._cbc ,&_cce );return _bbf ;};
|
|
|
|
// 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 (_gfa *ContentCreator )Add_CS (name _d .PdfObjectName )*ContentCreator {_bff :=ContentStreamOperation {};_bff .Operand ="\u0043\u0053";_bff .Params =_adde ([]_d .PdfObjectName {name });_gfa ._cbc =append (_gfa ._cbc ,&_bff );return _gfa ;};func (_fff *ContentStreamProcessor )handleCommand_cm (_ebbb *ContentStreamOperation ,_bgc *_bf .PdfPageResources )error {if len (_ebbb .Params )!=6{_ee .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 (_ebbb .Params ));return _g .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");};_bbbf ,_deeb :=_d .GetNumbersAsFloat (_ebbb .Params );if _deeb !=nil {return _deeb ;};_cdeg :=_ggc .NewMatrix (_bbbf [0],_bbbf [1],_bbbf [2],_bbbf [3],_bbbf [4],_bbbf [5]);_fff ._deae .CTM .Concat (_cdeg );return nil ;};
|
|
|
|
// 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.
|
|
//
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
|
func (_agc *ContentCreator )Add_quotes (textstr _d .PdfObjectString ,aw ,ac float64 )*ContentCreator {_fce :=ContentStreamOperation {};_fce .Operand ="\u0022";_fce .Params =_ffee ([]float64 {aw ,ac });_fce .Params =append (_fce .Params ,_gebb ([]_d .PdfObjectString {textstr })...);_agc ._cbc =append (_agc ._cbc ,&_fce );return _agc ;};func (_fda *ContentStreamParser )skipSpaces ()(int ,error ){_deb :=0;for {_dbe ,_gdc :=_fda ._agd .Peek (1);if _gdc !=nil {return 0,_gdc ;};if _d .IsWhiteSpace (_dbe [0]){_fda ._agd .ReadByte ();_deb ++;}else {break ;};};return _deb ,nil ;};
|
|
|
|
// Add_f appends 'f' operand to the content stream:
|
|
// Fill the path using the nonzero winding number rule to determine fill region.
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_bbc *ContentCreator )Add_f ()*ContentCreator {_ga :=ContentStreamOperation {};_ga .Operand ="\u0066";_bbc ._cbc =append (_bbc ._cbc ,&_ga );return _bbc ;};func (_dbgc *ContentStreamProcessor )handleCommand_g (_dbdf *ContentStreamOperation ,_eged *_bf .PdfPageResources )error {_beg :=_bf .NewPdfColorspaceDeviceGray ();if len (_dbdf .Params )!=_beg .GetNumComponents (){_ee .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");_ee .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 (_dbdf .Params ),_beg );return _g .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");};_adag ,_edaf :=_beg .ColorFromPdfObjects (_dbdf .Params );if _edaf !=nil {_ee .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",_beg ,_dbdf ,_edaf );return _edaf ;};_dbgc ._deae .ColorspaceNonStroking =_beg ;_dbgc ._deae .ColorNonStroking =_adag ;return nil ;};
|
|
|
|
// Add_Tr appends 'Tr' operand to the content stream:
|
|
// Set text rendering mode.
|
|
//
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
func (_bgad *ContentCreator )Add_Tr (render int64 )*ContentCreator {_dab :=ContentStreamOperation {};_dab .Operand ="\u0054\u0072";_dab .Params =_edfc ([]int64 {render });_bgad ._cbc =append (_bgad ._cbc ,&_dab );return _bgad ;};func _adde (_febf []_d .PdfObjectName )[]_d .PdfObject {var _edab []_d .PdfObject ;for _ ,_abfd :=range _febf {_edab =append (_edab ,_d .MakeName (string (_abfd )));};return _edab ;};
|
|
|
|
// NewContentStreamParser creates a new instance of the content stream parser from an input content
|
|
// stream string.
|
|
func NewContentStreamParser (contentStr string )*ContentStreamParser {_fee :=ContentStreamParser {};_adg :=_ba .NewBufferString (contentStr +"\u000a");_fee ._agd =_gg .NewReader (_adg );return &_fee ;};
|
|
|
|
// 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 (_cgde *ContentCreator )Add_Td (tx ,ty float64 )*ContentCreator {_ceg :=ContentStreamOperation {};_ceg .Operand ="\u0054\u0064";_ceg .Params =_ffee ([]float64 {tx ,ty });_cgde ._cbc =append (_cgde ._cbc ,&_ceg );return _cgde ;};
|
|
|
|
// Add_b_starred appends 'b*' operand to the content stream:
|
|
// Close, fill and then stroke the path (even-odd winding number rule).
|
|
//
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
func (_cab *ContentCreator )Add_b_starred ()*ContentCreator {_eff :=ContentStreamOperation {};_eff .Operand ="\u0062\u002a";_cab ._cbc =append (_cab ._cbc ,&_eff );return _cab ;};func _dfde (_ageg _d .PdfObject )(_bf .PdfColorspace ,error ){_eeaa ,_cfbeg :=_ageg .(*_d .PdfObjectArray );if !_cfbeg {_ee .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",_ageg );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if _eeaa .Len ()!=4{_ee .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",_eeaa .Len ());return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_aad ,_cfbeg :=_eeaa .Get (0).(*_d .PdfObjectName );if !_cfbeg {_ee .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",*_eeaa );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_aad !="\u0049"&&*_aad !="\u0049n\u0064\u0065\u0078\u0065\u0064"{_ee .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",*_aad );return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_aad ,_cfbeg =_eeaa .Get (1).(*_d .PdfObjectName );if !_cfbeg {_ee .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",*_eeaa );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_aad !="\u0047"&&*_aad !="\u0052\u0047\u0042"&&*_aad !="\u0043\u004d\u0059\u004b"&&*_aad !="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"&&*_aad !="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"&&*_aad !="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{_ee .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",*_aad );return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_cddc :="";switch *_aad {case "\u0047","\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_cddc ="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079";case "\u0052\u0047\u0042","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_cddc ="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B";case "\u0043\u004d\u0059\u004b","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_cddc ="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b";};_cbbf :=_d .MakeArray (_d .MakeName ("\u0049n\u0064\u0065\u0078\u0065\u0064"),_d .MakeName (_cddc ),_eeaa .Get (2),_eeaa .Get (3));return _bf .NewPdfColorspaceFromPdfObject (_cbbf );};func (_fbf *ContentStreamProcessor )handleCommand_SCN (_fcde *ContentStreamOperation ,_ccge *_bf .PdfPageResources )error {_gbdf :=_fbf ._deae .ColorspaceStroking ;if !_fdbfa (_gbdf ){if len (_fcde .Params )!=_gbdf .GetNumComponents (){_ee .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");_ee .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 (_fcde .Params ),_gbdf );return _g .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");};};_ecdge ,_ccdd :=_gbdf .ColorFromPdfObjects (_fcde .Params );if _ccdd !=nil {return _ccdd ;};_fbf ._deae .ColorStroking =_ecdge ;return nil ;};
|
|
|
|
// HandlerFunc is the function syntax that the ContentStreamProcessor handler must implement.
|
|
type HandlerFunc func (_aee *ContentStreamOperation ,_ggde GraphicsState ,_aaea *_bf .PdfPageResources )error ;
|
|
|
|
// Operations returns the list of operations.
|
|
func (_gef *ContentCreator )Operations ()*ContentStreamOperations {return &_gef ._cbc };
|
|
|
|
// Add_scn appends 'scn' operand to the content stream:
|
|
// Same as SC but for nonstroking operations.
|
|
//
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
func (_ccd *ContentCreator )Add_scn (c ...float64 )*ContentCreator {_ccfd :=ContentStreamOperation {};_ccfd .Operand ="\u0073\u0063\u006e";_ccfd .Params =_ffee (c );_ccd ._cbc =append (_ccd ._cbc ,&_ccfd );return _ccd ;};func (_ebda *ContentStreamProcessor )handleCommand_G (_aabg *ContentStreamOperation ,_cadd *_bf .PdfPageResources )error {_bggc :=_bf .NewPdfColorspaceDeviceGray ();if len (_aabg .Params )!=_bggc .GetNumComponents (){_ee .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");_ee .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 (_aabg .Params ),_bggc );return _g .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");};_eadb ,_ecfec :=_bggc .ColorFromPdfObjects (_aabg .Params );if _ecfec !=nil {return _ecfec ;};_ebda ._deae .ColorspaceStroking =_bggc ;_ebda ._deae .ColorStroking =_eadb ;return nil ;};
|
|
|
|
// 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 (_cec *ContentStreamProcessor )Process (resources *_bf .PdfPageResources )error {_cec ._deae .ColorspaceStroking =_bf .NewPdfColorspaceDeviceGray ();_cec ._deae .ColorspaceNonStroking =_bf .NewPdfColorspaceDeviceGray ();_cec ._deae .ColorStroking =_bf .NewPdfColorDeviceGray (0);_cec ._deae .ColorNonStroking =_bf .NewPdfColorDeviceGray (0);_cec ._deae .CTM =_ggc .IdentityMatrix ();for _ ,_fgcf :=range _cec ._cdeb {var _bcge error ;switch _fgcf .Operand {case "\u0071":_cec ._cafe .Push (_cec ._deae );case "\u0051":if len (_cec ._cafe )==0{_ee .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 ;};_cec ._deae =_cec ._cafe .Pop ();case "\u0043\u0053":_bcge =_cec .handleCommand_CS (_fgcf ,resources );case "\u0063\u0073":_bcge =_cec .handleCommand_cs (_fgcf ,resources );case "\u0053\u0043":_bcge =_cec .handleCommand_SC (_fgcf ,resources );case "\u0053\u0043\u004e":_bcge =_cec .handleCommand_SCN (_fgcf ,resources );case "\u0073\u0063":_bcge =_cec .handleCommand_sc (_fgcf ,resources );case "\u0073\u0063\u006e":_bcge =_cec .handleCommand_scn (_fgcf ,resources );case "\u0047":_bcge =_cec .handleCommand_G (_fgcf ,resources );case "\u0067":_bcge =_cec .handleCommand_g (_fgcf ,resources );case "\u0052\u0047":_bcge =_cec .handleCommand_RG (_fgcf ,resources );case "\u0072\u0067":_bcge =_cec .handleCommand_rg (_fgcf ,resources );case "\u004b":_bcge =_cec .handleCommand_K (_fgcf ,resources );case "\u006b":_bcge =_cec .handleCommand_k (_fgcf ,resources );case "\u0063\u006d":_bcge =_cec .handleCommand_cm (_fgcf ,resources );};if _bcge !=nil {_ee .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",_fgcf .Operand ,_bcge );_ee .Log .Debug ("\u004f\u0070\u0065r\u0061\u006e\u0064\u003a\u0020\u0025\u0023\u0076",_fgcf .Operand );return _bcge ;};for _ ,_ffd :=range _cec ._cded {var _gdfg error ;if _ffd .Condition .All (){_gdfg =_ffd .Handler (_fgcf ,_cec ._deae ,resources );}else if _ffd .Condition .Operand ()&&_fgcf .Operand ==_ffd .Operand {_gdfg =_ffd .Handler (_fgcf ,_cec ._deae ,resources );};if _gdfg !=nil {_ee .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",_gdfg );return _gdfg ;};};};return nil ;};
|
|
|
|
// Wrap ensures that the contentstream is wrapped within a balanced q ... Q expression.
|
|
func (_ac *ContentCreator )Wrap (){_ac ._cbc .WrapIfNeeded ()};
|
|
|
|
// Add_BT appends 'BT' operand to the content stream:
|
|
// Begin text.
|
|
//
|
|
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
|
|
func (_dcc *ContentCreator )Add_BT ()*ContentCreator {_ddee :=ContentStreamOperation {};_ddee .Operand ="\u0042\u0054";_dcc ._cbc =append (_dcc ._cbc ,&_ddee );return _dcc ;};
|
|
|
|
// SetStrokingColor sets the stroking `color` where color can be one of
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
func (_decb *ContentCreator )SetStrokingColor (color _bf .PdfColor )*ContentCreator {switch _aga :=color .(type ){case *_bf .PdfColorDeviceGray :_decb .Add_G (_aga .Val ());case *_bf .PdfColorDeviceRGB :_decb .Add_RG (_aga .R (),_aga .G (),_aga .B ());case *_bf .PdfColorDeviceCMYK :_decb .Add_K (_aga .C (),_aga .M (),_aga .Y (),_aga .K ());default:_ee .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",_aga );};return _decb ;};func (_cddb *ContentStreamParser )parseNumber ()(_d .PdfObject ,error ){return _d .ParseNumber (_cddb ._agd );};
|
|
|
|
// String returns `ops.Bytes()` as a string.
|
|
func (_ead *ContentStreamOperations )String ()string {return string (_ead .Bytes ())};
|
|
|
|
// Add_i adds 'i' operand to the content stream: Set the flatness tolerance in the graphics state.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_befb *ContentCreator )Add_i (flatness float64 )*ContentCreator {_bcc :=ContentStreamOperation {};_bcc .Operand ="\u0069";_bcc .Params =_ffee ([]float64 {flatness });_befb ._cbc =append (_befb ._cbc ,&_bcc );return _befb ;};
|
|
|
|
// Pop pops and returns the topmost GraphicsState off the `gsStack`.
|
|
func (_gaca *GraphicStateStack )Pop ()GraphicsState {_afdg :=(*_gaca )[len (*_gaca )-1];*_gaca =(*_gaca )[:len (*_gaca )-1];return _afdg ;};func _cbg (_bbdc *ContentStreamInlineImage )(*_d .DCTEncoder ,error ){_adca :=_d .NewDCTEncoder ();_ggda :=_ba .NewReader (_bbdc ._bed );_cbb ,_caec :=_cg .DecodeConfig (_ggda );if _caec !=nil {_ee .Log .Debug ("\u0045\u0072\u0072or\u0020\u0064\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0065\u003a\u0020\u0025\u0073",_caec );return nil ,_caec ;};switch _cbb .ColorModel {case _a .RGBAModel :_adca .BitsPerComponent =8;_adca .ColorComponents =3;case _a .RGBA64Model :_adca .BitsPerComponent =16;_adca .ColorComponents =3;case _a .GrayModel :_adca .BitsPerComponent =8;_adca .ColorComponents =1;case _a .Gray16Model :_adca .BitsPerComponent =16;_adca .ColorComponents =1;case _a .CMYKModel :_adca .BitsPerComponent =8;_adca .ColorComponents =4;case _a .YCbCrModel :_adca .BitsPerComponent =8;_adca .ColorComponents =3;default:return nil ,_g .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u006d\u006f\u0064\u0065\u006c");};_adca .Width =_cbb .Width ;_adca .Height =_cbb .Height ;_ee .Log .Trace ("\u0044\u0043T\u0020\u0045\u006ec\u006f\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076",_adca );return _adca ,nil ;};
|
|
|
|
// 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 (_gca *ContentStreamParser )ParseInlineImage ()(*ContentStreamInlineImage ,error ){_fag :=ContentStreamInlineImage {};for {_gca .skipSpaces ();_ffge ,_fec ,_cfec :=_gca .parseObject ();if _cfec !=nil {return nil ,_cfec ;};if !_fec {_bdd ,_bdad :=_d .GetName (_ffge );if !_bdad {_ee .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",_ffge );return nil ,_ec .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",_ffge );};_dgg ,_beeg ,_gbfb :=_gca .parseObject ();if _gbfb !=nil {return nil ,_gbfb ;};if _beeg {return nil ,_ec .Errorf ("\u006eo\u0074\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067 \u0061\u006e\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};switch *_bdd {case "\u0042\u0050\u0043","\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074":_fag .BitsPerComponent =_dgg ;case "\u0043\u0053","\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065":_fag .ColorSpace =_dgg ;case "\u0044","\u0044\u0065\u0063\u006f\u0064\u0065":_fag .Decode =_dgg ;case "\u0044\u0050","D\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073":_fag .DecodeParms =_dgg ;case "\u0046","\u0046\u0069\u006c\u0074\u0065\u0072":_fag .Filter =_dgg ;case "\u0048","\u0048\u0065\u0069\u0067\u0068\u0074":_fag .Height =_dgg ;case "\u0049\u004d","\u0049m\u0061\u0067\u0065\u004d\u0061\u0073k":_fag .ImageMask =_dgg ;case "\u0049\u006e\u0074\u0065\u006e\u0074":_fag .Intent =_dgg ;case "\u0049","I\u006e\u0074\u0065\u0072\u0070\u006f\u006c\u0061\u0074\u0065":_fag .Interpolate =_dgg ;case "\u0057","\u0057\u0069\u0064t\u0068":_fag .Width =_dgg ;case "\u004c\u0065\u006e\u0067\u0074\u0068","\u0053u\u0062\u0074\u0079\u0070\u0065","\u0054\u0079\u0070\u0065":_ee .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",*_bdd );default:return nil ,_ec .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",*_bdd );};};if _fec {_agfd ,_gfab :=_ffge .(*_d .PdfObjectString );if !_gfab {return nil ,_ec .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 _agfd .Str ()=="\u0045\u0049"{_ee .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 &_fag ,nil ;}else if _agfd .Str ()=="\u0049\u0044"{_ee .Log .Trace ("\u0049\u0044\u0020\u0073\u0074\u0061\u0072\u0074");_fgf ,_cfbd :=_gca ._agd .Peek (1);if _cfbd !=nil {return nil ,_cfbd ;};if _d .IsWhiteSpace (_fgf [0]){_gca ._agd .Discard (1);};_fag ._bed =[]byte {};_deec :=0;var _dfa []byte ;for {_dce ,_bce :=_gca ._agd .ReadByte ();if _bce !=nil {_ee .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 ,_bce ;};if _deec ==0{if _d .IsWhiteSpace (_dce ){_dfa =[]byte {};_dfa =append (_dfa ,_dce );_deec =1;}else if _dce =='E'{_dfa =append (_dfa ,_dce );_deec =2;}else {_fag ._bed =append (_fag ._bed ,_dce );};}else if _deec ==1{_dfa =append (_dfa ,_dce );if _dce =='E'{_deec =2;}else {_fag ._bed =append (_fag ._bed ,_dfa ...);_dfa =[]byte {};if _d .IsWhiteSpace (_dce ){_deec =1;}else {_deec =0;};};}else if _deec ==2{_dfa =append (_dfa ,_dce );if _dce =='I'{_deec =3;}else {_fag ._bed =append (_fag ._bed ,_dfa ...);_dfa =[]byte {};_deec =0;};}else if _deec ==3{_dfa =append (_dfa ,_dce );if _d .IsWhiteSpace (_dce ){_afea ,_ggcg :=_gca ._agd .Peek (20);if _ggcg !=nil &&_ggcg !=_c .EOF {return nil ,_ggcg ;};_gfd :=NewContentStreamParser (string (_afea ));_egf :=true ;for _dgc :=0;_dgc < 3;_dgc ++{_ebcf ,_fbd ,_babb :=_gfd .parseObject ();if _babb !=nil {if _babb ==_c .EOF {break ;};continue ;};if _fbd &&!_cca (_ebcf .String ()){_egf =false ;break ;};};if _egf {if len (_fag ._bed )> 100{_ee .Log .Trace ("\u0049\u006d\u0061\u0067\u0065\u0020\u0073\u0074\u0072\u0065\u0061m\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078 \u002e\u002e\u002e",len (_fag ._bed ),_fag ._bed [:100]);}else {_ee .Log .Trace ("\u0049\u006d\u0061\u0067e \u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025 \u0078",len (_fag ._bed ),_fag ._bed );};return &_fag ,nil ;};};_fag ._bed =append (_fag ._bed ,_dfa ...);_dfa =[]byte {};_deec =0;};};};};};};type handlerEntry struct{Condition HandlerConditionEnum ;Operand string ;Handler HandlerFunc ;};
|
|
|
|
// Add_W appends 'W' operand to the content stream:
|
|
// Modify the current clipping path by intersecting with the current path (nonzero winding rule).
|
|
//
|
|
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
|
|
func (_dg *ContentCreator )Add_W ()*ContentCreator {_fdfgd :=ContentStreamOperation {};_fdfgd .Operand ="\u0057";_dg ._cbc =append (_dg ._cbc ,&_fdfgd );return _dg ;};
|
|
|
|
// Transform returns coordinates x, y transformed by the CTM.
|
|
func (_cgcf *GraphicsState )Transform (x ,y float64 )(float64 ,float64 ){return _cgcf .CTM .Transform (x ,y );};
|
|
|
|
// NewContentCreator returns a new initialized ContentCreator.
|
|
func NewContentCreator ()*ContentCreator {_ge :=&ContentCreator {};_ge ._cbc =ContentStreamOperations {};return _ge ;};
|
|
|
|
// Add_q adds 'q' operand to the content stream: Pushes the current graphics state on the stack.
|
|
//
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
func (_fd *ContentCreator )Add_q ()*ContentCreator {_ddae :=ContentStreamOperation {};_ddae .Operand ="\u0071";_fd ._cbc =append (_fd ._cbc ,&_ddae );return _fd ;};
|
|
|
|
// 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.
|
|
//
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
func (_fge *ContentCreator )Add_c (x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_bfc :=ContentStreamOperation {};_bfc .Operand ="\u0063";_bfc .Params =_ffee ([]float64 {x1 ,y1 ,x2 ,y2 ,x3 ,y3 });_fge ._cbc =append (_fge ._cbc ,&_bfc );return _fge ;};
|
|
|
|
// 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 ;func _gebb (_cegc []_d .PdfObjectString )[]_d .PdfObject {var _ggbc []_d .PdfObject ;for _ ,_cdf :=range _cegc {_ggbc =append (_ggbc ,_d .MakeString (_cdf .Str ()));};return _ggbc ;};
|
|
|
|
// SetNonStrokingColor sets the non-stroking `color` where color can be one of
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
func (_gdg *ContentCreator )SetNonStrokingColor (color _bf .PdfColor )*ContentCreator {switch _gefg :=color .(type ){case *_bf .PdfColorDeviceGray :_gdg .Add_g (_gefg .Val ());case *_bf .PdfColorDeviceRGB :_gdg .Add_rg (_gefg .R (),_gefg .G (),_gefg .B ());case *_bf .PdfColorDeviceCMYK :_gdg .Add_k (_gefg .C (),_gefg .M (),_gefg .Y (),_gefg .K ());default:_ee .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",_gefg );};return _gdg ;};
|
|
|
|
// 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 (_cfe *ContentCreator )Add_rg (r ,g ,b float64 )*ContentCreator {_agf :=ContentStreamOperation {};_agf .Operand ="\u0072\u0067";_agf .Params =_ffee ([]float64 {r ,g ,b });_cfe ._cbc =append (_cfe ._cbc ,&_agf );return _cfe ;};
|
|
|
|
// Translate applies a simple x-y translation to the transformation matrix.
|
|
func (_ed *ContentCreator )Translate (tx ,ty float64 )*ContentCreator {return _ed .Add_cm (1,0,0,1,tx ,ty );};
|
|
|
|
// 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.
|
|
//
|
|
// Deprecated: More advanced text extraction is offered in package extractor with character encoding support.
|
|
func (_eg *ContentStreamParser )ExtractText ()(string ,error ){_cd ,_af :=_eg .Parse ();if _af !=nil {return "",_af ;};_cde :=false ;_ag ,_cc :=float64 (-1),float64 (-1);_efd :="";for _ ,_cbe :=range *_cd {if _cbe .Operand =="\u0042\u0054"{_cde =true ;}else if _cbe .Operand =="\u0045\u0054"{_cde =false ;};if _cbe .Operand =="\u0054\u0064"||_cbe .Operand =="\u0054\u0044"||_cbe .Operand =="\u0054\u002a"{_efd +="\u000a";};if _cbe .Operand =="\u0054\u006d"{if len (_cbe .Params )!=6{continue ;};_ddb ,_ad :=_cbe .Params [4].(*_d .PdfObjectFloat );if !_ad {_bad ,_fb :=_cbe .Params [4].(*_d .PdfObjectInteger );if !_fb {continue ;};_ddb =_d .MakeFloat (float64 (*_bad ));};_ecc ,_ad :=_cbe .Params [5].(*_d .PdfObjectFloat );if !_ad {_ce ,_cbf :=_cbe .Params [5].(*_d .PdfObjectInteger );if !_cbf {continue ;};_ecc =_d .MakeFloat (float64 (*_ce ));};if _cc ==-1{_cc =float64 (*_ecc );}else if _cc > float64 (*_ecc ){_efd +="\u000a";_ag =float64 (*_ddb );_cc =float64 (*_ecc );continue ;};if _ag ==-1{_ag =float64 (*_ddb );}else if _ag < float64 (*_ddb ){_efd +="\u0009";_ag =float64 (*_ddb );};};if _cde &&_cbe .Operand =="\u0054\u004a"{if len (_cbe .Params )< 1{continue ;};_fcf ,_eea :=_cbe .Params [0].(*_d .PdfObjectArray );if !_eea {return "",_ec .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",_cbe .Params [0]);};for _ ,_dda :=range _fcf .Elements (){switch _bfa :=_dda .(type ){case *_d .PdfObjectString :_efd +=_bfa .Str ();case *_d .PdfObjectFloat :if *_bfa < -100{_efd +="\u0020";};case *_d .PdfObjectInteger :if *_bfa < -100{_efd +="\u0020";};};};}else if _cde &&_cbe .Operand =="\u0054\u006a"{if len (_cbe .Params )< 1{continue ;};_bef ,_bdg :=_cbe .Params [0].(*_d .PdfObjectString );if !_bdg {return "",_ec .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",_cbe .Params [0]);};_efd +=_bef .Str ();};};return _efd ,nil ;};
|
|
|
|
// ContentStreamOperations is a slice of ContentStreamOperations.
|
|
type ContentStreamOperations []*ContentStreamOperation ; |