2022-07-13 21:28:43 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
2023-05-29 17:26:33 +00:00
|
|
|
package redactor ;import (_b "errors";_f "fmt";_cf "github.com/unidoc/unipdf/v3/common";_aa "github.com/unidoc/unipdf/v3/contentstream";_eb "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/creator";_ba "github.com/unidoc/unipdf/v3/extractor";
|
|
|
|
_gb "github.com/unidoc/unipdf/v3/model";_a "io";_c "regexp";_cg "sort";_bd "strings";);func _fd (_ad *_aa .ContentStreamOperations ,_be map[_eb .PdfObject ][]localSpanMarks )error {for _aag ,_d :=range _be {if _aag ==nil {continue ;};_cfa ,_bdf ,_fad :=_feg (_ad ,_aag );
|
|
|
|
if !_fad {_cf .Log .Debug ("Pd\u0066\u004fb\u006a\u0065\u0063\u0074\u0020\u0025\u0073\u006e\u006ft\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0069\u006e\u0020\u0073\u0069\u0064\u0065\u0020\u0074\u0068\u0065\u0020\u0063\u006f\u006e\u0074\u0065\u006e\u0074\u0073\u0074r\u0065a\u006d\u0020\u006f\u0070\u0065\u0072\u0061\u0074i\u006fn\u0020\u0025s",_aag ,_ad );
|
|
|
|
return nil ;};if _cfa .Operand =="\u0054\u006a"{_gbe :=_abc (_cfa ,_aag ,_d );if _gbe !=nil {return _gbe ;};}else if _cfa .Operand =="\u0054\u004a"{_ee :=_fed (_cfa ,_aag ,_d );if _ee !=nil {return _ee ;};}else if _cfa .Operand =="\u0027"||_cfa .Operand =="\u0022"{_fc :=_fe (_ad ,_cfa .Operand ,_bdf );
|
|
|
|
if _fc !=nil {return _fc ;};_fc =_abc (_cfa ,_aag ,_d );if _fc !=nil {return _fc ;};};};return nil ;};type localSpanMarks struct{_gaa *_ba .TextMarkArray ;_aga int ;_bfa string ;};func _fec (_cddc _eb .PdfObject ,_abeg *_gb .PdfFont )(string ,error ){_fcg ,_fegf :=_eb .GetStringBytes (_cddc );
|
|
|
|
if !_fegf {return "",_eb .ErrTypeError ;};_fcf :=_abeg .BytesToCharcodes (_fcg );_deeg ,_ddc ,_agf :=_abeg .CharcodesToStrings (_fcf );if _agf > 0{_cf .Log .Debug ("\u0072\u0065nd\u0065\u0072\u0054e\u0078\u0074\u003a\u0020num\u0043ha\u0072\u0073\u003d\u0025\u0064\u0020\u006eum\u004d\u0069\u0073\u0073\u0065\u0073\u003d%\u0064",_ddc ,_agf );
|
|
|
|
};_cga :=_bd .Join (_deeg ,"");return _cga ,nil ;};
|
2023-03-01 18:45:57 +00:00
|
|
|
|
2023-04-06 19:57:40 +00:00
|
|
|
// Redact executes the redact operation on a pdf file and updates the content streams of all pages of the file.
|
2023-05-29 17:26:33 +00:00
|
|
|
func (_bbca *Redactor )Redact ()error {_fcee ,_fdc :=_bbca ._eafd .GetNumPages ();if _fdc !=nil {return _f .Errorf ("\u0066\u0061\u0069\u006c\u0065\u0064 \u0074\u006f\u0020\u0067\u0065\u0074\u0020\u0074\u0068\u0065\u0020\u006e\u0075m\u0062\u0065\u0072\u0020\u006f\u0066\u0020P\u0061\u0067\u0065\u0073");
|
|
|
|
};_gae :=_bbca ._cgb .FillColor ;_acad :=_bbca ._cgb .BorderWidth ;_aacf :=_bbca ._cgb .FillOpacity ;for _cab :=1;_cab <=_fcee ;_cab ++{_bbf ,_ffbc :=_bbca ._eafd .GetPage (_cab );if _ffbc !=nil {return _ffbc ;};_bcbc ,_ffbc :=_ba .New (_bbf );if _ffbc !=nil {return _ffbc ;
|
|
|
|
};_afg ,_ ,_ ,_ffbc :=_bcbc .ExtractPageText ();if _ffbc !=nil {return _ffbc ;};_aceg :=_afg .GetContentStreamOps ();_eac ,_cee ,_ffbc :=_bbca .redactPage (_aceg ,_bbf .Resources );if _cee ==nil {_cf .Log .Info ("N\u006f\u0020\u006d\u0061\u0074\u0063\u0068\u0020\u0066\u006f\u0075\u006e\u0064\u0020\u0066\u006f\u0072\u0020t\u0068\u0065\u0020\u0070\u0072\u006f\u0076\u0069\u0064\u0065d \u0070\u0061\u0074t\u0061r\u006e\u002e");
|
|
|
|
_cee =_aceg ;};_bbf .SetContentStreams ([]string {_cee .String ()},_eb .NewFlateEncoder ());if _ffbc !=nil {return _ffbc ;};_eeaf ,_ffbc :=_bbf .GetMediaBox ();if _ffbc !=nil {return _ffbc ;};if _bbf .MediaBox ==nil {_bbf .MediaBox =_eeaf ;};if _gedc :=_bbca ._fcfd .AddPage (_bbf );
|
|
|
|
_gedc !=nil {return _gedc ;};_cfb :=_eeaf .Ury ;for _ ,_eefd :=range _eac {_cdfa :=_eefd ._dbb ;_ebg :=_bbca ._fcfd .NewRectangle (_cdfa .Llx ,_cfb -_cdfa .Lly ,_cdfa .Urx -_cdfa .Llx ,-(_cdfa .Ury -_cdfa .Lly ));_ebg .SetFillColor (_gae );_ebg .SetBorderWidth (_acad );
|
|
|
|
_ebg .SetFillOpacity (_aacf );if _bbfc :=_bbca ._fcfd .Draw (_ebg );_bbfc !=nil {return nil ;};};};_bbca ._fcfd .SetOutlineTree (_bbca ._eafd .GetOutlineTree ());return nil ;};
|
2023-03-01 18:45:57 +00:00
|
|
|
|
|
|
|
// RedactRectanglePropsNew return a new pointer to a default RectangleProps object.
|
2023-05-29 17:26:33 +00:00
|
|
|
func RedactRectanglePropsNew ()*RectangleProps {return &RectangleProps {FillColor :_e .ColorBlack ,BorderWidth :0.0,FillOpacity :1.0};};type placeHolders struct{_cgf []int ;_ea string ;_eaa float64 ;};func _fe (_ga *_aa .ContentStreamOperations ,_ac string ,_fb int )error {_cb :=_aa .ContentStreamOperations {};
|
|
|
|
var _eg _aa .ContentStreamOperation ;for _ebb ,_eba :=range *_ga {if _ebb ==_fb {if _ac =="\u0027"{_dg :=_aa .ContentStreamOperation {Operand :"\u0054\u002a"};_cb =append (_cb ,&_dg );_eg .Params =_eba .Params ;_eg .Operand ="\u0054\u006a";_cb =append (_cb ,&_eg );
|
|
|
|
}else if _ac =="\u0022"{_acg :=_eba .Params [:2];Tc ,Tw :=_acg [0],_acg [1];_gf :=_aa .ContentStreamOperation {Params :[]_eb .PdfObject {Tc },Operand :"\u0054\u0063"};_cb =append (_cb ,&_gf );_gf =_aa .ContentStreamOperation {Params :[]_eb .PdfObject {Tw },Operand :"\u0054\u0077"};
|
|
|
|
_cb =append (_cb ,&_gf );_eg .Params =[]_eb .PdfObject {_eba .Params [2]};_eg .Operand ="\u0054\u006a";_cb =append (_cb ,&_eg );};};_cb =append (_cb ,_eba );};*_ga =_cb ;return nil ;};func _cdea (_gcg []placeHolders )[]replacement {_abe :=[]replacement {};
|
|
|
|
for _ ,_bcd :=range _gcg {_bga :=_bcd ._cgf ;_efa :=_bcd ._ea ;_ace :=_bcd ._eaa ;for _ ,_ceae :=range _bga {_adg :=replacement {_fa :_efa ,_fac :_ace ,_bc :_ceae };_abe =append (_abe ,_adg );};};_cg .Slice (_abe ,func (_gcgb ,_geed int )bool {return _abe [_gcgb ]._bc < _abe [_geed ]._bc });
|
|
|
|
return _abe ;};
|
|
|
|
|
|
|
|
// RectangleProps defines properties of the redaction rectangle to be drawn.
|
|
|
|
type RectangleProps struct{FillColor _e .Color ;BorderWidth float64 ;FillOpacity float64 ;};func _cege (_gcb string ,_deac []replacement ,_bab *_gb .PdfFont )[]_eb .PdfObject {_deec :=[]_eb .PdfObject {};_bb :=0;_fadc :=_gcb ;for _ccee ,_cac :=range _deac {_gff :=_cac ._bc ;
|
|
|
|
_agc :=_cac ._fac ;_dga :=_cac ._fa ;_ggc :=_eb .MakeFloat (_agc );_efd :=_gcb [_bb :_gff ];_bbc :=_aba (_efd ,_bab );_aac :=_eb .MakeStringFromBytes (_bbc );_deec =append (_deec ,_aac );_deec =append (_deec ,_ggc );_bef :=_gff +len (_dga );_fadc =_gcb [_bef :];
|
|
|
|
_bb =_bef ;if _ccee ==len (_deac )-1{_bbc =_aba (_fadc ,_bab );_aac =_eb .MakeStringFromBytes (_bbc );_deec =append (_deec ,_aac );};};return _deec ;};type matchedBBox struct{_dbb _gb .PdfRectangle ;_gfg string ;};func _dee (_bdb *_gb .PdfFont ,_gfbd _ba .TextMark )float64 {_ddb :=0.001;
|
|
|
|
_ecb :=_gfbd .Th /100;if _bdb .Subtype ()=="\u0054\u0079\u0070e\u0033"{_ddb =1;};_bf ,_egc :=_bdb .GetRuneMetrics (' ');if !_egc {_bf ,_egc =_bdb .GetCharMetrics (32);};if !_egc {_bf ,_ =_gb .DefaultFont ().GetRuneMetrics (' ');};_ddd :=_ddb *((_bf .Wx *_gfbd .FontSize +_gfbd .Tc +_gfbd .Tw )/_ecb );
|
|
|
|
return _ddd ;};type regexMatcher struct{_cfc RedactionTerm };func _cccc (_ced RedactionTerm )(*regexMatcher ,error ){return ®exMatcher {_cfc :_ced },nil };func _eaf (_gbgg *_ba .TextMarkArray )(float64 ,error ){_bbg ,_aca :=_gbgg .BBox ();if !_aca {return 0.0,_f .Errorf ("\u0073\u0070\u0061\u006e\u004d\u0061\u0072\u006bs\u002e\u0042\u0042ox\u0020\u0068\u0061\u0073\u0020\u006eo\u0020\u0062\u006f\u0075\u006e\u0064\u0069\u006e\u0067\u0020\u0062\u006f\u0078\u002e\u0020s\u0070\u0061\u006e\u004d\u0061\u0072\u006b\u0073=\u0025\u0073",_gbgg );
|
|
|
|
};_dcb :=_cgg (_gbgg );_acaa :=0.0;_ ,_efdc :=_ce (_gbgg );_cgc :=_gbgg .Elements ()[_efdc ];_dgb :=_cgc .Font ;if _dcb > 0{_acaa =_dee (_dgb ,_cgc );};_aab :=(_bbg .Urx -_bbg .Llx );_aab =_aab +_acaa *float64 (_dcb );Tj :=_ega (_aab ,_cgc .FontSize ,_cgc .Th );
|
|
|
|
return Tj ,nil ;};func _dbd (_gfbb []localSpanMarks )(map[string ][]localSpanMarks ,[]string ){_ge :=make (map[string ][]localSpanMarks );_fdf :=[]string {};for _ ,_gdg :=range _gfbb {_edc :=_gdg ._bfa ;if _gdgd ,_ffb :=_ge [_edc ];_ffb {_ge [_edc ]=append (_gdgd ,_gdg );
|
|
|
|
}else {_ge [_edc ]=[]localSpanMarks {_gdg };_fdf =append (_fdf ,_edc );};};return _ge ,_fdf ;};
|
2022-07-13 21:28:43 +00:00
|
|
|
|
2023-04-06 19:57:40 +00:00
|
|
|
// RedactionTerm holds the regexp pattern and the replacement string for the redaction process.
|
2023-05-29 17:26:33 +00:00
|
|
|
type RedactionTerm struct{Pattern *_c .Regexp ;};func _eae (_agd []*matchedIndex )map[string ][][]int {_ebfb :=make (map[string ][][]int );for _ ,_abee :=range _agd {_dfdcf :=_abee ._gdf ;_dag :=[]int {_abee ._bae ,_abee ._afd };if _gbea ,_dbbb :=_ebfb [_dfdcf ];
|
|
|
|
_dbbb {_ebfb [_dfdcf ]=append (_gbea ,_dag );}else {_ebfb [_dfdcf ]=[][]int {_dag };};};return _ebfb ;};func _dbf (_fgae []int ,_egg *_ba .TextMarkArray ,_cdec string )(*_ba .TextMarkArray ,matchedBBox ,error ){_cffd :=matchedBBox {};_bdc :=_fgae [0];_edd :=_fgae [1];
|
|
|
|
_abd :=len (_cdec )-len (_bd .TrimLeft (_cdec ,"\u0020"));_deab :=len (_cdec )-len (_bd .TrimRight (_cdec ,"\u0020\u000a"));_bdc =_bdc +_abd ;_edd =_edd -_deab ;_cdec =_bd .Trim (_cdec ,"\u0020\u000a");_abab ,_ebag :=_egg .RangeOffset (_bdc ,_edd );if _ebag !=nil {return nil ,_cffd ,_ebag ;
|
|
|
|
};_abag ,_cfe :=_abab .BBox ();if !_cfe {return nil ,_cffd ,_f .Errorf ("\u0073\u0070\u0061\u006e\u004d\u0061\u0072\u006bs\u002e\u0042\u0042ox\u0020\u0068\u0061\u0073\u0020\u006eo\u0020\u0062\u006f\u0075\u006e\u0064\u0069\u006e\u0067\u0020\u0062\u006f\u0078\u002e\u0020s\u0070\u0061\u006e\u004d\u0061\u0072\u006b\u0073=\u0025\u0073",_abab );
|
|
|
|
};_cffd =matchedBBox {_gfg :_cdec ,_dbb :_abag };return _abab ,_cffd ,nil ;};func _fed (_eed *_aa .ContentStreamOperation ,_cbc _eb .PdfObject ,_fbf []localSpanMarks )error {_ag ,_cdg :=_eb .GetArray (_eed .Params [0]);_eab :=[]_eb .PdfObject {};if !_cdg {_cf .Log .Debug ("\u0045\u0052\u0052OR\u003a\u0020\u0054\u004a\u0020\u006f\u0070\u003d\u0025s\u0020G\u0065t\u0041r\u0072\u0061\u0079\u0056\u0061\u006c\u0020\u0066\u0061\u0069\u006c\u0065\u0064",_eed );
|
|
|
|
return _f .Errorf ("\u0073\u0070\u0061\u006e\u004d\u0061\u0072\u006bs\u002e\u0042\u0042ox\u0020\u0068\u0061\u0073\u0020\u006eo\u0020\u0062\u006f\u0075\u006e\u0064\u0069\u006e\u0067\u0020\u0062\u006f\u0078\u002e\u0020s\u0070\u0061\u006e\u004d\u0061\u0072\u006b\u0073=\u0025\u0073",_eed );
|
|
|
|
};_baf ,_acb :=_dbd (_fbf );if len (_acb )==1{_efe :=_acb [0];_gfb :=_baf [_efe ];if len (_gfb )==1{_ae :=_gfb [0];_ada :=_ae ._gaa ;_ab :=_fbff (_ada );_dea ,_df :=_fec (_cbc ,_ab );if _df !=nil {return _df ;};_cff ,_df :=_dgc (_ae ,_ada ,_ab ,_dea ,_efe );
|
|
|
|
if _df !=nil {return _df ;};for _ ,_ccc :=range _ag .Elements (){if _ccc ==_cbc {_eab =append (_eab ,_cff ...);}else {_eab =append (_eab ,_ccc );};};}else {_dd :=_gfb [0]._gaa ;_bcb :=_fbff (_dd );_cef ,_bac :=_fec (_cbc ,_bcb );if _bac !=nil {return _bac ;
|
|
|
|
};_db ,_bac :=_bddc (_cef ,_gfb );if _bac !=nil {return _bac ;};_bcf :=_cdea (_db );_efg :=_cege (_cef ,_bcf ,_bcb );for _ ,_ead :=range _ag .Elements (){if _ead ==_cbc {_eab =append (_eab ,_efg ...);}else {_eab =append (_eab ,_ead );};};};_eed .Params [0]=_eb .MakeArray (_eab ...);
|
|
|
|
}else if len (_acb )> 1{_cbf :=_fbf [0];_gd :=_cbf ._gaa ;_ ,_ec :=_ce (_gd );_fg :=_gd .Elements ()[_ec ];_dfd :=_fg .Font ;_ffc ,_deb :=_fec (_cbc ,_dfd );if _deb !=nil {return _deb ;};_bge ,_deb :=_bddc (_ffc ,_fbf );if _deb !=nil {return _deb ;};_egf :=_cdea (_bge );
|
|
|
|
_fce :=_cege (_ffc ,_egf ,_dfd );for _ ,_acc :=range _ag .Elements (){if _acc ==_cbc {_eab =append (_eab ,_fce ...);}else {_eab =append (_eab ,_acc );};};_eed .Params [0]=_eb .MakeArray (_eab ...);};return nil ;};
|
2022-09-23 18:05:51 +00:00
|
|
|
|
2023-04-06 19:57:40 +00:00
|
|
|
// Redactor represtents a Redactor object.
|
2023-05-29 17:26:33 +00:00
|
|
|
type Redactor struct{_eafd *_gb .PdfReader ;_fdeg *RedactionOptions ;_fcfd *_e .Creator ;_cgb *RectangleProps ;};
|
2023-01-08 22:34:27 +00:00
|
|
|
|
2023-04-06 19:57:40 +00:00
|
|
|
// Write writes the content of `re.creator` to writer of type io.Writer interface.
|
2023-05-29 17:26:33 +00:00
|
|
|
func (_gca *Redactor )Write (writer _a .Writer )error {return _gca ._fcfd .Write (writer )};func _afga (_cfeb *_ba .TextMarkArray ,_gdga int ,_cfgf int )int {_afc :=_cfeb .Elements ();_gaef :=_gdga -1;_gdc :=_gdga +1;_fgd :=-1;if _gaef >=0{_bdgf :=_afc [_gaef ];
|
|
|
|
_dfdc :=_bdgf .ObjString ;_cca :=len (_dfdc );_geacg :=_bdgf .Index ;if _geacg +1< _cca {_fgd =_gaef ;return _fgd ;};};if _gdc < len (_afc ){_debb :=_afc [_gdc ];_gdae :=_debb .ObjString ;if _gdae [0]!=_debb .Text {_fgd =_gdc ;return _fgd ;};};return _fgd ;
|
|
|
|
};func (_agab *Redactor )redactPage (_cfbc *_aa .ContentStreamOperations ,_gcc *_gb .PdfPageResources )([]matchedBBox ,*_aa .ContentStreamOperations ,error ){_daa ,_gaeb :=_ba .NewFromContents (_cfbc .String (),_gcc );if _gaeb !=nil {return nil ,nil ,_gaeb ;
|
|
|
|
};_cfd ,_ ,_ ,_gaeb :=_daa .ExtractPageText ();_cfbc =_cfd .GetContentStreamOps ();if _gaeb !=nil {return nil ,nil ,_gaeb ;};_cgca :=_cfd .Marks ();_fgfe :=_cfd .Text ();_bbce :=[]matchedBBox {};_gfbda :=make (map[_eb .PdfObject ][]localSpanMarks );for _ ,_gcd :=range _agab ._fdeg .Terms {_abg ,_acd :=_cccc (_gcd );
|
|
|
|
if _acd !=nil {return nil ,nil ,_acd ;};_egbf ,_acd :=_abg .match (_fgfe );if _acd !=nil {return nil ,nil ,_acd ;};_gda :=_eae (_egbf );for _bdga ,_abcd :=range _gda {_cgdb :=[]matchedBBox {};for _ ,_cceb :=range _abcd {_ccca ,_geac ,_acdg :=_dbf (_cceb ,_cgca ,_bdga );
|
|
|
|
if _acdg !=nil {return nil ,nil ,_acdg ;};_ccf :=_bed (_ccca );for _fge ,_fgbc :=range _ccf {_gdd :=localSpanMarks {_gaa :_fgbc ,_aga :_fge ,_bfa :_bdga };_dfdeg ,_ :=_ce (_fgbc );if _eca ,_deff :=_gfbda [_dfdeg ];_deff {_gfbda [_dfdeg ]=append (_eca ,_gdd );
|
|
|
|
}else {_gfbda [_dfdeg ]=[]localSpanMarks {_gdd };};};_cgdb =append (_cgdb ,_geac );};_bbce =append (_bbce ,_cgdb ...);};};_gaeb =_fd (_cfbc ,_gfbda );if _gaeb !=nil {return nil ,nil ,_gaeb ;};return _bbce ,_cfbc ,nil ;};func _bddc (_gbee string ,_cbe []localSpanMarks )([]placeHolders ,error ){_cae :="";
|
|
|
|
_cbca :=[]placeHolders {};for _cegaf ,_fea :=range _cbe {_fde :=_fea ._gaa ;_aee :=_fea ._bfa ;_acbc :=_bebe (_fde );_fdee ,_gad :=_eaf (_fde );if _gad !=nil {return nil ,_gad ;};if _acbc !=_cae {var _aea []int ;if _cegaf ==0&&_aee !=_acbc {_ged :=_bd .Index (_gbee ,_acbc );
|
|
|
|
_aea =[]int {_ged };}else if _cegaf ==len (_cbe )-1{_bfb :=_bd .LastIndex (_gbee ,_acbc );_aea =[]int {_bfb };}else {_aea =_baa (_gbee ,_acbc );};_fff :=placeHolders {_cgf :_aea ,_ea :_acbc ,_eaa :_fdee };_cbca =append (_cbca ,_fff );};_cae =_acbc ;};return _cbca ,nil ;
|
|
|
|
};
|
|
|
|
|
|
|
|
// RedactionOptions is a collection of RedactionTerm objects.
|
|
|
|
type RedactionOptions struct{Terms []RedactionTerm ;};
|
2023-03-01 18:45:57 +00:00
|
|
|
|
2023-04-06 19:57:40 +00:00
|
|
|
// WriteToFile writes the redacted document to file specified by `outputPath`.
|
2023-05-29 17:26:33 +00:00
|
|
|
func (_efb *Redactor )WriteToFile (outputPath string )error {if _abaf :=_efb ._fcfd .WriteToFile (outputPath );_abaf !=nil {return _f .Errorf ("\u0066\u0061\u0069l\u0065\u0064\u0020\u0074o\u0020\u0077\u0072\u0069\u0074\u0065\u0020t\u0068\u0065\u0020\u006f\u0075\u0074\u0070\u0075\u0074\u0020\u0066\u0069\u006c\u0065");
|
|
|
|
};return nil ;};func _ega (_fade ,_ggd ,_agg float64 )float64 {_agg =_agg /100;_ddg :=(-1000*_fade )/(_ggd *_agg );return _ddg ;};
|
|
|
|
|
|
|
|
// New instantiates a Redactor object with given PdfReader and `regex` pattern.
|
|
|
|
func New (reader *_gb .PdfReader ,opts *RedactionOptions ,rectProps *RectangleProps )*Redactor {if rectProps ==nil {rectProps =RedactRectanglePropsNew ();};return &Redactor {_eafd :reader ,_fdeg :opts ,_fcfd :_e .New (),_cgb :rectProps };};func _baa (_gbeb ,_cfg string )[]int {if len (_cfg )==0{return nil ;
|
|
|
|
};var _efde []int ;for _agfd :=0;_agfd < len (_gbeb );{_eec :=_bd .Index (_gbeb [_agfd :],_cfg );if _eec < 0{return _efde ;};_efde =append (_efde ,_agfd +_eec );_agfd +=_eec +len (_cfg );};return _efde ;};func _aba (_ed string ,_eda *_gb .PdfFont )[]byte {_dgd ,_cced :=_eda .StringToCharcodeBytes (_ed );
|
|
|
|
if _cced !=0{_cf .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0073\u006fm\u0065\u0020\u0072un\u0065\u0073\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u0065\u006e\u0063\u006f\u0064\u0065d\u002e\u000a\u0009\u0025\u0073\u0020\u002d\u003e \u0025\u0076",_ed ,_dgd );
|
|
|
|
};return _dgd ;};func _fbff (_ebd *_ba .TextMarkArray )*_gb .PdfFont {_ ,_edae :=_ce (_ebd );_cea :=_ebd .Elements ()[_edae ];_eaad :=_cea .Font ;return _eaad ;};func _dgc (_cffa localSpanMarks ,_ceg *_ba .TextMarkArray ,_bdd *_gb .PdfFont ,_bfd ,_egb string )([]_eb .PdfObject ,error ){_fbeb :=_bebe (_ceg );
|
|
|
|
Tj ,_aeb :=_eaf (_ceg );if _aeb !=nil {return nil ,_aeb ;};_dff :=len (_bfd );_edg :=len (_fbeb );_fcc :=-1;_cega :=_eb .MakeFloat (Tj );if _fbeb !=_egb {_adag :=_cffa ._aga ;if _adag ==0{_fcc =_bd .LastIndex (_bfd ,_fbeb );}else {_fcc =_bd .Index (_bfd ,_fbeb );
|
|
|
|
};}else {_fcc =_bd .Index (_bfd ,_fbeb );};_eff :=_fcc +_edg ;_gdb :=[]_eb .PdfObject {};if _fcc ==0&&_eff ==_dff {_gdb =append (_gdb ,_cega );}else if _fcc ==0&&_eff < _dff {_aede :=_aba (_bfd [_eff :],_bdd );_bfc :=_eb .MakeStringFromBytes (_aede );_gdb =append (_gdb ,_cega ,_bfc );
|
|
|
|
}else if _fcc > 0&&_eff >=_dff {_dc :=_aba (_bfd [:_fcc ],_bdd );_bee :=_eb .MakeStringFromBytes (_dc );_gdb =append (_gdb ,_bee ,_cega );}else if _fcc > 0&&_eff < _dff {_faa :=_aba (_bfd [:_fcc ],_bdd );_gc :=_aba (_bfd [_eff :],_bdd );_gga :=_eb .MakeStringFromBytes (_faa );
|
|
|
|
_fccb :=_eb .MakeString (string (_gc ));_gdb =append (_gdb ,_gga ,_cega ,_fccb );};return _gdb ,nil ;};func _ce (_ef *_ba .TextMarkArray )(_eb .PdfObject ,int ){var _cc _eb .PdfObject ;_cdf :=-1;for _de ,_gbg :=range _ef .Elements (){_cc =_gbg .DirectObject ;
|
|
|
|
_cdf =_de ;if _cc !=nil {break ;};};return _cc ,_cdf ;};func _bebe (_ccd *_ba .TextMarkArray )string {_cda :="";for _ ,_ecc :=range _ccd .Elements (){_cda +=_ecc .Text ;};return _cda ;};type replacement struct{_fa string ;_fac float64 ;_bc int ;};func _cgg (_ff *_ba .TextMarkArray )int {_bg :=0;
|
|
|
|
_cd :=_ff .Elements ();if _cd [0].Text =="\u0020"{_bg ++;};if _cd [_ff .Len ()-1].Text =="\u0020"{_bg ++;};return _bg ;};func _feg (_bff *_aa .ContentStreamOperations ,PdfObj _eb .PdfObject )(*_aa .ContentStreamOperation ,int ,bool ){for _bdg ,_bdda :=range *_bff {_abce :=_bdda .Operand ;
|
|
|
|
if _abce =="\u0054\u006a"{_cdd :=_eb .TraceToDirectObject (_bdda .Params [0]);if _cdd ==PdfObj {return _bdda ,_bdg ,true ;};}else if _abce =="\u0054\u004a"{_geeb ,_eafc :=_eb .GetArray (_bdda .Params [0]);if !_eafc {return nil ,_bdg ,_eafc ;};for _ ,_cad :=range _geeb .Elements (){if _cad ==PdfObj {return _bdda ,_bdg ,true ;
|
|
|
|
};};}else if _abce =="\u0022"{_fgf :=_eb .TraceToDirectObject (_bdda .Params [2]);if _fgf ==PdfObj {return _bdda ,_bdg ,true ;};}else if _abce =="\u0027"{_af :=_eb .TraceToDirectObject (_bdda .Params [0]);if _af ==PdfObj {return _bdda ,_bdg ,true ;};};
|
|
|
|
};return nil ,-1,false ;};func _abc (_fbe *_aa .ContentStreamOperation ,_aeg _eb .PdfObject ,_adb []localSpanMarks )error {var _abcb *_eb .PdfObjectArray ;_agb ,_fbc :=_dbd (_adb );if len (_fbc )==1{_cceda :=_fbc [0];_gg :=_agb [_cceda ];if len (_gg )==1{_eea :=_gg [0];
|
|
|
|
_fbcd :=_eea ._gaa ;_ffca :=_fbff (_fbcd );_da ,_cde :=_fec (_aeg ,_ffca );if _cde !=nil {return _cde ;};_fgb ,_cde :=_dgc (_eea ,_fbcd ,_ffca ,_da ,_cceda );if _cde !=nil {return _cde ;};_abcb =_eb .MakeArray (_fgb ...);}else {_cgd :=_gg [0]._gaa ;_ffe :=_fbff (_cgd );
|
|
|
|
_gfbbf ,_beg :=_fec (_aeg ,_ffe );if _beg !=nil {return _beg ;};_fgg ,_beg :=_bddc (_gfbbf ,_gg );if _beg !=nil {return _beg ;};_ca :=_cdea (_fgg );_dfde :=_cege (_gfbbf ,_ca ,_ffe );_abcb =_eb .MakeArray (_dfde ...);};}else if len (_fbc )> 1{_fbg :=_adb [0];
|
|
|
|
_fggg :=_fbg ._gaa ;_ ,_begg :=_ce (_fggg );_ebf :=_fggg .Elements ()[_begg ];_edag :=_ebf .Font ;_bgd ,_gea :=_fec (_aeg ,_edag );if _gea !=nil {return _gea ;};_beb ,_gea :=_bddc (_bgd ,_adb );if _gea !=nil {return _gea ;};_gee :=_cdea (_beb );_fgggc :=_cege (_bgd ,_gee ,_edag );
|
|
|
|
_abcb =_eb .MakeArray (_fgggc ...);};_fbe .Params [0]=_abcb ;_fbe .Operand ="\u0054\u004a";return nil ;};type matchedIndex struct{_bae int ;_afd int ;_gdf string ;};func (_fbd *regexMatcher )match (_gdgde string )([]*matchedIndex ,error ){_afa :=_fbd ._cfc .Pattern ;
|
|
|
|
if _afa ==nil {return nil ,_b .New ("\u006e\u006f\u0020\u0070at\u0074\u0065\u0072\u006e\u0020\u0063\u006f\u006d\u0070\u0069\u006c\u0065\u0064");};var (_dab =_afa .FindAllStringIndex (_gdgde ,-1);_eacc []*matchedIndex ;);for _ ,_bca :=range _dab {_eacc =append (_eacc ,&matchedIndex {_bae :_bca [0],_afd :_bca [1],_gdf :_gdgde [_bca [0]:_bca [1]]});
|
|
|
|
};return _eacc ,nil ;};func _bed (_fdeeg *_ba .TextMarkArray )[]*_ba .TextMarkArray {_gbf :=_fdeeg .Elements ();_fdd :=len (_gbf );var _fbbd _eb .PdfObject ;_ggg :=[]*_ba .TextMarkArray {};_ede :=&_ba .TextMarkArray {};_ebda :=-1;for _ece ,_cabg :=range _gbf {_eaff :=_cabg .DirectObject ;
|
|
|
|
_ebda =_cabg .Index ;if _eaff ==nil {_gfc :=_afga (_fdeeg ,_ece ,_ebda );if _fbbd !=nil {if _gfc ==-1||_gfc > _ece {_ggg =append (_ggg ,_ede );_ede =&_ba .TextMarkArray {};};};}else if _eaff !=nil &&_fbbd ==nil {if _ebda ==0&&_ece > 0{_ggg =append (_ggg ,_ede );
|
|
|
|
_ede =&_ba .TextMarkArray {};};}else if _eaff !=nil &&_fbbd !=nil {if _eaff !=_fbbd {_ggg =append (_ggg ,_ede );_ede =&_ba .TextMarkArray {};};};_fbbd =_eaff ;_ede .Append (_cabg );if _ece ==(_fdd -1){_ggg =append (_ggg ,_ede );};};return _ggg ;};
|