2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
|
|
|
//
|
|
|
|
// This is a commercial product and requires a license to operate.
|
|
|
|
// A trial license can be obtained at https://unidoc.io
|
|
|
|
//
|
|
|
|
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
|
|
|
//
|
|
|
|
// Use of this source code is governed by the UniDoc End User License Agreement
|
|
|
|
// terms that can be accessed at https://unidoc.io/eula/
|
|
|
|
|
|
|
|
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
|
|
|
|
// for PDF function type 4.
|
|
|
|
//
|
|
|
|
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
|
|
|
|
// for PDF function type 4.
|
2021-04-17 13:46:54 +00:00
|
|
|
package ps ;import (_bc "bufio";_e "bytes";_f "errors";_a "fmt";_ad "github.com/unidoc/unipdf/v3/common";_d "github.com/unidoc/unipdf/v3/core";_c "io";_ba "math";);
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-04-06 22:35:37 +00:00
|
|
|
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
|
2021-04-17 13:46:54 +00:00
|
|
|
func (_g *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_df :=range objects {_ec :=_g .Stack .Push (_df );if _ec !=nil {return nil ,_ec ;};};_gf :=_g ._fb .Exec (_g .Stack );if _gf !=nil {_ad .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_gf );
|
|
|
|
return nil ,_gf ;};_ea :=[]PSObject (*_g .Stack );_g .Stack .Empty ();return _ea ,nil ;};func (_fbga *PSParser )skipSpaces ()(int ,error ){_eab :=0;for {_gef ,_decf :=_fbga ._afe .Peek (1);if _decf !=nil {return 0,_decf ;};if _d .IsWhiteSpace (_gef [0]){_fbga ._afe .ReadByte ();
|
|
|
|
_eab ++;}else {break ;};};return _eab ,nil ;};const _ef =0.000001;func (_ecg *PSProgram )DebugString ()string {_eb :="\u007b\u0020";for _ ,_ffe :=range *_ecg {_eb +=_ffe .DebugString ();_eb +="\u0020";};_eb +="\u007d";return _eb ;};func (_gfaf *PSOperand )ne (_cdf *PSStack )error {_ggd :=_gfaf .eq (_cdf );
|
|
|
|
if _ggd !=nil {return _ggd ;};_ggd =_gfaf .not (_cdf );return _ggd ;};func (_afb *PSOperand )neg (_dga *PSStack )error {_gcec ,_afbe :=_dga .Pop ();if _afbe !=nil {return _afbe ;};if _bfgf ,_agcf :=_gcec .(*PSReal );_agcf {_afbe =_dga .Push (MakeReal (-_bfgf .Val ));
|
|
|
|
return _afbe ;}else if _cbde ,_eee :=_gcec .(*PSInteger );_eee {_afbe =_dga .Push (MakeInteger (-_cbde .Val ));return _afbe ;}else {return ErrTypeCheck ;};};
|
|
|
|
|
|
|
|
// MakeInteger returns a new PSInteger object initialized with `val`.
|
|
|
|
func MakeInteger (val int )*PSInteger {_gadf :=PSInteger {};_gadf .Val =val ;return &_gadf };
|
|
|
|
|
|
|
|
// MakeReal returns a new PSReal object initialized with `val`.
|
|
|
|
func MakeReal (val float64 )*PSReal {_fed :=PSReal {};_fed .Val =val ;return &_fed };func (_ded *PSOperand )roll (_bfc *PSStack )error {_bccc ,_eaf :=_bfc .Pop ();if _eaf !=nil {return _eaf ;};_ggb ,_eaf :=_bfc .Pop ();if _eaf !=nil {return _eaf ;};_bcab ,_aebc :=_bccc .(*PSInteger );
|
|
|
|
if !_aebc {return ErrTypeCheck ;};_bgdb ,_aebc :=_ggb .(*PSInteger );if !_aebc {return ErrTypeCheck ;};if _bgdb .Val < 0{return ErrRangeCheck ;};if _bgdb .Val ==0||_bgdb .Val ==1{return nil ;};if _bgdb .Val > len (*_bfc ){return ErrStackUnderflow ;};for _gac :=0;
|
|
|
|
_gac < _bgcc (_bcab .Val );_gac ++{var _ccf []PSObject ;_ccf =(*_bfc )[len (*_bfc )-(_bgdb .Val ):len (*_bfc )];if _bcab .Val > 0{_ebc :=_ccf [len (_ccf )-1];_ccf =append ([]PSObject {_ebc },_ccf [0:len (_ccf )-1]...);}else {_eaef :=_ccf [len (_ccf )-_bgdb .Val ];
|
|
|
|
_ccf =append (_ccf [1:],_eaef );};_fdfa :=append ((*_bfc )[0:len (*_bfc )-_bgdb .Val ],_ccf ...);_bfc =&_fdfa ;};return nil ;};func (_eeac *PSOperand )pop (_eaea *PSStack )error {_ ,_bcdc :=_eaea .Pop ();if _bcdc !=nil {return _bcdc ;};return nil ;};func (_dc *PSReal )Duplicate ()PSObject {_gcb :=PSReal {};
|
|
|
|
_gcb .Val =_dc .Val ;return &_gcb };func (_bccf *PSOperand )ln (_gdac *PSStack )error {_cgdf ,_caec :=_gdac .PopNumberAsFloat64 ();if _caec !=nil {return _caec ;};_deg :=_ba .Log (_cgdf );_caec =_gdac .Push (MakeReal (_deg ));return _caec ;};func (_adde *PSOperand )not (_geac *PSStack )error {_bdff ,_efe :=_geac .Pop ();
|
|
|
|
if _efe !=nil {return _efe ;};if _efge ,_ccd :=_bdff .(*PSBoolean );_ccd {_efe =_geac .Push (MakeBool (!_efge .Val ));return _efe ;}else if _ffbb ,_bcca :=_bdff .(*PSInteger );_bcca {_efe =_geac .Push (MakeInteger (^_ffbb .Val ));return _efe ;}else {return ErrTypeCheck ;
|
|
|
|
};};func (_gd *PSInteger )String ()string {return _a .Sprintf ("\u0025\u0064",_gd .Val )};func (_cbgd *PSOperand )cos (_cbe *PSStack )error {_beb ,_bdd :=_cbe .PopNumberAsFloat64 ();if _bdd !=nil {return _bdd ;};_adc :=_ba .Cos (_beb *_ba .Pi /180.0);_bdd =_cbe .Push (MakeReal (_adc ));
|
|
|
|
return _bdd ;};func (_aece *PSParser )parseFunction ()(*PSProgram ,error ){_bbcd ,_ :=_aece ._afe .ReadByte ();if _bbcd !='{'{return nil ,_f .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_aagb :=NewPSProgram ();
|
|
|
|
for {_aece .skipSpaces ();_fddb ,_fcbc :=_aece ._afe .Peek (2);if _fcbc !=nil {if _fcbc ==_c .EOF {break ;};return nil ,_fcbc ;};_ad .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_fddb ));if _fddb [0]=='}'{_ad .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");
|
|
|
|
_aece ._afe .ReadByte ();break ;}else if _fddb [0]=='{'{_ad .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_afeg ,_efgf :=_aece .parseFunction ();if _efgf !=nil {return nil ,_efgf ;};_aagb .Append (_afeg );}else if _d .IsDecimalDigit (_fddb [0])||(_fddb [0]=='-'&&_d .IsDecimalDigit (_fddb [1])){_ad .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");
|
|
|
|
_dccg ,_agd :=_aece .parseNumber ();if _agd !=nil {return nil ,_agd ;};_aagb .Append (_dccg );}else {_ad .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_fddb ,_ =_aece ._afe .Peek (5);_egcf :=string (_fddb );
|
|
|
|
_ad .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_egcf );if (len (_egcf )> 4)&&(_egcf [:5]=="\u0066\u0061\u006cs\u0065"){_bbdc ,_deag :=_aece .parseBool ();if _deag !=nil {return nil ,_deag ;};_aagb .Append (_bbdc );
|
|
|
|
}else if (len (_egcf )> 3)&&(_egcf [:4]=="\u0074\u0072\u0075\u0065"){_ecd ,_cbbd :=_aece .parseBool ();if _cbbd !=nil {return nil ,_cbbd ;};_aagb .Append (_ecd );}else {_dcd ,_cga :=_aece .parseOperand ();if _cga !=nil {return nil ,_cga ;};_aagb .Append (_dcd );
|
|
|
|
};};};return _aagb ,nil ;};
|
|
|
|
|
|
|
|
// PSObjectArrayToFloat64Array converts []PSObject into a []float64 array. Each PSObject must represent a number,
|
|
|
|
// otherwise a ErrTypeCheck error occurs.
|
|
|
|
func PSObjectArrayToFloat64Array (objects []PSObject )([]float64 ,error ){var _aa []float64 ;for _ ,_ff :=range objects {if _fa ,_aag :=_ff .(*PSInteger );_aag {_aa =append (_aa ,float64 (_fa .Val ));}else if _ag ,_bg :=_ff .(*PSReal );_bg {_aa =append (_aa ,_ag .Val );
|
|
|
|
}else {return nil ,ErrTypeCheck ;};};return _aa ,nil ;};func (_ed *PSOperand )atan (_beae *PSStack )error {_dfdg ,_egb :=_beae .PopNumberAsFloat64 ();if _egb !=nil {return _egb ;};_bdf ,_egb :=_beae .PopNumberAsFloat64 ();if _egb !=nil {return _egb ;};
|
|
|
|
if _dfdg ==0{var _agcg error ;if _bdf < 0{_agcg =_beae .Push (MakeReal (270));}else {_agcg =_beae .Push (MakeReal (90));};return _agcg ;};_gdg :=_bdf /_dfdg ;_ffc :=_ba .Atan (_gdg )*180/_ba .Pi ;_egb =_beae .Push (MakeReal (_ffc ));return _egb ;};func (_ge *PSReal )DebugString ()string {return _a .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_ge .Val );
|
|
|
|
};func (_bgc *PSOperand )DebugString ()string {return _a .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_bgc );};func (_ffb *PSOperand )cvi (_dfda *PSStack )error {_gfgc ,_fcce :=_dfda .Pop ();if _fcce !=nil {return _fcce ;};if _abd ,_faa :=_gfgc .(*PSReal );
|
|
|
|
_faa {_cca :=int (_abd .Val );_fcce =_dfda .Push (MakeInteger (_cca ));}else if _abed ,_agg :=_gfgc .(*PSInteger );_agg {_eef :=_abed .Val ;_fcce =_dfda .Push (MakeInteger (_eef ));}else {return ErrTypeCheck ;};return _fcce ;};func (_faf *PSProgram )String ()string {_fg :="\u007b\u0020";
|
|
|
|
for _ ,_db :=range *_faf {_fg +=_db .String ();_fg +="\u0020";};_fg +="\u007d";return _fg ;};func (_cbg *PSOperand )bitshift (_efg *PSStack )error {_gfb ,_eegd :=_efg .PopInteger ();if _eegd !=nil {return _eegd ;};_cbd ,_eegd :=_efg .PopInteger ();if _eegd !=nil {return _eegd ;
|
|
|
|
};var _ecc int ;if _gfb >=0{_ecc =_cbd <<uint (_gfb );}else {_ecc =_cbd >>uint (-_gfb );};_eegd =_efg .Push (MakeInteger (_ecc ));return _eegd ;};
|
|
|
|
|
|
|
|
// Exec executes the operand `op` in the state specified by `stack`.
|
|
|
|
func (_gdf *PSOperand )Exec (stack *PSStack )error {_bda :=ErrUnsupportedOperand ;switch *_gdf {case "\u0061\u0062\u0073":_bda =_gdf .abs (stack );case "\u0061\u0064\u0064":_bda =_gdf .add (stack );case "\u0061\u006e\u0064":_bda =_gdf .and (stack );case "\u0061\u0074\u0061\u006e":_bda =_gdf .atan (stack );
|
|
|
|
case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_bda =_gdf .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_bda =_gdf .ceiling (stack );case "\u0063\u006f\u0070\u0079":_bda =_gdf .copy (stack );case "\u0063\u006f\u0073":_bda =_gdf .cos (stack );
|
|
|
|
case "\u0063\u0076\u0069":_bda =_gdf .cvi (stack );case "\u0063\u0076\u0072":_bda =_gdf .cvr (stack );case "\u0064\u0069\u0076":_bda =_gdf .div (stack );case "\u0064\u0075\u0070":_bda =_gdf .dup (stack );case "\u0065\u0071":_bda =_gdf .eq (stack );case "\u0065\u0078\u0063\u0068":_bda =_gdf .exch (stack );
|
|
|
|
case "\u0065\u0078\u0070":_bda =_gdf .exp (stack );case "\u0066\u006c\u006fo\u0072":_bda =_gdf .floor (stack );case "\u0067\u0065":_bda =_gdf .ge (stack );case "\u0067\u0074":_bda =_gdf .gt (stack );case "\u0069\u0064\u0069\u0076":_bda =_gdf .idiv (stack );
|
|
|
|
case "\u0069\u0066":_bda =_gdf .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_bda =_gdf .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_bda =_gdf .index (stack );case "\u006c\u0065":_bda =_gdf .le (stack );case "\u006c\u006f\u0067":_bda =_gdf .log (stack );
|
|
|
|
case "\u006c\u006e":_bda =_gdf .ln (stack );case "\u006c\u0074":_bda =_gdf .lt (stack );case "\u006d\u006f\u0064":_bda =_gdf .mod (stack );case "\u006d\u0075\u006c":_bda =_gdf .mul (stack );case "\u006e\u0065":_bda =_gdf .ne (stack );case "\u006e\u0065\u0067":_bda =_gdf .neg (stack );
|
|
|
|
case "\u006e\u006f\u0074":_bda =_gdf .not (stack );case "\u006f\u0072":_bda =_gdf .or (stack );case "\u0070\u006f\u0070":_bda =_gdf .pop (stack );case "\u0072\u006f\u0075n\u0064":_bda =_gdf .round (stack );case "\u0072\u006f\u006c\u006c":_bda =_gdf .roll (stack );
|
|
|
|
case "\u0073\u0069\u006e":_bda =_gdf .sin (stack );case "\u0073\u0071\u0072\u0074":_bda =_gdf .sqrt (stack );case "\u0073\u0075\u0062":_bda =_gdf .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_bda =_gdf .truncate (stack );case "\u0078\u006f\u0072":_bda =_gdf .xor (stack );
|
|
|
|
};return _bda ;};
|
|
|
|
|
|
|
|
// Exec executes the program, typically leaving output values on the stack.
|
|
|
|
func (_af *PSProgram )Exec (stack *PSStack )error {for _ ,_fc :=range *_af {var _dbe error ;switch _ae :=_fc .(type ){case *PSInteger :_dbd :=_ae ;_dbe =stack .Push (_dbd );case *PSReal :_fbb :=_ae ;_dbe =stack .Push (_fbb );case *PSBoolean :_bd :=_ae ;
|
|
|
|
_dbe =stack .Push (_bd );case *PSProgram :_gg :=_ae ;_dbe =stack .Push (_gg );case *PSOperand :_gcc :=_ae ;_dbe =_gcc .Exec (stack );default:return ErrTypeCheck ;};if _dbe !=nil {return _dbe ;};};return nil ;};func (_cdfe *PSOperand )round (_fbge *PSStack )error {_aeb ,_deac :=_fbge .Pop ();
|
|
|
|
if _deac !=nil {return _deac ;};if _dbeg ,_ggdf :=_aeb .(*PSReal );_ggdf {_deac =_fbge .Push (MakeReal (_ba .Floor (_dbeg .Val +0.5)));}else if _bcda ,_debg :=_aeb .(*PSInteger );_debg {_deac =_fbge .Push (MakeInteger (_bcda .Val ));}else {return ErrTypeCheck ;
|
|
|
|
};return _deac ;};func (_gfe *PSOperand )div (_ccc *PSStack )error {_bcg ,_ebe :=_ccc .Pop ();if _ebe !=nil {return _ebe ;};_fd ,_ebe :=_ccc .Pop ();if _ebe !=nil {return _ebe ;};_dbdc ,_dac :=_bcg .(*PSReal );_bfge ,_fdf :=_bcg .(*PSInteger );if !_dac &&!_fdf {return ErrTypeCheck ;
|
|
|
|
};if _dac &&_dbdc .Val ==0{return ErrUndefinedResult ;};if _fdf &&_bfge .Val ==0{return ErrUndefinedResult ;};_ebfg ,_fdd :=_fd .(*PSReal );_gbe ,_egc :=_fd .(*PSInteger );if !_fdd &&!_egc {return ErrTypeCheck ;};var _gdga float64 ;if _fdd {_gdga =_ebfg .Val ;
|
|
|
|
}else {_gdga =float64 (_gbe .Val );};if _dac {_gdga /=_dbdc .Val ;}else {_gdga /=float64 (_bfge .Val );};_ebe =_ccc .Push (MakeReal (_gdga ));return _ebe ;};func (_abe *PSOperand )and (_bgd *PSStack )error {_gba ,_dff :=_bgd .Pop ();if _dff !=nil {return _dff ;
|
|
|
|
};_dfd ,_dff :=_bgd .Pop ();if _dff !=nil {return _dff ;};if _bgdc ,_gea :=_gba .(*PSBoolean );_gea {_agc ,_ebd :=_dfd .(*PSBoolean );if !_ebd {return ErrTypeCheck ;};_dff =_bgd .Push (MakeBool (_bgdc .Val &&_agc .Val ));return _dff ;};if _fba ,_eed :=_gba .(*PSInteger );
|
|
|
|
_eed {_dae ,_gdc :=_dfd .(*PSInteger );if !_gdc {return ErrTypeCheck ;};_dff =_bgd .Push (MakeInteger (_fba .Val &_dae .Val ));return _dff ;};return ErrTypeCheck ;};func (_acb *PSOperand )add (_bfg *PSStack )error {_ddg ,_cg :=_bfg .Pop ();if _cg !=nil {return _cg ;
|
|
|
|
};_adg ,_cg :=_bfg .Pop ();if _cg !=nil {return _cg ;};_fbgd ,_fcc :=_ddg .(*PSReal );_dfe ,_eaa :=_ddg .(*PSInteger );if !_fcc &&!_eaa {return ErrTypeCheck ;};_eff ,_dg :=_adg .(*PSReal );_gfa ,_eg :=_adg .(*PSInteger );if !_dg &&!_eg {return ErrTypeCheck ;
|
|
|
|
};if _eaa &&_eg {_gebb :=_dfe .Val +_gfa .Val ;_eeg :=_bfg .Push (MakeInteger (_gebb ));return _eeg ;};var _dee float64 ;if _fcc {_dee =_fbgd .Val ;}else {_dee =float64 (_dfe .Val );};if _dg {_dee +=_eff .Val ;}else {_dee +=float64 (_gfa .Val );};_cg =_bfg .Push (MakeReal (_dee ));
|
|
|
|
return _cg ;};
|
|
|
|
|
|
|
|
// PSInteger represents an integer.
|
|
|
|
type PSInteger struct{Val int ;};
|
2020-09-07 00:23:12 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// PSBoolean represents a boolean value.
|
2021-04-17 13:46:54 +00:00
|
|
|
type PSBoolean struct{Val bool ;};
|
|
|
|
|
|
|
|
// PSParser is a basic Postscript parser.
|
|
|
|
type PSParser struct{_afe *_bc .Reader };func (_eda *PSOperand )idiv (_dec *PSStack )error {_fbad ,_fddc :=_dec .Pop ();if _fddc !=nil {return _fddc ;};_fee ,_fddc :=_dec .Pop ();if _fddc !=nil {return _fddc ;};_eccb ,_eac :=_fbad .(*PSInteger );if !_eac {return ErrTypeCheck ;
|
|
|
|
};if _eccb .Val ==0{return ErrUndefinedResult ;};_aga ,_eac :=_fee .(*PSInteger );if !_eac {return ErrTypeCheck ;};_eca :=_aga .Val /_eccb .Val ;_fddc =_dec .Push (MakeInteger (_eca ));return _fddc ;};
|
|
|
|
|
|
|
|
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
|
|
|
|
type PSStack []PSObject ;func (_gad *PSOperand )sub (_fbgc *PSStack )error {_faaa ,_gafg :=_fbgc .Pop ();if _gafg !=nil {return _gafg ;};_fad ,_gafg :=_fbgc .Pop ();if _gafg !=nil {return _gafg ;};_gabe ,_bgac :=_faaa .(*PSReal );_dgc ,_aagg :=_faaa .(*PSInteger );
|
|
|
|
if !_bgac &&!_aagg {return ErrTypeCheck ;};_dbcg ,_fdea :=_fad .(*PSReal );_aecd ,_ggae :=_fad .(*PSInteger );if !_fdea &&!_ggae {return ErrTypeCheck ;};if _aagg &&_ggae {_acec :=_aecd .Val -_dgc .Val ;_dgf :=_fbgc .Push (MakeInteger (_acec ));return _dgf ;
|
|
|
|
};var _gaea float64 =0;if _fdea {_gaea =_dbcg .Val ;}else {_gaea =float64 (_aecd .Val );};if _bgac {_gaea -=_gabe .Val ;}else {_gaea -=float64 (_dgc .Val );};_gafg =_fbgc .Push (MakeReal (_gaea ));return _gafg ;};func (_gag *PSOperand )ceiling (_dgb *PSStack )error {_ce ,_dbef :=_dgb .Pop ();
|
|
|
|
if _dbef !=nil {return _dbef ;};if _gdd ,_cgg :=_ce .(*PSReal );_cgg {_dbef =_dgb .Push (MakeReal (_ba .Ceil (_gdd .Val )));}else if _adb ,_dbc :=_ce .(*PSInteger );_dbc {_dbef =_dgb .Push (MakeInteger (_adb .Val ));}else {_dbef =ErrTypeCheck ;};return _dbef ;
|
|
|
|
};func (_ee *PSBoolean )DebugString ()string {return _a .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_ee .Val );};var ErrUndefinedResult =_f .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");
|
|
|
|
|
|
|
|
|
|
|
|
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
|
|
|
|
// Real or integer only.
|
|
|
|
func (_bfea *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_fegf ,_cdff :=_bfea .Pop ();if _cdff !=nil {return 0,_cdff ;};if _aab ,_bdb :=_fegf .(*PSReal );_bdb {return _aab .Val ,nil ;}else if _ecf ,_fffd :=_fegf .(*PSInteger );_fffd {return float64 (_ecf .Val ),nil ;
|
|
|
|
}else {return 0,ErrTypeCheck ;};};func (_fge *PSOperand )exch (_fga *PSStack )error {_cbc ,_gab :=_fga .Pop ();if _gab !=nil {return _gab ;};_ffeb ,_gab :=_fga .Pop ();if _gab !=nil {return _gab ;};_gab =_fga .Push (_cbc );if _gab !=nil {return _gab ;};
|
|
|
|
_gab =_fga .Push (_ffeb );return _gab ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// Append appends an object to the PSProgram.
|
|
|
|
func (_efa *PSProgram )Append (obj PSObject ){*_efa =append (*_efa ,obj )};
|
|
|
|
|
|
|
|
// PSOperand represents a Postscript operand (text string).
|
|
|
|
type PSOperand string ;func (_dag *PSOperand )Duplicate ()PSObject {_geb :=*_dag ;return &_geb };
|
|
|
|
|
|
|
|
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
|
|
|
|
func NewPSExecutor (program *PSProgram )*PSExecutor {_fbg :=&PSExecutor {};_fbg .Stack =NewPSStack ();_fbg ._fb =program ;return _fbg ;};func (_aaf *PSOperand )ifCondition (_aec *PSStack )error {_bcf ,_gff :=_aec .Pop ();if _gff !=nil {return _gff ;};_agca ,_gff :=_aec .Pop ();
|
|
|
|
if _gff !=nil {return _gff ;};_fcf ,_fcb :=_bcf .(*PSProgram );if !_fcb {return ErrTypeCheck ;};_dbg ,_fcb :=_agca .(*PSBoolean );if !_fcb {return ErrTypeCheck ;};if _dbg .Val {_acc :=_fcf .Exec (_aec );return _acc ;};return nil ;};
|
|
|
|
|
|
|
|
// DebugString returns a descriptive string representation of the stack - intended for debugging.
|
|
|
|
func (_fbd *PSStack )DebugString ()string {_ffcf :="\u005b\u0020";for _ ,_ffea :=range *_fbd {_ffcf +=_ffea .DebugString ();_ffcf +="\u0020";};_ffcf +="\u005d";return _ffcf ;};func (_efd *PSOperand )lt (_debd *PSStack )error {_efb ,_ebb :=_debd .PopNumberAsFloat64 ();
|
|
|
|
if _ebb !=nil {return _ebb ;};_bed ,_ebb :=_debd .PopNumberAsFloat64 ();if _ebb !=nil {return _ebb ;};if _ba .Abs (_bed -_efb )< _ef {_ccb :=_debd .Push (MakeBool (false ));return _ccb ;}else if _bed < _efb {_cfb :=_debd .Push (MakeBool (true ));return _cfb ;
|
|
|
|
}else {_fcg :=_debd .Push (MakeBool (false ));return _fcg ;};};
|
2021-02-22 02:29:48 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// PSObject represents a postscript object.
|
|
|
|
type PSObject interface{
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// Duplicate makes a fresh copy of the PSObject.
|
|
|
|
Duplicate ()PSObject ;
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// DebugString returns a descriptive representation of the PSObject with more information than String()
|
|
|
|
// for debugging purposes.
|
|
|
|
DebugString ()string ;
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-03-23 23:12:52 +00:00
|
|
|
// String returns a string representation of the PSObject.
|
2021-04-17 13:46:54 +00:00
|
|
|
String ()string ;};func (_be *PSReal )String ()string {return _a .Sprintf ("\u0025\u002e\u0035\u0066",_be .Val )};func (_cbdf *PSOperand )index (_bae *PSStack )error {_gaf ,_efc :=_bae .Pop ();if _efc !=nil {return _efc ;};_cccb ,_accf :=_gaf .(*PSInteger );
|
|
|
|
if !_accf {return ErrTypeCheck ;};if _cccb .Val < 0{return ErrRangeCheck ;};if _cccb .Val > len (*_bae )-1{return ErrStackUnderflow ;};_babc :=(*_bae )[len (*_bae )-1-_cccb .Val ];_efc =_bae .Push (_babc .Duplicate ());return _efc ;};
|
2020-11-11 18:48:37 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// Empty empties the stack.
|
|
|
|
func (_bfe *PSStack )Empty (){*_bfe =[]PSObject {}};func (_edc *PSOperand )sqrt (_cge *PSStack )error {_facg ,_edad :=_cge .PopNumberAsFloat64 ();if _edad !=nil {return _edad ;};if _facg < 0{return ErrRangeCheck ;};_afg :=_ba .Sqrt (_facg );_edad =_cge .Push (MakeReal (_afg ));
|
|
|
|
return _edad ;};func (_add *PSOperand )dup (_aba *PSStack )error {_bfd ,_fde :=_aba .Pop ();if _fde !=nil {return _fde ;};_fde =_aba .Push (_bfd );if _fde !=nil {return _fde ;};_fde =_aba .Push (_bfd .Duplicate ());return _fde ;};func _bgcc (_cba int )int {if _cba < 0{return -_cba ;
|
|
|
|
};return _cba ;};func (_bbd *PSOperand )log (_cbgg *PSStack )error {_aagc ,_fcd :=_cbgg .PopNumberAsFloat64 ();if _fcd !=nil {return _fcd ;};_gfgd :=_ba .Log10 (_aagc );_fcd =_cbgg .Push (MakeReal (_gfgd ));return _fcd ;};func (_edbb *PSOperand )gt (_ffbd *PSStack )error {_fdg ,_ffee :=_ffbd .PopNumberAsFloat64 ();
|
|
|
|
if _ffee !=nil {return _ffee ;};_aaa ,_ffee :=_ffbd .PopNumberAsFloat64 ();if _ffee !=nil {return _ffee ;};if _ba .Abs (_aaa -_fdg )< _ef {_aegb :=_ffbd .Push (MakeBool (false ));return _aegb ;}else if _aaa > _fdg {_dgdd :=_ffbd .Push (MakeBool (true ));
|
|
|
|
return _dgdd ;}else {_ega :=_ffbd .Push (MakeBool (false ));return _ega ;};};var ErrUnsupportedOperand =_f .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_cc *PSProgram )Duplicate ()PSObject {_ab :=&PSProgram {};
|
|
|
|
for _ ,_ace :=range *_cc {_ab .Append (_ace .Duplicate ());};return _ab ;};func (_bcgg *PSParser )parseNumber ()(PSObject ,error ){_abbb ,_gdge :=_d .ParseNumber (_bcgg ._afe );if _gdge !=nil {return nil ,_gdge ;};switch _gaa :=_abbb .(type ){case *_d .PdfObjectFloat :return MakeReal (float64 (*_gaa )),nil ;
|
|
|
|
case *_d .PdfObjectInteger :return MakeInteger (int (*_gaa )),nil ;};return nil ,_a .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_abbb );};func (_gfg *PSInteger )DebugString ()string {return _a .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_gfg .Val );
|
|
|
|
};func (_debf *PSOperand )exp (_bce *PSStack )error {_bcgb ,_bcc :=_bce .PopNumberAsFloat64 ();if _bcc !=nil {return _bcc ;};_dge ,_bcc :=_bce .PopNumberAsFloat64 ();if _bcc !=nil {return _bcc ;};if _ba .Abs (_bcgb )< 1&&_dge < 0{return ErrUndefinedResult ;
|
|
|
|
};_agcc :=_ba .Pow (_dge ,_bcgb );_bcc =_bce .Push (MakeReal (_agcc ));return _bcc ;};func (_adgb *PSOperand )sin (_deef *PSStack )error {_ecab ,_fdcc :=_deef .PopNumberAsFloat64 ();if _fdcc !=nil {return _fdcc ;};_fgac :=_ba .Sin (_ecab *_ba .Pi /180.0);
|
|
|
|
_fdcc =_deef .Push (MakeReal (_fgac ));return _fdcc ;};func (_gcg *PSOperand )ge (_gcce *PSStack )error {_bab ,_bb :=_gcce .PopNumberAsFloat64 ();if _bb !=nil {return _bb ;};_agf ,_bb :=_gcce .PopNumberAsFloat64 ();if _bb !=nil {return _bb ;};if _ba .Abs (_agf -_bab )< _ef {_edbf :=_gcce .Push (MakeBool (true ));
|
|
|
|
return _edbf ;}else if _agf > _bab {_caa :=_gcce .Push (MakeBool (true ));return _caa ;}else {_ecgb :=_gcce .Push (MakeBool (false ));return _ecgb ;};};func (_aac *PSOperand )xor (_fef *PSStack )error {_gafd ,_dbcgf :=_fef .Pop ();if _dbcgf !=nil {return _dbcgf ;
|
|
|
|
};_dfef ,_dbcgf :=_fef .Pop ();if _dbcgf !=nil {return _dbcgf ;};if _ggc ,_ead :=_gafd .(*PSBoolean );_ead {_gfc ,_gdcf :=_dfef .(*PSBoolean );if !_gdcf {return ErrTypeCheck ;};_dbcgf =_fef .Push (MakeBool (_ggc .Val !=_gfc .Val ));return _dbcgf ;};if _abaa ,_gced :=_gafd .(*PSInteger );
|
|
|
|
_gced {_ddge ,_fab :=_dfef .(*PSInteger );if !_fab {return ErrTypeCheck ;};_dbcgf =_fef .Push (MakeInteger (_abaa .Val ^_ddge .Val ));return _dbcgf ;};return ErrTypeCheck ;};
|
2020-10-12 14:17:59 +00:00
|
|
|
|
2021-04-06 22:35:37 +00:00
|
|
|
// NewPSProgram returns an empty, initialized PSProgram.
|
2021-04-17 13:46:54 +00:00
|
|
|
func NewPSProgram ()*PSProgram {return &PSProgram {}};
|
2020-09-28 23:18:17 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
|
|
|
|
func NewPSParser (content []byte )*PSParser {_bebe :=PSParser {};_dagc :=_e .NewBuffer (content );_bebe ._afe =_bc .NewReader (_dagc );return &_bebe ;};
|
2021-04-06 22:35:37 +00:00
|
|
|
|
|
|
|
// Parse parses the postscript and store as a program that can be executed.
|
2021-04-17 13:46:54 +00:00
|
|
|
func (_ebcc *PSParser )Parse ()(*PSProgram ,error ){_ebcc .skipSpaces ();_abeg ,_dgea :=_ebcc ._afe .Peek (2);if _dgea !=nil {return nil ,_dgea ;};if _abeg [0]!='{'{return nil ,_f .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0053\u0020\u0050\u0072\u006f\u0067\u0072\u0061\u006d\u0020\u006e\u006f\u0074\u0020\u0073t\u0061\u0072\u0074\u0069\u006eg\u0020\u0077i\u0074\u0068\u0020\u007b");
|
|
|
|
};_beag ,_dgea :=_ebcc .parseFunction ();if _dgea !=nil &&_dgea !=_c .EOF {return nil ,_dgea ;};return _beag ,_dgea ;};func (_afa *PSOperand )le (_gabc *PSStack )error {_eae ,_daa :=_gabc .PopNumberAsFloat64 ();if _daa !=nil {return _daa ;};_fff ,_daa :=_gabc .PopNumberAsFloat64 ();
|
|
|
|
if _daa !=nil {return _daa ;};if _ba .Abs (_fff -_eae )< _ef {_edd :=_gabc .Push (MakeBool (true ));return _edd ;}else if _fff < _eae {_fgcba :=_gabc .Push (MakeBool (true ));return _fgcba ;}else {_gda :=_gabc .Push (MakeBool (false ));return _gda ;};};
|
2021-02-11 10:35:13 +00:00
|
|
|
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
|
|
|
|
type PSProgram []PSObject ;var ErrTypeCheck =_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");func (_dcc *PSOperand )eq (_fbaf *PSStack )error {_fac ,_fgc :=_fbaf .Pop ();if _fgc !=nil {return _fgc ;};_cgd ,_fgc :=_fbaf .Pop ();
|
|
|
|
if _fgc !=nil {return _fgc ;};_fag ,_gfgcc :=_fac .(*PSBoolean );_bcga ,_gce :=_cgd .(*PSBoolean );if _gfgcc ||_gce {var _dad error ;if _gfgcc &&_gce {_dad =_fbaf .Push (MakeBool (_fag .Val ==_bcga .Val ));}else {_dad =_fbaf .Push (MakeBool (false ));};
|
|
|
|
return _dad ;};var _aeg float64 ;var _feg float64 ;if _dgd ,_bfb :=_fac .(*PSInteger );_bfb {_aeg =float64 (_dgd .Val );}else if _dgg ,_cee :=_fac .(*PSReal );_cee {_aeg =_dgg .Val ;}else {return ErrTypeCheck ;};if _gbf ,_eea :=_cgd .(*PSInteger );_eea {_feg =float64 (_gbf .Val );
|
|
|
|
}else if _cab ,_dbfa :=_cgd .(*PSReal );_dbfa {_feg =_cab .Val ;}else {return ErrTypeCheck ;};if _ba .Abs (_feg -_aeg )< _ef {_fgc =_fbaf .Push (MakeBool (true ));}else {_fgc =_fbaf .Push (MakeBool (false ));};return _fgc ;};func (_fgb *PSOperand )mod (_agga *PSStack )error {_fdc ,_eede :=_agga .Pop ();
|
|
|
|
if _eede !=nil {return _eede ;};_bcd ,_eede :=_agga .Pop ();if _eede !=nil {return _eede ;};_ffa ,_aef :=_fdc .(*PSInteger );if !_aef {return ErrTypeCheck ;};if _ffa .Val ==0{return ErrUndefinedResult ;};_dbca ,_aef :=_bcd .(*PSInteger );if !_aef {return ErrTypeCheck ;
|
|
|
|
};_ebdc :=_dbca .Val %_ffa .Val ;_eede =_agga .Push (MakeInteger (_ebdc ));return _eede ;};func (_bga *PSOperand )or (_eaad *PSStack )error {_daeb ,_afc :=_eaad .Pop ();if _afc !=nil {return _afc ;};_eefg ,_afc :=_eaad .Pop ();if _afc !=nil {return _afc ;
|
|
|
|
};if _eddd ,_fdcg :=_daeb .(*PSBoolean );_fdcg {_egfd ,_cce :=_eefg .(*PSBoolean );if !_cce {return ErrTypeCheck ;};_afc =_eaad .Push (MakeBool (_eddd .Val ||_egfd .Val ));return _afc ;};if _dgdg ,_gae :=_daeb .(*PSInteger );_gae {_gdb ,_eacg :=_eefg .(*PSInteger );
|
|
|
|
if !_eacg {return ErrTypeCheck ;};_afc =_eaad .Push (MakeInteger (_dgdg .Val |_gdb .Val ));return _afc ;};return ErrTypeCheck ;};func (_cbb *PSOperand )cvr (_dea *PSStack )error {_bfa ,_ebf :=_dea .Pop ();if _ebf !=nil {return _ebf ;};if _gcf ,_gbag :=_bfa .(*PSReal );
|
|
|
|
_gbag {_ebf =_dea .Push (MakeReal (_gcf .Val ));}else if _ffd ,_edb :=_bfa .(*PSInteger );_edb {_ebf =_dea .Push (MakeReal (float64 (_ffd .Val )));}else {return ErrTypeCheck ;};return _ebf ;};func (_gcba *PSOperand )String ()string {return string (*_gcba )};
|
2020-10-19 10:58:10 +00:00
|
|
|
|
2021-04-06 22:35:37 +00:00
|
|
|
|
|
|
|
// MakeOperand returns a new PSOperand object based on string `val`.
|
2021-04-17 13:46:54 +00:00
|
|
|
func MakeOperand (val string )*PSOperand {_cbeg :=PSOperand (val );return &_cbeg };func (_cad *PSParser )parseOperand ()(*PSOperand ,error ){var _egfa []byte ;for {_deae ,_bcdb :=_cad ._afe .Peek (1);if _bcdb !=nil {if _bcdb ==_c .EOF {break ;};return nil ,_bcdb ;
|
|
|
|
};if _d .IsDelimiter (_deae [0]){break ;};if _d .IsWhiteSpace (_deae [0]){break ;};_cdcg ,_ :=_cad ._afe .ReadByte ();_egfa =append (_egfa ,_cdcg );};if len (_egfa )==0{return nil ,_f .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064\u0020\u0028\u0065\u006d\u0070\u0074\u0079\u0029");
|
|
|
|
};return MakeOperand (string (_egfa )),nil ;};func (_gc *PSInteger )Duplicate ()PSObject {_bca :=PSInteger {};_bca .Val =_gc .Val ;return &_bca };var ErrRangeCheck =_f .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");
|
2020-10-19 10:58:10 +00:00
|
|
|
|
2021-03-13 21:28:23 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// String returns a string representation of the stack.
|
|
|
|
func (_ddgf *PSStack )String ()string {_gaca :="\u005b\u0020";for _ ,_daae :=range *_ddgf {_gaca +=_daae .String ();_gaca +="\u0020";};_gaca +="\u005d";return _gaca ;};func (_egf *PSOperand )mul (_eba *PSStack )error {_ddd ,_egcc :=_eba .Pop ();if _egcc !=nil {return _egcc ;
|
|
|
|
};_gga ,_egcc :=_eba .Pop ();if _egcc !=nil {return _egcc ;};_fcfc ,_eaac :=_ddd .(*PSReal );_cdb ,_gdag :=_ddd .(*PSInteger );if !_eaac &&!_gdag {return ErrTypeCheck ;};_gge ,_dce :=_gga .(*PSReal );_caeb ,_dbab :=_gga .(*PSInteger );if !_dce &&!_dbab {return ErrTypeCheck ;
|
|
|
|
};if _gdag &&_dbab {_ffg :=_cdb .Val *_caeb .Val ;_ggea :=_eba .Push (MakeInteger (_ffg ));return _ggea ;};var _cgdg float64 ;if _eaac {_cgdg =_fcfc .Val ;}else {_cgdg =float64 (_cdb .Val );};if _dce {_cgdg *=_gge .Val ;}else {_cgdg *=float64 (_caeb .Val );
|
|
|
|
};_egcc =_eba .Push (MakeReal (_cgdg ));return _egcc ;};
|
2021-03-23 23:12:52 +00:00
|
|
|
|
|
|
|
// NewPSStack returns an initialized PSStack.
|
2021-04-06 22:35:37 +00:00
|
|
|
func NewPSStack ()*PSStack {return &PSStack {}};
|
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
|
|
|
|
type PSExecutor struct{Stack *PSStack ;_fb *PSProgram ;};func (_ga *PSBoolean )Duplicate ()PSObject {_bea :=PSBoolean {};_bea .Val =_ga .Val ;return &_bea };func (_ebfge *PSOperand )floor (_cf *PSStack )error {_cd ,_abf :=_cf .Pop ();if _abf !=nil {return _abf ;
|
|
|
|
};if _ceeb ,_cae :=_cd .(*PSReal );_cae {_abf =_cf .Push (MakeReal (_ba .Floor (_ceeb .Val )));}else if _def ,_fgf :=_cd .(*PSInteger );_fgf {_abf =_cf .Push (MakeInteger (_def .Val ));}else {return ErrTypeCheck ;};return _abf ;};func (_cb *PSBoolean )String ()string {return _a .Sprintf ("\u0025\u0076",_cb .Val )};
|
2021-04-06 22:35:37 +00:00
|
|
|
|
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
|
|
|
|
func (_edf *PSStack )PopInteger ()(int ,error ){_deeb ,_abbc :=_edf .Pop ();if _abbc !=nil {return 0,_abbc ;};if _fda ,_gggd :=_deeb .(*PSInteger );_gggd {return _fda .Val ,nil ;};return 0,ErrTypeCheck ;};func (_ece *PSOperand )abs (_daf *PSStack )error {_ca ,_age :=_daf .Pop ();
|
|
|
|
if _age !=nil {return _age ;};if _dd ,_de :=_ca .(*PSReal );_de {_bf :=_dd .Val ;if _bf < 0{_age =_daf .Push (MakeReal (-_bf ));}else {_age =_daf .Push (MakeReal (_bf ));};}else if _aed ,_bac :=_ca .(*PSInteger );_bac {_deb :=_aed .Val ;if _deb < 0{_age =_daf .Push (MakeInteger (-_deb ));
|
|
|
|
}else {_age =_daf .Push (MakeInteger (_deb ));};}else {return ErrTypeCheck ;};return _age ;};func (_fgg *PSOperand )truncate (_ebg *PSStack )error {_dde ,_fbf :=_ebg .Pop ();if _fbf !=nil {return _fbf ;};if _eag ,_cgge :=_dde .(*PSReal );_cgge {_gfga :=int (_eag .Val );
|
|
|
|
_fbf =_ebg .Push (MakeReal (float64 (_gfga )));}else if _bcdad ,_ebfb :=_dde .(*PSInteger );_ebfb {_fbf =_ebg .Push (MakeInteger (_bcdad .Val ));}else {return ErrTypeCheck ;};return _fbf ;};var ErrStackOverflow =_f .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");
|
2021-04-06 22:35:37 +00:00
|
|
|
|
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// Pop pops an object from the top of the stack.
|
|
|
|
func (_bdg *PSStack )Pop ()(PSObject ,error ){if len (*_bdg )< 1{return nil ,ErrStackUnderflow ;};_cdea :=(*_bdg )[len (*_bdg )-1];*_bdg =(*_bdg )[0:len (*_bdg )-1];return _cdea ,nil ;};
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// MakeBool returns a new PSBoolean object initialized with `val`.
|
|
|
|
func MakeBool (val bool )*PSBoolean {_addc :=PSBoolean {};_addc .Val =val ;return &_addc };var ErrStackUnderflow =_f .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");
|
2021-04-06 22:35:37 +00:00
|
|
|
|
2021-04-17 13:46:54 +00:00
|
|
|
// Push pushes an object on top of the stack.
|
|
|
|
func (_fage *PSStack )Push (obj PSObject )error {if len (*_fage )> 100{return ErrStackOverflow ;};*_fage =append (*_fage ,obj );return nil ;};
|
|
|
|
|
|
|
|
// PSReal represents a real number.
|
|
|
|
type PSReal struct{Val float64 ;};func (_dbec *PSOperand )copy (_dcg *PSStack )error {_abb ,_dbf :=_dcg .PopInteger ();if _dbf !=nil {return _dbf ;};if _abb < 0{return ErrRangeCheck ;};if _abb > len (*_dcg ){return ErrRangeCheck ;};*_dcg =append (*_dcg ,(*_dcg )[len (*_dcg )-_abb :]...);
|
|
|
|
return nil ;};func (_cde *PSOperand )ifelse (_ggg *PSStack )error {_dca ,_fgcb :=_ggg .Pop ();if _fgcb !=nil {return _fgcb ;};_gec ,_fgcb :=_ggg .Pop ();if _fgcb !=nil {return _fgcb ;};_cdc ,_fgcb :=_ggg .Pop ();if _fgcb !=nil {return _fgcb ;};_bbg ,_dggd :=_dca .(*PSProgram );
|
|
|
|
if !_dggd {return ErrTypeCheck ;};_bbc ,_dggd :=_gec .(*PSProgram );if !_dggd {return ErrTypeCheck ;};_bddc ,_dggd :=_cdc .(*PSBoolean );if !_dggd {return ErrTypeCheck ;};if _bddc .Val {_fce :=_bbc .Exec (_ggg );return _fce ;};_fgcb =_bbg .Exec (_ggg );
|
|
|
|
return _fgcb ;};func (_eaeb *PSParser )parseBool ()(*PSBoolean ,error ){_agcd ,_dcb :=_eaeb ._afe .Peek (4);if _dcb !=nil {return MakeBool (false ),_dcb ;};if (len (_agcd )>=4)&&(string (_agcd [:4])=="\u0074\u0072\u0075\u0065"){_eaeb ._afe .Discard (4);
|
|
|
|
return MakeBool (true ),nil ;};_agcd ,_dcb =_eaeb ._afe .Peek (5);if _dcb !=nil {return MakeBool (false ),_dcb ;};if (len (_agcd )>=5)&&(string (_agcd [:5])=="\u0066\u0061\u006cs\u0065"){_eaeb ._afe .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_f .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");
|
|
|
|
};
|