Merge pull request #408 from unidoc-build/prep-rc-v3.11.0

Prepare release UniPDF v3.11.0
This commit is contained in:
Gunnsteinn Hall 2020-09-07 12:04:04 +00:00 committed by GitHub
commit 16b59e59af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 5592 additions and 5475 deletions

File diff suppressed because one or more lines are too long

View File

@ -10,93 +10,93 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package common contains common properties used by the subpackages.
package common ;import (_d "fmt";_ge "io";_a "os";_c "path/filepath";_g "runtime";_db "time";);
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};
// LogLevel is the verbosity level for logging.
type LogLevel int ;
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_da ConsoleLogger )IsLogLevel (level LogLevel )bool {return _da .LogLevel >=level };
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// Debug logs debug message.
func (_aba ConsoleLogger )Debug (format string ,args ...interface{}){if _aba .LogLevel >=LogLevelDebug {_bg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_aba .output (_a .Stdout ,_bg ,format ,args ...);};};const _fe =2020;func (_dae WriterLogger )logToWriter (_fa _ge .Writer ,_ffa string ,_efg string ,_dd ...interface{}){_fd (_fa ,_ffa ,_efg ,_dd );};
// Error logs error message.
func (_gg WriterLogger )Error (format string ,args ...interface{}){if _gg .LogLevel >=LogLevelError {_dca :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gg .logToWriter (_gg .Output ,_dca ,format ,args ...);};};
// Warning logs warning message.
func (_ab ConsoleLogger )Warning (format string ,args ...interface{}){if _ab .LogLevel >=LogLevelWarning {_gd :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ab .output (_a .Stdout ,_gd ,format ,args ...);};};func UtcTimeFormat (t _db .Time )string {return t .Format (_gdaa )+"\u0020\u0055\u0054\u0043"};const _eeb =8;const _gdaa ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Notice logs notice message.
func (_cec WriterLogger )Notice (format string ,args ...interface{}){if _cec .LogLevel >=LogLevelNotice {_de :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_cec .logToWriter (_cec .Output ,_de ,format ,args ...);};};
// Notice logs notice message.
func (_ae ConsoleLogger )Notice (format string ,args ...interface{}){if _ae .LogLevel >=LogLevelNotice {_ee :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ae .output (_a .Stdout ,_ee ,format ,args ...);};};
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
// Trace logs trace message.
func (_gda ConsoleLogger )Trace (format string ,args ...interface{}){if _gda .LogLevel >=LogLevelTrace {_af :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gda .output (_a .Stdout ,_af ,format ,args ...);};};
// Warning logs warning message.
func (_efe WriterLogger )Warning (format string ,args ...interface{}){if _efe .LogLevel >=LogLevelWarning {_bb :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_efe .logToWriter (_efe .Output ,_bb ,format ,args ...);};};
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_gf string ,_f ...interface{});Warning (_b string ,_cf ...interface{});Notice (_ce string ,_bd ...interface{});Info (_df string ,_geg ...interface{});Debug (_gc string ,_ef ...interface{});Trace (_cef string ,_ff ...interface{});IsLogLevel (_dc LogLevel )bool ;};const _gecd =31;
// Info logs info message.
func (_bc ConsoleLogger )Info (format string ,args ...interface{}){if _bc .LogLevel >=LogLevelInfo {_aa :="\u005bI\u004e\u0046\u004f\u005d\u0020";_bc .output (_a .Stdout ,_aa ,format ,args ...);};};
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _ge .Writer )*WriterLogger {_fb :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_fb ;};func (_eec ConsoleLogger )output (_ad _ge .Writer ,_dab string ,_fg string ,_aff ...interface{}){_fd (_ad ,_dab ,_fg ,_aff ...);};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_ea WriterLogger )IsLogLevel (level LogLevel )bool {return _ea .LogLevel >=level };const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);const _eg =50;const Version ="\u0033\u002e\u0031\u0030\u002e\u0031";
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};var Log Logger =DummyLogger {};
// DummyLogger does nothing.
type DummyLogger struct{};const _cae =18;
// Trace logs trace message.
func (_gec WriterLogger )Trace (format string ,args ...interface{}){if _gec .LogLevel >=LogLevelTrace {_fc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gec .logToWriter (_gec .Output ,_fc ,format ,args ...);};};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
// Error logs error message.
func (_ca ConsoleLogger )Error (format string ,args ...interface{}){if _ca .LogLevel >=LogLevelError {_cg :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ca .output (_a .Stdout ,_cg ,format ,args ...);};};
package common ;import (_a "fmt";_aa "io";_dc "os";_d "path/filepath";_f "runtime";_bg "time";);const _bgg ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};func _fd (_ccf _ge .Writer ,_bgb string ,_fag string ,_gcc ...interface{}){_ ,_cd ,_ffd ,_dac :=_g .Caller (3);if !_dac {_cd ="\u003f\u003f\u003f";_ffd =0;}else {_cd =_c .Base (_cd );};_fcc :=_d .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bgb ,_cd ,_ffd )+_fag +"\u000a";_d .Fprintf (_ccf ,_fcc ,_gcc ...);};
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};
// Info logs info message.
func (_bba WriterLogger )Info (format string ,args ...interface{}){if _bba .LogLevel >=LogLevelInfo {_cc :="\u005bI\u004e\u0046\u004f\u005d\u0020";_bba .logToWriter (_bba .Output ,_cc ,format ,args ...);};};
// Warning logs warning message.
func (_bfc ConsoleLogger )Warning (format string ,args ...interface{}){if _bfc .LogLevel >=LogLevelWarning {_af :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_bfc .output (_dc .Stdout ,_af ,format ,args ...);};};
// WriterLogger is the logger that writes data to the Output writer
type WriterLogger struct{LogLevel LogLevel ;Output _ge .Writer ;};var ReleasedAt =_db .Date (_fe ,_eeb ,_gecd ,_cae ,_eg ,0,0,_db .UTC );
type WriterLogger struct{LogLevel LogLevel ;Output _aa .Writer ;};
// LogLevel is the verbosity level for logging.
type LogLevel int ;
// Debug logs debug message.
func (_cb ConsoleLogger )Debug (format string ,args ...interface{}){if _cb .LogLevel >=LogLevelDebug {_edg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_cb .output (_dc .Stdout ,_edg ,format ,args ...);};};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// Error logs error message.
func (_ea ConsoleLogger )Error (format string ,args ...interface{}){if _ea .LogLevel >=LogLevelError {_bb :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ea .output (_dc .Stdout ,_bb ,format ,args ...);};};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
// Info logs info message.
func (_ff ConsoleLogger )Info (format string ,args ...interface{}){if _ff .LogLevel >=LogLevelInfo {_ca :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ff .output (_dc .Stdout ,_ca ,format ,args ...);};};const _gecb =18;
// Trace logs trace message.
func (_gf ConsoleLogger )Trace (format string ,args ...interface{}){if _gf .LogLevel >=LogLevelTrace {_dcc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gf .output (_dc .Stdout ,_dcc ,format ,args ...);};};
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_afa WriterLogger )IsLogLevel (level LogLevel )bool {return _afa .LogLevel >=level };
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};
// Notice logs notice message.
func (_ed ConsoleLogger )Notice (format string ,args ...interface{}){if _ed .LogLevel >=LogLevelNotice {_fg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ed .output (_dc .Stdout ,_fg ,format ,args ...);};};
// Debug logs debug message.
func (_bfca WriterLogger )Debug (format string ,args ...interface{}){if _bfca .LogLevel >=LogLevelDebug {_de :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_bfca .logToWriter (_bfca .Output ,_de ,format ,args ...);};};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const _cbee =9;
// Notice logs notice message.
func (_ac WriterLogger )Notice (format string ,args ...interface{}){if _ac .LogLevel >=LogLevelNotice {_dgf :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ac .logToWriter (_ac .Output ,_dgf ,format ,args ...);};};func (_cc ConsoleLogger )output (_dg _aa .Writer ,_fa string ,_gde string ,_agge ...interface{}){_fad (_dg ,_fa ,_gde ,_agge ...);};
// Trace logs trace message.
func (_ee WriterLogger )Trace (format string ,args ...interface{}){if _ee .LogLevel >=LogLevelTrace {_ggc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ee .logToWriter (_ee .Output ,_ggc ,format ,args ...);};};
// Warning logs warning message.
func (_cg WriterLogger )Warning (format string ,args ...interface{}){if _cg .LogLevel >=LogLevelWarning {_ge :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_cg .logToWriter (_cg .Output ,_ge ,format ,args ...);};};
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_ba string ,_e ...interface{});Warning (_ag string ,_g ...interface{});Notice (_c string ,_cd ...interface{});Info (_agg string ,_gd ...interface{});Debug (_bc string ,_gdd ...interface{});Trace (_dcf string ,_bf ...interface{});IsLogLevel (_bfd LogLevel )bool ;};
// Error logs error message.
func (_ead WriterLogger )Error (format string ,args ...interface{}){if _ead .LogLevel >=LogLevelError {_be :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ead .logToWriter (_ead .Output ,_be ,format ,args ...);};};
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};
func (DummyLogger )Debug (format string ,args ...interface{}){};var Log Logger =DummyLogger {};const _gec =2020;const _gda =6;func (_da WriterLogger )logToWriter (_eb _aa .Writer ,_db string ,_bgd string ,_dae ...interface{}){_fad (_eb ,_db ,_bgd ,_dae );};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_gg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _gg .LogLevel >=level };func UtcTimeFormat (t _bg .Time )string {return t .Format (_bgg )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_bg .Date (_gec ,_cbee ,_gda ,_gecb ,_eg ,0,0,_bg .UTC );
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _aa .Writer )*WriterLogger {_ga :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_ga ;};const Version ="\u0033\u002e\u0031\u0031\u002e\u0030";const _eg =50;
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};
// DummyLogger does nothing.
type DummyLogger struct{};func _fad (_ace _aa .Writer ,_edb string ,_cga string ,_fd ...interface{}){_ ,_cae ,_ec ,_dbc :=_f .Caller (3);if !_dbc {_cae ="\u003f\u003f\u003f";_ec =0;}else {_cae =_d .Base (_cae );};_fge :=_a .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_edb ,_cae ,_ec )+_cga +"\u000a";_a .Fprintf (_ace ,_fge ,_fd ...);};
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };
// Debug logs debug message.
func (_ba WriterLogger )Debug (format string ,args ...interface{}){if _ba .LogLevel >=LogLevelDebug {_aea :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ba .logToWriter (_ba .Output ,_aea ,format ,args ...);};};
// Info logs info message.
func (_cba WriterLogger )Info (format string ,args ...interface{}){if _cba .LogLevel >=LogLevelInfo {_cbe :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cba .logToWriter (_cba .Output ,_cbe ,format ,args ...);};};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -14,170 +14,204 @@
// page content streams and XObject forms and thus also in annotation appearance streams.
//
// Also defines utility functions for drawing common shapes such as rectangles, lines and circles (ovals).
package draw ;import (_a "fmt";_f "github.com/unidoc/unipdf/v3/contentstream";_db "github.com/unidoc/unipdf/v3/core";_ac "github.com/unidoc/unipdf/v3/internal/transform";_g "github.com/unidoc/unipdf/v3/model";_dc "math";);
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_gb Point )Rotate (theta float64 )Point {_ff :=_ac .NewPoint (_gb .X ,_gb .Y ).Rotate (theta );return NewPoint (_ff .X ,_ff .Y );};
// FlipX flips the sign of the Dx component of the vector.
func (_cb Vector )FlipX ()Vector {_cb .Dx =-_cb .Dx ;return _cb };
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_bba Path )GetPointNumber (number int )Point {if number < 1||number > len (_bba .Points ){return Point {};};return _bba .Points [number -1];};
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
// if one occurred.
func (_fdc Line )Draw (gsName string )([]byte ,*_g .PdfRectangle ,error ){_aca ,_bc :=_fdc .X1 ,_fdc .X2 ;_acdd ,_cfd :=_fdc .Y1 ,_fdc .Y2 ;_feg :=_cfd -_acdd ;_bg :=_bc -_aca ;_gca :=_dc .Atan2 (_feg ,_bg );L :=_dc .Sqrt (_dc .Pow (_bg ,2.0)+_dc .Pow (_feg ,2.0));_cfb :=_fdc .LineWidth ;_fef :=_dc .Pi ;_fdd :=1.0;if _bg < 0{_fdd *=-1.0;};if _feg < 0{_fdd *=-1.0;};VsX :=_fdd *(-_cfb /2*_dc .Cos (_gca +_fef /2));VsY :=_fdd *(-_cfb /2*_dc .Sin (_gca +_fef /2)+_cfb *_dc .Sin (_gca +_fef /2));V1X :=VsX +_cfb /2*_dc .Cos (_gca +_fef /2);V1Y :=VsY +_cfb /2*_dc .Sin (_gca +_fef /2);V2X :=VsX +_cfb /2*_dc .Cos (_gca +_fef /2)+L *_dc .Cos (_gca );V2Y :=VsY +_cfb /2*_dc .Sin (_gca +_fef /2)+L *_dc .Sin (_gca );V3X :=VsX +_cfb /2*_dc .Cos (_gca +_fef /2)+L *_dc .Cos (_gca )+_cfb *_dc .Cos (_gca -_fef /2);V3Y :=VsY +_cfb /2*_dc .Sin (_gca +_fef /2)+L *_dc .Sin (_gca )+_cfb *_dc .Sin (_gca -_fef /2);V4X :=VsX +_cfb /2*_dc .Cos (_gca -_fef /2);V4Y :=VsY +_cfb /2*_dc .Sin (_gca -_fef /2);_fbe :=NewPath ();_fbe =_fbe .AppendPoint (NewPoint (V1X ,V1Y ));_fbe =_fbe .AppendPoint (NewPoint (V2X ,V2Y ));_fbe =_fbe .AppendPoint (NewPoint (V3X ,V3Y ));_fbe =_fbe .AppendPoint (NewPoint (V4X ,V4Y ));_gea :=_fdc .LineEndingStyle1 ;_bf :=_fdc .LineEndingStyle2 ;_dda :=3*_cfb ;_ecf :=3*_cfb ;_gfg :=(_ecf -_cfb )/2;if _bf ==LineEndingStyleArrow {_eaee :=_fbe .GetPointNumber (2);_dg :=NewVectorPolar (_dda ,_gca +_fef );_egd :=_eaee .AddVector (_dg );_fdg :=NewVectorPolar (_ecf /2,_gca +_fef /2);_gcb :=NewVectorPolar (_dda ,_gca );_gcf :=NewVectorPolar (_gfg ,_gca +_fef /2);_dcb :=_egd .AddVector (_gcf );_dbd :=_gcb .Add (_fdg .Flip ());_ebd :=_dcb .AddVector (_dbd );_bbaa :=_fdg .Scale (2).Flip ().Add (_dbd .Flip ());_agg :=_ebd .AddVector (_bbaa );_ceg :=_egd .AddVector (NewVectorPolar (_cfb ,_gca -_fef /2));_aae :=NewPath ();_aae =_aae .AppendPoint (_fbe .GetPointNumber (1));_aae =_aae .AppendPoint (_egd );_aae =_aae .AppendPoint (_dcb );_aae =_aae .AppendPoint (_ebd );_aae =_aae .AppendPoint (_agg );_aae =_aae .AppendPoint (_ceg );_aae =_aae .AppendPoint (_fbe .GetPointNumber (4));_fbe =_aae ;};if _gea ==LineEndingStyleArrow {_bda :=_fbe .GetPointNumber (1);_gd :=_fbe .GetPointNumber (_fbe .Length ());_bff :=NewVectorPolar (_cfb /2,_gca +_fef +_fef /2);_cd :=_bda .AddVector (_bff );_gee :=NewVectorPolar (_dda ,_gca ).Add (NewVectorPolar (_ecf /2,_gca +_fef /2));_acad :=_cd .AddVector (_gee );_cfe :=NewVectorPolar (_gfg ,_gca -_fef /2);_ggf :=_acad .AddVector (_cfe );_ebda :=NewVectorPolar (_dda ,_gca );_dbb :=_gd .AddVector (_ebda );_fdgd :=NewVectorPolar (_gfg ,_gca +_fef +_fef /2);_aec :=_dbb .AddVector (_fdgd );_ee :=_cd ;_ffb :=NewPath ();_ffb =_ffb .AppendPoint (_cd );_ffb =_ffb .AppendPoint (_acad );_ffb =_ffb .AppendPoint (_ggf );for _ ,_gbe :=range _fbe .Points [1:len (_fbe .Points )-1]{_ffb =_ffb .AppendPoint (_gbe );};_ffb =_ffb .AppendPoint (_dbb );_ffb =_ffb .AppendPoint (_aec );_ffb =_ffb .AppendPoint (_ee );_fbe =_ffb ;};_add :=_f .NewContentCreator ();_add .Add_q ().Add_rg (_fdc .LineColor .R (),_fdc .LineColor .G (),_fdc .LineColor .B ());if len (gsName )> 1{_add .Add_gs (_db .PdfObjectName (gsName ));};_fbe =_fbe .Offset (_fdc .X1 ,_fdc .Y1 );_gba :=_fbe .GetBoundingBox ();DrawPathWithCreator (_fbe ,_add );if _fdc .LineStyle ==LineStyleDashed {_add .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_add .Add_f ().Add_Q ();};_fbg :=&_g .PdfRectangle {};_fbg .Llx =_gba .X ;_fbg .Lly =_gba .Y ;_fbg .Urx =_gba .X +_gba .Width ;_fbg .Ury =_gba .Y +_gba .Height ;return _add .Bytes (),_fbg ,nil ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
// Copy returns a clone of the Bezier path.
func (_ea CubicBezierPath )Copy ()CubicBezierPath {_cg :=CubicBezierPath {};_cg .Curves =[]CubicBezierCurve {};for _ ,_dbe :=range _ea .Curves {_cg .Curves =append (_cg .Curves ,_dbe );};return _cg ;};
// Draw draws the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
// Returns the content stream as a byte array, the bounding box and an error on failure.
func (_ebg Circle )Draw (gsName string )([]byte ,*_g .PdfRectangle ,error ){_gc :=_ebg .Width /2;_be :=_ebg .Height /2;if _ebg .BorderEnabled {_gc -=_ebg .BorderWidth /2;_be -=_ebg .BorderWidth /2;};_geg :=0.551784;_fbf :=_gc *_geg ;_gbc :=_be *_geg ;_eda :=NewCubicBezierPath ();_eda =_eda .AppendCurve (NewCubicBezierCurve (-_gc ,0,-_gc ,_gbc ,-_fbf ,_be ,0,_be ));_eda =_eda .AppendCurve (NewCubicBezierCurve (0,_be ,_fbf ,_be ,_gc ,_gbc ,_gc ,0));_eda =_eda .AppendCurve (NewCubicBezierCurve (_gc ,0,_gc ,-_gbc ,_fbf ,-_be ,0,-_be ));_eda =_eda .AppendCurve (NewCubicBezierCurve (0,-_be ,-_fbf ,-_be ,-_gc ,-_gbc ,-_gc ,0));_eda =_eda .Offset (_gc ,_be );if _ebg .BorderEnabled {_eda =_eda .Offset (_ebg .BorderWidth /2,_ebg .BorderWidth /2);};if _ebg .X !=0||_ebg .Y !=0{_eda =_eda .Offset (_ebg .X ,_ebg .Y );};_dcf :=_f .NewContentCreator ();_dcf .Add_q ();if _ebg .FillEnabled {_dcf .Add_rg (_ebg .FillColor .R (),_ebg .FillColor .G (),_ebg .FillColor .B ());};if _ebg .BorderEnabled {_dcf .Add_RG (_ebg .BorderColor .R (),_ebg .BorderColor .G (),_ebg .BorderColor .B ());_dcf .Add_w (_ebg .BorderWidth );};if len (gsName )> 1{_dcf .Add_gs (_db .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_eda ,_dcf );_dcf .Add_h ();if _ebg .FillEnabled &&_ebg .BorderEnabled {_dcf .Add_B ();}else if _ebg .FillEnabled {_dcf .Add_f ();}else if _ebg .BorderEnabled {_dcf .Add_S ();};_dcf .Add_Q ();_aad :=_eda .GetBoundingBox ();if _ebg .BorderEnabled {_aad .Height +=_ebg .BorderWidth ;_aad .Width +=_ebg .BorderWidth ;_aad .X -=_ebg .BorderWidth /2;_aad .Y -=_ebg .BorderWidth /2;};_ec :=&_g .PdfRectangle {};_ec .Llx =_aad .X ;_ec .Lly =_aad .Y ;_ec .Urx =_aad .X +_aad .Width ;_ec .Ury =_aad .Y +_aad .Height ;return _dcf .Bytes (),_ec ,nil ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_cdg :=Vector {};_cdg .Dx =dx ;_cdg .Dy =dy ;return _cdg };
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// Magnitude returns the magnitude of the vector.
func (_cbed Vector )Magnitude ()float64 {return _dc .Sqrt (_dc .Pow (_cbed .Dx ,2.0)+_dc .Pow (_cbed .Dy ,2.0));};
// AppendPoint adds the specified point to the path.
func (_df Path )AppendPoint (point Point )Path {_df .Points =append (_df .Points ,point );return _df };func (_bde Point )String ()string {return _a .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_bde .X ,_bde .Y );};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_g .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// GetBoundingBox returns the bounding box of the path.
func (_gge Path )GetBoundingBox ()BoundingBox {_gf :=BoundingBox {};_fbc :=0.0;_fcc :=0.0;_ggd :=0.0;_bdf :=0.0;for _edg ,_adg :=range _gge .Points {if _edg ==0{_fbc =_adg .X ;_fcc =_adg .X ;_ggd =_adg .Y ;_bdf =_adg .Y ;continue ;};if _adg .X < _fbc {_fbc =_adg .X ;};if _adg .X > _fcc {_fcc =_adg .X ;};if _adg .Y < _ggd {_ggd =_adg .Y ;};if _adg .Y > _bdf {_bdf =_adg .Y ;};};_gf .X =_fbc ;_gf .Y =_ggd ;_gf .Width =_fcc -_fbc ;_gf .Height =_bdf -_ggd ;return _gf ;};
// Rotate rotates the vector by the specified angle.
func (_ccca Vector )Rotate (phi float64 )Vector {_dea :=_ccca .Magnitude ();_ebgc :=_ccca .GetPolarAngle ();return NewVectorPolar (_dea ,_ebgc +phi );};
// Copy returns a clone of the path.
func (_fd Path )Copy ()Path {_cfg :=Path {};_cfg .Points =[]Point {};for _ ,_fg :=range _fd .Points {_cfg .Points =append (_cfg .Points ,_fg );};return _cfg ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_edf :=Vector {};_edf .Dx =length *_dc .Cos (theta );_edf .Dy =length *_dc .Sin (theta );return _edf ;};
// NewVectorBetween returns a new vector with the direction specified by
// the subtraction of point a from point b (b-a).
func NewVectorBetween (a Point ,b Point )Vector {_cge :=Vector {};_cge .Dx =b .X -a .X ;_cge .Dy =b .Y -a .Y ;return _cge ;};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_acg CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_acg .P0 .X +=offX ;_acg .P1 .X +=offX ;_acg .P2 .X +=offX ;_acg .P3 .X +=offX ;_acg .P0 .Y +=offY ;_acg .P1 .Y +=offY ;_acg .P2 .Y +=offY ;_acg .P3 .Y +=offY ;return _acg ;};
package draw ;import (_f "fmt";_b "github.com/unidoc/unipdf/v3/contentstream";_e "github.com/unidoc/unipdf/v3/core";_ee "github.com/unidoc/unipdf/v3/internal/transform";_fe "github.com/unidoc/unipdf/v3/model";_g "math";);
// FlipY flips the sign of the Dy component of the vector.
func (_afe Vector )FlipY ()Vector {_afe .Dy =-_afe .Dy ;return _afe };
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_g .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_g .PdfColorDeviceRGB ;Opacity float64 ;};
// DrawBezierPathWithCreator makes the bezier path with the content creator.
// Adds the PDF commands to draw the path to the creator instance.
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_f .ContentCreator ){for _egf ,_ga :=range bpath .Curves {if _egf ==0{creator .Add_m (_ga .P0 .X ,_ga .P0 .Y );};creator .Add_c (_ga .P1 .X ,_ga .P1 .Y ,_ga .P2 .X ,_ga .P2 .Y ,_ga .P3 .X ,_ga .P3 .Y );};};
// GetBounds returns the bounding box of the Bezier curve.
func (_c CubicBezierCurve )GetBounds ()_g .PdfRectangle {_e :=_c .P0 .X ;_fb :=_c .P0 .X ;_cc :=_c .P0 .Y ;_b :=_c .P0 .Y ;for _ag :=0.0;_ag <=1.0;_ag +=0.001{Rx :=_c .P0 .X *_dc .Pow (1-_ag ,3)+_c .P1 .X *3*_ag *_dc .Pow (1-_ag ,2)+_c .P2 .X *3*_dc .Pow (_ag ,2)*(1-_ag )+_c .P3 .X *_dc .Pow (_ag ,3);Ry :=_c .P0 .Y *_dc .Pow (1-_ag ,3)+_c .P1 .Y *3*_ag *_dc .Pow (1-_ag ,2)+_c .P2 .Y *3*_dc .Pow (_ag ,2)*(1-_ag )+_c .P3 .Y *_dc .Pow (_ag ,3);if Rx < _e {_e =Rx ;};if Rx > _fb {_fb =Rx ;};if Ry < _cc {_cc =Ry ;};if Ry > _b {_b =Ry ;};};_fa :=_g .PdfRectangle {};_fa .Llx =_e ;_fa .Lly =_cc ;_fa .Urx =_fb ;_fa .Ury =_b ;return _fa ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_gg :=CubicBezierCurve {};_gg .P0 =NewPoint (x0 ,y0 );_gg .P1 =NewPoint (x1 ,y1 );_gg .P2 =NewPoint (x2 ,y2 );_gg .P3 =NewPoint (x3 ,y3 );return _gg ;};
// Length returns the number of points in the path.
func (_fc Path )Length ()int {return len (_fc .Points )};
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
func (_eae Rectangle )Draw (gsName string )([]byte ,*_g .PdfRectangle ,error ){_ce :=NewPath ();_ce =_ce .AppendPoint (NewPoint (0,0));_ce =_ce .AppendPoint (NewPoint (0,_eae .Height ));_ce =_ce .AppendPoint (NewPoint (_eae .Width ,_eae .Height ));_ce =_ce .AppendPoint (NewPoint (_eae .Width ,0));_ce =_ce .AppendPoint (NewPoint (0,0));if _eae .X !=0||_eae .Y !=0{_ce =_ce .Offset (_eae .X ,_eae .Y );};_dd :=_f .NewContentCreator ();_dd .Add_q ();if _eae .FillEnabled {_dd .Add_rg (_eae .FillColor .R (),_eae .FillColor .G (),_eae .FillColor .B ());};if _eae .BorderEnabled {_dd .Add_RG (_eae .BorderColor .R (),_eae .BorderColor .G (),_eae .BorderColor .B ());_dd .Add_w (_eae .BorderWidth );};if len (gsName )> 1{_dd .Add_gs (_db .PdfObjectName (gsName ));};DrawPathWithCreator (_ce ,_dd );_dd .Add_h ();if _eae .FillEnabled &&_eae .BorderEnabled {_dd .Add_B ();}else if _eae .FillEnabled {_dd .Add_f ();}else if _eae .BorderEnabled {_dd .Add_S ();};_dd .Add_Q ();_gfa :=_ce .GetBoundingBox ();_cgd :=&_g .PdfRectangle {};_cgd .Llx =_gfa .X ;_cgd .Lly =_gfa .Y ;_cgd .Urx =_gfa .X +_gfa .Width ;_cgd .Ury =_gfa .Y +_gfa .Height ;return _dd .Bytes (),_cgd ,nil ;};
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_de :=CubicBezierPath {};_de .Curves =[]CubicBezierCurve {};return _de ;};
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
// or arrows at either end. The line also has a specified width, color and opacity.
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_g .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// Offset shifts the path with the specified offsets.
func (_ae Path )Offset (offX ,offY float64 )Path {for _ed ,_fe :=range _ae .Points {_ae .Points [_ed ]=_fe .Add (offX ,offY );};return _ae ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// Flip changes the sign of the vector: -vector.
func (_bag Vector )Flip ()Vector {_aeg :=_bag .Magnitude ();_bga :=_bag .GetPolarAngle ();_bag .Dx =_aeg *_dc .Cos (_bga +_dc .Pi );_bag .Dy =_aeg *_dc .Sin (_bga +_dc .Pi );return _bag ;};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_eg Path )RemovePoint (number int )Path {if number < 1||number > len (_eg .Points ){return _eg ;};_bd :=number -1;_eg .Points =append (_eg .Points [:_bd ],_eg .Points [_bd +1:]...);return _eg ;};
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
// one occurred.
func (_cef BasicLine )Draw (gsName string )([]byte ,*_g .PdfRectangle ,error ){_bdee :=_cef .LineWidth ;_cgdb :=NewPath ();_cgdb =_cgdb .AppendPoint (NewPoint (_cef .X1 ,_cef .Y1 ));_cgdb =_cgdb .AppendPoint (NewPoint (_cef .X2 ,_cef .Y2 ));_ega :=_f .NewContentCreator ();_bgc :=_cgdb .GetBoundingBox ();DrawPathWithCreator (_cgdb ,_ega );if _cef .LineStyle ==LineStyleDashed {_ega .Add_d ([]int64 {1,1},0);};_ega .Add_RG (_cef .LineColor .R (),_cef .LineColor .G (),_cef .LineColor .B ()).Add_w (_bdee ).Add_S ().Add_Q ();_eef :=&_g .PdfRectangle {};_eef .Llx =_bgc .X ;_eef .Lly =_bgc .Y ;_eef .Urx =_bgc .X +_bgc .Width ;_eef .Ury =_bgc .Y +_bgc .Height ;return _ega .Bytes (),_eef ,nil ;};
func (_aac Vector )FlipY ()Vector {_aac .Dy =-_aac .Dy ;return _aac };
// DrawPathWithCreator makes the path with the content creator.
// Adds the PDF commands to draw the path to the creator instance.
func DrawPathWithCreator (path Path ,creator *_f .ContentCreator ){for _dbba ,_geag :=range path .Points {if _dbba ==0{creator .Add_m (_geag .X ,_geag .Y );}else {creator .Add_l (_geag .X ,_geag .Y );};};};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
func DrawPathWithCreator (path Path ,creator *_b .ContentCreator ){for _fdd ,_ffg :=range path .Points {if _fdd ==0{creator .Add_m (_ffg .X ,_ffg .Y );}else {creator .Add_l (_ffg .X ,_ffg .Y );};};};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};
// Rotate rotates the vector by the specified angle.
func (_ga Vector )Rotate (phi float64 )Vector {_ccd :=_ga .Magnitude ();_aaa :=_ga .GetPolarAngle ();return NewVectorPolar (_ccd ,_aaa +phi );};
// Add adds the specified vector to the current one and returns the result.
func (_bed Vector )Add (other Vector )Vector {_bed .Dx +=other .Dx ;_bed .Dy +=other .Dy ;return _bed };
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_aff Point )Add (dx ,dy float64 )Point {_aff .X +=dx ;_aff .Y +=dy ;return _aff };
// LineStyle refers to how the line will be created.
type LineStyle int ;
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_g .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_g .PdfColorDeviceRGB ;Opacity float64 ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_aa CubicBezierPath )GetBoundingBox ()Rectangle {_agc :=Rectangle {};_bb :=0.0;_ccc :=0.0;_cf :=0.0;_da :=0.0;for _acd ,_ba :=range _aa .Curves {_bbf :=_ba .GetBounds ();if _acd ==0{_bb =_bbf .Llx ;_ccc =_bbf .Urx ;_cf =_bbf .Lly ;_da =_bbf .Ury ;continue ;};if _bbf .Llx < _bb {_bb =_bbf .Llx ;};if _bbf .Urx > _ccc {_ccc =_bbf .Urx ;};if _bbf .Lly < _cf {_cf =_bbf .Lly ;};if _bbf .Ury > _da {_da =_bbf .Ury ;};};_agc .X =_bb ;_agc .Y =_cf ;_agc .Width =_ccc -_bb ;_agc .Height =_da -_cf ;return _agc ;};
// Offset shifts the Bezier path with the specified offsets.
func (_af CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _adf ,_acf :=range _af .Curves {_af .Curves [_adf ]=_acf .AddOffsetXY (offX ,offY );};return _af ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_fea :=CubicBezierCurve {};_fea .P0 =NewPoint (x0 ,y0 );_fea .P1 =NewPoint (x1 ,y1 );_fea .P2 =NewPoint (x2 ,y2 );_fea .P3 =NewPoint (x3 ,y3 );return _fea ;};
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_dgg BoundingBox )ToPdfRectangle ()*_fe .PdfRectangle {return &_fe .PdfRectangle {Llx :_dgg .X ,Lly :_dgg .Y ,Urx :_dgg .X +_dgg .Width ,Ury :_dgg .Y +_dgg .Height };};
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};
// GetBoundingBox returns the bounding box of the path.
func (_dg Path )GetBoundingBox ()BoundingBox {_cd :=BoundingBox {};_cgf :=0.0;_ce :=0.0;_dc :=0.0;_bb :=0.0;for _af ,_ea :=range _dg .Points {if _af ==0{_cgf =_ea .X ;_ce =_ea .X ;_dc =_ea .Y ;_bb =_ea .Y ;continue ;};if _ea .X < _cgf {_cgf =_ea .X ;};if _ea .X > _ce {_ce =_ea .X ;};if _ea .Y < _dc {_dc =_ea .Y ;};if _ea .Y > _bb {_bb =_ea .Y ;};};_cd .X =_cgf ;_cd .Y =_dc ;_cd .Width =_ce -_cgf ;_cd .Height =_bb -_dc ;return _cd ;};
// DrawBezierPathWithCreator makes the bezier path with the content creator.
// Adds the PDF commands to draw the path to the creator instance.
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_b .ContentCreator ){for _ebf ,_bcga :=range bpath .Curves {if _ebf ==0{creator .Add_m (_bcga .P0 .X ,_bcga .P0 .Y );};creator .Add_c (_bcga .P1 .X ,_bcga .P1 .Y ,_bcga .P2 .X ,_bcga .P2 .Y ,_bcga .P3 .X ,_bcga .P3 .Y );};};
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
// or arrows at either end. The line also has a specified width, color and opacity.
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// Scale scales the vector by the specified factor.
func (_ceb Vector )Scale (factor float64 )Vector {_ffc :=_ceb .Magnitude ();_ccc :=_ceb .GetPolarAngle ();_ceb .Dx =factor *_ffc *_g .Cos (_ccc );_ceb .Dy =factor *_ffc *_g .Sin (_ccc );return _ceb ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};func (_adb Point )String ()string {return _f .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_adb .X ,_adb .Y );};
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;};
// Draw draws the polyline. A graphics state name can be specified for
// setting the polyline properties (e.g. setting the opacity). Otherwise leave
// empty (""). Returns the content stream as a byte array and the polyline
// bounding box.
func (_edb Polyline )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){if _edb .LineColor ==nil {_edb .LineColor =_fe .NewPdfColorDeviceRGB (0,0,0);};_bagd :=NewPath ();for _ ,_bda :=range _edb .Points {_bagd =_bagd .AppendPoint (_bda );};_gfb :=_b .NewContentCreator ();_gfb .Add_q ();_gfb .Add_RG (_edb .LineColor .R (),_edb .LineColor .G (),_edb .LineColor .B ());_gfb .Add_w (_edb .LineWidth );if len (gsName )> 1{_gfb .Add_gs (_e .PdfObjectName (gsName ));};DrawPathWithCreator (_bagd ,_gfb );_gfb .Add_S ();_gfb .Add_Q ();return _gfb .Bytes (),_bagd .GetBoundingBox ().ToPdfRectangle (),nil ;};
// AppendCurve appends the specified Bezier curve to the path.
func (_ad CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ad .Curves =append (_ad .Curves ,curve );return _ad ;};
func (_de CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_de .Curves =append (_de .Curves ,curve );return _de ;};
// Magnitude returns the magnitude of the vector.
func (_gde Vector )Magnitude ()float64 {return _g .Sqrt (_g .Pow (_gde .Dx ,2.0)+_g .Pow (_gde .Dy ,2.0))};
// Copy returns a clone of the Bezier path.
func (_fg CubicBezierPath )Copy ()CubicBezierPath {_aa :=CubicBezierPath {};_aa .Curves =[]CubicBezierCurve {};for _ ,_dd :=range _fg .Curves {_aa .Curves =append (_aa .Curves ,_dd );};return _aa ;};
// Flip changes the sign of the vector: -vector.
func (_eecg Vector )Flip ()Vector {_cbg :=_eecg .Magnitude ();_cgd :=_eecg .GetPolarAngle ();_eecg .Dx =_cbg *_g .Cos (_cgd +_g .Pi );_eecg .Dy =_cbg *_g .Sin (_cgd +_g .Pi );return _eecg ;};
// Draw draws the polygon. A graphics state name can be specified for
// setting the polygon properties (e.g. setting the opacity). Otherwise leave
// empty (""). Returns the content stream as a byte array and the polygon
// bounding box.
func (_afa Polygon )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_dcf :=_b .NewContentCreator ();_dcf .Add_q ();_afa .FillEnabled =_afa .FillEnabled &&_afa .FillColor !=nil ;if _afa .FillEnabled {_dcf .Add_rg (_afa .FillColor .R (),_afa .FillColor .G (),_afa .FillColor .B ());};_afa .BorderEnabled =_afa .BorderEnabled &&_afa .BorderColor !=nil ;if _afa .BorderEnabled {_dcf .Add_RG (_afa .BorderColor .R (),_afa .BorderColor .G (),_afa .BorderColor .B ());_dcf .Add_w (_afa .BorderWidth );};if len (gsName )> 1{_dcf .Add_gs (_e .PdfObjectName (gsName ));};_ead :=NewPath ();for _ ,_gff :=range _afa .Points {for _dff ,_edf :=range _gff {_ead =_ead .AppendPoint (_edf );if _dff ==0{_dcf .Add_m (_edf .X ,_edf .Y );}else {_dcf .Add_l (_edf .X ,_edf .Y );};};_dcf .Add_h ();};if _afa .FillEnabled &&_afa .BorderEnabled {_dcf .Add_B ();}else if _afa .FillEnabled {_dcf .Add_f ();}else if _afa .BorderEnabled {_dcf .Add_S ();};_dcf .Add_Q ();return _dcf .Bytes (),_ead .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
// one occurred.
func (_bf BasicLine )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_agd :=_bf .LineWidth ;_egd :=NewPath ();_egd =_egd .AppendPoint (NewPoint (_bf .X1 ,_bf .Y1 ));_egd =_egd .AppendPoint (NewPoint (_bf .X2 ,_bf .Y2 ));_fbe :=_b .NewContentCreator ();_bab :=_egd .GetBoundingBox ();DrawPathWithCreator (_egd ,_fbe );if _bf .LineStyle ==LineStyleDashed {_fbe .Add_d ([]int64 {1,1},0);};_fbe .Add_RG (_bf .LineColor .R (),_bf .LineColor .G (),_bf .LineColor .B ()).Add_w (_agd ).Add_S ().Add_Q ();return _fbe .Bytes (),_bab .ToPdfRectangle (),nil ;};
// Copy returns a clone of the path.
func (_fc Path )Copy ()Path {_ag :=Path {};_ag .Points =[]Point {};for _ ,_gga :=range _fc .Points {_ag .Points =append (_ag .Points ,_gga );};return _ag ;};
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_fe .PdfColorDeviceRGB ;BorderWidth float64 ;};
// Length returns the number of points in the path.
func (_bcg Path )Length ()int {return len (_bcg .Points )};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_efe CubicBezierPath )GetBoundingBox ()Rectangle {_gc :=Rectangle {};_cb :=0.0;_ddb :=0.0;_aeb :=0.0;_ca :=0.0;for _cf ,_ec :=range _efe .Curves {_db :=_ec .GetBounds ();if _cf ==0{_cb =_db .Llx ;_ddb =_db .Urx ;_aeb =_db .Lly ;_ca =_db .Ury ;continue ;};if _db .Llx < _cb {_cb =_db .Llx ;};if _db .Urx > _ddb {_ddb =_db .Urx ;};if _db .Lly < _aeb {_aeb =_db .Lly ;};if _db .Ury > _ca {_ca =_db .Ury ;};};_gc .X =_cb ;_gc .Y =_aeb ;_gc .Width =_ddb -_cb ;_gc .Height =_ca -_aeb ;return _gc ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_cff Point )Add (dx ,dy float64 )Point {_cff .X +=dx ;_cff .Y +=dy ;return _cff };
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_da :=CubicBezierPath {};_da .Curves =[]CubicBezierCurve {};return _da ;};
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
// if one occurred.
func (_bcfe Line )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_eef ,_gd :=_bcfe .X1 ,_bcfe .X2 ;_gdf ,_efd :=_bcfe .Y1 ,_bcfe .Y2 ;_bcgf :=_efd -_gdf ;_eeg :=_gd -_eef ;_efa :=_g .Atan2 (_bcgf ,_eeg );L :=_g .Sqrt (_g .Pow (_eeg ,2.0)+_g .Pow (_bcgf ,2.0));_cdb :=_bcfe .LineWidth ;_afc :=_g .Pi ;_gfe :=1.0;if _eeg < 0{_gfe *=-1.0;};if _bcgf < 0{_gfe *=-1.0;};VsX :=_gfe *(-_cdb /2*_g .Cos (_efa +_afc /2));VsY :=_gfe *(-_cdb /2*_g .Sin (_efa +_afc /2)+_cdb *_g .Sin (_efa +_afc /2));V1X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2);V1Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2);V2X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2)+L *_g .Cos (_efa );V2Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2)+L *_g .Sin (_efa );V3X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2)+L *_g .Cos (_efa )+_cdb *_g .Cos (_efa -_afc /2);V3Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2)+L *_g .Sin (_efa )+_cdb *_g .Sin (_efa -_afc /2);V4X :=VsX +_cdb /2*_g .Cos (_efa -_afc /2);V4Y :=VsY +_cdb /2*_g .Sin (_efa -_afc /2);_daa :=NewPath ();_daa =_daa .AppendPoint (NewPoint (V1X ,V1Y ));_daa =_daa .AppendPoint (NewPoint (V2X ,V2Y ));_daa =_daa .AppendPoint (NewPoint (V3X ,V3Y ));_daa =_daa .AppendPoint (NewPoint (V4X ,V4Y ));_ece :=_bcfe .LineEndingStyle1 ;_ebb :=_bcfe .LineEndingStyle2 ;_dge :=3*_cdb ;_ceg :=3*_cdb ;_ac :=(_ceg -_cdb )/2;if _ebb ==LineEndingStyleArrow {_affb :=_daa .GetPointNumber (2);_fde :=NewVectorPolar (_dge ,_efa +_afc );_dfe :=_affb .AddVector (_fde );_bgc :=NewVectorPolar (_ceg /2,_efa +_afc /2);_afag :=NewVectorPolar (_dge ,_efa );_ecc :=NewVectorPolar (_ac ,_efa +_afc /2);_dce :=_dfe .AddVector (_ecc );_cfg :=_afag .Add (_bgc .Flip ());_fb :=_dce .AddVector (_cfg );_cec :=_bgc .Scale (2).Flip ().Add (_cfg .Flip ());_fbb :=_fb .AddVector (_cec );_ba :=_dfe .AddVector (NewVectorPolar (_cdb ,_efa -_afc /2));_eec :=NewPath ();_eec =_eec .AppendPoint (_daa .GetPointNumber (1));_eec =_eec .AppendPoint (_dfe );_eec =_eec .AppendPoint (_dce );_eec =_eec .AppendPoint (_fb );_eec =_eec .AppendPoint (_fbb );_eec =_eec .AppendPoint (_ba );_eec =_eec .AppendPoint (_daa .GetPointNumber (4));_daa =_eec ;};if _ece ==LineEndingStyleArrow {_dffa :=_daa .GetPointNumber (1);_aab :=_daa .GetPointNumber (_daa .Length ());_cecc :=NewVectorPolar (_cdb /2,_efa +_afc +_afc /2);_cef :=_dffa .AddVector (_cecc );_gdc :=NewVectorPolar (_dge ,_efa ).Add (NewVectorPolar (_ceg /2,_efa +_afc /2));_gb :=_cef .AddVector (_gdc );_aec :=NewVectorPolar (_ac ,_efa -_afc /2);_bag :=_gb .AddVector (_aec );_gfed :=NewVectorPolar (_dge ,_efa );_bd :=_aab .AddVector (_gfed );_dee :=NewVectorPolar (_ac ,_efa +_afc +_afc /2);_dfg :=_bd .AddVector (_dee );_gda :=_cef ;_egb :=NewPath ();_egb =_egb .AppendPoint (_cef );_egb =_egb .AppendPoint (_gb );_egb =_egb .AppendPoint (_bag );for _ ,_fcb :=range _daa .Points [1:len (_daa .Points )-1]{_egb =_egb .AppendPoint (_fcb );};_egb =_egb .AppendPoint (_bd );_egb =_egb .AppendPoint (_dfg );_egb =_egb .AppendPoint (_gda );_daa =_egb ;};_ebc :=_b .NewContentCreator ();_ebc .Add_q ().Add_rg (_bcfe .LineColor .R (),_bcfe .LineColor .G (),_bcfe .LineColor .B ());if len (gsName )> 1{_ebc .Add_gs (_e .PdfObjectName (gsName ));};_daa =_daa .Offset (_bcfe .X1 ,_bcfe .Y1 );_dfa :=_daa .GetBoundingBox ();DrawPathWithCreator (_daa ,_ebc );if _bcfe .LineStyle ==LineStyleDashed {_ebc .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_ebc .Add_f ().Add_Q ();};return _ebc .Bytes (),_dfa .ToPdfRectangle (),nil ;};
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// LineStyle refers to how the line will be created.
type LineStyle int ;
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
func (_dcg Rectangle )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_fed :=NewPath ();_fed =_fed .AppendPoint (NewPoint (0,0));_fed =_fed .AppendPoint (NewPoint (0,_dcg .Height ));_fed =_fed .AppendPoint (NewPoint (_dcg .Width ,_dcg .Height ));_fed =_fed .AppendPoint (NewPoint (_dcg .Width ,0));_fed =_fed .AppendPoint (NewPoint (0,0));if _dcg .X !=0||_dcg .Y !=0{_fed =_fed .Offset (_dcg .X ,_dcg .Y );};_ff :=_b .NewContentCreator ();_ff .Add_q ();if _dcg .FillEnabled {_ff .Add_rg (_dcg .FillColor .R (),_dcg .FillColor .G (),_dcg .FillColor .B ());};if _dcg .BorderEnabled {_ff .Add_RG (_dcg .BorderColor .R (),_dcg .BorderColor .G (),_dcg .BorderColor .B ());_ff .Add_w (_dcg .BorderWidth );};if len (gsName )> 1{_ff .Add_gs (_e .PdfObjectName (gsName ));};DrawPathWithCreator (_fed ,_ff );_ff .Add_h ();if _dcg .FillEnabled &&_dcg .BorderEnabled {_ff .Add_B ();}else if _dcg .FillEnabled {_ff .Add_f ();}else if _dcg .BorderEnabled {_ff .Add_S ();};_ff .Add_Q ();return _ff .Bytes (),_fed .GetBoundingBox ().ToPdfRectangle (),nil ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// Offset shifts the Bezier path with the specified offsets.
func (_bg CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _dad ,_cg :=range _bg .Curves {_bg .Curves [_dad ]=_cg .AddOffsetXY (offX ,offY );};return _bg ;};
// CubicBezierCurve is defined by:
// R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3
// where P0 is the current point, P1, P2 control points and P3 the final point.
type CubicBezierCurve struct{P0 Point ;P1 Point ;P2 Point ;P3 Point ;};
// AddVector adds vector to a point.
func (_eb Point )AddVector (v Vector )Point {_eb .X +=v .Dx ;_eb .Y +=v .Dy ;return _eb };
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;
// Scale scales the vector by the specified factor.
func (_egg Vector )Scale (factor float64 )Vector {_deb :=_egg .Magnitude ();_cbe :=_egg .GetPolarAngle ();_egg .Dx =factor *_deb *_dc .Cos (_cbe );_egg .Dy =factor *_deb *_dc .Sin (_cbe );return _egg ;};
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};
// GetBounds returns the bounding box of the Bezier curve.
func (_d CubicBezierCurve )GetBounds ()_fe .PdfRectangle {_ggc :=_d .P0 .X ;_ae :=_d .P0 .X ;_ad :=_d .P0 .Y ;_eb :=_d .P0 .Y ;for _c :=0.0;_c <=1.0;_c +=0.001{Rx :=_d .P0 .X *_g .Pow (1-_c ,3)+_d .P1 .X *3*_c *_g .Pow (1-_c ,2)+_d .P2 .X *3*_g .Pow (_c ,2)*(1-_c )+_d .P3 .X *_g .Pow (_c ,3);Ry :=_d .P0 .Y *_g .Pow (1-_c ,3)+_d .P1 .Y *3*_c *_g .Pow (1-_c ,2)+_d .P2 .Y *3*_g .Pow (_c ,2)*(1-_c )+_d .P3 .Y *_g .Pow (_c ,3);if Rx < _ggc {_ggc =Rx ;};if Rx > _ae {_ae =Rx ;};if Ry < _ad {_ad =Ry ;};if Ry > _eb {_eb =Ry ;};};_ef :=_fe .PdfRectangle {};_ef .Llx =_ggc ;_ef .Lly =_ad ;_ef .Urx =_ae ;_ef .Ury =_eb ;return _ef ;};
// Draw draws the composite Bezier curve. A graphics state name can be
// specified for setting the curve properties (e.g. setting the opacity).
// Otherwise leave empty (""). Returns the content stream as a byte array and
// the curve bounding box.
func (_ge PolyBezierCurve )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){if _ge .BorderColor ==nil {_ge .BorderColor =_fe .NewPdfColorDeviceRGB (0,0,0);};_feb :=NewCubicBezierPath ();for _ ,_cc :=range _ge .Curves {_feb =_feb .AppendCurve (_cc );};_age :=_b .NewContentCreator ();_age .Add_q ();_ge .FillEnabled =_ge .FillEnabled &&_ge .FillColor !=nil ;if _ge .FillEnabled {_age .Add_rg (_ge .FillColor .R (),_ge .FillColor .G (),_ge .FillColor .B ());};_age .Add_RG (_ge .BorderColor .R (),_ge .BorderColor .G (),_ge .BorderColor .B ());_age .Add_w (_ge .BorderWidth );if len (gsName )> 1{_age .Add_gs (_e .PdfObjectName (gsName ));};for _ ,_ccf :=range _feb .Curves {_age .Add_m (_ccf .P0 .X ,_ccf .P0 .Y );_age .Add_c (_ccf .P1 .X ,_ccf .P1 .Y ,_ccf .P2 .X ,_ccf .P2 .Y ,_ccf .P3 .X ,_ccf .P3 .Y );};if _ge .FillEnabled {_age .Add_h ();_age .Add_B ();}else {_age .Add_S ();};_age .Add_Q ();return _age .Bytes (),_feb .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_fe .PdfColorDeviceRGB ;LineWidth float64 ;};
// NewVectorBetween returns a new vector with the direction specified by
// the subtraction of point a from point b (b-a).
func NewVectorBetween (a Point ,b Point )Vector {_bbc :=Vector {};_bbc .Dx =b .X -a .X ;_bbc .Dy =b .Y -a .Y ;return _bbc ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_cce :=Vector {};_cce .Dx =dx ;_cce .Dy =dy ;return _cce };
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_be Path )GetPointNumber (number int )Point {if number < 1||number > len (_be .Points ){return Point {};};return _be .Points [number -1];};
// Add adds the specified vector to the current one and returns the result.
func (_ab Vector )Add (other Vector )Vector {_ab .Dx +=other .Dx ;_ab .Dy +=other .Dy ;return _ab };
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_fa Point )Rotate (theta float64 )Point {_agg :=_ee .NewPoint (_fa .X ,_fa .Y ).Rotate (theta );return NewPoint (_agg .X ,_agg .Y );};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_gg CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_gg .P0 .X +=offX ;_gg .P1 .X +=offX ;_gg .P2 .X +=offX ;_gg .P3 .X +=offX ;_gg .P0 .Y +=offY ;_gg .P1 .Y +=offY ;_gg .P2 .Y +=offY ;_gg .P3 .Y +=offY ;return _gg ;};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_cfd Path )RemovePoint (number int )Path {if number < 1||number > len (_cfd .Points ){return _cfd ;};_add :=number -1;_cfd .Points =append (_cfd .Points [:_add ],_cfd .Points [_add +1:]...);return _cfd ;};
// AppendPoint adds the specified point to the path.
func (_cbd Path )AppendPoint (point Point )Path {_cbd .Points =append (_cbd .Points ,point );return _cbd };
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_eeb :=Vector {};_eeb .Dx =length *_g .Cos (theta );_eeb .Dy =length *_g .Sin (theta );return _eeb ;};
// FlipX flips the sign of the Dx component of the vector.
func (_cgc Vector )FlipX ()Vector {_cgc .Dx =-_cgc .Dx ;return _cgc };
// Draw draws the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
// Returns the content stream as a byte array, the bounding box and an error on failure.
func (_ecd Circle )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_bcf :=_ecd .Width /2;_gfg :=_ecd .Height /2;if _ecd .BorderEnabled {_bcf -=_ecd .BorderWidth /2;_gfg -=_ecd .BorderWidth /2;};_agb :=0.551784;_fce :=_bcf *_agb ;_fd :=_gfg *_agb ;_ggca :=NewCubicBezierPath ();_ggca =_ggca .AppendCurve (NewCubicBezierCurve (-_bcf ,0,-_bcf ,_fd ,-_fce ,_gfg ,0,_gfg ));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (0,_gfg ,_fce ,_gfg ,_bcf ,_fd ,_bcf ,0));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (_bcf ,0,_bcf ,-_fd ,_fce ,-_gfg ,0,-_gfg ));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (0,-_gfg ,-_fce ,-_gfg ,-_bcf ,-_fd ,-_bcf ,0));_ggca =_ggca .Offset (_bcf ,_gfg );if _ecd .BorderEnabled {_ggca =_ggca .Offset (_ecd .BorderWidth /2,_ecd .BorderWidth /2);};if _ecd .X !=0||_ecd .Y !=0{_ggca =_ggca .Offset (_ecd .X ,_ecd .Y );};_dbg :=_b .NewContentCreator ();_dbg .Add_q ();if _ecd .FillEnabled {_dbg .Add_rg (_ecd .FillColor .R (),_ecd .FillColor .G (),_ecd .FillColor .B ());};if _ecd .BorderEnabled {_dbg .Add_RG (_ecd .BorderColor .R (),_ecd .BorderColor .G (),_ecd .BorderColor .B ());_dbg .Add_w (_ecd .BorderWidth );};if len (gsName )> 1{_dbg .Add_gs (_e .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_ggca ,_dbg );_dbg .Add_h ();if _ecd .FillEnabled &&_ecd .BorderEnabled {_dbg .Add_B ();}else if _ecd .FillEnabled {_dbg .Add_f ();}else if _ecd .BorderEnabled {_dbg .Add_S ();};_dbg .Add_Q ();_eg :=_ggca .GetBoundingBox ();if _ecd .BorderEnabled {_eg .Height +=_ecd .BorderWidth ;_eg .Width +=_ecd .BorderWidth ;_eg .X -=_ecd .BorderWidth /2;_eg .Y -=_ecd .BorderWidth /2;};return _dbg .Bytes (),_eg .ToPdfRectangle (),nil ;};
// Offset shifts the path with the specified offsets.
func (_gf Path )Offset (offX ,offY float64 )Path {for _df ,_ed :=range _gf .Points {_gf .Points [_df ]=_ed .Add (offX ,offY );};return _gf ;};
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_gfa Rectangle )ToPdfRectangle ()*_fe .PdfRectangle {return &_fe .PdfRectangle {Llx :_gfa .X ,Lly :_gfa .Y ,Urx :_gfa .X +_gfa .Width ,Ury :_gfa .Y +_gfa .Height };};
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_eca Vector )GetPolarAngle ()float64 {return _dc .Atan2 (_eca .Dy ,_eca .Dx )};
func (_faf Vector )GetPolarAngle ()float64 {return _g .Atan2 (_faf .Dy ,_faf .Dx )};
// AddVector adds vector to a point.
func (_dac Point )AddVector (v Vector )Point {_dac .X +=v .Dx ;_dac .Y +=v .Dy ;return _dac };

File diff suppressed because one or more lines are too long

View File

@ -9,11 +9,53 @@
// 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 crypt ;import (_e "crypto/aes";_c "crypto/cipher";_fd "crypto/md5";_fe "crypto/rand";_be "crypto/rc4";_f "fmt";_d "github.com/unidoc/unipdf/v3/common";_dd "github.com/unidoc/unipdf/v3/core/security";_b "io";);func init (){_dff ("\u0041\u0045\u0053V\u0032",_bec )};
package crypt ;import (_a "crypto/aes";_c "crypto/cipher";_d "crypto/md5";_e "crypto/rand";_aa "crypto/rc4";_g "fmt";_ee "github.com/unidoc/unipdf/v3/common";_ag "github.com/unidoc/unipdf/v3/core/security";_bc "io";);func init (){_bda ("\u0041\u0045\u0053V\u0032",_ad )};var _ Filter =filterV2 {};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ag .AuthEvent ;Length int ;};func (filterIdentity )KeyLength ()int {return 0};func _ad (_af FilterDict )(Filter ,error ){if _af .Length ==128{_ee .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_af .Length );_af .Length /=8;};if _af .Length !=0&&_af .Length !=16{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_af .Length );};return filterAESV2 {},nil ;};func _ade (_gd FilterDict )(Filter ,error ){if _gd .Length ==256{_ee .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_gd .Length );_gd .Length /=8;};if _gd .Length !=0&&_gd .Length !=32{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_gd .Length );};return filterAESV3 {},nil ;};var (_gba =make (map[string ]filterFunc ););
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_da ,_ab :=_ad (FilterDict {});if _ab !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ab );return filterAESV2 {};};return _da ;};
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};func init (){_bda ("\u0041\u0045\u0053V\u0033",_ade )};type filterAES struct{};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func _fgf (_cba string )(filterFunc ,error ){_ccd :=_gba [string (_cba )];if _ccd ==nil {return nil ,_g .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_cba );};return _ccd ,nil ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};var _ Filter =filterAESV2 {};
// KeyLength implements Filter interface.
func (_cfb filterV2 )KeyLength ()int {return _cfb ._fec };
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gfg (objNum ,genNum ,ekey ,true );};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_dc ,_cdc :=_aa .NewCipher (okey );if _cdc !=nil {return nil ,_cdc ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_dc .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ea ,_gf :=_a .NewCipher (okey );if _gf !=nil {return nil ,_gf ;};if len (buf )< 16{_ee .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_bg :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ee .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_bg ),_bg );_ee .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_bf :=_c .NewCBCDecrypter (_ea ,_bg );_ee .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ee .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_bf .CryptBlocks (buf ,buf );_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ee .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_ege :=int (buf [len (buf )-1]);if _ege > len (buf ){_ee .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_ege ,len (buf ));return buf ,_g .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ege ];return buf ,nil ;};type filterAESV2 struct{filterAES };func init (){_bda ("\u0056\u0032",_cg )};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
// PDFVersion implements Filter interface.
func (_eff filterV2 )PDFVersion ()[2]int {return [2]int {}};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ff ,_afb :=_a .NewCipher (okey );if _afb !=nil {return nil ,_afb ;};_ee .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _eg =_a .BlockSize ;_ef :=_eg -len (buf )%_eg ;for _bcg :=0;_bcg < _ef ;_bcg ++{buf =append (buf ,byte (_ef ));};_ee .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_adf :=make ([]byte ,_eg +len (buf ));_cd :=_adf [:_eg ];if _ ,_gc :=_bc .ReadFull (_e .Reader ,_cd );_gc !=nil {return nil ,_gc ;};_fg :=_c .NewCBCEncrypter (_ff ,_cd );_fg .CryptBlocks (_adf [_eg :],buf );buf =_adf ;_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
// MakeKey implements Filter interface.
func (_ffc filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gfg (objNum ,genNum ,ekey ,false );};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};
// Filter is a common interface for crypt filter methods.
type Filter interface{
@ -31,78 +73,36 @@ HandlerVersion ()(V ,R int );
// MakeKey generates a object encryption key based on file encryption key and object numbers.
// Used only for legacy filters - AESV3 doesn't change the key for each object.
MakeKey (_ge ,_bfga uint32 ,_gab []byte )([]byte ,error );
MakeKey (_eee ,_gfgc uint32 ,_gcf []byte )([]byte ,error );
// EncryptBytes encrypts a buffer using object encryption key, as returned by MakeKey.
// Implementation may reuse a buffer and encrypt data in-place.
EncryptBytes (_gdf []byte ,_fbg []byte )([]byte ,error );
EncryptBytes (_gga []byte ,_ga []byte )([]byte ,error );
// DecryptBytes decrypts a buffer using object encryption key, as returned by MakeKey.
// Implementation may reuse a buffer and decrypt data in-place.
DecryptBytes (_fec []byte ,_db []byte )([]byte ,error );};
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};
DecryptBytes (_ffd []byte ,_eb []byte )([]byte ,error );};var _ Filter =filterAESV3 {};
// HandlerVersion implements Filter interface.
func (_dde filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func _ff (_ab FilterDict )(Filter ,error ){if _ab .Length %8!=0{return nil ,_f .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_ab .Length );};if _ab .Length < 5||_ab .Length > 16{if _ab .Length ==40||_ab .Length ==64||_ab .Length ==128{_d .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_ab .Length );_ab .Length /=8;}else {return nil ,_f .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_ab .Length );};};return filterV2 {_ed :_ab .Length },nil ;};type filterAESV2 struct{filterAES };func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
func (_cga filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };type filterFunc func (_fcf FilterDict )(Filter ,error );type filterV2 struct{_fec int };
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ea ,_gge :=_be .NewCipher (okey );if _gge !=nil {return nil ,_gge ;};_d .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ea .XORKeyStream (buf ,buf );_d .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func init (){_dff ("\u0041\u0045\u0053V\u0033",_da )};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bc ,_cg :=_e .NewCipher (okey );if _cg !=nil {return nil ,_cg ;};if len (buf )< 16{_d .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_f .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_af :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_d .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_af ),_af );_d .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_f .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_bfd :=_c .NewCBCDecrypter (_bc ,_af );_d .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_d .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_bfd .CryptBlocks (buf ,buf );_d .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_d .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_dg :=int (buf [len (buf )-1]);if _dg > len (buf ){_d .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_dg ,len (buf ));return buf ,_f .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_dg ];return buf ,nil ;};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};type filterAESV3 struct{filterAES };
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fda ,_fc :=_e .NewCipher (okey );if _fc !=nil {return nil ,_fc ;};_d .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _ga =_e .BlockSize ;_fb :=_ga -len (buf )%_ga ;for _bfg :=0;_bfg < _fb ;_bfg ++{buf =append (buf ,byte (_fb ));};_d .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_cfd :=make ([]byte ,_ga +len (buf ));_bb :=_cfd [:_ga ];if _ ,_bg :=_b .ReadFull (_fe .Reader ,_bb );_bg !=nil {return nil ,_bg ;};_ddd :=_c .NewCBCEncrypter (_fda ,_bb );_ddd .CryptBlocks (_cfd [_ga :],buf );buf =_cfd ;_d .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func _bec (_df FilterDict )(Filter ,error ){if _df .Length ==128{_d .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_df .Length );_df .Length /=8;};if _df .Length !=0&&_df .Length !=16{return nil ,_f .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_df .Length );};return filterAESV2 {},nil ;};
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_eb ,_gd :=_da (FilterDict {});if _gd !=nil {_d .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_gd );return filterAESV3 {};};return _eb ;};func _fff (_bbg ,_bgb uint32 ,_ceb []byte ,_bbc bool )([]byte ,error ){_beb :=make ([]byte ,len (_ceb )+5);for _dgb :=0;_dgb < len (_ceb );_dgb ++{_beb [_dgb ]=_ceb [_dgb ];};for _abe :=0;_abe < 3;_abe ++{_cd :=byte ((_bbg >>uint32 (8*_abe ))&0xff);_beb [_abe +len (_ceb )]=_cd ;};for _ba :=0;_ba < 2;_ba ++{_ae :=byte ((_bgb >>uint32 (8*_ba ))&0xff);_beb [_ba +len (_ceb )+3]=_ae ;};if _bbc {_beb =append (_beb ,0x73);_beb =append (_beb ,0x41);_beb =append (_beb ,0x6C);_beb =append (_beb ,0x54);};_cebb :=_fd .New ();_cebb .Write (_beb );_ca :=_cebb .Sum (nil );if len (_ceb )+5< 16{return _ca [0:len (_ceb )+5],nil ;};return _ca ,nil ;};
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};func (filterIdentity )KeyLength ()int {return 0};func init (){_dff ("\u0056\u0032",_ff )};func _dff (_gfb string ,_cef filterFunc ){if _ ,_bfc :=_agb [_gfb ];_bfc {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_agb [_gfb ]=_cef ;};var _ Filter =filterAESV3 {};var _ Filter =filterAESV2 {};
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _fff (objNum ,genNum ,ekey ,true );};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_beg ,_gg :=_be .NewCipher (okey );if _gg !=nil {return nil ,_gg ;};_d .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_beg .XORKeyStream (buf ,buf );_d .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};type filterAES struct{};type filterIdentity struct{};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _dd .AuthEvent ;Length int ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };var (_agb =make (map[string ]filterFunc ););
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func _da (_ad FilterDict )(Filter ,error ){if _ad .Length ==256{_d .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_ad .Length );_ad .Length /=8;};if _ad .Length !=0&&_ad .Length !=32{return nil ,_f .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_ad .Length );};return filterAESV3 {},nil ;};type filterV2 struct{_ed int };type filterFunc func (_de FilterDict )(Filter ,error );
func NewFilterAESV3 ()Filter {_adg ,_ge :=_ade (FilterDict {});if _ge !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ge );return filterAESV3 {};};return _adg ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func _bda (_gff string ,_efb filterFunc ){if _ ,_bfc :=_gba [_gff ];_bfc {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_gba [_gff ]=_efb ;};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_ffa ,_adf :=_dgg (d .CFM );if _adf !=nil {return nil ,_adf ;};_gf ,_adf :=_ffa (d );if _adf !=nil {return nil ,_adf ;};return _gf ,nil ;};var _ Filter =filterV2 {};
func NewFilter (d FilterDict )(Filter ,error ){_cge ,_cbd :=_fgf (d .CFM );if _cbd !=nil {return nil ,_cbd ;};_gbf ,_cbd :=_cge (d );if _cbd !=nil {return nil ,_cbd ;};return _gbf ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _gfg (_db ,_fff uint32 ,_gfge []byte ,_cb bool )([]byte ,error ){_bcb :=make ([]byte ,len (_gfge )+5);for _de :=0;_de < len (_gfge );_de ++{_bcb [_de ]=_gfge [_de ];};for _cf :=0;_cf < 3;_cf ++{_cda :=byte ((_db >>uint32 (8*_cf ))&0xff);_bcb [_cf +len (_gfge )]=_cda ;};for _fe :=0;_fe < 2;_fe ++{_bb :=byte ((_fff >>uint32 (8*_fe ))&0xff);_bcb [_fe +len (_gfge )+3]=_bb ;};if _cb {_bcb =append (_bcb ,0x73);_bcb =append (_bcb ,0x41);_bcb =append (_bcb ,0x6C);_bcb =append (_bcb ,0x54);};_ead :=_d .New ();_ead .Write (_bcb );_fcc :=_ead .Sum (nil );if len (_gfge )+5< 16{return _fcc [0:len (_gfge )+5],nil ;};return _fcc ,nil ;};type filterIdentity struct{};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_cea ,_cbd :=_ff (FilterDict {Length :length });if _cbd !=nil {_d .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_cbd );return filterV2 {_ed :length };};return _cea ;};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_cf ,_gc :=_bec (FilterDict {});if _gc !=nil {_d .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_gc );return filterAESV2 {};};return _cf ;};
// PDFVersion implements Filter interface.
func (_ec filterV2 )PDFVersion ()[2]int {return [2]int {}};
// MakeKey implements Filter interface.
func (_cgg filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _fff (objNum ,genNum ,ekey ,false );};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gb ,_aaa :=_aa .NewCipher (okey );if _aaa !=nil {return nil ,_aaa ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_gb .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func _dgg (_eg string )(filterFunc ,error ){_cbdb :=_agb [string (_eg )];if _cbdb ==nil {return nil ,_f .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_eg );};return _cbdb ,nil ;};
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
// KeyLength implements Filter interface.
func (_bce filterV2 )KeyLength ()int {return _bce ._ed };
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};type filterAESV3 struct{filterAES };func _cg (_be FilterDict )(Filter ,error ){if _be .Length %8!=0{return nil ,_g .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_be .Length );};if _be .Length < 5||_be .Length > 16{if _be .Length ==40||_be .Length ==64||_be .Length ==128{_ee .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_be .Length );_be .Length /=8;}else {return nil ,_g .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_be .Length );};};return filterV2 {_fec :_be .Length },nil ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_bde ,_cde :=_cg (FilterDict {Length :length });if _cde !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_cde );return filterV2 {_fec :length };};return _bde ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,28 +10,28 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package fjson provides support for loading PDF form field data from JSON data/files.
package fjson ;import (_a "encoding/json";_ca "github.com/unidoc/unipdf/v3/core";_eg "github.com/unidoc/unipdf/v3/model";_e "io";_c "os";);type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
package fjson ;import (_e "encoding/json";_fe "github.com/unidoc/unipdf/v3/core";_fb "github.com/unidoc/unipdf/v3/model";_f "io";_aa "os";);type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
// Options lists allowed values if present.
Options []string `json:"options,omitempty"`;};
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_b []fieldValue };
// LoadFromJSON loads JSON form data from `r`.
func LoadFromJSON (r _e .Reader )(*FieldData ,error ){var _ce FieldData ;_bd :=_a .NewDecoder (r ).Decode (&_ce ._b );if _bd !=nil {return nil ,_bd ;};return &_ce ,nil ;};
func LoadFromJSON (r _f .Reader )(*FieldData ,error ){var _d FieldData ;_ea :=_e .NewDecoder (r ).Decode (&_d ._c );if _ea !=nil {return nil ,_ea ;};return &_d ,nil ;};
// FieldValues implements model.FieldValueProvider interface.
func (_fa *FieldData )FieldValues ()(map[string ]_ca .PdfObject ,error ){_bff :=make (map[string ]_ca .PdfObject );for _ ,_ccd :=range _fa ._b {if len (_ccd .Value )> 0{_bff [_ccd .Name ]=_ca .MakeString (_ccd .Value );};};return _bff ,nil ;};
// JSON returns the field data as a string in JSON format.
func (_gd FieldData )JSON ()(string ,error ){_gge ,_ded :=_a .MarshalIndent (_gd ._b ,"","\u0020\u0020\u0020\u0020");return string (_gge ),_ded ;};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _e .ReadSeeker )(*FieldData ,error ){_cef ,_d :=_eg .NewPdfReader (rs );if _d !=nil {return nil ,_d ;};if _cef .AcroForm ==nil {return nil ,nil ;};var _f []fieldValue ;_de :=_cef .AcroForm .AllFields ();for _ ,_ga :=range _de {var _dc []string ;_bg :=make (map[string ]struct{});_ab ,_gg :=_ga .FullName ();if _gg !=nil {return nil ,_gg ;};if _ag ,_cb :=_ga .V .(*_ca .PdfObjectString );_cb {_f =append (_f ,fieldValue {Name :_ab ,Value :_ag .Decoded ()});continue ;};var _ge string ;for _ ,_cg :=range _ga .Annotations {_fc ,_af :=_ca .GetName (_cg .AS );if _af {_ge =_fc .String ();};_egc ,_abf :=_ca .GetDict (_cg .AP );if !_abf {continue ;};_ef ,_ :=_ca .GetDict (_egc .Get ("\u004e"));for _ ,_gf :=range _ef .Keys (){_bba :=_gf .String ();if _ ,_fe :=_bg [_bba ];!_fe {_dc =append (_dc ,_bba );_bg [_bba ]=struct{}{};};};_ac ,_ :=_ca .GetDict (_egc .Get ("\u0044"));for _ ,_ae :=range _ac .Keys (){_ec :=_ae .String ();if _ ,_fbg :=_bg [_ec ];!_fbg {_dc =append (_dc ,_ec );_bg [_ec ]=struct{}{};};};};_gaf :=fieldValue {Name :_ab ,Value :_ge ,Options :_dc };_f =append (_f ,_gaf );};_cfe :=FieldData {_b :_f };return &_cfe ,nil ;};
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_c []fieldValue };
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_gc ,_bb :=_c .Open (filePath );if _bb !=nil {return nil ,_bb ;};defer _gc .Close ();return LoadFromJSON (_gc );};
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_df ,_cb :=_aa .Open (filePath );if _cb !=nil {return nil ,_cb ;};defer _df .Close ();return LoadFromJSON (_df );};
// FieldValues implements model.FieldValueProvider interface.
func (_ee *FieldData )FieldValues ()(map[string ]_fe .PdfObject ,error ){_ae :=make (map[string ]_fe .PdfObject );for _ ,_dd :=range _ee ._c {if len (_dd .Value )> 0{_ae [_dd .Name ]=_fe .MakeString (_dd .Value );};};return _ae ,nil ;};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_cc ,_da :=_c .Open (filePath );if _da !=nil {return nil ,_da ;};defer _cc .Close ();return LoadFromPDF (_cc );};
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_ag ,_acc :=_aa .Open (filePath );if _acc !=nil {return nil ,_acc ;};defer _ag .Close ();return LoadFromPDF (_ag );};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _f .ReadSeeker )(*FieldData ,error ){_dfd ,_cf :=_fb .NewPdfReader (rs );if _cf !=nil {return nil ,_cf ;};if _dfd .AcroForm ==nil {return nil ,nil ;};var _g []fieldValue ;_b :=_dfd .AcroForm .AllFields ();for _ ,_be :=range _b {var _fd []string ;_cd :=make (map[string ]struct{});_de ,_gb :=_be .FullName ();if _gb !=nil {return nil ,_gb ;};if _cdf ,_gd :=_be .V .(*_fe .PdfObjectString );_gd {_g =append (_g ,fieldValue {Name :_de ,Value :_cdf .Decoded ()});continue ;};var _ec string ;for _ ,_cff :=range _be .Annotations {_cbf ,_gc :=_fe .GetName (_cff .AS );if _gc {_ec =_cbf .String ();};_ecb ,_ac :=_fe .GetDict (_cff .AP );if !_ac {continue ;};_cc ,_ :=_fe .GetDict (_ecb .Get ("\u004e"));for _ ,_cbg :=range _cc .Keys (){_fef :=_cbg .String ();if _ ,_ccb :=_cd [_fef ];!_ccb {_fd =append (_fd ,_fef );_cd [_fef ]=struct{}{};};};_bb ,_ :=_fe .GetDict (_ecb .Get ("\u0044"));for _ ,_fde :=range _bb .Keys (){_gdf :=_fde .String ();if _ ,_ff :=_cd [_gdf ];!_ff {_fd =append (_fd ,_gdf );_cd [_gdf ]=struct{}{};};};};_bd :=fieldValue {Name :_de ,Value :_ec ,Options :_fd };_g =append (_g ,_bd );};_aae :=FieldData {_c :_g };return &_aae ,nil ;};
// JSON returns the field data as a string in JSON format.
func (_ecc FieldData )JSON ()(string ,error ){_eae ,_def :=_e .MarshalIndent (_ecc ._c ,"","\u0020\u0020\u0020\u0020");return string (_eae ),_def ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
// 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 endian ;import (_gb "encoding/binary";_b "unsafe";);func IsBig ()bool {return _a };func init (){const _bc =int (_b .Sizeof (0));_c :=1;_cg :=(*[_bc ]byte )(_b .Pointer (&_c ));if _cg [0]==0{_a =true ;ByteOrder =_gb .BigEndian ;}else {ByteOrder =_gb .LittleEndian ;};};var (ByteOrder _gb .ByteOrder ;_a bool ;);func IsLittle ()bool {return !_a };
package endian ;import (_g "encoding/binary";_gd "unsafe";);var (ByteOrder _g .ByteOrder ;_c bool ;);func init (){const _fb =int (_gd .Sizeof (0));_df :=1;_a :=(*[_fb ]byte )(_gd .Pointer (&_df ));if _a [0]==0{_c =true ;ByteOrder =_g .BigEndian ;}else {ByteOrder =_g .LittleEndian ;};};func IsBig ()bool {return _c };func IsLittle ()bool {return !_c };

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
// 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 basic ;import _a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func (_ab IntsMap )Delete (key uint64 ){delete (_ab ,key )};func (_fd *Stack )Peek ()(_ce interface{},_dc bool ){return _fd .peek ()};func Abs (v int )int {if v > 0{return v ;};return -v ;};type IntsMap map[uint64 ][]int ;func NewIntSlice (i int )*IntSlice {_ef :=IntSlice (make ([]int ,i ));return &_ef };func (_ea *IntSlice )Copy ()*IntSlice {_ee :=IntSlice (make ([]int ,len (*_ea )));copy (_ee ,*_ea );return &_ee ;};func (_gf *IntSlice )Add (v int )error {if _gf ==nil {return _a .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_gf =append (*_gf ,v );return nil ;};func (_db IntSlice )Get (index int )(int ,error ){if index > len (_db )-1{return 0,_a .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _db [index ],nil ;};type Stack struct{Data []interface{};Aux *Stack ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_gffg *Stack )top ()int {return len (_gffg .Data )-1};func (_d IntsMap )Get (key uint64 )(int ,bool ){_fg ,_dd :=_d [key ];if !_dd {return 0,false ;};if len (_fg )==0{return 0,false ;};return _fg [0],true ;};func (_g IntsMap )GetSlice (key uint64 )([]int ,bool ){_de ,_e :=_g [key ];if !_e {return nil ,false ;};return _de ,true ;};func (_dde *Stack )Pop ()(_bca interface{},_df bool ){_bca ,_df =_dde .peek ();if !_df {return nil ,_df ;};_dde .Data =_dde .Data [:_dde .top ()];return _bca ,true ;};func (_cg *NumSlice )AddInt (v int ){*_cg =append (*_cg ,float32 (v ))};func (_dg *Stack )peek ()(interface{},bool ){_aeg :=_dg .top ();if _aeg ==-1{return nil ,false ;};return _dg .Data [_aeg ],true ;};func (_f IntsMap )Add (key uint64 ,value int ){_f [key ]=append (_f [key ],value )};func (_ad NumSlice )GetIntSlice ()[]int {_bg :=make ([]int ,len (_ad ));for _fgd ,_da :=range _ad {_bg [_fgd ]=int (_da );};return _bg ;};func (_cc *Stack )Len ()int {return len (_cc .Data )};type NumSlice []float32 ;func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_gff NumSlice )GetInt (i int )(int ,error ){const _fb ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_gff )-1{return 0,_a .Errorf (_fb ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_ga :=_gff [i ];return int (_ga +Sign (_ga )*0.5),nil ;};func (_bc *NumSlice )Add (v float32 ){*_bc =append (*_bc ,v )};func (_ff IntSlice )Size ()int {return len (_ff )};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_gc NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_gc )-1{return 0,_a .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _gc [i ],nil ;};func (_ae *Stack )Push (v interface{}){_ae .Data =append (_ae .Data ,v )};type IntSlice []int ;func NewNumSlice (i int )*NumSlice {_b :=NumSlice (make ([]float32 ,i ));return &_b };
package basic ;import _da "github.com/unidoc/unipdf/v3/internal/jbig2/errors";type Stack struct{Data []interface{};Aux *Stack ;};func (_gf IntSlice )Get (index int )(int ,error ){if index > len (_gf )-1{return 0,_da .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _gf [index ],nil ;};func (_ac NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ac )-1{return 0,_da .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _ac [i ],nil ;};func NewNumSlice (i int )*NumSlice {_ed :=NumSlice (make ([]float32 ,i ));return &_ed };func (_ee IntSlice )Size ()int {return len (_ee )};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_eeb NumSlice )GetIntSlice ()[]int {_cdd :=make ([]int ,len (_eeb ));for _gg ,_bb :=range _eeb {_cdd [_gg ]=int (_bb );};return _cdd ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_ad NumSlice )GetInt (i int )(int ,error ){const _fd ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_ad )-1{return 0,_da .Errorf (_fd ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cb :=_ad [i ];return int (_cb +Sign (_cb )*0.5),nil ;};func (_dcb *Stack )Pop ()(_gd interface{},_gfa bool ){_gd ,_gfa =_dcb .peek ();if !_gfa {return nil ,_gfa ;};_dcb .Data =_dcb .Data [:_dcb .top ()];return _gd ,true ;};func (_cd *NumSlice )Add (v float32 ){*_cd =append (*_cd ,v )};func (_ged *Stack )Push (v interface{}){_ged .Data =append (_ged .Data ,v )};type IntsMap map[uint64 ][]int ;func (_gb IntsMap )Delete (key uint64 ){delete (_gb ,key )};func (_b *IntSlice )Copy ()*IntSlice {_dc :=IntSlice (make ([]int ,len (*_b )));copy (_dc ,*_b );return &_dc ;};func (_ab *Stack )top ()int {return len (_ab .Data )-1};func (_e IntsMap )Add (key uint64 ,value int ){_e [key ]=append (_e [key ],value )};func (_gbc *Stack )Len ()int {return len (_gbc .Data )};func Min (x ,y int )int {if x < y {return x ;};return y ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_bd *Stack )peek ()(interface{},bool ){_cbg :=_bd .top ();if _cbg ==-1{return nil ,false ;};return _bd .Data [_cbg ],true ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_fc IntsMap )GetSlice (key uint64 )([]int ,bool ){_a ,_dad :=_fc [key ];if !_dad {return nil ,false ;};return _a ,true ;};type IntSlice []int ;func NewIntSlice (i int )*IntSlice {_dg :=IntSlice (make ([]int ,i ));return &_dg };func (_ff *IntSlice )Add (v int )error {if _ff ==nil {return _da .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_ff =append (*_ff ,v );return nil ;};func (_fdd *Stack )Peek ()(_be interface{},_eee bool ){return _fdd .peek ()};func (_f IntsMap )Get (key uint64 )(int ,bool ){_g ,_c :=_f [key ];if !_c {return 0,false ;};if len (_g )==0{return 0,false ;};return _g [0],true ;};func (_ge *NumSlice )AddInt (v int ){*_ge =append (*_ge ,float32 (v ))};type NumSlice []float32 ;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
// 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 decoder ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_ae "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_f "github.com/unidoc/unipdf/v3/internal/jbig2/document";_ad "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "image";);func (_cd *Decoder )PageNumber ()(int ,error ){const _af ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _cd ._gd ==nil {return 0,_ad .Error (_af ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_cd ._gd .NumberOfPages ),nil ;};func (_cc *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _cc .decodePage (pageNumber )};type Parameters struct{UnpaddedData bool ;Color _ae .Color ;};func (_db *Decoder )decodePage (_cb int )([]byte ,error ){const _gee ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _cb < 0{return nil ,_ad .Errorf (_gee ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_cb );};if _cb > int (_db ._gd .NumberOfPages ){return nil ,_ad .Errorf (_gee ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_cb );};_ec ,_dd :=_db ._gd .GetPage (_cb );if _dd !=nil {return nil ,_ad .Wrap (_dd ,_gee ,"");};_ada ,_dd :=_ec .GetBitmap ();if _dd !=nil {return nil ,_ad .Wrap (_dd ,_gee ,"");};_ada .InverseData ();if !_db ._e .UnpaddedData {return _ada .Data ,nil ;};return _ada .GetUnpaddedData ();};func (_ed *Decoder )DecodeNextPage ()([]byte ,error ){_ed ._fc ++;_ge :=_ed ._fc ;return _ed .decodePage (_ge );};func Decode (input []byte ,parameters Parameters ,globals *_f .Globals )(*Decoder ,error ){_fa :=_g .NewReader (input );_gb ,_fb :=_f .DecodeDocument (_fa ,globals );if _fb !=nil {return nil ,_fb ;};return &Decoder {_c :_fa ,_gd :_gb ,_e :parameters },nil ;};func (_ac *Decoder )DecodePageImage (pageNumber int )(_a .Image ,error ){const _d ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_fe ,_ea :=_ac .decodePageImage (pageNumber );if _ea !=nil {return nil ,_ad .Wrap (_ea ,_d ,"");};return _fe ,nil ;};func (_gda *Decoder )decodePageImage (_adf int )(_a .Image ,error ){const _cg ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _adf < 0{return nil ,_ad .Errorf (_cg ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_adf );};if _adf > int (_gda ._gd .NumberOfPages ){return nil ,_ad .Errorf (_cg ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_adf );};_acd ,_fg :=_gda ._gd .GetPage (_adf );if _fg !=nil {return nil ,_ad .Wrap (_fg ,_cg ,"");};_dc ,_fg :=_acd .GetBitmap ();if _fg !=nil {return nil ,_ad .Wrap (_fg ,_cg ,"");};return _dc .ToImage (),nil ;};type Decoder struct{_c _g .StreamReader ;_gd *_f .Document ;_fc int ;_e Parameters ;};
package decoder ;import (_c "github.com/unidoc/unipdf/v3/internal/bitwise";_e "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_b "github.com/unidoc/unipdf/v3/internal/jbig2/document";_f "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "image";);func (_bf *Decoder )DecodePageImage (pageNumber int )(_a .Image ,error ){const _fa ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bg ,_gb :=_bf .decodePageImage (pageNumber );if _gb !=nil {return nil ,_f .Wrap (_gb ,_fa ,"");};return _bg ,nil ;};func (_ga *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _ga .decodePage (pageNumber )};type Parameters struct{UnpaddedData bool ;Color _e .Color ;};type Decoder struct{_d _c .StreamReader ;_fg *_b .Document ;_ae int ;_eb Parameters ;};func (_ac *Decoder )PageNumber ()(int ,error ){const _af ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _ac ._fg ==nil {return 0,_f .Error (_af ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_ac ._fg .NumberOfPages ),nil ;};func (_aff *Decoder )decodePage (_ad int )([]byte ,error ){const _be ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _ad < 0{return nil ,_f .Errorf (_be ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_ad );};if _ad > int (_aff ._fg .NumberOfPages ){return nil ,_f .Errorf (_be ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_ad );};_fd ,_adb :=_aff ._fg .GetPage (_ad );if _adb !=nil {return nil ,_f .Wrap (_adb ,_be ,"");};_gd ,_adb :=_fd .GetBitmap ();if _adb !=nil {return nil ,_f .Wrap (_adb ,_be ,"");};_gd .InverseData ();if !_aff ._eb .UnpaddedData {return _gd .Data ,nil ;};return _gd .GetUnpaddedData ();};func (_fb *Decoder )DecodeNextPage ()([]byte ,error ){_fb ._ae ++;_gg :=_fb ._ae ;return _fb .decodePage (_gg );};func (_ca *Decoder )decodePageImage (_bc int )(_a .Image ,error ){const _da ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _bc < 0{return nil ,_f .Errorf (_da ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_bc );};if _bc > int (_ca ._fg .NumberOfPages ){return nil ,_f .Errorf (_da ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_bc );};_fe ,_dg :=_ca ._fg .GetPage (_bc );if _dg !=nil {return nil ,_f .Wrap (_dg ,_da ,"");};_fgf ,_dg :=_fe .GetBitmap ();if _dg !=nil {return nil ,_f .Wrap (_dg ,_da ,"");};return _fgf .ToImage (),nil ;};func Decode (input []byte ,parameters Parameters ,globals *_b .Globals )(*Decoder ,error ){_ada :=_c .NewReader (input );_fad ,_gc :=_b .DecodeDocument (_ada ,globals );if _gc !=nil {return nil ,_gc ;};return &Decoder {_d :_ada ,_fg :_fad ,_eb :parameters },nil ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
// 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 errors ;import _ef "fmt";type processError struct{_eg string ;_f string ;_g string ;_ff error ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _a (_ef .Sprintf (message ,arguments ...),processName );};func (_c *processError )Error ()string {var _b string ;if _c ._eg !=""{_b =_c ._eg ;};_b +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_c ._f ;if _c ._g !=""{_b +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_c ._g ;};if _c ._ff !=nil {_b +="\u002e\u0020"+_c ._ff .Error ();};return _b ;};func Wrap (err error ,processName ,message string )error {if _fa ,_ec :=err .(*processError );_ec {_fa ._eg ="";};_cf :=_a (message ,processName );_cf ._ff =err ;return _cf ;};func _a (_ae ,_af string )*processError {return &processError {_eg :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_g :_ae ,_f :_af };};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _gc ,_fd :=err .(*processError );_fd {_gc ._eg ="";};_ag :=_a (_ef .Sprintf (message ,arguments ...),processName );_ag ._ff =err ;return _ag ;};func Error (processName ,message string )error {return _a (message ,processName )};
package errors ;import _g "fmt";func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _fb ,_ba :=err .(*processError );_ba {_fb ._d ="";};_fbg :=_dd (_g .Sprintf (message ,arguments ...),processName );_fbg ._a =err ;return _fbg ;};func Wrap (err error ,processName ,message string )error {if _dg ,_ee :=err .(*processError );_ee {_dg ._d ="";};_ec :=_dd (message ,processName );_ec ._a =err ;return _ec ;};type processError struct{_d string ;_e string ;_f string ;_a error ;};func Error (processName ,message string )error {return _dd (message ,processName )};func (_da *processError )Error ()string {var _c string ;if _da ._d !=""{_c =_da ._d ;};_c +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_da ._e ;if _da ._f !=""{_c +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_da ._f ;};if _da ._a !=nil {_c +="\u002e\u0020"+_da ._a .Error ();};return _c ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _dd (_g .Sprintf (message ,arguments ...),processName );};func _dd (_df ,_bf string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_f :_df ,_e :_bf };};

View File

@ -9,4 +9,4 @@
// 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 jbig2 ;import (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_bf "github.com/unidoc/unipdf/v3/internal/jbig2/document";_be "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_ba "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_g "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _c ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_ec :=_b .NewReader (encoded );_ca ,_ece :=_bf .DecodeDocument (_ec ,nil );if _ece !=nil {return nil ,_ba .Wrap (_ece ,_c ,"");};if _ca .GlobalSegments ==nil ||(_ca .GlobalSegments .Segments ==nil ){return nil ,_ba .Error (_c ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_db :=Globals {};for _ ,_bab :=range _ca .GlobalSegments .Segments {_db [int (_bab .SegmentNumber )]=_bab ;};return _db ,nil ;};func DecodeBytes (encoded []byte ,parameters _a .Parameters ,globals ...Globals )([]byte ,error ){var _f Globals ;if len (globals )> 0{_f =globals [0];};_d ,_gc :=_a .Decode (encoded ,parameters ,_f .ToDocumentGlobals ());if _gc !=nil {return nil ,_gc ;};return _d .DecodeNextPage ();};func (_fb Globals )ToDocumentGlobals ()*_bf .Globals {if _fb ==nil {return nil ;};_bfe :=[]*_be .Header {};for _ ,_fg :=range _fb {_bfe =append (_bfe ,_fg );};_g .Slice (_bfe ,func (_ee ,_ce int )bool {return _bfe [_ee ].SegmentNumber < _bfe [_ce ].SegmentNumber });return &_bf .Globals {Segments :_bfe };};type Globals map[int ]*_be .Header ;
package jbig2 ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_df "github.com/unidoc/unipdf/v3/internal/jbig2/document";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_da "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_b "sort";);type Globals map[int ]*_c .Header ;func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _bd Globals ;if len (globals )> 0{_bd =globals [0];};_e ,_gd :=_d .Decode (encoded ,parameters ,_bd .ToDocumentGlobals ());if _gd !=nil {return nil ,_gd ;};return _e .DecodeNextPage ();};func DecodeGlobals (encoded []byte )(Globals ,error ){const _dc ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_a :=_g .NewReader (encoded );_bdd ,_ed :=_df .DecodeDocument (_a ,nil );if _ed !=nil {return nil ,_da .Wrap (_ed ,_dc ,"");};if _bdd .GlobalSegments ==nil ||(_bdd .GlobalSegments .Segments ==nil ){return nil ,_da .Error (_dc ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_ec :=Globals {};for _ ,_de :=range _bdd .GlobalSegments .Segments {_ec [int (_de .SegmentNumber )]=_de ;};return _ec ,nil ;};func (_af Globals )ToDocumentGlobals ()*_df .Globals {if _af ==nil {return nil ;};_eb :=[]*_c .Header {};for _ ,_ee :=range _af {_eb =append (_eb ,_ee );};_b .Slice (_eb ,func (_ae ,_bg int )bool {return _eb [_ae ].SegmentNumber < _eb [_bg ].SegmentNumber });return &_df .Globals {Segments :_eb };};

View File

@ -9,4 +9,4 @@
// 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 sampling ;import (_cb "github.com/unidoc/unipdf/v3/internal/bitwise";_bb "github.com/unidoc/unipdf/v3/internal/imageutil";_c "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _ec []uint32 ;_bfg :=bitsPerOutputSample ;var _bg uint32 ;var _a uint32 ;_af :=0;_fdb :=0;_cef :=0;for _cef < len (data ){if _af > 0{_gfe :=_af ;if _bfg < _gfe {_gfe =_bfg ;};_bg =(_bg <<uint (_gfe ))|uint32 (_a >>uint (bitsPerInputSample -_gfe ));_af -=_gfe ;if _af > 0{_a =_a <<uint (_gfe );}else {_a =0;};_bfg -=_gfe ;if _bfg ==0{_ec =append (_ec ,_bg );_bfg =bitsPerOutputSample ;_bg =0;_fdb ++;};}else {_db :=data [_cef ];_cef ++;_ca :=bitsPerInputSample ;if _bfg < _ca {_ca =_bfg ;};_af =bitsPerInputSample -_ca ;_bg =(_bg <<uint (_ca ))|uint32 (_db >>uint (_af ));if _ca < bitsPerInputSample {_a =_db <<uint (_ca );};_bfg -=_ca ;if _bfg ==0{_ec =append (_ec ,_bg );_bfg =bitsPerOutputSample ;_bg =0;_fdb ++;};};};for _af >=bitsPerOutputSample {_ecd :=_af ;if _bfg < _ecd {_ecd =_bfg ;};_bg =(_bg <<uint (_ecd ))|uint32 (_a >>uint (bitsPerInputSample -_ecd ));_af -=_ecd ;if _af > 0{_a =_a <<uint (_ecd );}else {_a =0;};_bfg -=_ecd ;if _bfg ==0{_ec =append (_ec ,_bg );_bfg =bitsPerOutputSample ;_bg =0;_fdb ++;};};if _bfg > 0&&_bfg < bitsPerOutputSample {_bg <<=uint (_bfg );_ec =append (_ec ,_bg );};return _ec ;};func (_gcf *Reader )ReadSamples (samples []uint32 )(_cfe error ){for _bc :=0;_bc < len (samples );_bc ++{samples [_bc ],_cfe =_gcf .ReadSample ();if _cfe !=nil {return _cfe ;};};return nil ;};type SampleWriter interface{WriteSample (_ee uint32 )error ;WriteSamples (_ef []uint32 )error ;};func (_bbe *Writer )WriteSamples (samples []uint32 )error {for _bfe :=0;_bfe < len (samples );_bfe ++{if _fa :=_bbe .WriteSample (samples [_bfe ]);_fa !=nil {return _fa ;};};return nil ;};func (_bca *Writer )WriteSample (sample uint32 )error {if _ ,_bgb :=_bca ._fe .WriteBits (uint64 (sample ),_bca ._ac .BitsPerComponent );_bgb !=nil {return _bgb ;};_bca ._aa --;if _bca ._aa ==0{_bca ._aa =_bca ._ac .ColorComponents ;_bca ._ge ++;};if _bca ._ge ==_bca ._ac .Width {if _bca ._fg {_bca ._fe .FinishByte ();};_bca ._ge =0;};return nil ;};func NewReader (img _bb .ImageBase )*Reader {return &Reader {_da :_cb .NewReader (img .Data ),_d :img ,_gc :img .ColorComponents ,_be :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_f *Reader )ReadSample ()(uint32 ,error ){if _f ._g ==_f ._d .Height {return 0,_c .EOF ;};_ced ,_cf :=_f ._da .ReadBits (byte (_f ._d .BitsPerComponent ));if _cf !=nil {return 0,_cf ;};_f ._gc --;if _f ._gc ==0{_f ._gc =_f ._d .ColorComponents ;_f ._bf ++;};if _f ._bf ==_f ._d .Width {if _f ._be {_f ._da .ConsumeRemainingBits ();};_f ._bf =0;_f ._g ++;};return uint32 (_ced ),nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ce []uint32 )error ;};type Reader struct{_d _bb .ImageBase ;_da *_cb .Reader ;_bf ,_g ,_gc int ;_be bool ;};type Writer struct{_ac _bb .ImageBase ;_fe *_cb .Writer ;_ge ,_aa int ;_fg bool ;};func NewWriter (img _bb .ImageBase )*Writer {return &Writer {_fe :_cb .NewWriterMSB (img .Data ),_ac :img ,_aa :img .ColorComponents ,_fg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _beg []uint32 ;_cg :=bitsPerSample ;var _gf uint32 ;var _fd byte ;_bff :=0;_daa :=0;_e :=0;for _e < len (data ){if _bff > 0{_eg :=_bff ;if _cg < _eg {_eg =_cg ;};_gf =(_gf <<uint (_eg ))|uint32 (_fd >>uint (8-_eg ));_bff -=_eg ;if _bff > 0{_fd =_fd <<uint (_eg );}else {_fd =0;};_cg -=_eg ;if _cg ==0{_beg =append (_beg ,_gf );_cg =bitsPerSample ;_gf =0;_daa ++;};}else {_gcg :=data [_e ];_e ++;_dac :=8;if _cg < _dac {_dac =_cg ;};_bff =8-_dac ;_gf =(_gf <<uint (_dac ))|uint32 (_gcg >>uint (_bff ));if _dac < 8{_fd =_gcg <<uint (_dac );};_cg -=_dac ;if _cg ==0{_beg =append (_beg ,_gf );_cg =bitsPerSample ;_gf =0;_daa ++;};};};for _bff >=bitsPerSample {_ceg :=_bff ;if _cg < _ceg {_ceg =_cg ;};_gf =(_gf <<uint (_ceg ))|uint32 (_fd >>uint (8-_ceg ));_bff -=_ceg ;if _bff > 0{_fd =_fd <<uint (_ceg );}else {_fd =0;};_cg -=_ceg ;if _cg ==0{_beg =append (_beg ,_gf );_cg =bitsPerSample ;_gf =0;_daa ++;};};return _beg ;};
package sampling ;import (_a "github.com/unidoc/unipdf/v3/internal/bitwise";_dc "github.com/unidoc/unipdf/v3/internal/imageutil";_f "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _bb []uint32 ;_ab :=bitsPerOutputSample ;var _gg uint32 ;var _df uint32 ;_fad :=0;_dbb :=0;_gc :=0;for _gc < len (data ){if _fad > 0{_dba :=_fad ;if _ab < _dba {_dba =_ab ;};_gg =(_gg <<uint (_dba ))|uint32 (_df >>uint (bitsPerInputSample -_dba ));_fad -=_dba ;if _fad > 0{_df =_df <<uint (_dba );}else {_df =0;};_ab -=_dba ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};}else {_bg :=data [_gc ];_gc ++;_fec :=bitsPerInputSample ;if _ab < _fec {_fec =_ab ;};_fad =bitsPerInputSample -_fec ;_gg =(_gg <<uint (_fec ))|uint32 (_bg >>uint (_fad ));if _fec < bitsPerInputSample {_df =_bg <<uint (_fec );};_ab -=_fec ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};};};for _fad >=bitsPerOutputSample {_ace :=_fad ;if _ab < _ace {_ace =_ab ;};_gg =(_gg <<uint (_ace ))|uint32 (_df >>uint (bitsPerInputSample -_ace ));_fad -=_ace ;if _fad > 0{_df =_df <<uint (_ace );}else {_df =0;};_ab -=_ace ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};};if _ab > 0&&_ab < bitsPerOutputSample {_gg <<=uint (_ab );_bb =append (_bb ,_gg );};return _bb ;};func (_bd *Writer )WriteSample (sample uint32 )error {if _ ,_bac :=_bd ._ca .WriteBits (uint64 (sample ),_bd ._gf .BitsPerComponent );_bac !=nil {return _bac ;};_bd ._bbg --;if _bd ._bbg ==0{_bd ._bbg =_bd ._gf .ColorComponents ;_bd ._ff ++;};if _bd ._ff ==_bd ._gf .Width {if _bd ._ef {_bd ._ca .FinishByte ();};_bd ._ff =0;};return nil ;};func NewReader (img _dc .ImageBase )*Reader {return &Reader {_fb :_a .NewReader (img .Data ),_c :img ,_fe :img .ColorComponents ,_cg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_da *Writer )WriteSamples (samples []uint32 )error {for _bf :=0;_bf < len (samples );_bf ++{if _cf :=_da .WriteSample (samples [_bf ]);_cf !=nil {return _cf ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ee []uint32 ;_eea :=bitsPerSample ;var _g uint32 ;var _ba byte ;_fa :=0;_ec :=0;_afb :=0;for _afb < len (data ){if _fa > 0{_fc :=_fa ;if _eea < _fc {_fc =_eea ;};_g =(_g <<uint (_fc ))|uint32 (_ba >>uint (8-_fc ));_fa -=_fc ;if _fa > 0{_ba =_ba <<uint (_fc );}else {_ba =0;};_eea -=_fc ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};}else {_fg :=data [_afb ];_afb ++;_bc :=8;if _eea < _bc {_bc =_eea ;};_fa =8-_bc ;_g =(_g <<uint (_bc ))|uint32 (_fg >>uint (_fa ));if _bc < 8{_ba =_fg <<uint (_bc );};_eea -=_bc ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};};};for _fa >=bitsPerSample {_aff :=_fa ;if _eea < _aff {_aff =_eea ;};_g =(_g <<uint (_aff ))|uint32 (_ba >>uint (8-_aff ));_fa -=_aff ;if _fa > 0{_ba =_ba <<uint (_aff );}else {_ba =0;};_eea -=_aff ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};};return _ee ;};type SampleWriter interface{WriteSample (_afbf uint32 )error ;WriteSamples (_afc []uint32 )error ;};type Reader struct{_c _dc .ImageBase ;_fb *_a .Reader ;_ac ,_cc ,_fe int ;_cg bool ;};func NewWriter (img _dc .ImageBase )*Writer {return &Writer {_ca :_a .NewWriterMSB (img .Data ),_gf :img ,_bbg :img .ColorComponents ,_ef :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_e []uint32 )error ;};type Writer struct{_gf _dc .ImageBase ;_ca *_a .Writer ;_ff ,_bbg int ;_ef bool ;};func (_b *Reader )ReadSample ()(uint32 ,error ){if _b ._cc ==_b ._c .Height {return 0,_f .EOF ;};_db ,_af :=_b ._fb .ReadBits (byte (_b ._c .BitsPerComponent ));if _af !=nil {return 0,_af ;};_b ._fe --;if _b ._fe ==0{_b ._fe =_b ._c .ColorComponents ;_b ._ac ++;};if _b ._ac ==_b ._c .Width {if _b ._cg {_b ._fb .ConsumeRemainingBits ();};_b ._ac =0;_b ._cc ++;};return uint32 (_db ),nil ;};func (_dg *Reader )ReadSamples (samples []uint32 )(_eg error ){for _de :=0;_de < len (samples );_de ++{samples [_de ],_eg =_dg .ReadSample ();if _eg !=nil {return _eg ;};};return nil ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,4 @@
// 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 transform ;import (_d "fmt";_g "github.com/unidoc/unipdf/v3/common";_b "math";);func (_acab *Matrix )Unrealistic ()bool {_eg ,_df ,_ec ,_cgc :=_b .Abs (_acab [0]),_b .Abs (_acab [1]),_b .Abs (_acab [3]),_b .Abs (_acab [4]);_bc :=_eg > _aef &&_cgc > _aef ;_bab :=_df > _aef &&_ec > _aef ;return !(_bc ||_bab );};type Matrix [9]float64 ;func (_ga *Matrix )ScalingFactorY ()float64 {return _b .Hypot (_ga [3],_ga [4])};func IdentityMatrix ()Matrix {return NewMatrix (1,0,0,1,0,0)};func (_de *Matrix )Clone ()Matrix {return NewMatrix (_de [0],_de [1],_de [3],_de [4],_de [6],_de [7])};func (_ab Point )Distance (b Point )float64 {return _b .Hypot (_ab .X -b .X ,_ab .Y -b .Y )};func (_bf Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_bf .X +t *b .X ,Y :(1-t )*_bf .Y +t *b .Y };};type Point struct{X float64 ;Y float64 ;};func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};func (_ag *Matrix )ScalingFactorX ()float64 {return _b .Hypot (_ag [0],_ag [1])};func (_fce Point )Displace (delta Point )Point {return Point {_fce .X +delta .X ,_fce .Y +delta .Y }};func (_ba *Matrix )Shear (x ,y float64 ){_ba .Concat (ShearMatrix (x ,y ))};func (_gc *Matrix )Rotate (angle float64 ){_gc .Concat (RotationMatrix (angle ))};func (_aa *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_aa [0],_aa [1]=a ,b ;_aa [3],_aa [4]=c ,d ;_aa [6],_aa [7]=tx ,ty ;_aa .clampRange ();};func (_bcg *Point )transformByMatrix (_fg Matrix ){_bcg .X ,_bcg .Y =_fg .Transform (_bcg .X ,_bcg .Y )};func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};const _cd =1.0e-6;func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_ad :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1};_ad .clampRange ();return _ad ;};func (_fc *Point )Set (x ,y float64 ){_fc .X ,_fc .Y =x ,y };func (_fe *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_dd :=NewMatrix (a ,b ,c ,d ,tx ,ty );_fe .transformByMatrix (_dd );};func RotationMatrix (angle float64 )Matrix {_gg :=_b .Cos (angle );_ggb :=_b .Sin (angle );return NewMatrix (_gg ,_ggb ,-_ggb ,_gg ,0,0);};const _ff =1e9;func (_bg Point )String ()string {return _d .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_bg .X ,_bg .Y );};func (_bd *Matrix )clampRange (){for _cfb ,_aca :=range _bd {if _aca > _ff {_g .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_aca ,_ff );_bd [_cfb ]=_ff ;}else if _aca < -_ff {_g .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_aca ,-_ff );_bd [_cfb ]=-_ff ;};};};func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )};func (_edd *Matrix )Angle ()float64 {_fd :=_b .Atan2 (-_edd [1],_edd [0]);if _fd < 0.0{_fd +=2*_b .Pi ;};return _fd /_b .Pi *180.0;};func (_e *Matrix )Concat (b Matrix ){*_e =Matrix {b [0]*_e [0]+b [1]*_e [3],b [0]*_e [1]+b [1]*_e [4],0,b [3]*_e [0]+b [4]*_e [3],b [3]*_e [1]+b [4]*_e [4],0,b [6]*_e [0]+b [7]*_e [3]+_e [6],b [6]*_e [1]+b [7]*_e [4]+_e [7],1};_e .clampRange ();};func (_ac Matrix )Mult (b Matrix )Matrix {_ac .Concat (b );return _ac };func (_f Matrix )String ()string {_ae ,_fb ,_c ,_cg ,_ce ,_dg :=_f [0],_f [1],_f [3],_f [4],_f [6],_f [7];return _d .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_ae ,_fb ,_c ,_cg ,_ce ,_dg );};func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};const _aef =1e-6;func (_ed *Matrix )Scale (x ,y float64 ){_ed .Concat (ScaleMatrix (x ,y ))};func (_cgf *Matrix )Translation ()(float64 ,float64 ){return _cgf [6],_cgf [7]};func (_da *Matrix )Translate (x ,y float64 ){_da .Concat (TranslationMatrix (x ,y ))};func (_eda Point )Rotate (theta float64 )Point {_dc :=_b .Hypot (_eda .X ,_eda .Y );_cgg :=_b .Atan2 (_eda .Y ,_eda .X );_gb ,_fef :=_b .Sincos (_cgg +theta /180.0*_b .Pi );return Point {_dc *_fef ,_dc *_gb };};func (_ea *Matrix )Transform (x ,y float64 )(float64 ,float64 ){_cc :=x *_ea [0]+y *_ea [1]+_ea [6];_cf :=x *_ea [3]+y *_ea [4]+_ea [7];return _cc ,_cf ;};
package transform ;import (_cb "fmt";_a "github.com/unidoc/unipdf/v3/common";_g "math";);func (_gc *Matrix )Shear (x ,y float64 ){_gc .Concat (ShearMatrix (x ,y ))};func (_ad *Matrix )Scale (x ,y float64 ){_ad .Concat (ScaleMatrix (x ,y ))};func (_cc Point )Displace (delta Point )Point {return Point {_cc .X +delta .X ,_cc .Y +delta .Y }};func (_eafg *Point )Set (x ,y float64 ){_eafg .X ,_eafg .Y =x ,y };func (_db *Point )transformByMatrix (_fff Matrix ){_db .X ,_db .Y =_fff .Transform (_db .X ,_db .Y )};func (_bg Point )String ()string {return _cb .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_bg .X ,_bg .Y );};type Point struct{X float64 ;Y float64 ;};func (_ge *Matrix )Translation ()(float64 ,float64 ){return _ge [6],_ge [7]};func (_ac *Matrix )Concat (b Matrix ){*_ac =Matrix {b [0]*_ac [0]+b [1]*_ac [3],b [0]*_ac [1]+b [1]*_ac [4],0,b [3]*_ac [0]+b [4]*_ac [3],b [3]*_ac [1]+b [4]*_ac [4],0,b [6]*_ac [0]+b [7]*_ac [3]+_ac [6],b [6]*_ac [1]+b [7]*_ac [4]+_ac [7],1};_ac .clampRange ();};func (_geg *Matrix )ScalingFactorX ()float64 {return _g .Hypot (_geg [0],_geg [1])};func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};func (_ca *Matrix )Translate (x ,y float64 ){_ca .Concat (TranslationMatrix (x ,y ))};func (_df *Matrix )clampRange (){for _dd ,_caf :=range _df {if _caf > _ce {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_caf ,_ce );_df [_dd ]=_ce ;}else if _caf < -_ce {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_caf ,-_ce );_df [_dd ]=-_ce ;};};};func (_fb *Matrix )Angle ()float64 {_eaf :=_g .Atan2 (-_fb [1],_fb [0]);if _eaf < 0.0{_eaf +=2*_g .Pi ;};return _eaf /_g .Pi *180.0;};func (_fe *Matrix )Transform (x ,y float64 )(float64 ,float64 ){_ab :=x *_fe [0]+y *_fe [1]+_fe [6];_adb :=x *_fe [3]+y *_fe [4]+_fe [7];return _ab ,_adb ;};func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )};const _ggf =1.0e-6;func (_be *Matrix )Clone ()Matrix {return NewMatrix (_be [0],_be [1],_be [3],_be [4],_be [6],_be [7])};type Matrix [9]float64 ;func (_gcd Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_gcd .X +t *b .X ,Y :(1-t )*_gcd .Y +t *b .Y };};func (_ff *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_ff [0],_ff [1]=a ,b ;_ff [3],_ff [4]=c ,d ;_ff [6],_ff [7]=tx ,ty ;_ff .clampRange ();};func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_cg :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1};_cg .clampRange ();return _cg ;};func (_ga *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_gbd :=NewMatrix (a ,b ,c ,d ,tx ,ty );_ga .transformByMatrix (_gbd );};const _ce =1e9;func (_af Point )Distance (b Point )float64 {return _g .Hypot (_af .X -b .X ,_af .Y -b .Y )};func (_ced Point )Rotate (theta float64 )Point {_fa :=_g .Hypot (_ced .X ,_ced .Y );_ba :=_g .Atan2 (_ced .Y ,_ced .X );_dae ,_dad :=_g .Sincos (_ba +theta /180.0*_g .Pi );return Point {_fa *_dad ,_fa *_dae };};func (_d Matrix )String ()string {_ea ,_cgd ,_f ,_fd ,_fg ,_ee :=_d [0],_d [1],_d [3],_d [4],_d [6],_d [7];return _cb .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_ea ,_cgd ,_f ,_fd ,_fg ,_ee );};func IdentityMatrix ()Matrix {return NewMatrix (1,0,0,1,0,0)};const _cba =1e-6;func (_b *Matrix )Rotate (angle float64 ){_b .Concat (RotationMatrix (angle ))};func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};func (_dfb *Matrix )Unrealistic ()bool {_da ,_gg ,_fga ,_bd :=_g .Abs (_dfb [0]),_g .Abs (_dfb [1]),_g .Abs (_dfb [3]),_g .Abs (_dfb [4]);_ddc :=_da > _cba &&_bd > _cba ;_ed :=_gg > _cba &&_fga > _cba ;return !(_ddc ||_ed );};func RotationMatrix (angle float64 )Matrix {_e :=_g .Cos (angle );_ae :=_g .Sin (angle );return NewMatrix (_e ,_ae ,-_ae ,_e ,0,0);};func (_gb *Matrix )ScalingFactorY ()float64 {return _g .Hypot (_gb [3],_gb [4])};func (_dg Matrix )Mult (b Matrix )Matrix {_dg .Concat (b );return _dg };func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,75 +10,75 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package sighandler implements digital signature handlers for PDF signature validation and signing.
package sighandler ;import (_d "bytes";_ae "crypto";_ga "crypto/rand";_ac "crypto/rsa";_dd "crypto/x509";_aa "crypto/x509/pkix";_cb "encoding/asn1";_f "errors";_db "fmt";_gc "github.com/unidoc/pkcs7";_ca "github.com/unidoc/timestamp";_aeg "github.com/unidoc/unipdf/v3/core";_cc "github.com/unidoc/unipdf/v3/model";_eg "hash";_c "io";_ed "io/ioutil";_g "net/http";_e "time";);type adobeX509RSASHA1 struct{_cca *_ac .PrivateKey ;_gad *_dd .Certificate ;_ce SignFunc ;};func (_agf *docTimeStamp )getCertificate (_ebcc *_cc .PdfSignature )(*_dd .Certificate ,error ){var _bfab []byte ;switch _ef :=_ebcc .Cert .(type ){case *_aeg .PdfObjectString :_bfab =_ef .Bytes ();case *_aeg .PdfObjectArray :if _ef .Len ()==0{return nil ,_f .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_ada :=range _ef .Elements (){_abae ,_dda :=_aeg .GetString (_ada );if !_dda {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_ada );};_bfab =append (_bfab ,_abae .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_ef );};_ddbd ,_cad :=_dd .ParseCertificates (_bfab );if _cad !=nil {return nil ,_cad ;};return _ddbd [0],nil ;};
package sighandler ;import (_f "bytes";_e "crypto";_aab "crypto/rand";_dd "crypto/rsa";_cc "crypto/x509";_g "crypto/x509/pkix";_aa "encoding/asn1";_cf "errors";_eg "fmt";_cfb "github.com/unidoc/pkcs7";_dc "github.com/unidoc/timestamp";_dcb "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/model";_ca "hash";_c "io";_fg "io/ioutil";_ae "net/http";_a "time";);
// InitSignature initialises the PdfSignature.
func (_bf *adobePKCS7Detached )InitSignature (sig *_b .PdfSignature )error {if !_bf ._ba {if _bf ._bd ==nil {return _cf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _bf ._ge ==nil {return _cf .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_de :=*_bf ;sig .Handler =&_de ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_eb ,_egb :=_de .NewDigest (sig );if _egb !=nil {return _egb ;};_eb .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _de .Sign (sig ,_eb );};func (_baf *adobePKCS7Detached )getCertificate (_aeb *_b .PdfSignature )(*_cc .Certificate ,error ){if _baf ._bd !=nil {return _baf ._bd ,nil ;};var _cb []byte ;switch _fe :=_aeb .Cert .(type ){case *_dcb .PdfObjectString :_cb =_fe .Bytes ();case *_dcb .PdfObjectArray :if _fe .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_da :=range _fe .Elements (){_af ,_cfbc :=_dcb .GetString (_da );if !_cfbc {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_da );};_cb =append (_cb ,_af .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_fe );};_bad ,_dce :=_cc .ParseCertificates (_cb );if _dce !=nil {return nil ,_dce ;};return _bad [0],nil ;};type docTimeStamp struct{_ecc string ;_bbc _e .Hash ;};
// NewDigest creates a new digest.
func (_dc *adobePKCS7Detached )NewDigest (sig *_cc .PdfSignature )(_cc .Hasher ,error ){return _d .NewBuffer (nil ),nil ;};
// NewDigest creates a new digest.
func (_cbef *docTimeStamp )NewDigest (sig *_cc .PdfSignature )(_cc .Hasher ,error ){return _d .NewBuffer (nil ),nil ;};func _dad (_ddca _cb .ObjectIdentifier )(_ae .Hash ,error ){switch {case _ddca .Equal (_gc .OIDDigestAlgorithmSHA1 ),_ddca .Equal (_gc .OIDDigestAlgorithmECDSASHA1 ),_ddca .Equal (_gc .OIDDigestAlgorithmDSA ),_ddca .Equal (_gc .OIDDigestAlgorithmDSASHA1 ),_ddca .Equal (_gc .OIDEncryptionAlgorithmRSA ):return _ae .SHA1 ,nil ;case _ddca .Equal (_gc .OIDDigestAlgorithmSHA256 ),_ddca .Equal (_gc .OIDDigestAlgorithmECDSASHA256 ):return _ae .SHA256 ,nil ;case _ddca .Equal (_gc .OIDDigestAlgorithmSHA384 ),_ddca .Equal (_gc .OIDDigestAlgorithmECDSASHA384 ):return _ae .SHA384 ,nil ;case _ddca .Equal (_gc .OIDDigestAlgorithmSHA512 ),_ddca .Equal (_gc .OIDDigestAlgorithmECDSASHA512 ):return _ae .SHA512 ,nil ;};return _ae .Hash (0),_gc .ErrUnsupportedAlgorithm ;};
func (_bdc *adobePKCS7Detached )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};type timestampInfo struct{Version int ;Policy _aa .RawValue ;MessageImprint struct{HashAlgorithm _g .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _aa .RawValue ;GeneralizedTime _a .Time ;};type adobePKCS7Detached struct{_ge *_dd .PrivateKey ;_bd *_cc .Certificate ;_ba bool ;_ad int ;};
// Validate validates PdfSignature.
func (_ede *adobePKCS7Detached )Validate (sig *_cc .PdfSignature ,digest _cc .Hasher )(_cc .SignatureValidationResult ,error ){_bg :=sig .Contents .Bytes ();_cab ,_ad :=_gc .Parse (_bg );if _ad !=nil {return _cc .SignatureValidationResult {},_ad ;};_gdd :=digest .(*_d .Buffer );_cab .Content =_gdd .Bytes ();if _ad =_cab .Verify ();_ad !=nil {return _cc .SignatureValidationResult {},_ad ;};return _cc .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
func (_ff *adobeX509RSASHA1 )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_gc ,_dee :=_ff .getCertificate (sig );if _dee !=nil {return _b .SignatureValidationResult {},_dee ;};_bdd :=sig .Contents .Bytes ();var _cce []byte ;if _ ,_cceb :=_aa .Unmarshal (_bdd ,&_cce );_cceb !=nil {return _b .SignatureValidationResult {},_cceb ;};_fega ,_gd :=digest .(_ca .Hash );if !_gd {return _b .SignatureValidationResult {},_cf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_bec ,_ :=_fede (_gc .SignatureAlgorithm );if _cbc :=_dd .VerifyPKCS1v15 (_gc .PublicKey .(*_dd .PublicKey ),_bec ,_fega .Sum (nil ),_cce );_cbc !=nil {return _b .SignatureValidationResult {},_cbc ;};return _b .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// NewDigest creates a new digest.
func (_efc *docTimeStamp )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};
// NewDigest creates a new digest.
func (_dag *adobeX509RSASHA1 )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){_gec ,_dbd :=_dag .getCertificate (sig );if _dbd !=nil {return nil ,_dbd ;};_ecf ,_ :=_fede (_gec .SignatureAlgorithm );return _ecf .New (),nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_cfe *docTimeStamp )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {_ddc :=digest .(*_f .Buffer );_ceef :=_cfe ._bbc .New ();if _ ,_ecb :=_c .Copy (_ceef ,_ddc );_ecb !=nil {return _ecb ;};_bc :=_ceef .Sum (nil );_edd :=_dc .Request {HashAlgorithm :_cfe ._bbc ,HashedMessage :_bc ,Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_ea ,_dcf :=_edd .Marshal ();if _dcf !=nil {return _dcf ;};_ac ,_dcf :=_ae .Post (_cfe ._ecc ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_f .NewBuffer (_ea ));if _dcf !=nil {return _dcf ;};defer _ac .Body .Close ();_gfe ,_dcf :=_fg .ReadAll (_ac .Body );if _dcf !=nil {return _dcf ;};if _ac .StatusCode !=_ae .StatusOK {return _eg .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_ac .StatusCode );};var _adf struct{Version _aa .RawValue ;Content _aa .RawValue ;};_ ,_dcf =_aa .Unmarshal (_gfe ,&_adf );if _dcf !=nil {return _dcf ;};sig .Contents =_dcb .MakeHexString (string (_adf .Content .FullBytes ));return nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_aaf *_cc .PdfSignature ,_dg _cc .Hasher )([]byte ,error );
type SignFunc func (_ebc *_b .PdfSignature ,_gb _b .Hasher )([]byte ,error );
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_bedb *docTimeStamp )IsApplicable (sig *_cc .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};
// Validate validates PdfSignature.
func (_fgaa *docTimeStamp )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_cfbb :=sig .Contents .Bytes ();_gee ,_abf :=_cfb .Parse (_cfbb );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};if _abf =_gee .Verify ();_abf !=nil {return _b .SignatureValidationResult {},_abf ;};var _gafg timestampInfo ;_ ,_abf =_aa .Unmarshal (_gee .Content ,&_gafg );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};_bfb ,_abf :=_gagc (_gafg .MessageImprint .HashAlgorithm .Algorithm );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};_bbd :=_bfb .New ();_beg :=digest .(*_f .Buffer );_bbd .Write (_beg .Bytes ());_cee :=_bbd .Sum (nil );_cac :=_b .SignatureValidationResult {IsSigned :true ,IsVerified :_f .Equal (_cee ,_gafg .MessageImprint .HashedMessage ),GeneralizedTime :_gafg .GeneralizedTime };return _cac ,nil ;};func _fede (_feg _cc .SignatureAlgorithm )(_e .Hash ,bool ){return _e .SHA1 ,true };
// Sign sets the Contents fields for the PdfSignature.
func (_ebd *adobeX509RSASHA1 )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {var _cef []byte ;var _baa error ;if _ebd ._gac !=nil {_cef ,_baa =_ebd ._gac (sig ,digest );if _baa !=nil {return _baa ;};}else {_ceb ,_caa :=digest .(_ca .Hash );if !_caa {return _cf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_afd ,_ :=_fede (_ebd ._gag .SignatureAlgorithm );_cef ,_baa =_dd .SignPKCS1v15 (_aab .Reader ,_ebd ._ab ,_afd ,_ceb .Sum (nil ));if _baa !=nil {return _baa ;};};_cef ,_baa =_aa .Marshal (_cef );if _baa !=nil {return _baa ;};sig .Contents =_dcb .MakeHexString (string (_cef ));return nil ;};func (_fd *docTimeStamp )getCertificate (_fec *_b .PdfSignature )(*_cc .Certificate ,error ){var _gf []byte ;switch _bdcf :=_fec .Cert .(type ){case *_dcb .PdfObjectString :_gf =_bdcf .Bytes ();case *_dcb .PdfObjectArray :if _bdcf .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_geg :=range _bdcf .Elements (){_ebgd ,_dg :=_dcb .GetString (_geg );if !_dg {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_geg );};_gf =append (_gf ,_ebgd .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bdcf );};_cg ,_cfa :=_cc .ParseCertificates (_gf );if _cfa !=nil {return nil ,_cfa ;};return _cg [0],nil ;};
// Sign sets the Contents fields.
func (_fa *adobePKCS7Detached )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {if _fa ._ba {_fed :=_fa ._ad ;if _fed <=0{_fed =8192;};sig .Contents =_dcb .MakeHexString (string (make ([]byte ,_fed )));return nil ;};_ga :=digest .(*_f .Buffer );_adg ,_ebg :=_cfb .NewSignedData (_ga .Bytes ());if _ebg !=nil {return _ebg ;};if _gae :=_adg .AddSigner (_fa ._bd ,_fa ._ge ,_cfb .SignerInfoConfig {});_gae !=nil {return _gae ;};_adg .Detach ();_ed ,_ebg :=_adg .Finish ();if _ebg !=nil {return _ebg ;};_cec :=make ([]byte ,8192);copy (_cec ,_ed );sig .Contents =_dcb .MakeHexString (string (_cec ));return nil ;};
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler
// with a custom signing function. Both parameters may be nil for the signature validation.
func NewAdobeX509RSASHA1Custom (certificate *_dd .Certificate ,signFunc SignFunc )(_cc .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gad :certificate ,_ce :signFunc },nil ;};func (_b *adobePKCS7Detached )getCertificate (_fg *_cc .PdfSignature )(*_dd .Certificate ,error ){if _b ._gd !=nil {return _b ._gd ,nil ;};var _ee []byte ;switch _aca :=_fg .Cert .(type ){case *_aeg .PdfObjectString :_ee =_aca .Bytes ();case *_aeg .PdfObjectArray :if _aca .Len ()==0{return nil ,_f .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_bc :=range _aca .Elements (){_gf ,_de :=_aeg .GetString (_bc );if !_de {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_bc );};_ee =append (_ee ,_gf .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_aca );};_gdg ,_be :=_dd .ParseCertificates (_ee );if _be !=nil {return nil ,_be ;};return _gdg [0],nil ;};
// InitSignature initialises the PdfSignature.
func (_bgc *docTimeStamp )InitSignature (sig *_cc .PdfSignature )error {_gg :=*_bgc ;sig .Handler =&_gg ;sig .Filter =_aeg .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_aeg .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;_gda ,_dfb :=_bgc .NewDigest (sig );if _dfb !=nil {return _dfb ;};_gda .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _gg .Sign (sig ,_gda );};
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler.
// Both parameters may be nil for the signature validation.
func NewAdobeX509RSASHA1 (privateKey *_ac .PrivateKey ,certificate *_dd .Certificate )(_cc .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gad :certificate ,_cca :privateKey },nil ;};
// NewDigest creates a new digest.
func (_ace *adobeX509RSASHA1 )NewDigest (sig *_cc .PdfSignature )(_cc .Hasher ,error ){_agg ,_bfa :=_ace .getCertificate (sig );if _bfa !=nil {return nil ,_bfa ;};_aag ,_ :=_bfc (_agg .SignatureAlgorithm );return _aag .New (),nil ;};type docTimeStamp struct{_ffb string ;_ebd _ae .Hash ;};
// Validate validates PdfSignature.
func (_fb *docTimeStamp )Validate (sig *_cc .PdfSignature ,digest _cc .Hasher )(_cc .SignatureValidationResult ,error ){_bee :=sig .Contents .Bytes ();_cd ,_becg :=_gc .Parse (_bee );if _becg !=nil {return _cc .SignatureValidationResult {},_becg ;};if _becg =_cd .Verify ();_becg !=nil {return _cc .SignatureValidationResult {},_becg ;};var _bed timestampInfo ;_ ,_becg =_cb .Unmarshal (_cd .Content ,&_bed );if _becg !=nil {return _cc .SignatureValidationResult {},_becg ;};_fc ,_becg :=_dad (_bed .MessageImprint .HashAlgorithm .Algorithm );if _becg !=nil {return _cc .SignatureValidationResult {},_becg ;};_ceb :=_fc .New ();_edef :=digest .(*_d .Buffer );_ceb .Write (_edef .Bytes ());_ddcg :=_ceb .Sum (nil );_cebg :=_cc .SignatureValidationResult {IsSigned :true ,IsVerified :_d .Equal (_ddcg ,_bed .MessageImprint .HashedMessage ),GeneralizedTime :_bed .GeneralizedTime };return _cebg ,nil ;};
// Validate validates PdfSignature.
func (_ba *adobeX509RSASHA1 )Validate (sig *_cc .PdfSignature ,digest _cc .Hasher )(_cc .SignatureValidationResult ,error ){_bb ,_gea :=_ba .getCertificate (sig );if _gea !=nil {return _cc .SignatureValidationResult {},_gea ;};_aed :=sig .Contents .Bytes ();var _fgd []byte ;if _ ,_geg :=_cb .Unmarshal (_aed ,&_fgd );_geg !=nil {return _cc .SignatureValidationResult {},_geg ;};_ffc ,_age :=digest .(_eg .Hash );if !_age {return _cc .SignatureValidationResult {},_f .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_adb ,_ :=_bfc (_bb .SignatureAlgorithm );if _ebe :=_ac .VerifyPKCS1v15 (_bb .PublicKey .(*_ac .PublicKey ),_adb ,_ffc .Sum (nil ),_fgd );_ebe !=nil {return _cc .SignatureValidationResult {},_ebe ;};return _cc .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// InitSignature initialises the PdfSignature.
func (_gfc *adobeX509RSASHA1 )InitSignature (sig *_cc .PdfSignature )error {if _gfc ._gad ==nil {return _f .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _gfc ._cca ==nil &&_gfc ._ce ==nil {return _f .New ("\u006d\u0075\u0073\u0074\u0020\u0070\u0072o\u0076\u0069\u0064e\u0020\u0065\u0069t\u0068\u0065r\u0020\u0061\u0020\u0070\u0072\u0069v\u0061te\u0020\u006b\u0065\u0079\u0020\u006f\u0072\u0020\u0061\u0020\u0073\u0069\u0067\u006e\u0069\u006e\u0067\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_ccg :=*_gfc ;sig .Handler =&_ccg ;sig .Filter =_aeg .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_aeg .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_aeg .MakeString (string (_ccg ._gad .Raw ));sig .Reference =nil ;_dgf ,_df :=_ccg .NewDigest (sig );if _df !=nil {return _df ;};_dgf .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _ccg .Sign (sig ,_dgf );};
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
// Both parameters may be nil for the signature validation.
func NewAdobePKCS7Detached (privateKey *_ac .PrivateKey ,certificate *_dd .Certificate )(_cc .SignatureHandler ,error ){return &adobePKCS7Detached {_gd :certificate ,_ec :privateKey },nil ;};
// InitSignature initialises the PdfSignature.
func (_ag *adobePKCS7Detached )InitSignature (sig *_cc .PdfSignature )error {if !_ag ._fe {if _ag ._gd ==nil {return _f .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _ag ._ec ==nil {return _f .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_gdf :=*_ag ;sig .Handler =&_gdf ;sig .Filter =_aeg .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_aeg .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_dbg ,_gdfa :=_gdf .NewDigest (sig );if _gdfa !=nil {return _gdfa ;};_dbg .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _gdf .Sign (sig ,_dbg );};func (_cf *adobeX509RSASHA1 )getCertificate (_ddb *_cc .PdfSignature )(*_dd .Certificate ,error ){if _cf ._gad !=nil {return _cf ._gad ,nil ;};var _ge []byte ;switch _ddcd :=_ddb .Cert .(type ){case *_aeg .PdfObjectString :_ge =_ddcd .Bytes ();case *_aeg .PdfObjectArray :if _ddcd .Len ()==0{return nil ,_f .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_eeg :=range _ddcd .Elements (){_gb ,_ff :=_aeg .GetString (_eeg );if !_ff {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_eeg );};_ge =append (_ge ,_gb .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_ddcd );};_dgc ,_daa :=_dd .ParseCertificates (_ge );if _daa !=nil {return nil ,_daa ;};return _dgc [0],nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_gga *docTimeStamp )Sign (sig *_cc .PdfSignature ,digest _cc .Hasher )error {_egf :=digest .(*_d .Buffer );_bef :=_gga ._ebd .New ();if _ ,_aedf :=_c .Copy (_bef ,_egf );_aedf !=nil {return _aedf ;};_gbg :=_bef .Sum (nil );_adf :=_ca .Request {HashAlgorithm :_gga ._ebd ,HashedMessage :_gbg ,Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_gfe ,_efc :=_adf .Marshal ();if _efc !=nil {return _efc ;};_adbd ,_efc :=_g .Post (_gga ._ffb ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_d .NewBuffer (_gfe ));if _efc !=nil {return _efc ;};defer _adbd .Body .Close ();_acc ,_efc :=_ed .ReadAll (_adbd .Body );if _efc !=nil {return _efc ;};if _adbd .StatusCode !=_g .StatusOK {return _db .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_adbd .StatusCode );};var _egd struct{Version _cb .RawValue ;Content _cb .RawValue ;};_ ,_efc =_cb .Unmarshal (_acc ,&_egd );if _efc !=nil {return _efc ;};sig .Contents =_aeg .MakeHexString (string (_egd .Content .FullBytes ));return nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_cbe *adobeX509RSASHA1 )IsApplicable (sig *_cc .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};
// Sign sets the Contents fields for the PdfSignature.
func (_gcd *adobeX509RSASHA1 )Sign (sig *_cc .PdfSignature ,digest _cc .Hasher )error {var _bff []byte ;var _fd error ;if _gcd ._ce !=nil {_bff ,_fd =_gcd ._ce (sig ,digest );if _fd !=nil {return _fd ;};}else {_bfaf ,_gca :=digest .(_eg .Hash );if !_gca {return _f .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_aba ,_ :=_bfc (_gcd ._gad .SignatureAlgorithm );_bff ,_fd =_ac .SignPKCS1v15 (_ga .Reader ,_gcd ._cca ,_aba ,_bfaf .Sum (nil ));if _fd !=nil {return _fd ;};};_bff ,_fd =_cb .Marshal (_bff );if _fd !=nil {return _fd ;};sig .Contents =_aeg .MakeHexString (string (_bff ));return nil ;};type timestampInfo struct{Version int ;Policy _cb .RawValue ;MessageImprint struct{HashAlgorithm _aa .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _cb .RawValue ;GeneralizedTime _e .Time ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_ddc *adobePKCS7Detached )IsApplicable (sig *_cc .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};type adobePKCS7Detached struct{_ec *_ac .PrivateKey ;_gd *_dd .Certificate ;_fe bool ;_dbd int ;};func _bfc (_acdb _dd .SignatureAlgorithm )(_ae .Hash ,bool ){return _ae .SHA1 ,true };
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// The timestampServerURL parameter can be empty string for the signature validation.
// The hashAlgorithm parameter can be crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _ae .Hash )(_cc .SignatureHandler ,error ){return &docTimeStamp {_ffb :timestampServerURL ,_ebd :hashAlgorithm },nil ;};
// Sign sets the Contents fields.
func (_bd *adobePKCS7Detached )Sign (sig *_cc .PdfSignature ,digest _cc .Hasher )error {if _bd ._fe {_acd :=_bd ._dbd ;if _acd <=0{_acd =8192;};sig .Contents =_aeg .MakeHexString (string (make ([]byte ,_acd )));return nil ;};_gfd :=digest .(*_d .Buffer );_ab ,_bdf :=_gc .NewSignedData (_gfd .Bytes ());if _bdf !=nil {return _bdf ;};if _fa :=_ab .AddSigner (_bd ._gd ,_bd ._ec ,_gc .SignerInfoConfig {});_fa !=nil {return _fa ;};_ab .Detach ();_bf ,_bdf :=_ab .Finish ();if _bdf !=nil {return _bdf ;};_da :=make ([]byte ,8192);copy (_da ,_bf );sig .Contents =_aeg .MakeHexString (string (_da ));return nil ;};
func NewAdobeX509RSASHA1Custom (certificate *_cc .Certificate ,signFunc SignFunc )(_b .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gag :certificate ,_gac :signFunc },nil ;};
// NewEmptyAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached
// signature handler. The generated signature is empty and of size signatureLen.
// The signatureLen parameter can be 0 for the signature validation.
func NewEmptyAdobePKCS7Detached (signatureLen int )(_cc .SignatureHandler ,error ){return &adobePKCS7Detached {_fe :true ,_dbd :signatureLen },nil ;};
func NewEmptyAdobePKCS7Detached (signatureLen int )(_b .SignatureHandler ,error ){return &adobePKCS7Detached {_ba :true ,_ad :signatureLen },nil ;};
// Validate validates PdfSignature.
func (_ce *adobePKCS7Detached )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_df :=sig .Contents .Bytes ();_ef ,_bfc :=_cfb .Parse (_df );if _bfc !=nil {return _b .SignatureValidationResult {},_bfc ;};_afg :=digest .(*_f .Buffer );_ef .Content =_afg .Bytes ();if _bfc =_ef .Verify ();_bfc !=nil {return _b .SignatureValidationResult {},_bfc ;};return _b .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_dcc *adobePKCS7Detached )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
// Both parameters may be nil for the signature validation.
func NewAdobePKCS7Detached (privateKey *_dd .PrivateKey ,certificate *_cc .Certificate )(_b .SignatureHandler ,error ){return &adobePKCS7Detached {_bd :certificate ,_ge :privateKey },nil ;};
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler.
// Both parameters may be nil for the signature validation.
func NewAdobeX509RSASHA1 (privateKey *_dd .PrivateKey ,certificate *_cc .Certificate )(_b .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gag :certificate ,_ab :privateKey },nil ;};func _gagc (_fc _aa .ObjectIdentifier )(_e .Hash ,error ){switch {case _fc .Equal (_cfb .OIDDigestAlgorithmSHA1 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA1 ),_fc .Equal (_cfb .OIDDigestAlgorithmDSA ),_fc .Equal (_cfb .OIDDigestAlgorithmDSASHA1 ),_fc .Equal (_cfb .OIDEncryptionAlgorithmRSA ):return _e .SHA1 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA256 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA256 ):return _e .SHA256 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA384 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA384 ):return _e .SHA384 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA512 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA512 ):return _e .SHA512 ,nil ;};return _e .Hash (0),_cfb .ErrUnsupportedAlgorithm ;};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// The timestampServerURL parameter can be empty string for the signature validation.
// The hashAlgorithm parameter can be crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _e .Hash )(_b .SignatureHandler ,error ){return &docTimeStamp {_ecc :timestampServerURL ,_bbc :hashAlgorithm },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_eef *adobeX509RSASHA1 )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};func (_ec *adobeX509RSASHA1 )getCertificate (_cfg *_b .PdfSignature )(*_cc .Certificate ,error ){if _ec ._gag !=nil {return _ec ._gag ,nil ;};var _gaf []byte ;switch _fgg :=_cfg .Cert .(type ){case *_dcb .PdfObjectString :_gaf =_fgg .Bytes ();case *_dcb .PdfObjectArray :if _fgg .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_db :=range _fgg .Elements (){_gbe ,_gagg :=_dcb .GetString (_db );if !_gagg {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_db );};_gaf =append (_gaf ,_gbe .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_fgg );};_ee ,_bg :=_cc .ParseCertificates (_gaf );if _bg !=nil {return nil ,_bg ;};return _ee [0],nil ;};type adobeX509RSASHA1 struct{_ab *_dd .PrivateKey ;_gag *_cc .Certificate ;_gac SignFunc ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_fef *docTimeStamp )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};
// InitSignature initialises the PdfSignature.
func (_cecd *adobeX509RSASHA1 )InitSignature (sig *_b .PdfSignature )error {if _cecd ._gag ==nil {return _cf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _cecd ._ab ==nil &&_cecd ._gac ==nil {return _cf .New ("\u006d\u0075\u0073\u0074\u0020\u0070\u0072o\u0076\u0069\u0064e\u0020\u0065\u0069t\u0068\u0065r\u0020\u0061\u0020\u0070\u0072\u0069v\u0061te\u0020\u006b\u0065\u0079\u0020\u006f\u0072\u0020\u0061\u0020\u0073\u0069\u0067\u006e\u0069\u006e\u0067\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_bb :=*_cecd ;sig .Handler =&_bb ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_dcb .MakeString (string (_bb ._gag .Raw ));sig .Reference =nil ;_ced ,_aaa :=_bb .NewDigest (sig );if _aaa !=nil {return _aaa ;};_ced .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _bb .Sign (sig ,_ced );};
// InitSignature initialises the PdfSignature.
func (_abe *docTimeStamp )InitSignature (sig *_b .PdfSignature )error {_fb :=*_abe ;sig .Handler =&_fb ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;_dae ,_afe :=_abe .NewDigest (sig );if _afe !=nil {return _afe ;};_dae .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _fb .Sign (sig ,_dae );};

144
ps/ps.go
View File

@ -14,83 +14,36 @@
//
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
// for PDF function type 4.
package ps ;import (_aa "bufio";_a "bytes";_e "errors";_ed "fmt";_ag "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/core";_bg "io";_f "math";);
package ps ;import (_fe "bufio";_d "bytes";_e "errors";_fg "fmt";_b "github.com/unidoc/unipdf/v3/common";_feb "github.com/unidoc/unipdf/v3/core";_ea "io";_eg "math";);func (_ffac *PSOperand )sin (_ddb *PSStack )error {_afgc ,_geea :=_ddb .PopNumberAsFloat64 ();if _geea !=nil {return _geea ;};_eafa :=_eg .Sin (_afgc *_eg .Pi /180.0);_geea =_ddb .Push (MakeReal (_eafa ));return _geea ;};func (_dbe *PSOperand )copy (_cddb *PSStack )error {_deg ,_gab :=_cddb .PopInteger ();if _gab !=nil {return _gab ;};if _deg < 0{return ErrRangeCheck ;};if _deg > len (*_cddb ){return ErrRangeCheck ;};*_cddb =append (*_cddb ,(*_cddb )[len (*_cddb )-_deg :]...);return nil ;};func (_cab *PSOperand )DebugString ()string {return _fg .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_cab );};
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct{Stack *PSStack ;_agb *PSProgram ;};func (_ddg *PSOperand )add (_gbf *PSStack )error {_bag ,_cd :=_gbf .Pop ();if _cd !=nil {return _cd ;};_fc ,_cd :=_gbf .Pop ();if _cd !=nil {return _cd ;};_fdcd ,_bdfg :=_bag .(*PSReal );_bbe ,_gbb :=_bag .(*PSInteger );if !_bdfg &&!_gbb {return ErrTypeCheck ;};_gfb ,_cbc :=_fc .(*PSReal );_db ,_dbc :=_fc .(*PSInteger );if !_cbc &&!_dbc {return ErrTypeCheck ;};if _gbb &&_dbc {_eb :=_bbe .Val +_db .Val ;_dg :=_gbf .Push (MakeInteger (_eb ));return _dg ;};var _agd float64 =0;if _bdfg {_agd =_fdcd .Val ;}else {_agd =float64 (_bbe .Val );};if _cbc {_agd +=_gfb .Val ;}else {_agd +=float64 (_db .Val );};_cd =_gbf .Push (MakeReal (_agd ));return _cd ;};func (_fd *PSBoolean )DebugString ()string {return _ed .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_fd .Val );};func (_bdec *PSOperand )log (_ced *PSStack )error {_aaa ,_cedg :=_ced .PopNumberAsFloat64 ();if _cedg !=nil {return _cedg ;};_efa :=_f .Log10 (_aaa );_cedg =_ced .Push (MakeReal (_efa ));return _cedg ;};var ErrTypeCheck =_e .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");func (_aee *PSOperand )round (_ffg *PSStack )error {_eedc ,_cbdd :=_ffg .Pop ();if _cbdd !=nil {return _cbdd ;};if _cgf ,_cddb :=_eedc .(*PSReal );_cddb {_cbdd =_ffg .Push (MakeReal (_f .Floor (_cgf .Val +0.5)));}else if _fefa ,_fgeg :=_eedc .(*PSInteger );_fgeg {_cbdd =_ffg .Push (MakeInteger (_fefa .Val ));}else {return ErrTypeCheck ;};return _cbdd ;};func (_cb *PSReal )DebugString ()string {return _ed .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_cb .Val );};const _c =0.000001;func (_eccf *PSParser )parseNumber ()(PSObject ,error ){_ffe ,_ffee :=_g .ParseNumber (_eccf ._abgbc );if _ffee !=nil {return nil ,_ffee ;};switch _edf :=_ffe .(type ){case *_g .PdfObjectFloat :return MakeReal (float64 (*_edf )),nil ;case *_g .PdfObjectInteger :return MakeInteger (int (*_edf )),nil ;};return nil ,_ed .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_ffe );};func (_ggd *PSOperand )ifCondition (_aff *PSStack )error {_bbg ,_cde :=_aff .Pop ();if _cde !=nil {return _cde ;};_acad ,_cde :=_aff .Pop ();if _cde !=nil {return _cde ;};_fed ,_feg :=_bbg .(*PSProgram );if !_feg {return ErrTypeCheck ;};_dfee ,_feg :=_acad .(*PSBoolean );if !_feg {return ErrTypeCheck ;};if _dfee .Val {_ddcb :=_fed .Exec (_aff );return _ddcb ;};return nil ;};func (_agc *PSOperand )exp (_ffc *PSStack )error {_aef ,_bce :=_ffc .PopNumberAsFloat64 ();if _bce !=nil {return _bce ;};_feab ,_bce :=_ffc .PopNumberAsFloat64 ();if _bce !=nil {return _bce ;};if _f .Abs (_aef )< 1&&_feab < 0{return ErrUndefinedResult ;};_beeb :=_f .Pow (_feab ,_aef );_bce =_ffc .Push (MakeReal (_beeb ));return _bce ;};var ErrUnsupportedOperand =_e .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_df *PSInteger )DebugString ()string {return _ed .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_df .Val );};func (_cea *PSOperand )floor (_afb *PSStack )error {_gg ,_cgd :=_afb .Pop ();if _cgd !=nil {return _cgd ;};if _cdd ,_abe :=_gg .(*PSReal );_abe {_cgd =_afb .Push (MakeReal (_f .Floor (_cdd .Val )));}else if _dgd ,_ece :=_gg .(*PSInteger );_ece {_cgd =_afb .Push (MakeInteger (_dgd .Val ));}else {return ErrTypeCheck ;};return _cgd ;};
type PSExecutor struct{Stack *PSStack ;_fb *PSProgram ;};
// Empty empties the stack.
func (_efb *PSStack )Empty (){*_efb =[]PSObject {}};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_ccg :=PSInteger {};_ccg .Val =val ;return &_ccg };func (_eba *PSOperand )and (_dbg *PSStack )error {_ac ,_dcb :=_dbg .Pop ();if _dcb !=nil {return _dcb ;};_cbg ,_dcb :=_dbg .Pop ();if _dcb !=nil {return _dcb ;};if _adg ,_gcd :=_ac .(*PSBoolean );_gcd {_ebab ,_gcc :=_cbg .(*PSBoolean );if !_gcc {return ErrTypeCheck ;};_dcb =_dbg .Push (MakeBool (_adg .Val &&_ebab .Val ));return _dcb ;};if _dfaf ,_da :=_ac .(*PSInteger );_da {_dbf ,_gaf :=_cbg .(*PSInteger );if !_gaf {return ErrTypeCheck ;};_dcb =_dbg .Push (MakeInteger (_dfaf .Val &_dbf .Val ));return _dcb ;};return ErrTypeCheck ;};func (_dgdc *PSOperand )xor (_cebe *PSStack )error {_ecb ,_cacc :=_cebe .Pop ();if _cacc !=nil {return _cacc ;};_geab ,_cacc :=_cebe .Pop ();if _cacc !=nil {return _cacc ;};if _fdb ,_fcbe :=_ecb .(*PSBoolean );_fcbe {_gbad ,_gcca :=_geab .(*PSBoolean );if !_gcca {return ErrTypeCheck ;};_cacc =_cebe .Push (MakeBool (_fdb .Val !=_gbad .Val ));return _cacc ;};if _bbgc ,_bdfb :=_ecb .(*PSInteger );_bdfb {_agec ,_add :=_geab .(*PSInteger );if !_add {return ErrTypeCheck ;};_cacc =_cebe .Push (MakeInteger (_bbgc .Val ^_agec .Val ));return _cacc ;};return ErrTypeCheck ;};func (_debb *PSOperand )or (_fbe *PSStack )error {_bgf ,_abfc :=_fbe .Pop ();if _abfc !=nil {return _abfc ;};_adac ,_abfc :=_fbe .Pop ();if _abfc !=nil {return _abfc ;};if _gba ,_dgbg :=_bgf .(*PSBoolean );_dgbg {_beg ,_gef :=_adac .(*PSBoolean );if !_gef {return ErrTypeCheck ;};_abfc =_fbe .Push (MakeBool (_gba .Val ||_beg .Val ));return _abfc ;};if _cdbe ,_dfge :=_bgf .(*PSInteger );_dfge {_eaea ,_gea :=_adac .(*PSInteger );if !_gea {return ErrTypeCheck ;};_abfc =_fbe .Push (MakeInteger (_cdbe .Val |_eaea .Val ));return _abfc ;};return ErrTypeCheck ;};func (_ce *PSProgram )String ()string {_bda :="\u007b\u0020";for _ ,_cad :=range *_ce {_bda +=_cad .String ();_bda +="\u0020";};_bda +="\u007d";return _bda ;};func (_be *PSInteger )Duplicate ()PSObject {_ec :=PSInteger {};_ec .Val =_be .Val ;return &_ec };func (_ecce *PSOperand )sqrt (_abgg *PSStack )error {_dgc ,_cba :=_abgg .PopNumberAsFloat64 ();if _cba !=nil {return _cba ;};if _dgc < 0{return ErrRangeCheck ;};_ccdg :=_f .Sqrt (_dgc );_cba =_abgg .Push (MakeReal (_ccdg ));return _cba ;};
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};
// MakeReal returns a new PSReal object initialized with `val`.
func MakeReal (val float64 )*PSReal {_cag :=PSReal {};_cag .Val =val ;return &_cag };func _aaffe (_aede int )int {if _aede < 0{return -_aede ;};return _aede ;};
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_dga :=PSOperand (val );return &_dga };func (_gda *PSOperand )ge (_bgab *PSStack )error {_cdb ,_egb :=_bgab .PopNumberAsFloat64 ();if _egb !=nil {return _egb ;};_bdb ,_egb :=_bgab .PopNumberAsFloat64 ();if _egb !=nil {return _egb ;};if _f .Abs (_bdb -_cdb )< _c {_ggc :=_bgab .Push (MakeBool (true ));return _ggc ;}else if _bdb > _cdb {_aca :=_bgab .Push (MakeBool (true ));return _aca ;}else {_abgb :=_bgab .Push (MakeBool (false ));return _abgb ;};};
// PSReal represents a real number.
type PSReal struct{Val float64 ;};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};func (_dbgd *PSOperand )idiv (_gfce *PSStack )error {_aag ,_cdbc :=_gfce .Pop ();if _cdbc !=nil {return _cdbc ;};_dac ,_cdbc :=_gfce .Pop ();if _cdbc !=nil {return _cdbc ;};_ebe ,_gdf :=_aag .(*PSInteger );if !_gdf {return ErrTypeCheck ;};if _ebe .Val ==0{return ErrUndefinedResult ;};_aaff ,_gdf :=_dac .(*PSInteger );if !_gdf {return ErrTypeCheck ;};_afc :=_aaff .Val /_ebe .Val ;_cdbc =_gfce .Push (MakeInteger (_afc ));return _cdbc ;};func (_dbgda *PSOperand )le (_gfcc *PSStack )error {_dfec ,_gad :=_gfcc .PopNumberAsFloat64 ();if _gad !=nil {return _gad ;};_agde ,_gad :=_gfcc .PopNumberAsFloat64 ();if _gad !=nil {return _gad ;};if _f .Abs (_agde -_dfec )< _c {_bace :=_gfcc .Push (MakeBool (true ));return _bace ;}else if _agde < _dfec {_fbb :=_gfcc .Push (MakeBool (true ));return _fbb ;}else {_gegd :=_gfcc .Push (MakeBool (false ));return _gegd ;};};
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_ade :=PSBoolean {};_ade .Val =val ;return &_ade };func (_gdg *PSOperand )ifCondition (_caff *PSStack )error {_edc ,_afc :=_caff .Pop ();if _afc !=nil {return _afc ;};_aac ,_afc :=_caff .Pop ();if _afc !=nil {return _afc ;};_gbfd ,_abad :=_edc .(*PSProgram );if !_abad {return ErrTypeCheck ;};_cba ,_abad :=_aac .(*PSBoolean );if !_abad {return ErrTypeCheck ;};if _cba .Val {_eaf :=_gbfd .Exec (_caff );return _eaf ;};return nil ;};
// Exec executes the program, typically leaving output values on the stack.
func (_bdg *PSProgram )Exec (stack *PSStack )error {for _ ,_gfc :=range *_bdg {var _aac error ;switch _ede :=_gfc .(type ){case *PSInteger :_ba :=_ede ;_aac =stack .Push (_ba );case *PSReal :_gcfg :=_ede ;_aac =stack .Push (_gcfg );case *PSBoolean :_dfg :=_ede ;_aac =stack .Push (_dfg );case *PSProgram :_gbg :=_ede ;_aac =stack .Push (_gbg );case *PSOperand :_fdc :=_ede ;_aac =_fdc .Exec (stack );default:return ErrTypeCheck ;};if _aac !=nil {return _aac ;};};return nil ;};func (_bece *PSOperand )exch (_deb *PSStack )error {_bfd ,_cda :=_deb .Pop ();if _cda !=nil {return _cda ;};_dge ,_cda :=_deb .Pop ();if _cda !=nil {return _cda ;};_cda =_deb .Push (_bfd );if _cda !=nil {return _cda ;};_cda =_deb .Push (_dge );return _cda ;};func (_gee *PSOperand )neg (_fae *PSStack )error {_cbd ,_efaf :=_fae .Pop ();if _efaf !=nil {return _efaf ;};if _cee ,_abea :=_cbd .(*PSReal );_abea {_efaf =_fae .Push (MakeReal (-_cee .Val ));return _efaf ;}else if _egbe ,_gab :=_cbd .(*PSInteger );_gab {_efaf =_fae .Push (MakeInteger (-_egbe .Val ));return _efaf ;}else {return ErrTypeCheck ;};};func (_gfe *PSOperand )mul (_cedf *PSStack )error {_bff ,_beaf :=_cedf .Pop ();if _beaf !=nil {return _beaf ;};_bage ,_beaf :=_cedf .Pop ();if _beaf !=nil {return _beaf ;};_bdad ,_eca :=_bff .(*PSReal );_ebbc ,_eee :=_bff .(*PSInteger );if !_eca &&!_eee {return ErrTypeCheck ;};_eebd ,_fegd :=_bage .(*PSReal );_bdae ,_ceca :=_bage .(*PSInteger );if !_fegd &&!_ceca {return ErrTypeCheck ;};if _eee &&_ceca {_abag :=_ebbc .Val *_bdae .Val ;_gdg :=_cedf .Push (MakeInteger (_abag ));return _gdg ;};var _gfgd float64 =0;if _eca {_gfgd =_bdad .Val ;}else {_gfgd =float64 (_ebbc .Val );};if _fegd {_gfgd *=_eebd .Val ;}else {_gfgd *=float64 (_bdae .Val );};_beaf =_cedf .Push (MakeReal (_gfgd ));return _beaf ;};func (_agbaa *PSOperand )sin (_ceeb *PSStack )error {_eaee ,_adbg :=_ceeb .PopNumberAsFloat64 ();if _adbg !=nil {return _adbg ;};_caa :=_f .Sin (_eaee *_f .Pi /180.0);_adbg =_ceeb .Push (MakeReal (_caa ));return _adbg ;};
func (_cdd *PSProgram )Exec (stack *PSStack )error {for _ ,_fdf :=range *_cdd {var _fgd error ;switch _dcg :=_fdf .(type ){case *PSInteger :_cfd :=_dcg ;_fgd =stack .Push (_cfd );case *PSReal :_caa :=_dcg ;_fgd =stack .Push (_caa );case *PSBoolean :_fc :=_dcg ;_fgd =stack .Push (_fc );case *PSProgram :_egf :=_dcg ;_fgd =stack .Push (_egf );case *PSOperand :_geb :=_dcg ;_fgd =_geb .Exec (stack );default:return ErrTypeCheck ;};if _fgd !=nil {return _fgd ;};};return nil ;};func (_ge *PSInteger )Duplicate ()PSObject {_c :=PSInteger {};_c .Val =_ge .Val ;return &_c };func (_decc *PSOperand )sub (_fgdb *PSStack )error {_gce ,_gadb :=_fgdb .Pop ();if _gadb !=nil {return _gadb ;};_ddga ,_gadb :=_fgdb .Pop ();if _gadb !=nil {return _gadb ;};_agg ,_dcec :=_gce .(*PSReal );_badc ,_gefb :=_gce .(*PSInteger );if !_dcec &&!_gefb {return ErrTypeCheck ;};_efd ,_acg :=_ddga .(*PSReal );_aaa ,_fdd :=_ddga .(*PSInteger );if !_acg &&!_fdd {return ErrTypeCheck ;};if _gefb &&_fdd {_gca :=_aaa .Val -_badc .Val ;_ffef :=_fgdb .Push (MakeInteger (_gca ));return _ffef ;};var _bbcfb float64 =0;if _acg {_bbcfb =_efd .Val ;}else {_bbcfb =float64 (_aaa .Val );};if _dcec {_bbcfb -=_agg .Val ;}else {_bbcfb -=float64 (_badc .Val );};_gadb =_fgdb .Push (MakeReal (_bbcfb ));return _gadb ;};var ErrTypeCheck =_e .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
func (_cebf *PSStack )PopInteger ()(int ,error ){_bgdc ,_bcf :=_cebf .Pop ();if _bcf !=nil {return 0,_bcf ;};if _ddf ,_bbb :=_bgdc .(*PSInteger );_bbb {return _ddf .Val ,nil ;};return 0,ErrTypeCheck ;};func (_fab *PSOperand )bitshift (_abd *PSStack )error {_aeg ,_bgd :=_abd .PopInteger ();if _bgd !=nil {return _bgd ;};_bbeb ,_bgd :=_abd .PopInteger ();if _bgd !=nil {return _bgd ;};var _edb int ;if _aeg >=0{_edb =_bbeb <<uint (_aeg );}else {_edb =_bbeb >>uint (-_aeg );};_bgd =_abd .Push (MakeInteger (_edb ));return _bgd ;};func (_bdd *PSOperand )pop (_bcg *PSStack )error {_ ,_baf :=_bcg .Pop ();if _baf !=nil {return _baf ;};return nil ;};func (_eda *PSOperand )Duplicate ()PSObject {_fea :=*_eda ;return &_fea };
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_gfeea :=PSOperand (val );return &_gfeea };func (_cbe *PSOperand )gt (_cae *PSStack )error {_ded ,_gec :=_cae .PopNumberAsFloat64 ();if _gec !=nil {return _gec ;};_dbed ,_gec :=_cae .PopNumberAsFloat64 ();if _gec !=nil {return _gec ;};if _eg .Abs (_dbed -_ded )< _a {_eea :=_cae .Push (MakeBool (false ));return _eea ;}else if _dbed > _ded {_fda :=_cae .Push (MakeBool (true ));return _fda ;}else {_egb :=_cae .Push (MakeBool (false ));return _egb ;};};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_ae *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_gc :=range objects {_geg :=_ae .Stack .Push (_gc );if _geg !=nil {return nil ,_geg ;};};_bd :=_ae ._agb .Exec (_ae .Stack );if _bd !=nil {_ag .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_bd );return nil ,_bd ;};_ca :=[]PSObject (*_ae .Stack );_ae .Stack .Empty ();return _ca ,nil ;};func (_gabc *PSParser )skipSpaces ()(int ,error ){_fgd :=0;for {_ecca ,_cdg :=_gabc ._abgbc .Peek (1);if _cdg !=nil {return 0,_cdg ;};if _g .IsWhiteSpace (_ecca [0]){_gabc ._abgbc .ReadByte ();_fgd ++;}else {break ;};};return _fgd ,nil ;};
// Exec executes the operand `op` in the state specified by `stack`.
func (_dce *PSOperand )Exec (stack *PSStack )error {_eg :=ErrUnsupportedOperand ;switch *_dce {case "\u0061\u0062\u0073":_eg =_dce .abs (stack );case "\u0061\u0064\u0064":_eg =_dce .add (stack );case "\u0061\u006e\u0064":_eg =_dce .and (stack );case "\u0061\u0074\u0061\u006e":_eg =_dce .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_eg =_dce .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_eg =_dce .ceiling (stack );case "\u0063\u006f\u0070\u0079":_eg =_dce .copy (stack );case "\u0063\u006f\u0073":_eg =_dce .cos (stack );case "\u0063\u0076\u0069":_eg =_dce .cvi (stack );case "\u0063\u0076\u0072":_eg =_dce .cvr (stack );case "\u0064\u0069\u0076":_eg =_dce .div (stack );case "\u0064\u0075\u0070":_eg =_dce .dup (stack );case "\u0065\u0071":_eg =_dce .eq (stack );case "\u0065\u0078\u0063\u0068":_eg =_dce .exch (stack );case "\u0065\u0078\u0070":_eg =_dce .exp (stack );case "\u0066\u006c\u006fo\u0072":_eg =_dce .floor (stack );case "\u0067\u0065":_eg =_dce .ge (stack );case "\u0067\u0074":_eg =_dce .gt (stack );case "\u0069\u0064\u0069\u0076":_eg =_dce .idiv (stack );case "\u0069\u0066":_eg =_dce .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_eg =_dce .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_eg =_dce .index (stack );case "\u006c\u0065":_eg =_dce .le (stack );case "\u006c\u006f\u0067":_eg =_dce .log (stack );case "\u006c\u006e":_eg =_dce .ln (stack );case "\u006c\u0074":_eg =_dce .lt (stack );case "\u006d\u006f\u0064":_eg =_dce .mod (stack );case "\u006d\u0075\u006c":_eg =_dce .mul (stack );case "\u006e\u0065":_eg =_dce .ne (stack );case "\u006e\u0065\u0067":_eg =_dce .neg (stack );case "\u006e\u006f\u0074":_eg =_dce .not (stack );case "\u006f\u0072":_eg =_dce .or (stack );case "\u0070\u006f\u0070":_eg =_dce .pop (stack );case "\u0072\u006f\u0075n\u0064":_eg =_dce .round (stack );case "\u0072\u006f\u006c\u006c":_eg =_dce .roll (stack );case "\u0073\u0069\u006e":_eg =_dce .sin (stack );case "\u0073\u0071\u0072\u0074":_eg =_dce .sqrt (stack );case "\u0073\u0075\u0062":_eg =_dce .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_eg =_dce .truncate (stack );case "\u0078\u006f\u0072":_eg =_dce .xor (stack );};return _eg ;};func (_gcf *PSBoolean )Duplicate ()PSObject {_ged :=PSBoolean {};_ged .Val =_gcf .Val ;return &_ged };func (_gfae *PSOperand )roll (_cbee *PSStack )error {_gae ,_ebba :=_cbee .Pop ();if _ebba !=nil {return _ebba ;};_cacff ,_ebba :=_cbee .Pop ();if _ebba !=nil {return _ebba ;};_egbb ,_cgde :=_gae .(*PSInteger );if !_cgde {return ErrTypeCheck ;};_cbf ,_cgde :=_cacff .(*PSInteger );if !_cgde {return ErrTypeCheck ;};if _cbf .Val < 0{return ErrRangeCheck ;};if _cbf .Val ==0||_cbf .Val ==1{return nil ;};if _cbf .Val > len (*_cbee ){return ErrStackUnderflow ;};for _bcd :=0;_bcd < _aaffe (_egbb .Val );_bcd ++{var _gaff []PSObject ;_gaff =(*_cbee )[len (*_cbee )-(_cbf .Val ):len (*_cbee )];if _egbb .Val > 0{_cbeg :=_gaff [len (_gaff )-1];_gaff =append ([]PSObject {_cbeg },_gaff [0:len (_gaff )-1]...);}else {_gdab :=_gaff [len (_gaff )-_cbf .Val ];_gaff =append (_gaff [1:],_gdab );};_gbbc :=append ((*_cbee )[0:len (*_cbee )-_cbf .Val ],_gaff ...);_cbee =&_gbbc ;};return nil ;};func (_fg *PSProgram )Duplicate ()PSObject {_adf :=&PSProgram {};for _ ,_adfe :=range *_fg {_adf .Append (_adfe .Duplicate ());};return _adf ;};func (_dfe *PSReal )String ()string {return _ed .Sprintf ("\u0025\u002e\u0035\u0066",_dfe .Val )};func (_aeb *PSInteger )String ()string {return _ed .Sprintf ("\u0025\u0064",_aeb .Val )};func (_afa *PSOperand )lt (_fge *PSStack )error {_eegf ,_eafe :=_fge .PopNumberAsFloat64 ();if _eafe !=nil {return _eafe ;};_cge ,_eafe :=_fge .PopNumberAsFloat64 ();if _eafe !=nil {return _eafe ;};if _f .Abs (_cge -_eegf )< _c {_bcce :=_fge .Push (MakeBool (false ));return _bcce ;}else if _cge < _eegf {_adfd :=_fge .Push (MakeBool (true ));return _adfd ;}else {_gde :=_fge .Push (MakeBool (false ));return _gde ;};};func (_adb *PSOperand )String ()string {return _ed .Sprintf ("\u0025\u0073",*_adb )};func (_ga *PSReal )Duplicate ()PSObject {_eed :=PSReal {};_eed .Val =_ga .Val ;return &_eed };
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_ccb :=PSParser {};_dfd :=_a .NewBuffer (content );_ccb ._abgbc =_aa .NewReader (_dfd );return &_ccb ;};func (_ccfc *PSOperand )truncate (_fff *PSStack )error {_bba ,_beb :=_fff .Pop ();if _beb !=nil {return _beb ;};if _eeae ,_dae :=_bba .(*PSReal );_dae {_agf :=int (_eeae .Val );_beb =_fff .Push (MakeReal (float64 (_agf )));}else if _cebc ,_cce :=_bba .(*PSInteger );_cce {_beb =_fff .Push (MakeInteger (_cebc .Val ));}else {return ErrTypeCheck ;};return _beb ;};func (_fce *PSOperand )div (_adfg *PSStack )error {_eeb ,_cca :=_adfg .Pop ();if _cca !=nil {return _cca ;};_bagf ,_cca :=_adfg .Pop ();if _cca !=nil {return _cca ;};_fda ,_fbg :=_eeb .(*PSReal );_dba ,_fde :=_eeb .(*PSInteger );if !_fbg &&!_fde {return ErrTypeCheck ;};if _fbg &&_fda .Val ==0{return ErrUndefinedResult ;};if _fde &&_dba .Val ==0{return ErrUndefinedResult ;};_ccce ,_ada :=_bagf .(*PSReal );_fbgc ,_fgg :=_bagf .(*PSInteger );if !_ada &&!_fgg {return ErrTypeCheck ;};var _ddce float64 =0;if _ada {_ddce =_ccce .Val ;}else {_ddce =float64 (_fbgc .Val );};if _fbg {_ddce /=_fda .Val ;}else {_ddce /=float64 (_dba .Val );};_cca =_adfg .Push (MakeReal (_ddce ));return _cca ;};func (_eea *PSOperand )ceiling (_af *PSStack )error {_bcc ,_fadd :=_af .Pop ();if _fadd !=nil {return _fadd ;};if _fcb ,_daa :=_bcc .(*PSReal );_daa {_fadd =_af .Push (MakeReal (_f .Ceil (_fcb .Val )));}else if _ffb ,_bec :=_bcc .(*PSInteger );_bec {_fadd =_af .Push (MakeInteger (_ffb .Val ));}else {_fadd =ErrTypeCheck ;};return _fadd ;};func (_eag *PSOperand )not (_beff *PSStack )error {_cdaa ,_adab :=_beff .Pop ();if _adab !=nil {return _adab ;};if _gdfe ,_eff :=_cdaa .(*PSBoolean );_eff {_adab =_beff .Push (MakeBool (!_gdfe .Val ));return _adab ;}else if _aceb ,_fcbg :=_cdaa .(*PSInteger );_fcbg {_adab =_beff .Push (MakeInteger (^_aceb .Val ));return _adab ;}else {return ErrTypeCheck ;};};func (_dcdf *PSOperand )ln (_cf *PSStack )error {_aba ,_cfd :=_cf .PopNumberAsFloat64 ();if _cfd !=nil {return _cfd ;};_eedb :=_f .Log (_aba );_cfd =_cf .Push (MakeReal (_eedb ));return _cfd ;};func (_ebg *PSParser )parseFunction ()(*PSProgram ,error ){_ggg ,_ :=_ebg ._abgbc .ReadByte ();if _ggg !='{'{return nil ,_e .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_adca :=NewPSProgram ();for {_ebg .skipSpaces ();_gcba ,_fbc :=_ebg ._abgbc .Peek (2);if _fbc !=nil {if _fbc ==_bg .EOF {break ;};return nil ,_fbc ;};_ag .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_gcba ));if _gcba [0]=='}'{_ag .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_ebg ._abgbc .ReadByte ();break ;}else if _gcba [0]=='{'{_ag .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_gaea ,_abgd :=_ebg .parseFunction ();if _abgd !=nil {return nil ,_abgd ;};_adca .Append (_gaea );}else if _g .IsDecimalDigit (_gcba [0])||(_gcba [0]=='-'&&_g .IsDecimalDigit (_gcba [1])){_ag .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_fbfd ,_adgd :=_ebg .parseNumber ();if _adgd !=nil {return nil ,_adgd ;};_adca .Append (_fbfd );}else {_ag .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_gcba ,_ =_ebg ._abgbc .Peek (5);_aafa :=string (_gcba );_ag .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_aafa );if (len (_aafa )> 4)&&(_aafa [:5]=="\u0066\u0061\u006cs\u0065"){_beae ,_dbb :=_ebg .parseBool ();if _dbb !=nil {return nil ,_dbb ;};_adca .Append (_beae );}else if (len (_aafa )> 3)&&(_aafa [:4]=="\u0074\u0072\u0075\u0065"){_dcbe ,_edbe :=_ebg .parseBool ();if _edbe !=nil {return nil ,_edbe ;};_adca .Append (_dcbe );}else {_ffad ,_ccdb :=_ebg .parseOperand ();if _ccdb !=nil {return nil ,_ccdb ;};_adca .Append (_ffad );};};};return _adca ,nil ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_abgbc *_aa .Reader };func (_bed *PSOperand )eq (_adfa *PSStack )error {_gca ,_gcde :=_adfa .Pop ();if _gcde !=nil {return _gcde ;};_cadb ,_gcde :=_adfa .Pop ();if _gcde !=nil {return _gcde ;};_fca ,_afe :=_gca .(*PSBoolean );_fbd ,_bae :=_cadb .(*PSBoolean );if _afe ||_bae {var _ffbd error ;if _afe &&_bae {_ffbd =_adfa .Push (MakeBool (_fca .Val ==_fbd .Val ));}else {_ffbd =_adfa .Push (MakeBool (false ));};return _ffbd ;};var _fdcc float64 ;var _ebb float64 ;if _cacda ,_dag :=_gca .(*PSInteger );_dag {_fdcc =float64 (_cacda .Val );}else if _fee ,_aege :=_gca .(*PSReal );_aege {_fdcc =_fee .Val ;}else {return ErrTypeCheck ;};if _fcf ,_edc :=_cadb .(*PSInteger );_edc {_ebb =float64 (_fcf .Val );}else if _ecc ,_dcbf :=_cadb .(*PSReal );_dcbf {_ebb =_ecc .Val ;}else {return ErrTypeCheck ;};if _f .Abs (_ebb -_fdcc )< _c {_gcde =_adfa .Push (MakeBool (true ));}else {_gcde =_adfa .Push (MakeBool (false ));};return _gcde ;};func (_gfd *PSOperand )dup (_age *PSStack )error {_cadc ,_eegg :=_age .Pop ();if _eegg !=nil {return _eegg ;};_eegg =_age .Push (_cadc );if _eegg !=nil {return _eegg ;};_eegg =_age .Push (_cadc .Duplicate ());return _eegg ;};func (_gegg *PSParser )parseBool ()(*PSBoolean ,error ){_bgg ,_fec :=_gegg ._abgbc .Peek (4);if _fec !=nil {return MakeBool (false ),_fec ;};if (len (_bgg )>=4)&&(string (_bgg [:4])=="\u0074\u0072\u0075\u0065"){_gegg ._abgbc .Discard (4);return MakeBool (true ),nil ;};_bgg ,_fec =_gegg ._abgbc .Peek (5);if _fec !=nil {return MakeBool (false ),_fec ;};if (len (_bgg )>=5)&&(string (_bgg [:5])=="\u0066\u0061\u006cs\u0065"){_gegg ._abgbc .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_e .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
func NewPSExecutor (program *PSProgram )*PSExecutor {_ee :=&PSExecutor {};_ee .Stack =NewPSStack ();_ee ._agb =program ;return _ee ;};func (_eaf *PSOperand )gt (_abed *PSStack )error {_bbc ,_ega :=_abed .PopNumberAsFloat64 ();if _ega !=nil {return _ega ;};_aad ,_ega :=_abed .PopNumberAsFloat64 ();if _ega !=nil {return _ega ;};if _f .Abs (_aad -_bbc )< _c {_ageb :=_abed .Push (MakeBool (false ));return _ageb ;}else if _aad > _bbc {_fbf :=_abed .Push (MakeBool (true ));return _fbf ;}else {_bbd :=_abed .Push (MakeBool (false ));return _bbd ;};};var ErrUndefinedResult =_e .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_ebgb *PSParser )parseOperand ()(*PSOperand ,error ){var _feb []byte ;for {_aacf ,_dbad :=_ebgb ._abgbc .Peek (1);if _dbad !=nil {if _dbad ==_bg .EOF {break ;};return nil ,_dbad ;};if _g .IsDelimiter (_aacf [0]){break ;};if _g .IsWhiteSpace (_aacf [0]){break ;};_gec ,_ :=_ebgb ._abgbc .ReadByte ();_feb =append (_feb ,_gec );};if len (_feb )==0{return nil ,_e .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 (_feb )),nil ;};
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_dadb *PSStack )DebugString ()string {_degg :="\u005b\u0020";for _ ,_dcf :=range *_dadb {_degg +=_dcf .DebugString ();_degg +="\u0020";};_degg +="\u005d";return _degg ;};func (_fe *PSBoolean )String ()string {return _ed .Sprintf ("\u0025\u0076",_fe .Val )};
// 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 _ff []float64 ;for _ ,_ac :=range objects {if _acc ,_g :=_ac .(*PSInteger );_g {_ff =append (_ff ,float64 (_acc .Val ));}else if _eb ,_af :=_ac .(*PSReal );_af {_ff =append (_ff ,_eb .Val );}else {return nil ,ErrTypeCheck ;};};return _ff ,nil ;};func (_cag *PSOperand )add (_dac *PSStack )error {_bae ,_gcb :=_dac .Pop ();if _gcb !=nil {return _gcb ;};_baf ,_gcb :=_dac .Pop ();if _gcb !=nil {return _gcb ;};_bbd ,_dea :=_bae .(*PSReal );_ffg ,_df :=_bae .(*PSInteger );if !_dea &&!_df {return ErrTypeCheck ;};_dec ,_agf :=_baf .(*PSReal );_bdc ,_gbc :=_baf .(*PSInteger );if !_agf &&!_gbc {return ErrTypeCheck ;};if _df &&_gbc {_ffb :=_ffg .Val +_bdc .Val ;_gee :=_dac .Push (MakeInteger (_ffb ));return _gee ;};var _adg float64 =0;if _dea {_adg =_bbd .Val ;}else {_adg =float64 (_ffg .Val );};if _agf {_adg +=_dec .Val ;}else {_adg +=float64 (_bdc .Val );};_gcb =_dac .Push (MakeReal (_adg ));return _gcb ;};var ErrRangeCheck =_e .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_cce *PSOperand )lt (_cbfa *PSStack )error {_agcf ,_gag :=_cbfa .PopNumberAsFloat64 ();if _gag !=nil {return _gag ;};_fggb ,_gag :=_cbfa .PopNumberAsFloat64 ();if _gag !=nil {return _gag ;};if _eg .Abs (_fggb -_agcf )< _a {_cgc :=_cbfa .Push (MakeBool (false ));return _cgc ;}else if _fggb < _agcf {_dggb :=_cbfa .Push (MakeBool (true ));return _dggb ;}else {_bbdg :=_cbfa .Push (MakeBool (false ));return _bbdg ;};};func _abbb (_dfaa int )int {if _dfaa < 0{return -_dfaa ;};return _dfaa ;};var ErrUndefinedResult =_e .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_ag *PSProgram )DebugString ()string {_gb :="\u007b\u0020";for _ ,_ffc :=range *_ag {_gb +=_ffc .DebugString ();_gb +="\u0020";};_gb +="\u007d";return _gb ;};func (_agfa *PSOperand )div (_cda *PSStack )error {_dbd ,_dcge :=_cda .Pop ();if _dcge !=nil {return _dcge ;};_cdf ,_dcge :=_cda .Pop ();if _dcge !=nil {return _dcge ;};_bbcf ,_dd :=_dbd .(*PSReal );_acb ,_ada :=_dbd .(*PSInteger );if !_dd &&!_ada {return ErrTypeCheck ;};if _dd &&_bbcf .Val ==0{return ErrUndefinedResult ;};if _ada &&_acb .Val ==0{return ErrUndefinedResult ;};_fcg ,_bafe :=_cdf .(*PSReal );_eeb ,_gd :=_cdf .(*PSInteger );if !_bafe &&!_gd {return ErrTypeCheck ;};var _cca float64 =0;if _bafe {_cca =_fcg .Val ;}else {_cca =float64 (_eeb .Val );};if _dd {_cca /=_bbcf .Val ;}else {_cca /=float64 (_acb .Val );};_dcge =_cda .Push (MakeReal (_cca ));return _dcge ;};func (_ebab *PSOperand )mod (_fbd *PSStack )error {_adbe ,_gdgg :=_fbd .Pop ();if _gdgg !=nil {return _gdgg ;};_edg ,_gdgg :=_fbd .Pop ();if _gdgg !=nil {return _gdgg ;};_gfg ,_bcag :=_adbe .(*PSInteger );if !_bcag {return ErrTypeCheck ;};if _gfg .Val ==0{return ErrUndefinedResult ;};_ecc ,_bcag :=_edg .(*PSInteger );if !_bcag {return ErrTypeCheck ;};_cgdd :=_ecc .Val %_gfg .Val ;_gdgg =_fbd .Push (MakeInteger (_cgdd ));return _gdgg ;};func (_dcc *PSOperand )dup (_bcc *PSStack )error {_fgg ,_eggd :=_bcc .Pop ();if _eggd !=nil {return _eggd ;};_eggd =_bcc .Push (_fgg );if _eggd !=nil {return _eggd ;};_eggd =_bcc .Push (_fgg .Duplicate ());return _eggd ;};func (_ebd *PSOperand )bitshift (_dgb *PSStack )error {_dgf ,_ed :=_dgb .PopInteger ();if _ed !=nil {return _ed ;};_bgec ,_ed :=_dgb .PopInteger ();if _ed !=nil {return _ed ;};var _eca int ;if _dgf >=0{_eca =_bgec <<uint (_dgf );}else {_eca =_bgec >>uint (-_dgf );};_ed =_dgb .Push (MakeInteger (_eca ));return _ed ;};func (_cegf *PSOperand )atan (_dee *PSStack )error {_adb ,_aag :=_dee .PopNumberAsFloat64 ();if _aag !=nil {return _aag ;};_egg ,_aag :=_dee .PopNumberAsFloat64 ();if _aag !=nil {return _aag ;};if _adb ==0{var _bba error ;if _egg < 0{_bba =_dee .Push (MakeReal (270));}else {_bba =_dee .Push (MakeReal (90));};return _bba ;};_cdde :=_egg /_adb ;_dfgf :=_eg .Atan (_cdde )*180/_eg .Pi ;_aag =_dee .Push (MakeReal (_dfgf ));return _aag ;};
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
// Real or integer only.
func (_fgaa *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_affe ,_aebe :=_fgaa .Pop ();if _aebe !=nil {return 0,_aebe ;};if _ecd ,_gga :=_affe .(*PSReal );_gga {return _ecd .Val ,nil ;}else if _baea ,_deg :=_affe .(*PSInteger );_deg {return float64 (_baea .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_gf *PSProgram )DebugString ()string {_bc :="\u007b\u0020";for _ ,_ef :=range *_gf {_bc +=_ef .DebugString ();_bc +="\u0020";};_bc +="\u007d";return _bc ;};func (_bee *PSOperand )cvi (_bca *PSStack )error {_bccb ,_dbga :=_bca .Pop ();if _dbga !=nil {return _dbga ;};if _ccc ,_bea :=_bccb .(*PSReal );_bea {_bef :=int (_ccc .Val );_dbga =_bca .Push (MakeInteger (_bef ));}else if _agdg ,_dec :=_bccb .(*PSInteger );_dec {_def :=_agdg .Val ;_dbga =_bca .Push (MakeInteger (_def ));}else {return ErrTypeCheck ;};return _dbga ;};
func (_ccea *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_ebc ,_gfa :=_ccea .Pop ();if _gfa !=nil {return 0,_gfa ;};if _bgfd ,_ffgd :=_ebc .(*PSReal );_ffgd {return _bgfd .Val ,nil ;}else if _gagc ,_ggd :=_ebc .(*PSInteger );_ggd {return float64 (_gagc .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_ebb *PSOperand )sqrt (_gbag *PSStack )error {_fcfe ,_dcaa :=_gbag .PopNumberAsFloat64 ();if _dcaa !=nil {return _dcaa ;};if _fcfe < 0{return ErrRangeCheck ;};_gad :=_eg .Sqrt (_fcfe );_dcaa =_gbag .Push (MakeReal (_gad ));return _dcaa ;};func (_dce *PSOperand )cvr (_gbf *PSStack )error {_bbc ,_ega :=_gbf .Pop ();if _ega !=nil {return _ega ;};if _baa ,_ebf :=_bbc .(*PSReal );_ebf {_ega =_gbf .Push (MakeReal (_baa .Val ));}else if _bdad ,_dead :=_bbc .(*PSInteger );_dead {_ega =_gbf .Push (MakeReal (float64 (_bdad .Val )));}else {return ErrTypeCheck ;};return _ega ;};
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
type PSProgram []PSObject ;
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_fadf :=PSBoolean {};_fadf .Val =val ;return &_fadf };func (_gcg *PSOperand )cvr (_cbe *PSStack )error {_ddgc ,_dbgg :=_cbe .Pop ();if _dbgg !=nil {return _dbgg ;};if _fga ,_bde :=_ddgc .(*PSReal );_bde {_dbgg =_cbe .Push (MakeReal (_fga .Val ));}else if _dcd ,_aaf :=_ddgc .(*PSInteger );_aaf {_dbgg =_cbe .Push (MakeReal (float64 (_dcd .Val )));}else {return ErrTypeCheck ;};return _dbgg ;};func (_cg *PSOperand )copy (_ceb *PSStack )error {_dfc ,_cef :=_ceb .PopInteger ();if _cef !=nil {return _cef ;};if _dfc < 0{return ErrRangeCheck ;};if _dfc > len (*_ceb ){return ErrRangeCheck ;};*_ceb =append (*_ceb ,(*_ceb )[len (*_ceb )-_dfc :]...);return nil ;};
// String returns a string representation of the stack.
func (_gggc *PSStack )String ()string {_dad :="\u005b\u0020";for _ ,_ccfb :=range *_gggc {_dad +=_ccfb .String ();_dad +="\u0020";};_dad +="\u005d";return _dad ;};
// Push pushes an object on top of the stack.
func (_cgc *PSStack )Push (obj PSObject )error {if len (*_cgc )> 100{return ErrStackOverflow ;};*_cgc =append (*_cgc ,obj );return nil ;};
// Pop pops an object from the top of the stack.
func (_eedd *PSStack )Pop ()(PSObject ,error ){if len (*_eedd )< 1{return nil ,ErrStackUnderflow ;};_ggb :=(*_eedd )[len (*_eedd )-1];*_eedd =(*_eedd )[0:len (*_eedd )-1];return _ggb ,nil ;};
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;func (_fdg *PSOperand )mod (_ecg *PSStack )error {_fef ,_dgb :=_ecg .Pop ();if _dgb !=nil {return _dgb ;};_fbaf ,_dgb :=_ecg .Pop ();if _dgb !=nil {return _dgb ;};_aefg ,_agba :=_fef .(*PSInteger );if !_agba {return ErrTypeCheck ;};if _aefg .Val ==0{return ErrUndefinedResult ;};_cec ,_agba :=_fbaf .(*PSInteger );if !_agba {return ErrTypeCheck ;};_aed :=_cec .Val %_aefg .Val ;_dgb =_ecg .Push (MakeInteger (_aed ));return _dgb ;};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};func (_bf *PSProgram )String ()string {_ca :="\u007b\u0020";for _ ,_afg :=range *_bf {_ca +=_afg .String ();_ca +="\u0020";};_ca +="\u007d";return _ca ;};func (_gae *PSOperand )ln (_edce *PSStack )error {_gdb ,_gacg :=_edce .PopNumberAsFloat64 ();if _gacg !=nil {return _gacg ;};_cabc :=_eg .Log (_gdb );_gacg =_edce .Push (MakeReal (_cabc ));return _gacg ;};
// Append appends an object to the PSProgram.
func (_dc *PSProgram )Append (obj PSObject ){*_dc =append (*_dc ,obj )};func (_de *PSOperand )DebugString ()string {return _ed .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_de );};func (_fba *PSOperand )index (_edg *PSStack )error {_gfa ,_bfe :=_edg .Pop ();if _bfe !=nil {return _bfe ;};_cbgd ,_eef :=_gfa .(*PSInteger );if !_eef {return ErrTypeCheck ;};if _cbgd .Val < 0{return ErrRangeCheck ;};if _cbgd .Val > len (*_edg )-1{return ErrStackUnderflow ;};_cacf :=(*_edg )[len (*_edg )-1-_cbgd .Val ];_bfe =_edg .Push (_cacf .Duplicate ());return _bfe ;};
func (_aa *PSProgram )Append (obj PSObject ){*_aa =append (*_aa ,obj )};func (_bbg *PSOperand )ne (_cfaa *PSStack )error {_bbgd :=_bbg .eq (_cfaa );if _bbgd !=nil {return _bbgd ;};_bbgd =_bbg .not (_cfaa );return _bbgd ;};func (_ga *PSProgram )Duplicate ()PSObject {_db :=&PSProgram {};for _ ,_caf :=range *_ga {_db .Append (_caf .Duplicate ());};return _db ;};
// String returns a string representation of the stack.
func (_gfee *PSStack )String ()string {_bdge :="\u005b\u0020";for _ ,_agfd :=range *_gfee {_bdge +=_agfd .String ();_bdge +="\u0020";};_bdge +="\u005d";return _bdge ;};
// PSObject represents a postscript object.
type PSObject interface{
@ -103,17 +56,64 @@ Duplicate ()PSObject ;
DebugString ()string ;
// String returns a string representation of the PSObject.
String ()string ;};
String ()string ;};func (_ad *PSOperand )String ()string {return _fg .Sprintf ("\u0025\u0073",*_ad )};func (_gc *PSOperand )Duplicate ()PSObject {_fde :=*_gc ;return &_fde };func (_bbde *PSOperand )ceiling (_bda *PSStack )error {_decb ,_ace :=_bda .Pop ();if _ace !=nil {return _ace ;};if _efc ,_gef :=_decb .(*PSReal );_gef {_ace =_bda .Push (MakeReal (_eg .Ceil (_efc .Val )));}else if _deb ,_edb :=_decb .(*PSInteger );_edb {_ace =_bda .Push (MakeInteger (_deb .Val ));}else {_ace =ErrTypeCheck ;};return _ace ;};func (_bgge *PSParser )parseFunction ()(*PSProgram ,error ){_fge ,_ :=_bgge ._gde .ReadByte ();if _fge !='{'{return nil ,_e .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_gccd :=NewPSProgram ();for {_bgge .skipSpaces ();_fbdf ,_dbc :=_bgge ._gde .Peek (2);if _dbc !=nil {if _dbc ==_ea .EOF {break ;};return nil ,_dbc ;};_b .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_fbdf ));if _fbdf [0]=='}'{_b .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_bgge ._gde .ReadByte ();break ;}else if _fbdf [0]=='{'{_b .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_fce ,_faa :=_bgge .parseFunction ();if _faa !=nil {return nil ,_faa ;};_gccd .Append (_fce );}else if _feb .IsDecimalDigit (_fbdf [0])||(_fbdf [0]=='-'&&_feb .IsDecimalDigit (_fbdf [1])){_b .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_bbgg ,_gcaa :=_bgge .parseNumber ();if _gcaa !=nil {return nil ,_gcaa ;};_gccd .Append (_bbgg );}else {_b .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_fbdf ,_ =_bgge ._gde .Peek (5);_fafb :=string (_fbdf );_b .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_fafb );if (len (_fafb )> 4)&&(_fafb [:5]=="\u0066\u0061\u006cs\u0065"){_fbgc ,_abce :=_bgge .parseBool ();if _abce !=nil {return nil ,_abce ;};_gccd .Append (_fbgc );}else if (len (_fafb )> 3)&&(_fafb [:4]=="\u0074\u0072\u0075\u0065"){_afbf ,_baad :=_bgge .parseBool ();if _baad !=nil {return nil ,_baad ;};_gccd .Append (_afbf );}else {_aadb ,_cedb :=_bgge .parseOperand ();if _cedb !=nil {return nil ,_cedb ;};_gccd .Append (_aadb );};};};return _gccd ,nil ;};func (_dbdc *PSOperand )floor (_abc *PSStack )error {_cfa ,_gdd :=_abc .Pop ();if _gdd !=nil {return _gdd ;};if _cfe ,_cdbc :=_cfa .(*PSReal );_cdbc {_gdd =_abc .Push (MakeReal (_eg .Floor (_cfe .Val )));}else if _cac ,_ede :=_cfa .(*PSInteger );_ede {_gdd =_abc .Push (MakeInteger (_cac .Val ));}else {return ErrTypeCheck ;};return _gdd ;};const _a =0.000001;func (_gf *PSBoolean )String ()string {return _fg .Sprintf ("\u0025\u0076",_gf .Val )};func (_dbb *PSOperand )cvi (_dba *PSStack )error {_gabc ,_fgc :=_dba .Pop ();if _fgc !=nil {return _fgc ;};if _gebg ,_bef :=_gabc .(*PSReal );_bef {_afgb :=int (_gebg .Val );_fgc =_dba .Push (MakeInteger (_afgb ));}else if _cdbb ,_efa :=_gabc .(*PSInteger );_efa {_decd :=_cdbb .Val ;_fgc =_dba .Push (MakeInteger (_decd ));}else {return ErrTypeCheck ;};return _fgc ;};func (_gaa *PSOperand )roll (_gggf *PSStack )error {_caae ,_edcc :=_gggf .Pop ();if _edcc !=nil {return _edcc ;};_bcd ,_edcc :=_gggf .Pop ();if _edcc !=nil {return _edcc ;};_abae ,_ggae :=_caae .(*PSInteger );if !_ggae {return ErrTypeCheck ;};_bgag ,_ggae :=_bcd .(*PSInteger );if !_ggae {return ErrTypeCheck ;};if _bgag .Val < 0{return ErrRangeCheck ;};if _bgag .Val ==0||_bgag .Val ==1{return nil ;};if _bgag .Val > len (*_gggf ){return ErrStackUnderflow ;};for _fdb :=0;_fdb < _abbb (_abae .Val );_fdb ++{var _ggf []PSObject ;_ggf =(*_gggf )[len (*_gggf )-(_bgag .Val ):len (*_gggf )];if _abae .Val > 0{_ecee :=_ggf [len (_ggf )-1];_ggf =append ([]PSObject {_ecee },_ggf [0:len (_ggf )-1]...);}else {_cceb :=_ggf [len (_ggf )-_bgag .Val ];_ggf =append (_ggf [1:],_cceb );};_bgg :=append ((*_gggf )[0:len (*_gggf )-_bgag .Val ],_ggf ...);_gggf =&_bgg ;};return nil ;};
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_fdbd *PSStack )DebugString ()string {_dceca :="\u005b\u0020";for _ ,_bfcf :=range *_fdbd {_dceca +=_bfcf .DebugString ();_dceca +="\u0020";};_dceca +="\u005d";return _dceca ;};func (_gg *PSInteger )DebugString ()string {return _fg .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_gg .Val );};func (_dc *PSInteger )String ()string {return _fg .Sprintf ("\u0025\u0064",_dc .Val )};func (_affd *PSOperand )mul (_bdgc *PSStack )error {_egd ,_ege :=_bdgc .Pop ();if _ege !=nil {return _ege ;};_ggg ,_ege :=_bdgc .Pop ();if _ege !=nil {return _ege ;};_afa ,_ffdf :=_egd .(*PSReal );_gbfb ,_abac :=_egd .(*PSInteger );if !_ffdf &&!_abac {return ErrTypeCheck ;};_baee ,_acfc :=_ggg .(*PSReal );_bad ,_fbg :=_ggg .(*PSInteger );if !_acfc &&!_fbg {return ErrTypeCheck ;};if _abac &&_fbg {_befc :=_gbfb .Val *_bad .Val ;_ffa :=_bdgc .Push (MakeInteger (_befc ));return _ffa ;};var _fef float64 =0;if _ffdf {_fef =_afa .Val ;}else {_fef =float64 (_gbfb .Val );};if _acfc {_fef *=_baee .Val ;}else {_fef *=float64 (_bad .Val );};_ege =_bdgc .Push (MakeReal (_fef ));return _ege ;};
// PSBoolean represents a boolean value.
type PSBoolean struct{Val bool ;};
type PSBoolean struct{Val bool ;};func (_bgf *PSOperand )abs (_gfd *PSStack )error {_gcc ,_bd :=_gfd .Pop ();if _bd !=nil {return _bd ;};if _ffe ,_ebe :=_gcc .(*PSReal );_ebe {_aca :=_ffe .Val ;if _aca < 0{_bd =_gfd .Push (MakeReal (-_aca ));}else {_bd =_gfd .Push (MakeReal (_aca ));};}else if _ece ,_fga :=_gcc .(*PSInteger );_fga {_gfe :=_ece .Val ;if _gfe < 0{_bd =_gfd .Push (MakeInteger (-_gfe ));}else {_bd =_gfd .Push (MakeInteger (_gfe ));};}else {return ErrTypeCheck ;};return _bd ;};func (_cga *PSOperand )exp (_aga *PSStack )error {_ced ,_bga :=_aga .PopNumberAsFloat64 ();if _bga !=nil {return _bga ;};_bcbf ,_bga :=_aga .PopNumberAsFloat64 ();if _bga !=nil {return _bga ;};if _eg .Abs (_ced )< 1&&_bcbf < 0{return ErrUndefinedResult ;};_dgg :=_eg .Pow (_bcbf ,_ced );_bga =_aga .Push (MakeReal (_dgg ));return _bga ;};func (_bb *PSReal )DebugString ()string {return _fg .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_bb .Val );};func (_eggb *PSParser )parseNumber ()(PSObject ,error ){_eaga ,_adffa :=_feb .ParseNumber (_eggb ._gde );if _adffa !=nil {return nil ,_adffa ;};switch _gage :=_eaga .(type ){case *_feb .PdfObjectFloat :return MakeReal (float64 (*_gage )),nil ;case *_feb .PdfObjectInteger :return MakeInteger (int (*_gage )),nil ;};return nil ,_fg .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_eaga );};var ErrUnsupportedOperand =_e .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_abcf *PSParser )parseOperand ()(*PSOperand ,error ){var _dfe []byte ;for {_fbcb ,_abb :=_abcf ._gde .Peek (1);if _abb !=nil {if _abb ==_ea .EOF {break ;};return nil ,_abb ;};if _feb .IsDelimiter (_fbcb [0]){break ;};if _feb .IsWhiteSpace (_fbcb [0]){break ;};_bdd ,_ :=_abcf ._gde .ReadByte ();_dfe =append (_dfe ,_bdd );};if len (_dfe )==0{return nil ,_e .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 (_dfe )),nil ;};func (_gfde *PSOperand )log (_fgcc *PSStack )error {_cadb ,_ddg :=_fgcc .PopNumberAsFloat64 ();if _ddg !=nil {return _ddg ;};_bbe :=_eg .Log10 (_cadb );_ddg =_fgcc .Push (MakeReal (_bbe ));return _ddg ;};
// Parse parses the postscript and store as a program that can be executed.
func (_gdfa *PSParser )Parse ()(*PSProgram ,error ){_gdfa .skipSpaces ();_ccbc ,_gff :=_gdfa ._abgbc .Peek (2);if _gff !=nil {return nil ,_gff ;};if _ccbc [0]!='{'{return nil ,_e .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");};_gcb ,_gff :=_gdfa .parseFunction ();if _gff !=nil &&_gff !=_bg .EOF {return nil ,_gff ;};return _gcb ,_gff ;};func (_ddc *PSOperand )abs (_fa *PSStack )error {_bac ,_gfg :=_fa .Pop ();if _gfg !=nil {return _gfg ;};if _abf ,_faf :=_bac .(*PSReal );_faf {_dfa :=_abf .Val ;if _dfa < 0{_gfg =_fa .Push (MakeReal (-_dfa ));}else {_gfg =_fa .Push (MakeReal (_dfa ));};}else if _fad ,_bb :=_bac .(*PSInteger );_bb {_ccd :=_fad .Val ;if _ccd < 0{_gfg =_fa .Push (MakeInteger (-_ccd ));}else {_gfg =_fa .Push (MakeInteger (_ccd ));};}else {return ErrTypeCheck ;};return _gfg ;};
func (_bbdf *PSParser )Parse ()(*PSProgram ,error ){_bbdf .skipSpaces ();_dgff ,_dag :=_bbdf ._gde .Peek (2);if _dag !=nil {return nil ,_dag ;};if _dgff [0]!='{'{return nil ,_e .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");};_abg ,_dag :=_bbdf .parseFunction ();if _dag !=nil &&_dag !=_ea .EOF {return nil ,_dag ;};return _abg ,_dag ;};func (_bea *PSOperand )ifelse (_aff *PSStack )error {_dbee ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_gbg ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_eba ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_cea ,_gga :=_dbee .(*PSProgram );if !_gga {return ErrTypeCheck ;};_adf ,_gga :=_gbg .(*PSProgram );if !_gga {return ErrTypeCheck ;};_def ,_gga :=_eba .(*PSBoolean );if !_gga {return ErrTypeCheck ;};if _def .Val {_bebd :=_adf .Exec (_aff );return _bebd ;};_dbda =_cea .Exec (_aff );return _dbda ;};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_aef :=PSInteger {};_aef .Val =val ;return &_aef };func (_ffd *PSBoolean )DebugString ()string {return _fg .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_ffd .Val );};func (_cbee *PSOperand )not (_bab *PSStack )error {_eccg ,_cgdg :=_bab .Pop ();if _cgdg !=nil {return _cgdg ;};if _aegg ,_cdbbg :=_eccg .(*PSBoolean );_cdbbg {_cgdg =_bab .Push (MakeBool (!_aegg .Val ));return _cgdg ;}else if _affe ,_bagf :=_eccg .(*PSInteger );_bagf {_cgdg =_bab .Push (MakeInteger (^_affe .Val ));return _cgdg ;}else {return ErrTypeCheck ;};};func (_edec *PSOperand )ge (_bage *PSStack )error {_bfe ,_bdg :=_bage .PopNumberAsFloat64 ();if _bdg !=nil {return _bdg ;};_adc ,_bdg :=_bage .PopNumberAsFloat64 ();if _bdg !=nil {return _bdg ;};if _eg .Abs (_adc -_bfe )< _a {_fad :=_bage .Push (MakeBool (true ));return _fad ;}else if _adc > _bfe {_fff :=_bage .Push (MakeBool (true ));return _fff ;}else {_cef :=_bage .Push (MakeBool (false ));return _cef ;};};func (_ee *PSReal )Duplicate ()PSObject {_aba :=PSReal {};_aba .Val =_ee .Val ;return &_aba };var ErrStackOverflow =_e .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
func NewPSExecutor (program *PSProgram )*PSExecutor {_de :=&PSExecutor {};_de .Stack =NewPSStack ();_de ._fb =program ;return _de ;};
// PSReal represents a real number.
type PSReal struct{Val float64 ;};
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};func (_cd *PSReal )String ()string {return _fg .Sprintf ("\u0025\u002e\u0035\u0066",_cd .Val )};
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;
// Push pushes an object on top of the stack.
func (_edee *PSStack )Push (obj PSObject )error {if len (*_edee )> 100{return ErrStackOverflow ;};*_edee =append (*_edee ,obj );return nil ;};
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_fd *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_bg :=range objects {_ec :=_fd .Stack .Push (_bg );if _ec !=nil {return nil ,_ec ;};};_bge :=_fd ._fb .Exec (_fd .Stack );if _bge !=nil {_b .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_bge );return nil ,_bge ;};_febb :=[]PSObject (*_fd .Stack );_fd .Stack .Empty ();return _febb ,nil ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_gde *_fe .Reader };func (_adff *PSOperand )or (_dcgb *PSStack )error {_befe ,_adac :=_dcgb .Pop ();if _adac !=nil {return _adac ;};_dca ,_adac :=_dcgb .Pop ();if _adac !=nil {return _adac ;};if _dgd ,_bgc :=_befe .(*PSBoolean );_bgc {_fbe ,_fcfb :=_dca .(*PSBoolean );if !_fcfb {return ErrTypeCheck ;};_adac =_dcgb .Push (MakeBool (_dgd .Val ||_fbe .Val ));return _adac ;};if _bgcg ,_faf :=_befe .(*PSInteger );_faf {_fbc ,_fdec :=_dca .(*PSInteger );if !_fdec {return ErrTypeCheck ;};_adac =_dcgb .Push (MakeInteger (_bgcg .Val |_fbc .Val ));return _adac ;};return ErrTypeCheck ;};func (_afe *PSParser )parseBool ()(*PSBoolean ,error ){_dcfb ,_fgef :=_afe ._gde .Peek (4);if _fgef !=nil {return MakeBool (false ),_fgef ;};if (len (_dcfb )>=4)&&(string (_dcfb [:4])=="\u0074\u0072\u0075\u0065"){_afe ._gde .Discard (4);return MakeBool (true ),nil ;};_dcfb ,_fgef =_afe ._gde .Peek (5);if _fgef !=nil {return MakeBool (false ),_fgef ;};if (len (_dcfb )>=5)&&(string (_dcfb [:5])=="\u0066\u0061\u006cs\u0065"){_afe ._gde .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_e .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};func (_fcc *PSOperand )le (_ecf *PSStack )error {_eebg ,_cedc :=_ecf .PopNumberAsFloat64 ();if _cedc !=nil {return _cedc ;};_dcce ,_cedc :=_ecf .PopNumberAsFloat64 ();if _cedc !=nil {return _cedc ;};if _eg .Abs (_dcce -_eebg )< _a {_bgd :=_ecf .Push (MakeBool (true ));return _bgd ;}else if _dcce < _eebg {_bfbf :=_ecf .Push (MakeBool (true ));return _bfbf ;}else {_bfc :=_ecf .Push (MakeBool (false ));return _bfc ;};};func (_be *PSOperand )cos (_abe *PSStack )error {_beb ,_gfb :=_abe .PopNumberAsFloat64 ();if _gfb !=nil {return _gfb ;};_bgee :=_eg .Cos (_beb *_eg .Pi /180.0);_gfb =_abe .Push (MakeReal (_bgee ));return _gfb ;};
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
func (_ddbg *PSStack )PopInteger ()(int ,error ){_ebbe ,_aed :=_ddbg .Pop ();if _aed !=nil {return 0,_aed ;};if _abd ,_fee :=_ebbe .(*PSInteger );_fee {return _abd .Val ,nil ;};return 0,ErrTypeCheck ;};
// Exec executes the operand `op` in the state specified by `stack`.
func (_aad *PSOperand )Exec (stack *PSStack )error {_cc :=ErrUnsupportedOperand ;switch *_aad {case "\u0061\u0062\u0073":_cc =_aad .abs (stack );case "\u0061\u0064\u0064":_cc =_aad .add (stack );case "\u0061\u006e\u0064":_cc =_aad .and (stack );case "\u0061\u0074\u0061\u006e":_cc =_aad .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_cc =_aad .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_cc =_aad .ceiling (stack );case "\u0063\u006f\u0070\u0079":_cc =_aad .copy (stack );case "\u0063\u006f\u0073":_cc =_aad .cos (stack );case "\u0063\u0076\u0069":_cc =_aad .cvi (stack );case "\u0063\u0076\u0072":_cc =_aad .cvr (stack );case "\u0064\u0069\u0076":_cc =_aad .div (stack );case "\u0064\u0075\u0070":_cc =_aad .dup (stack );case "\u0065\u0071":_cc =_aad .eq (stack );case "\u0065\u0078\u0063\u0068":_cc =_aad .exch (stack );case "\u0065\u0078\u0070":_cc =_aad .exp (stack );case "\u0066\u006c\u006fo\u0072":_cc =_aad .floor (stack );case "\u0067\u0065":_cc =_aad .ge (stack );case "\u0067\u0074":_cc =_aad .gt (stack );case "\u0069\u0064\u0069\u0076":_cc =_aad .idiv (stack );case "\u0069\u0066":_cc =_aad .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_cc =_aad .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_cc =_aad .index (stack );case "\u006c\u0065":_cc =_aad .le (stack );case "\u006c\u006f\u0067":_cc =_aad .log (stack );case "\u006c\u006e":_cc =_aad .ln (stack );case "\u006c\u0074":_cc =_aad .lt (stack );case "\u006d\u006f\u0064":_cc =_aad .mod (stack );case "\u006d\u0075\u006c":_cc =_aad .mul (stack );case "\u006e\u0065":_cc =_aad .ne (stack );case "\u006e\u0065\u0067":_cc =_aad .neg (stack );case "\u006e\u006f\u0074":_cc =_aad .not (stack );case "\u006f\u0072":_cc =_aad .or (stack );case "\u0070\u006f\u0070":_cc =_aad .pop (stack );case "\u0072\u006f\u0075n\u0064":_cc =_aad .round (stack );case "\u0072\u006f\u006c\u006c":_cc =_aad .roll (stack );case "\u0073\u0069\u006e":_cc =_aad .sin (stack );case "\u0073\u0071\u0072\u0074":_cc =_aad .sqrt (stack );case "\u0073\u0075\u0062":_cc =_aad .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_cc =_aad .truncate (stack );case "\u0078\u006f\u0072":_cc =_aad .xor (stack );};return _cc ;};
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
type PSProgram []PSObject ;func (_faga *PSOperand )round (_cddd *PSStack )error {_bfd ,_dfa :=_cddd .Pop ();if _dfa !=nil {return _dfa ;};if _gba ,_gbe :=_bfd .(*PSReal );_gbe {_dfa =_cddd .Push (MakeReal (_eg .Floor (_gba .Val +0.5)));}else if _eage ,_caef :=_bfd .(*PSInteger );_caef {_dfa =_cddd .Push (MakeInteger (_eage .Val ));}else {return ErrTypeCheck ;};return _dfa ;};func (_ce *PSOperand )and (_fec *PSStack )error {_fa ,_aaf :=_fec .Pop ();if _aaf !=nil {return _aaf ;};_bc ,_aaf :=_fec .Pop ();if _aaf !=nil {return _aaf ;};if _dg ,_bde :=_fa .(*PSBoolean );_bde {_bca ,_eeg :=_bc .(*PSBoolean );if !_eeg {return ErrTypeCheck ;};_aaf =_fec .Push (MakeBool (_dg .Val &&_bca .Val ));return _aaf ;};if _efb ,_ceg :=_fa .(*PSInteger );_ceg {_dfg ,_cdb :=_bc .(*PSInteger );if !_cdb {return ErrTypeCheck ;};_aaf =_fec .Push (MakeInteger (_efb .Val &_dfg .Val ));return _aaf ;};return ErrTypeCheck ;};func (_da *PSBoolean )Duplicate ()PSObject {_ef :=PSBoolean {};_ef .Val =_da .Val ;return &_ef };
// Pop pops an object from the top of the stack.
func (_cbeg *PSStack )Pop ()(PSObject ,error ){if len (*_cbeg )< 1{return nil ,ErrStackUnderflow ;};_egec :=(*_cbeg )[len (*_cbeg )-1];*_cbeg =(*_cbeg )[0:len (*_cbeg )-1];return _egec ,nil ;};func (_eed *PSOperand )xor (_bee *PSStack )error {_ddc ,_debg :=_bee .Pop ();if _debg !=nil {return _debg ;};_ecg ,_debg :=_bee .Pop ();if _debg !=nil {return _debg ;};if _bdb ,_aec :=_ddc .(*PSBoolean );_aec {_dedd ,_aeec :=_ecg .(*PSBoolean );if !_aeec {return ErrTypeCheck ;};_debg =_bee .Push (MakeBool (_bdb .Val !=_dedd .Val ));return _debg ;};if _fffb ,_dga :=_ddc .(*PSInteger );_dga {_gabd ,_abada :=_ecg .(*PSInteger );if !_abada {return ErrTypeCheck ;};_debg =_bee .Push (MakeInteger (_fffb .Val ^_gabd .Val ));return _debg ;};return ErrTypeCheck ;};var ErrStackUnderflow =_e .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");func (_ccf *PSParser )skipSpaces ()(int ,error ){_bfde :=0;for {_gcf ,_acda :=_ccf ._gde .Peek (1);if _acda !=nil {return 0,_acda ;};if _feb .IsWhiteSpace (_gcf [0]){_ccf ._gde .ReadByte ();_bfde ++;}else {break ;};};return _bfde ,nil ;};func (_gge *PSOperand )truncate (_afce *PSStack )error {_cgf ,_ecb :=_afce .Pop ();if _ecb !=nil {return _ecb ;};if _acdb ,_gcbc :=_cgf .(*PSReal );_gcbc {_cde :=int (_acdb .Val );_ecb =_afce .Push (MakeReal (float64 (_cde )));}else if _gfcd ,_fbec :=_cgf .(*PSInteger );_fbec {_ecb =_afce .Push (MakeInteger (_gfcd .Val ));}else {return ErrTypeCheck ;};return _ecb ;};func (_edba *PSOperand )index (_eeab *PSStack )error {_fcf ,_cad :=_eeab .Pop ();if _cad !=nil {return _cad ;};_bcae ,_fagd :=_fcf .(*PSInteger );if !_fagd {return ErrTypeCheck ;};if _bcae .Val < 0{return ErrRangeCheck ;};if _bcae .Val > len (*_eeab )-1{return ErrStackUnderflow ;};_adfe :=(*_eeab )[len (*_eeab )-1-_bcae .Val ];_cad =_eeab .Push (_adfe .Duplicate ());return _cad ;};
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_bdab :=PSParser {};_bagd :=_d .NewBuffer (content );_bdab ._gde =_fe .NewReader (_bagd );return &_bdab ;};
// MakeReal returns a new PSReal object initialized with `val`.
func MakeReal (val float64 )*PSReal {_dbdb :=PSReal {};_dbdb .Val =val ;return &_dbdb };func (_egc *PSOperand )idiv (_egfe *PSStack )error {_dae ,_acd :=_egfe .Pop ();if _acd !=nil {return _acd ;};_ggb ,_acd :=_egfe .Pop ();if _acd !=nil {return _acd ;};_bce ,_gebb :=_dae .(*PSInteger );if !_gebb {return ErrTypeCheck ;};if _bce .Val ==0{return ErrUndefinedResult ;};_dfc ,_gebb :=_ggb .(*PSInteger );if !_gebb {return ErrTypeCheck ;};_fea :=_dfc .Val /_bce .Val ;_acd =_egfe .Push (MakeInteger (_fea ));return _acd ;};func (_geffc *PSOperand )pop (_baeb *PSStack )error {_ ,_gdc :=_baeb .Pop ();if _gdc !=nil {return _gdc ;};return nil ;};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;
// Empty empties the stack.
func (_dcff *PSStack )Empty (){*_dcff =[]PSObject {}};func (_aee *PSOperand )neg (_ccgb *PSStack )error {_gdf ,_acde :=_ccgb .Pop ();if _acde !=nil {return _acde ;};if _agd ,_dbbd :=_gdf .(*PSReal );_dbbd {_acde =_ccgb .Push (MakeReal (-_agd .Val ));return _acde ;}else if _eaa ,_bfa :=_gdf .(*PSInteger );_bfa {_acde =_ccgb .Push (MakeInteger (-_eaa .Val ));return _acde ;}else {return ErrTypeCheck ;};};func (_cdfa *PSOperand )exch (_fag *PSStack )error {_aeg ,_acf :=_fag .Pop ();if _acf !=nil {return _acf ;};_beff ,_acf :=_fag .Pop ();if _acf !=nil {return _acf ;};_acf =_fag .Push (_aeg );if _acf !=nil {return _acf ;};_acf =_fag .Push (_beff );return _acf ;};
// NewPSStack returns an initialized PSStack.
func NewPSStack ()*PSStack {return &PSStack {}};func (_fdea *PSOperand )sub (_gag *PSStack )error {_bfba ,_fead :=_gag .Pop ();if _fead !=nil {return _fead ;};_dff ,_fead :=_gag .Pop ();if _fead !=nil {return _fead ;};_ebd ,_gfge :=_bfba .(*PSReal );_gdea ,_egd :=_bfba .(*PSInteger );if !_gfge &&!_egd {return ErrTypeCheck ;};_caf ,_cgb :=_dff .(*PSReal );_gcgb ,_bgag :=_dff .(*PSInteger );if !_cgb &&!_bgag {return ErrTypeCheck ;};if _egd &&_bgag {_ebbd :=_gcgb .Val -_gdea .Val ;_ebdg :=_gag .Push (MakeInteger (_ebbd ));return _ebdg ;};var _bfec float64 =0;if _cgb {_bfec =_caf .Val ;}else {_bfec =float64 (_gcgb .Val );};if _gfge {_bfec -=_ebd .Val ;}else {_bfec -=float64 (_gdea .Val );};_fead =_gag .Push (MakeReal (_bfec ));return _fead ;};func (_gcfd *PSOperand )ifelse (_ffa *PSStack )error {_fedd ,_cga :=_ffa .Pop ();if _cga !=nil {return _cga ;};_cgg ,_cga :=_ffa .Pop ();if _cga !=nil {return _cga ;};_ead ,_cga :=_ffa .Pop ();if _cga !=nil {return _cga ;};_bgae ,_bbdg :=_fedd .(*PSProgram );if !_bbdg {return ErrTypeCheck ;};_adc ,_bbdg :=_cgg .(*PSProgram );if !_bbdg {return ErrTypeCheck ;};_bgb ,_bbdg :=_ead .(*PSBoolean );if !_bbdg {return ErrTypeCheck ;};if _bgb .Val {_ddb :=_adc .Exec (_ffa );return _ddb ;};_cga =_bgae .Exec (_ffa );return _cga ;};func (_ff *PSOperand )atan (_bf *PSStack )error {_cac ,_acf :=_bf .PopNumberAsFloat64 ();if _acf !=nil {return _acf ;};_cacd ,_acf :=_bf .PopNumberAsFloat64 ();if _acf !=nil {return _acf ;};if _cac ==0{var _fb error ;if _cacd < 0{_fb =_bf .Push (MakeReal (270));}else {_fb =_bf .Push (MakeReal (90));};return _fb ;};_abg :=_cacd /_cac ;_ea :=_f .Atan (_abg )*180/_f .Pi ;_acf =_bf .Push (MakeReal (_ea ));return _acf ;};var ErrRangeCheck =_e .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");
// 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 _ge []float64 ;for _ ,_gb :=range objects {if _eeg ,_d :=_gb .(*PSInteger );_d {_ge =append (_ge ,float64 (_eeg .Val ));}else if _dd ,_ab :=_gb .(*PSReal );_ab {_ge =append (_ge ,_dd .Val );}else {return nil ,ErrTypeCheck ;};};return _ge ,nil ;};var ErrStackOverflow =_e .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");func (_egc *PSOperand )cos (_ace *PSStack )error {_bfb ,_cefc :=_ace .PopNumberAsFloat64 ();if _cefc !=nil {return _cefc ;};_eae :=_f .Cos (_bfb *_f .Pi /180.0);_cefc =_ace .Push (MakeReal (_eae ));return _cefc ;};var ErrStackUnderflow =_e .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");func (_edeg *PSOperand )ne (_aab *PSStack )error {_bcb :=_edeg .eq (_aab );if _bcb !=nil {return _bcb ;};_bcb =_edeg .not (_aab );return _bcb ;};
func NewPSStack ()*PSStack {return &PSStack {}};func (_bag *PSOperand )eq (_ccg *PSStack )error {_cgd ,_geff :=_ccg .Pop ();if _geff !=nil {return _geff ;};_bcb ,_geff :=_ccg .Pop ();if _geff !=nil {return _geff ;};_cb ,_ccag :=_cgd .(*PSBoolean );_gfc ,_gac :=_bcb .(*PSBoolean );if _ccag ||_gac {var _afgd error ;if _ccag &&_gac {_afgd =_ccg .Push (MakeBool (_cb .Val ==_gfc .Val ));}else {_afgd =_ccg .Push (MakeBool (false ));};return _afgd ;};var _edbg float64 ;var _gebe float64 ;if _cbf ,_ggc :=_cgd .(*PSInteger );_ggc {_edbg =float64 (_cbf .Val );}else if _ae ,_agc :=_cgd .(*PSReal );_agc {_edbg =_ae .Val ;}else {return ErrTypeCheck ;};if _dfd ,_acbc :=_bcb .(*PSInteger );_acbc {_gebe =float64 (_dfd .Val );}else if _gff ,_bfb :=_bcb .(*PSReal );_bfb {_gebe =_gff .Val ;}else {return ErrTypeCheck ;};if _eg .Abs (_gebe -_edbg )< _a {_geff =_ccg .Push (MakeBool (true ));}else {_geff =_ccg .Push (MakeBool (false ));};return _geff ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long