2022-02-05 21:34:53 +00:00

52 lines
12 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 docutil ;import (_f "errors";_fa "fmt";_b "github.com/unidoc/unipdf/v3/common";_a "github.com/unidoc/unipdf/v3/core";);func (_fdg *Catalog )GetMarkInfo ()(*_a .PdfObjectDictionary ,bool ){_cg ,_cc :=_a .GetDict (_fdg .Object .Get ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f"));
return _cg ,_cc ;};type OutputIntents struct{_gc *_a .PdfObjectArray ;_ddf *Document ;_bgf *_a .PdfIndirectObject ;};func (_fe *OutputIntents )Add (oi _a .PdfObject )error {_dgd ,_cga :=oi .(*_a .PdfObjectDictionary );if !_cga {return _f .New ("\u0069\u006e\u0070\u0075\u0074\u0020\u006f\u0075\u0074\u0070\u0075\u0074\u0020\u0069\u006e\u0074\u0065\u006et\u0020\u0073\u0068\u006f\u0075\u006c\u0064 \u0062\u0065\u0020\u0061\u006e\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0064\u0069\u0063\u0074\u0069\u006f\u006e\u0061\u0072\u0079");
};if _ag ,_gd :=_a .GetStream (_dgd .Get ("\u0044\u0065\u0073\u0074\u004f\u0075\u0074\u0070\u0075\u0074\u0050\u0072o\u0066\u0069\u006c\u0065"));_gd {_fe ._ddf .Objects =append (_fe ._ddf .Objects ,_ag );};_bd ,_gad :=oi .(*_a .PdfIndirectObject );if !_gad {_bd =_a .MakeIndirectObject (oi );
};if _fe ._gc ==nil {_fe ._gc =_a .MakeArray (_bd );}else {_fe ._gc .Append (_bd );};_fe ._ddf .Objects =append (_fe ._ddf .Objects ,_bd );return nil ;};func (_ff *Catalog )SetVersion (){_ff .Object .Set ("\u0056e\u0072\u0073\u0069\u006f\u006e",_a .MakeName (_fa .Sprintf ("\u0025\u0064\u002e%\u0064",_ff ._d .Version .Major ,_ff ._d .Version .Minor )));
};type Content struct{Stream *_a .PdfObjectStream ;_bbb int ;_ffg Page ;};func (_gba *Page )Number ()int {return _gba ._ca };func (_cgae Page )GetContents ()([]Content ,bool ){_gcb ,_fbd :=_a .GetArray (_cgae .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));
if !_fbd {return nil ,false ;};_cbd :=make ([]Content ,_gcb .Len ());for _geb ,_cfe :=range _gcb .Elements (){_bgc ,_gae :=_a .GetStream (_cfe );if !_gae {continue ;};_cbd [_geb ]=Content {Stream :_bgc ,_ffg :_cgae ,_bbb :_geb };};return _cbd ,true ;};
func (_fc *OutputIntents )Get (i int )(OutputIntent ,bool ){if _fc ._gc ==nil {return OutputIntent {},false ;};if i >=_fc ._gc .Len (){return OutputIntent {},false ;};_bf :=_fc ._gc .Get (i );_adb ,_ce :=_a .GetIndirect (_bf );if !_ce {_gge ,_aeb :=_a .GetDict (_bf );
return OutputIntent {Object :_gge },_aeb ;};_cgf ,_gcf :=_a .GetDict (_adb .PdfObject );return OutputIntent {Object :_cgf },_gcf ;};func _ced (_gcc _a .PdfObject )(_a .PdfObjectName ,error ){var _fad *_a .PdfObjectName ;var _aec *_a .PdfObjectArray ;if _abf ,_ege :=_gcc .(*_a .PdfIndirectObject );
_ege {if _cea ,_adbe :=_abf .PdfObject .(*_a .PdfObjectArray );_adbe {_aec =_cea ;}else if _edg ,_af :=_abf .PdfObject .(*_a .PdfObjectName );_af {_fad =_edg ;};}else if _fec ,_afd :=_gcc .(*_a .PdfObjectArray );_afd {_aec =_fec ;}else if _cde ,_adg :=_gcc .(*_a .PdfObjectName );
_adg {_fad =_cde ;};if _fad !=nil {switch *_fad {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return *_fad ,nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return *_fad ,nil ;
};};if _aec !=nil &&_aec .Len ()> 0{if _eb ,_gdd :=_aec .Get (0).(*_a .PdfObjectName );_gdd {switch *_eb {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":if _aec .Len ()==1{return *_eb ,nil ;
};case "\u0043a\u006c\u0047\u0072\u0061\u0079","\u0043\u0061\u006c\u0052\u0047\u0042","\u004c\u0061\u0062":return *_eb ,nil ;case "\u0049\u0043\u0043\u0042\u0061\u0073\u0065\u0064","\u0050a\u0074\u0074\u0065\u0072\u006e","\u0049n\u0064\u0065\u0078\u0065\u0064":return *_eb ,nil ;
case "\u0053\u0065\u0070\u0061\u0072\u0061\u0074\u0069\u006f\u006e","\u0044e\u0076\u0069\u0063\u0065\u004e":return *_eb ,nil ;};};};return "",nil ;};func (_dgdg *Document )AddIndirectObject (indirect *_a .PdfIndirectObject ){for _ ,_fef :=range _dgdg .Objects {if _fef ==indirect {return ;
};};_dgdg .Objects =append (_dgdg .Objects ,indirect );};func (_ffc *Catalog )SetMetadata (data []byte )error {_da ,_gf :=_a .MakeStream (data ,nil );if _gf !=nil {return _gf ;};_da .Set ("\u0054\u0079\u0070\u0065",_a .MakeName ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"));
_da .Set ("\u0053u\u0062\u0074\u0079\u0070\u0065",_a .MakeName ("\u0058\u004d\u004c"));_ffc .Object .Set ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061",_da );_ffc ._d .Objects =append (_ffc ._d .Objects ,_da );return nil ;};type Catalog struct{Object *_a .PdfObjectDictionary ;
_d *Document ;};type OutputIntent struct{Object *_a .PdfObjectDictionary ;};func (_gdb Page )FindXObjectImages ()([]*Image ,error ){_faa ,_bc :=_gdb .GetResourcesXObject ();if !_bc {return nil ,nil ;};var _df []*Image ;var _abfg error ;_ebf :=map[*_a .PdfObjectStream ]int {};
_dcg :=map[*_a .PdfObjectStream ]struct{}{};var _ac int ;for _ ,_dba :=range _faa .Keys (){_dbd ,_gddc :=_a .GetStream (_faa .Get (_dba ));if !_gddc {continue ;};if _ ,_dac :=_ebf [_dbd ];_dac {continue ;};_cee ,_ebfb :=_a .GetName (_dbd .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));
if !_ebfb ||_cee .String ()!="\u0049\u006d\u0061g\u0065"{continue ;};_bde :=Image {BitsPerComponent :8,Stream :_dbd ,Name :string (_dba )};if _bde .Colorspace ,_abfg =_ced (_dbd .PdfObjectDictionary .Get ("\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065"));
_abfg !=nil {_b .Log .Error ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u0025\u0073",_abfg );continue ;};if _ef ,_aa :=_a .GetIntVal (_dbd .PdfObjectDictionary .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074"));
_aa {_bde .BitsPerComponent =_ef ;};if _dfd ,_bga :=_a .GetIntVal (_dbd .PdfObjectDictionary .Get ("\u0057\u0069\u0064t\u0068"));_bga {_bde .Width =_dfd ;};if _bcf ,_gga :=_a .GetIntVal (_dbd .PdfObjectDictionary .Get ("\u0048\u0065\u0069\u0067\u0068\u0074"));
_gga {_bde .Height =_bcf ;};if _dff ,_bcb :=_a .GetStream (_dbd .Get ("\u0053\u004d\u0061s\u006b"));_bcb {_bde .SMask =&ImageSMask {Image :&_bde ,Stream :_dff };_dcg [_dff ]=struct{}{};};switch _bde .Colorspace {case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_bde .ColorComponents =3;
case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_bde .ColorComponents =1;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_bde .ColorComponents =4;default:_bde .ColorComponents =-1;};_ebf [_dbd ]=_ac ;_df =append (_df ,&_bde );
_ac ++;};var _add []int ;for _ ,_faf :=range _df {if _faf .SMask !=nil {_acc ,_bdb :=_ebf [_faf .SMask .Stream ];if _bdb {_add =append (_add ,_acc );};};};_fgd :=make ([]*Image ,len (_df )-len (_add ));_ac =0;_gde :for _ea ,_ee :=range _df {for _ ,_bfb :=range _add {if _ea ==_bfb {continue _gde ;
};};_fgd [_ac ]=_ee ;_ac ++;};return _df ,nil ;};func (_gb *Catalog )SetMarkInfo (mi _a .PdfObject ){_gb .Object .Set ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f",mi );_gb ._d .Objects =append (_gb ._d .Objects ,mi );};type Image struct{Name string ;
Width int ;Height int ;Colorspace _a .PdfObjectName ;ColorComponents int ;BitsPerComponent int ;SMask *ImageSMask ;Stream *_a .PdfObjectStream ;};func (_fbc Content )GetData ()([]byte ,error ){_cdg ,_aag :=_a .NewEncoderFromStream (_fbc .Stream );if _aag !=nil {return nil ,_aag ;
};_fgda ,_aag :=_cdg .DecodeStream (_fbc .Stream );if _aag !=nil {return nil ,_aag ;};return _fgda ,nil ;};type Document struct{ID [2]string ;Version _a .Version ;Objects []_a .PdfObject ;Info _a .PdfObject ;Crypt *_a .PdfCrypt ;UseHashBasedID bool ;};
func (_fcc *Content )SetData (data []byte )error {_cef ,_gcbd :=_a .MakeStream (data ,_a .NewFlateEncoder ());if _gcbd !=nil {return _gcbd ;};_bgfb ,_ :=_a .GetArray (_fcc ._ffg .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if _gcbd =_bgfb .Set (_fcc ._bbb ,_cef );
_gcbd !=nil {return _gcbd ;};_fcc ._ffg ._ddg .Objects =append (_fcc ._ffg ._ddg .Objects ,_cef );return nil ;};func (_db *Catalog )NewOutputIntents ()*OutputIntents {return &OutputIntents {_ddf :_db ._d }};func (_fg *Document )AddStream (stream *_a .PdfObjectStream ){for _ ,_agd :=range _fg .Objects {if _agd ==stream {return ;
};};_fg .Objects =append (_fg .Objects ,stream );};func (_feg Page )GetResourcesXObject ()(*_a .PdfObjectDictionary ,bool ){_ecc ,_cdf :=_feg .GetResources ();if !_cdf {return nil ,false ;};return _a .GetDict (_ecc .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));
};func (_beg *Document )GetPages ()([]Page ,bool ){_dgb ,_cce :=_beg .FindCatalog ();if !_cce {return nil ,false ;};return _dgb .GetPages ();};func (_dg *Catalog )HasMetadata ()bool {_bg :=_dg .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061");
return _bg !=nil ;};func (_ab *Catalog )GetMetadata ()(*_a .PdfObjectStream ,bool ){_cbg ,_dd :=_a .GetStream (_ab .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"));return _cbg ,_dd ;};type ImageSMask struct{Image *Image ;Stream *_a .PdfObjectStream ;
};func (_fge Page )FindXObjectForms ()[]*_a .PdfObjectStream {_dfb ,_acd :=_fge .GetResourcesXObject ();if !_acd {return nil ;};_bec :=map[*_a .PdfObjectStream ]struct{}{};for _ ,_ccf :=range _dfb .Keys (){_bbg ,_edf :=_a .GetStream (_dfb .Get (_ccf ));
if !_edf {continue ;};if _ ,_aba :=_bec [_bbg ];_aba {continue ;};_aeg ,_ceec :=_a .GetName (_bbg .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));if !_ceec ||_aeg .String ()!="\u0046\u006f\u0072\u006d"{continue ;};_bec [_bbg ]=struct{}{};};var _fgeb []*_a .PdfObjectStream ;
for _fba :=range _bec {_fgeb =append (_fgeb ,_fba );};return _fgeb ;};type Page struct{_ca int ;Object *_a .PdfObjectDictionary ;_ddg *Document ;};func (_bef Page )GetResources ()(*_a .PdfObjectDictionary ,bool ){return _a .GetDict (_bef .Object .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));
};func (_adc *Document )FindCatalog ()(*Catalog ,bool ){var _bbd *_a .PdfObjectDictionary ;for _ ,_ed :=range _adc .Objects {_fbf ,_aee :=_a .GetDict (_ed );if !_aee {continue ;};if _bdg ,_agc :=_a .GetName (_fbf .Get ("\u0054\u0079\u0070\u0065"));_agc &&*_bdg =="\u0043a\u0074\u0061\u006c\u006f\u0067"{_bbd =_fbf ;
break ;};};if _bbd ==nil {return nil ,false ;};return &Catalog {Object :_bbd ,_d :_adc },true ;};func (_ec *OutputIntents )Len ()int {return _ec ._gc .Len ()};func (_fd *Catalog )GetPages ()([]Page ,bool ){_g ,_ad :=_a .GetDict (_fd .Object .Get ("\u0050\u0061\u0067e\u0073"));
if !_ad {return nil ,false ;};_dc ,_be :=_a .GetArray (_g .Get ("\u004b\u0069\u0064\u0073"));if !_be {return nil ,false ;};_ga :=make ([]Page ,_dc .Len ());for _gg ,_de :=range _dc .Elements (){_cb ,_cd :=_a .GetDict (_de );if !_cd {continue ;};_ga [_gg ]=Page {Object :_cb ,_ca :_gg +1,_ddg :_fd ._d };
};return _ga ,true ;};func (_dcb *Catalog )SetOutputIntents (outputIntents *OutputIntents ){if _fb :=_dcb .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073");_fb !=nil {for _ae ,_cf :=range _dcb ._d .Objects {if _cf ==_fb {if outputIntents ._bgf ==_fb {return ;
};_dcb ._d .Objects =append (_dcb ._d .Objects [:_ae ],_dcb ._d .Objects [_ae +1:]...);break ;};};};_gfd :=outputIntents ._bgf ;if _gfd ==nil {_gfd =_a .MakeIndirectObject (outputIntents ._gc );};_dcb .Object .Set ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073",_gfd );
_dcb ._d .Objects =append (_dcb ._d .Objects ,_gfd );};func (_gaf *Catalog )GetOutputIntents ()(*OutputIntents ,bool ){_bb :=_gaf .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073");if _bb ==nil {return nil ,false ;
};_ge ,_dbf :=_a .GetIndirect (_bb );if !_dbf {return nil ,false ;};_ba ,_e :=_a .GetArray (_ge .PdfObject );if !_e {return nil ,false ;};return &OutputIntents {_bgf :_ge ,_gc :_ba ,_ddf :_gaf ._d },true ;};