mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +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 (_d "bufio";_ca "bytes";_fa "encoding/hex";_c "errors";_ga "fmt";_gg "github.com/unidoc/unipdf/v3/common";_ge "github.com/unidoc/unipdf/v3/core";_da "github.com/unidoc/unipdf/v3/internal/imageutil";_dd "github.com/unidoc/unipdf/v3/internal/transform";_fd "github.com/unidoc/unipdf/v3/model";_a "image/color";_cg "image/jpeg";_gf "io";_b "math";_f "strconv";);
|
|
|
|
// 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 (_fge *ContentStreamOperations )WrapIfNeeded ()*ContentStreamOperations {if len (*_fge )==0{return _fge ;};if _fge .isWrapped (){return _fge ;};*_fge =append ([]*ContentStreamOperation {{Operand :"\u0071"}},*_fge ...);_ddf :=0;for _ ,_dc :=range *_fge {if _dc .Operand =="\u0071"{_ddf ++;}else if _dc .Operand =="\u0051"{_ddf --;};};for _ddf > 0{*_fge =append (*_fge ,&ContentStreamOperation {Operand :"\u0051"});_ddf --;};return _fge ;};
|
|
|
|
// 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 (_acd *ContentCreator )Add_Tstar ()*ContentCreator {_dfd :=ContentStreamOperation {};_dfd .Operand ="\u0054\u002a";_acd ._fgea =append (_acd ._fgea ,&_dfd );return _acd ;};func (_ecf *ContentStreamParser )parseBool ()(_ge .PdfObjectBool ,error ){_gdf ,_bagg :=_ecf ._acag .Peek (4);if _bagg !=nil {return _ge .PdfObjectBool (false ),_bagg ;};if (len (_gdf )>=4)&&(string (_gdf [:4])=="\u0074\u0072\u0075\u0065"){_ecf ._acag .Discard (4);return _ge .PdfObjectBool (true ),nil ;};_gdf ,_bagg =_ecf ._acag .Peek (5);if _bagg !=nil {return _ge .PdfObjectBool (false ),_bagg ;};if (len (_gdf )>=5)&&(string (_gdf [:5])=="\u0066\u0061\u006cs\u0065"){_ecf ._acag .Discard (5);return _ge .PdfObjectBool (false ),nil ;};return _ge .PdfObjectBool (false ),_c .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
|
|
|
|
// SetStrokingColor sets the stroking `color` where color can be one of
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
func (_ffe *ContentCreator )SetStrokingColor (color _fd .PdfColor )*ContentCreator {switch _gfgf :=color .(type ){case *_fd .PdfColorDeviceGray :_ffe .Add_G (_gfgf .Val ());case *_fd .PdfColorDeviceRGB :_ffe .Add_RG (_gfgf .R (),_gfgf .G (),_gfgf .B ());case *_fd .PdfColorDeviceCMYK :_ffe .Add_K (_gfgf .C (),_gfgf .M (),_gfgf .Y (),_gfgf .K ());default:_gg .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",_gfgf );};return _ffe ;};
|
|
|
|
// 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 (_cfa *ContentCreator )Add_f ()*ContentCreator {_fff :=ContentStreamOperation {};_fff .Operand ="\u0066";_cfa ._fgea =append (_cfa ._fgea ,&_fff );return _cfa ;};
|
|
|
|
// 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 (_bfb *ContentCreator )Add_y (x1 ,y1 ,x3 ,y3 float64 )*ContentCreator {_gb :=ContentStreamOperation {};_gb .Operand ="\u0079";_gb .Params =_cgfcc ([]float64 {x1 ,y1 ,x3 ,y3 });_bfb ._fgea =append (_bfb ._fgea ,&_gb );return _bfb ;};
|
|
|
|
// 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 (_acfa *ContentCreator )Add_CS (name _ge .PdfObjectName )*ContentCreator {_cef :=ContentStreamOperation {};_cef .Operand ="\u0043\u0053";_cef .Params =_eccb ([]_ge .PdfObjectName {name });_acfa ._fgea =append (_acfa ._fgea ,&_cef );return _acfa ;};func (_dbbbc *ContentStreamParser )parseArray ()(*_ge .PdfObjectArray ,error ){_efdb :=_ge .MakeArray ();_dbbbc ._acag .ReadByte ();for {_dbbbc .skipSpaces ();_bcbc ,_afbb :=_dbbbc ._acag .Peek (1);if _afbb !=nil {return _efdb ,_afbb ;};if _bcbc [0]==']'{_dbbbc ._acag .ReadByte ();break ;};_eba ,_ ,_afbb :=_dbbbc .parseObject ();if _afbb !=nil {return _efdb ,_afbb ;};_efdb .Append (_eba );};return _efdb ,nil ;};
|
|
|
|
// 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 ;
|
|
|
|
// 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 (_fcd *ContentCreator )Add_Tf (fontName _ge .PdfObjectName ,fontSize float64 )*ContentCreator {_gbgb :=ContentStreamOperation {};_gbgb .Operand ="\u0054\u0066";_gbgb .Params =_eccb ([]_ge .PdfObjectName {fontName });_gbgb .Params =append (_gbgb .Params ,_cgfcc ([]float64 {fontSize })...);_fcd ._fgea =append (_fcd ._fgea ,&_gbgb );return _fcd ;};
|
|
|
|
// 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 (_dde *ContentCreator )Add_d (dashArray []int64 ,dashPhase int64 )*ContentCreator {_ddg :=ContentStreamOperation {};_ddg .Operand ="\u0064";_ddg .Params =[]_ge .PdfObject {};_ddg .Params =append (_ddg .Params ,_ge .MakeArrayFromIntegers64 (dashArray ));_ddg .Params =append (_ddg .Params ,_ge .MakeInteger (dashPhase ));_dde ._fgea =append (_dde ._fgea ,&_ddg );return _dde ;};
|
|
|
|
// 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 (_cgge *ContentCreator )Add_b_starred ()*ContentCreator {_dcb :=ContentStreamOperation {};_dcb .Operand ="\u0062\u002a";_cgge ._fgea =append (_cgge ._fgea ,&_dcb );return _cgge ;};func (_acg *ContentStreamParser )skipComments ()error {if _ ,_acfd :=_acg .skipSpaces ();_acfd !=nil {return _acfd ;};_agag :=true ;for {_eggb ,_eca :=_acg ._acag .Peek (1);if _eca !=nil {_gg .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0025\u0073",_eca .Error ());return _eca ;};if _agag &&_eggb [0]!='%'{return nil ;};_agag =false ;if (_eggb [0]!='\r')&&(_eggb [0]!='\n'){_acg ._acag .ReadByte ();}else {break ;};};return _acg .skipComments ();};func _cacc (_gad *ContentStreamInlineImage ,_ecc *_ge .PdfObjectDictionary )(*_ge .FlateEncoder ,error ){_aca :=_ge .NewFlateEncoder ();if _gad ._gbgbb !=nil {_aca .SetImage (_gad ._gbgbb );};if _ecc ==nil {_eaf :=_gad .DecodeParms ;if _eaf !=nil {_bgd ,_dgc :=_ge .GetDict (_eaf );if !_dgc {_gg .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",_eaf );return nil ,_ga .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_ecc =_bgd ;};};if _ecc ==nil {return _aca ,nil ;};_gg .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_ecc .String ());_dda :=_ecc .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _dda ==nil {_gg .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 {_bgg ,_gda :=_dda .(*_ge .PdfObjectInteger );if !_gda {_gg .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",_dda );return nil ,_ga .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_aca .Predictor =int (*_bgg );};_dda =_ecc .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _dda !=nil {_bag ,_gdc :=_dda .(*_ge .PdfObjectInteger );if !_gdc {_gg .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 ,_ga .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_aca .BitsPerComponent =int (*_bag );};if _aca .Predictor > 1{_aca .Columns =1;_dda =_ecc .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _dda !=nil {_adg ,_aac :=_dda .(*_ge .PdfObjectInteger );if !_aac {return nil ,_ga .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_aca .Columns =int (*_adg );};_aca .Colors =1;_geg :=_ecc .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _geg !=nil {_aec ,_fcb :=_geg .(*_ge .PdfObjectInteger );if !_fcb {return nil ,_ga .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");};_aca .Colors =int (*_aec );};};return _aca ,nil ;};
|
|
|
|
// 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 (_dbe *ContentCreator )Add_Tw (wordSpace float64 )*ContentCreator {_eea :=ContentStreamOperation {};_eea .Operand ="\u0054\u0077";_eea .Params =_cgfcc ([]float64 {wordSpace });_dbe ._fgea =append (_dbe ._fgea ,&_eea );return _dbe ;};
|
|
|
|
// 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 (_ffff *ContentCreator )Add_TD (tx ,ty float64 )*ContentCreator {_gee :=ContentStreamOperation {};_gee .Operand ="\u0054\u0044";_gee .Params =_cgfcc ([]float64 {tx ,ty });_ffff ._fgea =append (_ffff ._fgea ,&_gee );return _ffff ;};
|
|
|
|
// HandlerFunc is the function syntax that the ContentStreamProcessor handler must implement.
|
|
type HandlerFunc func (_ggbg *ContentStreamOperation ,_gbec GraphicsState ,_eagg *_fd .PdfPageResources )error ;
|
|
|
|
// 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 (_dbb *ContentCreator )Add_Tm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_ddgb :=ContentStreamOperation {};_ddgb .Operand ="\u0054\u006d";_ddgb .Params =_cgfcc ([]float64 {a ,b ,c ,d ,e ,f });_dbb ._fgea =append (_dbb ._fgea ,&_ddgb );return _dbb ;};func (_ffa *ContentStreamParser )parseNumber ()(_ge .PdfObject ,error ){return _ge .ParseNumber (_ffa ._acag );};
|
|
|
|
// 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 (_aaag *ContentCreator )Add_K (c ,m ,y ,k float64 )*ContentCreator {_dafb :=ContentStreamOperation {};_dafb .Operand ="\u004b";_dafb .Params =_cgfcc ([]float64 {c ,m ,y ,k });_aaag ._fgea =append (_aaag ._fgea ,&_dafb );return _aaag ;};func _gbee (_bffe string )bool {_ ,_bgba :=_eacf [_bffe ];return _bgba };
|
|
|
|
// NewInlineImageFromImage makes a new content stream inline image object from an image.
|
|
func NewInlineImageFromImage (img _fd .Image ,encoder _ge .StreamEncoder )(*ContentStreamInlineImage ,error ){if encoder ==nil {encoder =_ge .NewRawEncoder ();};encoder .UpdateParams (img .GetParamsDict ());_cee :=ContentStreamInlineImage {};if img .ColorComponents ==1{_cee .ColorSpace =_ge .MakeName ("\u0047");}else if img .ColorComponents ==3{_cee .ColorSpace =_ge .MakeName ("\u0052\u0047\u0042");}else if img .ColorComponents ==4{_cee .ColorSpace =_ge .MakeName ("\u0043\u004d\u0059\u004b");}else {_gg .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 ,_c .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");};_cee .BitsPerComponent =_ge .MakeInteger (img .BitsPerComponent );_cee .Width =_ge .MakeInteger (img .Width );_cee .Height =_ge .MakeInteger (img .Height );_ede ,_feg :=encoder .EncodeBytes (img .Data );if _feg !=nil {return nil ,_feg ;};_cee ._dfc =_ede ;_cada :=encoder .GetFilterName ();if _cada !=_ge .StreamEncodingFilterNameRaw {_cee .Filter =_ge .MakeName (_cada );};return &_cee ,nil ;};func (_debc *ContentStreamProcessor )handleCommand_cm (_agda *ContentStreamOperation ,_cdbf *_fd .PdfPageResources )error {if len (_agda .Params )!=6{_gg .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 (_agda .Params ));return _c .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");};_ebdf ,_cedb :=_ge .GetNumbersAsFloat (_agda .Params );if _cedb !=nil {return _cedb ;};_cfegd :=_dd .NewMatrix (_ebdf [0],_ebdf [1],_ebdf [2],_ebdf [3],_ebdf [4],_ebdf [5]);_debc ._ebeb .CTM .Concat (_cfegd );return nil ;};func (_fdfg *ContentStreamParser )parseString ()(*_ge .PdfObjectString ,error ){_fdfg ._acag .ReadByte ();var _gdcd []byte ;_edb :=1;for {_deae ,_beg :=_fdfg ._acag .Peek (1);if _beg !=nil {return _ge .MakeString (string (_gdcd )),_beg ;};if _deae [0]=='\\'{_fdfg ._acag .ReadByte ();_dfg ,_fafg :=_fdfg ._acag .ReadByte ();if _fafg !=nil {return _ge .MakeString (string (_gdcd )),_fafg ;};if _ge .IsOctalDigit (_dfg ){_becb ,_fgd :=_fdfg ._acag .Peek (2);if _fgd !=nil {return _ge .MakeString (string (_gdcd )),_fgd ;};var _fgc []byte ;_fgc =append (_fgc ,_dfg );for _ ,_agcb :=range _becb {if _ge .IsOctalDigit (_agcb ){_fgc =append (_fgc ,_agcb );}else {break ;};};_fdfg ._acag .Discard (len (_fgc )-1);_gg .Log .Trace ("\u004e\u0075\u006d\u0065ri\u0063\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u0020\u0022\u0025\u0073\u0022",_fgc );_eccg ,_fgd :=_f .ParseUint (string (_fgc ),8,32);if _fgd !=nil {return _ge .MakeString (string (_gdcd )),_fgd ;};_gdcd =append (_gdcd ,byte (_eccg ));continue ;};switch _dfg {case 'n':_gdcd =append (_gdcd ,'\n');case 'r':_gdcd =append (_gdcd ,'\r');case 't':_gdcd =append (_gdcd ,'\t');case 'b':_gdcd =append (_gdcd ,'\b');case 'f':_gdcd =append (_gdcd ,'\f');case '(':_gdcd =append (_gdcd ,'(');case ')':_gdcd =append (_gdcd ,')');case '\\':_gdcd =append (_gdcd ,'\\');};continue ;}else if _deae [0]=='('{_edb ++;}else if _deae [0]==')'{_edb --;if _edb ==0{_fdfg ._acag .ReadByte ();break ;};};_aed ,_ :=_fdfg ._acag .ReadByte ();_gdcd =append (_gdcd ,_aed );};return _ge .MakeString (string (_gdcd )),nil ;};
|
|
|
|
// 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 (_ece *ContentCreator )Add_re (x ,y ,width ,height float64 )*ContentCreator {_gfc :=ContentStreamOperation {};_gfc .Operand ="\u0072\u0065";_gfc .Params =_cgfcc ([]float64 {x ,y ,width ,height });_ece ._fgea =append (_ece ._fgea ,&_gfc );return _ece ;};
|
|
|
|
// 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 (_fe *ContentCreator )Add_rg (r ,g ,b float64 )*ContentCreator {_bg :=ContentStreamOperation {};_bg .Operand ="\u0072\u0067";_bg .Params =_cgfcc ([]float64 {r ,g ,b });_fe ._fgea =append (_fe ._fgea ,&_bg );return _fe ;};
|
|
|
|
// 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 (_bf *ContentCreator )Add_m (x ,y float64 )*ContentCreator {_ced :=ContentStreamOperation {};_ced .Operand ="\u006d";_ced .Params =_cgfcc ([]float64 {x ,y });_bf ._fgea =append (_bf ._fgea ,&_ced );return _bf ;};
|
|
|
|
// 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 (_ecd *ContentCreator )Add_Tj (textstr _ge .PdfObjectString )*ContentCreator {_cge :=ContentStreamOperation {};_cge .Operand ="\u0054\u006a";_cge .Params =_baef ([]_ge .PdfObjectString {textstr });_ecd ._fgea =append (_ecd ._fgea ,&_cge );return _ecd ;};
|
|
|
|
// 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 (_adf *ContentCreator )Add_f_starred ()*ContentCreator {_gbg :=ContentStreamOperation {};_gbg .Operand ="\u0066\u002a";_adf ._fgea =append (_adf ._fgea ,&_gbg );return _adf ;};func (_caca *ContentStreamProcessor )handleCommand_scn (_ddgbe *ContentStreamOperation ,_daag *_fd .PdfPageResources )error {_dbec :=_caca ._ebeb .ColorspaceNonStroking ;if !_cdcc (_dbec ){if len (_ddgbe .Params )!=_dbec .GetNumComponents (){_gg .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");_gg .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 (_ddgbe .Params ),_dbec );return _c .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");};};_gfb ,_begd :=_dbec .ColorFromPdfObjects (_ddgbe .Params );if _begd !=nil {_gg .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",_ddgbe .Params ,_dbec );return _begd ;};_caca ._ebeb .ColorNonStroking =_gfb ;return nil ;};
|
|
|
|
// NewContentStreamParser creates a new instance of the content stream parser from an input content
|
|
// stream string.
|
|
func NewContentStreamParser (contentStr string )*ContentStreamParser {_cebd :=ContentStreamParser {};_ecbf :=_ca .NewBufferString (contentStr +"\u000a");_cebd ._acag =_d .NewReader (_ecbf );return &_cebd ;};
|
|
|
|
// Parse parses all commands in content stream, returning a list of operation data.
|
|
func (_ebcb *ContentStreamParser )Parse ()(*ContentStreamOperations ,error ){_cfed :=ContentStreamOperations {};for {_ege :=ContentStreamOperation {};for {_fgec ,_eec ,_fbgc :=_ebcb .parseObject ();if _fbgc !=nil {if _fbgc ==_gf .EOF {return &_cfed ,nil ;};return &_cfed ,_fbgc ;};if _eec {_ege .Operand ,_ =_ge .GetStringVal (_fgec );_cfed =append (_cfed ,&_ege );break ;}else {_ege .Params =append (_ege .Params ,_fgec );};};if _ege .Operand =="\u0042\u0049"{_eag ,_gbf :=_ebcb .ParseInlineImage ();if _gbf !=nil {return &_cfed ,_gbf ;};_ege .Params =append (_ege .Params ,_eag );};};};
|
|
|
|
// 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 (_dge *ContentCreator )Add_k (c ,m ,y ,k float64 )*ContentCreator {_accd :=ContentStreamOperation {};_accd .Operand ="\u006b";_accd .Params =_cgfcc ([]float64 {c ,m ,y ,k });_dge ._fgea =append (_dge ._fgea ,&_accd );return _dge ;};
|
|
|
|
// 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 (_eab *ContentCreator )Add_s ()*ContentCreator {_bc :=ContentStreamOperation {};_bc .Operand ="\u0073";_eab ._fgea =append (_eab ._fgea ,&_bc );return _eab ;};
|
|
|
|
// 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 (_cdg *ContentStreamInlineImage )IsMask ()(bool ,error ){if _cdg .ImageMask !=nil {_aae ,_fcba :=_cdg .ImageMask .(*_ge .PdfObjectBool );if !_fcba {_gg .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 ,_c .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u0079\u0070\u0065");};return bool (*_aae ),nil ;};return false ,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 (_cecc *ContentCreator )Add_RG (r ,g ,b float64 )*ContentCreator {_ffb :=ContentStreamOperation {};_ffb .Operand ="\u0052\u0047";_ffb .Params =_cgfcc ([]float64 {r ,g ,b });_cecc ._fgea =append (_cecc ._fgea ,&_ffb );return _cecc ;};
|
|
|
|
// 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 (_accfd *ContentCreator )Add_EMC ()*ContentCreator {_ggfa :=ContentStreamOperation {};_ggfa .Operand ="\u0045\u004d\u0043";_accfd ._fgea =append (_accfd ._fgea ,&_ggfa );return _accfd ;};
|
|
|
|
// 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 (_cca *ContentCreator )Add_SCN (c ...float64 )*ContentCreator {_ab :=ContentStreamOperation {};_ab .Operand ="\u0053\u0043\u004e";_ab .Params =_cgfcc (c );_cca ._fgea =append (_cca ._fgea ,&_ab );return _cca ;};func (_bac *ContentStreamInlineImage )String ()string {_bec :=_ga .Sprintf ("I\u006el\u0069\u006e\u0065\u0049\u006d\u0061\u0067\u0065(\u006c\u0065\u006e\u003d%d\u0029\u000a",len (_bac ._dfc ));if _bac .BitsPerComponent !=nil {_bec +="\u002d\u0020\u0042\u0050\u0043\u0020"+_bac .BitsPerComponent .WriteString ()+"\u000a";};if _bac .ColorSpace !=nil {_bec +="\u002d\u0020\u0043S\u0020"+_bac .ColorSpace .WriteString ()+"\u000a";};if _bac .Decode !=nil {_bec +="\u002d\u0020\u0044\u0020"+_bac .Decode .WriteString ()+"\u000a";};if _bac .DecodeParms !=nil {_bec +="\u002d\u0020\u0044P\u0020"+_bac .DecodeParms .WriteString ()+"\u000a";};if _bac .Filter !=nil {_bec +="\u002d\u0020\u0046\u0020"+_bac .Filter .WriteString ()+"\u000a";};if _bac .Height !=nil {_bec +="\u002d\u0020\u0048\u0020"+_bac .Height .WriteString ()+"\u000a";};if _bac .ImageMask !=nil {_bec +="\u002d\u0020\u0049M\u0020"+_bac .ImageMask .WriteString ()+"\u000a";};if _bac .Intent !=nil {_bec +="\u002d \u0049\u006e\u0074\u0065\u006e\u0074 "+_bac .Intent .WriteString ()+"\u000a";};if _bac .Interpolate !=nil {_bec +="\u002d\u0020\u0049\u0020"+_bac .Interpolate .WriteString ()+"\u000a";};if _bac .Width !=nil {_bec +="\u002d\u0020\u0057\u0020"+_bac .Width .WriteString ()+"\u000a";};return _bec ;};func (_aag *ContentStreamParser )parseHexString ()(*_ge .PdfObjectString ,error ){_aag ._acag .ReadByte ();_bee :=[]byte ("\u0030\u0031\u0032\u003345\u0036\u0037\u0038\u0039\u0061\u0062\u0063\u0064\u0065\u0066\u0041\u0042\u0043\u0044E\u0046");var _bagd []byte ;for {_aag .skipSpaces ();_ada ,_gdg :=_aag ._acag .Peek (1);if _gdg !=nil {return _ge .MakeString (""),_gdg ;};if _ada [0]=='>'{_aag ._acag .ReadByte ();break ;};_fgfd ,_ :=_aag ._acag .ReadByte ();if _ca .IndexByte (_bee ,_fgfd )>=0{_bagd =append (_bagd ,_fgfd );};};if len (_bagd )%2==1{_bagd =append (_bagd ,'0');};_gef ,_ :=_fa .DecodeString (string (_bagd ));return _ge .MakeHexString (string (_gef )),nil ;};
|
|
|
|
// 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 (_fcfb *ContentCreator )Add_n ()*ContentCreator {_acf :=ContentStreamOperation {};_acf .Operand ="\u006e";_fcfb ._fgea =append (_fcfb ._fgea ,&_acf );return _fcfb ;};var _eacf =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{}{}};
|
|
|
|
// 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 (_gc *ContentCreator )Add_i (flatness float64 )*ContentCreator {_cfg :=ContentStreamOperation {};_cfg .Operand ="\u0069";_cfg .Params =_cgfcc ([]float64 {flatness });_gc ._fgea =append (_gc ._fgea ,&_cfg );return _gc ;};
|
|
|
|
// Push pushes `gs` on the `gsStack`.
|
|
func (_ggee *GraphicStateStack )Push (gs GraphicsState ){*_ggee =append (*_ggee ,gs )};
|
|
|
|
// 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 (_deg *ContentCreator )Add_b ()*ContentCreator {_eef :=ContentStreamOperation {};_eef .Operand ="\u0062";_deg ._fgea =append (_deg ._fgea ,&_eef );return _deg ;};
|
|
|
|
// 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 (_acc *ContentCreator )Add_Do (name _ge .PdfObjectName )*ContentCreator {_ddcg :=ContentStreamOperation {};_ddcg .Operand ="\u0044\u006f";_ddcg .Params =_eccb ([]_ge .PdfObjectName {name });_acc ._fgea =append (_acc ._fgea ,&_ddcg );return _acc ;};
|
|
|
|
// 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 (_dea *ContentCreator )Add_l (x ,y float64 )*ContentCreator {_fcf :=ContentStreamOperation {};_fcf .Operand ="\u006c";_fcf .Params =_cgfcc ([]float64 {x ,y });_dea ._fgea =append (_dea ._fgea ,&_fcf );return _dea ;};
|
|
|
|
// 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 (_cd *ContentCreator )Add_c (x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_adbe :=ContentStreamOperation {};_adbe .Operand ="\u0063";_adbe .Params =_cgfcc ([]float64 {x1 ,y1 ,x2 ,y2 ,x3 ,y3 });_cd ._fgea =append (_cd ._fgea ,&_adbe );return _cd ;};
|
|
|
|
// Operations returns the list of operations.
|
|
func (_ddc *ContentCreator )Operations ()*ContentStreamOperations {return &_ddc ._fgea };
|
|
|
|
// 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 (_gfgg *ContentCreator )Add_quote (textstr _ge .PdfObjectString )*ContentCreator {_gacg :=ContentStreamOperation {};_gacg .Operand ="\u0027";_gacg .Params =_baef ([]_ge .PdfObjectString {textstr });_gfgg ._fgea =append (_gfgg ._fgea ,&_gacg );return _gfgg ;};
|
|
|
|
// GraphicStateStack represents a stack of GraphicsState.
|
|
type GraphicStateStack []GraphicsState ;
|
|
|
|
// 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 (_gfd *ContentCreator )Add_cs (name _ge .PdfObjectName )*ContentCreator {_cfgg :=ContentStreamOperation {};_cfgg .Operand ="\u0063\u0073";_cfgg .Params =_eccb ([]_ge .PdfObjectName {name });_gfd ._fgea =append (_gfd ._fgea ,&_cfgg );return _gfd ;};func (_gfdc *ContentStreamProcessor )handleCommand_K (_bfbe *ContentStreamOperation ,_fgdc *_fd .PdfPageResources )error {_dga :=_fd .NewPdfColorspaceDeviceCMYK ();if len (_bfbe .Params )!=_dga .GetNumComponents (){_gg .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");_gg .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 (_bfbe .Params ),_dga );return _c .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");};_cfef ,_gegc :=_dga .ColorFromPdfObjects (_bfbe .Params );if _gegc !=nil {return _gegc ;};_gfdc ._ebeb .ColorspaceStroking =_dga ;_gfdc ._ebeb .ColorStroking =_cfef ;return nil ;};func _faagg (_fbd *ContentStreamInlineImage )(*_ge .MultiEncoder ,error ){_fdf :=_ge .NewMultiEncoder ();var _feb *_ge .PdfObjectDictionary ;var _bffg []_ge .PdfObject ;if _fag :=_fbd .DecodeParms ;_fag !=nil {_dcfa ,_gba :=_fag .(*_ge .PdfObjectDictionary );if _gba {_feb =_dcfa ;};_cfde ,_aecc :=_fag .(*_ge .PdfObjectArray );if _aecc {for _ ,_gbe :=range _cfde .Elements (){if _aacb ,_dgeb :=_gbe .(*_ge .PdfObjectDictionary );_dgeb {_bffg =append (_bffg ,_aacb );}else {_bffg =append (_bffg ,nil );};};};};_cfee :=_fbd .Filter ;if _cfee ==nil {return nil ,_ga .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006d\u0069s\u0073\u0069\u006e\u0067");};_cfb ,_ggfbf :=_cfee .(*_ge .PdfObjectArray );if !_ggfbf {return nil ,_ga .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 _gacc ,_daa :=range _cfb .Elements (){_afd ,_adbg :=_daa .(*_ge .PdfObjectName );if !_adbg {return nil ,_ga .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 _cdf _ge .PdfObject ;if _feb !=nil {_cdf =_feb ;}else {if len (_bffg )> 0{if _gacc >=len (_bffg ){return nil ,_ga .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");};_cdf =_bffg [_gacc ];};};var _debb *_ge .PdfObjectDictionary ;if _cbfg ,_ddfb :=_cdf .(*_ge .PdfObjectDictionary );_ddfb {_debb =_cbfg ;};if *_afd ==_ge .StreamEncodingFilterNameFlate ||*_afd =="\u0046\u006c"{_faab ,_bdca :=_cacc (_fbd ,_debb );if _bdca !=nil {return nil ,_bdca ;};_fdf .AddEncoder (_faab );}else if *_afd ==_ge .StreamEncodingFilterNameLZW {_cad ,_ffdb :=_eeb (_fbd ,_debb );if _ffdb !=nil {return nil ,_ffdb ;};_fdf .AddEncoder (_cad );}else if *_afd ==_ge .StreamEncodingFilterNameASCIIHex {_cgdc :=_ge .NewASCIIHexEncoder ();_fdf .AddEncoder (_cgdc );}else if *_afd ==_ge .StreamEncodingFilterNameASCII85 ||*_afd =="\u0041\u0038\u0035"{_bfae :=_ge .NewASCII85Encoder ();_fdf .AddEncoder (_bfae );}else {_gg .Log .Error ("U\u006e\u0073\u0075\u0070po\u0072t\u0065\u0064\u0020\u0066\u0069l\u0074\u0065\u0072\u0020\u0025\u0073",*_afd );return nil ,_ga .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 _fdf ,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 (_aaeg *ContentStreamParser )ParseInlineImage ()(*ContentStreamInlineImage ,error ){_ccc :=ContentStreamInlineImage {};for {_aaeg .skipSpaces ();_agf ,_dcfg ,_cgdb :=_aaeg .parseObject ();if _cgdb !=nil {return nil ,_cgdb ;};if !_dcfg {_efb ,_bffb :=_ge .GetName (_agf );if !_bffb {_gg .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",_agf );return nil ,_ga .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",_agf );};_dgd ,_baf ,_efed :=_aaeg .parseObject ();if _efed !=nil {return nil ,_efed ;};if _baf {return nil ,_ga .Errorf ("\u006eo\u0074\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067 \u0061\u006e\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};switch *_efb {case "\u0042\u0050\u0043","\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074":_ccc .BitsPerComponent =_dgd ;case "\u0043\u0053","\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065":_ccc .ColorSpace =_dgd ;case "\u0044","\u0044\u0065\u0063\u006f\u0064\u0065":_ccc .Decode =_dgd ;case "\u0044\u0050","D\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073":_ccc .DecodeParms =_dgd ;case "\u0046","\u0046\u0069\u006c\u0074\u0065\u0072":_ccc .Filter =_dgd ;case "\u0048","\u0048\u0065\u0069\u0067\u0068\u0074":_ccc .Height =_dgd ;case "\u0049\u004d","\u0049m\u0061\u0067\u0065\u004d\u0061\u0073k":_ccc .ImageMask =_dgd ;case "\u0049\u006e\u0074\u0065\u006e\u0074":_ccc .Intent =_dgd ;case "\u0049","I\u006e\u0074\u0065\u0072\u0070\u006f\u006c\u0061\u0074\u0065":_ccc .Interpolate =_dgd ;case "\u0057","\u0057\u0069\u0064t\u0068":_ccc .Width =_dgd ;case "\u004c\u0065\u006e\u0067\u0074\u0068","\u0053u\u0062\u0074\u0079\u0070\u0065","\u0054\u0079\u0070\u0065":_gg .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",*_efb );default:return nil ,_ga .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",*_efb );};};if _dcfg {_aecf ,_cgb :=_agf .(*_ge .PdfObjectString );if !_cgb {return nil ,_ga .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 _aecf .Str ()=="\u0045\u0049"{_gg .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 &_ccc ,nil ;}else if _aecf .Str ()=="\u0049\u0044"{_gg .Log .Trace ("\u0049\u0044\u0020\u0073\u0074\u0061\u0072\u0074");_fbb ,_gdb :=_aaeg ._acag .Peek (1);if _gdb !=nil {return nil ,_gdb ;};if _ge .IsWhiteSpace (_fbb [0]){_aaeg ._acag .Discard (1);};_ccc ._dfc =[]byte {};_cfeg :=0;var _dcdb []byte ;for {_gcge ,_cdgg :=_aaeg ._acag .ReadByte ();if _cdgg !=nil {_gg .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 ,_cdgg ;};if _cfeg ==0{if _ge .IsWhiteSpace (_gcge ){_dcdb =[]byte {};_dcdb =append (_dcdb ,_gcge );_cfeg =1;}else if _gcge =='E'{_dcdb =append (_dcdb ,_gcge );_cfeg =2;}else {_ccc ._dfc =append (_ccc ._dfc ,_gcge );};}else if _cfeg ==1{_dcdb =append (_dcdb ,_gcge );if _gcge =='E'{_cfeg =2;}else {_ccc ._dfc =append (_ccc ._dfc ,_dcdb ...);_dcdb =[]byte {};if _ge .IsWhiteSpace (_gcge ){_cfeg =1;}else {_cfeg =0;};};}else if _cfeg ==2{_dcdb =append (_dcdb ,_gcge );if _gcge =='I'{_cfeg =3;}else {_ccc ._dfc =append (_ccc ._dfc ,_dcdb ...);_dcdb =[]byte {};_cfeg =0;};}else if _cfeg ==3{_dcdb =append (_dcdb ,_gcge );if _ge .IsWhiteSpace (_gcge ){_add ,_gdad :=_aaeg ._acag .Peek (20);if _gdad !=nil &&_gdad !=_gf .EOF {return nil ,_gdad ;};_fcbac :=NewContentStreamParser (string (_add ));_ebg :=true ;for _dagf :=0;_dagf < 3;_dagf ++{_abg ,_ecb ,_afba :=_fcbac .parseObject ();if _afba !=nil {if _afba ==_gf .EOF {break ;};continue ;};if _ecb &&!_gbee (_abg .String ()){_ebg =false ;break ;};};if _ebg {if len (_ccc ._dfc )> 100{_gg .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 (_ccc ._dfc ),_ccc ._dfc [:100]);}else {_gg .Log .Trace ("\u0049\u006d\u0061\u0067e \u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025 \u0078",len (_ccc ._dfc ),_ccc ._dfc );};return &_ccc ,nil ;};};_ccc ._dfc =append (_ccc ._dfc ,_dcdb ...);_dcdb =[]byte {};_cfeg =0;};};};};};};var (ErrInvalidOperand =_c .New ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064"););func _ebe (_gcg *ContentStreamInlineImage )(*_ge .DCTEncoder ,error ){_aegf :=_ge .NewDCTEncoder ();_efe :=_ca .NewReader (_gcg ._dfc );_bgb ,_cfe :=_cg .DecodeConfig (_efe );if _cfe !=nil {_gg .Log .Debug ("\u0045\u0072\u0072or\u0020\u0064\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0065\u003a\u0020\u0025\u0073",_cfe );return nil ,_cfe ;};switch _bgb .ColorModel {case _a .RGBAModel :_aegf .BitsPerComponent =8;_aegf .ColorComponents =3;case _a .RGBA64Model :_aegf .BitsPerComponent =16;_aegf .ColorComponents =3;case _a .GrayModel :_aegf .BitsPerComponent =8;_aegf .ColorComponents =1;case _a .Gray16Model :_aegf .BitsPerComponent =16;_aegf .ColorComponents =1;case _a .CMYKModel :_aegf .BitsPerComponent =8;_aegf .ColorComponents =4;case _a .YCbCrModel :_aegf .BitsPerComponent =8;_aegf .ColorComponents =3;default:return nil ,_c .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u006d\u006f\u0064\u0065\u006c");};_aegf .Width =_bgb .Width ;_aegf .Height =_bgb .Height ;_gg .Log .Trace ("\u0044\u0043T\u0020\u0045\u006ec\u006f\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076",_aegf );return _aegf ,nil ;};
|
|
|
|
// 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 (_adbc *ContentCreator )Add_TL (leading float64 )*ContentCreator {_degg :=ContentStreamOperation {};_degg .Operand ="\u0054\u004c";_degg .Params =_cgfcc ([]float64 {leading });_adbc ._fgea =append (_adbc ._fgea ,&_degg );return _adbc ;};func (_bgeg *ContentStreamParser )parseObject ()(_eade _ge .PdfObject ,_afc bool ,_debbb error ){_bgeg .skipSpaces ();for {_bcbb ,_fbc :=_bgeg ._acag .Peek (2);if _fbc !=nil {return nil ,false ,_fbc ;};_gg .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_bcbb ));if _bcbb [0]=='%'{_bgeg .skipComments ();continue ;}else if _bcbb [0]=='/'{_daae ,_abf :=_bgeg .parseName ();_gg .Log .Trace ("\u002d\u003e\u004ea\u006d\u0065\u003a\u0020\u0027\u0025\u0073\u0027",_daae );return &_daae ,false ,_abf ;}else if _bcbb [0]=='('{_gg .Log .Trace ("\u002d>\u0053\u0074\u0072\u0069\u006e\u0067!");_ebaf ,_aacd :=_bgeg .parseString ();return _ebaf ,false ,_aacd ;}else if _bcbb [0]=='<'&&_bcbb [1]!='<'{_gg .Log .Trace ("\u002d\u003e\u0048\u0065\u0078\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0021");_bgbc ,_fafd :=_bgeg .parseHexString ();return _bgbc ,false ,_fafd ;}else if _bcbb [0]=='['{_gg .Log .Trace ("\u002d\u003e\u0041\u0072\u0072\u0061\u0079\u0021");_ecbd ,_gcgg :=_bgeg .parseArray ();return _ecbd ,false ,_gcgg ;}else if _ge .IsFloatDigit (_bcbb [0])||(_bcbb [0]=='-'&&_ge .IsFloatDigit (_bcbb [1])){_gg .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_aedb ,_ecda :=_bgeg .parseNumber ();return _aedb ,false ,_ecda ;}else if _bcbb [0]=='<'&&_bcbb [1]=='<'{_gab ,_aeee :=_bgeg .parseDict ();return _gab ,false ,_aeee ;}else {_gg .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_bcbb ,_ =_bgeg ._acag .Peek (5);_dccd :=string (_bcbb );_gg .Log .Trace ("\u0063\u006f\u006e\u0074\u0020\u0050\u0065\u0065\u006b\u0020\u0073\u0074r\u003a\u0020\u0025\u0073",_dccd );if (len (_dccd )> 3)&&(_dccd [:4]=="\u006e\u0075\u006c\u006c"){_eee ,_eecg :=_bgeg .parseNull ();return &_eee ,false ,_eecg ;}else if (len (_dccd )> 4)&&(_dccd [:5]=="\u0066\u0061\u006cs\u0065"){_abc ,_beef :=_bgeg .parseBool ();return &_abc ,false ,_beef ;}else if (len (_dccd )> 3)&&(_dccd [:4]=="\u0074\u0072\u0075\u0065"){_bdec ,_ggdc :=_bgeg .parseBool ();return &_bdec ,false ,_ggdc ;};_cecce ,_agfd :=_bgeg .parseOperand ();if _agfd !=nil {return _cecce ,false ,_agfd ;};if len (_cecce .String ())< 1{return _cecce ,false ,ErrInvalidOperand ;};return _cecce ,true ,nil ;};};};func _cdcc (_ccfd _fd .PdfColorspace )bool {_ ,_edcb :=_ccfd .(*_fd .PdfColorspaceSpecialPattern );return _edcb ;};
|
|
|
|
// String returns `ops.Bytes()` as a string.
|
|
func (_cbc *ContentStreamOperations )String ()string {return string (_cbc .Bytes ())};func (_dbgb *ContentStreamProcessor )handleCommand_k (_dagb *ContentStreamOperation ,_efa *_fd .PdfPageResources )error {_gegf :=_fd .NewPdfColorspaceDeviceCMYK ();if len (_dagb .Params )!=_gegf .GetNumComponents (){_gg .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");_gg .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 (_dagb .Params ),_gegf );return _c .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");};_fbcb ,_caf :=_gegf .ColorFromPdfObjects (_dagb .Params );if _caf !=nil {return _caf ;};_dbgb ._ebeb .ColorspaceNonStroking =_gegf ;_dbgb ._ebeb .ColorNonStroking =_fbcb ;return nil ;};
|
|
|
|
// 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 (_eg *ContentCreator )Add_v (x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_ggf :=ContentStreamOperation {};_ggf .Operand ="\u0076";_ggf .Params =_cgfcc ([]float64 {x2 ,y2 ,x3 ,y3 });_eg ._fgea =append (_eg ._fgea ,&_ggf );return _eg ;};func (_bfc *ContentStreamProcessor )handleCommand_g (_agg *ContentStreamOperation ,_ebbf *_fd .PdfPageResources )error {_bbad :=_fd .NewPdfColorspaceDeviceGray ();if len (_agg .Params )!=_bbad .GetNumComponents (){_gg .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");_gg .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 (_agg .Params ),_bbad );return _c .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");};_fbce ,_ffcb :=_bbad .ColorFromPdfObjects (_agg .Params );if _ffcb !=nil {_gg .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",_bbad ,_agg ,_ffcb );return _ffcb ;};_bfc ._ebeb .ColorspaceNonStroking =_bbad ;_bfc ._ebeb .ColorNonStroking =_fbce ;return nil ;};
|
|
|
|
// 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 (_adcg *ContentCreator )Add_j (lineJoinStyle string )*ContentCreator {_gaa :=ContentStreamOperation {};_gaa .Operand ="\u006a";_gaa .Params =_eccb ([]_ge .PdfObjectName {_ge .PdfObjectName (lineJoinStyle )});_adcg ._fgea =append (_adcg ._fgea ,&_gaa );return _adcg ;};
|
|
|
|
// Translate applies a simple x-y translation to the transformation matrix.
|
|
func (_fb *ContentCreator )Translate (tx ,ty float64 )*ContentCreator {return _fb .Add_cm (1,0,0,1,tx ,ty );};
|
|
|
|
// 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 (_dcd *ContentCreator )Add_BT ()*ContentCreator {_cfggb :=ContentStreamOperation {};_cfggb .Operand ="\u0042\u0054";_dcd ._fgea =append (_dcd ._fgea ,&_cfggb );return _dcd ;};func (_gbdf *ContentStreamParser )parseDict ()(*_ge .PdfObjectDictionary ,error ){_gg .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");_bdb :=_ge .MakeDict ();_gfdd ,_ :=_gbdf ._acag .ReadByte ();if _gfdd !='<'{return nil ,_c .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};_gfdd ,_ =_gbdf ._acag .ReadByte ();if _gfdd !='<'{return nil ,_c .New ("\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0064\u0069\u0063\u0074");};for {_gbdf .skipSpaces ();_bdf ,_gaccg :=_gbdf ._acag .Peek (2);if _gaccg !=nil {return nil ,_gaccg ;};_gg .Log .Trace ("D\u0069c\u0074\u0020\u0070\u0065\u0065\u006b\u003a\u0020%\u0073\u0020\u0028\u0025 x\u0029\u0021",string (_bdf ),string (_bdf ));if (_bdf [0]=='>')&&(_bdf [1]=='>'){_gg .Log .Trace ("\u0045\u004f\u0046\u0020\u0064\u0069\u0063\u0074\u0069o\u006e\u0061\u0072\u0079");_gbdf ._acag .ReadByte ();_gbdf ._acag .ReadByte ();break ;};_gg .Log .Trace ("\u0050a\u0072s\u0065\u0020\u0074\u0068\u0065\u0020\u006e\u0061\u006d\u0065\u0021");_bgc ,_gaccg :=_gbdf .parseName ();_gg .Log .Trace ("\u004be\u0079\u003a\u0020\u0025\u0073",_bgc );if _gaccg !=nil {_gg .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",_gaccg );return nil ,_gaccg ;};if len (_bgc )> 4&&_bgc [len (_bgc )-4:]=="\u006e\u0075\u006c\u006c"{_fdb :=_bgc [0:len (_bgc )-4];_gg .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",_bgc );_gg .Log .Trace ("\u004e\u0065\u0077\u0020ke\u0079\u0020\u0022\u0025\u0073\u0022\u0020\u003d\u0020\u006e\u0075\u006c\u006c",_fdb );_gbdf .skipSpaces ();_gbb ,_ :=_gbdf ._acag .Peek (1);if _gbb [0]=='/'{_bdb .Set (_fdb ,_ge .MakeNull ());continue ;};};_gbdf .skipSpaces ();_gce ,_ ,_gaccg :=_gbdf .parseObject ();if _gaccg !=nil {return nil ,_gaccg ;};_bdb .Set (_bgc ,_gce );_gg .Log .Trace ("\u0064\u0069\u0063\u0074\u005b\u0025\u0073\u005d\u0020\u003d\u0020\u0025\u0073",_bgc ,_gce .String ());};return _bdb ,nil ;};
|
|
|
|
// ContentStreamOperation represents an operation in PDF contentstream which consists of
|
|
// an operand and parameters.
|
|
type ContentStreamOperation struct{Params []_ge .PdfObject ;Operand string ;};
|
|
|
|
// 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 (_edg *ContentCreator )Add_ET ()*ContentCreator {_cbb :=ContentStreamOperation {};_cbb .Operand ="\u0045\u0054";_edg ._fgea =append (_edg ._fgea ,&_cbb );return _edg ;};
|
|
|
|
// 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 (_aga *ContentCreator )Add_Tr (render int64 )*ContentCreator {_gfe :=ContentStreamOperation {};_gfe .Operand ="\u0054\u0072";_gfe .Params =_cfcc ([]int64 {render });_aga ._fgea =append (_aga ._fgea ,&_gfe );return _aga ;};func _eccb (_cab []_ge .PdfObjectName )[]_ge .PdfObject {var _bdab []_ge .PdfObject ;for _ ,_dba :=range _cab {_bdab =append (_bdab ,_ge .MakeName (string (_dba )));};return _bdab ;};const (HandlerConditionEnumOperand HandlerConditionEnum =iota ;HandlerConditionEnumAllOperands ;);func (_dbg *ContentStreamParser )parseName ()(_ge .PdfObjectName ,error ){_fab :="";_ceff :=false ;for {_fed ,_bga :=_dbg ._acag .Peek (1);if _bga ==_gf .EOF {break ;};if _bga !=nil {return _ge .PdfObjectName (_fab ),_bga ;};if !_ceff {if _fed [0]=='/'{_ceff =true ;_dbg ._acag .ReadByte ();}else {_gg .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",_fed ,_fed );return _ge .PdfObjectName (_fab ),_ga .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u006ea\u006d\u0065:\u0020\u0028\u0025\u0063\u0029",_fed [0]);};}else {if _ge .IsWhiteSpace (_fed [0]){break ;}else if (_fed [0]=='/')||(_fed [0]=='[')||(_fed [0]=='(')||(_fed [0]==']')||(_fed [0]=='<')||(_fed [0]=='>'){break ;}else if _fed [0]=='#'{_eacb ,_dbbbf :=_dbg ._acag .Peek (3);if _dbbbf !=nil {return _ge .PdfObjectName (_fab ),_dbbbf ;};_dbg ._acag .Discard (3);_aba ,_dbbbf :=_fa .DecodeString (string (_eacb [1:3]));if _dbbbf !=nil {return _ge .PdfObjectName (_fab ),_dbbbf ;};_fab +=string (_aba );}else {_cfba ,_ :=_dbg ._acag .ReadByte ();_fab +=string (_cfba );};};};return _ge .PdfObjectName (_fab ),nil ;};func _eeb (_gcb *ContentStreamInlineImage ,_dbbb *_ge .PdfObjectDictionary )(*_ge .LZWEncoder ,error ){_ggfb :=_ge .NewLZWEncoder ();if _dbbb ==nil {if _gcb .DecodeParms !=nil {_deb ,_ccf :=_ge .GetDict (_gcb .DecodeParms );if !_ccf {_gg .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",_gcb .DecodeParms );return nil ,_ga .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_dbbb =_deb ;};};if _dbbb ==nil {return _ggfb ,nil ;};_eac :=_dbbb .Get ("E\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");if _eac !=nil {_egc ,_ebb :=_eac .(*_ge .PdfObjectInteger );if !_ebb {_gg .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",_eac );return nil ,_ga .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");};if *_egc !=0&&*_egc !=1{return nil ,_ga .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");};_ggfb .EarlyChange =int (*_egc );}else {_ggfb .EarlyChange =1;};_eac =_dbbb .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _eac !=nil {_cacf ,_fef :=_eac .(*_ge .PdfObjectInteger );if !_fef {_gg .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",_eac );return nil ,_ga .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_ggfb .Predictor =int (*_cacf );};_eac =_dbbb .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _eac !=nil {_cda ,_bge :=_eac .(*_ge .PdfObjectInteger );if !_bge {_gg .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 ,_ga .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_ggfb .BitsPerComponent =int (*_cda );};if _ggfb .Predictor > 1{_ggfb .Columns =1;_eac =_dbbb .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _eac !=nil {_dafe ,_dgb :=_eac .(*_ge .PdfObjectInteger );if !_dgb {return nil ,_ga .Errorf ("\u0070r\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u0063\u006f\u006cu\u006d\u006e\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_ggfb .Columns =int (*_dafe );};_ggfb .Colors =1;_eac =_dbbb .Get ("\u0043\u006f\u006c\u006f\u0072\u0073");if _eac !=nil {_dae ,_afef :=_eac .(*_ge .PdfObjectInteger );if !_afef {return nil ,_ga .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");};_ggfb .Colors =int (*_dae );};};_gg .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_dbbb .String ());return _ggfb ,nil ;};func _baef (_cdaf []_ge .PdfObjectString )[]_ge .PdfObject {var _eabb []_ge .PdfObject ;for _ ,_ccbca :=range _cdaf {_eabb =append (_eabb ,_ge .MakeString (_ccbca .Str ()));};return _eabb ;};
|
|
|
|
// 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 (_bda *ContentStreamProcessor )Process (resources *_fd .PdfPageResources )error {_bda ._ebeb .ColorspaceStroking =_fd .NewPdfColorspaceDeviceGray ();_bda ._ebeb .ColorspaceNonStroking =_fd .NewPdfColorspaceDeviceGray ();_bda ._ebeb .ColorStroking =_fd .NewPdfColorDeviceGray (0);_bda ._ebeb .ColorNonStroking =_fd .NewPdfColorDeviceGray (0);_bda ._ebeb .CTM =_dd .IdentityMatrix ();for _ ,_eeg :=range _bda ._faagf {var _dccc error ;switch _eeg .Operand {case "\u0071":_bda ._agaf .Push (_bda ._ebeb );case "\u0051":if len (_bda ._agaf )==0{_gg .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 ;};_bda ._ebeb =_bda ._agaf .Pop ();case "\u0043\u0053":_dccc =_bda .handleCommand_CS (_eeg ,resources );case "\u0063\u0073":_dccc =_bda .handleCommand_cs (_eeg ,resources );case "\u0053\u0043":_dccc =_bda .handleCommand_SC (_eeg ,resources );case "\u0053\u0043\u004e":_dccc =_bda .handleCommand_SCN (_eeg ,resources );case "\u0073\u0063":_dccc =_bda .handleCommand_sc (_eeg ,resources );case "\u0073\u0063\u006e":_dccc =_bda .handleCommand_scn (_eeg ,resources );case "\u0047":_dccc =_bda .handleCommand_G (_eeg ,resources );case "\u0067":_dccc =_bda .handleCommand_g (_eeg ,resources );case "\u0052\u0047":_dccc =_bda .handleCommand_RG (_eeg ,resources );case "\u0072\u0067":_dccc =_bda .handleCommand_rg (_eeg ,resources );case "\u004b":_dccc =_bda .handleCommand_K (_eeg ,resources );case "\u006b":_dccc =_bda .handleCommand_k (_eeg ,resources );case "\u0063\u006d":_dccc =_bda .handleCommand_cm (_eeg ,resources );};if _dccc !=nil {_gg .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",_eeg .Operand ,_dccc );_gg .Log .Debug ("\u004f\u0070\u0065r\u0061\u006e\u0064\u003a\u0020\u0025\u0023\u0076",_eeg .Operand );return _dccc ;};for _ ,_eeca :=range _bda ._bgbg {var _egd error ;if _eeca .Condition .All (){_egd =_eeca .Handler (_eeg ,_bda ._ebeb ,resources );}else if _eeca .Condition .Operand ()&&_eeg .Operand ==_eeca .Operand {_egd =_eeca .Handler (_eeg ,_bda ._ebeb ,resources );};if _egd !=nil {_gg .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",_egd );return _egd ;};};};return nil ;};
|
|
|
|
// Pop pops and returns the topmost GraphicsState off the `gsStack`.
|
|
func (_aebb *GraphicStateStack )Pop ()GraphicsState {_fdac :=(*_aebb )[len (*_aebb )-1];*_aebb =(*_aebb )[:len (*_aebb )-1];return _fdac ;};
|
|
|
|
// 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 (_eb *ContentCreator )Add_Ts (rise float64 )*ContentCreator {_bea :=ContentStreamOperation {};_bea .Operand ="\u0054\u0073";_bea .Params =_cgfcc ([]float64 {rise });_eb ._fgea =append (_eb ._fgea ,&_bea );return _eb ;};
|
|
|
|
// 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 (_cfd *ContentCreator )Add_W ()*ContentCreator {_bfa :=ContentStreamOperation {};_bfa .Operand ="\u0057";_cfd ._fgea =append (_cfd ._fgea ,&_bfa );return _cfd ;};
|
|
|
|
// 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 (_bdeb *ContentCreator )Add_w (lineWidth float64 )*ContentCreator {_gga :=ContentStreamOperation {};_gga .Operand ="\u0077";_gga .Params =_cgfcc ([]float64 {lineWidth });_bdeb ._fgea =append (_bdeb ._fgea ,&_gga );return _bdeb ;};
|
|
|
|
// 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 (_db *ContentCreator )Add_B ()*ContentCreator {_fggb :=ContentStreamOperation {};_fggb .Operand ="\u0042";_db ._fgea =append (_db ._fgea ,&_fggb );return _db ;};func (_dad *ContentStreamInlineImage )toImageBase (_bbg *_fd .PdfPageResources )(*_da .ImageBase ,error ){if _dad ._gbgbb !=nil {return _dad ._gbgbb ,nil ;};_bdd :=_da .ImageBase {};if _dad .Height ==nil {return nil ,_c .New ("\u0068e\u0069\u0067\u0068\u0074\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_decb ,_dfe :=_dad .Height .(*_ge .PdfObjectInteger );if !_dfe {return nil ,_c .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0068e\u0069\u0067\u0068\u0074");};_bdd .Height =int (*_decb );if _dad .Width ==nil {return nil ,_c .New ("\u0077\u0069\u0064th\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_fca ,_dfe :=_dad .Width .(*_ge .PdfObjectInteger );if !_dfe {return nil ,_c .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0069\u0064\u0074\u0068");};_bdd .Width =int (*_fca );_ebc ,_cbg :=_dad .IsMask ();if _cbg !=nil {return nil ,_cbg ;};if _ebc {_bdd .BitsPerComponent =1;_bdd .ColorComponents =1;}else {if _dad .BitsPerComponent ==nil {_gg .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");_bdd .BitsPerComponent =8;}else {_cff ,_cbe :=_dad .BitsPerComponent .(*_ge .PdfObjectInteger );if !_cbe {_gg .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",_dad .BitsPerComponent );return nil ,_c .New ("\u0042\u0050\u0043\u0020\u0054\u0079\u0070\u0065\u0020e\u0072\u0072\u006f\u0072");};_bdd .BitsPerComponent =int (*_cff );};if _dad .ColorSpace !=nil {_ceca ,_agdg :=_dad .GetColorSpace (_bbg );if _agdg !=nil {return nil ,_agdg ;};_bdd .ColorComponents =_ceca .GetNumComponents ();}else {_gg .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");_bdd .ColorComponents =1;};};if _fce ,_bfea :=_ge .GetArray (_dad .Decode );_bfea {_bdd .Decode ,_cbg =_fce .ToFloat64Array ();if _cbg !=nil {return nil ,_cbg ;};};_dad ._gbgbb =&_bdd ;return _dad ._gbgbb ,nil ;};
|
|
|
|
// 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 (_agd *ContentCreator )Add_BMC (tag _ge .PdfObjectName )*ContentCreator {_ef :=ContentStreamOperation {};_ef .Operand ="\u0042\u004d\u0043";_ef .Params =_eccb ([]_ge .PdfObjectName {tag });_agd ._fgea =append (_agd ._fgea ,&_ef );return _agd ;};
|
|
|
|
// ContentCreator is a builder for PDF content streams.
|
|
type ContentCreator struct{_fgea ContentStreamOperations };func (_bgbae *ContentStreamProcessor )handleCommand_SCN (_gceg *ContentStreamOperation ,_fagd *_fd .PdfPageResources )error {_gcef :=_bgbae ._ebeb .ColorspaceStroking ;if !_cdcc (_gcef ){if len (_gceg .Params )!=_gcef .GetNumComponents (){_gg .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");_gg .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 (_gceg .Params ),_gcef );return _c .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");};};_fac ,_cdac :=_gcef .ColorFromPdfObjects (_gceg .Params );if _cdac !=nil {return _cdac ;};_bgbae ._ebeb .ColorStroking =_fac ;return nil ;};
|
|
|
|
// Wrap ensures that the contentstream is wrapped within a balanced q ... Q expression.
|
|
func (_bdc *ContentCreator )Wrap (){_bdc ._fgea .WrapIfNeeded ()};
|
|
|
|
// NewContentStreamProcessor returns a new ContentStreamProcessor for operations `ops`.
|
|
func NewContentStreamProcessor (ops []*ContentStreamOperation )*ContentStreamProcessor {_cfgd :=ContentStreamProcessor {};_cfgd ._agaf =GraphicStateStack {};_fad :=GraphicsState {};_cfgd ._ebeb =_fad ;_cfgd ._bgbg =[]handlerEntry {};_cfgd ._decd =0;_cfgd ._faagf =ops ;return &_cfgd ;};
|
|
|
|
// 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 (_ddfa *ContentCreator )Add_quotes (textstr _ge .PdfObjectString ,aw ,ac float64 )*ContentCreator {_cag :=ContentStreamOperation {};_cag .Operand ="\u0022";_cag .Params =_cgfcc ([]float64 {aw ,ac });_cag .Params =append (_cag .Params ,_baef ([]_ge .PdfObjectString {textstr })...);_ddfa ._fgea =append (_ddfa ._fgea ,&_cag );return _ddfa ;};func _cgfcc (_bgga []float64 )[]_ge .PdfObject {var _cfddc []_ge .PdfObject ;for _ ,_cgdd :=range _bgga {_cfddc =append (_cfddc ,_ge .MakeFloat (_cgdd ));};return _cfddc ;};
|
|
|
|
// 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 (_cfgc *ContentCreator )Add_B_starred ()*ContentCreator {_ggd :=ContentStreamOperation {};_ggd .Operand ="\u0042\u002a";_cfgc ._fgea =append (_cfgc ._fgea ,&_ggd );return _cfgc ;};
|
|
|
|
// 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 (_dbd *ContentCreator )Add_Td (tx ,ty float64 )*ContentCreator {_fcg :=ContentStreamOperation {};_fcg .Operand ="\u0054\u0064";_fcg .Params =_cgfcc ([]float64 {tx ,ty });_dbd ._fgea =append (_dbd ._fgea ,&_fcg );return _dbd ;};
|
|
|
|
// 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 (_ged *ContentStreamOperations )Bytes ()[]byte {var _gge _ca .Buffer ;for _ ,_faa :=range *_ged {if _faa ==nil {continue ;};if _faa .Operand =="\u0042\u0049"{_gge .WriteString (_faa .Operand +"\u000a");_gge .WriteString (_faa .Params [0].WriteString ());}else {for _ ,_ea :=range _faa .Params {_gge .WriteString (_ea .WriteString ());_gge .WriteString ("\u0020");};_gge .WriteString (_faa .Operand +"\u000a");};};return _gge .Bytes ();};
|
|
|
|
// Scale applies x-y scaling to the transformation matrix.
|
|
func (_aee *ContentCreator )Scale (sx ,sy float64 )*ContentCreator {return _aee .Add_cm (sx ,0,0,sy ,0,0);};
|
|
|
|
// 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 (_ace *ContentCreator )Add_Tz (scale float64 )*ContentCreator {_gag :=ContentStreamOperation {};_gag .Operand ="\u0054\u007a";_gag .Params =_cgfcc ([]float64 {scale });_ace ._fgea =append (_ace ._fgea ,&_gag );return _ace ;};func (_fg *ContentStreamOperations )isWrapped ()bool {if len (*_fg )< 2{return false ;};_bd :=0;for _ ,_ac :=range *_fg {if _ac .Operand =="\u0071"{_bd ++;}else if _ac .Operand =="\u0051"{_bd --;}else {if _bd < 1{return false ;};};};return _bd ==0;};
|
|
|
|
// GetColorSpace returns the colorspace of the inline image.
|
|
func (_bcc *ContentStreamInlineImage )GetColorSpace (resources *_fd .PdfPageResources )(_fd .PdfColorspace ,error ){if _bcc .ColorSpace ==nil {_gg .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 _fd .NewPdfColorspaceDeviceGray (),nil ;};if _efd ,_bebg :=_bcc .ColorSpace .(*_ge .PdfObjectArray );_bebg {return _abfc (_efd );};_agcc ,_ddgc :=_bcc .ColorSpace .(*_ge .PdfObjectName );if !_ddgc {_gg .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",_bcc .ColorSpace ,_bcc .ColorSpace );return nil ,_c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_agcc =="\u0047"||*_agcc =="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"{return _fd .NewPdfColorspaceDeviceGray (),nil ;}else if *_agcc =="\u0052\u0047\u0042"||*_agcc =="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"{return _fd .NewPdfColorspaceDeviceRGB (),nil ;}else if *_agcc =="\u0043\u004d\u0059\u004b"||*_agcc =="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{return _fd .NewPdfColorspaceDeviceCMYK (),nil ;}else if *_agcc =="\u0049"||*_agcc =="\u0049n\u0064\u0065\u0078\u0065\u0064"{return nil ,_c .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 {_gg .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",*_agcc );return nil ,_c .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};_gafc ,_gafb :=resources .GetColorspaceByName (*_agcc );if !_gafb {_gg .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",*_agcc );return nil ,_c .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};return _gafc ,nil ;};};func (_edbg *ContentStreamProcessor )getInitialColor (_gedf _fd .PdfColorspace )(_fd .PdfColor ,error ){switch _eeag :=_gedf .(type ){case *_fd .PdfColorspaceDeviceGray :return _fd .NewPdfColorDeviceGray (0.0),nil ;case *_fd .PdfColorspaceDeviceRGB :return _fd .NewPdfColorDeviceRGB (0.0,0.0,0.0),nil ;case *_fd .PdfColorspaceDeviceCMYK :return _fd .NewPdfColorDeviceCMYK (0.0,0.0,0.0,1.0),nil ;case *_fd .PdfColorspaceCalGray :return _fd .NewPdfColorCalGray (0.0),nil ;case *_fd .PdfColorspaceCalRGB :return _fd .NewPdfColorCalRGB (0.0,0.0,0.0),nil ;case *_fd .PdfColorspaceLab :_ebcc :=0.0;_fged :=0.0;_caa :=0.0;if _eeag .Range [0]> 0{_ebcc =_eeag .Range [0];};if _eeag .Range [2]> 0{_fged =_eeag .Range [2];};return _fd .NewPdfColorLab (_ebcc ,_fged ,_caa ),nil ;case *_fd .PdfColorspaceICCBased :if _eeag .Alternate ==nil {_gg .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",_eeag .N );if _eeag .N ==1{_gg .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 _edbg .getInitialColor (_fd .NewPdfColorspaceDeviceGray ());}else if _eeag .N ==3{_gg .Log .Trace ("\u0046a\u006c\u006c\u0069\u006eg\u0020\u0062\u0061\u0063\u006b \u0074o\u0020D\u0065\u0076\u0069\u0063\u0065\u0052\u0047B");return _edbg .getInitialColor (_fd .NewPdfColorspaceDeviceRGB ());}else if _eeag .N ==4{_gg .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 _edbg .getInitialColor (_fd .NewPdfColorspaceDeviceCMYK ());}else {return nil ,_c .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 _edbg .getInitialColor (_eeag .Alternate );case *_fd .PdfColorspaceSpecialIndexed :if _eeag .Base ==nil {return nil ,_c .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 _edbg .getInitialColor (_eeag .Base );case *_fd .PdfColorspaceSpecialSeparation :if _eeag .AlternateSpace ==nil {return nil ,_c .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 _edbg .getInitialColor (_eeag .AlternateSpace );case *_fd .PdfColorspaceDeviceN :if _eeag .AlternateSpace ==nil {return nil ,_c .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 _edbg .getInitialColor (_eeag .AlternateSpace );case *_fd .PdfColorspaceSpecialPattern :return nil ,nil ;};_gg .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",_gedf );return nil ,_c .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061c\u0065");};func (_ddfba *ContentStreamProcessor )handleCommand_cs (_gbdfd *ContentStreamOperation ,_abd *_fd .PdfPageResources )error {if len (_gbdfd .Params )< 1{_gg .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 _c .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_gbdfd .Params )> 1{_gg .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 _c .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_acec ,_gcgd :=_gbdfd .Params [0].(*_ge .PdfObjectName );if !_gcgd {_gg .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 _c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_eggcc ,_ebgc :=_ddfba .getColorspace (string (*_acec ),_abd );if _ebgc !=nil {return _ebgc ;};_ddfba ._ebeb .ColorspaceNonStroking =_eggcc ;_bgca ,_ebgc :=_ddfba .getInitialColor (_eggcc );if _ebgc !=nil {return _ebgc ;};_ddfba ._ebeb .ColorNonStroking =_bgca ;return nil ;};
|
|
|
|
// 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 (_faf *ContentCreator )Add_cm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_cga :=ContentStreamOperation {};_cga .Operand ="\u0063\u006d";_cga .Params =_cgfcc ([]float64 {a ,b ,c ,d ,e ,f });_faf ._fgea =append (_faf ._fgea ,&_cga );return _faf ;};
|
|
|
|
// String is same as Bytes() except returns as a string for convenience.
|
|
func (_cf *ContentCreator )String ()string {return string (_cf ._fgea .Bytes ())};func (_adgc *ContentStreamProcessor )getColorspace (_adga string ,_adfd *_fd .PdfPageResources )(_fd .PdfColorspace ,error ){switch _adga {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":return _fd .NewPdfColorspaceDeviceGray (),nil ;case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":return _fd .NewPdfColorspaceDeviceRGB (),nil ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return _fd .NewPdfColorspaceDeviceCMYK (),nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return _fd .NewPdfColorspaceSpecialPattern (),nil ;};_eggc ,_eded :=_adfd .GetColorspaceByName (_ge .PdfObjectName (_adga ));if _eded {return _eggc ,nil ;};switch _adga {case "\u0043a\u006c\u0047\u0072\u0061\u0079":return _fd .NewPdfColorspaceCalGray (),nil ;case "\u0043\u0061\u006c\u0052\u0047\u0042":return _fd .NewPdfColorspaceCalRGB (),nil ;case "\u004c\u0061\u0062":return _fd .NewPdfColorspaceLab (),nil ;};_gg .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",_adga );return nil ,_ga .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",_adga );};
|
|
|
|
// 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 (_accf *ContentCreator )Add_SCN_pattern (name _ge .PdfObjectName ,c ...float64 )*ContentCreator {_fcfbc :=ContentStreamOperation {};_fcfbc .Operand ="\u0053\u0043\u004e";_fcfbc .Params =_cgfcc (c );_fcfbc .Params =append (_fcfbc .Params ,_ge .MakeName (string (name )));_accf ._fgea =append (_accf ._fgea ,&_fcfbc );return _accf ;};
|
|
|
|
// Transform returns coordinates x, y transformed by the CTM.
|
|
func (_ccec *GraphicsState )Transform (x ,y float64 )(float64 ,float64 ){return _ccec .CTM .Transform (x ,y );};
|
|
|
|
// 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 (_ffd *ContentCreator )Add_TJ (vals ..._ge .PdfObject )*ContentCreator {_bcd :=ContentStreamOperation {};_bcd .Operand ="\u0054\u004a";_bcd .Params =[]_ge .PdfObject {_ge .MakeArray (vals ...)};_ffd ._fgea =append (_ffd ._fgea ,&_bcd );return _ffd ;};
|
|
|
|
// 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 (_bae *ContentCreator )Add_M (miterlimit float64 )*ContentCreator {_ec :=ContentStreamOperation {};_ec .Operand ="\u004d";_ec .Params =_cgfcc ([]float64 {miterlimit });_bae ._fgea =append (_bae ._fgea ,&_ec );return _bae ;};
|
|
|
|
// 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{_agaf GraphicStateStack ;_faagf []*ContentStreamOperation ;_ebeb GraphicsState ;_bgbg []handlerEntry ;_decd int ;};
|
|
|
|
// 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 (_edd *ContentCreator )Bytes ()[]byte {return _edd ._fgea .Bytes ()};
|
|
|
|
// 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 (_dcc *ContentCreator )Add_scn (c ...float64 )*ContentCreator {_df :=ContentStreamOperation {};_df .Operand ="\u0073\u0063\u006e";_df .Params =_cgfcc (c );_dcc ._fgea =append (_dcc ._fgea ,&_df );return _dcc ;};
|
|
|
|
// 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 (_be *ContentCreator )Add_ri (intent _ge .PdfObjectName )*ContentCreator {_ee :=ContentStreamOperation {};_ee .Operand ="\u0072\u0069";_ee .Params =_eccb ([]_ge .PdfObjectName {intent });_be ._fgea =append (_be ._fgea ,&_ee );return _be ;};type handlerEntry struct{Condition HandlerConditionEnum ;Operand string ;Handler HandlerFunc ;};
|
|
|
|
// AddOperand adds a specified operand.
|
|
func (_cec *ContentCreator )AddOperand (op ContentStreamOperation )*ContentCreator {_cec ._fgea =append (_cec ._fgea ,&op );return _cec ;};
|
|
|
|
// 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 (_fc *ContentCreator )Add_gs (dictName _ge .PdfObjectName )*ContentCreator {_dcf :=ContentStreamOperation {};_dcf .Operand ="\u0067\u0073";_dcf .Params =_eccb ([]_ge .PdfObjectName {dictName });_fc ._fgea =append (_fc ._fgea ,&_dcf );return _fc ;};
|
|
|
|
// 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 (_eaa *ContentCreator )Add_Tc (charSpace float64 )*ContentCreator {_ccd :=ContentStreamOperation {};_ccd .Operand ="\u0054\u0063";_ccd .Params =_cgfcc ([]float64 {charSpace });_eaa ._fgea =append (_eaa ._fgea ,&_ccd );return _eaa ;};
|
|
|
|
// 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 (_ae *ContentCreator )Add_q ()*ContentCreator {_ag :=ContentStreamOperation {};_ag .Operand ="\u0071";_ae ._fgea =append (_ae ._fgea ,&_ag );return _ae ;};
|
|
|
|
// 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 (_dag *ContentCreator )Add_Q ()*ContentCreator {_dagd :=ContentStreamOperation {};_dagd .Operand ="\u0051";_dag ._fgea =append (_dag ._fgea ,&_dagd );return _dag ;};
|
|
|
|
// ContentStreamParser represents a content stream parser for parsing content streams in PDFs.
|
|
type ContentStreamParser struct{_acag *_d .Reader };
|
|
|
|
// GetEncoder returns the encoder of the inline image.
|
|
func (_cgf *ContentStreamInlineImage )GetEncoder ()(_ge .StreamEncoder ,error ){return _cecb (_cgf )};
|
|
|
|
// 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 (_dff *ContentCreator )Add_G (gray float64 )*ContentCreator {_eddd :=ContentStreamOperation {};_eddd .Operand ="\u0047";_eddd .Params =_cgfcc ([]float64 {gray });_dff ._fgea =append (_dff ._fgea ,&_eddd );return _dff ;};func (_dcff *ContentStreamParser )skipSpaces ()(int ,error ){_bbf :=0;for {_cce ,_egg :=_dcff ._acag .Peek (1);if _egg !=nil {return 0,_egg ;};if _ge .IsWhiteSpace (_cce [0]){_dcff ._acag .ReadByte ();_bbf ++;}else {break ;};};return _bbf ,nil ;};func (_ccfec *ContentStreamProcessor )handleCommand_rg (_gcc *ContentStreamOperation ,_adac *_fd .PdfPageResources )error {_bdfg :=_fd .NewPdfColorspaceDeviceRGB ();if len (_gcc .Params )!=_bdfg .GetNumComponents (){_gg .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");_gg .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 (_gcc .Params ),_bdfg );return _c .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");};_cccd ,_beec :=_bdfg .ColorFromPdfObjects (_gcc .Params );if _beec !=nil {return _beec ;};_ccfec ._ebeb .ColorspaceNonStroking =_bdfg ;_ccfec ._ebeb .ColorNonStroking =_cccd ;return nil ;};
|
|
|
|
// 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 _ge .PdfObject ;ColorSpace _ge .PdfObject ;Decode _ge .PdfObject ;DecodeParms _ge .PdfObject ;Filter _ge .PdfObject ;Height _ge .PdfObject ;ImageMask _ge .PdfObject ;Intent _ge .PdfObject ;Interpolate _ge .PdfObject ;Width _ge .PdfObject ;_dfc []byte ;_gbgbb *_da .ImageBase ;};
|
|
|
|
// 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 (_beb *ContentCreator )Add_W_starred ()*ContentCreator {_fgb :=ContentStreamOperation {};_fgb .Operand ="\u0057\u002a";_beb ._fgea =append (_beb ._fgea ,&_fgb );return _beb ;};func (_ebda *ContentStreamProcessor )handleCommand_sc (_agad *ContentStreamOperation ,_eae *_fd .PdfPageResources )error {_efea :=_ebda ._ebeb .ColorspaceNonStroking ;if !_cdcc (_efea ){if len (_agad .Params )!=_efea .GetNumComponents (){_gg .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");_gg .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 (_agad .Params ),_efea );return _c .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");};};_fgbg ,_ebcbc :=_efea .ColorFromPdfObjects (_agad .Params );if _ebcbc !=nil {return _ebcbc ;};_ebda ._ebeb .ColorNonStroking =_fgbg ;return nil ;};func _cecb (_ceb *ContentStreamInlineImage )(_ge .StreamEncoder ,error ){if _ceb .Filter ==nil {return _ge .NewRawEncoder (),nil ;};_faff ,_eff :=_ceb .Filter .(*_ge .PdfObjectName );if !_eff {_edgc ,_ebf :=_ceb .Filter .(*_ge .PdfObjectArray );if !_ebf {return nil ,_ga .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 _edgc .Len ()==0{return _ge .NewRawEncoder (),nil ;};if _edgc .Len ()!=1{_fbg ,_agc :=_faagg (_ceb );if _agc !=nil {_gg .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",_agc );return nil ,_agc ;};_gg .Log .Trace ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063:\u0020\u0025\u0073\u000a",_fbg );return _fbg ,nil ;};_fbe :=_edgc .Get (0);_faff ,_ebf =_fbe .(*_ge .PdfObjectName );if !_ebf {return nil ,_ga .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 *_faff {case "\u0041\u0048\u0078","\u0041\u0053\u0043\u0049\u0049\u0048\u0065\u0078\u0044e\u0063\u006f\u0064\u0065":return _ge .NewASCIIHexEncoder (),nil ;case "\u0041\u0038\u0035","\u0041\u0053\u0043\u0049\u0049\u0038\u0035\u0044\u0065\u0063\u006f\u0064\u0065":return _ge .NewASCII85Encoder (),nil ;case "\u0044\u0043\u0054","\u0044C\u0054\u0044\u0065\u0063\u006f\u0064e":return _ebe (_ceb );case "\u0046\u006c","F\u006c\u0061\u0074\u0065\u0044\u0065\u0063\u006f\u0064\u0065":return _cacc (_ceb ,nil );case "\u004c\u005a\u0057","\u004cZ\u0057\u0044\u0065\u0063\u006f\u0064e":return _eeb (_ceb ,nil );case "\u0043\u0043\u0046","\u0043\u0043\u0049\u0054\u0054\u0046\u0061\u0078\u0044e\u0063\u006f\u0064\u0065":return _ge .NewCCITTFaxEncoder (),nil ;case "\u0052\u004c","\u0052u\u006eL\u0065\u006e\u0067\u0074\u0068\u0044\u0065\u0063\u006f\u0064\u0065":return _ge .NewRunLengthEncoder (),nil ;default:_gg .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",*_faff );return nil ,_c .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006el\u0069n\u0065 \u0065n\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};};
|
|
|
|
// Add_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 (_bff *ContentCreator )Add_scn_pattern (name _ge .PdfObjectName ,c ...float64 )*ContentCreator {_geb :=ContentStreamOperation {};_geb .Operand ="\u0073\u0063\u006e";_geb .Params =_cgfcc (c );_geb .Params =append (_geb .Params ,_ge .MakeName (string (name )));_bff ._fgea =append (_bff ._fgea ,&_geb );return _bff ;};
|
|
|
|
// WriteString outputs the object as it is to be written to file.
|
|
func (_cdc *ContentStreamInlineImage )WriteString ()string {var _fgbe _ca .Buffer ;_bfe :="";if _cdc .BitsPerComponent !=nil {_bfe +="\u002f\u0042\u0050C\u0020"+_cdc .BitsPerComponent .WriteString ()+"\u000a";};if _cdc .ColorSpace !=nil {_bfe +="\u002f\u0043\u0053\u0020"+_cdc .ColorSpace .WriteString ()+"\u000a";};if _cdc .Decode !=nil {_bfe +="\u002f\u0044\u0020"+_cdc .Decode .WriteString ()+"\u000a";};if _cdc .DecodeParms !=nil {_bfe +="\u002f\u0044\u0050\u0020"+_cdc .DecodeParms .WriteString ()+"\u000a";};if _cdc .Filter !=nil {_bfe +="\u002f\u0046\u0020"+_cdc .Filter .WriteString ()+"\u000a";};if _cdc .Height !=nil {_bfe +="\u002f\u0048\u0020"+_cdc .Height .WriteString ()+"\u000a";};if _cdc .ImageMask !=nil {_bfe +="\u002f\u0049\u004d\u0020"+_cdc .ImageMask .WriteString ()+"\u000a";};if _cdc .Intent !=nil {_bfe +="\u002f\u0049\u006e\u0074\u0065\u006e\u0074\u0020"+_cdc .Intent .WriteString ()+"\u000a";};if _cdc .Interpolate !=nil {_bfe +="\u002f\u0049\u0020"+_cdc .Interpolate .WriteString ()+"\u000a";};if _cdc .Width !=nil {_bfe +="\u002f\u0057\u0020"+_cdc .Width .WriteString ()+"\u000a";};_fgbe .WriteString (_bfe );_fgbe .WriteString ("\u0049\u0044\u0020");_fgbe .Write (_cdc ._dfc );_fgbe .WriteString ("\u000a\u0045\u0049\u000a");return _fgbe .String ();};
|
|
|
|
// ToImage exports the inline image to Image which can be transformed or exported easily.
|
|
// Page resources are needed to look up colorspace information.
|
|
func (_acab *ContentStreamInlineImage )ToImage (resources *_fd .PdfPageResources )(*_fd .Image ,error ){_gfeg ,_afb :=_acab .toImageBase (resources );if _afb !=nil {return nil ,_afb ;};_ccb ,_afb :=_cecb (_acab );if _afb !=nil {return nil ,_afb ;};_gg .Log .Trace ("\u0065n\u0063o\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076\u0020\u0025\u0054",_ccb ,_ccb );_gg .Log .Trace ("\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065:\u0020\u0025\u002b\u0076",_acab );_gaaf ,_afb :=_ccb .DecodeBytes (_acab ._dfc );if _afb !=nil {return nil ,_afb ;};_dcfb :=&_fd .Image {Width :int64 (_gfeg .Width ),Height :int64 (_gfeg .Height ),BitsPerComponent :int64 (_gfeg .BitsPerComponent ),ColorComponents :_gfeg .ColorComponents ,Data :_gaaf };if len (_gfeg .Decode )> 0{for _eaaf :=0;_eaaf < len (_gfeg .Decode );_eaaf ++{_gfeg .Decode [_eaaf ]*=float64 ((int (1)<<uint (_gfeg .BitsPerComponent ))-1);};_dcfb .SetDecode (_gfeg .Decode );};return _dcfb ,nil ;};
|
|
|
|
// 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 _fd .PdfColorspace ;ColorspaceNonStroking _fd .PdfColorspace ;ColorStroking _fd .PdfColor ;ColorNonStroking _fd .PdfColor ;CTM _dd .Matrix ;};
|
|
|
|
// 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 (_cgcc *ContentStreamParser )ExtractText ()(string ,error ){_de ,_cc :=_cgcc .Parse ();if _cc !=nil {return "",_cc ;};_ed :=false ;_bde ,_af :=float64 (-1),float64 (-1);_ce :="";for _ ,_ff :=range *_de {if _ff .Operand =="\u0042\u0054"{_ed =true ;}else if _ff .Operand =="\u0045\u0054"{_ed =false ;};if _ff .Operand =="\u0054\u0064"||_ff .Operand =="\u0054\u0044"||_ff .Operand =="\u0054\u002a"{_ce +="\u000a";};if _ff .Operand =="\u0054\u006d"{if len (_ff .Params )!=6{continue ;};_ead ,_cac :=_ff .Params [4].(*_ge .PdfObjectFloat );if !_cac {_aa ,_gd :=_ff .Params [4].(*_ge .PdfObjectInteger );if !_gd {continue ;};_ead =_ge .MakeFloat (float64 (*_aa ));};_cgg ,_cac :=_ff .Params [5].(*_ge .PdfObjectFloat );if !_cac {_gfa ,_gaf :=_ff .Params [5].(*_ge .PdfObjectInteger );if !_gaf {continue ;};_cgg =_ge .MakeFloat (float64 (*_gfa ));};if _af ==-1{_af =float64 (*_cgg );}else if _af > float64 (*_cgg ){_ce +="\u000a";_bde =float64 (*_ead );_af =float64 (*_cgg );continue ;};if _bde ==-1{_bde =float64 (*_ead );}else if _bde < float64 (*_ead ){_ce +="\u0009";_bde =float64 (*_ead );};};if _ed &&_ff .Operand =="\u0054\u004a"{if len (_ff .Params )< 1{continue ;};_faag ,_gac :=_ff .Params [0].(*_ge .PdfObjectArray );if !_gac {return "",_ga .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",_ff .Params [0]);};for _ ,_daf :=range _faag .Elements (){switch _cbf :=_daf .(type ){case *_ge .PdfObjectString :_ce +=_cbf .Str ();case *_ge .PdfObjectFloat :if *_cbf < -100{_ce +="\u0020";};case *_ge .PdfObjectInteger :if *_cbf < -100{_ce +="\u0020";};};};}else if _ed &&_ff .Operand =="\u0054\u006a"{if len (_ff .Params )< 1{continue ;};_dg ,_ba :=_ff .Params [0].(*_ge .PdfObjectString );if !_ba {return "",_ga .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",_ff .Params [0]);};_ce +=_dg .Str ();};};return _ce ,nil ;};
|
|
|
|
// ContentStreamOperations is a slice of ContentStreamOperations.
|
|
type ContentStreamOperations []*ContentStreamOperation ;
|
|
|
|
// Operand returns true if `hce` is equivalent to HandlerConditionEnumOperand.
|
|
func (_fba HandlerConditionEnum )Operand ()bool {return _fba ==HandlerConditionEnumOperand };
|
|
|
|
// 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 (_gbd *ContentCreator )Add_g (gray float64 )*ContentCreator {_aeg :=ContentStreamOperation {};_aeg .Operand ="\u0067";_aeg .Params =_cgfcc ([]float64 {gray });_gbd ._fgea =append (_gbd ._fgea ,&_aeg );return _gbd ;};
|
|
|
|
// 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 (_fgeab *ContentCreator )Add_sh (name _ge .PdfObjectName )*ContentCreator {_cdb :=ContentStreamOperation {};_cdb .Operand ="\u0073\u0068";_cdb .Params =_eccb ([]_ge .PdfObjectName {name });_fgeab ._fgea =append (_fgeab ._fgea ,&_cdb );return _fgeab ;};func _cfcc (_adcf []int64 )[]_ge .PdfObject {var _cfca []_ge .PdfObject ;for _ ,_cdd :=range _adcf {_cfca =append (_cfca ,_ge .MakeInteger (_cdd ));};return _cfca ;};func (_cde *ContentStreamParser )parseOperand ()(*_ge .PdfObjectString ,error ){var _bfef []byte ;for {_dab ,_dfgg :=_cde ._acag .Peek (1);if _dfgg !=nil {return _ge .MakeString (string (_bfef )),_dfgg ;};if _ge .IsDelimiter (_dab [0]){break ;};if _ge .IsWhiteSpace (_dab [0]){break ;};_agfa ,_ :=_cde ._acag .ReadByte ();_bfef =append (_bfef ,_agfa );};return _ge .MakeString (string (_bfef )),nil ;};
|
|
|
|
// SetNonStrokingColor sets the non-stroking `color` where color can be one of
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
func (_dgea *ContentCreator )SetNonStrokingColor (color _fd .PdfColor )*ContentCreator {switch _aegc :=color .(type ){case *_fd .PdfColorDeviceGray :_dgea .Add_g (_aegc .Val ());case *_fd .PdfColorDeviceRGB :_dgea .Add_rg (_aegc .R (),_aegc .G (),_aegc .B ());case *_fd .PdfColorDeviceCMYK :_dgea .Add_k (_aegc .C (),_aegc .M (),_aegc .Y (),_aegc .K ());default:_gg .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",_aegc );};return _dgea ;};func (_dccg *ContentStreamProcessor )handleCommand_RG (_cfdd *ContentStreamOperation ,_ded *_fd .PdfPageResources )error {_acdb :=_fd .NewPdfColorspaceDeviceRGB ();if len (_cfdd .Params )!=_acdb .GetNumComponents (){_gg .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");_gg .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 (_cfdd .Params ),_acdb );return _c .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");};_dcdbg ,_cacae :=_acdb .ColorFromPdfObjects (_cfdd .Params );if _cacae !=nil {return _cacae ;};_dccg ._ebeb .ColorspaceStroking =_acdb ;_dccg ._ebeb .ColorStroking =_dcdbg ;return nil ;};func (_bbgd *ContentStreamProcessor )handleCommand_CS (_cfc *ContentStreamOperation ,_ebd *_fd .PdfPageResources )error {if len (_cfc .Params )< 1{_gg .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 _c .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_cfc .Params )> 1{_gg .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 _c .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_efeb ,_gbff :=_cfc .Params [0].(*_ge .PdfObjectName );if !_gbff {_gg .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 _c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_dca ,_gfad :=_bbgd .getColorspace (string (*_efeb ),_ebd );if _gfad !=nil {return _gfad ;};_bbgd ._ebeb .ColorspaceStroking =_dca ;_faaa ,_gfad :=_bbgd .getInitialColor (_dca );if _gfad !=nil {return _gfad ;};_bbgd ._ebeb .ColorStroking =_faaa ;return nil ;};func (_gdadb *ContentStreamParser )parseNull ()(_ge .PdfObjectNull ,error ){_ ,_eaaa :=_gdadb ._acag .Discard (4);return _ge .PdfObjectNull {},_eaaa ;};
|
|
|
|
// 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 (_afe *ContentCreator )Add_SC (c ...float64 )*ContentCreator {_aaa :=ContentStreamOperation {};_aaa .Operand ="\u0053\u0043";_aaa .Params =_cgfcc (c );_afe ._fgea =append (_afe ._fgea ,&_aaa );return _afe ;};
|
|
|
|
// AddHandler adds a new ContentStreamProcessor `handler` of type `condition` for `operand`.
|
|
func (_edce *ContentStreamProcessor )AddHandler (condition HandlerConditionEnum ,operand string ,handler HandlerFunc ){_aeccg :=handlerEntry {};_aeccg .Condition =condition ;_aeccg .Operand =operand ;_aeccg .Handler =handler ;_edce ._bgbg =append (_edce ._bgbg ,_aeccg );};
|
|
|
|
// 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 (_fda *ContentCreator )Add_h ()*ContentCreator {_fgf :=ContentStreamOperation {};_fgf .Operand ="\u0068";_fda ._fgea =append (_fda ._fgea ,&_fgf );return _fda ;};
|
|
|
|
// RotateDeg applies a rotation to the transformation matrix.
|
|
func (_bb *ContentCreator )RotateDeg (angle float64 )*ContentCreator {_ggc :=_b .Cos (angle *_b .Pi /180.0);_gfg :=_b .Sin (angle *_b .Pi /180.0);_cgd :=-_b .Sin (angle *_b .Pi /180.0);_adc :=_b .Cos (angle *_b .Pi /180.0);return _bb .Add_cm (_ggc ,_gfg ,_cgd ,_adc ,0,0);};
|
|
|
|
// 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 (_adb *ContentCreator )Add_J (lineCapStyle string )*ContentCreator {_aeb :=ContentStreamOperation {};_aeb .Operand ="\u004a";_aeb .Params =_eccb ([]_ge .PdfObjectName {_ge .PdfObjectName (lineCapStyle )});_adb ._fgea =append (_adb ._fgea ,&_aeb );return _adb ;};
|
|
|
|
// 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 (_fgg *ContentCreator )Add_S ()*ContentCreator {_ggb :=ContentStreamOperation {};_ggb .Operand ="\u0053";_fgg ._fgea =append (_fgg ._fgea ,&_ggb );return _fgg ;};
|
|
|
|
// All returns true if `hce` is equivalent to HandlerConditionEnumAllOperands.
|
|
func (_cacg HandlerConditionEnum )All ()bool {return _cacg ==HandlerConditionEnumAllOperands };func (_bba *ContentStreamProcessor )handleCommand_G (_dcae *ContentStreamOperation ,_gea *_fd .PdfPageResources )error {_cgfc :=_fd .NewPdfColorspaceDeviceGray ();if len (_dcae .Params )!=_cgfc .GetNumComponents (){_gg .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");_gg .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 (_dcae .Params ),_cgfc );return _c .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");};_ffdc ,_eadc :=_cgfc .ColorFromPdfObjects (_dcae .Params );if _eadc !=nil {return _eadc ;};_bba ._ebeb .ColorspaceStroking =_cgfc ;_bba ._ebeb .ColorStroking =_ffdc ;return nil ;};func _abfc (_eefc _ge .PdfObject )(_fd .PdfColorspace ,error ){_eagc ,_gcea :=_eefc .(*_ge .PdfObjectArray );if !_gcea {_gg .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",_eefc );return nil ,_c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if _eagc .Len ()!=4{_gg .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",_eagc .Len ());return nil ,_c .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_fbf ,_gcea :=_eagc .Get (0).(*_ge .PdfObjectName );if !_gcea {_gg .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",*_eagc );return nil ,_c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_fbf !="\u0049"&&*_fbf !="\u0049n\u0064\u0065\u0078\u0065\u0064"{_gg .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",*_fbf );return nil ,_c .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_fbf ,_gcea =_eagc .Get (1).(*_ge .PdfObjectName );if !_gcea {_gg .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",*_eagc );return nil ,_c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_fbf !="\u0047"&&*_fbf !="\u0052\u0047\u0042"&&*_fbf !="\u0043\u004d\u0059\u004b"&&*_fbf !="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"&&*_fbf !="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"&&*_fbf !="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{_gg .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",*_fbf );return nil ,_c .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_dfdf :="";switch *_fbf {case "\u0047","\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_dfdf ="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079";case "\u0052\u0047\u0042","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_dfdf ="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B";case "\u0043\u004d\u0059\u004b","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_dfdf ="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b";};_fcbf :=_ge .MakeArray (_ge .MakeName ("\u0049n\u0064\u0065\u0078\u0065\u0064"),_ge .MakeName (_dfdf ),_eagc .Get (2),_eagc .Get (3));return _fd .NewPdfColorspaceFromPdfObject (_fcbf );};func (_fdd *ContentStreamProcessor )handleCommand_SC (_ggcg *ContentStreamOperation ,_dega *_fd .PdfPageResources )error {_ccbc :=_fdd ._ebeb .ColorspaceStroking ;if len (_ggcg .Params )!=_ccbc .GetNumComponents (){_gg .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");_gg .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 (_ggcg .Params ),_ccbc );return _c .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");};_cbbb ,_fdc :=_ccbc .ColorFromPdfObjects (_ggcg .Params );if _fdc !=nil {return _fdc ;};_fdd ._ebeb .ColorStroking =_cbbb ;return nil ;};
|
|
|
|
// NewContentCreator returns a new initialized ContentCreator.
|
|
func NewContentCreator ()*ContentCreator {_dec :=&ContentCreator {};_dec ._fgea =ContentStreamOperations {};return _dec ;}; |