Merge pull request #424 from unidoc-build/prep-rc-v3.14.0-take4

Prepare release of UniPDF v3.14.0
This commit is contained in:
Gunnsteinn Hall 2020-11-12 08:33:18 +00:00 committed by GitHub
commit e189fab718
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
47 changed files with 6101 additions and 5836 deletions

File diff suppressed because one or more lines are too long

View File

@ -10,93 +10,96 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package common contains common properties used by the subpackages.
package common ;import (_f "fmt";_e "io";_dd "os";_a "path/filepath";_fb "runtime";_b "time";);
package common ;import (_b "fmt";_fg "io";_bb "os";_f "path/filepath";_g "runtime";_a "time";);func (_ea WriterLogger )logToWriter (_ge _fg .Writer ,_bbd string ,_ag string ,_gf ...interface{}){_cf (_ge ,_bbd ,_ag ,_gf );};
// DummyLogger does nothing.
type DummyLogger struct{};
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};
// Trace logs trace message.
func (_dbf ConsoleLogger )Trace (format string ,args ...interface{}){if _dbf .LogLevel >=LogLevelTrace {_ab :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_dbf .output (_dd .Stdout ,_ab ,format ,args ...);};};
// Info logs info message.
func (_gdb WriterLogger )Info (format string ,args ...interface{}){if _gdb .LogLevel >=LogLevelInfo {_ddd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_gdb .logToWriter (_gdb .Output ,_ddd ,format ,args ...);};};const Version ="\u0033\u002e\u0031\u0033\u002e\u0030";var Log Logger =DummyLogger {};
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};func (_fe WriterLogger )logToWriter (_abf _e .Writer ,_feb string ,_gcf string ,_dbb ...interface{}){_eeb (_abf ,_feb ,_gcf ,_dbb );};func (_ba ConsoleLogger )output (_gg _e .Writer ,_baa string ,_fbb string ,_gc ...interface{}){_eeb (_gg ,_baa ,_fbb ,_gc ...);};var ReleasedAt =_b .Date (_cbd ,_geb ,_ac ,_bag ,_fbf ,0,0,_b .UTC );
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const _gff ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _e .Writer )*WriterLogger {_ead :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_ead ;};
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_aea ConsoleLogger )IsLogLevel (level LogLevel )bool {return _aea .LogLevel >=level };
// 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 (_cg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cg .LogLevel >=level };
// Warning logs warning message.
func (_ceb ConsoleLogger )Warning (format string ,args ...interface{}){if _ceb .LogLevel >=LogLevelWarning {_gba :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ceb .output (_bb .Stdout ,_gba ,format ,args ...);};};
// Debug logs debug message.
func (_aa ConsoleLogger )Debug (format string ,args ...interface{}){if _aa .LogLevel >=LogLevelDebug {_db :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_aa .output (_bb .Stdout ,_db ,format ,args ...);};};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };const _bag =10;
// Debug logs debug message.
func (_cec WriterLogger )Debug (format string ,args ...interface{}){if _cec .LogLevel >=LogLevelDebug {_bfb :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_cec .logToWriter (_cec .Output ,_bfb ,format ,args ...);};};
// Warning logs warning message.
func (_fa WriterLogger )Warning (format string ,args ...interface{}){if _fa .LogLevel >=LogLevelWarning {_ece :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_fa .logToWriter (_fa .Output ,_ece ,format ,args ...);};};const _geb =10;
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };
// Error logs error message.
func (_ce WriterLogger )Error (format string ,args ...interface{}){if _ce .LogLevel >=LogLevelError {_bd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ce .logToWriter (_ce .Output ,_bd ,format ,args ...);};};const _ac =19;
func (_dbe WriterLogger )Error (format string ,args ...interface{}){if _dbe .LogLevel >=LogLevelError {_ba :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_dbe .logToWriter (_dbe .Output ,_ba ,format ,args ...);};};func (_dg ConsoleLogger )output (_fgb _fg .Writer ,_de string ,_dee string ,_cde ...interface{}){_cf (_fgb ,_de ,_dee ,_cde ...);};const _eb =11;const Version ="\u0033\u002e\u0031\u0034\u002e\u0030";
// Error logs error message.
func (_gde ConsoleLogger )Error (format string ,args ...interface{}){if _gde .LogLevel >=LogLevelError {_bf :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gde .output (_dd .Stdout ,_bf ,format ,args ...);};};
// DummyLogger does nothing.
type DummyLogger struct{};
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_fe string ,_fga ...interface{});Warning (_e string ,_ce ...interface{});Notice (_cc string ,_d ...interface{});Info (_bf string ,_gb ...interface{});Debug (_ae string ,_da ...interface{});Trace (_fc string ,_ad ...interface{});IsLogLevel (_bbb LogLevel )bool ;};
// Warning logs warning message.
func (_gf ConsoleLogger )Warning (format string ,args ...interface{}){if _gf .LogLevel >=LogLevelWarning {_ec :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_gf .output (_dd .Stdout ,_ec ,format ,args ...);};};
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};
// Debug logs debug message.
func (_efb ConsoleLogger )Debug (format string ,args ...interface{}){if _efb .LogLevel >=LogLevelDebug {_ee :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_efb .output (_dd .Stdout ,_ee ,format ,args ...);};};func UtcTimeFormat (t _b .Time )string {return t .Format (_gff )+"\u0020\u0055\u0054\u0043"};func _eeb (_cb _e .Writer ,_cdc string ,_ff string ,_bfg ...interface{}){_ ,_fba ,_gce ,_gda :=_fb .Caller (3);if !_gda {_fba ="\u003f\u003f\u003f";_gce =0;}else {_fba =_a .Base (_fba );};_bdg :=_f .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_cdc ,_fba ,_gce )+_ff +"\u000a";_f .Fprintf (_cb ,_bdg ,_bfg ...);};
// UtcTimeFormat returns a formatted string describing a UTC timestamp.
func UtcTimeFormat (t _a .Time )string {return t .Format (_ee )+"\u0020\u0055\u0054\u0043"};
// Trace logs trace message.
func (_ebf WriterLogger )Trace (format string ,args ...interface{}){if _ebf .LogLevel >=LogLevelTrace {_aee :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ebf .logToWriter (_ebf .Output ,_aee ,format ,args ...);};};
func (_bg ConsoleLogger )Trace (format string ,args ...interface{}){if _bg .LogLevel >=LogLevelTrace {_fb :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_bg .output (_bb .Stdout ,_fb ,format ,args ...);};};
// Info logs info message.
func (_ef ConsoleLogger )Info (format string ,args ...interface{}){if _ef .LogLevel >=LogLevelInfo {_cdg :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ef .output (_dd .Stdout ,_cdg ,format ,args ...);};};const _cbd =2020;
// Notice logs notice message.
func (_db ConsoleLogger )Notice (format string ,args ...interface{}){if _db .LogLevel >=LogLevelNotice {_ge :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_db .output (_dd .Stdout ,_ge ,format ,args ...);};};
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};const _ebd =15;
// WriterLogger is the logger that writes data to the Output writer
type WriterLogger struct{LogLevel LogLevel ;Output _e .Writer ;};const _fbf =15;
type WriterLogger struct{LogLevel LogLevel ;Output _fg .Writer ;};var Log Logger =DummyLogger {};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_bc WriterLogger )IsLogLevel (level LogLevel )bool {return _bc .LogLevel >=level };
// Info logs info message.
func (_ed WriterLogger )Info (format string ,args ...interface{}){if _ed .LogLevel >=LogLevelInfo {_dae :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ed .logToWriter (_ed .Output ,_dae ,format ,args ...);};};
// Error logs error message.
func (_bd ConsoleLogger )Error (format string ,args ...interface{}){if _bd .LogLevel >=LogLevelError {_cd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_bd .output (_bb .Stdout ,_cd ,format ,args ...);};};
// Notice logs notice message.
func (_ada ConsoleLogger )Notice (format string ,args ...interface{}){if _ada .LogLevel >=LogLevelNotice {_bfe :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ada .output (_bb .Stdout ,_bfe ,format ,args ...);};};
// Debug logs debug message.
func (_dd WriterLogger )Debug (format string ,args ...interface{}){if _dd .LogLevel >=LogLevelDebug {_fgg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_dd .logToWriter (_dd .Output ,_fgg ,format ,args ...);};};const _ee ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};
func (DummyLogger )Trace (format string ,args ...interface{}){};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
// Trace logs trace message.
func (_cg WriterLogger )Trace (format string ,args ...interface{}){if _cg .LogLevel >=LogLevelTrace {_ceg :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_cg .logToWriter (_cg .Output ,_ceg ,format ,args ...);};};const _cb =18;
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};func _cf (_ef _fg .Writer ,_aee string ,_fee string ,_fcb ...interface{}){_ ,_gbae ,_ca ,_fd :=_g .Caller (3);if !_fd {_gbae ="\u003f\u003f\u003f";_ca =0;}else {_gbae =_f .Base (_gbae );};_ccc :=_b .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_aee ,_gbae ,_ca )+_fee +"\u000a";_b .Fprintf (_ef ,_ccc ,_fcb ...);};
// Warning logs warning message.
func (_cdc WriterLogger )Warning (format string ,args ...interface{}){if _cdc .LogLevel >=LogLevelWarning {_ceba :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_cdc .logToWriter (_cdc .Output ,_ceba ,format ,args ...);};};
// LogLevel is the verbosity level for logging.
type LogLevel int ;
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_aa string ,_df ...interface{});Warning (_eb string ,_g ...interface{});Notice (_ae string ,_c ...interface{});Info (_gd string ,_ad ...interface{});Debug (_ea string ,_cc ...interface{});Trace (_gb string ,_cd ...interface{});IsLogLevel (_bb LogLevel )bool ;};
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _fg .Writer )*WriterLogger {_bdd :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_bdd ;};const _ab =2020;
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_ec WriterLogger )IsLogLevel (level LogLevel )bool {return _ec .LogLevel >=level };const _ddb =11;var ReleasedAt =_a .Date (_ab ,_ddb ,_eb ,_cb ,_ebd ,0,0,_a .UTC );
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };
// Info logs info message.
func (_gg ConsoleLogger )Info (format string ,args ...interface{}){if _gg .LogLevel >=LogLevelInfo {_be :="\u005bI\u004e\u0046\u004f\u005d\u0020";_gg .output (_bb .Stdout ,_be ,format ,args ...);};};
// Notice logs notice message.
func (_ca WriterLogger )Notice (format string ,args ...interface{}){if _ca .LogLevel >=LogLevelNotice {_bda :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ca .logToWriter (_ca .Output ,_bda ,format ,args ...);};};
func (_bda WriterLogger )Notice (format string ,args ...interface{}){if _bda .LogLevel >=LogLevelNotice {_dab :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bda .logToWriter (_bda .Output ,_dab ,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,204 +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 (_f "fmt";_fb "github.com/unidoc/unipdf/v3/contentstream";_a "github.com/unidoc/unipdf/v3/core";_d "github.com/unidoc/unipdf/v3/internal/transform";_cf "github.com/unidoc/unipdf/v3/model";_ce "math";);
package draw ;import (_e "fmt";_d "github.com/unidoc/unipdf/v3/contentstream";_ea "github.com/unidoc/unipdf/v3/core";_c "github.com/unidoc/unipdf/v3/internal/transform";_a "github.com/unidoc/unipdf/v3/model";_f "math";);
// Offset shifts the path with the specified offsets.
func (_fgg Path )Offset (offX ,offY float64 )Path {for _ee ,_cef :=range _fgg .Points {_fgg .Points [_ee ]=_cef .Add (offX ,offY );};return _fgg ;};
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;func (_egg Point )String ()string {return _e .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_egg .X ,_egg .Y );};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_ea CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_ea .P0 .X +=offX ;_ea .P1 .X +=offX ;_ea .P2 .X +=offX ;_ea .P3 .X +=offX ;_ea .P0 .Y +=offY ;_ea .P1 .Y +=offY ;_ea .P2 .Y +=offY ;_ea .P3 .Y +=offY ;return _ea ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// Copy returns a clone of the path.
func (_af Path )Copy ()Path {_df :=Path {};_df .Points =[]Point {};for _ ,_bea :=range _af .Points {_df .Points =append (_df .Points ,_bea );};return _df ;};
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_gce Rectangle )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_gce .X ,Lly :_gce .Y ,Urx :_gce .X +_gce .Width ,Ury :_gce .Y +_gce .Height };};
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_cf .PdfColorDeviceRGB ;BorderWidth float64 ;};
// Rotate rotates the vector by the specified angle.
func (_defe Vector )Rotate (phi float64 )Vector {_bbe :=_defe .Magnitude ();_bec :=_defe .GetPolarAngle ();return NewVectorPolar (_bbe ,_bec +phi );};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// FlipY flips the sign of the Dy component of the vector.
func (_dgg Vector )FlipY ()Vector {_dgg .Dy =-_dgg .Dy ;return _dgg };
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// 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 (_eab Line )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_aec ,_ee :=_eab .X1 ,_eab .X2 ;_efd ,_gcb :=_eab .Y1 ,_eab .Y2 ;_dba :=_gcb -_efd ;_faa :=_ee -_aec ;_bbbe :=_f .Atan2 (_dba ,_faa );L :=_f .Sqrt (_f .Pow (_faa ,2.0)+_f .Pow (_dba ,2.0));_baa :=_eab .LineWidth ;_gfd :=_f .Pi ;_bae :=1.0;if _faa < 0{_bae *=-1.0;};if _dba < 0{_bae *=-1.0;};VsX :=_bae *(-_baa /2*_f .Cos (_bbbe +_gfd /2));VsY :=_bae *(-_baa /2*_f .Sin (_bbbe +_gfd /2)+_baa *_f .Sin (_bbbe +_gfd /2));V1X :=VsX +_baa /2*_f .Cos (_bbbe +_gfd /2);V1Y :=VsY +_baa /2*_f .Sin (_bbbe +_gfd /2);V2X :=VsX +_baa /2*_f .Cos (_bbbe +_gfd /2)+L *_f .Cos (_bbbe );V2Y :=VsY +_baa /2*_f .Sin (_bbbe +_gfd /2)+L *_f .Sin (_bbbe );V3X :=VsX +_baa /2*_f .Cos (_bbbe +_gfd /2)+L *_f .Cos (_bbbe )+_baa *_f .Cos (_bbbe -_gfd /2);V3Y :=VsY +_baa /2*_f .Sin (_bbbe +_gfd /2)+L *_f .Sin (_bbbe )+_baa *_f .Sin (_bbbe -_gfd /2);V4X :=VsX +_baa /2*_f .Cos (_bbbe -_gfd /2);V4Y :=VsY +_baa /2*_f .Sin (_bbbe -_gfd /2);_fd :=NewPath ();_fd =_fd .AppendPoint (NewPoint (V1X ,V1Y ));_fd =_fd .AppendPoint (NewPoint (V2X ,V2Y ));_fd =_fd .AppendPoint (NewPoint (V3X ,V3Y ));_fd =_fd .AppendPoint (NewPoint (V4X ,V4Y ));_dc :=_eab .LineEndingStyle1 ;_afe :=_eab .LineEndingStyle2 ;_aae :=3*_baa ;_cged :=3*_baa ;_fed :=(_cged -_baa )/2;if _afe ==LineEndingStyleArrow {_bd :=_fd .GetPointNumber (2);_cbb :=NewVectorPolar (_aae ,_bbbe +_gfd );_bda :=_bd .AddVector (_cbb );_dgg :=NewVectorPolar (_cged /2,_bbbe +_gfd /2);_cgdg :=NewVectorPolar (_aae ,_bbbe );_eabg :=NewVectorPolar (_fed ,_bbbe +_gfd /2);_cd :=_bda .AddVector (_eabg );_fcd :=_cgdg .Add (_dgg .Flip ());_eae :=_cd .AddVector (_fcd );_dd :=_dgg .Scale (2).Flip ().Add (_fcd .Flip ());_acf :=_eae .AddVector (_dd );_egb :=_bda .AddVector (NewVectorPolar (_baa ,_bbbe -_gfd /2));_fb :=NewPath ();_fb =_fb .AppendPoint (_fd .GetPointNumber (1));_fb =_fb .AppendPoint (_bda );_fb =_fb .AppendPoint (_cd );_fb =_fb .AppendPoint (_eae );_fb =_fb .AppendPoint (_acf );_fb =_fb .AppendPoint (_egb );_fb =_fb .AppendPoint (_fd .GetPointNumber (4));_fd =_fb ;};if _dc ==LineEndingStyleArrow {_dacc :=_fd .GetPointNumber (1);_dgf :=_fd .GetPointNumber (_fd .Length ());_bee :=NewVectorPolar (_baa /2,_bbbe +_gfd +_gfd /2);_ddd :=_dacc .AddVector (_bee );_aca :=NewVectorPolar (_aae ,_bbbe ).Add (NewVectorPolar (_cged /2,_bbbe +_gfd /2));_fbb :=_ddd .AddVector (_aca );_fda :=NewVectorPolar (_fed ,_bbbe -_gfd /2);_edg :=_fbb .AddVector (_fda );_bff :=NewVectorPolar (_aae ,_bbbe );_cad :=_dgf .AddVector (_bff );_df :=NewVectorPolar (_fed ,_bbbe +_gfd +_gfd /2);_caf :=_cad .AddVector (_df );_cca :=_ddd ;_gab :=NewPath ();_gab =_gab .AppendPoint (_ddd );_gab =_gab .AppendPoint (_fbb );_gab =_gab .AppendPoint (_edg );for _ ,_gcbd :=range _fd .Points [1:len (_fd .Points )-1]{_gab =_gab .AppendPoint (_gcbd );};_gab =_gab .AppendPoint (_cad );_gab =_gab .AppendPoint (_caf );_gab =_gab .AppendPoint (_cca );_fd =_gab ;};_ad :=_d .NewContentCreator ();_ad .Add_q ().Add_rg (_eab .LineColor .R (),_eab .LineColor .G (),_eab .LineColor .B ());if len (gsName )> 1{_ad .Add_gs (_ea .PdfObjectName (gsName ));};_fd =_fd .Offset (_eab .X1 ,_eab .Y1 );_gabd :=_fd .GetBoundingBox ();DrawPathWithCreator (_fd ,_ad );if _eab .LineStyle ==LineStyleDashed {_ad .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_ad .Add_f ().Add_Q ();};return _ad .Bytes (),_gabd .ToPdfRectangle (),nil ;};
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// GetBoundingBox returns the bounding box of the path.
func (_ag Path )GetBoundingBox ()BoundingBox {_ce :=BoundingBox {};_afd :=0.0;_afa :=0.0;_cgd :=0.0;_cbe :=0.0;for _bbb ,_de :=range _ag .Points {if _bbb ==0{_afd =_de .X ;_afa =_de .X ;_cgd =_de .Y ;_cbe =_de .Y ;continue ;};if _de .X < _afd {_afd =_de .X ;};if _de .X > _afa {_afa =_de .X ;};if _de .Y < _cgd {_cgd =_de .Y ;};if _de .Y > _cbe {_cbe =_de .Y ;};};_ce .X =_afd ;_ce .Y =_cgd ;_ce .Width =_afa -_afd ;_ce .Height =_cbe -_cgd ;return _ce ;};
// 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 (_afg PolyBezierCurve )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _afg .BorderColor ==nil {_afg .BorderColor =_a .NewPdfColorDeviceRGB (0,0,0);};_ac :=NewCubicBezierPath ();for _ ,_ba :=range _afg .Curves {_ac =_ac .AppendCurve (_ba );};_fee :=_d .NewContentCreator ();_fee .Add_q ();_afg .FillEnabled =_afg .FillEnabled &&_afg .FillColor !=nil ;if _afg .FillEnabled {_fee .Add_rg (_afg .FillColor .R (),_afg .FillColor .G (),_afg .FillColor .B ());};_fee .Add_RG (_afg .BorderColor .R (),_afg .BorderColor .G (),_afg .BorderColor .B ());_fee .Add_w (_afg .BorderWidth );if len (gsName )> 1{_fee .Add_gs (_ea .PdfObjectName (gsName ));};for _ ,_fcb :=range _ac .Curves {_fee .Add_m (_fcb .P0 .X ,_fcb .P0 .Y );_fee .Add_c (_fcb .P1 .X ,_fcb .P1 .Y ,_fcb .P2 .X ,_fcb .P2 .Y ,_fcb .P3 .X ,_fcb .P3 .Y );};if _afg .FillEnabled {_fee .Add_h ();_fee .Add_B ();}else {_fee .Add_S ();};_fee .Add_Q ();return _fee .Bytes (),_ac .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Copy returns a clone of the Bezier path.
func (_bg CubicBezierPath )Copy ()CubicBezierPath {_ga :=CubicBezierPath {};_ga .Curves =append (_ga .Curves ,_bg .Curves ...);return _ga ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_e :=CubicBezierCurve {};_e .P0 =NewPoint (x0 ,y0 );_e .P1 =NewPoint (x1 ,y1 );_e .P2 =NewPoint (x2 ,y2 );_e .P3 =NewPoint (x3 ,y3 );return _e ;};
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_da :=CubicBezierCurve {};_da .P0 =NewPoint (x0 ,y0 );_da .P1 =NewPoint (x1 ,y1 );_da .P2 =NewPoint (x2 ,y2 );_da .P3 =NewPoint (x3 ,y3 );return _da ;};
// 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 (_aed BasicLine )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_edg :=_aed .LineWidth ;_bbg :=NewPath ();_bbg =_bbg .AppendPoint (NewPoint (_aed .X1 ,_aed .Y1 ));_bbg =_bbg .AppendPoint (NewPoint (_aed .X2 ,_aed .Y2 ));_eda :=_fb .NewContentCreator ();_ebd :=_bbg .GetBoundingBox ();DrawPathWithCreator (_bbg ,_eda );if _aed .LineStyle ==LineStyleDashed {_eda .Add_d ([]int64 {1,1},0);};_eda .Add_RG (_aed .LineColor .R (),_aed .LineColor .G (),_aed .LineColor .B ()).Add_w (_edg ).Add_S ().Add_Q ();return _eda .Bytes (),_ebd .ToPdfRectangle (),nil ;};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_bgc Path )RemovePoint (number int )Path {if number < 1||number > len (_bgc .Points ){return _bgc ;};_db :=number -1;_bgc .Points =append (_bgc .Points [:_db ],_bgc .Points [_db +1:]...);return _bgc ;};
// AddVector adds vector to a point.
func (_ccc Point )AddVector (v Vector )Point {_ccc .X +=v .Dx ;_ccc .Y +=v .Dy ;return _ccc };
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;
// FlipY flips the sign of the Dy component of the vector.
func (_bfbf Vector )FlipY ()Vector {_bfbf .Dy =-_bfbf .Dy ;return _bfbf };
// GetBounds returns the bounding box of the Bezier curve.
func (_g CubicBezierCurve )GetBounds ()_cf .PdfRectangle {_dd :=_g .P0 .X ;_ddb :=_g .P0 .X ;_ca :=_g .P0 .Y ;_b :=_g .P0 .Y ;for _bc :=0.0;_bc <=1.0;_bc +=0.001{Rx :=_g .P0 .X *_ce .Pow (1-_bc ,3)+_g .P1 .X *3*_bc *_ce .Pow (1-_bc ,2)+_g .P2 .X *3*_ce .Pow (_bc ,2)*(1-_bc )+_g .P3 .X *_ce .Pow (_bc ,3);Ry :=_g .P0 .Y *_ce .Pow (1-_bc ,3)+_g .P1 .Y *3*_bc *_ce .Pow (1-_bc ,2)+_g .P2 .Y *3*_ce .Pow (_bc ,2)*(1-_bc )+_g .P3 .Y *_ce .Pow (_bc ,3);if Rx < _dd {_dd =Rx ;};if Rx > _ddb {_ddb =Rx ;};if Ry < _ca {_ca =Ry ;};if Ry > _b {_b =Ry ;};};_ad :=_cf .PdfRectangle {};_ad .Llx =_dd ;_ad .Lly =_ca ;_ad .Urx =_ddb ;_ad .Ury =_b ;return _ad ;};
// LineStyle refers to how the line will be created.
type LineStyle int ;
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_bbf :=Vector {};_bbf .Dx =dx ;_bbf .Dy =dy ;return _bbf };
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_ceea Vector )GetPolarAngle ()float64 {return _f .Atan2 (_ceea .Dy ,_ceea .Dx )};
// 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 (_dgc Circle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_ab :=_dgc .Width /2;_ced :=_dgc .Height /2;if _dgc .BorderEnabled {_ab -=_dgc .BorderWidth /2;_ced -=_dgc .BorderWidth /2;};_abd :=0.551784;_gag :=_ab *_abd ;_dge :=_ced *_abd ;_gf :=NewCubicBezierPath ();_gf =_gf .AppendCurve (NewCubicBezierCurve (-_ab ,0,-_ab ,_dge ,-_gag ,_ced ,0,_ced ));_gf =_gf .AppendCurve (NewCubicBezierCurve (0,_ced ,_gag ,_ced ,_ab ,_dge ,_ab ,0));_gf =_gf .AppendCurve (NewCubicBezierCurve (_ab ,0,_ab ,-_dge ,_gag ,-_ced ,0,-_ced ));_gf =_gf .AppendCurve (NewCubicBezierCurve (0,-_ced ,-_gag ,-_ced ,-_ab ,-_dge ,-_ab ,0));_gf =_gf .Offset (_ab ,_ced );if _dgc .BorderEnabled {_gf =_gf .Offset (_dgc .BorderWidth /2,_dgc .BorderWidth /2);};if _dgc .X !=0||_dgc .Y !=0{_gf =_gf .Offset (_dgc .X ,_dgc .Y );};_gc :=_d .NewContentCreator ();_gc .Add_q ();if _dgc .FillEnabled {_gc .Add_rg (_dgc .FillColor .R (),_dgc .FillColor .G (),_dgc .FillColor .B ());};if _dgc .BorderEnabled {_gc .Add_RG (_dgc .BorderColor .R (),_dgc .BorderColor .G (),_dgc .BorderColor .B ());_gc .Add_w (_dgc .BorderWidth );};if len (gsName )> 1{_gc .Add_gs (_ea .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_gf ,_gc );_gc .Add_h ();if _dgc .FillEnabled &&_dgc .BorderEnabled {_gc .Add_B ();}else if _dgc .FillEnabled {_gc .Add_f ();}else if _dgc .BorderEnabled {_gc .Add_S ();};_gc .Add_Q ();_gd :=_gf .GetBoundingBox ();if _dgc .BorderEnabled {_gd .Height +=_dgc .BorderWidth ;_gd .Width +=_dgc .BorderWidth ;_gd .X -=_dgc .BorderWidth /2;_gd .Y -=_dgc .BorderWidth /2;};return _gc .Bytes (),_gd .ToPdfRectangle (),nil ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_bgd Point )Add (dx ,dy float64 )Point {_bgd .X +=dx ;_bgd .Y +=dy ;return _bgd };
// 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 *_d .ContentCreator ){for _agf ,_fcc :=range bpath .Curves {if _agf ==0{creator .Add_m (_fcc .P0 .X ,_fcc .P0 .Y );};creator .Add_c (_fcc .P1 .X ,_fcc .P1 .Y ,_fcc .P2 .X ,_fcc .P2 .Y ,_fcc .P3 .X ,_fcc .P3 .Y );};};
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_dg BoundingBox )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_dg .X ,Lly :_dg .Y ,Urx :_dg .X +_dg .Width ,Ury :_dg .Y +_dg .Height };};
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_ed Path )GetPointNumber (number int )Point {if number < 1||number > len (_ed .Points ){return Point {};};return _ed .Points [number -1];};
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_egc Point )Rotate (theta float64 )Point {_bfb :=_c .NewPoint (_egc .X ,_egc .Y ).Rotate (theta );return NewPoint (_bfb .X ,_bfb .Y );};
// Add adds the specified vector to the current one and returns the result.
func (_aac Vector )Add (other Vector )Vector {_aac .Dx +=other .Dx ;_aac .Dy +=other .Dy ;return _aac };
// 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 *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
// Copy returns a clone of the path.
func (_ffa Path )Copy ()Path {_geg :=Path {};_geg .Points =append (_geg .Points ,_ffa .Points ...);return _geg ;};
// AppendPoint adds the specified point to the path.
func (_ebc Path )AppendPoint (point Point )Path {_ebc .Points =append (_ebc .Points ,point );return _ebc };
// Scale scales the vector by the specified factor.
func (_ffd Vector )Scale (factor float64 )Vector {_gef :=_ffd .Magnitude ();_acge :=_ffd .GetPolarAngle ();_ffd .Dx =factor *_gef *_f .Cos (_acge );_ffd .Dy =factor *_gef *_f .Sin (_acge );return _ffd ;};
// 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 *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// Offset shifts the Bezier path with the specified offsets.
func (_aad CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _bb ,_ca :=range _aad .Curves {_aad .Curves [_bb ]=_ca .AddOffsetXY (offX ,offY );};return _aad ;};
// Rotate rotates the vector by the specified angle.
func (_gg Vector )Rotate (phi float64 )Vector {_ccc :=_gg .Magnitude ();_fcg :=_gg .GetPolarAngle ();return NewVectorPolar (_ccc ,_fcg +phi );};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_aa CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_aa .P0 .X +=offX ;_aa .P1 .X +=offX ;_aa .P2 .X +=offX ;_aa .P3 .X +=offX ;_aa .P0 .Y +=offY ;_aa .P1 .Y +=offY ;_aa .P2 .Y +=offY ;_aa .P3 .Y +=offY ;return _aa ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_gb CubicBezierPath )GetBoundingBox ()Rectangle {_ef :=Rectangle {};_cg :=0.0;_dac :=0.0;_eb :=0.0;_ged :=0.0;for _bgg ,_fa :=range _gb .Curves {_ff :=_fa .GetBounds ();if _bgg ==0{_cg =_ff .Llx ;_dac =_ff .Urx ;_eb =_ff .Lly ;_ged =_ff .Ury ;continue ;};if _ff .Llx < _cg {_cg =_ff .Llx ;};if _ff .Urx > _dac {_dac =_ff .Urx ;};if _ff .Lly < _eb {_eb =_ff .Lly ;};if _ff .Ury > _ged {_ged =_ff .Ury ;};};_ef .X =_cg ;_ef .Y =_eb ;_ef .Width =_dac -_cg ;_ef .Height =_ged -_eb ;return _ef ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_a .PdfColorDeviceRGB ;LineWidth float64 ;};
// FlipX flips the sign of the Dx component of the vector.
func (_cfd Vector )FlipX ()Vector {_cfd .Dx =-_cfd .Dx ;return _cfd };
// 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 (_ddbe Polyline )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){if _ddbe .LineColor ==nil {_ddbe .LineColor =_cf .NewPdfColorDeviceRGB (0,0,0);};_abfa :=NewPath ();for _ ,_edf :=range _ddbe .Points {_abfa =_abfa .AppendPoint (_edf );};_gge :=_fb .NewContentCreator ();_gge .Add_q ();_gge .Add_RG (_ddbe .LineColor .R (),_ddbe .LineColor .G (),_ddbe .LineColor .B ());_gge .Add_w (_ddbe .LineWidth );if len (gsName )> 1{_gge .Add_gs (_a .PdfObjectName (gsName ));};DrawPathWithCreator (_abfa ,_gge );_gge .Add_S ();_gge .Add_Q ();return _gge .Bytes (),_abfa .GetBoundingBox ().ToPdfRectangle (),nil ;};
func (_baf Polyline )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _baf .LineColor ==nil {_baf .LineColor =_a .NewPdfColorDeviceRGB (0,0,0);};_ecb :=NewPath ();for _ ,_egf :=range _baf .Points {_ecb =_ecb .AppendPoint (_egf );};_edd :=_d .NewContentCreator ();_edd .Add_q ();_edd .Add_RG (_baf .LineColor .R (),_baf .LineColor .G (),_baf .LineColor .B ());_edd .Add_w (_baf .LineWidth );if len (gsName )> 1{_edd .Add_gs (_ea .PdfObjectName (gsName ));};DrawPathWithCreator (_ecb ,_edd );_edd .Add_S ();_edd .Add_Q ();return _edd .Bytes (),_ecb .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Magnitude returns the magnitude of the vector.
func (_gfa Vector )Magnitude ()float64 {return _ce .Sqrt (_ce .Pow (_gfa .Dx ,2.0)+_ce .Pow (_gfa .Dy ,2.0));};
// 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 *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// 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 *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;};func (_ebb Point )String ()string {return _f .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_ebb .X ,_ebb .Y );};
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};
// Copy returns a clone of the Bezier path.
func (_cd CubicBezierPath )Copy ()CubicBezierPath {_dc :=CubicBezierPath {};_dc .Curves =[]CubicBezierCurve {};for _ ,_ddg :=range _cd .Curves {_dc .Curves =append (_dc .Curves ,_ddg );};return _dc ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_ae Point )Add (dx ,dy float64 )Point {_ae .X +=dx ;_ae .Y +=dy ;return _ae };
// 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 {_dad :=Vector {};_dad .Dx =b .X -a .X ;_dad .Dy =b .Y -a .Y ;return _dad ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_acf :=Vector {};_acf .Dx =dx ;_acf .Dy =dy ;return _acf };
// 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 *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;};
// 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 (_ece Line )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_fdg ,_eg :=_ece .X1 ,_ece .X2 ;_gcf ,_dfa :=_ece .Y1 ,_ece .Y2 ;_bg :=_dfa -_gcf ;_bfbd :=_eg -_fdg ;_abdb :=_ce .Atan2 (_bg ,_bfbd );L :=_ce .Sqrt (_ce .Pow (_bfbd ,2.0)+_ce .Pow (_bg ,2.0));_dac :=_ece .LineWidth ;_ag :=_ce .Pi ;_gbf :=1.0;if _bfbd < 0{_gbf *=-1.0;};if _bg < 0{_gbf *=-1.0;};VsX :=_gbf *(-_dac /2*_ce .Cos (_abdb +_ag /2));VsY :=_gbf *(-_dac /2*_ce .Sin (_abdb +_ag /2)+_dac *_ce .Sin (_abdb +_ag /2));V1X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2);V1Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2);V2X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2)+L *_ce .Cos (_abdb );V2Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2)+L *_ce .Sin (_abdb );V3X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2)+L *_ce .Cos (_abdb )+_dac *_ce .Cos (_abdb -_ag /2);V3Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2)+L *_ce .Sin (_abdb )+_dac *_ce .Sin (_abdb -_ag /2);V4X :=VsX +_dac /2*_ce .Cos (_abdb -_ag /2);V4Y :=VsY +_dac /2*_ce .Sin (_abdb -_ag /2);_abg :=NewPath ();_abg =_abg .AppendPoint (NewPoint (V1X ,V1Y ));_abg =_abg .AppendPoint (NewPoint (V2X ,V2Y ));_abg =_abg .AppendPoint (NewPoint (V3X ,V3Y ));_abg =_abg .AppendPoint (NewPoint (V4X ,V4Y ));_fdd :=_ece .LineEndingStyle1 ;_eeac :=_ece .LineEndingStyle2 ;_fff :=3*_dac ;_egf :=3*_dac ;_eae :=(_egf -_dac )/2;if _eeac ==LineEndingStyleArrow {_egfc :=_abg .GetPointNumber (2);_bfg :=NewVectorPolar (_fff ,_abdb +_ag );_egc :=_egfc .AddVector (_bfg );_gda :=NewVectorPolar (_egf /2,_abdb +_ag /2);_cdae :=NewVectorPolar (_fff ,_abdb );_ceff :=NewVectorPolar (_eae ,_abdb +_ag /2);_abb :=_egc .AddVector (_ceff );_fgd :=_cdae .Add (_gda .Flip ());_cae :=_abb .AddVector (_fgd );_bgc :=_gda .Scale (2).Flip ().Add (_fgd .Flip ());_dab :=_cae .AddVector (_bgc );_ede :=_egc .AddVector (NewVectorPolar (_dac ,_abdb -_ag /2));_dfge :=NewPath ();_dfge =_dfge .AppendPoint (_abg .GetPointNumber (1));_dfge =_dfge .AppendPoint (_egc );_dfge =_dfge .AppendPoint (_abb );_dfge =_dfge .AppendPoint (_cae );_dfge =_dfge .AppendPoint (_dab );_dfge =_dfge .AppendPoint (_ede );_dfge =_dfge .AppendPoint (_abg .GetPointNumber (4));_abg =_dfge ;};if _fdd ==LineEndingStyleArrow {_ecd :=_abg .GetPointNumber (1);_geb :=_abg .GetPointNumber (_abg .Length ());_ebba :=NewVectorPolar (_dac /2,_abdb +_ag +_ag /2);_fggb :=_ecd .AddVector (_ebba );_fdc :=NewVectorPolar (_fff ,_abdb ).Add (NewVectorPolar (_egf /2,_abdb +_ag /2));_adb :=_fggb .AddVector (_fdc );_eaa :=NewVectorPolar (_eae ,_abdb -_ag /2);_bdg :=_adb .AddVector (_eaa );_dfe :=NewVectorPolar (_fff ,_abdb );_dg :=_geb .AddVector (_dfe );_gfc :=NewVectorPolar (_eae ,_abdb +_ag +_ag /2);_eec :=_dg .AddVector (_gfc );_fbg :=_fggb ;_eag :=NewPath ();_eag =_eag .AppendPoint (_fggb );_eag =_eag .AppendPoint (_adb );_eag =_eag .AppendPoint (_bdg );for _ ,_ba :=range _abg .Points [1:len (_abg .Points )-1]{_eag =_eag .AppendPoint (_ba );};_eag =_eag .AppendPoint (_dg );_eag =_eag .AppendPoint (_eec );_eag =_eag .AppendPoint (_fbg );_abg =_eag ;};_gg :=_fb .NewContentCreator ();_gg .Add_q ().Add_rg (_ece .LineColor .R (),_ece .LineColor .G (),_ece .LineColor .B ());if len (gsName )> 1{_gg .Add_gs (_a .PdfObjectName (gsName ));};_abg =_abg .Offset (_ece .X1 ,_ece .Y1 );_efe :=_abg .GetBoundingBox ();DrawPathWithCreator (_abg ,_gg );if _ece .LineStyle ==LineStyleDashed {_gg .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_gg .Add_f ().Add_Q ();};return _gg .Bytes (),_efe .ToPdfRectangle (),nil ;};
// Scale scales the vector by the specified factor.
func (_gde Vector )Scale (factor float64 )Vector {_bfbc :=_gde .Magnitude ();_ddc :=_gde .GetPolarAngle ();_gde .Dx =factor *_bfbc *_ce .Cos (_ddc );_gde .Dy =factor *_bfbc *_ce .Sin (_ddc );return _gde ;};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_cf .PdfColorDeviceRGB ;LineWidth float64 ;};
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_bf BoundingBox )ToPdfRectangle ()*_cf .PdfRectangle {return &_cf .PdfRectangle {Llx :_bf .X ,Lly :_bf .Y ,Urx :_bf .X +_bf .Width ,Ury :_bf .Y +_bf .Height };};
// GetBounds returns the bounding box of the Bezier curve.
func (_b CubicBezierCurve )GetBounds ()_a .PdfRectangle {_ge :=_b .P0 .X ;_af :=_b .P0 .X ;_ae :=_b .P0 .Y ;_ec :=_b .P0 .Y ;for _eg :=0.0;_eg <=1.0;_eg +=0.001{Rx :=_b .P0 .X *_f .Pow (1-_eg ,3)+_b .P1 .X *3*_eg *_f .Pow (1-_eg ,2)+_b .P2 .X *3*_f .Pow (_eg ,2)*(1-_eg )+_b .P3 .X *_f .Pow (_eg ,3);Ry :=_b .P0 .Y *_f .Pow (1-_eg ,3)+_b .P1 .Y *3*_eg *_f .Pow (1-_eg ,2)+_b .P2 .Y *3*_f .Pow (_eg ,2)*(1-_eg )+_b .P3 .Y *_f .Pow (_eg ,3);if Rx < _ge {_ge =Rx ;};if Rx > _af {_af =Rx ;};if Ry < _ae {_ae =Ry ;};if Ry > _ec {_ec =Ry ;};};_fe :=_a .PdfRectangle {};_fe .Llx =_ge ;_fe .Lly =_ae ;_fe .Urx =_af ;_fe .Ury =_ec ;return _fe ;};
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;};
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;};
// Offset shifts the Bezier path with the specified offsets.
func (_be CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _aa ,_ge :=range _be .Curves {_be .Curves [_aa ]=_ge .AddOffsetXY (offX ,offY );};return _be ;};
// 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 *_fb .ContentCreator ){for _fdb ,_fbf :=range bpath .Curves {if _fdb ==0{creator .Add_m (_fbf .P0 .X ,_fbf .P0 .Y );};creator .Add_c (_fbf .P1 .X ,_fbf .P1 .Y ,_fbf .P2 .X ,_fbf .P2 .Y ,_fbf .P3 .X ,_fbf .P3 .Y );};};
// AppendCurve appends the specified Bezier curve to the path.
func (_cb CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_cb .Curves =append (_cb .Curves ,curve );return _cb ;};
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_de :=CubicBezierPath {};_de .Curves =[]CubicBezierCurve {};return _de ;};
func NewCubicBezierPath ()CubicBezierPath {_bf :=CubicBezierPath {};_bf .Curves =[]CubicBezierCurve {};return _bf ;};
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_deed Rectangle )ToPdfRectangle ()*_cf .PdfRectangle {return &_cf .PdfRectangle {Llx :_deed .X ,Lly :_deed .Y ,Urx :_deed .X +_deed .Width ,Ury :_deed .Y +_deed .Height };};
// AddVector adds vector to a point.
func (_be Point )AddVector (v Vector )Point {_be .X +=v .Dx ;_be .Y +=v .Dy ;return _be };
// 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 (_dda Rectangle )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_dbb :=NewPath ();_dbb =_dbb .AppendPoint (NewPoint (0,0));_dbb =_dbb .AppendPoint (NewPoint (0,_dda .Height ));_dbb =_dbb .AppendPoint (NewPoint (_dda .Width ,_dda .Height ));_dbb =_dbb .AppendPoint (NewPoint (_dda .Width ,0));_dbb =_dbb .AppendPoint (NewPoint (0,0));if _dda .X !=0||_dda .Y !=0{_dbb =_dbb .Offset (_dda .X ,_dda .Y );};_eac :=_fb .NewContentCreator ();_eac .Add_q ();if _dda .FillEnabled {_eac .Add_rg (_dda .FillColor .R (),_dda .FillColor .G (),_dda .FillColor .B ());};if _dda .BorderEnabled {_eac .Add_RG (_dda .BorderColor .R (),_dda .BorderColor .G (),_dda .BorderColor .B ());_eac .Add_w (_dda .BorderWidth );};if len (gsName )> 1{_eac .Add_gs (_a .PdfObjectName (gsName ));};DrawPathWithCreator (_dbb ,_eac );_eac .Add_h ();if _dda .FillEnabled &&_dda .BorderEnabled {_eac .Add_B ();}else if _dda .FillEnabled {_eac .Add_f ();}else if _dda .BorderEnabled {_eac .Add_S ();};_eac .Add_Q ();return _eac .Bytes (),_dbb .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Flip changes the sign of the vector: -vector.
func (_dcc Vector )Flip ()Vector {_fafg :=_dcc .Magnitude ();_egge :=_dcc .GetPolarAngle ();_dcc .Dx =_fafg *_f .Cos (_egge +_f .Pi );_dcc .Dy =_fafg *_f .Sin (_egge +_f .Pi );return _dcc ;};
// 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 {_dcb :=Vector {};_dcb .Dx =b .X -a .X ;_dcb .Dy =b .Y -a .Y ;return _dcb ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_cag :=Vector {};_cag .Dx =length *_f .Cos (theta );_cag .Dy =length *_f .Sin (theta );return _cag ;};
// Magnitude returns the magnitude of the vector.
func (_cde Vector )Magnitude ()float64 {return _f .Sqrt (_f .Pow (_cde .Dx ,2.0)+_f .Pow (_cde .Dy ,2.0))};
// 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 *_d .ContentCreator ){for _def ,_gcbf :=range path .Points {if _def ==0{creator .Add_m (_gcbf .X ,_gcbf .Y );}else {creator .Add_l (_gcbf .X ,_gcbf .Y );};};};
// Length returns the number of points in the path.
func (_fc Path )Length ()int {return len (_fc .Points )};
// 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 ;};
// 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 (_gc Circle )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_def :=_gc .Width /2;_ddf :=_gc .Height /2;if _gc .BorderEnabled {_def -=_gc .BorderWidth /2;_ddf -=_gc .BorderWidth /2;};_adf :=0.551784;_aab :=_def *_adf ;_cda :=_ddf *_adf ;_eea :=NewCubicBezierPath ();_eea =_eea .AppendCurve (NewCubicBezierCurve (-_def ,0,-_def ,_cda ,-_aab ,_ddf ,0,_ddf ));_eea =_eea .AppendCurve (NewCubicBezierCurve (0,_ddf ,_aab ,_ddf ,_def ,_cda ,_def ,0));_eea =_eea .AppendCurve (NewCubicBezierCurve (_def ,0,_def ,-_cda ,_aab ,-_ddf ,0,-_ddf ));_eea =_eea .AppendCurve (NewCubicBezierCurve (0,-_ddf ,-_aab ,-_ddf ,-_def ,-_cda ,-_def ,0));_eea =_eea .Offset (_def ,_ddf );if _gc .BorderEnabled {_eea =_eea .Offset (_gc .BorderWidth /2,_gc .BorderWidth /2);};if _gc .X !=0||_gc .Y !=0{_eea =_eea .Offset (_gc .X ,_gc .Y );};_acb :=_fb .NewContentCreator ();_acb .Add_q ();if _gc .FillEnabled {_acb .Add_rg (_gc .FillColor .R (),_gc .FillColor .G (),_gc .FillColor .B ());};if _gc .BorderEnabled {_acb .Add_RG (_gc .BorderColor .R (),_gc .BorderColor .G (),_gc .BorderColor .B ());_acb .Add_w (_gc .BorderWidth );};if len (gsName )> 1{_acb .Add_gs (_a .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_eea ,_acb );_acb .Add_h ();if _gc .FillEnabled &&_gc .BorderEnabled {_acb .Add_B ();}else if _gc .FillEnabled {_acb .Add_f ();}else if _gc .BorderEnabled {_acb .Add_S ();};_acb .Add_Q ();_gdg :=_eea .GetBoundingBox ();if _gc .BorderEnabled {_gdg .Height +=_gc .BorderWidth ;_gdg .Width +=_gc .BorderWidth ;_gdg .X -=_gc .BorderWidth /2;_gdg .Y -=_gc .BorderWidth /2;};return _acb .Bytes (),_gdg .ToPdfRectangle (),nil ;};
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_a .PdfColorDeviceRGB ;BorderWidth float64 ;};
// 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 *_cf .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// Offset shifts the path with the specified offsets.
func (_gec Path )Offset (offX ,offY float64 )Path {for _cc ,_gee :=range _gec .Points {_gec .Points [_cc ]=_gee .Add (offX ,offY );};return _gec ;};
// 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 *_cf .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// 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 (_faf BasicLine )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_bbbg :=_faf .LineWidth ;_gdg :=NewPath ();_gdg =_gdg .AppendPoint (NewPoint (_faf .X1 ,_faf .Y1 ));_gdg =_gdg .AppendPoint (NewPoint (_faf .X2 ,_faf .Y2 ));_bc :=_d .NewContentCreator ();_gcdc :=_gdg .GetBoundingBox ();DrawPathWithCreator (_gdg ,_bc );if _faf .LineStyle ==LineStyleDashed {_bc .Add_d ([]int64 {1,1},0);};_bc .Add_RG (_faf .LineColor .R (),_faf .LineColor .G (),_faf .LineColor .B ()).Add_w (_bbbg ).Add_S ().Add_Q ();return _bc .Bytes (),_gcdc .ToPdfRectangle (),nil ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_dbd :=Vector {};_dbd .Dx =length *_ce .Cos (theta );_dbd .Dy =length *_ce .Sin (theta );return _dbd ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// Add adds the specified vector to the current one and returns the result.
func (_ffg Vector )Add (other Vector )Vector {_ffg .Dx +=other .Dx ;_ffg .Dy +=other .Dy ;return _ffg };
// Length returns the number of points in the path.
func (_fd Path )Length ()int {return len (_fd .Points )};
// 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 *_fb .ContentCreator ){for _dgc ,_fba :=range path .Points {if _dgc ==0{creator .Add_m (_fba .X ,_fba .Y );}else {creator .Add_l (_fba .X ,_fba .Y );};};};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_ec Path )RemovePoint (number int )Path {if number < 1||number > len (_ec .Points ){return _ec ;};_bcg :=number -1;_ec .Points =append (_ec .Points [:_bcg ],_ec .Points [_bcg +1:]...);return _ec ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_gd Path )GetPointNumber (number int )Point {if number < 1||number > len (_gd .Points ){return Point {};};return _gd .Points [number -1];};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_bgb Vector )GetPolarAngle ()float64 {return _ce .Atan2 (_bgb .Dy ,_bgb .Dx )};
// 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 (_bba Rectangle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_cf :=NewPath ();_cf =_cf .AppendPoint (NewPoint (0,0));_cf =_cf .AppendPoint (NewPoint (0,_bba .Height ));_cf =_cf .AppendPoint (NewPoint (_bba .Width ,_bba .Height ));_cf =_cf .AppendPoint (NewPoint (_bba .Width ,0));_cf =_cf .AppendPoint (NewPoint (0,0));if _bba .X !=0||_bba .Y !=0{_cf =_cf .Offset (_bba .X ,_bba .Y );};_gbb :=_d .NewContentCreator ();_gbb .Add_q ();if _bba .FillEnabled {_gbb .Add_rg (_bba .FillColor .R (),_bba .FillColor .G (),_bba .FillColor .B ());};if _bba .BorderEnabled {_gbb .Add_RG (_bba .BorderColor .R (),_bba .BorderColor .G (),_bba .BorderColor .B ());_gbb .Add_w (_bba .BorderWidth );};if len (gsName )> 1{_gbb .Add_gs (_ea .PdfObjectName (gsName ));};DrawPathWithCreator (_cf ,_gbb );_gbb .Add_h ();if _bba .FillEnabled &&_bba .BorderEnabled {_gbb .Add_B ();}else if _bba .FillEnabled {_gbb .Add_f ();}else if _bba .BorderEnabled {_gbb .Add_S ();};_gbb .Add_Q ();return _gbb .Bytes (),_cf .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 (_fga Polygon )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_gca :=_fb .NewContentCreator ();_gca .Add_q ();_fga .FillEnabled =_fga .FillEnabled &&_fga .FillColor !=nil ;if _fga .FillEnabled {_gca .Add_rg (_fga .FillColor .R (),_fga .FillColor .G (),_fga .FillColor .B ());};_fga .BorderEnabled =_fga .BorderEnabled &&_fga .BorderColor !=nil ;if _fga .BorderEnabled {_gca .Add_RG (_fga .BorderColor .R (),_fga .BorderColor .G (),_fga .BorderColor .B ());_gca .Add_w (_fga .BorderWidth );};if len (gsName )> 1{_gca .Add_gs (_a .PdfObjectName (gsName ));};_abd :=NewPath ();for _ ,_gcb :=range _fga .Points {for _cdf ,_efc :=range _gcb {_abd =_abd .AppendPoint (_efc );if _cdf ==0{_gca .Add_m (_efc .X ,_efc .Y );}else {_gca .Add_l (_efc .X ,_efc .Y );};};_gca .Add_h ();};if _fga .FillEnabled &&_fga .BorderEnabled {_gca .Add_B ();}else if _fga .FillEnabled {_gca .Add_f ();}else if _fga .BorderEnabled {_gca .Add_S ();};_gca .Add_Q ();return _gca .Bytes (),_abd .GetBoundingBox ().ToPdfRectangle (),nil ;};
func (_gcd Polygon )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_efe :=_d .NewContentCreator ();_efe .Add_q ();_gcd .FillEnabled =_gcd .FillEnabled &&_gcd .FillColor !=nil ;if _gcd .FillEnabled {_efe .Add_rg (_gcd .FillColor .R (),_gcd .FillColor .G (),_gcd .FillColor .B ());};_gcd .BorderEnabled =_gcd .BorderEnabled &&_gcd .BorderColor !=nil ;if _gcd .BorderEnabled {_efe .Add_RG (_gcd .BorderColor .R (),_gcd .BorderColor .G (),_gcd .BorderColor .B ());_efe .Add_w (_gcd .BorderWidth );};if len (gsName )> 1{_efe .Add_gs (_ea .PdfObjectName (gsName ));};_acg :=NewPath ();for _ ,_aeb :=range _gcd .Points {for _dbd ,_cge :=range _aeb {_acg =_acg .AppendPoint (_cge );if _dbd ==0{_efe .Add_m (_cge .X ,_cge .Y );}else {_efe .Add_l (_cge .X ,_cge .Y );};};_efe .Add_h ();};if _gcd .FillEnabled &&_gcd .BorderEnabled {_efe .Add_B ();}else if _gcd .FillEnabled {_efe .Add_f ();}else if _gcd .BorderEnabled {_efe .Add_S ();};_efe .Add_Q ();return _efe .Bytes (),_acg .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 (_dfg PolyBezierCurve )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){if _dfg .BorderColor ==nil {_dfg .BorderColor =_cf .NewPdfColorDeviceRGB (0,0,0);};_eab :=NewCubicBezierPath ();for _ ,_dee :=range _dfg .Curves {_eab =_eab .AppendCurve (_dee );};_ab :=_fb .NewContentCreator ();_ab .Add_q ();_dfg .FillEnabled =_dfg .FillEnabled &&_dfg .FillColor !=nil ;if _dfg .FillEnabled {_ab .Add_rg (_dfg .FillColor .R (),_dfg .FillColor .G (),_dfg .FillColor .B ());};_ab .Add_RG (_dfg .BorderColor .R (),_dfg .BorderColor .G (),_dfg .BorderColor .B ());_ab .Add_w (_dfg .BorderWidth );if len (gsName )> 1{_ab .Add_gs (_a .PdfObjectName (gsName ));};for _ ,_bfb :=range _eab .Curves {_ab .Add_m (_bfb .P0 .X ,_bfb .P0 .Y );_ab .Add_c (_bfb .P1 .X ,_bfb .P1 .Y ,_bfb .P2 .X ,_bfb .P2 .Y ,_bfb .P3 .X ,_bfb .P3 .Y );};if _dfg .FillEnabled {_ab .Add_h ();_ab .Add_B ();}else {_ab .Add_S ();};_ab .Add_Q ();return _ab .Bytes (),_eab .GetBoundingBox ().ToPdfRectangle (),nil ;};
// LineStyle refers to how the line will be created.
type LineStyle int ;
// AppendPoint adds the specified point to the path.
func (_cab Path )AppendPoint (point Point )Path {_cab .Points =append (_cab .Points ,point );return _cab };
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// FlipX flips the sign of the Dx component of the vector.
func (_ebbd Vector )FlipX ()Vector {_ebbd .Dx =-_ebbd .Dx ;return _ebbd };
// Flip changes the sign of the vector: -vector.
func (_gee Vector )Flip ()Vector {_ebe :=_gee .Magnitude ();_ffae :=_gee .GetPolarAngle ();_gee .Dx =_ebe *_ce .Cos (_ffae +_ce .Pi );_gee .Dy =_ebe *_ce .Sin (_ffae +_ce .Pi );return _gee ;};
// GetBoundingBox returns the bounding box of the path.
func (_cgb Path )GetBoundingBox ()BoundingBox {_ef :=BoundingBox {};_gf :=0.0;_caf :=0.0;_bd :=0.0;_ed :=0.0;for _ffa ,_fa :=range _cgb .Points {if _ffa ==0{_gf =_fa .X ;_caf =_fa .X ;_bd =_fa .Y ;_ed =_fa .Y ;continue ;};if _fa .X < _gf {_gf =_fa .X ;};if _fa .X > _caf {_caf =_fa .X ;};if _fa .Y < _bd {_bd =_fa .Y ;};if _fa .Y > _ed {_ed =_fa .Y ;};};_ef .X =_gf ;_ef .Y =_bd ;_ef .Width =_caf -_gf ;_ef .Height =_ed -_bd ;return _ef ;};
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_cdc Point )Rotate (theta float64 )Point {_fc :=_d .NewPoint (_cdc .X ,_cdc .Y ).Rotate (theta );return NewPoint (_fc .X ,_fc .Y );};
// AppendCurve appends the specified Bezier curve to the path.
func (_fg CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_fg .Curves =append (_fg .Curves ,curve );return _fg ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_fbc CubicBezierPath )GetBoundingBox ()Rectangle {_bb :=Rectangle {};_cg :=0.0;_eb :=0.0;_gb :=0.0;_ac :=0.0;for _cea ,_da :=range _fbc .Curves {_gbb :=_da .GetBounds ();if _cea ==0{_cg =_gbb .Llx ;_eb =_gbb .Urx ;_gb =_gbb .Lly ;_ac =_gbb .Ury ;continue ;};if _gbb .Llx < _cg {_cg =_gbb .Llx ;};if _gbb .Urx > _eb {_eb =_gbb .Urx ;};if _gbb .Lly < _gb {_gb =_gbb .Lly ;};if _gbb .Ury > _ac {_ac =_gbb .Ury ;};};_bb .X =_cg ;_bb .Y =_gb ;_bb .Width =_eb -_cg ;_bb .Height =_ac -_gb ;return _bb ;};
// 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 *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};

File diff suppressed because one or more lines are too long

View File

@ -9,68 +9,29 @@
// 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 (_d "crypto/aes";_ed "crypto/cipher";_b "crypto/md5";_dc "crypto/rand";_fd "crypto/rc4";_a "fmt";_fb "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/core/security";_f "io";);func init (){_cfa ("\u0041\u0045\u0053V\u0032",_g )};func _fe (_gf FilterDict )(Filter ,error ){if _gf .Length ==256{_fb .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",_gf .Length );_gf .Length /=8;};if _gf .Length !=0&&_gf .Length !=32{return nil ,_a .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",_gf .Length );};return filterAESV3 {},nil ;};
package crypt ;import (_f "crypto/aes";_ec "crypto/cipher";_ea "crypto/md5";_fe "crypto/rand";_d "crypto/rc4";_e "fmt";_c "github.com/unidoc/unipdf/v3/common";_ff "github.com/unidoc/unipdf/v3/core/security";_b "io";);func init (){_ddb ("\u0041\u0045\u0053V\u0032",_cf )};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_cde ,_eg :=_fbf (d .CFM );if _eg !=nil {return nil ,_eg ;};_ffce ,_eg :=_cde (d );if _eg !=nil {return nil ,_eg ;};return _ffce ,nil ;};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};type filterAES struct{};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ec .AuthEvent ;Length int ;};
type FilterDict struct{CFM string ;AuthEvent _ff .AuthEvent ;Length int ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};type filterAESV3 struct{filterAES };
// KeyLength implements Filter interface.
func (_bba filterV2 )KeyLength ()int {return _bba ._feba };func _db (_eg ,_feb uint32 ,_gdc []byte ,_efe bool )([]byte ,error ){_cgg :=make ([]byte ,len (_gdc )+5);for _ee :=0;_ee < len (_gdc );_ee ++{_cgg [_ee ]=_gdc [_ee ];};for _efg :=0;_efg < 3;_efg ++{_fce :=byte ((_eg >>uint32 (8*_efg ))&0xff);_cgg [_efg +len (_gdc )]=_fce ;};for _gfa :=0;_gfa < 2;_gfa ++{_bcc :=byte ((_feb >>uint32 (8*_gfa ))&0xff);_cgg [_gfa +len (_gdc )+3]=_bcc ;};if _efe {_cgg =append (_cgg ,0x73);_cgg =append (_cgg ,0x41);_cgg =append (_cgg ,0x6C);_cgg =append (_cgg ,0x54);};_egb :=_b .New ();_egb .Write (_cgg );_gff :=_egb .Sum (nil );if len (_gdc )+5< 16{return _gff [0:len (_gdc )+5],nil ;};return _gff ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_dad ,_ecb :=_ffg (FilterDict {Length :length });if _ecb !=nil {_fb .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",_ecb );return filterV2 {_feba :length };};return _dad ;};type filterAES struct{};func init (){_cfa ("\u0041\u0045\u0053V\u0033",_fe )};type filterFunc func (_aac FilterDict )(Filter ,error );func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fc ,_ab :=_d .NewCipher (okey );if _ab !=nil {return nil ,_ab ;};_fb .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _c =_d .BlockSize ;_ae :=_c -len (buf )%_c ;for _ff :=0;_ff < _ae ;_ff ++{buf =append (buf ,byte (_ae ));};_fb .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_cg :=make ([]byte ,_c +len (buf ));_gd :=_cg [:_c ];if _ ,_eda :=_f .ReadFull (_dc .Reader ,_gd );_eda !=nil {return nil ,_eda ;};_bg :=_ed .NewCBCEncrypter (_fc ,_gd );_bg .CryptBlocks (_cg [_c :],buf );buf =_cg ;_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_ba ,_bd :=_fe (FilterDict {});if _bd !=nil {_fb .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",_bd );return filterAESV3 {};};return _ba ;};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};func (filterIdentity )KeyLength ()int {return 0};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};var (_gdf =make (map[string ]filterFunc ););type filterAESV2 struct{filterAES };
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_bf ,_ef :=_g (FilterDict {});if _ef !=nil {_fb .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",_ef );return filterAESV2 {};};return _bf ;};var _ Filter =filterAESV3 {};func init (){_cfa ("\u0056\u0032",_ffg )};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _fb (objNum ,genNum ,ekey ,true );};func _fg (_gb FilterDict )(Filter ,error ){if _gb .Length ==256{_c .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",_gb .Length );_gb .Length /=8;};if _gb .Length !=0&&_gb .Length !=32{return nil ,_e .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",_gb .Length );};return filterAESV3 {},nil ;};
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func _cf (_ab FilterDict )(Filter ,error ){if _ab .Length ==128{_c .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",_ab .Length );_ab .Length /=8;};if _ab .Length !=0&&_ab .Length !=16{return nil ,_e .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",_ab .Length );};return filterAESV2 {},nil ;};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_ed ,_a :=_cf (FilterDict {});if _a !=nil {_c .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",_a );return filterAESV2 {};};return _ed ;};func init (){_ddb ("\u0041\u0045\u0053V\u0033",_fg )};func _ddb (_da string ,_aac filterFunc ){if _ ,_eb :=_bce [_da ];_eb {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_bce [_da ]=_aac ;};
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bab ,_add :=_fd .NewCipher (okey );if _add !=nil {return nil ,_add ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bab .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _cfa (_ebe string ,_dcf filterFunc ){if _ ,_ea :=_gdf [_ebe ];_ea {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_gdf [_ebe ]=_dcf ;};type filterV2 struct{_feba int };func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bbe ,_fcc :=_fd .NewCipher (okey );if _fcc !=nil {return nil ,_fcc ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bbe .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};var _ Filter =filterAESV2 {};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};func _bde (_ca string )(filterFunc ,error ){_dg :=_gdf [string (_ca )];if _dg ==nil {return nil ,_a .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",_ca );};return _dg ,nil ;};
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _db (objNum ,genNum ,ekey ,true );};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_cf ,_bdg :=_bde (d .CFM );if _bdg !=nil {return nil ,_bdg ;};_aec ,_bdg :=_cf (d );if _bdg !=nil {return nil ,_bdg ;};return _aec ,nil ;};
// MakeKey implements Filter interface.
func (_ddad filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _db (objNum ,genNum ,ekey ,false );};
// HandlerVersion implements Filter interface.
func (_dda filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// Filter is a common interface for crypt filter methods.
type Filter interface{
@ -88,21 +49,60 @@ 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 (_ac ,_ag uint32 ,_fea []byte )([]byte ,error );
MakeKey (_df ,_cb uint32 ,_fcd []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 (_fef []byte ,_abf []byte )([]byte ,error );
EncryptBytes (_adfd []byte ,_ece []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 (_aacb []byte ,_abg []byte )([]byte ,error );};
DecryptBytes (_dcb []byte ,_ecgg []byte )([]byte ,error );};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};var _ Filter =filterV2 {};
// PDFVersion implements Filter interface.
func (_gcf filterV2 )PDFVersion ()[2]int {return [2]int {}};func _ffg (_fff FilterDict )(Filter ,error ){if _fff .Length %8!=0{return nil ,_a .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",_fff .Length );};if _fff .Length < 5||_fff .Length > 16{if _fff .Length ==40||_fff .Length ==64||_fff .Length ==128{_fb .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",_fff .Length );_fff .Length /=8;}else {return nil ,_a .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",_fff .Length );};};return filterV2 {_feba :_fff .Length },nil ;};
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};type filterIdentity struct{};
// 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 {_ad ,_ef :=_fg (FilterDict {});if _ef !=nil {_c .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",_ef );return filterAESV3 {};};return _ad ;};
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };var _ Filter =filterV2 {};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ecc ,_eb :=_d .NewCipher (okey );if _eb !=nil {return nil ,_eb ;};if len (buf )< 16{_fb .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 ,_a .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_da :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_fb .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_da ),_da );_fb .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_a .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 ));};_gc :=_ed .NewCBCDecrypter (_ecc ,_da );_fb .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_fb .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 );_gc .CryptBlocks (buf ,buf );_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_fb .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 ;};_ad :=int (buf [len (buf )-1]);if _ad > len (buf ){_fb .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",_ad ,len (buf ));return buf ,_a .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ad ];return buf ,nil ;};func _g (_bb FilterDict )(Filter ,error ){if _bb .Length ==128{_fb .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",_bb .Length );_bb .Length /=8;};if _bb .Length !=0&&_bb .Length !=16{return nil ,_a .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",_bb .Length );};return filterAESV2 {},nil ;};
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };func _fb (_ffc ,_bd uint32 ,_fa []byte ,_ae bool )([]byte ,error ){_dc :=make ([]byte ,len (_fa )+5);for _aee :=0;_aee < len (_fa );_aee ++{_dc [_aee ]=_fa [_aee ];};for _bga :=0;_bga < 3;_bga ++{_feg :=byte ((_ffc >>uint32 (8*_bga ))&0xff);_dc [_bga +len (_fa )]=_feg ;};for _fee :=0;_fee < 2;_fee ++{_gc :=byte ((_bd >>uint32 (8*_fee ))&0xff);_dc [_fee +len (_fa )+3]=_gc ;};if _ae {_dc =append (_dc ,0x73);_dc =append (_dc ,0x41);_dc =append (_dc ,0x6C);_dc =append (_dc ,0x54);};_dba :=_ea .New ();_dba .Write (_dc );_ffd :=_dba .Sum (nil );if len (_fa )+5< 16{return _ffd [0:len (_fa )+5],nil ;};return _ffd ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
// HandlerVersion implements Filter interface.
func (_adf filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func init (){_ddb ("\u0056\u0032",_eab )};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ccc ,_ccd :=_f .NewCipher (okey );if _ccd !=nil {return nil ,_ccd ;};_c .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _bc =_f .BlockSize ;_gf :=_bc -len (buf )%_bc ;for _cd :=0;_cd < _gf ;_cd ++{buf =append (buf ,byte (_gf ));};_c .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_ac :=make ([]byte ,_bc +len (buf ));_adg :=_ac [:_bc ];if _ ,_adge :=_b .ReadFull (_fe .Reader ,_adg );_adge !=nil {return nil ,_adge ;};_aa :=_ec .NewCBCEncrypter (_ccc ,_adg );_aa .CryptBlocks (_ac [_bc :],buf );buf =_ac ;_c .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};var (_bce =make (map[string ]filterFunc ););func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_cdg ,_ag :=_d .NewCipher (okey );if _ag !=nil {return nil ,_ag ;};_c .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_cdg .XORKeyStream (buf ,buf );_c .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
// PDFVersion implements Filter interface.
func (_aea filterV2 )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};var _ Filter =filterAESV3 {};func _fbf (_daa string )(filterFunc ,error ){_ebe :=_bce [_daa ];if _ebe ==nil {return nil ,_e .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",_daa );};return _ebe ,nil ;};var _ Filter =filterAESV2 {};type filterAESV3 struct{filterAES };
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ecb ,_ee :=_d .NewCipher (okey );if _ee !=nil {return nil ,_ee ;};_c .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ecb .XORKeyStream (buf ,buf );_c .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
// MakeKey implements Filter interface.
func (_bcg filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _fb (objNum ,genNum ,ekey ,false );};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_fc ,_dd :=_eab (FilterDict {Length :length });if _dd !=nil {_c .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",_dd );return filterV2 {_fcb :length };};return _fc ;};type filterV2 struct{_fcb int };type filterIdentity struct{};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};type filterAESV2 struct{filterAES };func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};func (filterIdentity )KeyLength ()int {return 0};
// KeyLength implements Filter interface.
func (_ade filterV2 )KeyLength ()int {return _ade ._fcb };func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ca ,_ga :=_f .NewCipher (okey );if _ga !=nil {return nil ,_ga ;};if len (buf )< 16{_c .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 ,_e .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_ecg :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_c .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_ecg ),_ecg );_c .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_e .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 ));};_bg :=_ec .NewCBCDecrypter (_ca ,_ecg );_c .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_c .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 );_bg .CryptBlocks (buf ,buf );_c .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_c .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 ;};_ceb :=int (buf [len (buf )-1]);if _ceb > len (buf ){_c .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",_ceb ,len (buf ));return buf ,_e .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ceb ];return buf ,nil ;};type filterFunc func (_gfg FilterDict )(Filter ,error );func _eab (_adb FilterDict )(Filter ,error ){if _adb .Length %8!=0{return nil ,_e .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",_adb .Length );};if _adb .Length < 5||_adb .Length > 16{if _adb .Length ==40||_adb .Length ==64||_adb .Length ==128{_c .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",_adb .Length );_adb .Length /=8;}else {return nil ,_e .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",_adb .Length );};};return filterV2 {_fcb :_adb .Length },nil ;};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};

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 (_f "encoding/json";_ge "github.com/unidoc/unipdf/v3/core";_geg "github.com/unidoc/unipdf/v3/model";_g "io";_c "os";);
package fjson ;import (_e "encoding/json";_da "github.com/unidoc/unipdf/v3/core";_ad "github.com/unidoc/unipdf/v3/model";_a "io";_dc "os";);
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_gd ,_fb :=_c .Open (filePath );if _fb !=nil {return nil ,_fb ;};defer _gd .Close ();return LoadFromJSON (_gd );};
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_f ,_fb :=_dc .Open (filePath );if _fb !=nil {return nil ,_fb ;};defer _f .Close ();return LoadFromJSON (_f );};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fd ,_gdb :=_c .Open (filePath );if _gdb !=nil {return nil ,_gdb ;};defer _fd .Close ();return LoadFromPDF (_fd );};
// JSON returns the field data as a string in JSON format.
func (_gb FieldData )JSON ()(string ,error ){_eaf ,_dce :=_f .MarshalIndent (_gb ._a ,"","\u0020\u0020\u0020\u0020");return string (_eaf ),_dce ;};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _g .ReadSeeker )(*FieldData ,error ){_ca ,_cf :=_geg .NewPdfReader (rs );if _cf !=nil {return nil ,_cf ;};if _ca .AcroForm ==nil {return nil ,nil ;};var _b []fieldValue ;_ad :=_ca .AcroForm .AllFields ();for _ ,_be :=range _ad {var _ed []string ;_ec :=make (map[string ]struct{});_ae ,_aeg :=_be .FullName ();if _aeg !=nil {return nil ,_aeg ;};if _ef ,_cg :=_be .V .(*_ge .PdfObjectString );_cg {_b =append (_b ,fieldValue {Name :_ae ,Value :_ef .Decoded ()});continue ;};var _gg string ;for _ ,_fbb :=range _be .Annotations {_ga ,_eaa :=_ge .GetName (_fbb .AS );if _eaa {_gg =_ga .String ();};_d ,_ggg :=_ge .GetDict (_fbb .AP );if !_ggg {continue ;};_de ,_ :=_ge .GetDict (_d .Get ("\u004e"));for _ ,_eg :=range _de .Keys (){_dc :=_eg .String ();if _ ,_bg :=_ec [_dc ];!_bg {_ed =append (_ed ,_dc );_ec [_dc ]=struct{}{};};};_gag ,_ :=_ge .GetDict (_d .Get ("\u0044"));for _ ,_gggd :=range _gag .Keys (){_bbf :=_gggd .String ();if _ ,_abg :=_ec [_bbf ];!_abg {_ed =append (_ed ,_bbf );_ec [_bbf ]=struct{}{};};};};_adb :=fieldValue {Name :_ae ,Value :_gg ,Options :_ed };_b =append (_b ,_adb );};_ee :=FieldData {_a :_b };return &_ee ,nil ;};
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_ab ,_dbf :=_dc .Open (filePath );if _dbf !=nil {return nil ,_dbf ;};defer _ab .Close ();return LoadFromPDF (_ab );};
// LoadFromJSON loads JSON form data from `r`.
func LoadFromJSON (r _g .Reader )(*FieldData ,error ){var _ea FieldData ;_ab :=_f .NewDecoder (r ).Decode (&_ea ._a );if _ab !=nil {return nil ,_ab ;};return &_ea ,nil ;};
func LoadFromJSON (r _a .Reader )(*FieldData ,error ){var _b FieldData ;_c :=_e .NewDecoder (r ).Decode (&_b ._af );if _c !=nil {return nil ,_c ;};return &_b ,nil ;};
// FieldValues implements model.FieldValueProvider interface.
func (_abgg *FieldData )FieldValues ()(map[string ]_ge .PdfObject ,error ){_ggc :=make (map[string ]_ge .PdfObject );for _ ,_ac :=range _abgg ._a {if len (_ac .Value )> 0{_ggc [_ac .Name ]=_ge .MakeString (_ac .Value );};};return _ggc ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_af []fieldValue };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{_a []fieldValue };
// FieldValues implements model.FieldValueProvider interface.
func (_gb *FieldData )FieldValues ()(map[string ]_da .PdfObject ,error ){_abb :=make (map[string ]_da .PdfObject );for _ ,_dec :=range _gb ._af {if len (_dec .Value )> 0{_abb [_dec .Name ]=_da .MakeString (_dec .Value );};};return _abb ,nil ;};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _a .ReadSeeker )(*FieldData ,error ){_ec ,_bf :=_ad .NewPdfReader (rs );if _bf !=nil {return nil ,_bf ;};if _ec .AcroForm ==nil {return nil ,nil ;};var _ca []fieldValue ;_fba :=_ec .AcroForm .AllFields ();for _ ,_cg :=range _fba {var _afa []string ;_fc :=make (map[string ]struct{});_g ,_ee :=_cg .FullName ();if _ee !=nil {return nil ,_ee ;};if _de ,_adg :=_cg .V .(*_da .PdfObjectString );_adg {_ca =append (_ca ,fieldValue {Name :_g ,Value :_de .Decoded ()});continue ;};var _fd string ;for _ ,_ef :=range _cg .Annotations {_bd ,_fg :=_da .GetName (_ef .AS );if _fg {_fd =_bd .String ();};_ed ,_bg :=_da .GetDict (_ef .AP );if !_bg {continue ;};_adf ,_ :=_da .GetDict (_ed .Get ("\u004e"));for _ ,_bb :=range _adf .Keys (){_caa :=_bb .String ();if _ ,_dga :=_fc [_caa ];!_dga {_afa =append (_afa ,_caa );_fc [_caa ]=struct{}{};};};_fdc ,_ :=_da .GetDict (_ed .Get ("\u0044"));for _ ,_ga :=range _fdc .Keys (){_eg :=_ga .String ();if _ ,_ae :=_fc [_eg ];!_ae {_afa =append (_afa ,_eg );_fc [_eg ]=struct{}{};};};};_gg :=fieldValue {Name :_g ,Value :_fd ,Options :_afa };_ca =append (_ca ,_gg );};_ac :=FieldData {_af :_ca };return &_ac ,nil ;};
// JSON returns the field data as a string in JSON format.
func (_aa FieldData )JSON ()(string ,error ){_ege ,_be :=_e .MarshalIndent (_aa ._af ,"","\u0020\u0020\u0020\u0020");return string (_ege ),_be ;};

2
go.sum
View File

@ -20,11 +20,13 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df h1:1RV3lxQ6L6xGFNhngpP9iMjJPSwvH3p17JNbK9u5274=
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8=
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw=
github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w=
github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=

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 (_e "encoding/binary";_bb "unsafe";);func IsBig ()bool {return _g };func init (){const _d =int (_bb .Sizeof (0));_c :=1;_dg :=(*[_d ]byte )(_bb .Pointer (&_c ));if _dg [0]==0{_g =true ;ByteOrder =_e .BigEndian ;}else {ByteOrder =_e .LittleEndian ;};};func IsLittle ()bool {return !_g };var (ByteOrder _e .ByteOrder ;_g bool ;);
package endian ;import (_b "encoding/binary";_bf "unsafe";);func IsBig ()bool {return _g };func init (){const _gb =int (_bf .Sizeof (0));_ed :=1;_f :=(*[_gb ]byte )(_bf .Pointer (&_ed ));if _f [0]==0{_g =true ;ByteOrder =_b .BigEndian ;}else {ByteOrder =_b .LittleEndian ;};};func IsLittle ()bool {return !_g };var (ByteOrder _b .ByteOrder ;_g bool ;);

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 _b "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func NewIntSlice (i int )*IntSlice {_ca :=IntSlice (make ([]int ,i ));return &_ca };func (_ac *Stack )Pop ()(_fed interface{},_bf bool ){_fed ,_bf =_ac .peek ();if !_bf {return nil ,_bf ;};_ac .Data =_ac .Data [:_ac .top ()];return _fed ,true ;};func (_ce *Stack )peek ()(interface{},bool ){_ddb :=_ce .top ();if _ddb ==-1{return nil ,false ;};return _ce .Data [_ddb ],true ;};func (_fea *IntSlice )Copy ()*IntSlice {_e :=IntSlice (make ([]int ,len (*_fea )));copy (_e ,*_fea );return &_e ;};func NewNumSlice (i int )*NumSlice {_gc :=NumSlice (make ([]float32 ,i ));return &_gc };func (_bg *NumSlice )Add (v float32 ){*_bg =append (*_bg ,v )};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_ag IntSlice )Size ()int {return len (_ag )};type Stack struct{Data []interface{};Aux *Stack ;};func (_dg *Stack )top ()int {return len (_dg .Data )-1};type NumSlice []float32 ;type IntsMap map[uint64 ][]int ;func (_ggd NumSlice )GetInt (i int )(int ,error ){const _be ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_ggd )-1{return 0,_b .Errorf (_be ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_ddg :=_ggd [i ];return int (_ddg +Sign (_ddg )*0.5),nil ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_a IntsMap )Add (key uint64 ,value int ){_a [key ]=append (_a [key ],value )};type IntSlice []int ;func (_aa NumSlice )GetIntSlice ()[]int {_ab :=make ([]int ,len (_aa ));for _ff ,_cd :=range _aa {_ab [_ff ]=int (_cd );};return _ab ;};func (_dd IntSlice )Get (index int )(int ,error ){if index > len (_dd )-1{return 0,_b .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 _dd [index ],nil ;};func (_bgf NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_bgf )-1{return 0,_b .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 _bgf [i ],nil ;};func (_ebe *Stack )Push (v interface{}){_ebe .Data =append (_ebe .Data ,v )};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_ae *IntSlice )Add (v int )error {if _ae ==nil {return _b .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");};*_ae =append (*_ae ,v );return nil ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_c IntsMap )Get (key uint64 )(int ,bool ){_g ,_gg :=_c [key ];if !_gg {return 0,false ;};if len (_g )==0{return 0,false ;};return _g [0],true ;};func (_aae *Stack )Peek ()(_aga interface{},_eb bool ){return _aae .peek ()};func (_fg *Stack )Len ()int {return len (_fg .Data )};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_cb *NumSlice )AddInt (v int ){*_cb =append (*_cb ,float32 (v ))};func (_fe IntsMap )Delete (key uint64 ){delete (_fe ,key )};func (_d IntsMap )GetSlice (key uint64 )([]int ,bool ){_ad ,_bb :=_d [key ];if !_bb {return nil ,false ;};return _ad ,true ;};
package basic ;import _f "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func (_ae IntsMap )GetSlice (key uint64 )([]int ,bool ){_e ,_ac :=_ae [key ];if !_ac {return nil ,false ;};return _e ,true ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_cb IntSlice )Get (index int )(int ,error ){if index > len (_cb )-1{return 0,_f .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 _cb [index ],nil ;};type IntsMap map[uint64 ][]int ;func (_fc NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_fc )-1{return 0,_f .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 _fc [i ],nil ;};func NewIntSlice (i int )*IntSlice {_g :=IntSlice (make ([]int ,i ));return &_g };func (_dd *NumSlice )Add (v float32 ){*_dd =append (*_dd ,v )};func (_a IntsMap )Get (key uint64 )(int ,bool ){_b ,_db :=_a [key ];if !_db {return 0,false ;};if len (_b )==0{return 0,false ;};return _b [0],true ;};type IntSlice []int ;func (_fcc *Stack )Pop ()(_gb interface{},_daf bool ){_gb ,_daf =_fcc .peek ();if !_daf {return nil ,_daf ;};_fcc .Data =_fcc .Data [:_fcc .top ()];return _gb ,true ;};type Stack struct{Data []interface{};Aux *Stack ;};func NewNumSlice (i int )*NumSlice {_ge :=NumSlice (make ([]float32 ,i ));return &_ge };func (_bg *Stack )top ()int {return len (_bg .Data )-1};func (_ag *Stack )Len ()int {return len (_ag .Data )};type NumSlice []float32 ;func (_ga *Stack )Peek ()(_bb interface{},_agc bool ){return _ga .peek ()};func (_da NumSlice )GetIntSlice ()[]int {_af :=make ([]int ,len (_da ));for _gg ,_ee :=range _da {_af [_gg ]=int (_ee );};return _af ;};func (_ff IntsMap )Delete (key uint64 ){delete (_ff ,key )};func (_bf *Stack )peek ()(interface{},bool ){_acd :=_bf .top ();if _acd ==-1{return nil ,false ;};return _bf .Data [_acd ],true ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_de NumSlice )GetInt (i int )(int ,error ){const _ba ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_de )-1{return 0,_f .Errorf (_ba ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cbd :=_de [i ];return int (_cbd +Sign (_cbd )*0.5),nil ;};func (_ddd *NumSlice )AddInt (v int ){*_ddd =append (*_ddd ,float32 (v ))};func (_c IntsMap )Add (key uint64 ,value int ){_c [key ]=append (_c [key ],value )};func (_ab IntSlice )Size ()int {return len (_ab )};func (_ce *Stack )Push (v interface{}){_ce .Data =append (_ce .Data ,v )};func (_cd *IntSlice )Add (v int )error {if _cd ==nil {return _f .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");};*_cd =append (*_cd ,v );return nil ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_eg *IntSlice )Copy ()*IntSlice {_aef :=IntSlice (make ([]int ,len (*_eg )));copy (_aef ,*_eg );return &_aef ;};

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 (_a "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";_g "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";);func (_cd *Decoder )decodePage (_aae int )([]byte ,error ){const _fa ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _aae < 0{return nil ,_g .Errorf (_fa ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_aae );};if _aae > int (_cd ._ef .NumberOfPages ){return nil ,_g .Errorf (_fa ,"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",_aae );};_cca ,_aac :=_cd ._ef .GetPage (_aae );if _aac !=nil {return nil ,_g .Wrap (_aac ,_fa ,"");};_cda ,_aac :=_cca .GetBitmap ();if _aac !=nil {return nil ,_g .Wrap (_aac ,_fa ,"");};_cda .InverseData ();if !_cd ._de .UnpaddedData {return _cda .Data ,nil ;};return _cda .GetUnpaddedData ();};func (_ea *Decoder )DecodePageImage (pageNumber int )(_d .Image ,error ){const _ae ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_cbg ,_cf :=_ea .decodePageImage (pageNumber );if _cf !=nil {return nil ,_g .Wrap (_cf ,_ae ,"");};return _cbg ,nil ;};func (_f *Decoder )DecodeNextPage ()([]byte ,error ){_f ._cb ++;_cbb :=_f ._cb ;return _f .decodePage (_cbb );};func (_dg *Decoder )PageNumber ()(int ,error ){const _cc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _dg ._ef ==nil {return 0,_g .Error (_cc ,"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 (_dg ._ef .NumberOfPages ),nil ;};type Parameters struct{UnpaddedData bool ;Color _e .Color ;};func (_ed *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _ed .decodePage (pageNumber )};type Decoder struct{_aa _a .StreamReader ;_ef *_b .Document ;_cb int ;_de Parameters ;};func Decode (input []byte ,parameters Parameters ,globals *_b .Globals )(*Decoder ,error ){_ac :=_a .NewReader (input );_ff ,_cbbd :=_b .DecodeDocument (_ac ,globals );if _cbbd !=nil {return nil ,_cbbd ;};return &Decoder {_aa :_ac ,_ef :_ff ,_de :parameters },nil ;};func (_ce *Decoder )decodePageImage (_dd int )(_d .Image ,error ){const _dc ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _dd < 0{return nil ,_g .Errorf (_dc ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_dd );};if _dd > int (_ce ._ef .NumberOfPages ){return nil ,_g .Errorf (_dc ,"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",_dd );};_deb ,_ceb :=_ce ._ef .GetPage (_dd );if _ceb !=nil {return nil ,_g .Wrap (_ceb ,_dc ,"");};_cg ,_ceb :=_deb .GetBitmap ();if _ceb !=nil {return nil ,_g .Wrap (_ceb ,_dc ,"");};return _cg .ToImage (),nil ;};
package decoder ;import (_ce "github.com/unidoc/unipdf/v3/internal/bitwise";_cf "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_bd "github.com/unidoc/unipdf/v3/internal/jbig2/document";_b "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_c "image";);type Parameters struct{UnpaddedData bool ;Color _cf .Color ;};func (_ae *Decoder )DecodePageImage (pageNumber int )(_c .Image ,error ){const _cfec ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bf ,_fc :=_ae .decodePageImage (pageNumber );if _fc !=nil {return nil ,_b .Wrap (_fc ,_cfec ,"");};return _bf ,nil ;};func (_d *Decoder )decodePage (_fd int )([]byte ,error ){const _ca ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _fd < 0{return nil ,_b .Errorf (_ca ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_fd );};if _fd > int (_d ._bb .NumberOfPages ){return nil ,_b .Errorf (_ca ,"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",_fd );};_bc ,_ad :=_d ._bb .GetPage (_fd );if _ad !=nil {return nil ,_b .Wrap (_ad ,_ca ,"");};_dd ,_ad :=_bc .GetBitmap ();if _ad !=nil {return nil ,_b .Wrap (_ad ,_ca ,"");};_dd .InverseData ();if !_d ._cfea .UnpaddedData {return _dd .Data ,nil ;};return _dd .GetUnpaddedData ();};func (_ddb *Decoder )decodePageImage (_e int )(_c .Image ,error ){const _aa ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _e < 0{return nil ,_b .Errorf (_aa ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_e );};if _e > int (_ddb ._bb .NumberOfPages ){return nil ,_b .Errorf (_aa ,"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",_e );};_bcb ,_db :=_ddb ._bb .GetPage (_e );if _db !=nil {return nil ,_b .Wrap (_db ,_aa ,"");};_de ,_db :=_bcb .GetBitmap ();if _db !=nil {return nil ,_b .Wrap (_db ,_aa ,"");};return _de .ToImage (),nil ;};func (_g *Decoder )PageNumber ()(int ,error ){const _gd ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _g ._bb ==nil {return 0,_b .Error (_gd ,"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 (_g ._bb .NumberOfPages ),nil ;};type Decoder struct{_f _ce .StreamReader ;_bb *_bd .Document ;_cfe int ;_cfea Parameters ;};func (_fcd *Decoder )DecodeNextPage ()([]byte ,error ){_fcd ._cfe ++;_cb :=_fcd ._cfe ;return _fcd .decodePage (_cb );};func (_af *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _af .decodePage (pageNumber )};func Decode (input []byte ,parameters Parameters ,globals *_bd .Globals )(*Decoder ,error ){_dde :=_ce .NewReader (input );_ef ,_ceg :=_bd .DecodeDocument (_dde ,globals );if _ceg !=nil {return nil ,_ceg ;};return &Decoder {_f :_dde ,_bb :_ef ,_cfea :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 _c "fmt";type processError struct{_d string ;_b string ;_f string ;_bb error ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _ga ,_ec :=err .(*processError );_ec {_ga ._d ="";};_gaf :=_e (_c .Sprintf (message ,arguments ...),processName );_gaf ._bb =err ;return _gaf ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _e (_c .Sprintf (message ,arguments ...),processName );};func Wrap (err error ,processName ,message string )error {if _bc ,_ac :=err .(*processError );_ac {_bc ._d ="";};_ce :=_e (message ,processName );_ce ._bb =err ;return _ce ;};func (_de *processError )Error ()string {var _da string ;if _de ._d !=""{_da =_de ._d ;};_da +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_de ._b ;if _de ._f !=""{_da +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_de ._f ;};if _de ._bb !=nil {_da +="\u002e\u0020"+_de ._bb .Error ();};return _da ;};func Error (processName ,message string )error {return _e (message ,processName )};func _e (_g ,_cf string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_f :_g ,_b :_cf };};
package errors ;import (_c "fmt";_gb "golang.org/x/xerrors";);func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _db ,_ce :=err .(*processError );_ce {_db ._e ="";};_cf :=_fg (_c .Sprintf (message ,arguments ...),processName );_cf ._ee =err ;return _cf ;};func _fg (_cac ,_ge string )*processError {return &processError {_e :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_bd :_cac ,_ca :_ge };};func Error (processName ,message string )error {return _fg (message ,processName )};type processError struct{_e string ;_ca string ;_bd string ;_ee error ;};func Wrap (err error ,processName ,message string )error {if _ea ,_gc :=err .(*processError );_gc {_ea ._e ="";};_a :=_fg (message ,processName );_a ._ee =err ;return _a ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _fg (_c .Sprintf (message ,arguments ...),processName );};func (_f *processError )Unwrap ()error {return _f ._ee };var _ _gb .Wrapper =(*processError )(nil );func (_d *processError )Error ()string {var _ec string ;if _d ._e !=""{_ec =_d ._e ;};_ec +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_d ._ca ;if _d ._bd !=""{_ec +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_d ._bd ;};if _d ._ee !=nil {_ec +="\u002e\u0020"+_d ._ee .Error ();};return _ec ;};

View File

@ -0,0 +1,12 @@
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package internal ;import _a "errors";var ErrOOB =_a .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064");

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";_g "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document";_d "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_gb "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_e "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _db ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_dg :=_b .NewReader (encoded );_af ,_ff :=_c .DecodeDocument (_dg ,nil );if _ff !=nil {return nil ,_gb .Wrap (_ff ,_db ,"");};if _af .GlobalSegments ==nil ||(_af .GlobalSegments .Segments ==nil ){return nil ,_gb .Error (_db ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_ad :=Globals {};for _ ,_bf :=range _af .GlobalSegments .Segments {_ad [int (_bf .SegmentNumber )]=_bf ;};return _ad ,nil ;};func DecodeBytes (encoded []byte ,parameters _g .Parameters ,globals ...Globals )([]byte ,error ){var _a Globals ;if len (globals )> 0{_a =globals [0];};_aa ,_fe :=_g .Decode (encoded ,parameters ,_a .ToDocumentGlobals ());if _fe !=nil {return nil ,_fe ;};return _aa .DecodeNextPage ();};func (_gc Globals )ToDocumentGlobals ()*_c .Globals {if _gc ==nil {return nil ;};_de :=[]*_d .Header {};for _ ,_bg :=range _gc {_de =append (_de ,_bg );};_e .Slice (_de ,func (_ag ,_fdf int )bool {return _de [_ag ].SegmentNumber < _de [_fdf ].SegmentNumber });return &_c .Globals {Segments :_de };};type Globals map[int ]*_d .Header ;
package jbig2 ;import (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_dc "github.com/unidoc/unipdf/v3/internal/jbig2/document";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_ag "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _ac ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_ed :=_b .NewReader (encoded );_de ,_f :=_dc .DecodeDocument (_ed ,nil );if _f !=nil {return nil ,_ag .Wrap (_f ,_ac ,"");};if _de .GlobalSegments ==nil ||(_de .GlobalSegments .Segments ==nil ){return nil ,_ag .Error (_ac ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_fd :=Globals {};for _ ,_dg :=range _de .GlobalSegments .Segments {_fd [int (_dg .SegmentNumber )]=_dg ;};return _fd ,nil ;};func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _e Globals ;if len (globals )> 0{_e =globals [0];};_ee ,_ad :=_d .Decode (encoded ,parameters ,_e .ToDocumentGlobals ());if _ad !=nil {return nil ,_ad ;};return _ee .DecodeNextPage ();};type Globals map[int ]*_c .Header ;func (_bd Globals )ToDocumentGlobals ()*_dc .Globals {if _bd ==nil {return nil ;};_ca :=[]*_c .Header {};for _ ,_def :=range _bd {_ca =append (_ca ,_def );};_a .Slice (_ca ,func (_bc ,_ga int )bool {return _ca [_bc ].SegmentNumber < _ca [_ga ].SegmentNumber });return &_dc .Globals {Segments :_ca };};

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 (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_f "github.com/unidoc/unipdf/v3/internal/imageutil";_b "io";);type Writer struct{_dbc _f .ImageBase ;_ea *_e .Writer ;_cdf ,_fda int ;_beg bool ;};func (_gf *Writer )WriteSample (sample uint32 )error {if _ ,_ead :=_gf ._ea .WriteBits (uint64 (sample ),_gf ._dbc .BitsPerComponent );_ead !=nil {return _ead ;};_gf ._fda --;if _gf ._fda ==0{_gf ._fda =_gf ._dbc .ColorComponents ;_gf ._cdf ++;};if _gf ._cdf ==_gf ._dbc .Width {if _gf ._beg {_gf ._ea .FinishByte ();};_gf ._cdf =0;};return nil ;};func (_fb *Reader )ReadSample ()(uint32 ,error ){if _fb ._cg ==_fb ._g .Height {return 0,_b .EOF ;};_af ,_fa :=_fb ._bg .ReadBits (byte (_fb ._g .BitsPerComponent ));if _fa !=nil {return 0,_fa ;};_fb ._bb --;if _fb ._bb ==0{_fb ._bb =_fb ._g .ColorComponents ;_fb ._be ++;};if _fb ._be ==_fb ._g .Width {if _fb ._gb {_fb ._bg .ConsumeRemainingBits ();};_fb ._be =0;_fb ._cg ++;};return uint32 (_af ),nil ;};type Reader struct{_g _f .ImageBase ;_bg *_e .Reader ;_be ,_cg ,_bb int ;_gb bool ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ce []uint32 ;_ad :=bitsPerSample ;var _fbf uint32 ;var _bd byte ;_eg :=0;_ge :=0;_cge :=0;for _cge < len (data ){if _eg > 0{_d :=_eg ;if _ad < _d {_d =_ad ;};_fbf =(_fbf <<uint (_d ))|uint32 (_bd >>uint (8-_d ));_eg -=_d ;if _eg > 0{_bd =_bd <<uint (_d );}else {_bd =0;};_ad -=_d ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};}else {_ed :=data [_cge ];_cge ++;_ff :=8;if _ad < _ff {_ff =_ad ;};_eg =8-_ff ;_fbf =(_fbf <<uint (_ff ))|uint32 (_ed >>uint (_eg ));if _ff < 8{_bd =_ed <<uint (_ff );};_ad -=_ff ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};};};for _eg >=bitsPerSample {_fab :=_eg ;if _ad < _fab {_fab =_ad ;};_fbf =(_fbf <<uint (_fab ))|uint32 (_bd >>uint (8-_fab ));_eg -=_fab ;if _eg > 0{_bd =_bd <<uint (_fab );}else {_bd =0;};_ad -=_fab ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};};return _ce ;};func (_fad *Reader )ReadSamples (samples []uint32 )(_ba error ){for _cd :=0;_cd < len (samples );_cd ++{samples [_cd ],_ba =_fad .ReadSample ();if _ba !=nil {return _ba ;};};return nil ;};func NewWriter (img _f .ImageBase )*Writer {return &Writer {_ea :_e .NewWriterMSB (img .Data ),_dbc :img ,_fda :img .ColorComponents ,_beg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func NewReader (img _f .ImageBase )*Reader {return &Reader {_bg :_e .NewReader (img .Data ),_g :img ,_bb :img .ColorComponents ,_gb :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _de []uint32 ;_da :=bitsPerOutputSample ;var _bbf uint32 ;var _db uint32 ;_bgg :=0;_cgc :=0;_fd :=0;for _fd < len (data ){if _bgg > 0{_eda :=_bgg ;if _da < _eda {_eda =_da ;};_bbf =(_bbf <<uint (_eda ))|uint32 (_db >>uint (bitsPerInputSample -_eda ));_bgg -=_eda ;if _bgg > 0{_db =_db <<uint (_eda );}else {_db =0;};_da -=_eda ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};}else {_ffe :=data [_fd ];_fd ++;_ede :=bitsPerInputSample ;if _da < _ede {_ede =_da ;};_bgg =bitsPerInputSample -_ede ;_bbf =(_bbf <<uint (_ede ))|uint32 (_ffe >>uint (_bgg ));if _ede < bitsPerInputSample {_db =_ffe <<uint (_ede );};_da -=_ede ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};};};for _bgg >=bitsPerOutputSample {_ef :=_bgg ;if _da < _ef {_ef =_da ;};_bbf =(_bbf <<uint (_ef ))|uint32 (_db >>uint (bitsPerInputSample -_ef ));_bgg -=_ef ;if _bgg > 0{_db =_db <<uint (_ef );}else {_db =0;};_da -=_ef ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};};if _da > 0&&_da < bitsPerOutputSample {_bbf <<=uint (_da );_de =append (_de ,_bbf );};return _de ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_c []uint32 )error ;};func (_cdg *Writer )WriteSamples (samples []uint32 )error {for _fg :=0;_fg < len (samples );_fg ++{if _cb :=_cdg .WriteSample (samples [_fg ]);_cb !=nil {return _cb ;};};return nil ;};type SampleWriter interface{WriteSample (_eff uint32 )error ;WriteSamples (_dbg []uint32 )error ;};
package sampling ;import (_bf "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/imageutil";_b "io";);func NewWriter (img _c .ImageBase )*Writer {return &Writer {_fg :_bf .NewWriterMSB (img .Data ),_acgf :img ,_ced :img .ColorComponents ,_fbd :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_ebe *Reader )ReadSamples (samples []uint32 )(_ef error ){for _cdd :=0;_cdd < len (samples );_cdd ++{samples [_cdd ],_ef =_ebe .ReadSample ();if _ef !=nil {return _ef ;};};return nil ;};type Writer struct{_acgf _c .ImageBase ;_fg *_bf .Writer ;_fb ,_ced int ;_fbd bool ;};func NewReader (img _c .ImageBase )*Reader {return &Reader {_ce :_bf .NewReader (img .Data ),_e :img ,_a :img .ColorComponents ,_de :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_acf *Writer )WriteSamples (samples []uint32 )error {for _dee :=0;_dee < len (samples );_dee ++{if _aac :=_acf .WriteSample (samples [_dee ]);_aac !=nil {return _aac ;};};return nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_d []uint32 )error ;};func (_ac *Reader )ReadSample ()(uint32 ,error ){if _ac ._bc ==_ac ._e .Height {return 0,_b .EOF ;};_cd ,_ea :=_ac ._ce .ReadBits (byte (_ac ._e .BitsPerComponent ));if _ea !=nil {return 0,_ea ;};_ac ._a --;if _ac ._a ==0{_ac ._a =_ac ._e .ColorComponents ;_ac ._eb ++;};if _ac ._eb ==_ac ._e .Width {if _ac ._de {_ac ._ce .ConsumeRemainingBits ();};_ac ._eb =0;_ac ._bc ++;};return uint32 (_cd ),nil ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _gdb []uint32 ;_bd :=bitsPerOutputSample ;var _bca uint32 ;var _bff uint32 ;_eaf :=0;_ge :=0;_gf :=0;for _gf < len (data ){if _eaf > 0{_ed :=_eaf ;if _bd < _ed {_ed =_bd ;};_bca =(_bca <<uint (_ed ))|(_bff >>uint (bitsPerInputSample -_ed ));_eaf -=_ed ;if _eaf > 0{_bff =_bff <<uint (_ed );}else {_bff =0;};_bd -=_ed ;if _bd ==0{_gdb =append (_gdb ,_bca );_bd =bitsPerOutputSample ;_bca =0;_ge ++;};}else {_edg :=data [_gf ];_gf ++;_acg :=bitsPerInputSample ;if _bd < _acg {_acg =_bd ;};_eaf =bitsPerInputSample -_acg ;_bca =(_bca <<uint (_acg ))|(_edg >>uint (_eaf ));if _acg < bitsPerInputSample {_bff =_edg <<uint (_acg );};_bd -=_acg ;if _bd ==0{_gdb =append (_gdb ,_bca );_bd =bitsPerOutputSample ;_bca =0;_ge ++;};};};for _eaf >=bitsPerOutputSample {_bfg :=_eaf ;if _bd < _bfg {_bfg =_bd ;};_bca =(_bca <<uint (_bfg ))|(_bff >>uint (bitsPerInputSample -_bfg ));_eaf -=_bfg ;if _eaf > 0{_bff =_bff <<uint (_bfg );}else {_bff =0;};_bd -=_bfg ;if _bd ==0{_gdb =append (_gdb ,_bca );_bd =bitsPerOutputSample ;_bca =0;_ge ++;};};if _bd > 0&&_bd < bitsPerOutputSample {_bca <<=uint (_bd );_gdb =append (_gdb ,_bca );};return _gdb ;};type Reader struct{_e _c .ImageBase ;_ce *_bf .Reader ;_eb ,_bc ,_a int ;_de bool ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _gc []uint32 ;_da :=bitsPerSample ;var _gd uint32 ;var _f byte ;_ec :=0;_cb :=0;_gcb :=0;for _gcb < len (data ){if _ec > 0{_cdde :=_ec ;if _da < _cdde {_cdde =_da ;};_gd =(_gd <<uint (_cdde ))|uint32 (_f >>uint (8-_cdde ));_ec -=_cdde ;if _ec > 0{_f =_f <<uint (_cdde );}else {_f =0;};_da -=_cdde ;if _da ==0{_gc =append (_gc ,_gd );_da =bitsPerSample ;_gd =0;_cb ++;};}else {_af :=data [_gcb ];_gcb ++;_dae :=8;if _da < _dae {_dae =_da ;};_ec =8-_dae ;_gd =(_gd <<uint (_dae ))|uint32 (_af >>uint (_ec ));if _dae < 8{_f =_af <<uint (_dae );};_da -=_dae ;if _da ==0{_gc =append (_gc ,_gd );_da =bitsPerSample ;_gd =0;_cb ++;};};};for _ec >=bitsPerSample {_aa :=_ec ;if _da < _aa {_aa =_da ;};_gd =(_gd <<uint (_aa ))|uint32 (_f >>uint (8-_aa ));_ec -=_aa ;if _ec > 0{_f =_f <<uint (_aa );}else {_f =0;};_da -=_aa ;if _da ==0{_gc =append (_gc ,_gd );_da =bitsPerSample ;_gd =0;_cb ++;};};return _gc ;};type SampleWriter interface{WriteSample (_ga uint32 )error ;WriteSamples (_fd []uint32 )error ;};func (_ecg *Writer )WriteSample (sample uint32 )error {if _ ,_afa :=_ecg ._fg .WriteBits (uint64 (sample ),_ecg ._acgf .BitsPerComponent );_afa !=nil {return _afa ;};_ecg ._ced --;if _ecg ._ced ==0{_ecg ._ced =_ecg ._acgf .ColorComponents ;_ecg ._fb ++;};if _ecg ._fb ==_ecg ._acgf .Width {if _ecg ._fbd {_ecg ._fg .FinishByte ();};_ecg ._fb =0;};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

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,26 +10,10 @@
// 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 (_f "bytes";_gd "crypto";_ge "crypto/rand";_fd "crypto/rsa";_ddb "crypto/x509";_de "crypto/x509/pkix";_b "encoding/asn1";_ddf "errors";_gdg "fmt";_gg "github.com/unidoc/pkcs7";_bg "github.com/unidoc/timestamp";_fce "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";_dd "hash";_a "io";_c "io/ioutil";_g "net/http";_fc "time";);
package sighandler ;import (_e "bytes";_fe "crypto";_ad "crypto/rand";_fg "crypto/rsa";_dc "crypto/x509";_fa "crypto/x509/pkix";_dg "encoding/asn1";_de "errors";_g "fmt";_c "github.com/unidoc/pkcs7";_edb "github.com/unidoc/timestamp";_b "github.com/unidoc/unipdf/v3/core";_cg "github.com/unidoc/unipdf/v3/model";_a "hash";_ed "io";_f "io/ioutil";_dd "net/http";_eb "time";);
// 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 *_fd .PrivateKey ,certificate *_ddb .Certificate )(_e .SignatureHandler ,error ){return &adobePKCS7Detached {_fg :certificate ,_fe :privateKey },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_ebb *adobeX509RSASHA1 )IsApplicable (sig *_e .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 (_dc *adobePKCS7Detached )getCertificate (_cf *_e .PdfSignature )(*_ddb .Certificate ,error ){if _dc ._fg !=nil {return _dc ._fg ,nil ;};var _fa []byte ;switch _bb :=_cf .Cert .(type ){case *_fce .PdfObjectString :_fa =_bb .Bytes ();case *_fce .PdfObjectArray :if _bb .Len ()==0{return nil ,_ddf .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 _ ,_be :=range _bb .Elements (){_bde ,_bf :=_fce .GetString (_be );if !_bf {return nil ,_gdg .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",_be );};_fa =append (_fa ,_bde .Bytes ()...);};default:return nil ,_gdg .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",_bb );};_ggb ,_fb :=_ddb .ParseCertificates (_fa );if _fb !=nil {return nil ,_fb ;};return _ggb [0],nil ;};
// Sign sets the Contents fields.
func (_ef *adobePKCS7Detached )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {if _ef ._gdgd {_dcc :=_ef ._fdc ;if _dcc <=0{_dcc =8192;};sig .Contents =_fce .MakeHexString (string (make ([]byte ,_dcc )));return nil ;};_ded :=digest .(*_f .Buffer );_ab ,_ggbd :=_gg .NewSignedData (_ded .Bytes ());if _ggbd !=nil {return _ggbd ;};if _ae :=_ab .AddSigner (_ef ._fg ,_ef ._fe ,_gg .SignerInfoConfig {});_ae !=nil {return _ae ;};_ab .Detach ();_fed ,_ggbd :=_ab .Finish ();if _ggbd !=nil {return _ggbd ;};_bdf :=make ([]byte ,8192);copy (_bdf ,_fed );sig .Contents =_fce .MakeHexString (string (_bdf ));return nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_efe *docTimeStamp )IsApplicable (sig *_e .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";};
// NewDigest creates a new digest.
func (_eb *adobePKCS7Detached )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};
// InitSignature initialises the PdfSignature.
func (_gacg *docTimeStamp )InitSignature (sig *_e .PdfSignature )error {_dfc :=*_gacg ;sig .Handler =&_dfc ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _gacg ._da > 0{sig .Contents =_fce .MakeHexString (string (make ([]byte ,_gacg ._da )));}else {_bbb ,_fae :=_gacg .NewDigest (sig );if _fae !=nil {return _fae ;};_bbb .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"));if _fae =_dfc .Sign (sig ,_bbb );_fae !=nil {return _fae ;};_gacg ._da =_dfc ._da ;};return nil ;};type adobeX509RSASHA1 struct{_gf *_fd .PrivateKey ;_gdgdb *_ddb .Certificate ;_fad SignFunc ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_fbd *adobePKCS7Detached )IsApplicable (sig *_cg .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";};
// DocTimeStampOpts defines options for configuring the timestamp handler.
type DocTimeStampOpts struct{
@ -41,32 +25,39 @@ type DocTimeStampOpts struct{
// signature.
SignatureSize int ;};
// InitSignature initialises the PdfSignature.
func (_ec *adobePKCS7Detached )InitSignature (sig *_cg .PdfSignature )error {if !_ec ._dgc {if _ec ._ga ==nil {return _de .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 _ec ._fgf ==nil {return _de .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");};};_ff :=*_ec ;sig .Handler =&_ff ;sig .Filter =_b .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_b .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_cgb ,_ef :=_ff .NewDigest (sig );if _ef !=nil {return _ef ;};_cgb .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 _ff .Sign (sig ,_cgb );};func (_dee *adobePKCS7Detached )getCertificate (_gd *_cg .PdfSignature )(*_dc .Certificate ,error ){if _dee ._ga !=nil {return _dee ._ga ,nil ;};_eca ,_gag :=_gd .GetCerts ();if _gag !=nil {return nil ,_gag ;};return _eca [0],nil ;};
// Validate validates PdfSignature.
func (_gee *docTimeStamp )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_dad :=sig .Contents .Bytes ();_ebdbb ,_def :=_gg .Parse (_dad );if _def !=nil {return _e .SignatureValidationResult {},_def ;};if _def =_ebdbb .Verify ();_def !=nil {return _e .SignatureValidationResult {},_def ;};var _cb timestampInfo ;_ ,_def =_b .Unmarshal (_ebdbb .Content ,&_cb );if _def !=nil {return _e .SignatureValidationResult {},_def ;};_ebf ,_def :=_db (_cb .MessageImprint .HashAlgorithm .Algorithm );if _def !=nil {return _e .SignatureValidationResult {},_def ;};_cca :=_ebf .New ();_dgd :=digest .(*_f .Buffer );_cca .Write (_dgd .Bytes ());_ccf :=_cca .Sum (nil );_bge :=_e .SignatureValidationResult {IsSigned :true ,IsVerified :_f .Equal (_ccf ,_cb .MessageImprint .HashedMessage ),GeneralizedTime :_cb .GeneralizedTime };return _bge ,nil ;};func _db (_aed _b .ObjectIdentifier )(_gd .Hash ,error ){switch {case _aed .Equal (_gg .OIDDigestAlgorithmSHA1 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA1 ),_aed .Equal (_gg .OIDDigestAlgorithmDSA ),_aed .Equal (_gg .OIDDigestAlgorithmDSASHA1 ),_aed .Equal (_gg .OIDEncryptionAlgorithmRSA ):return _gd .SHA1 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA256 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA256 ):return _gd .SHA256 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA384 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA384 ):return _gd .SHA384 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA512 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA512 ):return _gd .SHA512 ,nil ;};return _gd .Hash (0),_gg .ErrUnsupportedAlgorithm ;};type timestampInfo struct{Version int ;Policy _b .RawValue ;MessageImprint struct{HashAlgorithm _de .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _b .RawValue ;GeneralizedTime _fc .Time ;};
func (_cff *adobeX509RSASHA1 )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_fed ,_ea :=_cff .getCertificate (sig );if _ea !=nil {return _cg .SignatureValidationResult {},_ea ;};_edbg :=sig .Contents .Bytes ();var _gfa []byte ;if _ ,_ffd :=_dg .Unmarshal (_edbg ,&_gfa );_ffd !=nil {return _cg .SignatureValidationResult {},_ffd ;};_bde ,_efb :=digest .(_a .Hash );if !_efb {return _cg .SignatureValidationResult {},_de .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_aca ,_ :=_fgb (_fed .SignatureAlgorithm );if _ca :=_fg .VerifyPKCS1v15 (_fed .PublicKey .(*_fg .PublicKey ),_aca ,_bde .Sum (nil ),_gfa );_ca !=nil {return _cg .SignatureValidationResult {},_ca ;};return _cg .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// NewDigest creates a new digest.
func (_bee *docTimeStamp )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};
func (_gf *adobePKCS7Detached )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){return _e .NewBuffer (nil ),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 *_ddb .Certificate ,signFunc SignFunc )(_e .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gdgdb :certificate ,_fad :signFunc },nil ;};
// AdobeX509RSASHA1Opts defines options for configuring the adbe.x509.rsa_sha1
// signature handler.
type AdobeX509RSASHA1Opts struct{
// EstimateSize specifies whether the size of the signature contents
// should be estimated based on the modulus size of the public key
// extracted from the signing certificate. If set to false, a mock Sign
// call is made in order to estimate the size of the signature contents.
EstimateSize bool ;};
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
// specified options. If no options are provided, default options will be used.
// Both the timestamp server URL and the hash algorithm can be empty for the
// signature validation.
// The following hash algorithms are supported:
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _fe .Hash ,opts *DocTimeStampOpts )(_cg .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_abe :timestampServerURL ,_cb :hashAlgorithm ,_bf :opts .SignatureSize },nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_dfg *_e .PdfSignature ,_ddc _e .Hasher )([]byte ,error );
type SignFunc func (_cd *_cg .PdfSignature ,_af _cg .Hasher )([]byte ,error );type adobePKCS7Detached struct{_fgf *_fg .PrivateKey ;_ga *_dc .Certificate ;_dgc bool ;_db int ;};
// InitSignature initialises the PdfSignature.
func (_fee *adobeX509RSASHA1 )InitSignature (sig *_e .PdfSignature )error {if _fee ._gdgdb ==nil {return _ddf .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 _fee ._gf ==nil &&_fee ._fad ==nil {return _ddf .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");};_ebd :=*_fee ;sig .Handler =&_ebd ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_fce .MakeString (string (_ebd ._gdgdb .Raw ));sig .Reference =nil ;_ga ,_faa :=_ebd .NewDigest (sig );if _faa !=nil {return _faa ;};_ga .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 _ebd .Sign (sig ,_ga );};
// Sign sets the Contents fields for the PdfSignature.
func (_acg *docTimeStamp )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {_adf :=digest .(*_f .Buffer );_gacd :=_acg ._ffg .New ();if _ ,_fde :=_a .Copy (_gacd ,_adf );_fde !=nil {return _fde ;};_cdc :=_bg .Request {HashAlgorithm :_acg ._ffg ,HashedMessage :_gacd .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_ggfg ,_feg :=_cdc .Marshal ();if _feg !=nil {return _feg ;};_agg ,_feg :=_g .Post (_acg ._cd ,"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 (_ggfg ));if _feg !=nil {return _feg ;};defer _agg .Body .Close ();_ffae ,_feg :=_c .ReadAll (_agg .Body );if _feg !=nil {return _feg ;};if _agg .StatusCode !=_g .StatusOK {return _gdg .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",_agg .StatusCode );};var _gff struct{Version _b .RawValue ;Content _b .RawValue ;};if _ ,_feg =_b .Unmarshal (_ffae ,&_gff );_feg !=nil {return _feg ;};_afc :=len (_gff .Content .FullBytes );if _acg ._da > 0&&_afc > _acg ._da {return _e .ErrSignNotEnoughSpace ;};if _afc > 0{_acg ._da =_afc +128;};sig .Contents =_fce .MakeHexString (string (_gff .Content .FullBytes ));return nil ;};func (_aa *adobeX509RSASHA1 )getCertificate (_gac *_e .PdfSignature )(*_ddb .Certificate ,error ){if _aa ._gdgdb !=nil {return _aa ._gdgdb ,nil ;};var _gfg []byte ;switch _cfc :=_gac .Cert .(type ){case *_fce .PdfObjectString :_gfg =_cfc .Bytes ();case *_fce .PdfObjectArray :if _cfc .Len ()==0{return nil ,_ddf .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 _ ,_efb :=range _cfc .Elements (){_gace ,_gec :=_fce .GetString (_efb );if !_gec {return nil ,_gdg .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",_efb );};_gfg =append (_gfg ,_gace .Bytes ()...);};default:return nil ,_gdg .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",_cfc );};_ad ,_ce :=_ddb .ParseCertificates (_gfg );if _ce !=nil {return nil ,_ce ;};return _ad [0],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 *_fd .PrivateKey ,certificate *_ddb .Certificate )(_e .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gdgdb :certificate ,_gf :privateKey },nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_ggf *adobeX509RSASHA1 )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {var _ebdb []byte ;var _ba error ;if _ggf ._fad !=nil {_ebdb ,_ba =_ggf ._fad (sig ,digest );if _ba !=nil {return _ba ;};}else {_fbe ,_afa :=digest .(_dd .Hash );if !_afa {return _ddf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_dg ,_ :=_aca (_ggf ._gdgdb .SignatureAlgorithm );_ebdb ,_ba =_fd .SignPKCS1v15 (_ge .Reader ,_ggf ._gf ,_dg ,_fbe .Sum (nil ));if _ba !=nil {return _ba ;};};_ebdb ,_ba =_b .Marshal (_ebdb );if _ba !=nil {return _ba ;};sig .Contents =_fce .MakeHexString (string (_ebdb ));return nil ;};type docTimeStamp struct{_cd string ;_ffg _gd .Hash ;_da int ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_fggg *docTimeStamp )IsApplicable (sig *_cg .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";};type docTimeStamp struct{_abe string ;_cb _fe .Hash ;_bf int ;};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// Both the timestamp server URL and the hash algorithm can be empty for the
@ -76,32 +67,63 @@ func (_ggf *adobeX509RSASHA1 )Sign (sig *_e .PdfSignature ,digest _e .Hasher )er
// NOTE: the handler will do a mock Sign when initializing the signature
// in order to estimate the signature size. Use NewDocTimeStampWithOpts
// for providing the signature size.
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _gd .Hash )(_e .SignatureHandler ,error ){return &docTimeStamp {_cd :timestampServerURL ,_ffg :hashAlgorithm },nil ;};
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _fe .Hash )(_cg .SignatureHandler ,error ){return &docTimeStamp {_abe :timestampServerURL ,_cb :hashAlgorithm },nil ;};
// Validate validates PdfSignature.
func (_ff *adobePKCS7Detached )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_df :=sig .Contents .Bytes ();_ea ,_ee :=_gg .Parse (_df );if _ee !=nil {return _e .SignatureValidationResult {},_ee ;};_bdg :=digest .(*_f .Buffer );_ea .Content =_bdg .Bytes ();if _ee =_ea .Verify ();_ee !=nil {return _e .SignatureValidationResult {},_ee ;};return _e .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
func (_fef *adobePKCS7Detached )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_ade :=sig .Contents .Bytes ();_fb ,_gb :=_c .Parse (_ade );if _gb !=nil {return _cg .SignatureValidationResult {},_gb ;};_gfe :=digest .(*_e .Buffer );_fb .Content =_gfe .Bytes ();if _gb =_fb .Verify ();_gb !=nil {return _cg .SignatureValidationResult {},_gb ;};return _cg .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// Validate validates PdfSignature.
func (_dge *docTimeStamp )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_fgg :=sig .Contents .Bytes ();_eae ,_gfc :=_c .Parse (_fgg );if _gfc !=nil {return _cg .SignatureValidationResult {},_gfc ;};if _gfc =_eae .Verify ();_gfc !=nil {return _cg .SignatureValidationResult {},_gfc ;};var _ag timestampInfo ;_ ,_gfc =_dg .Unmarshal (_eae .Content ,&_ag );if _gfc !=nil {return _cg .SignatureValidationResult {},_gfc ;};_bfa ,_gfc :=_ecb (_ag .MessageImprint .HashAlgorithm .Algorithm );if _gfc !=nil {return _cg .SignatureValidationResult {},_gfc ;};_gbb :=_bfa .New ();_afce :=digest .(*_e .Buffer );_gbb .Write (_afce .Bytes ());_fbdg :=_gbb .Sum (nil );_cee :=_cg .SignatureValidationResult {IsSigned :true ,IsVerified :_e .Equal (_fbdg ,_ag .MessageImprint .HashedMessage ),GeneralizedTime :_ag .GeneralizedTime };return _cee ,nil ;};
// NewAdobeX509RSASHA1CustomWithOpts creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler with a custom signing function. The
// handler is configured based on the provided options. If no options are
// provided, default options will be used. Both the certificate and the sign
// function can be nil for the signature validation.
func NewAdobeX509RSASHA1CustomWithOpts (certificate *_dc .Certificate ,signFunc SignFunc ,opts *AdobeX509RSASHA1Opts )(_cg .SignatureHandler ,error ){if opts ==nil {opts =&AdobeX509RSASHA1Opts {};};return &adobeX509RSASHA1 {_fd :certificate ,_afc :signFunc ,_gdb :opts .EstimateSize },nil ;};type timestampInfo struct{Version int ;Policy _dg .RawValue ;MessageImprint struct{HashAlgorithm _fa .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _dg .RawValue ;GeneralizedTime _eb .Time ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_ffa *adobeX509RSASHA1 )IsApplicable (sig *_cg .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";};type adobeX509RSASHA1 struct{_gdc *_fg .PrivateKey ;_fd *_dc .Certificate ;_afc SignFunc ;_gdb bool ;};
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler with a custom signing function. Both the
// certificate and the sign function can be nil for the signature validation.
// NOTE: the handler will do a mock Sign when initializing the signature in
// order to estimate the signature size. Use NewAdobeX509RSASHA1CustomWithOpts
// for configuring the handler to estimate the signature size.
func NewAdobeX509RSASHA1Custom (certificate *_dc .Certificate ,signFunc SignFunc )(_cg .SignatureHandler ,error ){return &adobeX509RSASHA1 {_fd :certificate ,_afc :signFunc },nil ;};
// 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 *_fg .PrivateKey ,certificate *_dc .Certificate )(_cg .SignatureHandler ,error ){return &adobePKCS7Detached {_ga :certificate ,_fgf :privateKey },nil ;};func (_gce *adobeX509RSASHA1 )getCertificate (_df *_cg .PdfSignature )(*_dc .Certificate ,error ){if _gce ._fd !=nil {return _gce ._fd ,nil ;};_dec ,_cda :=_df .GetCerts ();if _cda !=nil {return nil ,_cda ;};return _dec [0],nil ;};
// NewDigest creates a new digest.
func (_bd *adobeX509RSASHA1 )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){_bcg ,_ac :=_bd .getCertificate (sig );if _ac !=nil {return nil ,_ac ;};_ffg ,_ :=_fgb (_bcg .SignatureAlgorithm );return _ffg .New (),nil ;};
// InitSignature initialises the PdfSignature.
func (_ffae *docTimeStamp )InitSignature (sig *_cg .PdfSignature )error {_fgc :=*_ffae ;sig .Handler =&_fgc ;sig .Filter =_b .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_b .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _ffae ._bf > 0{sig .Contents =_b .MakeHexString (string (make ([]byte ,_ffae ._bf )));}else {_fefa ,_fcda :=_ffae .NewDigest (sig );if _fcda !=nil {return _fcda ;};_fefa .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"));if _fcda =_fgc .Sign (sig ,_fefa );_fcda !=nil {return _fcda ;};_ffae ._bf =_fgc ._bf ;};return nil ;};func _ecb (_eaf _dg .ObjectIdentifier )(_fe .Hash ,error ){switch {case _eaf .Equal (_c .OIDDigestAlgorithmSHA1 ),_eaf .Equal (_c .OIDDigestAlgorithmECDSASHA1 ),_eaf .Equal (_c .OIDDigestAlgorithmDSA ),_eaf .Equal (_c .OIDDigestAlgorithmDSASHA1 ),_eaf .Equal (_c .OIDEncryptionAlgorithmRSA ):return _fe .SHA1 ,nil ;case _eaf .Equal (_c .OIDDigestAlgorithmSHA256 ),_eaf .Equal (_c .OIDDigestAlgorithmECDSASHA256 ):return _fe .SHA256 ,nil ;case _eaf .Equal (_c .OIDDigestAlgorithmSHA384 ),_eaf .Equal (_c .OIDDigestAlgorithmECDSASHA384 ):return _fe .SHA384 ,nil ;case _eaf .Equal (_c .OIDDigestAlgorithmSHA512 ),_eaf .Equal (_c .OIDDigestAlgorithmECDSASHA512 ):return _fe .SHA512 ,nil ;};return _fe .Hash (0),_c .ErrUnsupportedAlgorithm ;};
// InitSignature initialises the PdfSignature.
func (_cc *adobeX509RSASHA1 )InitSignature (sig *_cg .PdfSignature )error {if _cc ._fd ==nil {return _de .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 _cc ._gdc ==nil &&_cc ._afc ==nil {return _de .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");};_eg :=*_cc ;sig .Handler =&_eg ;sig .Filter =_b .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_b .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_b .MakeString (string (_eg ._fd .Raw ));sig .Reference =nil ;_cf ,_abg :=_eg .NewDigest (sig );if _abg !=nil {return _abg ;};_cf .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 _eg .sign (sig ,_cf ,_cc ._gdb );};
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler. Both the private key and the
// certificate can be nil for the signature validation.
func NewAdobeX509RSASHA1 (privateKey *_fg .PrivateKey ,certificate *_dc .Certificate )(_cg .SignatureHandler ,error ){return &adobeX509RSASHA1 {_fd :certificate ,_gdc :privateKey },nil ;};
// NewDigest creates a new digest.
func (_cfc *docTimeStamp )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){return _e .NewBuffer (nil ),nil ;};
// Sign sets the Contents fields.
func (_ab *adobePKCS7Detached )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {if _ab ._dgc {_ge :=_ab ._db ;if _ge <=0{_ge =8192;};sig .Contents =_b .MakeHexString (string (make ([]byte ,_ge )));return nil ;};_dea :=digest .(*_e .Buffer );_bc ,_efg :=_c .NewSignedData (_dea .Bytes ());if _efg !=nil {return _efg ;};if _dga :=_bc .AddSigner (_ab ._ga ,_ab ._fgf ,_c .SignerInfoConfig {});_dga !=nil {return _dga ;};_bc .Detach ();_gdf ,_efg :=_bc .Finish ();if _efg !=nil {return _efg ;};_ba :=make ([]byte ,8192);copy (_ba ,_gdf );sig .Contents =_b .MakeHexString (string (_ba ));return 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 )(_e .SignatureHandler ,error ){return &adobePKCS7Detached {_gdgd :true ,_fdc :signatureLen },nil ;};
func NewEmptyAdobePKCS7Detached (signatureLen int )(_cg .SignatureHandler ,error ){return &adobePKCS7Detached {_dgc :true ,_db :signatureLen },nil ;};func (_bcgc *adobeX509RSASHA1 )sign (_gdd *_cg .PdfSignature ,_gff _cg .Hasher ,_gac bool )error {if !_gac {return _bcgc .Sign (_gdd ,_gff );};_ce ,_ebg :=_bcgc ._fd .PublicKey .(*_fg .PublicKey );if !_ebg {return _g .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u006b\u0065y\u0020\u0074\u0079p\u0065:\u0020\u0025\u0054",_ce );};_bce ,_gcd :=_dg .Marshal (make ([]byte ,_ce .Size ()));if _gcd !=nil {return _gcd ;};_gdd .Contents =_b .MakeHexString (string (_bce ));return nil ;};
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
// specified options. If no options are provided, default options will be used.
// Both the timestamp server URL and the hash algorithm can be empty for the
// signature validation.
// The following hash algorithms are supported:
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _gd .Hash ,opts *DocTimeStampOpts )(_e .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_cd :timestampServerURL ,_ffg :hashAlgorithm ,_da :opts .SignatureSize },nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_dbe *adobeX509RSASHA1 )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {var _bb []byte ;var _fc error ;if _dbe ._afc !=nil {_bb ,_fc =_dbe ._afc (sig ,digest );if _fc !=nil {return _fc ;};}else {_caa ,_gcc :=digest .(_a .Hash );if !_gcc {return _de .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_fdg ,_ :=_fgb (_dbe ._fd .SignatureAlgorithm );_bb ,_fc =_fg .SignPKCS1v15 (_ad .Reader ,_dbe ._gdc ,_fdg ,_caa .Sum (nil ));if _fc !=nil {return _fc ;};};_bb ,_fc =_dg .Marshal (_bb );if _fc !=nil {return _fc ;};sig .Contents =_b .MakeHexString (string (_bb ));return nil ;};
// InitSignature initialises the PdfSignature.
func (_bd *adobePKCS7Detached )InitSignature (sig *_e .PdfSignature )error {if !_bd ._gdgd {if _bd ._fg ==nil {return _ddf .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 _bd ._fe ==nil {return _ddf .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");};};_cg :=*_bd ;sig .Handler =&_cg ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_ac ,_cge :=_cg .NewDigest (sig );if _cge !=nil {return _cge ;};_ac .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 _cg .Sign (sig ,_ac );};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_dcg *adobePKCS7Detached )IsApplicable (sig *_e .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";};
// Validate validates PdfSignature.
func (_cc *adobeX509RSASHA1 )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_af ,_eg :=_cc .getCertificate (sig );if _eg !=nil {return _e .SignatureValidationResult {},_eg ;};_fdcb :=sig .Contents .Bytes ();var _fgg []byte ;if _ ,_ffa :=_b .Unmarshal (_fdcb ,&_fgg );_ffa !=nil {return _e .SignatureValidationResult {},_ffa ;};_bca ,_fcg :=digest .(_dd .Hash );if !_fcg {return _e .SignatureValidationResult {},_ddf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_eaa ,_ :=_aca (_af .SignatureAlgorithm );if _gc :=_fd .VerifyPKCS1v15 (_af .PublicKey .(*_fd .PublicKey ),_eaa ,_bca .Sum (nil ),_fgg );_gc !=nil {return _e .SignatureValidationResult {},_gc ;};return _e .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};type adobePKCS7Detached struct{_fe *_fd .PrivateKey ;_fg *_ddb .Certificate ;_gdgd bool ;_fdc int ;};func _aca (_beb _ddb .SignatureAlgorithm )(_gd .Hash ,bool ){var _ca _gd .Hash ;switch _beb {case _ddb .SHA1WithRSA :_ca =_gd .SHA1 ;case _ddb .SHA256WithRSA :_ca =_gd .SHA256 ;case _ddb .SHA384WithRSA :_ca =_gd .SHA384 ;case _ddb .SHA512WithRSA :_ca =_gd .SHA512 ;default:return _gd .SHA1 ,false ;};return _ca ,true ;};
// NewDigest creates a new digest.
func (_aad *adobeX509RSASHA1 )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){_gab ,_gdf :=_aad .getCertificate (sig );if _gdf !=nil {return nil ,_gdf ;};_fff ,_ :=_aca (_gab .SignatureAlgorithm );return _fff .New (),nil ;};func (_daa *docTimeStamp )getCertificate (_ag *_e .PdfSignature )(*_ddb .Certificate ,error ){var _dfa []byte ;switch _bfg :=_ag .Cert .(type ){case *_fce .PdfObjectString :_dfa =_bfg .Bytes ();case *_fce .PdfObjectArray :if _bfg .Len ()==0{return nil ,_ddf .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 _ ,_bba :=range _bfg .Elements (){_agb ,_fab :=_fce .GetString (_bba );if !_fab {return nil ,_gdg .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",_bba );};_dfa =append (_dfa ,_agb .Bytes ()...);};default:return nil ,_gdg .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",_bfg );};_afe ,_ddcb :=_ddb .ParseCertificates (_dfa );if _ddcb !=nil {return nil ,_ddcb ;};return _afe [0],nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_gef *docTimeStamp )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {_efbf :=digest .(*_e .Buffer );_aeg :=_gef ._cb .New ();if _ ,_aba :=_ed .Copy (_aeg ,_efbf );_aba !=nil {return _aba ;};_cbe :=_edb .Request {HashAlgorithm :_gef ._cb ,HashedMessage :_aeg .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_dgg ,_cbg :=_cbe .Marshal ();if _cbg !=nil {return _cbg ;};_acc ,_cbg :=_dd .Post (_gef ._abe ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_e .NewBuffer (_dgg ));if _cbg !=nil {return _cbg ;};defer _acc .Body .Close ();_cdg ,_cbg :=_f .ReadAll (_acc .Body );if _cbg !=nil {return _cbg ;};if _acc .StatusCode !=_dd .StatusOK {return _g .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",_acc .StatusCode );};var _deeb struct{Version _dg .RawValue ;Content _dg .RawValue ;};if _ ,_cbg =_dg .Unmarshal (_cdg ,&_deeb );_cbg !=nil {return _cbg ;};_aed :=len (_deeb .Content .FullBytes );if _gef ._bf > 0&&_aed > _gef ._bf {return _cg .ErrSignNotEnoughSpace ;};if _aed > 0{_gef ._bf =_aed +128;};sig .Contents =_b .MakeHexString (string (_deeb .Content .FullBytes ));return nil ;};func (_bfg *docTimeStamp )getCertificate (_ece *_cg .PdfSignature )(*_dc .Certificate ,error ){_fgd ,_ede :=_ece .GetCerts ();if _ede !=nil {return nil ,_ede ;};return _fgd [0],nil ;};func _fgb (_ae _dc .SignatureAlgorithm )(_fe .Hash ,bool ){var _gc _fe .Hash ;switch _ae {case _dc .SHA1WithRSA :_gc =_fe .SHA1 ;case _dc .SHA256WithRSA :_gc =_fe .SHA256 ;case _dc .SHA384WithRSA :_gc =_fe .SHA384 ;case _dc .SHA512WithRSA :_gc =_fe .SHA512 ;default:return _fe .SHA1 ,false ;};return _gc ,true ;};

67
model/sigutil/sigutil.go Normal file
View File

@ -0,0 +1,67 @@
//
// Copyright 2020 FoxyUtils ehf. All rights reserved.
//
// This is a commercial product and requires a license to operate.
// A trial license can be obtained at https://unidoc.io
//
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
//
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package sigutil ;import (_e "bytes";_d "crypto";_fg "crypto/x509";_bb "encoding/pem";_f "errors";_gf "fmt";_ba "github.com/unidoc/unipdf/v3/common";_cb "golang.org/x/crypto/ocsp";_c "io/ioutil";_fa "net/http";_g "time";);
// NewCertClient returns a new certificate client.
func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_ddd ()}};
// IsCA returns true if the provided certificate appears to be a CA certificate.
func (_eff *CertClient )IsCA (cert *_fg .Certificate )bool {return cert .IsCA &&_e .Equal (cert .RawIssuer ,cert .RawSubject );};
// OCSPClient represents a OCSP (Online Certificate Status Protocol) client.
// It is used to request revocation data from OCSP servers.
type OCSPClient struct{
// HTTPClient is the HTTP client used to make OCSP requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_fa .Client ;
// Hash is the hash function used when constructing the OCSP
// requests. If zero, SHA-1 will be used.
Hash _d .Hash ;};
// MakeRequest makes a CRL request to the specified server and returns the
// response. If a server URL is not provided, it is extracted from the certificate.
func (_fda *CRLClient )MakeRequest (serverURL string ,cert *_fg .Certificate )([]byte ,error ){if _fda .HTTPClient ==nil {_fda .HTTPClient =_ddd ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_f .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063\u0061t\u0065\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0070ec\u0069\u0066\u0079 \u0061\u006ey\u0020\u0043\u0052\u004c\u0020\u0073e\u0072\u0076e\u0072\u0073");};serverURL =cert .CRLDistributionPoints [0];};_aca ,_ddc :=_fda .HTTPClient .Get (serverURL );if _ddc !=nil {return nil ,_ddc ;};defer _aca .Body .Close ();_efe ,_ddc :=_c .ReadAll (_aca .Body );if _ddc !=nil {return nil ,_ddc ;};if _efc ,_ :=_bb .Decode (_efe );_efc !=nil {_efe =_efc .Bytes ;};return _efe ,nil ;};
// NewOCSPClient returns a new OCSP client.
func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_ddd (),Hash :_d .SHA1 }};func _ddd ()*_fa .Client {return &_fa .Client {Timeout :5*_g .Second }};
// Get retrieves the certificate at the specified URL.
func (_gb *CertClient )Get (url string )(*_fg .Certificate ,error ){if _gb .HTTPClient ==nil {_gb .HTTPClient =_ddd ();};_db ,_a :=_gb .HTTPClient .Get (url );if _a !=nil {return nil ,_a ;};defer _db .Body .Close ();_ac ,_a :=_c .ReadAll (_db .Body );if _a !=nil {return nil ,_a ;};if _fd ,_ :=_bb .Decode (_ac );_fd !=nil {_ac =_fd .Bytes ;};_dda ,_a :=_fg .ParseCertificate (_ac );if _a !=nil {return nil ,_a ;};return _dda ,nil ;};
// CertClient represents a X.509 certificate client. Its primary purpose
// is to download certificates.
type CertClient struct{
// HTTPClient is the HTTP client used to make certificate requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_fa .Client ;};
// NewCRLClient returns a new CRL client.
func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_ddd ()}};
// GetIssuer retrieves the issuer of the provided certificate.
func (_fb *CertClient )GetIssuer (cert *_fg .Certificate )(*_fg .Certificate ,error ){for _ ,_ge :=range cert .IssuingCertificateURL {_fc ,_ab :=_fb .Get (_ge );if _ab !=nil {_ba .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074 \u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u0020\u0069\u0073\u0073\u0075e\u0072\u0020\u0066\u006f\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066ic\u0061\u0074\u0065\u0020\u0025\u0076\u003a\u0020\u0025\u0076",cert .Subject .CommonName ,_ab );continue ;};return _fc ,nil ;};return nil ,_gf .Errorf ("\u0069\u0073\u0073\u0075e\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063a\u0074e\u0020\u006e\u006f\u0074\u0020\u0066\u006fu\u006e\u0064");};
// MakeRequest makes a OCSP request to the specified server and returns
// the parsed and raw responses. If a server URL is not provided, it is
// extracted from the certificate.
func (_gee *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_fg .Certificate )(*_cb .Response ,[]byte ,error ){if _gee .HTTPClient ==nil {_gee .HTTPClient =_ddd ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_f .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063a\u0074\u0065\u0020\u0064\u006f\u0065\u0073 \u006e\u006f\u0074\u0020\u0073\u0070e\u0063\u0069\u0066\u0079\u0020\u0061\u006e\u0079\u0020\u004f\u0043S\u0050\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0073");};serverURL =cert .OCSPServer [0];};_ff ,_dbf :=_cb .CreateRequest (cert ,issuer ,&_cb .RequestOptions {Hash :_gee .Hash });if _dbf !=nil {return nil ,nil ,_dbf ;};_fbc ,_dbf :=_gee .HTTPClient .Post (serverURL ,"\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u006fc\u0073\u0070\u002d\u0072\u0065\u0071\u0075\u0065\u0073\u0074",_e .NewReader (_ff ));if _dbf !=nil {return nil ,nil ,_dbf ;};defer _fbc .Body .Close ();_gg ,_dbf :=_c .ReadAll (_fbc .Body );if _dbf !=nil {return nil ,nil ,_dbf ;};if _fbf ,_ :=_bb .Decode (_gg );_fbf !=nil {_gg =_fbf .Bytes ;};_cg ,_dbf :=_cb .ParseResponseForCert (_gg ,cert ,issuer );if _dbf !=nil {return nil ,nil ,_dbf ;};return _cg ,_gg ,nil ;};
// CRLClient represents a CRL (Certificate revocation list) client.
// It is used to request revocation data from CRL servers.
type CRLClient struct{
// HTTPClient is the HTTP client used to make CRL requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_fa .Client ;};

View File

@ -9,7 +9,7 @@
// 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 pdfutil ;import (_ef "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/contentstream";_bd "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/model";);
package pdfutil ;import (_ef "github.com/unidoc/unipdf/v3/common";_gb "github.com/unidoc/unipdf/v3/contentstream";_g "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_ec "github.com/unidoc/unipdf/v3/model";);
// NormalizePage performs the following operations on the passed in page:
// - Normalize the page rotation.
@ -26,4 +26,4 @@ package pdfutil ;import (_ef "github.com/unidoc/unipdf/v3/common";_ec "github.co
// PDF viewer.
// NOTE: This function does not normalize annotations, outlines other parts
// that are not part of the basic geometry and page content streams.
func NormalizePage (page *_b .PdfPage )error {_fg ,_ecc :=page .GetMediaBox ();if _ecc !=nil {return _ecc ;};_bb :=page .Rotate ;_a :=_bb !=nil &&*_bb %360!=0&&*_bb %90==0;_fg .Normalize ();_ee ,_eg ,_bda ,_bg :=_fg .Llx ,_fg .Lly ,_fg .Width (),_fg .Height ();_af :=_ee !=0||_eg !=0;if !_a &&!_af {return nil ;};_c :=func (_d ,_eb ,_ab float64 )_bd .BoundingBox {return _bd .Path {Points :[]_bd .Point {_bd .NewPoint (0,0).Rotate (_ab ),_bd .NewPoint (_d ,0).Rotate (_ab ),_bd .NewPoint (0,_eb ).Rotate (_ab ),_bd .NewPoint (_d ,_eb ).Rotate (_ab )}}.GetBoundingBox ();};_g :=_ec .NewContentCreator ();var _ebb float64 ;if _a {_ebb =-float64 (*page .Rotate );_ce :=_c (_bda ,_bg ,_ebb );_g .Translate ((_ce .Width -_bda )/2+_bda /2,(_ce .Height -_bg )/2+_bg /2);_g .RotateDeg (_ebb );_g .Translate (-_bda /2,-_bg /2);_bda ,_bg =_ce .Width ,_ce .Height ;};if _af {_g .Translate (-_ee ,-_eg );};_de :=_g .Operations ();_cg ,_ecc :=_f .MakeStream (_de .Bytes (),_f .NewFlateEncoder ());if _ecc !=nil {return _ecc ;};_bdf :=_f .MakeArray (_cg );_bdf .Append (page .GetContentStreamObjs ()...);*_fg =_b .PdfRectangle {Urx :_bda ,Ury :_bg };if _ga :=page .CropBox ;_ga !=nil {_ga .Normalize ();_ebbd ,_ea ,_gg ,_gc :=_ga .Llx -_ee ,_ga .Lly -_eg ,_ga .Width (),_ga .Height ();if _a {_aa :=_c (_gg ,_gc ,_ebb );_gg ,_gc =_aa .Width ,_aa .Height ;};*_ga =_b .PdfRectangle {Llx :_ebbd ,Lly :_ea ,Urx :_ebbd +_gg ,Ury :_ea +_gc };};_ef .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ebb ,_de ,_fg );page .Contents =_bdf ;page .Rotate =nil ;return nil ;};
func NormalizePage (page *_ec .PdfPage )error {_eg ,_b :=page .GetMediaBox ();if _b !=nil {return _b ;};_c :=page .Rotate ;_d :=_c !=nil &&*_c %360!=0&&*_c %90==0;_eg .Normalize ();_bc ,_ca ,_fd ,_bd :=_eg .Llx ,_eg .Lly ,_eg .Width (),_eg .Height ();_eb :=_bc !=0||_ca !=0;if !_d &&!_eb {return nil ;};_ce :=func (_ed ,_cg ,_bca float64 )_g .BoundingBox {return _g .Path {Points :[]_g .Point {_g .NewPoint (0,0).Rotate (_bca ),_g .NewPoint (_ed ,0).Rotate (_bca ),_g .NewPoint (0,_cg ).Rotate (_bca ),_g .NewPoint (_ed ,_cg ).Rotate (_bca )}}.GetBoundingBox ();};_fa :=_gb .NewContentCreator ();var _gd float64 ;if _d {_gd =-float64 (*page .Rotate );_edd :=_ce (_fd ,_bd ,_gd );_fa .Translate ((_edd .Width -_fd )/2+_fd /2,(_edd .Height -_bd )/2+_bd /2);_fa .RotateDeg (_gd );_fa .Translate (-_fd /2,-_bd /2);_fd ,_bd =_edd .Width ,_edd .Height ;};if _eb {_fa .Translate (-_bc ,-_ca );};_egg :=_fa .Operations ();_ee ,_b :=_f .MakeStream (_egg .Bytes (),_f .NewFlateEncoder ());if _b !=nil {return _b ;};_bg :=_f .MakeArray (_ee );_bg .Append (page .GetContentStreamObjs ()...);*_eg =_ec .PdfRectangle {Urx :_fd ,Ury :_bd };if _eee :=page .CropBox ;_eee !=nil {_eee .Normalize ();_bge ,_a ,_ecb ,_cc :=_eee .Llx -_bc ,_eee .Lly -_ca ,_eee .Width (),_eee .Height ();if _d {_fad :=_ce (_ecb ,_cc ,_gd );_ecb ,_cc =_fad .Width ,_fad .Height ;};*_eee =_ec .PdfRectangle {Llx :_bge ,Lly :_a ,Urx :_bge +_ecb ,Ury :_a +_cc };};_ef .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_gd ,_egg ,_eg );page .Contents =_bg ;page .Rotate =nil ;return nil ;};

134
ps/ps.go
View File

@ -14,13 +14,13 @@
//
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
// for PDF function type 4.
package ps ;import (_ef "bufio";_a "bytes";_g "errors";_dg "fmt";_f "github.com/unidoc/unipdf/v3/common";_df "github.com/unidoc/unipdf/v3/core";_e "io";_c "math";);
package ps ;import (_c "bufio";_db "bytes";_eg "errors";_df "fmt";_dg "github.com/unidoc/unipdf/v3/common";_f "github.com/unidoc/unipdf/v3/core";_d "io";_ca "math";);func (_bfga *PSOperand )ifCondition (_ggg *PSStack )error {_dag ,_acdc :=_ggg .Pop ();if _acdc !=nil {return _acdc ;};_bag ,_acdc :=_ggg .Pop ();if _acdc !=nil {return _acdc ;};_ddcc ,_cdg :=_dag .(*PSProgram );if !_cdg {return ErrTypeCheck ;};_gbdd ,_cdg :=_bag .(*PSBoolean );if !_cdg {return ErrTypeCheck ;};if _gbdd .Val {_cgdb :=_ddcc .Exec (_ggg );return _cgdb ;};return nil ;};func (_bdgg *PSOperand )pop (_aaa *PSStack )error {_ ,_aea :=_aaa .Pop ();if _aea !=nil {return _aea ;};return nil ;};
// Append appends an object to the PSProgram.
func (_gg *PSProgram )Append (obj PSObject ){*_gg =append (*_gg ,obj )};
// MakeReal returns a new PSReal object initialized with `val`.
func MakeReal (val float64 )*PSReal {_bagb :=PSReal {};_bagb .Val =val ;return &_bagb };func (_ef *PSProgram )String ()string {_bac :="\u007b\u0020";for _ ,_bc :=range *_ef {_bac +=_bc .String ();_bac +="\u0020";};_bac +="\u007d";return _bac ;};func (_dac *PSBoolean )String ()string {return _df .Sprintf ("\u0025\u0076",_dac .Val )};
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;func (_af *PSInteger )DebugString ()string {return _dg .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_af .Val );};
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_eab *PSStack )DebugString ()string {_gacf :="\u005b\u0020";for _ ,_egbg :=range *_eab {_gacf +=_egbg .DebugString ();_gacf +="\u0020";};_gacf +="\u005d";return _gacf ;};const _b =0.000001;
// PSObject represents a postscript object.
type PSObject interface{
@ -33,87 +33,87 @@ Duplicate ()PSObject ;
DebugString ()string ;
// String returns a string representation of the PSObject.
String ()string ;};func (_cgfa *PSOperand )xor (_cbdd *PSStack )error {_cdba ,_faba :=_cbdd .Pop ();if _faba !=nil {return _faba ;};_ggb ,_faba :=_cbdd .Pop ();if _faba !=nil {return _faba ;};if _ega ,_gcb :=_cdba .(*PSBoolean );_gcb {_adfc ,_bcdg :=_ggb .(*PSBoolean );if !_bcdg {return ErrTypeCheck ;};_faba =_cbdd .Push (MakeBool (_ega .Val !=_adfc .Val ));return _faba ;};if _ecba ,_cde :=_cdba .(*PSInteger );_cde {_age ,_dcfd :=_ggb .(*PSInteger );if !_dcfd {return ErrTypeCheck ;};_faba =_cbdd .Push (MakeInteger (_ecba .Val ^_age .Val ));return _faba ;};return ErrTypeCheck ;};func (_dgce *PSOperand )roll (_cdbg *PSStack )error {_ada ,_fdbg :=_cdbg .Pop ();if _fdbg !=nil {return _fdbg ;};_bbb ,_fdbg :=_cdbg .Pop ();if _fdbg !=nil {return _fdbg ;};_ebbg ,_cbg :=_ada .(*PSInteger );if !_cbg {return ErrTypeCheck ;};_dfge ,_cbg :=_bbb .(*PSInteger );if !_cbg {return ErrTypeCheck ;};if _dfge .Val < 0{return ErrRangeCheck ;};if _dfge .Val ==0||_dfge .Val ==1{return nil ;};if _dfge .Val > len (*_cdbg ){return ErrStackUnderflow ;};for _dfgb :=0;_dfgb < _ccg (_ebbg .Val );_dfgb ++{var _eefg []PSObject ;_eefg =(*_cdbg )[len (*_cdbg )-(_dfge .Val ):len (*_cdbg )];if _ebbg .Val > 0{_dfbd :=_eefg [len (_eefg )-1];_eefg =append ([]PSObject {_dfbd },_eefg [0:len (_eefg )-1]...);}else {_acb :=_eefg [len (_eefg )-_dfge .Val ];_eefg =append (_eefg [1:],_acb );};_feg :=append ((*_cdbg )[0:len (*_cdbg )-_dfge .Val ],_eefg ...);_cdbg =&_feg ;};return nil ;};
String ()string ;};func (_cab *PSOperand )bitshift (_aeb *PSStack )error {_bb ,_feg :=_aeb .PopInteger ();if _feg !=nil {return _feg ;};_gdc ,_feg :=_aeb .PopInteger ();if _feg !=nil {return _feg ;};var _ac int ;if _bb >=0{_ac =_gdc <<uint (_bb );}else {_ac =_gdc >>uint (-_bb );};_feg =_aeb .Push (MakeInteger (_ac ));return _feg ;};func (_gacc *PSOperand )sub (_cged *PSStack )error {_abg ,_gff :=_cged .Pop ();if _gff !=nil {return _gff ;};_gec ,_gff :=_cged .Pop ();if _gff !=nil {return _gff ;};_bbaf ,_adde :=_abg .(*PSReal );_dgeee ,_cae :=_abg .(*PSInteger );if !_adde &&!_cae {return ErrTypeCheck ;};_bfcg ,_dfec :=_gec .(*PSReal );_bcd ,_eeg :=_gec .(*PSInteger );if !_dfec &&!_eeg {return ErrTypeCheck ;};if _cae &&_eeg {_cdfg :=_bcd .Val -_dgeee .Val ;_gfbg :=_cged .Push (MakeInteger (_cdfg ));return _gfbg ;};var _gbfb float64 =0;if _dfec {_gbfb =_bfcg .Val ;}else {_gbfb =float64 (_bcd .Val );};if _adde {_gbfb -=_bbaf .Val ;}else {_gbfb -=float64 (_dgeee .Val );};_gff =_cged .Push (MakeReal (_gbfb ));return _gff ;};func (_ddd *PSInteger )Duplicate ()PSObject {_ged :=PSInteger {};_ged .Val =_ddd .Val ;return &_ged };func (_dgcb *PSParser )parseFunction ()(*PSProgram ,error ){_defc ,_ :=_dgcb ._dcaf .ReadByte ();if _defc !='{'{return nil ,_eg .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_bcc :=NewPSProgram ();for {_dgcb .skipSpaces ();_cbb ,_bea :=_dgcb ._dcaf .Peek (2);if _bea !=nil {if _bea ==_d .EOF {break ;};return nil ,_bea ;};_dg .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_cbb ));if _cbb [0]=='}'{_dg .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_dgcb ._dcaf .ReadByte ();break ;}else if _cbb [0]=='{'{_dg .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_febc ,_bbb :=_dgcb .parseFunction ();if _bbb !=nil {return nil ,_bbb ;};_bcc .Append (_febc );}else if _f .IsDecimalDigit (_cbb [0])||(_cbb [0]=='-'&&_f .IsDecimalDigit (_cbb [1])){_dg .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_bbfd ,_gbg :=_dgcb .parseNumber ();if _gbg !=nil {return nil ,_gbg ;};_bcc .Append (_bbfd );}else {_dg .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_cbb ,_ =_dgcb ._dcaf .Peek (5);_dffd :=string (_cbb );_dg .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_dffd );if (len (_dffd )> 4)&&(_dffd [:5]=="\u0066\u0061\u006cs\u0065"){_agcb ,_dfg :=_dgcb .parseBool ();if _dfg !=nil {return nil ,_dfg ;};_bcc .Append (_agcb );}else if (len (_dffd )> 3)&&(_dffd [:4]=="\u0074\u0072\u0075\u0065"){_dcad ,_cbc :=_dgcb .parseBool ();if _cbc !=nil {return nil ,_cbc ;};_bcc .Append (_dcad );}else {_cff ,_dda :=_dgcb .parseOperand ();if _dda !=nil {return nil ,_dda ;};_bcc .Append (_cff );};};};return _bcc ,nil ;};
// Push pushes an object on top of the stack.
func (_fac *PSStack )Push (obj PSObject )error {if len (*_fac )> 100{return ErrStackOverflow ;};*_fac =append (*_fac ,obj );return nil ;};func (_afba *PSParser )parseFunction ()(*PSProgram ,error ){_geb ,_ :=_afba ._bcgg .ReadByte ();if _geb !='{'{return nil ,_g .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_egc :=NewPSProgram ();for {_afba .skipSpaces ();_ggc ,_edea :=_afba ._bcgg .Peek (2);if _edea !=nil {if _edea ==_e .EOF {break ;};return nil ,_edea ;};_f .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_ggc ));if _ggc [0]=='}'{_f .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_afba ._bcgg .ReadByte ();break ;}else if _ggc [0]=='{'{_f .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_deeg ,_eada :=_afba .parseFunction ();if _eada !=nil {return nil ,_eada ;};_egc .Append (_deeg );}else if _df .IsDecimalDigit (_ggc [0])||(_ggc [0]=='-'&&_df .IsDecimalDigit (_ggc [1])){_f .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_afbc ,_geec :=_afba .parseNumber ();if _geec !=nil {return nil ,_geec ;};_egc .Append (_afbc );}else {_f .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_ggc ,_ =_afba ._bcgg .Peek (5);_cbfd :=string (_ggc );_f .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_cbfd );if (len (_cbfd )> 4)&&(_cbfd [:5]=="\u0066\u0061\u006cs\u0065"){_efcb ,_dgcbd :=_afba .parseBool ();if _dgcbd !=nil {return nil ,_dgcbd ;};_egc .Append (_efcb );}else if (len (_cbfd )> 3)&&(_cbfd [:4]=="\u0074\u0072\u0075\u0065"){_adeg ,_dbd :=_afba .parseBool ();if _dbd !=nil {return nil ,_dbd ;};_egc .Append (_adeg );}else {_gaa ,_fccb :=_afba .parseOperand ();if _fccb !=nil {return nil ,_fccb ;};_egc .Append (_gaa );};};};return _egc ,nil ;};func (_eeg *PSOperand )cvi (_dffe *PSStack )error {_ffd ,_dfad :=_dffe .Pop ();if _dfad !=nil {return _dfad ;};if _efd ,_abb :=_ffd .(*PSReal );_abb {_daa :=int (_efd .Val );_dfad =_dffe .Push (MakeInteger (_daa ));}else if _gee ,_gae :=_ffd .(*PSInteger );_gae {_fca :=_gee .Val ;_dfad =_dffe .Push (MakeInteger (_fca ));}else {return ErrTypeCheck ;};return _dfad ;};
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_bg *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_fd :=range objects {_dd :=_bg .Stack .Push (_fd );if _dd !=nil {return nil ,_dd ;};};_gcb :=_bg ._g .Exec (_bg .Stack );if _gcb !=nil {_dg .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_gcb );return nil ,_gcb ;};_ge :=[]PSObject (*_bg .Stack );_bg .Stack .Empty ();return _ge ,nil ;};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_ccaa :=PSInteger {};_ccaa .Val =val ;return &_ccaa };func (_ffa *PSOperand )copy (_abd *PSStack )error {_gdc ,_ffg :=_abd .PopInteger ();if _ffg !=nil {return _ffg ;};if _gdc < 0{return ErrRangeCheck ;};if _gdc > len (*_abd ){return ErrRangeCheck ;};*_abd =append (*_abd ,(*_abd )[len (*_abd )-_gdc :]...);return nil ;};var ErrUnsupportedOperand =_g .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");
// Exec executes the operand `op` in the state specified by `stack`.
func (_dgc *PSOperand )Exec (stack *PSStack )error {_eb :=ErrUnsupportedOperand ;switch *_dgc {case "\u0061\u0062\u0073":_eb =_dgc .abs (stack );case "\u0061\u0064\u0064":_eb =_dgc .add (stack );case "\u0061\u006e\u0064":_eb =_dgc .and (stack );case "\u0061\u0074\u0061\u006e":_eb =_dgc .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_eb =_dgc .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_eb =_dgc .ceiling (stack );case "\u0063\u006f\u0070\u0079":_eb =_dgc .copy (stack );case "\u0063\u006f\u0073":_eb =_dgc .cos (stack );case "\u0063\u0076\u0069":_eb =_dgc .cvi (stack );case "\u0063\u0076\u0072":_eb =_dgc .cvr (stack );case "\u0064\u0069\u0076":_eb =_dgc .div (stack );case "\u0064\u0075\u0070":_eb =_dgc .dup (stack );case "\u0065\u0071":_eb =_dgc .eq (stack );case "\u0065\u0078\u0063\u0068":_eb =_dgc .exch (stack );case "\u0065\u0078\u0070":_eb =_dgc .exp (stack );case "\u0066\u006c\u006fo\u0072":_eb =_dgc .floor (stack );case "\u0067\u0065":_eb =_dgc .ge (stack );case "\u0067\u0074":_eb =_dgc .gt (stack );case "\u0069\u0064\u0069\u0076":_eb =_dgc .idiv (stack );case "\u0069\u0066":_eb =_dgc .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_eb =_dgc .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_eb =_dgc .index (stack );case "\u006c\u0065":_eb =_dgc .le (stack );case "\u006c\u006f\u0067":_eb =_dgc .log (stack );case "\u006c\u006e":_eb =_dgc .ln (stack );case "\u006c\u0074":_eb =_dgc .lt (stack );case "\u006d\u006f\u0064":_eb =_dgc .mod (stack );case "\u006d\u0075\u006c":_eb =_dgc .mul (stack );case "\u006e\u0065":_eb =_dgc .ne (stack );case "\u006e\u0065\u0067":_eb =_dgc .neg (stack );case "\u006e\u006f\u0074":_eb =_dgc .not (stack );case "\u006f\u0072":_eb =_dgc .or (stack );case "\u0070\u006f\u0070":_eb =_dgc .pop (stack );case "\u0072\u006f\u0075n\u0064":_eb =_dgc .round (stack );case "\u0072\u006f\u006c\u006c":_eb =_dgc .roll (stack );case "\u0073\u0069\u006e":_eb =_dgc .sin (stack );case "\u0073\u0071\u0072\u0074":_eb =_dgc .sqrt (stack );case "\u0073\u0075\u0062":_eb =_dgc .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_eb =_dgc .truncate (stack );case "\u0078\u006f\u0072":_eb =_dgc .xor (stack );};return _eb ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_dcaf *_c .Reader };func (_ffe *PSOperand )ifelse (_gcee *PSStack )error {_cce ,_geee :=_gcee .Pop ();if _geee !=nil {return _geee ;};_bff ,_geee :=_gcee .Pop ();if _geee !=nil {return _geee ;};_aca ,_geee :=_gcee .Pop ();if _geee !=nil {return _geee ;};_gfe ,_agc :=_cce .(*PSProgram );if !_agc {return ErrTypeCheck ;};_cbe ,_agc :=_bff .(*PSProgram );if !_agc {return ErrTypeCheck ;};_dfcd ,_agc :=_aca .(*PSBoolean );if !_agc {return ErrTypeCheck ;};if _dfcd .Val {_beb :=_cbe .Exec (_gcee );return _beb ;};_geee =_gfe .Exec (_gcee );return _geee ;};func (_dbda *PSOperand )round (_dgee *PSStack )error {_beea ,_ebcd :=_dgee .Pop ();if _ebcd !=nil {return _ebcd ;};if _dgga ,_cgg :=_beea .(*PSReal );_cgg {_ebcd =_dgee .Push (MakeReal (_ca .Floor (_dgga .Val +0.5)));}else if _aabc ,_dgeb :=_beea .(*PSInteger );_dgeb {_ebcd =_dgee .Push (MakeInteger (_aabc .Val ));}else {return ErrTypeCheck ;};return _ebcd ;};
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
type PSProgram []PSObject ;
// PSReal represents a real number.
type PSReal struct{Val float64 ;};func (_bde *PSParser )skipSpaces ()(int ,error ){_dcb :=0;for {_ccfa ,_efd :=_bde ._dcaf .Peek (1);if _efd !=nil {return 0,_efd ;};if _f .IsWhiteSpace (_ccfa [0]){_bde ._dcaf .ReadByte ();_dcb ++;}else {break ;};};return _dcb ,nil ;};
// Empty empties the stack.
func (_geg *PSStack )Empty (){*_geg =[]PSObject {}};func (_gbcg *PSOperand )sin (_bbfa *PSStack )error {_cbdb ,_bffc :=_bbfa .PopNumberAsFloat64 ();if _bffc !=nil {return _bffc ;};_bddg :=_ca .Sin (_cbdb *_ca .Pi /180.0);_bffc =_bbfa .Push (MakeReal (_bddg ));return _bffc ;};func (_af *PSProgram )DebugString ()string {_cf :="\u007b\u0020";for _ ,_bgb :=range *_af {_cf +=_bgb .DebugString ();_cf +="\u0020";};_cf +="\u007d";return _cf ;};func (_gceb *PSOperand )floor (_gae *PSStack )error {_gbeg ,_fea :=_gae .Pop ();if _fea !=nil {return _fea ;};if _dgcgb ,_gbfc :=_gbeg .(*PSReal );_gbfc {_fea =_gae .Push (MakeReal (_ca .Floor (_dgcgb .Val )));}else if _faa ,_fcfd :=_gbeg .(*PSInteger );_fcfd {_fea =_gae .Push (MakeInteger (_faa .Val ));}else {return ErrTypeCheck ;};return _fea ;};func (_ggce *PSOperand )copy (_cgac *PSStack )error {_bdd ,_aae :=_cgac .PopInteger ();if _aae !=nil {return _aae ;};if _bdd < 0{return ErrRangeCheck ;};if _bdd > len (*_cgac ){return ErrRangeCheck ;};*_cgac =append (*_cgac ,(*_cgac )[len (*_cgac )-_bdd :]...);return nil ;};func (_eaa *PSOperand )le (_fdca *PSStack )error {_aaf ,_ebf :=_fdca .PopNumberAsFloat64 ();if _ebf !=nil {return _ebf ;};_fbef ,_ebf :=_fdca .PopNumberAsFloat64 ();if _ebf !=nil {return _ebf ;};if _ca .Abs (_fbef -_aaf )< _b {_cdga :=_fdca .Push (MakeBool (true ));return _cdga ;}else if _fbef < _aaf {_cbed :=_fdca .Push (MakeBool (true ));return _cbed ;}else {_bede :=_fdca .Push (MakeBool (false ));return _bede ;};};
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_eca :=PSBoolean {};_eca .Val =val ;return &_eca };
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};var ErrUndefinedResult =_eg .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_cge *PSOperand )lt (_gbbb *PSStack )error {_bfb ,_ffd :=_gbbb .PopNumberAsFloat64 ();if _ffd !=nil {return _ffd ;};_aee ,_ffd :=_gbbb .PopNumberAsFloat64 ();if _ffd !=nil {return _ffd ;};if _ca .Abs (_aee -_bfb )< _b {_cege :=_gbbb .Push (MakeBool (false ));return _cege ;}else if _aee < _bfb {_bdc :=_gbbb .Push (MakeBool (true ));return _bdc ;}else {_cgb :=_gbbb .Push (MakeBool (false ));return _cgb ;};};func (_aa *PSOperand )atan (_ege *PSStack )error {_cad ,_bed :=_ege .PopNumberAsFloat64 ();if _bed !=nil {return _bed ;};_ga ,_bed :=_ege .PopNumberAsFloat64 ();if _bed !=nil {return _bed ;};if _cad ==0{var _egf error ;if _ga < 0{_egf =_ege .Push (MakeReal (270));}else {_egf =_ege .Push (MakeReal (90));};return _egf ;};_dbd :=_ga /_cad ;_ae :=_ca .Atan (_dbd )*180/_ca .Pi ;_bed =_ege .Push (MakeReal (_ae ));return _bed ;};func (_afg *PSOperand )mul (_caba *PSStack )error {_aed ,_edd :=_caba .Pop ();if _edd !=nil {return _edd ;};_gfb ,_edd :=_caba .Pop ();if _edd !=nil {return _edd ;};_aac ,_abbc :=_aed .(*PSReal );_cbeg ,_bdf :=_aed .(*PSInteger );if !_abbc &&!_bdf {return ErrTypeCheck ;};_afe ,_cgda :=_gfb .(*PSReal );_bbcf ,_dadb :=_gfb .(*PSInteger );if !_cgda &&!_dadb {return ErrTypeCheck ;};if _bdf &&_dadb {_bffb :=_cbeg .Val *_bbcf .Val ;_dea :=_caba .Push (MakeInteger (_bffb ));return _dea ;};var _gbbbg float64 ;if _abbc {_gbbbg =_aac .Val ;}else {_gbbbg =float64 (_cbeg .Val );};if _cgda {_gbbbg *=_afe .Val ;}else {_gbbbg *=float64 (_bbcf .Val );};_edd =_caba .Push (MakeReal (_gbbbg ));return _edd ;};func (_ggd *PSOperand )sqrt (_age *PSStack )error {_agg ,_cbf :=_age .PopNumberAsFloat64 ();if _cbf !=nil {return _cbf ;};if _agg < 0{return ErrRangeCheck ;};_cceg :=_ca .Sqrt (_agg );_cbf =_age .Push (MakeReal (_cceg ));return _cbf ;};func (_ddg *PSOperand )ne (_fgge *PSStack )error {_fbda :=_ddg .eq (_fgge );if _fbda !=nil {return _fbda ;};_fbda =_ddg .not (_fgge );return _fbda ;};
// PSBoolean represents a boolean value.
type PSBoolean struct{Val bool ;};func (_ddb *PSOperand )index (_cac *PSStack )error {_aba ,_fdba :=_cac .Pop ();if _fdba !=nil {return _fdba ;};_gac ,_fcg :=_aba .(*PSInteger );if !_fcg {return ErrTypeCheck ;};if _gac .Val < 0{return ErrRangeCheck ;};if _gac .Val > len (*_cac )-1{return ErrStackUnderflow ;};_dadd :=(*_cac )[len (*_cac )-1-_gac .Val ];_fdba =_cac .Push (_dadd .Duplicate ());return _fdba ;};func (_gfc *PSOperand )roll (_gbec *PSStack )error {_bdbd ,_cdb :=_gbec .Pop ();if _cdb !=nil {return _cdb ;};_caae ,_cdb :=_gbec .Pop ();if _cdb !=nil {return _cdb ;};_cdeg ,_dgeea :=_bdbd .(*PSInteger );if !_dgeea {return ErrTypeCheck ;};_bffe ,_dgeea :=_caae .(*PSInteger );if !_dgeea {return ErrTypeCheck ;};if _bffe .Val < 0{return ErrRangeCheck ;};if _bffe .Val ==0||_bffe .Val ==1{return nil ;};if _bffe .Val > len (*_gbec ){return ErrStackUnderflow ;};for _ceca :=0;_ceca < _ggbb (_cdeg .Val );_ceca ++{var _fcc []PSObject ;_fcc =(*_gbec )[len (*_gbec )-(_bffe .Val ):len (*_gbec )];if _cdeg .Val > 0{_fbfb :=_fcc [len (_fcc )-1];_fcc =append ([]PSObject {_fbfb },_fcc [0:len (_fcc )-1]...);}else {_bbd :=_fcc [len (_fcc )-_bffe .Val ];_fcc =append (_fcc [1:],_bbd );};_aef :=append ((*_gbec )[0:len (*_gbec )-_bffe .Val ],_fcc ...);_gbec =&_aef ;};return nil ;};func (_a *PSBoolean )Duplicate ()PSObject {_dgd :=PSBoolean {};_dgd .Val =_a .Val ;return &_dgd };func (_ecde *PSParser )parseBool ()(*PSBoolean ,error ){_efc ,_fccc :=_ecde ._dcaf .Peek (4);if _fccc !=nil {return MakeBool (false ),_fccc ;};if (len (_efc )>=4)&&(string (_efc [:4])=="\u0074\u0072\u0075\u0065"){_ecde ._dcaf .Discard (4);return MakeBool (true ),nil ;};_efc ,_fccc =_ecde ._dcaf .Peek (5);if _fccc !=nil {return MakeBool (false ),_fccc ;};if (len (_efc )>=5)&&(string (_efc [:5])=="\u0066\u0061\u006cs\u0065"){_ecde ._dcaf .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_eg .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_ffcd :=PSOperand (val );return &_ffcd };func (_bgea *PSParser )parseNumber ()(PSObject ,error ){_eff ,_fcd :=_f .ParseNumber (_bgea ._dcaf );if _fcd !=nil {return nil ,_fcd ;};switch _gdf :=_eff .(type ){case *_f .PdfObjectFloat :return MakeReal (float64 (*_gdf )),nil ;case *_f .PdfObjectInteger :return MakeInteger (int (*_gdf )),nil ;};return nil ,_df .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_eff );};func (_ebc *PSOperand )or (_baf *PSStack )error {_cegfb ,_egg :=_baf .Pop ();if _egg !=nil {return _egg ;};_affc ,_egg :=_baf .Pop ();if _egg !=nil {return _egg ;};if _ffdg ,_bbcfe :=_cegfb .(*PSBoolean );_bbcfe {_acf ,_afc :=_affc .(*PSBoolean );if !_afc {return ErrTypeCheck ;};_egg =_baf .Push (MakeBool (_ffdg .Val ||_acf .Val ));return _egg ;};if _agdd ,_ccd :=_cegfb .(*PSInteger );_ccd {_gcag ,_ada :=_affc .(*PSInteger );if !_ada {return ErrTypeCheck ;};_egg =_baf .Push (MakeInteger (_agdd .Val |_gcag .Val ));return _egg ;};return ErrTypeCheck ;};
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
func (_bccd *PSStack )PopInteger ()(int ,error ){_bbf ,_aeda :=_bccd .Pop ();if _aeda !=nil {return 0,_aeda ;};if _cbc ,_bfe :=_bbf .(*PSInteger );_bfe {return _cbc .Val ,nil ;};return 0,ErrTypeCheck ;};func (_cag *PSOperand )log (_ddcg *PSStack )error {_dcccg ,_dgf :=_ddcg .PopNumberAsFloat64 ();if _dgf !=nil {return _dgf ;};_eba :=_c .Log10 (_dcccg );_dgf =_ddcg .Push (MakeReal (_eba ));return _dgf ;};
func (_defbe *PSStack )PopInteger ()(int ,error ){_edb ,_eddbd :=_defbe .Pop ();if _eddbd !=nil {return 0,_eddbd ;};if _efbd ,_fgf :=_edb .(*PSInteger );_fgf {return _efbd .Val ,nil ;};return 0,ErrTypeCheck ;};func (_gb *PSOperand )DebugString ()string {return _df .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_gb );};func (_ec *PSInteger )String ()string {return _df .Sprintf ("\u0025\u0064",_ec .Val )};func (_fga *PSOperand )gt (_cgf *PSStack )error {_abeb ,_agbf :=_cgf .PopNumberAsFloat64 ();if _agbf !=nil {return _agbf ;};_dfb ,_agbf :=_cgf .PopNumberAsFloat64 ();if _agbf !=nil {return _agbf ;};if _ca .Abs (_dfb -_abeb )< _b {_gcac :=_cgf .Push (MakeBool (false ));return _gcac ;}else if _dfb > _abeb {_gee :=_cgf .Push (MakeBool (true ));return _gee ;}else {_acd :=_cgf .Push (MakeBool (false ));return _acd ;};};func (_fcf *PSOperand )div (_fdb *PSStack )error {_cfcf ,_bbg :=_fdb .Pop ();if _bbg !=nil {return _bbg ;};_fad ,_bbg :=_fdb .Pop ();if _bbg !=nil {return _bbg ;};_gf ,_fbf :=_cfcf .(*PSReal );_fbfe ,_ddfc :=_cfcf .(*PSInteger );if !_fbf &&!_ddfc {return ErrTypeCheck ;};if _fbf &&_gf .Val ==0{return ErrUndefinedResult ;};if _ddfc &&_fbfe .Val ==0{return ErrUndefinedResult ;};_gge ,_ggf :=_fad .(*PSReal );_bbf ,_agd :=_fad .(*PSInteger );if !_ggf &&!_agd {return ErrTypeCheck ;};var _bce float64 ;if _ggf {_bce =_gge .Val ;}else {_bce =float64 (_bbf .Val );};if _fbf {_bce /=_gf .Val ;}else {_bce /=float64 (_fbfe .Val );};_bbg =_fdb .Push (MakeReal (_bce ));return _bbg ;};func (_fgb *PSOperand )ln (_bbc *PSStack )error {_fcfc ,_cde :=_bbc .PopNumberAsFloat64 ();if _cde !=nil {return _cde ;};_egae :=_ca .Log (_fcfc );_cde =_bbc .Push (MakeReal (_egae ));return _cde ;};
// NewPSStack returns an initialized PSStack.
func NewPSStack ()*PSStack {return &PSStack {}};func (_eed *PSOperand )ifCondition (_gcegg *PSStack )error {_beg ,_gda :=_gcegg .Pop ();if _gda !=nil {return _gda ;};_eggg ,_gda :=_gcegg .Pop ();if _gda !=nil {return _gda ;};_aeg ,_cab :=_beg .(*PSProgram );if !_cab {return ErrTypeCheck ;};_abbb ,_cab :=_eggg .(*PSBoolean );if !_cab {return ErrTypeCheck ;};if _abbb .Val {_ddce :=_aeg .Exec (_gcegg );return _ddce ;};return nil ;};func (_dcb *PSOperand )and (_dbf *PSStack )error {_bdg ,_agc :=_dbf .Pop ();if _agc !=nil {return _agc ;};_eab ,_agc :=_dbf .Pop ();if _agc !=nil {return _agc ;};if _ff ,_bbe :=_bdg .(*PSBoolean );_bbe {_fde ,_fc :=_eab .(*PSBoolean );if !_fc {return ErrTypeCheck ;};_agc =_dbf .Push (MakeBool (_ff .Val &&_fde .Val ));return _agc ;};if _gfee ,_fbgc :=_bdg .(*PSInteger );_fbgc {_dag ,_bgb :=_eab .(*PSInteger );if !_bgb {return ErrTypeCheck ;};_agc =_dbf .Push (MakeInteger (_gfee .Val &_dag .Val ));return _agc ;};return ErrTypeCheck ;};func (_geg *PSOperand )exch (_egf *PSStack )error {_bde ,_fdea :=_egf .Pop ();if _fdea !=nil {return _fdea ;};_bdb ,_fdea :=_egf .Pop ();if _fdea !=nil {return _fdea ;};_fdea =_egf .Push (_bde );if _fdea !=nil {return _fdea ;};_fdea =_egf .Push (_bdb );return _fdea ;};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_bbbg :=PSInteger {};_bbbg .Val =val ;return &_bbbg };func (_gdcg *PSOperand )dup (_cag *PSStack )error {_ccbg ,_dga :=_cag .Pop ();if _dga !=nil {return _dga ;};_dga =_cag .Push (_ccbg );if _dga !=nil {return _dga ;};_dga =_cag .Push (_ccbg .Duplicate ());return _dga ;};
// Parse parses the postscript and store as a program that can be executed.
func (_ace *PSParser )Parse ()(*PSProgram ,error ){_ace .skipSpaces ();_accf ,_ggg :=_ace ._bcgg .Peek (2);if _ggg !=nil {return nil ,_ggg ;};if _accf [0]!='{'{return nil ,_g .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");};_fgf ,_ggg :=_ace .parseFunction ();if _ggg !=nil &&_ggg !=_e .EOF {return nil ,_ggg ;};return _fgf ,_ggg ;};var ErrUndefinedResult =_g .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_dd *PSReal )String ()string {return _dg .Sprintf ("\u0025\u002e\u0035\u0066",_dd .Val )};var ErrStackUnderflow =_g .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_bcdb *PSStack )DebugString ()string {_cfeg :="\u005b\u0020";for _ ,_bab :=range *_bcdb {_cfeg +=_bab .DebugString ();_cfeg +="\u0020";};_cfeg +="\u005d";return _cfeg ;};func (_aa *PSProgram )DebugString ()string {_fae :="\u007b\u0020";for _ ,_cc :=range *_aa {_fae +=_cc .DebugString ();_fae +="\u0020";};_fae +="\u007d";return _fae ;};func _ccg (_bdf int )int {if _bdf < 0{return -_bdf ;};return _bdf ;};func (_adc *PSOperand )idiv (_bfgb *PSStack )error {_bfff ,_cedd :=_bfgb .Pop ();if _cedd !=nil {return _cedd ;};_eef ,_cedd :=_bfgb .Pop ();if _cedd !=nil {return _cedd ;};_bfb ,_fdf :=_bfff .(*PSInteger );if !_fdf {return ErrTypeCheck ;};if _bfb .Val ==0{return ErrUndefinedResult ;};_dae ,_fdf :=_eef .(*PSInteger );if !_fdf {return ErrTypeCheck ;};_cfd :=_dae .Val /_bfb .Val ;_cedd =_bfgb .Push (MakeInteger (_cfd ));return _cedd ;};func (_bfcb *PSOperand )mul (_fcdab *PSStack )error {_fdde ,_fdda :=_fcdab .Pop ();if _fdda !=nil {return _fdda ;};_adff ,_fdda :=_fcdab .Pop ();if _fdda !=nil {return _fdda ;};_cega ,_aec :=_fdde .(*PSReal );_ebg ,_adcg :=_fdde .(*PSInteger );if !_aec &&!_adcg {return ErrTypeCheck ;};_dbeb ,_cfbg :=_adff .(*PSReal );_fdfa ,_bada :=_adff .(*PSInteger );if !_cfbg &&!_bada {return ErrTypeCheck ;};if _adcg &&_bada {_gdb :=_ebg .Val *_fdfa .Val ;_faeb :=_fcdab .Push (MakeInteger (_gdb ));return _faeb ;};var _dfb float64 =0;if _aec {_dfb =_cega .Val ;}else {_dfb =float64 (_ebg .Val );};if _cfbg {_dfb *=_dbeb .Val ;}else {_dfb *=float64 (_fdfa .Val );};_fdda =_fcdab .Push (MakeReal (_dfb ));return _fdda ;};func (_cba *PSOperand )sub (_faa *PSStack )error {_cbd ,_cbgd :=_faa .Pop ();if _cbgd !=nil {return _cbgd ;};_bagf ,_cbgd :=_faa .Pop ();if _cbgd !=nil {return _cbgd ;};_cgb ,_edbf :=_cbd .(*PSReal );_gcda ,_eedbd :=_cbd .(*PSInteger );if !_edbf &&!_eedbd {return ErrTypeCheck ;};_cfcc ,_gcg :=_bagf .(*PSReal );_aae ,_bbad :=_bagf .(*PSInteger );if !_gcg &&!_bbad {return ErrTypeCheck ;};if _eedbd &&_bbad {_ecga :=_aae .Val -_gcda .Val ;_geae :=_faa .Push (MakeInteger (_ecga ));return _geae ;};var _cegc float64 =0;if _gcg {_cegc =_cfcc .Val ;}else {_cegc =float64 (_aae .Val );};if _edbf {_cegc -=_cgb .Val ;}else {_cegc -=float64 (_gcda .Val );};_cbgd =_faa .Push (MakeReal (_cegc ));return _cbgd ;};func (_fd *PSInteger )String ()string {return _dg .Sprintf ("\u0025\u0064",_fd .Val )};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;func (_gbf *PSOperand )cvr (_bba *PSStack )error {_dgba ,_abe :=_bba .Pop ();if _abe !=nil {return _abe ;};if _egbb ,_cfb :=_dgba .(*PSReal );_cfb {_abe =_bba .Push (MakeReal (_egbb .Val ));}else if _dgg ,_egac :=_dgba .(*PSInteger );_egac {_abe =_bba .Push (MakeReal (float64 (_dgg .Val )));}else {return ErrTypeCheck ;};return _abe ;};func (_dff *PSOperand )eq (_bad *PSStack )error {_bedd ,_ddde :=_bad .Pop ();if _ddde !=nil {return _ddde ;};_ccc ,_ddde :=_bad .Pop ();if _ddde !=nil {return _ddde ;};_ea ,_gca :=_bedd .(*PSBoolean );_afb ,_ccf :=_ccc .(*PSBoolean );if _gca ||_ccf {var _gbfa error ;if _gca &&_ccf {_gbfa =_bad .Push (MakeBool (_ea .Val ==_afb .Val ));}else {_gbfa =_bad .Push (MakeBool (false ));};return _gbfa ;};var _cbd float64 ;var _abf float64 ;if _cagb ,_fddf :=_bedd .(*PSInteger );_fddf {_cbd =float64 (_cagb .Val );}else if _fde ,_dc :=_bedd .(*PSReal );_dc {_cbd =_fde .Val ;}else {return ErrTypeCheck ;};if _bbad ,_dcc :=_ccc .(*PSInteger );_dcc {_abf =float64 (_bbad .Val );}else if _fdbb ,_ggb :=_ccc .(*PSReal );_ggb {_abf =_fdbb .Val ;}else {return ErrTypeCheck ;};if _ca .Abs (_abf -_cbd )< _b {_ddde =_bad .Push (MakeBool (true ));}else {_ddde =_bad .Push (MakeBool (false ));};return _ddde ;};func (_ccb *PSProgram )Duplicate ()PSObject {_fdde :=&PSProgram {};for _ ,_cd :=range *_ccb {_fdde .Append (_cd .Duplicate ());};return _fdde ;};func (_ede *PSOperand )neg (_eda *PSStack )error {_bcea ,_beda :=_eda .Pop ();if _beda !=nil {return _beda ;};if _efgb ,_geddd :=_bcea .(*PSReal );_geddd {_beda =_eda .Push (MakeReal (-_efgb .Val ));return _beda ;}else if _bcf ,_fcfe :=_bcea .(*PSInteger );_fcfe {_beda =_eda .Push (MakeInteger (-_bcf .Val ));return _beda ;}else {return ErrTypeCheck ;};};var ErrRangeCheck =_eg .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_ecd *PSReal )Duplicate ()PSObject {_caf :=PSReal {};_caf .Val =_ecd .Val ;return &_caf };var ErrStackUnderflow =_eg .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");func (_gce *PSOperand )String ()string {return string (*_gce )};func (_gd *PSBoolean )DebugString ()string {return _df .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_gd .Val );};
// Pop pops an object from the top of the stack.
func (_aged *PSStack )Pop ()(PSObject ,error ){if len (*_aged )< 1{return nil ,ErrStackUnderflow ;};_gfd :=(*_aged )[len (*_aged )-1];*_aged =(*_aged )[0:len (*_aged )-1];return _gfd ,nil ;};func (_bdafe *PSOperand )eq (_fab *PSStack )error {_bac ,_eae :=_fab .Pop ();if _eae !=nil {return _eae ;};_gaf ,_eae :=_fab .Pop ();if _eae !=nil {return _eae ;};_bcc ,_dba :=_bac .(*PSBoolean );_gdd ,_gca :=_gaf .(*PSBoolean );if _dba ||_gca {var _fee error ;if _dba &&_gca {_fee =_fab .Push (MakeBool (_bcc .Val ==_gdd .Val ));}else {_fee =_fab .Push (MakeBool (false ));};return _fee ;};var _efa float64 ;var _bfc float64 ;if _feb ,_ed :=_bac .(*PSInteger );_ed {_efa =float64 (_feb .Val );}else if _cefc ,_gbe :=_bac .(*PSReal );_gbe {_efa =_cefc .Val ;}else {return ErrTypeCheck ;};if _dada ,_ebe :=_gaf .(*PSInteger );_ebe {_bfc =float64 (_dada .Val );}else if _ebf ,_afce :=_gaf .(*PSReal );_afce {_bfc =_ebf .Val ;}else {return ErrTypeCheck ;};if _c .Abs (_bfc -_efa )< _b {_eae =_fab .Push (MakeBool (true ));}else {_eae =_fab .Push (MakeBool (false ));};return _eae ;};
func (_gfec *PSStack )Pop ()(PSObject ,error ){if len (*_gfec )< 1{return nil ,ErrStackUnderflow ;};_cecf :=(*_gfec )[len (*_gfec )-1];*_gfec =(*_gfec )[0:len (*_gfec )-1];return _cecf ,nil ;};
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
// Real or integer only.
func (_ebba *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_dcec ,_edg :=_ebba .Pop ();if _edg !=nil {return 0,_edg ;};if _gga ,_fdc :=_dcec .(*PSReal );_fdc {return _gga .Val ,nil ;}else if _fcdf ,_dcea :=_dcec .(*PSInteger );_dcea {return float64 (_fcdf .Val ),nil ;}else {return 0,ErrTypeCheck ;};};
func (_gcbe *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_aaca ,_cbbd :=_gcbe .Pop ();if _cbbd !=nil {return 0,_cbbd ;};if _adf ,_cacd :=_aaca .(*PSReal );_cacd {return _adf .Val ,nil ;}else if _gcc ,_cagc :=_aaca .(*PSInteger );_cagc {return float64 (_gcc .Val ),nil ;}else {return 0,ErrTypeCheck ;};};
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_cdgb :=PSOperand (val );return &_cdgb };
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct{Stack *PSStack ;_g *PSProgram ;};
// PSReal represents a real number.
type PSReal struct{Val float64 ;};var ErrTypeCheck =_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");func (_dega *PSParser )skipSpaces ()(int ,error ){_badb :=0;for {_ddad ,_cbgdc :=_dega ._bcgg .Peek (1);if _cbgdc !=nil {return 0,_cbgdc ;};if _df .IsWhiteSpace (_ddad [0]){_dega ._bcgg .ReadByte ();_badb ++;}else {break ;};};return _badb ,nil ;};
// NewPSStack returns an initialized PSStack.
func NewPSStack ()*PSStack {return &PSStack {}};func (_ddce *PSOperand )exp (_ded *PSStack )error {_bbfb ,_bbadb :=_ded .PopNumberAsFloat64 ();if _bbadb !=nil {return _bbadb ;};_cdd ,_bbadb :=_ded .PopNumberAsFloat64 ();if _bbadb !=nil {return _bbadb ;};if _ca .Abs (_bbfb )< 1&&_cdd < 0{return ErrUndefinedResult ;};_abba :=_ca .Pow (_cdd ,_bbfb );_bbadb =_ded .Push (MakeReal (_abba ));return _bbadb ;};
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_cfde :=PSBoolean {};_cfde .Val =val ;return &_cfde };func (_gd *PSOperand )DebugString ()string {return _dg .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_gd );};func (_bdec *PSOperand )or (_bacf *PSStack )error {_dac ,_dbgb :=_bacf .Pop ();if _dbgb !=nil {return _dbgb ;};_eedb ,_dbgb :=_bacf .Pop ();if _dbgb !=nil {return _dbgb ;};if _ccd ,_eccea :=_dac .(*PSBoolean );_eccea {_fed ,_adcc :=_eedb .(*PSBoolean );if !_adcc {return ErrTypeCheck ;};_dbgb =_bacf .Push (MakeBool (_ccd .Val ||_fed .Val ));return _dbgb ;};if _gaff ,_bebc :=_dac .(*PSInteger );_bebc {_cfcf ,_bgfb :=_eedb .(*PSInteger );if !_bgfb {return ErrTypeCheck ;};_dbgb =_bacf .Push (MakeInteger (_gaff .Val |_cfcf .Val ));return _dbgb ;};return ErrTypeCheck ;};func (_bba *PSOperand )ne (_ede *PSStack )error {_adbg :=_bba .eq (_ede );if _adbg !=nil {return _adbg ;};_adbg =_bba .not (_ede );return _adbg ;};func (_ced *PSOperand )cvr (_cfaf *PSStack )error {_afb ,_aff :=_cfaf .Pop ();if _aff !=nil {return _aff ;};if _gag ,_dea :=_afb .(*PSReal );_dea {_aff =_cfaf .Push (MakeReal (_gag .Val ));}else if _bc ,_bfad :=_afb .(*PSInteger );_bfad {_aff =_cfaf .Push (MakeReal (float64 (_bc .Val )));}else {return ErrTypeCheck ;};return _aff ;};
// Parse parses the postscript and store as a program that can be executed.
func (_defd *PSParser )Parse ()(*PSProgram ,error ){_defd .skipSpaces ();_cefb ,_egge :=_defd ._dcaf .Peek (2);if _egge !=nil {return nil ,_egge ;};if _cefb [0]!='{'{return nil ,_eg .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");};_bec ,_egge :=_defd .parseFunction ();if _egge !=nil &&_egge !=_d .EOF {return nil ,_egge ;};return _bec ,_egge ;};func (_dfed *PSOperand )ge (_fgg *PSStack )error {_cfd ,_add :=_fgg .PopNumberAsFloat64 ();if _add !=nil {return _add ;};_dcd ,_add :=_fgg .PopNumberAsFloat64 ();if _add !=nil {return _add ;};if _ca .Abs (_dcd -_cfd )< _b {_cdf :=_fgg .Push (MakeBool (true ));return _cdf ;}else if _dcd > _cfd {_fdc :=_fgg .Push (MakeBool (true ));return _fdc ;}else {_bfg :=_fgg .Push (MakeBool (false ));return _bfg ;};};func (_fbac *PSOperand )not (_ead *PSStack )error {_ggbg ,_gcbg :=_ead .Pop ();if _gcbg !=nil {return _gcbg ;};if _addd ,_gbc :=_ggbg .(*PSBoolean );_gbc {_gcbg =_ead .Push (MakeBool (!_addd .Val ));return _gcbg ;}else if _aga ,_bffbb :=_ggbg .(*PSInteger );_bffbb {_gcbg =_ead .Push (MakeInteger (^_aga .Val ));return _gcbg ;}else {return ErrTypeCheck ;};};func (_eba *PSOperand )abs (_bae *PSStack )error {_ab ,_beg :=_bae .Pop ();if _beg !=nil {return _beg ;};if _eef ,_dge :=_ab .(*PSReal );_dge {_bcb :=_eef .Val ;if _bcb < 0{_beg =_bae .Push (MakeReal (-_bcb ));}else {_beg =_bae .Push (MakeReal (_bcb ));};}else if _ceb ,_ceg :=_ab .(*PSInteger );_ceg {_cec :=_ceb .Val ;if _cec < 0{_beg =_bae .Push (MakeInteger (-_cec ));}else {_beg =_bae .Push (MakeInteger (_cec ));};}else {return ErrTypeCheck ;};return _beg ;};func (_be *PSInteger )DebugString ()string {return _df .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_be .Val );};func (_dfea *PSOperand )exch (_ccg *PSStack )error {_dad ,_badb :=_ccg .Pop ();if _badb !=nil {return _badb ;};_bged ,_badb :=_ccg .Pop ();if _badb !=nil {return _badb ;};_badb =_ccg .Push (_dad );if _badb !=nil {return _badb ;};_badb =_ccg .Push (_bged );return _badb ;};func (_cfa *PSOperand )idiv (_bdg *PSStack )error {_ebe ,_bdgc :=_bdg .Pop ();if _bdgc !=nil {return _bdgc ;};_dcf ,_bdgc :=_bdg .Pop ();if _bdgc !=nil {return _bdgc ;};_cef ,_cabc :=_ebe .(*PSInteger );if !_cabc {return ErrTypeCheck ;};if _cef .Val ==0{return ErrUndefinedResult ;};_gbb ,_cabc :=_dcf .(*PSInteger );if !_cabc {return ErrTypeCheck ;};_fag :=_gbb .Val /_cef .Val ;_bdgc =_bdg .Push (MakeInteger (_fag ));return _bdgc ;};func (_bege *PSParser )parseOperand ()(*PSOperand ,error ){var _bcge []byte ;for {_dbcf ,_cbef :=_bege ._dcaf .Peek (1);if _cbef !=nil {if _cbef ==_d .EOF {break ;};return nil ,_cbef ;};if _f .IsDelimiter (_dbcf [0]){break ;};if _f .IsWhiteSpace (_dbcf [0]){break ;};_gag ,_ :=_bege ._dcaf .ReadByte ();_bcge =append (_bcge ,_gag );};if len (_bcge )==0{return nil ,_eg .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 (_bcge )),nil ;};func (_ccff *PSOperand )truncate (_bcg *PSStack )error {_acfc ,_ffc :=_bcg .Pop ();if _ffc !=nil {return _ffc ;};if _babb ,_fbefa :=_acfc .(*PSReal );_fbefa {_begd :=int (_babb .Val );_ffc =_bcg .Push (MakeReal (float64 (_begd )));}else if _fcgg ,_eaf :=_acfc .(*PSInteger );_eaf {_ffc =_bcg .Push (MakeInteger (_fcgg .Val ));}else {return ErrTypeCheck ;};return _ffc ;};
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};
// Append appends an object to the PSProgram.
func (_fdd *PSProgram )Append (obj PSObject ){*_fdd =append (*_fdd ,obj )};
// Push pushes an object on top of the stack.
func (_aad *PSStack )Push (obj PSObject )error {if len (*_aad )> 100{return ErrStackOverflow ;};*_aad =append (*_aad ,obj );return nil ;};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};var ErrStackOverflow =_eg .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;func (_cda *PSOperand )ceiling (_fec *PSStack )error {_gddg ,_ed :=_fec .Pop ();if _ed !=nil {return _ed ;};if _dgcg ,_dec :=_gddg .(*PSReal );_dec {_ed =_fec .Push (MakeReal (_ca .Ceil (_dgcg .Val )));}else if _efg ,_gbe :=_gddg .(*PSInteger );_gbe {_ed =_fec .Push (MakeInteger (_efg .Val ));}else {_ed =ErrTypeCheck ;};return _ed ;};func (_cfc *PSOperand )add (_ddf *PSStack )error {_fe ,_dfce :=_ddf .Pop ();if _dfce !=nil {return _dfce ;};_bfc ,_dfce :=_ddf .Pop ();if _dfce !=nil {return _dfce ;};_fba ,_fc :=_fe .(*PSReal );_bd ,_dfe :=_fe .(*PSInteger );if !_fc &&!_dfe {return ErrTypeCheck ;};_fbae ,_dbg :=_bfc .(*PSReal );_cgd ,_fbb :=_bfc .(*PSInteger );if !_dbg &&!_fbb {return ErrTypeCheck ;};if _dfe &&_fbb {_ag :=_bd .Val +_cgd .Val ;_egb :=_ddf .Push (MakeInteger (_ag ));return _egb ;};var _dgb float64 ;if _fc {_dgb =_fba .Val ;}else {_dgb =float64 (_bd .Val );};if _dbg {_dgb +=_fbae .Val ;}else {_dgb +=float64 (_cgd .Val );};_dfce =_ddf .Push (MakeReal (_dgb ));return _dfce ;};var ErrTypeCheck =_eg .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");func (_dfc *PSReal )String ()string {return _df .Sprintf ("\u0025\u002e\u0035\u0066",_dfc .Val )};
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
func NewPSExecutor (program *PSProgram )*PSExecutor {_ce :=&PSExecutor {};_ce .Stack =NewPSStack ();_ce ._g =program ;return _ce ;};func (_fgd *PSOperand )cvi (_fa *PSStack )error {_cegf ,_bgf :=_fa .Pop ();if _bgf !=nil {return _bgf ;};if _dfd ,_gbd :=_cegf .(*PSReal );_gbd {_fee :=int (_dfd .Val );_bgf =_fa .Push (MakeInteger (_fee ));}else if _gef ,_abb :=_cegf .(*PSInteger );_abb {_gea :=_gef .Val ;_bgf =_fa .Push (MakeInteger (_gea ));}else {return ErrTypeCheck ;};return _bgf ;};func (_cdag *PSOperand )xor (_eddb *PSStack )error {_bada ,_feb :=_eddb .Pop ();if _feb !=nil {return _feb ;};_gda ,_feb :=_eddb .Pop ();if _feb !=nil {return _feb ;};if _cfcc ,_defb :=_bada .(*PSBoolean );_defb {_bfd ,_gddgf :=_gda .(*PSBoolean );if !_gddgf {return ErrTypeCheck ;};_feb =_eddb .Push (MakeBool (_cfcc .Val !=_bfd .Val ));return _feb ;};if _dca ,_babd :=_bada .(*PSInteger );_babd {_fef ,_bfge :=_gda .(*PSInteger );if !_bfge {return ErrTypeCheck ;};_feb =_eddb .Push (MakeInteger (_dca .Val ^_fef .Val ));return _feb ;};return ErrTypeCheck ;};
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_aafad :=PSParser {};_ceec :=_db .NewBuffer (content );_aafad ._dcaf =_c .NewReader (_ceec );return &_aafad ;};
// 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 _gb []float64 ;for _ ,_gf :=range objects {if _fa ,_fb :=_gf .(*PSInteger );_fb {_gb =append (_gb ,float64 (_fa .Val ));}else if _ag ,_cf :=_gf .(*PSReal );_cf {_gb =append (_gb ,_ag .Val );}else {return nil ,ErrTypeCheck ;};};return _gb ,nil ;};
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct{Stack *PSStack ;_bf *PSProgram ;};func (_abbg *PSOperand )ge (_dfae *PSStack )error {_dce ,_ddc :=_dfae .PopNumberAsFloat64 ();if _ddc !=nil {return _ddc ;};_fcc ,_ddc :=_dfae .PopNumberAsFloat64 ();if _ddc !=nil {return _ddc ;};if _c .Abs (_fcc -_dce )< _b {_abf :=_dfae .Push (MakeBool (true ));return _abf ;}else if _fcc > _dce {_fgg :=_dfae .Push (MakeBool (true ));return _fgg ;}else {_dedd :=_dfae .Push (MakeBool (false ));return _dedd ;};};func (_efe *PSBoolean )DebugString ()string {return _dg .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_efe .Val );};
// MakeReal returns a new PSReal object initialized with `val`.
func MakeReal (val float64 )*PSReal {_add :=PSReal {};_add .Val =val ;return &_add };
// Empty empties the stack.
func (_bcf *PSStack )Empty (){*_bcf =[]PSObject {}};
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_de *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_bd :=range objects {_cd :=_de .Stack .Push (_bd );if _cd !=nil {return nil ,_cd ;};};_cfe :=_de ._bf .Exec (_de .Stack );if _cfe !=nil {_f .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_cfe );return nil ,_cfe ;};_dfa :=[]PSObject (*_de .Stack );_de .Stack .Empty ();return _dfa ,nil ;};func (_cg *PSOperand )exp (_gddf *PSStack )error {_ca ,_gagb :=_gddf .PopNumberAsFloat64 ();if _gagb !=nil {return _gagb ;};_egg ,_gagb :=_gddf .PopNumberAsFloat64 ();if _gagb !=nil {return _gagb ;};if _c .Abs (_ca )< 1&&_egg < 0{return ErrUndefinedResult ;};_ac :=_c .Pow (_egg ,_ca );_gagb =_gddf .Push (MakeReal (_ac ));return _gagb ;};func (_adb *PSOperand )ln (_eccf *PSStack )error {_fdd ,_fbe :=_eccf .PopNumberAsFloat64 ();if _fbe !=nil {return _fbe ;};_ffe :=_c .Log (_fdd );_fbe =_eccf .Push (MakeReal (_ffe ));return _fbe ;};func (_cfa *PSOperand )abs (_ecc *PSStack )error {_ecce ,_aac :=_ecc .Pop ();if _aac !=nil {return _aac ;};if _aba ,_abe :=_ecce .(*PSReal );_abe {_ad :=_aba .Val ;if _ad < 0{_aac =_ecc .Push (MakeReal (-_ad ));}else {_aac =_ecc .Push (MakeReal (_ad ));};}else if _bb ,_gcd :=_ecce .(*PSInteger );_gcd {_eff :=_bb .Val ;if _eff < 0{_aac =_ecc .Push (MakeInteger (-_eff ));}else {_aac =_ecc .Push (MakeInteger (_eff ));};}else {return ErrTypeCheck ;};return _aac ;};func (_ab *PSProgram )Duplicate ()PSObject {_fg :=&PSProgram {};for _ ,_ba :=range *_ab {_fg .Append (_ba .Duplicate ());};return _fg ;};func (_dc *PSProgram )String ()string {_efc :="\u007b\u0020";for _ ,_bfa :=range *_dc {_efc +=_bfa .String ();_efc +="\u0020";};_efc +="\u007d";return _efc ;};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;var ErrStackOverflow =_g .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");var ErrRangeCheck =_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_dbc *PSOperand )le (_bgf *PSStack )error {_dbe ,_agb :=_bgf .PopNumberAsFloat64 ();if _agb !=nil {return _agb ;};_ebc ,_agb :=_bgf .PopNumberAsFloat64 ();if _agb !=nil {return _agb ;};if _c .Abs (_ebc -_dbe )< _b {_fcda :=_bgf .Push (MakeBool (true ));return _fcda ;}else if _ebc < _dbe {_ecg :=_bgf .Push (MakeBool (true ));return _ecg ;}else {_bea :=_bgf .Push (MakeBool (false ));return _bea ;};};
func PSObjectArrayToFloat64Array (objects []PSObject )([]float64 ,error ){var _dgf []float64 ;for _ ,_ggc :=range objects {if _da ,_cc :=_ggc .(*PSInteger );_cc {_dgf =append (_dgf ,float64 (_da .Val ));}else if _fg ,_gc :=_ggc .(*PSReal );_gc {_dgf =append (_dgf ,_fg .Val );}else {return nil ,ErrTypeCheck ;};};return _dgf ,nil ;};
// String returns a string representation of the stack.
func (_fce *PSStack )String ()string {_adg :="\u005b\u0020";for _ ,_aada :=range *_fce {_adg +=_aada .String ();_adg +="\u0020";};_adg +="\u005d";return _adg ;};func (_ga *PSOperand )String ()string {return _dg .Sprintf ("\u0025\u0073",*_ga )};func (_ffdd *PSOperand )gt (_cdg *PSStack )error {_ddca ,_cdc :=_cdg .PopNumberAsFloat64 ();if _cdc !=nil {return _cdc ;};_gega ,_cdc :=_cdg .PopNumberAsFloat64 ();if _cdc !=nil {return _cdc ;};if _c .Abs (_gega -_ddca )< _b {_gddb :=_cdg .Push (MakeBool (false ));return _gddb ;}else if _gega > _ddca {_fcga :=_cdg .Push (MakeBool (true ));return _fcga ;}else {_cb :=_cdg .Push (MakeBool (false ));return _cb ;};};
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
type PSProgram []PSObject ;func (_bgbc *PSOperand )ifelse (_gdda *PSStack )error {_dead ,_bee :=_gdda .Pop ();if _bee !=nil {return _bee ;};_eca ,_bee :=_gdda .Pop ();if _bee !=nil {return _bee ;};_cec ,_bee :=_gdda .Pop ();if _bee !=nil {return _bee ;};_bdc ,_cefa :=_dead .(*PSProgram );if !_cefa {return ErrTypeCheck ;};_bfbc ,_cefa :=_eca .(*PSProgram );if !_cefa {return ErrTypeCheck ;};_eegc ,_cefa :=_cec .(*PSBoolean );if !_cefa {return ErrTypeCheck ;};if _eegc .Val {_fdec :=_bfbc .Exec (_gdda );return _fdec ;};_bee =_bdc .Exec (_gdda );return _bee ;};func (_ece *PSOperand )lt (_cbf *PSStack )error {_eaa ,_beee :=_cbf .PopNumberAsFloat64 ();if _beee !=nil {return _beee ;};_ffab ,_beee :=_cbf .PopNumberAsFloat64 ();if _beee !=nil {return _beee ;};if _c .Abs (_ffab -_eaa )< _b {_cfc :=_cbf .Push (MakeBool (false ));return _cfc ;}else if _ffab < _eaa {_bgbe :=_cbf .Push (MakeBool (true ));return _bgbe ;}else {_dgcb :=_cbf .Push (MakeBool (false ));return _dgcb ;};};func (_aab *PSOperand )mod (_ead *PSStack )error {_afa ,_gdg :=_ead .Pop ();if _gdg !=nil {return _gdg ;};_bdcf ,_gdg :=_ead .Pop ();if _gdg !=nil {return _gdg ;};_aegb ,_deec :=_afa .(*PSInteger );if !_deec {return ErrTypeCheck ;};if _aegb .Val ==0{return ErrUndefinedResult ;};_aedc ,_deec :=_bdcf .(*PSInteger );if !_deec {return ErrTypeCheck ;};_dbgg :=_aedc .Val %_aegb .Val ;_gdg =_ead .Push (MakeInteger (_dbgg ));return _gdg ;};func (_bda *PSOperand )ceiling (_fga *PSStack )error {_gbc ,_adf :=_fga .Pop ();if _adf !=nil {return _adf ;};if _ee ,_dga :=_gbc .(*PSReal );_dga {_adf =_fga .Push (MakeReal (_c .Ceil (_ee .Val )));}else if _dad ,_bdaf :=_gbc .(*PSInteger );_bdaf {_adf =_fga .Push (MakeInteger (_dad .Val ));}else {_adf =ErrTypeCheck ;};return _adf ;};func (_ec *PSBoolean )String ()string {return _dg .Sprintf ("\u0025\u0076",_ec .Val )};
// Exec executes the operand `op` in the state specified by `stack`.
func (_ded *PSOperand )Exec (stack *PSStack )error {_gea :=ErrUnsupportedOperand ;switch *_ded {case "\u0061\u0062\u0073":_gea =_ded .abs (stack );case "\u0061\u0064\u0064":_gea =_ded .add (stack );case "\u0061\u006e\u0064":_gea =_ded .and (stack );case "\u0061\u0074\u0061\u006e":_gea =_ded .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_gea =_ded .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_gea =_ded .ceiling (stack );case "\u0063\u006f\u0070\u0079":_gea =_ded .copy (stack );case "\u0063\u006f\u0073":_gea =_ded .cos (stack );case "\u0063\u0076\u0069":_gea =_ded .cvi (stack );case "\u0063\u0076\u0072":_gea =_ded .cvr (stack );case "\u0064\u0069\u0076":_gea =_ded .div (stack );case "\u0064\u0075\u0070":_gea =_ded .dup (stack );case "\u0065\u0071":_gea =_ded .eq (stack );case "\u0065\u0078\u0063\u0068":_gea =_ded .exch (stack );case "\u0065\u0078\u0070":_gea =_ded .exp (stack );case "\u0066\u006c\u006fo\u0072":_gea =_ded .floor (stack );case "\u0067\u0065":_gea =_ded .ge (stack );case "\u0067\u0074":_gea =_ded .gt (stack );case "\u0069\u0064\u0069\u0076":_gea =_ded .idiv (stack );case "\u0069\u0066":_gea =_ded .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_gea =_ded .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_gea =_ded .index (stack );case "\u006c\u0065":_gea =_ded .le (stack );case "\u006c\u006f\u0067":_gea =_ded .log (stack );case "\u006c\u006e":_gea =_ded .ln (stack );case "\u006c\u0074":_gea =_ded .lt (stack );case "\u006d\u006f\u0064":_gea =_ded .mod (stack );case "\u006d\u0075\u006c":_gea =_ded .mul (stack );case "\u006e\u0065":_gea =_ded .ne (stack );case "\u006e\u0065\u0067":_gea =_ded .neg (stack );case "\u006e\u006f\u0074":_gea =_ded .not (stack );case "\u006f\u0072":_gea =_ded .or (stack );case "\u0070\u006f\u0070":_gea =_ded .pop (stack );case "\u0072\u006f\u0075n\u0064":_gea =_ded .round (stack );case "\u0072\u006f\u006c\u006c":_gea =_ded .roll (stack );case "\u0073\u0069\u006e":_gea =_ded .sin (stack );case "\u0073\u0071\u0072\u0074":_gea =_ded .sqrt (stack );case "\u0073\u0075\u0062":_gea =_ded .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_gea =_ded .truncate (stack );case "\u0078\u006f\u0072":_gea =_ded .xor (stack );};return _gea ;};func (_afc *PSReal )DebugString ()string {return _dg .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_afc .Val );};func (_eag *PSOperand )sin (_cegd *PSStack )error {_ade ,_gfa :=_cegd .PopNumberAsFloat64 ();if _gfa !=nil {return _gfa ;};_bcd :=_c .Sin (_ade *_c .Pi /180.0);_gfa =_cegd .Push (MakeReal (_bcd ));return _gfa ;};
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
func NewPSExecutor (program *PSProgram )*PSExecutor {_ge :=&PSExecutor {};_ge .Stack =NewPSStack ();_ge ._bf =program ;return _ge ;};
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_fedc :=PSParser {};_dbb :=_a .NewBuffer (content );_fedc ._bcgg =_ef .NewReader (_dbb );return &_fedc ;};func (_afcee *PSOperand )sqrt (_eeb *PSStack )error {_egd ,_bga :=_eeb .PopNumberAsFloat64 ();if _bga !=nil {return _bga ;};if _egd < 0{return ErrRangeCheck ;};_bgg :=_c .Sqrt (_egd );_bga =_eeb .Push (MakeReal (_bgg ));return _bga ;};
func (_dfcf *PSStack )String ()string {_ffa :="\u005b\u0020";for _ ,_cfcg :=range *_dfcf {_ffa +=_cfcg .String ();_ffa +="\u0020";};_ffa +="\u005d";return _ffa ;};var ErrUnsupportedOperand =_eg .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func _ggbb (_dffb int )int {if _dffb < 0{return -_dffb ;};return _dffb ;};func (_gcae *PSOperand )log (_cfde *PSStack )error {_gaf ,_aafa :=_cfde .PopNumberAsFloat64 ();if _aafa !=nil {return _aafa ;};_fbd :=_ca .Log10 (_gaf );_aafa =_cfde .Push (MakeReal (_fbd ));return _aafa ;};func (_ddc *PSReal )DebugString ()string {return _df .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_ddc .Val );};func (_de *PSOperand )Duplicate ()PSObject {_gga :=*_de ;return &_gga };
// Exec executes the program, typically leaving output values on the stack.
func (_fe *PSProgram )Exec (stack *PSStack )error {for _ ,_aad :=range *_fe {var _fbg error ;switch _dee :=_aad .(type ){case *PSInteger :_dbg :=_dee ;_fbg =stack .Push (_dbg );case *PSReal :_ceg :=_dee ;_fbg =stack .Push (_ceg );case *PSBoolean :_bff :=_dee ;_fbg =stack .Push (_bff );case *PSProgram :_ddb :=_dee ;_fbg =stack .Push (_ddb );case *PSOperand :_efgf :=_dee ;_fbg =_efgf .Exec (stack );default:return ErrTypeCheck ;};if _fbg !=nil {return _fbg ;};};return nil ;};func (_bg *PSReal )Duplicate ()PSObject {_dgc :=PSReal {};_dgc .Val =_bg .Val ;return &_dgc };func (_gbf *PSOperand )not (_gcf *PSStack )error {_acc ,_dgba :=_gcf .Pop ();if _dgba !=nil {return _dgba ;};if _dbac ,_afag :=_acc .(*PSBoolean );_afag {_dgba =_gcf .Push (MakeBool (!_dbac .Val ));return _dgba ;}else if _cefg ,_cfcb :=_acc .(*PSInteger );_cfcb {_dgba =_gcf .Push (MakeInteger (^_cefg .Val ));return _dgba ;}else {return ErrTypeCheck ;};};func (_eb *PSOperand )div (_bed *PSStack )error {_fba ,_fdg :=_bed .Pop ();if _fdg !=nil {return _fdg ;};_cea ,_fdg :=_bed .Pop ();if _fdg !=nil {return _fdg ;};_dgag ,_cca :=_fba .(*PSReal );_affe ,_efb :=_fba .(*PSInteger );if !_cca &&!_efb {return ErrTypeCheck ;};if _cca &&_dgag .Val ==0{return ErrUndefinedResult ;};if _efb &&_affe .Val ==0{return ErrUndefinedResult ;};_eccd ,_gfeg :=_cea .(*PSReal );_gfg ,_gbg :=_cea .(*PSInteger );if !_gfeg &&!_gbg {return ErrTypeCheck ;};var _bag float64 =0;if _gfeg {_bag =_eccd .Val ;}else {_bag =float64 (_gfg .Val );};if _cca {_bag /=_dgag .Val ;}else {_bag /=float64 (_affe .Val );};_fdg =_bed .Push (MakeReal (_bag ));return _fdg ;};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};func (_dfadg *PSOperand )dup (_fcg *PSStack )error {_ddd ,_ggd :=_fcg .Pop ();if _ggd !=nil {return _ggd ;};_ggd =_fcg .Push (_ddd );if _ggd !=nil {return _ggd ;};_ggd =_fcg .Push (_ddd .Duplicate ());return _ggd ;};
// PSBoolean represents a boolean value.
type PSBoolean struct{Val bool ;};func (_dca *PSOperand )atan (_be *PSStack )error {_bad ,_cdf :=_be .PopNumberAsFloat64 ();if _cdf !=nil {return _cdf ;};_gce ,_cdf :=_be .PopNumberAsFloat64 ();if _cdf !=nil {return _cdf ;};if _bad ==0{var _cef error ;if _gce < 0{_cef =_be .Push (MakeReal (270));}else {_cef =_be .Push (MakeReal (90));};return _cef ;};_afd :=_gce /_bad ;_ggf :=_c .Atan (_afd )*180/_c .Pi ;_cdf =_be .Push (MakeReal (_ggf ));return _cdf ;};const _b =0.000001;func (_db *PSInteger )Duplicate ()PSObject {_ea :=PSInteger {};_ea .Val =_db .Val ;return &_ea };func (_fbgf *PSOperand )cos (_ccc *PSStack )error {_aadf ,_eacd :=_ccc .PopNumberAsFloat64 ();if _eacd !=nil {return _eacd ;};_agd :=_c .Cos (_aadf *_c .Pi /180.0);_eacd =_ccc .Push (MakeReal (_agd ));return _eacd ;};func (_agcg *PSOperand )index (_fec *PSStack )error {_gab ,_fcd :=_fec .Pop ();if _fcd !=nil {return _fcd ;};_bbd ,_ecf :=_gab .(*PSInteger );if !_ecf {return ErrTypeCheck ;};if _bbd .Val < 0{return ErrRangeCheck ;};if _bbd .Val > len (*_fec )-1{return ErrStackUnderflow ;};_fcf :=(*_fec )[len (*_fec )-1-_bbd .Val ];_fcd =_fec .Push (_fcf .Duplicate ());return _fcd ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_bcgg *_ef .Reader };func (_edc *PSOperand )floor (_fabb *PSStack )error {_bcg ,_cge :=_fabb .Pop ();if _cge !=nil {return _cge ;};if _edb ,_fafb :=_bcg .(*PSReal );_fafb {_cge =_fabb .Push (MakeReal (_c .Floor (_edb .Val )));}else if _cfbc ,_bffb :=_bcg .(*PSInteger );_bffb {_cge =_fabb .Push (MakeInteger (_cfbc .Val ));}else {return ErrTypeCheck ;};return _cge ;};func (_eg *PSOperand )Duplicate ()PSObject {_cdb :=*_eg ;return &_cdb };func (_abbd *PSParser )parseOperand ()(*PSOperand ,error ){var _abeb []byte ;for {_gcfa ,_dfff :=_abbd ._bcgg .Peek (1);if _dfff !=nil {if _dfff ==_e .EOF {break ;};return nil ,_dfff ;};if _df .IsDelimiter (_gcfa [0]){break ;};if _df .IsWhiteSpace (_gcfa [0]){break ;};_bdd ,_ :=_abbd ._bcgg .ReadByte ();_abeb =append (_abeb ,_bdd );};if len (_abeb )==0{return nil ,_g .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 (_abeb )),nil ;};func (_bfg *PSOperand )add (_da *PSStack )error {_fbd ,_dgb :=_da .Pop ();if _dgb !=nil {return _dgb ;};_efcf ,_dgb :=_da .Pop ();if _dgb !=nil {return _dgb ;};_dcc ,_dccc :=_fbd .(*PSReal );_eac ,_aed :=_fbd .(*PSInteger );if !_dccc &&!_aed {return ErrTypeCheck ;};_eacg ,_gfc :=_efcf .(*PSReal );_efcfb ,_fad :=_efcf .(*PSInteger );if !_gfc &&!_fad {return ErrTypeCheck ;};if _aed &&_fad {_cfb :=_eac .Val +_efcfb .Val ;_dfg :=_da .Push (MakeInteger (_cfb ));return _dfg ;};var _deg float64 =0;if _dccc {_deg =_dcc .Val ;}else {_deg =float64 (_eac .Val );};if _gfc {_deg +=_eacg .Val ;}else {_deg +=float64 (_efcfb .Val );};_dgb =_da .Push (MakeReal (_deg ));return _dgb ;};func (_dgfe *PSParser )parseNumber ()(PSObject ,error ){_gbee ,_cae :=_df .ParseNumber (_dgfe ._bcgg );if _cae !=nil {return nil ,_cae ;};switch _aacb :=_gbee .(type ){case *_df .PdfObjectFloat :return MakeReal (float64 (*_aacb )),nil ;case *_df .PdfObjectInteger :return MakeInteger (int (*_aacb )),nil ;};return nil ,_dg .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_gbee );};func (_cgf *PSOperand )round (_efae *PSStack )error {_ccb ,_cfaa :=_efae .Pop ();if _cfaa !=nil {return _cfaa ;};if _cedf ,_fdb :=_ccb .(*PSReal );_fdb {_cfaa =_efae .Push (MakeReal (_c .Floor (_cedf .Val +0.5)));}else if _cbe ,_cfag :=_ccb .(*PSInteger );_cfag {_cfaa =_efae .Push (MakeInteger (_cbe .Val ));}else {return ErrTypeCheck ;};return _cfaa ;};func (_dda *PSOperand )truncate (_dcac *PSStack )error {_ceae ,_ecfe :=_dcac .Pop ();if _ecfe !=nil {return _ecfe ;};if _bfd ,_dbgf :=_ceae .(*PSReal );_dbgf {_aeb :=int (_bfd .Val );_ecfe =_dcac .Push (MakeReal (float64 (_aeb )));}else if _fea ,_dace :=_ceae .(*PSInteger );_dace {_ecfe =_dcac .Push (MakeInteger (_fea .Val ));}else {return ErrTypeCheck ;};return _ecfe ;};func (_dagb *PSParser )parseBool ()(*PSBoolean ,error ){_cbb ,_eded :=_dagb ._bcgg .Peek (4);if _eded !=nil {return MakeBool (false ),_eded ;};if (len (_cbb )>=4)&&(string (_cbb [:4])=="\u0074\u0072\u0075\u0065"){_dagb ._bcgg .Discard (4);return MakeBool (true ),nil ;};_cbb ,_eded =_dagb ._bcgg .Peek (5);if _eded !=nil {return MakeBool (false ),_eded ;};if (len (_cbb )>=5)&&(string (_cbb [:5])=="\u0066\u0061\u006cs\u0065"){_dagb ._bcgg .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_g .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};func (_dcf *PSOperand )neg (_cee *PSStack )error {_aca ,_efde :=_cee .Pop ();if _efde !=nil {return _efde ;};if _dgbb ,_ebab :=_aca .(*PSReal );_ebab {_efde =_cee .Push (MakeReal (-_dgbb .Val ));return _efde ;}else if _fcb ,_beb :=_aca .(*PSInteger );_beb {_efde =_cee .Push (MakeInteger (-_fcb .Val ));return _efde ;}else {return ErrTypeCheck ;};};func (_afg *PSOperand )bitshift (_ecb *PSStack )error {_aee ,_fbga :=_ecb .PopInteger ();if _fbga !=nil {return _fbga ;};_gceg ,_fbga :=_ecb .PopInteger ();if _fbga !=nil {return _fbga ;};var _dff int ;if _aee >=0{_dff =_gceg <<uint (_aee );}else {_dff =_gceg >>uint (-_aee );};_fbga =_ecb .Push (MakeInteger (_dff ));return _fbga ;};func (_gc *PSBoolean )Duplicate ()PSObject {_efg :=PSBoolean {};_efg .Val =_gc .Val ;return &_efg };func (_deeb *PSOperand )pop (_dde *PSStack )error {_ ,_afga :=_dde .Pop ();if _afga !=nil {return _afga ;};return nil ;};
func (_ee *PSProgram )Exec (stack *PSStack )error {for _ ,_bf :=range *_ee {var _fb error ;switch _ced :=_bf .(type ){case *PSInteger :_bab :=_ced ;_fb =stack .Push (_bab );case *PSReal :_cb :=_ced ;_fb =stack .Push (_cb );case *PSBoolean :_efb :=_ced ;_fb =stack .Push (_efb );case *PSProgram :_fbe :=_ced ;_fb =stack .Push (_fbe );case *PSOperand :_cg :=_ced ;_fb =_cg .Exec (stack );default:return ErrTypeCheck ;};if _fb !=nil {return _fb ;};};return nil ;};func (_def *PSOperand )mod (_cagd *PSStack )error {_aab ,_caa :=_cagd .Pop ();if _caa !=nil {return _caa ;};_bdcg ,_caa :=_cagd .Pop ();if _caa !=nil {return _caa ;};_edf ,_faae :=_aab .(*PSInteger );if !_faae {return ErrTypeCheck ;};if _edf .Val ==0{return ErrUndefinedResult ;};_cee ,_faae :=_bdcg .(*PSInteger );if !_faae {return ErrTypeCheck ;};_aeea :=_cee .Val %_edf .Val ;_caa =_cagd .Push (MakeInteger (_aeea ));return _caa ;};func (_agb *PSOperand )cos (_aff *PSStack )error {_agbg ,_ega :=_aff .PopNumberAsFloat64 ();if _ega !=nil {return _ega ;};_bgc :=_ca .Cos (_agbg *_ca .Pi /180.0);_ega =_aff .Push (MakeReal (_bgc ));return _ega ;};func (_dbc *PSOperand )and (_bdb *PSStack )error {_gedd ,_bge :=_bdb .Pop ();if _bge !=nil {return _bge ;};_cecg ,_bge :=_bdb .Pop ();if _bge !=nil {return _bge ;};if _cga ,_dfeg :=_gedd .(*PSBoolean );_dfeg {_bfe ,_efe :=_cecg .(*PSBoolean );if !_efe {return ErrTypeCheck ;};_bge =_bdb .Push (MakeBool (_cga .Val &&_bfe .Val ));return _bge ;};if _ad ,_cbg :=_gedd .(*PSInteger );_cbg {_dba ,_gdd :=_cecg .(*PSInteger );if !_gdd {return ErrTypeCheck ;};_bge =_bdb .Push (MakeInteger (_ad .Val &_dba .Val ));return _bge ;};return ErrTypeCheck ;};

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