prepare release

This commit is contained in:
UniDoc Build 2020-10-05 19:28:24 +00:00
parent 6ea4d7271f
commit 87cbc66cbd
44 changed files with 5625 additions and 5625 deletions

File diff suppressed because one or more lines are too long

View File

@ -10,93 +10,93 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package common contains common properties used by the subpackages.
package common ;import (_e "fmt";_ec "io";_gb "os";_g "path/filepath";_ab "runtime";_a "time";);
// DummyLogger does nothing.
type DummyLogger struct{};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_dg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _dg .LogLevel >=level };func UtcTimeFormat (t _a .Time )string {return t .Format (_ccc )+"\u0020\u0055\u0054\u0043"};const _beg =9;const Version ="\u0033\u002e\u0031\u0032\u002e\u0031";
// Error logs error message.
func (_fb ConsoleLogger )Error (format string ,args ...interface{}){if _fb .LogLevel >=LogLevelError {_ag :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_fb .output (_gb .Stdout ,_ag ,format ,args ...);};};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
package common ;import (_e "fmt";_fe "io";_b "os";_eb "path/filepath";_fg "runtime";_c "time";);const _ede =2020;func UtcTimeFormat (t _c .Time )string {return t .Format (_ff )+"\u0020\u0055\u0054\u0043"};
// Info logs info message.
func (_ca ConsoleLogger )Info (format string ,args ...interface{}){if _ca .LogLevel >=LogLevelInfo {_abfg :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ca .output (_gb .Stdout ,_abfg ,format ,args ...);};};var ReleasedAt =_a .Date (_abc ,_beg ,_eeef ,_ce ,_eb ,0,0,_a .UTC );
func (_fed ConsoleLogger )Info (format string ,args ...interface{}){if _fed .LogLevel >=LogLevelInfo {_gf :="\u005bI\u004e\u0046\u004f\u005d\u0020";_fed .output (_b .Stdout ,_gf ,format ,args ...);};};
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};
// Trace logs trace message.
func (_ab WriterLogger )Trace (format string ,args ...interface{}){if _ab .LogLevel >=LogLevelTrace {_bde :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ab .logToWriter (_ab .Output ,_bde ,format ,args ...);};};func (_fd ConsoleLogger )output (_ca _fe .Writer ,_ccf string ,_ga string ,_ec ...interface{}){_bb (_ca ,_ccf ,_ga ,_ec ...);};
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_bb WriterLogger )IsLogLevel (level LogLevel )bool {return _bb .LogLevel >=level };func (_aa ConsoleLogger )output (_bd _ec .Writer ,_fa string ,_eee string ,_bga ...interface{}){_eed (_bd ,_fa ,_eee ,_bga ...);};
func (_bd WriterLogger )IsLogLevel (level LogLevel )bool {return _bd .LogLevel >=level };
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// LogLevel is the verbosity level for logging.
type LogLevel int ;var Log Logger =DummyLogger {};func _eed (_cc _ec .Writer ,_dbg string ,_dcd string ,_dca ...interface{}){_ ,_be ,_bef ,_dce :=_ab .Caller (3);if !_dce {_be ="\u003f\u003f\u003f";_bef =0;}else {_be =_g .Base (_be );};_gdf :=_e .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_dbg ,_be ,_bef )+_dcd +"\u000a";_e .Fprintf (_cc ,_gdf ,_dca ...);};
type LogLevel int ;
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};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 (_baa ConsoleLogger )IsLogLevel (level LogLevel )bool {return _baa .LogLevel >=level };func _bb (_bag _fe .Writer ,_bdb string ,_fb string ,_ebc ...interface{}){_ ,_fbc ,_ecb ,_gbc :=_fg .Caller (3);if !_gbc {_fbc ="\u003f\u003f\u003f";_ecb =0;}else {_fbc =_eb .Base (_fbc );};_aaf :=_e .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bdb ,_fbc ,_ecb )+_fb +"\u000a";_e .Fprintf (_bag ,_aaf ,_ebc ...);};const _bba =18;
// Notice logs notice message.
func (_gec WriterLogger )Notice (format string ,args ...interface{}){if _gec .LogLevel >=LogLevelNotice {_cg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_gec .logToWriter (_gec .Output ,_cg ,format ,args ...);};};
// Debug logs debug message.
func (_ag ConsoleLogger )Debug (format string ,args ...interface{}){if _ag .LogLevel >=LogLevelDebug {_ae :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ag .output (_b .Stdout ,_ae ,format ,args ...);};};
// Warning logs warning message.
func (_bf ConsoleLogger )Warning (format string ,args ...interface{}){if _bf .LogLevel >=LogLevelWarning {_dd :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_bf .output (_b .Stdout ,_dd ,format ,args ...);};};
// Info logs info message.
func (_ecd WriterLogger )Info (format string ,args ...interface{}){if _ecd .LogLevel >=LogLevelInfo {_gd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ecd .logToWriter (_ecd .Output ,_gd ,format ,args ...);};};const _ff ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Notice logs notice message.
func (_bae ConsoleLogger )Notice (format string ,args ...interface{}){if _bae .LogLevel >=LogLevelNotice {_de :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bae .output (_b .Stdout ,_de ,format ,args ...);};};func (_da WriterLogger )logToWriter (_cge _fe .Writer ,_fec string ,_aba string ,_gbg ...interface{}){_bb (_cge ,_fec ,_aba ,_gbg );};
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};
// Error logs error message.
func (_bcg WriterLogger )Error (format string ,args ...interface{}){if _bcg .LogLevel >=LogLevelError {_fce :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_bcg .logToWriter (_bcg .Output ,_fce ,format ,args ...);};};
// Warning logs warning message.
func (_ac ConsoleLogger )Warning (format string ,args ...interface{}){if _ac .LogLevel >=LogLevelWarning {_ba :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ac .output (_gb .Stdout ,_ba ,format ,args ...);};};
// Notice logs notice message.
func (_bab WriterLogger )Notice (format string ,args ...interface{}){if _bab .LogLevel >=LogLevelNotice {_eca :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bab .logToWriter (_bab .Output ,_eca ,format ,args ...);};};
// Warning logs warning message.
func (_ecg WriterLogger )Warning (format string ,args ...interface{}){if _ecg .LogLevel >=LogLevelWarning {_caa :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ecg .logToWriter (_ecg .Output ,_caa ,format ,args ...);};};const _eeef =28;
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_ed string ,_ad ...interface{});Warning (_ee string ,_ef ...interface{});Notice (_gg string ,_c ...interface{});Info (_abf string ,_b ...interface{});Debug (_cd string ,_d ...interface{});Trace (_bc string ,_fc ...interface{});IsLogLevel (_edf LogLevel )bool ;};
// Trace logs trace message.
func (_geg WriterLogger )Trace (format string ,args ...interface{}){if _geg .LogLevel >=LogLevelTrace {_gf :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_geg .logToWriter (_geg .Output ,_gf ,format ,args ...);};};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// Notice logs notice message.
func (_da ConsoleLogger )Notice (format string ,args ...interface{}){if _da .LogLevel >=LogLevelNotice {_gc :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_da .output (_gb .Stdout ,_gc ,format ,args ...);};};const _abc =2020;
// Info logs info message.
func (_dc WriterLogger )Info (format string ,args ...interface{}){if _dc .LogLevel >=LogLevelInfo {_bdc :="\u005bI\u004e\u0046\u004f\u005d\u0020";_dc .logToWriter (_dc .Output ,_bdc ,format ,args ...);};};const _ccc ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Debug logs debug message.
func (_fe ConsoleLogger )Debug (format string ,args ...interface{}){if _fe .LogLevel >=LogLevelDebug {_bg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_fe .output (_gb .Stdout ,_bg ,format ,args ...);};};
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};const _ce =21;
// Debug logs debug message.
func (_ge WriterLogger )Debug (format string ,args ...interface{}){if _ge .LogLevel >=LogLevelDebug {_dgg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ge .logToWriter (_ge .Output ,_dgg ,format ,args ...);};};
// Trace logs trace message.
func (_gd ConsoleLogger )Trace (format string ,args ...interface{}){if _gd .LogLevel >=LogLevelTrace {_af :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gd .output (_gb .Stdout ,_af ,format ,args ...);};};func (_gdb WriterLogger )logToWriter (_fg _ec .Writer ,_dcf string ,_db string ,_cae ...interface{}){_eed (_fg ,_dcf ,_db ,_cae );};
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};
func (_a ConsoleLogger )Error (format string ,args ...interface{}){if _a .LogLevel >=LogLevelError {_ceg :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_a .output (_b .Stdout ,_ceg ,format ,args ...);};};
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _ec .Writer )*WriterLogger {_aba :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_aba ;};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
// Warning logs warning message.
func (_ccb WriterLogger )Warning (format string ,args ...interface{}){if _ccb .LogLevel >=LogLevelWarning {_ge :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ccb .logToWriter (_ccb .Output ,_ge ,format ,args ...);};};
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };const _eb =50;
func SetLogger (logger Logger ){Log =logger };const _feg =45;
// Debug logs debug message.
func (_gb WriterLogger )Debug (format string ,args ...interface{}){if _gb .LogLevel >=LogLevelDebug {_ea :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_gb .logToWriter (_gb .Output ,_ea ,format ,args ...);};};
// Trace logs trace message.
func (_dca ConsoleLogger )Trace (format string ,args ...interface{}){if _dca .LogLevel >=LogLevelTrace {_bab :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_dca .output (_b .Stdout ,_bab ,format ,args ...);};};
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};const Version ="\u0033\u002e\u0031\u0032\u002e\u0032";var ReleasedAt =_c .Date (_ede ,_ffc ,_be ,_bba ,_feg ,0,0,_c .UTC );
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _fe .Writer )*WriterLogger {_fgd :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_fgd ;};const _ffc =10;var Log Logger =DummyLogger {};
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_eg string ,_fea ...interface{});Warning (_ba string ,_g ...interface{});Notice (_fa string ,_fead ...interface{});Info (_ce string ,_fc ...interface{});Debug (_fga string ,_d ...interface{});Trace (_dc string ,_ed ...interface{});IsLogLevel (_cc LogLevel )bool ;};
// WriterLogger is the logger that writes data to the Output writer
type WriterLogger struct{LogLevel LogLevel ;Output _ec .Writer ;};
type WriterLogger struct{LogLevel LogLevel ;Output _fe .Writer ;};
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
// Error logs error message.
func (_df WriterLogger )Error (format string ,args ...interface{}){if _df .LogLevel >=LogLevelError {_cd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_df .logToWriter (_df .Output ,_cd ,format ,args ...);};};
// DummyLogger does nothing.
type DummyLogger struct{};const _be =5;
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};

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 (_g "fmt";_c "github.com/unidoc/unipdf/v3/contentstream";_f "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/transform";_bg "github.com/unidoc/unipdf/v3/model";_b "math";);
package draw ;import (_g "fmt";_c "github.com/unidoc/unipdf/v3/contentstream";_ba "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/transform";_d "github.com/unidoc/unipdf/v3/model";_bd "math";);
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_ggd BoundingBox )ToPdfRectangle ()*_bg .PdfRectangle {return &_bg .PdfRectangle {Llx :_ggd .X ,Lly :_ggd .Y ,Urx :_ggd .X +_ggd .Width ,Ury :_ggd .Y +_ggd .Height };};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_gd Path )RemovePoint (number int )Path {if number < 1||number > len (_gd .Points ){return _gd ;};_cbe :=number -1;_gd .Points =append (_gd .Points [:_cbe ],_gd .Points [_cbe +1:]...);return _gd ;};
// 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 (_aef BasicLine )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){_cfbe :=_aef .LineWidth ;_abbg :=NewPath ();_abbg =_abbg .AppendPoint (NewPoint (_aef .X1 ,_aef .Y1 ));_abbg =_abbg .AppendPoint (NewPoint (_aef .X2 ,_aef .Y2 ));_acd :=_c .NewContentCreator ();_dcg :=_abbg .GetBoundingBox ();DrawPathWithCreator (_abbg ,_acd );if _aef .LineStyle ==LineStyleDashed {_acd .Add_d ([]int64 {1,1},0);};_acd .Add_RG (_aef .LineColor .R (),_aef .LineColor .G (),_aef .LineColor .B ()).Add_w (_cfbe ).Add_S ().Add_Q ();return _acd .Bytes (),_dcg .ToPdfRectangle (),nil ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// 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 *_d .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// FlipY flips the sign of the Dy component of the vector.
func (_gcac Vector )FlipY ()Vector {_gcac .Dy =-_gcac .Dy ;return _gcac };
// 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 ,*_d .PdfRectangle ,error ){_ge :=_c .NewContentCreator ();_ge .Add_q ();_fga .FillEnabled =_fga .FillEnabled &&_fga .FillColor !=nil ;if _fga .FillEnabled {_ge .Add_rg (_fga .FillColor .R (),_fga .FillColor .G (),_fga .FillColor .B ());};_fga .BorderEnabled =_fga .BorderEnabled &&_fga .BorderColor !=nil ;if _fga .BorderEnabled {_ge .Add_RG (_fga .BorderColor .R (),_fga .BorderColor .G (),_fga .BorderColor .B ());_ge .Add_w (_fga .BorderWidth );};if len (gsName )> 1{_ge .Add_gs (_ba .PdfObjectName (gsName ));};_eec :=NewPath ();for _ ,_fge :=range _fga .Points {for _cegf ,_cf :=range _fge {_eec =_eec .AppendPoint (_cf );if _cegf ==0{_ge .Add_m (_cf .X ,_cf .Y );}else {_ge .Add_l (_cf .X ,_cf .Y );};};_ge .Add_h ();};if _fga .FillEnabled &&_fga .BorderEnabled {_ge .Add_B ();}else if _fga .FillEnabled {_ge .Add_f ();}else if _fga .BorderEnabled {_ge .Add_S ();};_ge .Add_Q ();return _ge .Bytes (),_eec .GetBoundingBox ().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 *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_d .PdfColorDeviceRGB ;BorderWidth float64 ;};
// 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 {_dab :=Vector {};_dab .Dx =dx ;_dab .Dy =dy ;return _dab };
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_eb Path )RemovePoint (number int )Path {if number < 1||number > len (_eb .Points ){return _eb ;};_eeb :=number -1;_eb .Points =append (_eb .Points [:_eeb ],_eb .Points [_eeb +1:]...);return _eb ;};
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_d .PdfColorDeviceRGB ;};
// AppendPoint adds the specified point to the path.
func (_ed Path )AppendPoint (point Point )Path {_ed .Points =append (_ed .Points ,point );return _ed };
// Offset shifts the Bezier path with the specified offsets.
func (_ecf CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _dg ,_ca :=range _ecf .Curves {_ecf .Curves [_dg ]=_ca .AddOffsetXY (offX ,offY );};return _ecf ;};func (_gab Point )String ()string {return _g .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_gab .X ,_gab .Y );};
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_bg :=CubicBezierPath {};_bg .Curves =[]CubicBezierCurve {};return _bg ;};
// 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 (_cgc Line )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_abe ,_aae :=_cgc .X1 ,_cgc .X2 ;_ecc ,_ad :=_cgc .Y1 ,_cgc .Y2 ;_fd :=_ad -_ecc ;_cce :=_aae -_abe ;_cee :=_bd .Atan2 (_fd ,_cce );L :=_bd .Sqrt (_bd .Pow (_cce ,2.0)+_bd .Pow (_fd ,2.0));_abec :=_cgc .LineWidth ;_fc :=_bd .Pi ;_cfe :=1.0;if _cce < 0{_cfe *=-1.0;};if _fd < 0{_cfe *=-1.0;};VsX :=_cfe *(-_abec /2*_bd .Cos (_cee +_fc /2));VsY :=_cfe *(-_abec /2*_bd .Sin (_cee +_fc /2)+_abec *_bd .Sin (_cee +_fc /2));V1X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2);V1Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2);V2X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2)+L *_bd .Cos (_cee );V2Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2)+L *_bd .Sin (_cee );V3X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2)+L *_bd .Cos (_cee )+_abec *_bd .Cos (_cee -_fc /2);V3Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2)+L *_bd .Sin (_cee )+_abec *_bd .Sin (_cee -_fc /2);V4X :=VsX +_abec /2*_bd .Cos (_cee -_fc /2);V4Y :=VsY +_abec /2*_bd .Sin (_cee -_fc /2);_eee :=NewPath ();_eee =_eee .AppendPoint (NewPoint (V1X ,V1Y ));_eee =_eee .AppendPoint (NewPoint (V2X ,V2Y ));_eee =_eee .AppendPoint (NewPoint (V3X ,V3Y ));_eee =_eee .AppendPoint (NewPoint (V4X ,V4Y ));_cdg :=_cgc .LineEndingStyle1 ;_dba :=_cgc .LineEndingStyle2 ;_df :=3*_abec ;_edb :=3*_abec ;_cfc :=(_edb -_abec )/2;if _dba ==LineEndingStyleArrow {_ebe :=_eee .GetPointNumber (2);_cca :=NewVectorPolar (_df ,_cee +_fc );_fcc :=_ebe .AddVector (_cca );_ace :=NewVectorPolar (_edb /2,_cee +_fc /2);_dea :=NewVectorPolar (_df ,_cee );_gga :=NewVectorPolar (_cfc ,_cee +_fc /2);_ag :=_fcc .AddVector (_gga );_daf :=_dea .Add (_ace .Flip ());_dbe :=_ag .AddVector (_daf );_fdg :=_ace .Scale (2).Flip ().Add (_daf .Flip ());_dbd :=_dbe .AddVector (_fdg );_ccae :=_fcc .AddVector (NewVectorPolar (_abec ,_cee -_fc /2));_ebc :=NewPath ();_ebc =_ebc .AppendPoint (_eee .GetPointNumber (1));_ebc =_ebc .AppendPoint (_fcc );_ebc =_ebc .AppendPoint (_ag );_ebc =_ebc .AppendPoint (_dbe );_ebc =_ebc .AppendPoint (_dbd );_ebc =_ebc .AppendPoint (_ccae );_ebc =_ebc .AppendPoint (_eee .GetPointNumber (4));_eee =_ebc ;};if _cdg ==LineEndingStyleArrow {_dbg :=_eee .GetPointNumber (1);_aaea :=_eee .GetPointNumber (_eee .Length ());_gaa :=NewVectorPolar (_abec /2,_cee +_fc +_fc /2);_bac :=_dbg .AddVector (_gaa );_feaa :=NewVectorPolar (_df ,_cee ).Add (NewVectorPolar (_edb /2,_cee +_fc /2));_aga :=_bac .AddVector (_feaa );_cfed :=NewVectorPolar (_cfc ,_cee -_fc /2);_ceb :=_aga .AddVector (_cfed );_fdb :=NewVectorPolar (_df ,_cee );_adc :=_aaea .AddVector (_fdb );_gafd :=NewVectorPolar (_cfc ,_cee +_fc +_fc /2);_be :=_adc .AddVector (_gafd );_ccg :=_bac ;_ggg :=NewPath ();_ggg =_ggg .AppendPoint (_bac );_ggg =_ggg .AppendPoint (_aga );_ggg =_ggg .AppendPoint (_ceb );for _ ,_cfd :=range _eee .Points [1:len (_eee .Points )-1]{_ggg =_ggg .AppendPoint (_cfd );};_ggg =_ggg .AppendPoint (_adc );_ggg =_ggg .AppendPoint (_be );_ggg =_ggg .AppendPoint (_ccg );_eee =_ggg ;};_eff :=_c .NewContentCreator ();_eff .Add_q ().Add_rg (_cgc .LineColor .R (),_cgc .LineColor .G (),_cgc .LineColor .B ());if len (gsName )> 1{_eff .Add_gs (_ba .PdfObjectName (gsName ));};_eee =_eee .Offset (_cgc .X1 ,_cgc .Y1 );_ade :=_eee .GetBoundingBox ();DrawPathWithCreator (_eee ,_eff );if _cgc .LineStyle ==LineStyleDashed {_eff .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_eff .Add_f ().Add_Q ();};return _eff .Bytes (),_ade .ToPdfRectangle (),nil ;};
// AddVector adds vector to a point.
func (_aff Point )AddVector (v Vector )Point {_aff .X +=v .Dx ;_aff .Y +=v .Dy ;return _aff };const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_da BoundingBox )ToPdfRectangle ()*_d .PdfRectangle {return &_d .PdfRectangle {Llx :_da .X ,Lly :_da .Y ,Urx :_da .X +_da .Width ,Ury :_da .Y +_da .Height };};
// 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 {_efd :=Vector {};_efd .Dx =b .X -a .X ;_efd .Dy =b .Y -a .Y ;return _efd ;};
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;
// Scale scales the vector by the specified factor.
func (_gce Vector )Scale (factor float64 )Vector {_gfa :=_gce .Magnitude ();_bae :=_gce .GetPolarAngle ();_gce .Dx =factor *_gfa *_bd .Cos (_bae );_gce .Dy =factor *_gfa *_bd .Sin (_bae );return _gce ;};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_ec CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_ec .P0 .X +=offX ;_ec .P1 .X +=offX ;_ec .P2 .X +=offX ;_ec .P3 .X +=offX ;_ec .P0 .Y +=offY ;_ec .P1 .Y +=offY ;_ec .P2 .Y +=offY ;_ec .P3 .Y +=offY ;return _ec ;};
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// FlipX flips the sign of the Dx component of the vector.
func (_ea Vector )FlipX ()Vector {_ea .Dx =-_ea .Dx ;return _ea };
// 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 (_gffe BasicLine )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_dfd :=_gffe .LineWidth ;_bfa :=NewPath ();_bfa =_bfa .AppendPoint (NewPoint (_gffe .X1 ,_gffe .Y1 ));_bfa =_bfa .AppendPoint (NewPoint (_gffe .X2 ,_gffe .Y2 ));_beg :=_c .NewContentCreator ();_bdag :=_bfa .GetBoundingBox ();DrawPathWithCreator (_bfa ,_beg );if _gffe .LineStyle ==LineStyleDashed {_beg .Add_d ([]int64 {1,1},0);};_beg .Add_RG (_gffe .LineColor .R (),_gffe .LineColor .G (),_gffe .LineColor .B ()).Add_w (_dfd ).Add_S ().Add_Q ();return _beg .Bytes (),_bdag .ToPdfRectangle (),nil ;};
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_cda Rectangle )ToPdfRectangle ()*_bg .PdfRectangle {return &_bg .PdfRectangle {Llx :_cda .X ,Lly :_cda .Y ,Urx :_cda .X +_cda .Width ,Ury :_cda .Y +_cda .Height };};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
func (_cbe Rectangle )ToPdfRectangle ()*_d .PdfRectangle {return &_d .PdfRectangle {Llx :_cbe .X ,Lly :_cbe .Y ,Urx :_cbe .X +_cbe .Width ,Ury :_cbe .Y +_cbe .Height };};
// AppendCurve appends the specified Bezier curve to the path.
func (_ef CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ef .Curves =append (_ef .Curves ,curve );return _ef ;};
// Copy returns a clone of the path.
func (_eg Path )Copy ()Path {_fg :=Path {};_fg .Points =[]Point {};for _ ,_ecd :=range _eg .Points {_fg .Points =append (_fg .Points ,_ecd );};return _fg ;};
// 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 (_gfe Rectangle )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_gaf :=NewPath ();_gaf =_gaf .AppendPoint (NewPoint (0,0));_gaf =_gaf .AppendPoint (NewPoint (0,_gfe .Height ));_gaf =_gaf .AppendPoint (NewPoint (_gfe .Width ,_gfe .Height ));_gaf =_gaf .AppendPoint (NewPoint (_gfe .Width ,0));_gaf =_gaf .AppendPoint (NewPoint (0,0));if _gfe .X !=0||_gfe .Y !=0{_gaf =_gaf .Offset (_gfe .X ,_gfe .Y );};_fea :=_c .NewContentCreator ();_fea .Add_q ();if _gfe .FillEnabled {_fea .Add_rg (_gfe .FillColor .R (),_gfe .FillColor .G (),_gfe .FillColor .B ());};if _gfe .BorderEnabled {_fea .Add_RG (_gfe .BorderColor .R (),_gfe .BorderColor .G (),_gfe .BorderColor .B ());_fea .Add_w (_gfe .BorderWidth );};if len (gsName )> 1{_fea .Add_gs (_ba .PdfObjectName (gsName ));};DrawPathWithCreator (_gaf ,_fea );_fea .Add_h ();if _gfe .FillEnabled &&_gfe .BorderEnabled {_fea .Add_B ();}else if _gfe .FillEnabled {_fea .Add_f ();}else if _gfe .BorderEnabled {_fea .Add_S ();};_fea .Add_Q ();return _fea .Bytes (),_gaf .GetBoundingBox ().ToPdfRectangle (),nil ;};
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_bb Path )GetPointNumber (number int )Point {if number < 1||number > len (_bb .Points ){return Point {};};return _bb .Points [number -1];};
// Length returns the number of points in the path.
func (_afe Path )Length ()int {return len (_afe .Points )};
// 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 *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;Opacity float64 ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_ab CubicBezierPath )GetBoundingBox ()Rectangle {_gad :=Rectangle {};_dd :=0.0;_efe :=0.0;_fed :=0.0;_fb :=0.0;for _cac ,_cb :=range _ab .Curves {_af :=_cb .GetBounds ();if _cac ==0{_dd =_af .Llx ;_efe =_af .Urx ;_fed =_af .Lly ;_fb =_af .Ury ;continue ;};if _af .Llx < _dd {_dd =_af .Llx ;};if _af .Urx > _efe {_efe =_af .Urx ;};if _af .Lly < _fed {_fed =_af .Lly ;};if _af .Ury > _fb {_fb =_af .Ury ;};};_gad .X =_dd ;_gad .Y =_fed ;_gad .Width =_efe -_dd ;_gad .Height =_fb -_fed ;return _gad ;};
// Rotate rotates the vector by the specified angle.
func (_gcc Vector )Rotate (phi float64 )Vector {_afea :=_gcc .Magnitude ();_eebd :=_gcc .GetPolarAngle ();return NewVectorPolar (_afea ,_eebd +phi );};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_d .PdfColorDeviceRGB ;LineWidth float64 ;};
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// GetBoundingBox returns the bounding box of the path.
func (_bc Path )GetBoundingBox ()BoundingBox {_cacb :=BoundingBox {};_ege :=0.0;_gc :=0.0;_gf :=0.0;_gca :=0.0;for _dc ,_gdg :=range _bc .Points {if _dc ==0{_ege =_gdg .X ;_gc =_gdg .X ;_gf =_gdg .Y ;_gca =_gdg .Y ;continue ;};if _gdg .X < _ege {_ege =_gdg .X ;};if _gdg .X > _gc {_gc =_gdg .X ;};if _gdg .Y < _gf {_gf =_gdg .Y ;};if _gdg .Y > _gca {_gca =_gdg .Y ;};};_cacb .X =_ege ;_cacb .Y =_gf ;_cacb .Width =_gc -_ege ;_cacb .Height =_gca -_gf ;return _cacb ;};
// Add adds the specified vector to the current one and returns the result.
func (_bdagf Vector )Add (other Vector )Vector {_bdagf .Dx +=other .Dx ;_bdagf .Dy +=other .Dy ;return _bdagf ;};
// 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 *_c .ContentCreator ){for _ffd ,_gcd :=range bpath .Curves {if _ffd ==0{creator .Add_m (_gcd .P0 .X ,_gcd .P0 .Y );};creator .Add_c (_gcd .P1 .X ,_gcd .P1 .Y ,_gcd .P2 .X ,_gcd .P2 .Y ,_gcd .P3 .X ,_gcd .P3 .Y );};};
// Copy returns a clone of the Bezier path.
func (_ga CubicBezierPath )Copy ()CubicBezierPath {_bf :=CubicBezierPath {};_bf .Curves =[]CubicBezierCurve {};for _ ,_cge :=range _ga .Curves {_bf .Curves =append (_bf .Curves ,_cge );};return _bf ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_ccaa :=Vector {};_ccaa .Dx =length *_bd .Cos (theta );_ccaa .Dy =length *_bd .Sin (theta );return _ccaa ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// GetBounds returns the bounding box of the Bezier curve.
func (_a CubicBezierCurve )GetBounds ()_d .PdfRectangle {_de :=_a .P0 .X ;_ee :=_a .P0 .X ;_cg :=_a .P0 .Y ;_bda :=_a .P0 .Y ;for _cc :=0.0;_cc <=1.0;_cc +=0.001{Rx :=_a .P0 .X *_bd .Pow (1-_cc ,3)+_a .P1 .X *3*_cc *_bd .Pow (1-_cc ,2)+_a .P2 .X *3*_bd .Pow (_cc ,2)*(1-_cc )+_a .P3 .X *_bd .Pow (_cc ,3);Ry :=_a .P0 .Y *_bd .Pow (1-_cc ,3)+_a .P1 .Y *3*_cc *_bd .Pow (1-_cc ,2)+_a .P2 .Y *3*_bd .Pow (_cc ,2)*(1-_cc )+_a .P3 .Y *_bd .Pow (_cc ,3);if Rx < _de {_de =Rx ;};if Rx > _ee {_ee =Rx ;};if Ry < _cg {_cg =Ry ;};if Ry > _bda {_bda =Ry ;};};_fe :=_d .PdfRectangle {};_fe .Llx =_de ;_fe .Lly =_cg ;_fe .Urx =_ee ;_fe .Ury =_bda ;return _fe ;};
// Offset shifts the path with the specified offsets.
func (_ac Path )Offset (offX ,offY float64 )Path {for _gd ,_bgg :=range _ac .Points {_ac .Points [_gd ]=_bgg .Add (offX ,offY );};return _ac ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_ceg Point )Add (dx ,dy float64 )Point {_ceg .X +=dx ;_ceg .Y +=dy ;return _ceg };
// 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 *_c .ContentCreator ){for _fa ,_baa :=range path .Points {if _fa ==0{creator .Add_m (_baa .X ,_baa .Y );}else {creator .Add_l (_baa .X ,_baa .Y );};};};
// 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 ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_gda Point )Add (dx ,dy float64 )Point {_gda .X +=dx ;_gda .Y +=dy ;return _gda };
// 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 (_gdaf PolyBezierCurve )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){if _gdaf .BorderColor ==nil {_gdaf .BorderColor =_bg .NewPdfColorDeviceRGB (0,0,0);};_fbd :=NewCubicBezierPath ();for _ ,_ag :=range _gdaf .Curves {_fbd =_fbd .AppendCurve (_ag );};_ga :=_c .NewContentCreator ();_ga .Add_q ();_gdaf .FillEnabled =_gdaf .FillEnabled &&_gdaf .FillColor !=nil ;if _gdaf .FillEnabled {_ga .Add_rg (_gdaf .FillColor .R (),_gdaf .FillColor .G (),_gdaf .FillColor .B ());};_ga .Add_RG (_gdaf .BorderColor .R (),_gdaf .BorderColor .G (),_gdaf .BorderColor .B ());_ga .Add_w (_gdaf .BorderWidth );if len (gsName )> 1{_ga .Add_gs (_f .PdfObjectName (gsName ));};for _ ,_cdd :=range _fbd .Curves {_ga .Add_m (_cdd .P0 .X ,_cdd .P0 .Y );_ga .Add_c (_cdd .P1 .X ,_cdd .P1 .Y ,_cdd .P2 .X ,_cdd .P2 .Y ,_cdd .P3 .X ,_cdd .P3 .Y );};if _gdaf .FillEnabled {_ga .Add_h ();_ga .Add_B ();}else {_ga .Add_S ();};_ga .Add_Q ();return _ga .Bytes (),_fbd .GetBoundingBox ().ToPdfRectangle (),nil ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_cgg :=Vector {};_cgg .Dx =dx ;_cgg .Dy =dy ;return _cgg };
// Copy returns a clone of the path.
func (_be Path )Copy ()Path {_de :=Path {};_de .Points =[]Point {};for _ ,_dge :=range _be .Points {_de .Points =append (_de .Points ,_dge );};return _de ;};
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_eed Point )Rotate (theta float64 )Point {_aeb :=_e .NewPoint (_eed .X ,_eed .Y ).Rotate (theta );return NewPoint (_aeb .X ,_aeb .Y );};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// Copy returns a clone of the Bezier path.
func (_ee CubicBezierPath )Copy ()CubicBezierPath {_dg :=CubicBezierPath {};_dg .Curves =[]CubicBezierCurve {};for _ ,_abb :=range _ee .Curves {_dg .Curves =append (_dg .Curves ,_abb );};return _dg ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_fa :=CubicBezierCurve {};_fa .P0 =NewPoint (x0 ,y0 );_fa .P1 =NewPoint (x1 ,y1 );_fa .P2 =NewPoint (x2 ,y2 );_fa .P3 =NewPoint (x3 ,y3 );return _fa ;};
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_bg .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_bg .PdfColorDeviceRGB ;};
// 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 *_bg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_bg .PdfColorDeviceRGB ;Opacity float64 ;};
// NewVectorBetween returns a new vector with the direction specified by
// the subtraction of point a from point b (b-a).
func NewVectorBetween (a Point ,b Point )Vector {_gdeg :=Vector {};_gdeg .Dx =b .X -a .X ;_gdeg .Dy =b .Y -a .Y ;return _gdeg ;};
// AppendPoint adds the specified point to the path.
func (_cd Path )AppendPoint (point Point )Path {_cd .Points =append (_cd .Points ,point );return _cd };
// FlipX flips the sign of the Dx component of the vector.
func (_cdae Vector )FlipX ()Vector {_cdae .Dx =-_cdae .Dx ;return _cdae };
// Scale scales the vector by the specified factor.
func (_fe Vector )Scale (factor float64 )Vector {_ggde :=_fe .Magnitude ();_eda :=_fe .GetPolarAngle ();_fe .Dx =factor *_ggde *_b .Cos (_eda );_fe .Dy =factor *_ggde *_b .Sin (_eda );return _fe ;};
// AddVector adds vector to a point.
func (_eeg Point )AddVector (v Vector )Point {_eeg .X +=v .Dx ;_eeg .Y +=v .Dy ;return _eeg };
// 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 (_gbc Polygon )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){_beb :=_c .NewContentCreator ();_beb .Add_q ();_gbc .FillEnabled =_gbc .FillEnabled &&_gbc .FillColor !=nil ;if _gbc .FillEnabled {_beb .Add_rg (_gbc .FillColor .R (),_gbc .FillColor .G (),_gbc .FillColor .B ());};_gbc .BorderEnabled =_gbc .BorderEnabled &&_gbc .BorderColor !=nil ;if _gbc .BorderEnabled {_beb .Add_RG (_gbc .BorderColor .R (),_gbc .BorderColor .G (),_gbc .BorderColor .B ());_beb .Add_w (_gbc .BorderWidth );};if len (gsName )> 1{_beb .Add_gs (_f .PdfObjectName (gsName ));};_fgd :=NewPath ();for _ ,_bcb :=range _gbc .Points {for _gag ,_edb :=range _bcb {_fgd =_fgd .AppendPoint (_edb );if _gag ==0{_beb .Add_m (_edb .X ,_edb .Y );}else {_beb .Add_l (_edb .X ,_edb .Y );};};_beb .Add_h ();};if _gbc .FillEnabled &&_gbc .BorderEnabled {_beb .Add_B ();}else if _gbc .FillEnabled {_beb .Add_f ();}else if _gbc .BorderEnabled {_beb .Add_S ();};_beb .Add_Q ();return _beb .Bytes (),_fgd .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 (_gdac Line )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){_aga ,_dfa :=_gdac .X1 ,_gdac .X2 ;_gaa ,_cf :=_gdac .Y1 ,_gdac .Y2 ;_gff :=_cf -_gaa ;_bga :=_dfa -_aga ;_dba :=_b .Atan2 (_gff ,_bga );L :=_b .Sqrt (_b .Pow (_bga ,2.0)+_b .Pow (_gff ,2.0));_edg :=_gdac .LineWidth ;_aa :=_b .Pi ;_ef :=1.0;if _bga < 0{_ef *=-1.0;};if _gff < 0{_ef *=-1.0;};VsX :=_ef *(-_edg /2*_b .Cos (_dba +_aa /2));VsY :=_ef *(-_edg /2*_b .Sin (_dba +_aa /2)+_edg *_b .Sin (_dba +_aa /2));V1X :=VsX +_edg /2*_b .Cos (_dba +_aa /2);V1Y :=VsY +_edg /2*_b .Sin (_dba +_aa /2);V2X :=VsX +_edg /2*_b .Cos (_dba +_aa /2)+L *_b .Cos (_dba );V2Y :=VsY +_edg /2*_b .Sin (_dba +_aa /2)+L *_b .Sin (_dba );V3X :=VsX +_edg /2*_b .Cos (_dba +_aa /2)+L *_b .Cos (_dba )+_edg *_b .Cos (_dba -_aa /2);V3Y :=VsY +_edg /2*_b .Sin (_dba +_aa /2)+L *_b .Sin (_dba )+_edg *_b .Sin (_dba -_aa /2);V4X :=VsX +_edg /2*_b .Cos (_dba -_aa /2);V4Y :=VsY +_edg /2*_b .Sin (_dba -_aa /2);_fba :=NewPath ();_fba =_fba .AppendPoint (NewPoint (V1X ,V1Y ));_fba =_fba .AppendPoint (NewPoint (V2X ,V2Y ));_fba =_fba .AppendPoint (NewPoint (V3X ,V3Y ));_fba =_fba .AppendPoint (NewPoint (V4X ,V4Y ));_ba :=_gdac .LineEndingStyle1 ;_cfb :=_gdac .LineEndingStyle2 ;_bea :=3*_edg ;_gc :=3*_edg ;_gba :=(_gc -_edg )/2;if _cfb ==LineEndingStyleArrow {_gea :=_fba .GetPointNumber (2);_bf :=NewVectorPolar (_bea ,_dba +_aa );_ffa :=_gea .AddVector (_bf );_cg :=NewVectorPolar (_gc /2,_dba +_aa /2);_fge :=NewVectorPolar (_bea ,_dba );_dbd :=NewVectorPolar (_gba ,_dba +_aa /2);_fac :=_ffa .AddVector (_dbd );_bgdd :=_fge .Add (_cg .Flip ());_afg :=_fac .AddVector (_bgdd );_gffa :=_cg .Scale (2).Flip ().Add (_bgdd .Flip ());_bfg :=_afg .AddVector (_gffa );_geb :=_ffa .AddVector (NewVectorPolar (_edg ,_dba -_aa /2));_gde :=NewPath ();_gde =_gde .AppendPoint (_fba .GetPointNumber (1));_gde =_gde .AppendPoint (_ffa );_gde =_gde .AppendPoint (_fac );_gde =_gde .AppendPoint (_afg );_gde =_gde .AppendPoint (_bfg );_gde =_gde .AppendPoint (_geb );_gde =_gde .AppendPoint (_fba .GetPointNumber (4));_fba =_gde ;};if _ba ==LineEndingStyleArrow {_cga :=_fba .GetPointNumber (1);_cba :=_fba .GetPointNumber (_fba .Length ());_bca :=NewVectorPolar (_edg /2,_dba +_aa +_aa /2);_abg :=_cga .AddVector (_bca );_beae :=NewVectorPolar (_bea ,_dba ).Add (NewVectorPolar (_gc /2,_dba +_aa /2));_bed :=_abg .AddVector (_beae );_caf :=NewVectorPolar (_gba ,_dba -_aa /2);_gaaa :=_bed .AddVector (_caf );_bgb :=NewVectorPolar (_bea ,_dba );_fd :=_cba .AddVector (_bgb );_ccb :=NewVectorPolar (_gba ,_dba +_aa +_aa /2);_dda :=_fd .AddVector (_ccb );_egde :=_abg ;_gaf :=NewPath ();_gaf =_gaf .AppendPoint (_abg );_gaf =_gaf .AppendPoint (_bed );_gaf =_gaf .AppendPoint (_gaaa );for _ ,_ffad :=range _fba .Points [1:len (_fba .Points )-1]{_gaf =_gaf .AppendPoint (_ffad );};_gaf =_gaf .AppendPoint (_fd );_gaf =_gaf .AppendPoint (_dda );_gaf =_gaf .AppendPoint (_egde );_fba =_gaf ;};_bgg :=_c .NewContentCreator ();_bgg .Add_q ().Add_rg (_gdac .LineColor .R (),_gdac .LineColor .G (),_gdac .LineColor .B ());if len (gsName )> 1{_bgg .Add_gs (_f .PdfObjectName (gsName ));};_fba =_fba .Offset (_gdac .X1 ,_gdac .Y1 );_fgc :=_fba .GetBoundingBox ();DrawPathWithCreator (_fba ,_bgg );if _gdac .LineStyle ==LineStyleDashed {_bgg .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_bgg .Add_f ().Add_Q ();};return _bgg .Bytes (),_fgc .ToPdfRectangle (),nil ;};
// GetBoundingBox returns the bounding box of the path.
func (_acg Path )GetBoundingBox ()BoundingBox {_gbg :=BoundingBox {};_adf :=0.0;_fg :=0.0;_egd :=0.0;_deg :=0.0;for _ff ,_eac :=range _acg .Points {if _ff ==0{_adf =_eac .X ;_fg =_eac .X ;_egd =_eac .Y ;_deg =_eac .Y ;continue ;};if _eac .X < _adf {_adf =_eac .X ;};if _eac .X > _fg {_fg =_eac .X ;};if _eac .Y < _egd {_egd =_eac .Y ;};if _eac .Y > _deg {_deg =_eac .Y ;};};_gbg .X =_adf ;_gbg .Y =_egd ;_gbg .Width =_fg -_adf ;_gbg .Height =_deg -_egd ;return _gbg ;};
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_bg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_bg .PdfColorDeviceRGB ;BorderWidth float64 ;};
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_ed :=CubicBezierPath {};_ed .Curves =[]CubicBezierCurve {};return _ed ;};
// 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 ;
// 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 *_bg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// 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 (_cc Circle )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){_da :=_cc .Width /2;_ge :=_cc .Height /2;if _cc .BorderEnabled {_da -=_cc .BorderWidth /2;_ge -=_cc .BorderWidth /2;};_fce :=0.551784;_faa :=_da *_fce ;_ggfg :=_ge *_fce ;_acgd :=NewCubicBezierPath ();_acgd =_acgd .AppendCurve (NewCubicBezierCurve (-_da ,0,-_da ,_ggfg ,-_faa ,_ge ,0,_ge ));_acgd =_acgd .AppendCurve (NewCubicBezierCurve (0,_ge ,_faa ,_ge ,_da ,_ggfg ,_da ,0));_acgd =_acgd .AppendCurve (NewCubicBezierCurve (_da ,0,_da ,-_ggfg ,_faa ,-_ge ,0,-_ge ));_acgd =_acgd .AppendCurve (NewCubicBezierCurve (0,-_ge ,-_faa ,-_ge ,-_da ,-_ggfg ,-_da ,0));_acgd =_acgd .Offset (_da ,_ge );if _cc .BorderEnabled {_acgd =_acgd .Offset (_cc .BorderWidth /2,_cc .BorderWidth /2);};if _cc .X !=0||_cc .Y !=0{_acgd =_acgd .Offset (_cc .X ,_cc .Y );};_dce :=_c .NewContentCreator ();_dce .Add_q ();if _cc .FillEnabled {_dce .Add_rg (_cc .FillColor .R (),_cc .FillColor .G (),_cc .FillColor .B ());};if _cc .BorderEnabled {_dce .Add_RG (_cc .BorderColor .R (),_cc .BorderColor .G (),_cc .BorderColor .B ());_dce .Add_w (_cc .BorderWidth );};if len (gsName )> 1{_dce .Add_gs (_f .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_acgd ,_dce );_dce .Add_h ();if _cc .FillEnabled &&_cc .BorderEnabled {_dce .Add_B ();}else if _cc .FillEnabled {_dce .Add_f ();}else if _cc .BorderEnabled {_dce .Add_S ();};_dce .Add_Q ();_ffc :=_acgd .GetBoundingBox ();if _cc .BorderEnabled {_ffc .Height +=_cc .BorderWidth ;_ffc .Width +=_cc .BorderWidth ;_ffc .X -=_cc .BorderWidth /2;_ffc .Y -=_cc .BorderWidth /2;};return _dce .Bytes (),_ffc .ToPdfRectangle (),nil ;};
// FlipY flips the sign of the Dy component of the vector.
func (_fbb Vector )FlipY ()Vector {_fbb .Dy =-_fbb .Dy ;return _fbb };
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// 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 *_c .ContentCreator ){for _acdd ,_ec :=range path .Points {if _acdd ==0{creator .Add_m (_ec .X ,_ec .Y );}else {creator .Add_l (_ec .X ,_ec .Y );};};};
// Offset shifts the path with the specified offsets.
func (_ce Path )Offset (offX ,offY float64 )Path {for _eg ,_db :=range _ce .Points {_ce .Points [_eg ]=_db .Add (offX ,offY );};return _ce ;};
// 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 *_bg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_ac Path )GetPointNumber (number int )Point {if number < 1||number > len (_ac .Points ){return Point {};};return _ac .Points [number -1];};
// Magnitude returns the magnitude of the vector.
func (_fee Vector )Magnitude ()float64 {return _bd .Sqrt (_bd .Pow (_fee .Dx ,2.0)+_bd .Pow (_fee .Dy ,2.0));};
// 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 (_dbab Polyline )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){if _dbab .LineColor ==nil {_dbab .LineColor =_bg .NewPdfColorDeviceRGB (0,0,0);};_eagd :=NewPath ();for _ ,_fdd :=range _dbab .Points {_eagd =_eagd .AppendPoint (_fdd );};_cdc :=_c .NewContentCreator ();_cdc .Add_q ();_cdc .Add_RG (_dbab .LineColor .R (),_dbab .LineColor .G (),_dbab .LineColor .B ());_cdc .Add_w (_dbab .LineWidth );if len (gsName )> 1{_cdc .Add_gs (_f .PdfObjectName (gsName ));};DrawPathWithCreator (_eagd ,_cdc );_cdc .Add_S ();_cdc .Add_Q ();return _cdc .Bytes (),_eagd .GetBoundingBox ().ToPdfRectangle (),nil ;};
func (_ecfg Polyline )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){if _ecfg .LineColor ==nil {_ecfg .LineColor =_d .NewPdfColorDeviceRGB (0,0,0);};_dggc :=NewPath ();for _ ,_fgd :=range _ecfg .Points {_dggc =_dggc .AppendPoint (_fgd );};_add :=_c .NewContentCreator ();_add .Add_q ();_add .Add_RG (_ecfg .LineColor .R (),_ecfg .LineColor .G (),_ecfg .LineColor .B ());_add .Add_w (_ecfg .LineWidth );if len (gsName )> 1{_add .Add_gs (_ba .PdfObjectName (gsName ));};DrawPathWithCreator (_dggc ,_add );_add .Add_S ();_add .Add_Q ();return _add .Bytes (),_dggc .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Magnitude returns the magnitude of the vector.
func (_aebe Vector )Magnitude ()float64 {return _b .Sqrt (_b .Pow (_aebe .Dx ,2.0)+_b .Pow (_aebe .Dy ,2.0));};
// Flip changes the sign of the vector: -vector.
func (_ffae Vector )Flip ()Vector {_gdg :=_ffae .Magnitude ();_eaf :=_ffae .GetPolarAngle ();_ffae .Dx =_gdg *_b .Cos (_eaf +_b .Pi );_ffae .Dy =_gdg *_b .Sin (_eaf +_b .Pi );return _ffae ;};
// GetBounds returns the bounding box of the Bezier curve.
func (_bc CubicBezierCurve )GetBounds ()_bg .PdfRectangle {_cb :=_bc .P0 .X ;_dd :=_bc .P0 .X ;_ea :=_bc .P0 .Y ;_ca :=_bc .P0 .Y ;for _ae :=0.0;_ae <=1.0;_ae +=0.001{Rx :=_bc .P0 .X *_b .Pow (1-_ae ,3)+_bc .P1 .X *3*_ae *_b .Pow (1-_ae ,2)+_bc .P2 .X *3*_b .Pow (_ae ,2)*(1-_ae )+_bc .P3 .X *_b .Pow (_ae ,3);Ry :=_bc .P0 .Y *_b .Pow (1-_ae ,3)+_bc .P1 .Y *3*_ae *_b .Pow (1-_ae ,2)+_bc .P2 .Y *3*_b .Pow (_ae ,2)*(1-_ae )+_bc .P3 .Y *_b .Pow (_ae ,3);if Rx < _cb {_cb =Rx ;};if Rx > _dd {_dd =Rx ;};if Ry < _ea {_ea =Ry ;};if Ry > _ca {_ca =Ry ;};};_ab :=_bg .PdfRectangle {};_ab .Llx =_cb ;_ab .Lly =_ea ;_ab .Urx =_dd ;_ab .Ury =_ca ;return _ab ;};
// 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 *_c .ContentCreator ){for _efg ,_cag :=range bpath .Curves {if _efg ==0{creator .Add_m (_cag .P0 .X ,_cag .P0 .Y );};creator .Add_c (_cag .P1 .X ,_cag .P1 .Y ,_cag .P2 .X ,_cag .P2 .Y ,_cag .P3 .X ,_cag .P3 .Y );};};
// AppendCurve appends the specified Bezier curve to the path.
func (_eae CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_eae .Curves =append (_eae .Curves ,curve );return _eae ;};
// LineStyle refers to how the line will be created.
type LineStyle int ;
// Rotate rotates the vector by the specified angle.
func (_dfd Vector )Rotate (phi float64 )Vector {_gdegb :=_dfd .Magnitude ();_ace :=_dfd .GetPolarAngle ();return NewVectorPolar (_gdegb ,_ace +phi );};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_d CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_d .P0 .X +=offX ;_d .P1 .X +=offX ;_d .P2 .X +=offX ;_d .P3 .X +=offX ;_d .P0 .Y +=offY ;_d .P1 .Y +=offY ;_d .P2 .Y +=offY ;_d .P3 .Y +=offY ;return _d ;};
// Length returns the number of points in the path.
func (_ade Path )Length ()int {return len (_ade .Points )};
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// Offset shifts the Bezier path with the specified offsets.
func (_af CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _gb ,_dc :=range _af .Curves {_af .Curves [_gb ]=_dc .AddOffsetXY (offX ,offY );};return _af ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_fb CubicBezierPath )GetBoundingBox ()Rectangle {_fc :=Rectangle {};_eb :=0.0;_eag :=0.0;_gge :=0.0;_gf :=0.0;for _ggf ,_ad :=range _fb .Curves {_df :=_ad .GetBounds ();if _ggf ==0{_eb =_df .Llx ;_eag =_df .Urx ;_gge =_df .Lly ;_gf =_df .Ury ;continue ;};if _df .Llx < _eb {_eb =_df .Llx ;};if _df .Urx > _eag {_eag =_df .Urx ;};if _df .Lly < _gge {_gge =_df .Lly ;};if _df .Ury > _gf {_gf =_df .Ury ;};};_fc .X =_eb ;_fc .Y =_gge ;_fc .Width =_eag -_eb ;_fc .Height =_gf -_gge ;return _fc ;};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_bg .PdfColorDeviceRGB ;LineWidth float64 ;};
// Add adds the specified vector to the current one and returns the result.
func (_gbe Vector )Add (other Vector )Vector {_gbe .Dx +=other .Dx ;_gbe .Dy +=other .Dy ;return _gbe };
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};func (_gbf Point )String ()string {return _g .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_gbf .X ,_gbf .Y );};
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_abc Vector )GetPolarAngle ()float64 {return _b .Atan2 (_abc .Dy ,_abc .Dx )};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
func (_dgeb Vector )GetPolarAngle ()float64 {return _bd .Atan2 (_dgeb .Dy ,_dgeb .Dx )};
// 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 *_bg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_bg .PdfColorDeviceRGB ;Opacity float64 ;};
// 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 (_gff PolyBezierCurve )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){if _gff .BorderColor ==nil {_gff .BorderColor =_d .NewPdfColorDeviceRGB (0,0,0);};_ede :=NewCubicBezierPath ();for _ ,_cgd :=range _gff .Curves {_ede =_ede .AppendCurve (_cgd );};_fbd :=_c .NewContentCreator ();_fbd .Add_q ();_gff .FillEnabled =_gff .FillEnabled &&_gff .FillColor !=nil ;if _gff .FillEnabled {_fbd .Add_rg (_gff .FillColor .R (),_gff .FillColor .G (),_gff .FillColor .B ());};_fbd .Add_RG (_gff .BorderColor .R (),_gff .BorderColor .G (),_gff .BorderColor .B ());_fbd .Add_w (_gff .BorderWidth );if len (gsName )> 1{_fbd .Add_gs (_ba .PdfObjectName (gsName ));};for _ ,_ffb :=range _ede .Curves {_fbd .Add_m (_ffb .P0 .X ,_ffb .P0 .Y );_fbd .Add_c (_ffb .P1 .X ,_ffb .P1 .Y ,_ffb .P2 .X ,_ffb .P2 .Y ,_ffb .P3 .X ,_ffb .P3 .Y );};if _gff .FillEnabled {_fbd .Add_h ();_fbd .Add_B ();}else {_fbd .Add_S ();};_fbd .Add_Q ();return _fbd .Bytes (),_ede .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 (_def Rectangle )Draw (gsName string )([]byte ,*_bg .PdfRectangle ,error ){_age :=NewPath ();_age =_age .AppendPoint (NewPoint (0,0));_age =_age .AppendPoint (NewPoint (0,_def .Height ));_age =_age .AppendPoint (NewPoint (_def .Width ,_def .Height ));_age =_age .AppendPoint (NewPoint (_def .Width ,0));_age =_age .AppendPoint (NewPoint (0,0));if _def .X !=0||_def .Y !=0{_age =_age .Offset (_def .X ,_def .Y );};_bgd :=_c .NewContentCreator ();_bgd .Add_q ();if _def .FillEnabled {_bgd .Add_rg (_def .FillColor .R (),_def .FillColor .G (),_def .FillColor .B ());};if _def .BorderEnabled {_bgd .Add_RG (_def .BorderColor .R (),_def .BorderColor .G (),_def .BorderColor .B ());_bgd .Add_w (_def .BorderWidth );};if len (gsName )> 1{_bgd .Add_gs (_f .PdfObjectName (gsName ));};DrawPathWithCreator (_age ,_bgd );_bgd .Add_h ();if _def .FillEnabled &&_def .BorderEnabled {_bgd .Add_B ();}else if _def .FillEnabled {_bgd .Add_f ();}else if _def .BorderEnabled {_bgd .Add_S ();};_bgd .Add_Q ();return _bgd .Bytes (),_age .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 (_fba Circle )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_cbd :=_fba .Width /2;_cd :=_fba .Height /2;if _fba .BorderEnabled {_cbd -=_fba .BorderWidth /2;_cd -=_fba .BorderWidth /2;};_bde :=0.551784;_bag :=_cbd *_bde ;_ddc :=_cd *_bde ;_aca :=NewCubicBezierPath ();_aca =_aca .AppendCurve (NewCubicBezierCurve (-_cbd ,0,-_cbd ,_ddc ,-_bag ,_cd ,0,_cd ));_aca =_aca .AppendCurve (NewCubicBezierCurve (0,_cd ,_bag ,_cd ,_cbd ,_ddc ,_cbd ,0));_aca =_aca .AppendCurve (NewCubicBezierCurve (_cbd ,0,_cbd ,-_ddc ,_bag ,-_cd ,0,-_cd ));_aca =_aca .AppendCurve (NewCubicBezierCurve (0,-_cd ,-_bag ,-_cd ,-_cbd ,-_ddc ,-_cbd ,0));_aca =_aca .Offset (_cbd ,_cd );if _fba .BorderEnabled {_aca =_aca .Offset (_fba .BorderWidth /2,_fba .BorderWidth /2);};if _fba .X !=0||_fba .Y !=0{_aca =_aca .Offset (_fba .X ,_fba .Y );};_gg :=_c .NewContentCreator ();_gg .Add_q ();if _fba .FillEnabled {_gg .Add_rg (_fba .FillColor .R (),_fba .FillColor .G (),_fba .FillColor .B ());};if _fba .BorderEnabled {_gg .Add_RG (_fba .BorderColor .R (),_fba .BorderColor .G (),_fba .BorderColor .B ());_gg .Add_w (_fba .BorderWidth );};if len (gsName )> 1{_gg .Add_gs (_ba .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_aca ,_gg );_gg .Add_h ();if _fba .FillEnabled &&_fba .BorderEnabled {_gg .Add_B ();}else if _fba .FillEnabled {_gg .Add_f ();}else if _fba .BorderEnabled {_gg .Add_S ();};_gg .Add_Q ();_dge :=_aca .GetBoundingBox ();if _fba .BorderEnabled {_dge .Height +=_fba .BorderWidth ;_dge .Width +=_fba .BorderWidth ;_dge .X -=_fba .BorderWidth /2;_dge .Y -=_fba .BorderWidth /2;};return _gg .Bytes (),_dge .ToPdfRectangle (),nil ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_bcd :=Vector {};_bcd .Dx =length *_b .Cos (theta );_bcd .Dy =length *_b .Sin (theta );return _bcd ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_f :=CubicBezierCurve {};_f .P0 =NewPoint (x0 ,y0 );_f .P1 =NewPoint (x1 ,y1 );_f .P2 =NewPoint (x2 ,y2 );_f .P3 =NewPoint (x3 ,y3 );return _f ;};
// 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 *_d .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// Flip changes the sign of the vector: -vector.
func (_bdeg Vector )Flip ()Vector {_gcae :=_bdeg .Magnitude ();_gb :=_bdeg .GetPolarAngle ();_bdeg .Dx =_gcae *_bd .Cos (_gb +_bd .Pi );_bdeg .Dy =_gcae *_bd .Sin (_gb +_bd .Pi );return _bdeg ;};
// 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 *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;Opacity float64 ;};
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_dgg Point )Rotate (theta float64 )Point {_bcb :=_e .NewPoint (_dgg .X ,_dgg .Y ).Rotate (theta );return NewPoint (_bcb .X ,_bcb .Y );};

File diff suppressed because one or more lines are too long

View File

@ -9,41 +9,77 @@
// 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 (_fe "crypto/aes";_g "crypto/cipher";_fd "crypto/md5";_c "crypto/rand";_ec "crypto/rc4";_a "fmt";_ff "github.com/unidoc/unipdf/v3/common";_ab "github.com/unidoc/unipdf/v3/core/security";_e "io";);func init (){_gfg ("\u0041\u0045\u0053V\u0032",_abf )};func _abf (_ac FilterDict )(Filter ,error ){if _ac .Length ==128{_ff .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",_ac .Length );_ac .Length /=8;};if _ac .Length !=0&&_ac .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",_ac .Length );};return filterAESV2 {},nil ;};type filterIdentity struct{};
package crypt ;import (_d "crypto/aes";_f "crypto/cipher";_gf "crypto/md5";_de "crypto/rand";_eg "crypto/rc4";_g "fmt";_gfe "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/core/security";_e "io";);func init (){_cd ("\u0041\u0045\u0053V\u0032",_c )};func _dc (_fbc ,_beb uint32 ,_gcc []byte ,_bbd bool )([]byte ,error ){_cg :=make ([]byte ,len (_gcc )+5);for _gfaf :=0;_gfaf < len (_gcc );_gfaf ++{_cg [_gfaf ]=_gcc [_gfaf ];};for _ec :=0;_ec < 3;_ec ++{_gcf :=byte ((_fbc >>uint32 (8*_ec ))&0xff);_cg [_ec +len (_gcc )]=_gcf ;};for _ba :=0;_ba < 2;_ba ++{_ddc :=byte ((_beb >>uint32 (8*_ba ))&0xff);_cg [_ba +len (_gcc )+3]=_ddc ;};if _bbd {_cg =append (_cg ,0x73);_cg =append (_cg ,0x41);_cg =append (_cg ,0x6C);_cg =append (_cg ,0x54);};_gab :=_gf .New ();_gab .Write (_cg );_cga :=_gab .Sum (nil );if len (_gcc )+5< 16{return _cga [0:len (_gcc )+5],nil ;};return _cga ,nil ;};type filterIdentity struct{};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};type filterAESV3 struct{filterAES };
// MakeKey implements Filter interface.
func (_bg filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _dc (objNum ,genNum ,ekey ,false );};func _ee (_dg FilterDict )(Filter ,error ){if _dg .Length ==256{_gfe .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",_dg .Length );_dg .Length /=8;};if _dg .Length !=0&&_dg .Length !=32{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_dg .Length );};return filterAESV3 {},nil ;};type filterV2 struct{_fg int };
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func init (){_cd ("\u0041\u0045\u0053V\u0033",_ee )};func _agc (_dec string )(filterFunc ,error ){_dege :=_bgb [string (_dec )];if _dege ==nil {return nil ,_g .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_dec );};return _dege ,nil ;};
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };var (_bgb =make (map[string ]filterFunc ););
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gac ,_fcb :=_eg .NewCipher (okey );if _fcb !=nil {return nil ,_fcb ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_gac .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _fb (_gca FilterDict )(Filter ,error ){if _gca .Length %8!=0{return nil ,_g .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_gca .Length );};if _gca .Length < 5||_gca .Length > 16{if _gca .Length ==40||_gca .Length ==64||_gca .Length ==128{_gfe .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",_gca .Length );_gca .Length /=8;}else {return nil ,_g .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_gca .Length );};};return filterV2 {_fg :_gca .Length },nil ;};type filterAESV2 struct{filterAES };
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_ga ,_ega :=_c (FilterDict {});if _ega !=nil {_gfe .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",_ega );return filterAESV2 {};};return _ga ;};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_db ,_cab :=_fb (FilterDict {Length :length });if _cab !=nil {_gfe .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",_cab );return filterV2 {_fg :length };};return _db ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_feb ,_bb :=_d .NewCipher (okey );if _bb !=nil {return nil ,_bb ;};if len (buf )< 16{_gfe .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_be :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_gfe .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_be ),_be );_gfe .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_gee :=_f .NewCBCDecrypter (_feb ,_be );_gfe .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_gfe .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 );_gee .CryptBlocks (buf ,buf );_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_gfe .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 ;};_caf :=int (buf [len (buf )-1]);if _caf > len (buf ){_gfe .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",_caf ,len (buf ));return buf ,_g .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_caf ];return buf ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};func init (){_cd ("\u0056\u0032",_fb )};func _cd (_cf string ,_ede filterFunc ){if _ ,_gbf :=_bgb [_cf ];_gbf {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_bgb [_cf ]=_ede ;};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
// HandlerVersion implements Filter interface.
func (_gec filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_fbe ,_fbf :=_bae (d .CFM );if _fbf !=nil {return nil ,_fbf ;};_ca ,_fbf :=_fbe (d );if _fbf !=nil {return nil ,_fbf ;};return _ca ,nil ;};
// KeyLength implements Filter interface.
func (_bbe filterV2 )KeyLength ()int {return _bbe ._ade };
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ed .AuthEvent ;Length int ;};var _ Filter =filterAESV3 {};
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_fa ,_ce :=_dg (FilterDict {});if _ce !=nil {_ff .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",_ce );return filterAESV3 {};};return _fa ;};
func NewFilterAESV3 ()Filter {_ce ,_ge :=_ee (FilterDict {});if _ge !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ge );return filterAESV3 {};};return _ce ;};var _ Filter =filterV2 {};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ab .AuthEvent ;Length int ;};
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};func _c (_gfa FilterDict )(Filter ,error ){if _gfa .Length ==128{_gfe .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",_gfa .Length );_gfa .Length /=8;};if _gfa .Length !=0&&_gfa .Length !=16{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_gfa .Length );};return filterAESV2 {},nil ;};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};var _ Filter =filterAESV2 {};func init (){_gfg ("\u0041\u0045\u0053V\u0033",_dg )};type filterV2 struct{_ade int };
func (filterV2 )Name ()string {return "\u0056\u0032"};type filterFunc func (_ecd FilterDict )(Filter ,error );func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
// MakeKey implements Filter interface.
func (_ge filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ffb (objNum ,genNum ,ekey ,false );};
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _dc (objNum ,genNum ,ekey ,true );};type filterAES struct{};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_gc ,_ef :=_cd (FilterDict {Length :length });if _ef !=nil {_ff .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",_ef );return filterV2 {_ade :length };};return _gc ;};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_ece ,_deg :=_agc (d .CFM );if _deg !=nil {return nil ,_deg ;};_fa ,_deg :=_ece (d );if _deg !=nil {return nil ,_deg ;};return _fa ,nil ;};
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ffb (objNum ,genNum ,ekey ,true );};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gg ,_bb :=_fe .NewCipher (okey );if _bb !=nil {return nil ,_bb ;};if len (buf )< 16{_ff .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 ));};_ga :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ff .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_ga ),_ga );_ff .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 ));};_ecf :=_g .NewCBCDecrypter (_gg ,_ga );_ff .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ff .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 );_ecf .CryptBlocks (buf ,buf );_ff .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ff .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 ;};_agd :=int (buf [len (buf )-1]);if _agd > len (buf ){_ff .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",_agd ,len (buf ));return buf ,_a .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_agd ];return buf ,nil ;};type filterAESV2 struct{filterAES };type filterFunc func (_cca FilterDict )(Filter ,error );
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_af ,_cabe :=_eg .NewCipher (okey );if _cabe !=nil {return nil ,_cabe ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_af .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};
func (_gccc filterV2 )KeyLength ()int {return _gccc ._fg };func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};func (filterIdentity )KeyLength ()int {return 0};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
// PDFVersion implements Filter interface.
func (_geg filterV2 )PDFVersion ()[2]int {return [2]int {}};var _ Filter =filterAESV2 {};
// Filter is a common interface for crypt filter methods.
type Filter interface{
@ -61,48 +97,12 @@ 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 (_db ,_gdg uint32 ,_cff []byte )([]byte ,error );
MakeKey (_gae ,_da uint32 ,_cb []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 (_deg []byte ,_ead []byte )([]byte ,error );
EncryptBytes (_aac []byte ,_baa []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 (_bg []byte ,_efa []byte )([]byte ,error );};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_eb ,_dc :=_fe .NewCipher (okey );if _dc !=nil {return nil ,_dc ;};_ff .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _fdg =_fe .BlockSize ;_af :=_fdg -len (buf )%_fdg ;for _ag :=0;_ag < _af ;_ag ++{buf =append (buf ,byte (_af ));};_ff .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_cf :=make ([]byte ,_fdg +len (buf ));_da :=_cf [:_fdg ];if _ ,_b :=_e .ReadFull (_c .Reader ,_da );_b !=nil {return nil ,_b ;};_fc :=_g .NewCBCEncrypter (_eb ,_da );_fc .CryptBlocks (_cf [_fdg :],buf );buf =_cf ;_ff .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"};func init (){_gfg ("\u0056\u0032",_cd )};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_cc ,_cb :=_abf (FilterDict {});if _cb !=nil {_ff .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",_cb );return filterAESV2 {};};return _cc ;};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
// HandlerVersion implements Filter interface.
func (_gag filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};var _ Filter =filterV2 {};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_df ,_afg :=_ec .NewCipher (okey );if _afg !=nil {return nil ,_afg ;};_ff .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_df .XORKeyStream (buf ,buf );_ff .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};var _ Filter =filterAESV3 {};func _cd (_de FilterDict )(Filter ,error ){if _de .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",_de .Length );};if _de .Length < 5||_de .Length > 16{if _de .Length ==40||_de .Length ==64||_de .Length ==128{_ff .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",_de .Length );_de .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",_de .Length );};};return filterV2 {_ade :_de .Length },nil ;};type filterAESV3 struct{filterAES };func (filterIdentity )KeyLength ()int {return 0};func _ffb (_fea ,_fb uint32 ,_feag []byte ,_gac bool )([]byte ,error ){_dcd :=make ([]byte ,len (_feag )+5);for _cbb :=0;_cbb < len (_feag );_cbb ++{_dcd [_cbb ]=_feag [_cbb ];};for _gd :=0;_gd < 3;_gd ++{_ae :=byte ((_fea >>uint32 (8*_gd ))&0xff);_dcd [_gd +len (_feag )]=_ae ;};for _def :=0;_def < 2;_def ++{_eg :=byte ((_fb >>uint32 (8*_def ))&0xff);_dcd [_def +len (_feag )+3]=_eg ;};if _gac {_dcd =append (_dcd ,0x73);_dcd =append (_dcd ,0x41);_dcd =append (_dcd ,0x6C);_dcd =append (_dcd ,0x54);};_ad :=_fd .New ();_ad .Write (_dcd );_ced :=_ad .Sum (nil );if len (_feag )+5< 16{return _ced [0:len (_feag )+5],nil ;};return _ced ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _dg (_ea FilterDict )(Filter ,error ){if _ea .Length ==256{_ff .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",_ea .Length );_ea .Length /=8;};if _ea .Length !=0&&_ea .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",_ea .Length );};return filterAESV3 {},nil ;};func _bae (_egd string )(filterFunc ,error ){_cce :=_cba [string (_egd )];if _cce ==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",_egd );};return _cce ,nil ;};
// PDFVersion implements Filter interface.
func (_aef filterV2 )PDFVersion ()[2]int {return [2]int {}};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_cfa ,_eff :=_ec .NewCipher (okey );if _eff !=nil {return nil ,_eff ;};_ff .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_cfa .XORKeyStream (buf ,buf );_ff .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};type filterAES struct{};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };func _gfg (_bgb string ,_ba filterFunc ){if _ ,_age :=_cba [_bgb ];_age {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_cba [_bgb ]=_ba ;};var (_cba =make (map[string ]filterFunc ););
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};
DecryptBytes (_eea []byte ,_dbg []byte )([]byte ,error );};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fc ,_gc :=_d .NewCipher (okey );if _gc !=nil {return nil ,_gc ;};_gfe .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _efc =_d .BlockSize ;_a :=_efc -len (buf )%_efc ;for _ag :=0;_ag < _a ;_ag ++{buf =append (buf ,byte (_a ));};_gfe .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_ca :=make ([]byte ,_efc +len (buf ));_dda :=_ca [:_efc ];if _ ,_gb :=_e .ReadFull (_de .Reader ,_dda );_gb !=nil {return nil ,_gb ;};_ff :=_f .NewCBCEncrypter (_fc ,_dda );_ff .CryptBlocks (_ca [_efc :],buf );buf =_ca ;_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};

View File

@ -9,50 +9,50 @@
// 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 security ;import (_fa "bytes";_f "crypto/aes";_e "crypto/cipher";_ea "crypto/md5";_ef "crypto/rand";_cd "crypto/rc4";_dc "crypto/sha256";_gc "crypto/sha512";_dca "encoding/binary";_c "errors";_ce "fmt";_a "github.com/unidoc/unipdf/v3/common";_eb "hash";_g "io";_ff "math";);func (_gag errInvalidField )Error ()string {return _ce .Sprintf ("\u0025s\u003a\u0020e\u0078\u0070\u0065\u0063t\u0065\u0064\u0020%\u0073\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0074o \u0062\u0065\u0020%\u0064\u0020b\u0079\u0074\u0065\u0073\u002c\u0020g\u006f\u0074 \u0025\u0064",_gag .Func ,_gag .Field ,_gag .Exp ,_gag .Got );};func _aa (_ga _e .Block )_e .BlockMode {return (*ecbDecrypter )(_gg (_ga ))};func _gg (_dcg _e .Block )*ecb {return &ecb {_ad :_dcg ,_de :_dcg .BlockSize ()}};const (PermOwner =Permissions (_ff .MaxUint32 );PermPrinting =Permissions (1<<2);PermModify =Permissions (1<<3);PermExtractGraphics =Permissions (1<<4);PermAnnotate =Permissions (1<<5);PermFillForms =Permissions (1<<8);PermDisabilityExtract =Permissions (1<<9);PermRotateInsert =Permissions (1<<10);PermFullPrintQuality =Permissions (1<<11););
package security ;import (_gf "bytes";_g "crypto/aes";_c "crypto/cipher";_afg "crypto/md5";_af "crypto/rand";_ca "crypto/rc4";_bd "crypto/sha256";_d "crypto/sha512";_bdc "encoding/binary";_ge "errors";_e "fmt";_aa "github.com/unidoc/unipdf/v3/common";_b "hash";_ce "io";_da "math";);const _abg ="\x28\277\116\136\x4e\x75\x8a\x41\x64\000\x4e\x56\377"+"\xfa\001\010\056\x2e\x00\xb6\xd0\x68\076\x80\x2f\014"+"\251\xfe\x64\x53\x69\172";type stdHandlerR4 struct{Length int ;ID0 string ;};func (_eag stdHandlerR6 )alg13 (_fcf *StdEncryptDict ,_dffa []byte )error {if _cfe :=_fg ("\u0061\u006c\u00671\u0033","\u004b\u0065\u0079",32,_dffa );_cfe !=nil {return _cfe ;};if _agef :=_fg ("\u0061\u006c\u00671\u0033","\u0050\u0065\u0072m\u0073",16,_fcf .Perms );_agef !=nil {return _agef ;};_fgd :=make ([]byte ,16);copy (_fgd ,_fcf .Perms [:16]);_bcf ,_bfa :=_g .NewCipher (_dffa [:32]);if _bfa !=nil {return _bfa ;};_bfag :=_ef (_bcf );_bfag .CryptBlocks (_fgd ,_fgd );if !_gf .Equal (_fgd [9:12],[]byte ("\u0061\u0064\u0062")){return _ge .New ("\u0064\u0065\u0063o\u0064\u0065\u0064\u0020p\u0065\u0072\u006d\u0069\u0073\u0073\u0069o\u006e\u0073\u0020\u0061\u0072\u0065\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_ccd :=Permissions (_bdc .LittleEndian .Uint32 (_fgd [0:4]));if _ccd !=_fcf .P {return _ge .New ("\u0070\u0065r\u006d\u0069\u0073\u0073\u0069\u006f\u006e\u0073\u0020\u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066\u0061il\u0065\u0064");};_bgg :=true ;if _fgd [8]=='T'{_bgg =true ;}else if _fgd [8]=='F'{_bgg =false ;}else {return _ge .New ("\u0064\u0065\u0063\u006f\u0064\u0065\u0064 \u006d\u0065\u0074a\u0064\u0061\u0074\u0061 \u0065\u006e\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e\u0020\u0066\u006c\u0061\u0067\u0020\u0069\u0073\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};if _bgg !=_fcf .EncryptMetadata {return _ge .New ("\u006d\u0065t\u0061\u0064\u0061\u0074a\u0020\u0065n\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e \u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066a\u0069\u006c\u0065\u0064");};return nil ;};func (_ec stdHandlerR4 )alg3 (R int ,_ddg ,_gb []byte )([]byte ,error ){var _gcc []byte ;if len (_gb )> 0{_gcc =_ec .alg3Key (R ,_gb );}else {_gcc =_ec .alg3Key (R ,_ddg );};_ba ,_fea :=_ca .NewCipher (_gcc );if _fea !=nil {return nil ,_ge .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_gcdf :=_ec .paddedPass (_ddg );_ceae :=make ([]byte ,len (_gcdf ));_ba .XORKeyStream (_ceae ,_gcdf );if R >=3{_bg :=make ([]byte ,len (_gcc ));for _bb :=0;_bb < 19;_bb ++{for _ecc :=0;_ecc < len (_gcc );_ecc ++{_bg [_ecc ]=_gcc [_ecc ]^byte (_bb +1);};_gfcg ,_fec :=_ca .NewCipher (_bg );if _fec !=nil {return nil ,_ge .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_gfcg .XORKeyStream (_ceae ,_ceae );};};return _ceae ,nil ;};func (_efc stdHandlerR4 )alg7 (_afge *StdEncryptDict ,_ggf []byte )([]byte ,error ){_ae :=_efc .alg3Key (_afge .R ,_ggf );_ged :=make ([]byte ,len (_afge .O ));if _afge .R ==2{_acb ,_gfe :=_ca .NewCipher (_ae );if _gfe !=nil {return nil ,_ge .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_acb .XORKeyStream (_ged ,_afge .O );}else if _afge .R >=3{_ccga :=append ([]byte {},_afge .O ...);for _cbg :=0;_cbg < 20;_cbg ++{_efe :=append ([]byte {},_ae ...);for _gda :=0;_gda < len (_ae );_gda ++{_efe [_gda ]^=byte (19-_cbg );};_cag ,_ccbc :=_ca .NewCipher (_efe );if _ccbc !=nil {return nil ,_ge .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_cag .XORKeyStream (_ged ,_ccga );_ccga =append ([]byte {},_ged ...);};}else {return nil ,_ge .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");};_fbc ,_gde :=_efc .alg6 (_afge ,_ged );if _gde !=nil {return nil ,nil ;};return _fbc ,nil ;};
// Allowed checks if a set of permissions can be granted.
func (_ba Permissions )Allowed (p2 Permissions )bool {return _ba &p2 ==p2 };func (_dg *ecbEncrypter )BlockSize ()int {return _dg ._de };type stdHandlerR4 struct{Length int ;ID0 string ;};type ecbDecrypter ecb ;func (_ec *ecbDecrypter )CryptBlocks (dst ,src []byte ){if len (src )%_ec ._de !=0{_a .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0064\u0065\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");return ;};if len (dst )< len (src ){_a .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0064\u0065\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");return ;};for len (src )> 0{_ec ._ad .Decrypt (dst ,src [:_ec ._de ]);src =src [_ec ._de :];dst =dst [_ec ._de :];};};func (_eg *ecbEncrypter )CryptBlocks (dst ,src []byte ){if len (src )%_eg ._de !=0{_a .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0065\u006e\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");return ;};if len (dst )< len (src ){_a .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");return ;};for len (src )> 0{_eg ._ad .Encrypt (dst ,src [:_eg ._de ]);src =src [_eg ._de :];dst =dst [_eg ._de :];};};
// GenerateParams is the algorithm opposite to alg2a (R>=5).
// It generates U,O,UE,OE,Perms fields using AESv3 encryption.
// There is no algorithm number assigned to this function in the spec.
// It expects R, P and EncryptMetadata fields to be set.
func (_afe stdHandlerR6 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){_ddaf :=make ([]byte ,32);if _ ,_cced :=_ce .ReadFull (_af .Reader ,_ddaf );_cced !=nil {return nil ,_cced ;};d .U =nil ;d .O =nil ;d .UE =nil ;d .OE =nil ;d .Perms =nil ;if len (upass )> 127{upass =upass [:127];};if len (opass )> 127{opass =opass [:127];};if _ffaa :=_afe .alg8 (d ,_ddaf ,upass );_ffaa !=nil {return nil ,_ffaa ;};if _acf :=_afe .alg9 (d ,_ddaf ,opass );_acf !=nil {return nil ,_acf ;};if d .R ==5{return _ddaf ,nil ;};if _cdf :=_afe .alg10 (d ,_ddaf );_cdf !=nil {return nil ,_cdf ;};return _ddaf ,nil ;};func (_gddc stdHandlerR6 )alg10 (_cce *StdEncryptDict ,_agg []byte )error {if _ggge :=_fg ("\u0061\u006c\u00671\u0030","\u004b\u0065\u0079",32,_agg );_ggge !=nil {return _ggge ;};_fag :=uint64 (uint32 (_cce .P ))|(_da .MaxUint32 <<32);Perms :=make ([]byte ,16);_bdc .LittleEndian .PutUint64 (Perms [:8],_fag );if _cce .EncryptMetadata {Perms [8]='T';}else {Perms [8]='F';};copy (Perms [9:12],"\u0061\u0064\u0062");if _ ,_afga :=_ce .ReadFull (_af .Reader ,Perms [12:16]);_afga !=nil {return _afga ;};_ffe ,_dafe :=_eg (_agg [:32]);if _dafe !=nil {return _dafe ;};_ddd :=_fe (_ffe );_ddd .CryptBlocks (Perms ,Perms );_cce .Perms =Perms [:16];return nil ;};var _ StdHandler =stdHandlerR6 {};func _dgc (_ddf ,_cbe ,_cec []byte )([]byte ,error ){var (_ddb ,_ggg ,_bbc _b .Hash ;);_ddb =_bd .New ();_aab :=make ([]byte ,64);_bcbg :=_ddb ;_bcbg .Write (_ddf );K :=_bcbg .Sum (_aab [:0]);_gdff :=make ([]byte ,64*(127+64+48));_aec :=func (_fcb int )([]byte ,error ){_abf :=len (_cbe )+len (K )+len (_cec );_ced :=_gdff [:_abf ];_eeb :=copy (_ced ,_cbe );_eeb +=copy (_ced [_eeb :],K [:]);_eeb +=copy (_ced [_eeb :],_cec );if _eeb !=_abf {_aa .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020u\u006e\u0065\u0078\u0070\u0065\u0063t\u0065\u0064\u0020\u0072\u006f\u0075\u006ed\u0020\u0069\u006e\u0070\u0075\u0074\u0020\u0073\u0069\u007ae\u002e");return nil ,_ge .New ("\u0077\u0072\u006f\u006e\u0067\u0020\u0073\u0069\u007a\u0065");};K1 :=_gdff [:_abf *64];_egb (K1 ,_abf );_dgb ,_feba :=_eg (K [0:16]);if _feba !=nil {return nil ,_feba ;};_aaa :=_c .NewCBCEncrypter (_dgb ,K [16:32]);_aaa .CryptBlocks (K1 ,K1 );E :=K1 ;_ead :=0;for _geg :=0;_geg < 16;_geg ++{_ead +=int (E [_geg ]%3);};var _fdc _b .Hash ;switch _ead %3{case 0:_fdc =_ddb ;case 1:if _ggg ==nil {_ggg =_d .New384 ();};_fdc =_ggg ;case 2:if _bbc ==nil {_bbc =_d .New ();};_fdc =_bbc ;};_fdc .Reset ();_fdc .Write (E );K =_fdc .Sum (_aab [:0]);return E ,nil ;};for _ebeg :=0;;{E ,_dcg :=_aec (_ebeg );if _dcg !=nil {return nil ,_dcg ;};_edg :=uint8 (E [len (E )-1]);_ebeg ++;if _ebeg >=64&&_edg <=uint8 (_ebeg -32){break ;};};return K [:32],nil ;};func (_ccb stdHandlerR4 )alg6 (_eb *StdEncryptDict ,_agb []byte )([]byte ,error ){var (_cfg []byte ;_abc error ;);_fbd :=_ccb .alg2 (_eb ,_agb );if _eb .R ==2{_cfg ,_abc =_ccb .alg4 (_fbd ,_agb );}else if _eb .R >=3{_cfg ,_abc =_ccb .alg5 (_fbd ,_agb );}else {return nil ,_ge .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");};if _abc !=nil {return nil ,_abc ;};_aa .Log .Trace ("\u0063\u0068\u0065\u0063k:\u0020\u0025\u0020\u0078\u0020\u003d\u003d\u0020\u0025\u0020\u0078\u0020\u003f",string (_cfg ),string (_eb .U ));_ff :=_cfg ;_dda :=_eb .U ;if _eb .R >=3{if len (_ff )> 16{_ff =_ff [0:16];};if len (_dda )> 16{_dda =_dda [0:16];};};if !_gf .Equal (_ff ,_dda ){return nil ,nil ;};return _fbd ,nil ;};type ecbDecrypter ecb ;func (_gg *ecbEncrypter )CryptBlocks (dst ,src []byte ){if len (src )%_gg ._f !=0{_aa .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0065\u006e\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");return ;};if len (dst )< len (src ){_aa .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");return ;};for len (src )> 0{_gg ._ea .Encrypt (dst ,src [:_gg ._f ]);src =src [_gg ._f :];dst =dst [_gg ._f :];};};func (stdHandlerR4 )paddedPass (_fa []byte )[]byte {_age :=make ([]byte ,32);_dd :=copy (_age ,_fa );for ;_dd < 32;_dd ++{_age [_dd ]=_abg [_dd -len (_fa )];};return _age ;};
// AuthEvent is an event type that triggers authentication.
type AuthEvent string ;
// NewHandlerR4 creates a new standard security handler for R<=4.
func NewHandlerR4 (id0 string ,length int )StdHandler {return stdHandlerR4 {ID0 :id0 ,Length :length }};func (_cdc stdHandlerR6 )alg8 (_ggbad *StdEncryptDict ,_dac []byte ,_gad []byte )error {if _dacb :=_dga ("\u0061\u006c\u0067\u0038","\u004b\u0065\u0079",32,_dac );_dacb !=nil {return _dacb ;};var _daa [16]byte ;if _ ,_ada :=_g .ReadFull (_ef .Reader ,_daa [:]);_ada !=nil {return _ada ;};_ecac :=_daa [0:8];_dgbc :=_daa [8:16];_aeeb :=make ([]byte ,len (_gad )+len (_ecac ));_ega :=copy (_aeeb ,_gad );_ega +=copy (_aeeb [_ega :],_ecac );_db ,_cbbg :=_cdc .alg2b (_ggbad .R ,_aeeb ,_gad ,nil );if _cbbg !=nil {return _cbbg ;};U :=make ([]byte ,len (_db )+len (_ecac )+len (_dgbc ));_ega =copy (U ,_db [:32]);_ega +=copy (U [_ega :],_ecac );_ega +=copy (U [_ega :],_dgbc );_ggbad .U =U ;_ega =len (_gad );_ega +=copy (_aeeb [_ega :],_dgbc );_db ,_cbbg =_cdc .alg2b (_ggbad .R ,_aeeb ,_gad ,nil );if _cbbg !=nil {return _cbbg ;};_adaf ,_cbbg :=_adea (_db [:32]);if _cbbg !=nil {return _cbbg ;};_dad :=make ([]byte ,_f .BlockSize );_cff :=_e .NewCBCEncrypter (_adaf ,_dad );UE :=make ([]byte ,32);_cff .CryptBlocks (UE ,_dac [:32]);_ggbad .UE =UE ;return nil ;};const (EventDocOpen =AuthEvent ("\u0044o\u0063\u004f\u0070\u0065\u006e");EventEFOpen =AuthEvent ("\u0045\u0046\u004f\u0070\u0065\u006e"););func (_bb stdHandlerR4 )alg3Key (R int ,_ffb []byte )[]byte {_cg :=_ea .New ();_aaa :=_bb .paddedPass (_ffb );_cg .Write (_aaa );if R >=3{for _ae :=0;_ae < 50;_ae ++{_cbb :=_cg .Sum (nil );_cg =_ea .New ();_cg .Write (_cbb );};};_ge :=_cg .Sum (nil );if R ==2{_ge =_ge [0:5];}else {_ge =_ge [0:_bb .Length /8];};return _ge ;};type ecbEncrypter ecb ;var _ StdHandler =stdHandlerR4 {};func (_bdb stdHandlerR4 )alg3 (R int ,_ebc ,_cf []byte )([]byte ,error ){var _dfg []byte ;if len (_cf )> 0{_dfg =_bdb .alg3Key (R ,_cf );}else {_dfg =_bdb .alg3Key (R ,_ebc );};_adf ,_fe :=_cd .NewCipher (_dfg );if _fe !=nil {return nil ,_c .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_cdg :=_bdb .paddedPass (_ebc );_ee :=make ([]byte ,len (_cdg ));_adf .XORKeyStream (_ee ,_cdg );if R >=3{_da :=make ([]byte ,len (_dfg ));for _gf :=0;_gf < 19;_gf ++{for _ecg :=0;_ecg < len (_dfg );_ecg ++{_da [_ecg ]=_dfg [_ecg ]^byte (_gf +1);};_eag ,_ded :=_cd .NewCipher (_da );if _ded !=nil {return nil ,_c .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_eag .XORKeyStream (_ee ,_ee );};};return _ee ,nil ;};
func NewHandlerR4 (id0 string ,length int )StdHandler {return stdHandlerR4 {ID0 :id0 ,Length :length }};type stdHandlerR6 struct{};func (_ggfe stdHandlerR6 )alg2b (R int ,_gdfe ,_cd ,_gea []byte )([]byte ,error ){if R ==5{return _egc (_gdfe );};return _dgc (_gdfe ,_cd ,_gea );};
// StdHandler is an interface for standard security handlers.
type StdHandler interface{
// GenerateParams uses owner and user passwords to set encryption parameters and generate an encryption key.
// It assumes that R, P and EncryptMetadata are already set.
GenerateParams (_ggc *StdEncryptDict ,_ead ,_bdc []byte )([]byte ,error );
GenerateParams (_ag *StdEncryptDict ,_bc ,_dc []byte )([]byte ,error );
// Authenticate uses encryption dictionary parameters and the password to calculate
// the document encryption key. It also returns permissions that should be granted to a user.
// In case of failed authentication, it returns empty key and zero permissions with no error.
Authenticate (_fb *StdEncryptDict ,_ed []byte )([]byte ,Permissions ,error );};
Authenticate (_bce *StdEncryptDict ,_gc []byte )([]byte ,Permissions ,error );};
// NewHandlerR6 creates a new standard security handler for R=5 and R=6.
func NewHandlerR6 ()StdHandler {return stdHandlerR6 {}};type errInvalidField struct{Func string ;Field string ;Exp int ;Got int ;};func (_bd *ecbDecrypter )BlockSize ()int {return _bd ._de };func (_fce stdHandlerR6 )alg2a (_beg *StdEncryptDict ,_aef []byte )([]byte ,Permissions ,error ){if _fef :=_dga ("\u0061\u006c\u00672\u0061","\u004f",48,_beg .O );_fef !=nil {return nil ,0,_fef ;};if _cef :=_dga ("\u0061\u006c\u00672\u0061","\u0055",48,_beg .U );_cef !=nil {return nil ,0,_cef ;};if len (_aef )> 127{_aef =_aef [:127];};_gbe ,_fg :=_fce .alg12 (_beg ,_aef );if _fg !=nil {return nil ,0,_fg ;};var (_cga []byte ;_ggba []byte ;_cba []byte ;);var _gcd Permissions ;if len (_gbe )!=0{_gcd =PermOwner ;_fgd :=make ([]byte ,len (_aef )+8+48);_aeb :=copy (_fgd ,_aef );_aeb +=copy (_fgd [_aeb :],_beg .O [40:48]);_aeb +=copy (_fgd [_aeb :],_beg .U [0:48]);_cga =_fgd ;_ggba =_beg .OE ;_cba =_beg .U [0:48];}else {_gbe ,_fg =_fce .alg11 (_beg ,_aef );if _fg ==nil &&len (_gbe )==0{_gbe ,_fg =_fce .alg11 (_beg ,[]byte (""));};if _fg !=nil {return nil ,0,_fg ;}else if len (_gbe )==0{return nil ,0,nil ;};_gcd =_beg .P ;_bfc :=make ([]byte ,len (_aef )+8);_bfg :=copy (_bfc ,_aef );_bfg +=copy (_bfc [_bfg :],_beg .U [40:48]);_cga =_bfc ;_ggba =_beg .UE ;_cba =nil ;};if _bga :=_dga ("\u0061\u006c\u00672\u0061","\u004b\u0065\u0079",32,_ggba );_bga !=nil {return nil ,0,_bga ;};_ggba =_ggba [:32];_cfc ,_fg :=_fce .alg2b (_beg .R ,_cga ,_aef ,_cba );if _fg !=nil {return nil ,0,_fg ;};_dcd ,_fg :=_f .NewCipher (_cfc [:32]);if _fg !=nil {return nil ,0,_fg ;};_ceg :=make ([]byte ,_f .BlockSize );_acb :=_e .NewCBCDecrypter (_dcd ,_ceg );_dedd :=make ([]byte ,32);_acb .CryptBlocks (_dedd ,_ggba );if _beg .R ==5{return _dedd ,_gcd ,nil ;};_fg =_fce .alg13 (_beg ,_dedd );if _fg !=nil {return nil ,0,_fg ;};return _dedd ,_gcd ,nil ;};func (_egf stdHandlerR4 )alg6 (_cedd *StdEncryptDict ,_bbe []byte )([]byte ,error ){var (_dde []byte ;_cc error ;);_eaf :=_egf .alg2 (_cedd ,_bbe );if _cedd .R ==2{_dde ,_cc =_egf .alg4 (_eaf ,_bbe );}else if _cedd .R >=3{_dde ,_cc =_egf .alg5 (_eaf ,_bbe );}else {return nil ,_c .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");};if _cc !=nil {return nil ,_cc ;};_a .Log .Trace ("\u0063\u0068\u0065\u0063k:\u0020\u0025\u0020\u0078\u0020\u003d\u003d\u0020\u0025\u0020\u0078\u0020\u003f",string (_dde ),string (_cedd .U ));_gdd :=_dde ;_fea :=_cedd .U ;if _cedd .R >=3{if len (_gdd )> 16{_gdd =_gdd [0:16];};if len (_fea )> 16{_fea =_fea [0:16];};};if !_fa .Equal (_gdd ,_fea ){return nil ,nil ;};return _eaf ,nil ;};func _eea (_cfa []byte ,_eca int ){_fd :=_eca ;for _fd < len (_cfa ){copy (_cfa [_fd :],_cfa [:_fd ]);_fd *=2;};};
// GenerateParams is the algorithm opposite to alg2a (R>=5).
// It generates U,O,UE,OE,Perms fields using AESv3 encryption.
// There is no algorithm number assigned to this function in the spec.
// It expects R, P and EncryptMetadata fields to be set.
func (_ebgd stdHandlerR6 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){_fde :=make ([]byte ,32);if _ ,_dfgb :=_g .ReadFull (_ef .Reader ,_fde );_dfgb !=nil {return nil ,_dfgb ;};d .U =nil ;d .O =nil ;d .UE =nil ;d .OE =nil ;d .Perms =nil ;if len (upass )> 127{upass =upass [:127];};if len (opass )> 127{opass =opass [:127];};if _ddd :=_ebgd .alg8 (d ,_fde ,upass );_ddd !=nil {return nil ,_ddd ;};if _gae :=_ebgd .alg9 (d ,_fde ,opass );_gae !=nil {return nil ,_gae ;};if d .R ==5{return _fde ,nil ;};if _gdf :=_ebgd .alg10 (d ,_fde );_gdf !=nil {return nil ,_gdf ;};return _fde ,nil ;};func (_bc stdHandlerR4 )alg2 (_ffc *StdEncryptDict ,_gb []byte )[]byte {_a .Log .Trace ("\u0061\u006c\u0067\u0032");_eaa :=_bc .paddedPass (_gb );_dcgg :=_ea .New ();_dcgg .Write (_eaa );_dcgg .Write (_ffc .O );var _gd [4]byte ;_dca .LittleEndian .PutUint32 (_gd [:],uint32 (_ffc .P ));_dcgg .Write (_gd [:]);_a .Log .Trace ("\u0067o\u0020\u0050\u003a\u0020\u0025\u0020x",_gd );_dcgg .Write ([]byte (_bc .ID0 ));_a .Log .Trace ("\u0074\u0068\u0069\u0073\u002e\u0052\u0020\u003d\u0020\u0025d\u0020\u0065\u006e\u0063\u0072\u0079\u0070t\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061\u0020\u0025\u0076",_ffc .R ,_ffc .EncryptMetadata );if (_ffc .R >=4)&&!_ffc .EncryptMetadata {_dcgg .Write ([]byte {0xff,0xff,0xff,0xff});};_efd :=_dcgg .Sum (nil );if _ffc .R >=3{_dcgg =_ea .New ();for _gdg :=0;_gdg < 50;_gdg ++{_dcgg .Reset ();_dcgg .Write (_efd [0:_bc .Length /8]);_efd =_dcgg .Sum (nil );};};if _ffc .R >=3{return _efd [0:_bc .Length /8];};return _efd [0:5];};
// Authenticate implements StdHandler interface.
func (_fca stdHandlerR6 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){return _fca .alg2a (d ,pass );};func _fg (_bf ,_cc string ,_de int ,_ee []byte )error {if len (_ee )< _de {return errInvalidField {Func :_bf ,Field :_cc ,Exp :_de ,Got :len (_ee )};};return nil ;};func (_eab *ecbDecrypter )BlockSize ()int {return _eab ._f };func (_ab *ecbDecrypter )CryptBlocks (dst ,src []byte ){if len (src )%_ab ._f !=0{_aa .Log .Error ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0045\u0043\u0042\u0020\u0064\u0065\u0063\u0072\u0079\u0070\u0074\u003a \u0069\u006e\u0070\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u0066\u0075\u006c\u006c\u0020\u0062\u006c\u006f\u0063\u006b\u0073");return ;};if len (dst )< len (src ){_aa .Log .Error ("\u0045R\u0052\u004fR\u003a\u0020\u0045C\u0042\u0020\u0064\u0065\u0063\u0072\u0079p\u0074\u003a\u0020\u006f\u0075\u0074p\u0075\u0074\u0020\u0073\u006d\u0061\u006c\u006c\u0065\u0072\u0020t\u0068\u0061\u006e\u0020\u0069\u006e\u0070\u0075\u0074");return ;};for len (src )> 0{_ab ._ea .Decrypt (dst ,src [:_ab ._f ]);src =src [_ab ._f :];dst =dst [_ab ._f :];};};func (_bdf stdHandlerR4 )alg4 (_fef []byte ,_eccg []byte )([]byte ,error ){_cf ,_eed :=_ca .NewCipher (_fef );if _eed !=nil {return nil ,_ge .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_ecb :=[]byte (_abg );_feb :=make ([]byte ,len (_ecb ));_cf .XORKeyStream (_feb ,_ecb );return _feb ,nil ;};func (_dea stdHandlerR6 )alg12 (_ebd *StdEncryptDict ,_dff []byte )([]byte ,error ){if _dafd :=_fg ("\u0061\u006c\u00671\u0032","\u0055",48,_ebd .U );_dafd !=nil {return nil ,_dafd ;};if _cbaf :=_fg ("\u0061\u006c\u00671\u0032","\u004f",48,_ebd .O );_cbaf !=nil {return nil ,_cbaf ;};_dagd :=make ([]byte ,len (_dff )+8+48);_be :=copy (_dagd ,_dff );_be +=copy (_dagd [_be :],_ebd .O [32:40]);_be +=copy (_dagd [_be :],_ebd .U [0:48]);_gfa ,_abd :=_dea .alg2b (_ebd .R ,_dagd ,_dff ,_ebd .U [0:48]);if _abd !=nil {return nil ,_abd ;};_gfa =_gfa [:32];if !_gf .Equal (_gfa ,_ebd .O [:32]){return nil ,nil ;};return _gfa ,nil ;};type errInvalidField struct{Func string ;Field string ;Exp int ;Got int ;};func (_dfb stdHandlerR6 )alg2a (_aea *StdEncryptDict ,_gfb []byte )([]byte ,Permissions ,error ){if _afd :=_fg ("\u0061\u006c\u00672\u0061","\u004f",48,_aea .O );_afd !=nil {return nil ,0,_afd ;};if _fee :=_fg ("\u0061\u006c\u00672\u0061","\u0055",48,_aea .U );_fee !=nil {return nil ,0,_fee ;};if len (_gfb )> 127{_gfb =_gfb [:127];};_ceb ,_cadd :=_dfb .alg12 (_aea ,_gfb );if _cadd !=nil {return nil ,0,_cadd ;};var (_gbc []byte ;_aee []byte ;_db []byte ;);var _cfc Permissions ;if len (_ceb )!=0{_cfc =PermOwner ;_bbg :=make ([]byte ,len (_gfb )+8+48);_ecga :=copy (_bbg ,_gfb );_ecga +=copy (_bbg [_ecga :],_aea .O [40:48]);_ecga +=copy (_bbg [_ecga :],_aea .U [0:48]);_gbc =_bbg ;_aee =_aea .OE ;_db =_aea .U [0:48];}else {_ceb ,_cadd =_dfb .alg11 (_aea ,_gfb );if _cadd ==nil &&len (_ceb )==0{_ceb ,_cadd =_dfb .alg11 (_aea ,[]byte (""));};if _cadd !=nil {return nil ,0,_cadd ;}else if len (_ceb )==0{return nil ,0,nil ;};_cfc =_aea .P ;_ade :=make ([]byte ,len (_gfb )+8);_dec :=copy (_ade ,_gfb );_dec +=copy (_ade [_dec :],_aea .U [40:48]);_gbc =_ade ;_aee =_aea .UE ;_db =nil ;};if _aaf :=_fg ("\u0061\u006c\u00672\u0061","\u004b\u0065\u0079",32,_aee );_aaf !=nil {return nil ,0,_aaf ;};_aee =_aee [:32];_dg ,_cadd :=_dfb .alg2b (_aea .R ,_gbc ,_gfb ,_db );if _cadd !=nil {return nil ,0,_cadd ;};_gfd ,_cadd :=_g .NewCipher (_dg [:32]);if _cadd !=nil {return nil ,0,_cadd ;};_abcb :=make ([]byte ,_g .BlockSize );_fda :=_c .NewCBCDecrypter (_gfd ,_abcb );_baf :=make ([]byte ,32);_fda .CryptBlocks (_baf ,_aee );if _aea .R ==5{return _baf ,_cfc ,nil ;};_cadd =_dfb .alg13 (_aea ,_baf );if _cadd !=nil {return nil ,0,_cadd ;};return _baf ,_cfc ,nil ;};
// GenerateParams generates and sets O and U parameters for the encryption dictionary.
// It expects R, P and EncryptMetadata fields to be set.
func (_bee stdHandlerR4 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){O ,_bcgc :=_bee .alg3 (d .R ,upass ,opass );if _bcgc !=nil {_a .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_bcgc );return nil ,_bcgc ;};d .O =O ;_a .Log .Trace ("\u0067\u0065\u006e\u0020\u004f\u003a\u0020\u0025\u0020\u0078",O );_ecd :=_bee .alg2 (d ,upass );U ,_bcgc :=_bee .alg5 (_ecd ,upass );if _bcgc !=nil {_a .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_bcgc );return nil ,_bcgc ;};d .U =U ;_a .Log .Trace ("\u0067\u0065\u006e\u0020\u0055\u003a\u0020\u0025\u0020\u0078",U );return _ecd ,nil ;};func _gge (_bea ,_bdfa ,_ag []byte )([]byte ,error ){var (_bbc ,_bgc ,_beae _eb .Hash ;);_bbc =_dc .New ();_abf :=make ([]byte ,64);_aeg :=_bbc ;_aeg .Write (_bea );K :=_aeg .Sum (_abf [:0]);_bdcd :=make ([]byte ,64*(127+64+48));_aeec :=func (_daf int )([]byte ,error ){_bad :=len (_bdfa )+len (K )+len (_ag );_gff :=_bdcd [:_bad ];_fgdc :=copy (_gff ,_bdfa );_fgdc +=copy (_gff [_fgdc :],K [:]);_fgdc +=copy (_gff [_fgdc :],_ag );if _fgdc !=_bad {_a .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020u\u006e\u0065\u0078\u0070\u0065\u0063t\u0065\u0064\u0020\u0072\u006f\u0075\u006ed\u0020\u0069\u006e\u0070\u0075\u0074\u0020\u0073\u0069\u007ae\u002e");return nil ,_c .New ("\u0077\u0072\u006f\u006e\u0067\u0020\u0073\u0069\u007a\u0065");};K1 :=_bdcd [:_bad *64];_eea (K1 ,_bad );_eee ,_dgb :=_adea (K [0:16]);if _dgb !=nil {return nil ,_dgb ;};_adg :=_e .NewCBCEncrypter (_eee ,K [16:32]);_adg .CryptBlocks (K1 ,K1 );E :=K1 ;_cbaa :=0;for _ccf :=0;_ccf < 16;_ccf ++{_cbaa +=int (E [_ccf ]%3);};var _cfg _eb .Hash ;switch _cbaa %3{case 0:_cfg =_bbc ;case 1:if _bgc ==nil {_bgc =_gc .New384 ();};_cfg =_bgc ;case 2:if _beae ==nil {_beae =_gc .New ();};_cfg =_beae ;};_cfg .Reset ();_cfg .Write (E );K =_cfg .Sum (_abf [:0]);return E ,nil ;};for _ebd :=0;;{E ,_cab :=_aeec (_ebd );if _cab !=nil {return nil ,_cab ;};_bae :=uint8 (E [len (E )-1]);_ebd ++;if _ebd >=64&&_bae <=uint8 (_ebd -32){break ;};};return K [:32],nil ;};func (_aca stdHandlerR6 )alg12 (_aefc *StdEncryptDict ,_bdbe []byte )([]byte ,error ){if _fbfa :=_dga ("\u0061\u006c\u00671\u0032","\u0055",48,_aefc .U );_fbfa !=nil {return nil ,_fbfa ;};if _agg :=_dga ("\u0061\u006c\u00671\u0032","\u004f",48,_aefc .O );_agg !=nil {return nil ,_agg ;};_gbef :=make ([]byte ,len (_bdbe )+8+48);_cbge :=copy (_gbef ,_bdbe );_cbge +=copy (_gbef [_cbge :],_aefc .O [32:40]);_cbge +=copy (_gbef [_cbge :],_aefc .U [0:48]);_cca ,_geba :=_aca .alg2b (_aefc .R ,_gbef ,_bdbe ,_aefc .U [0:48]);if _geba !=nil {return nil ,_geba ;};_cca =_cca [:32];if !_fa .Equal (_cca ,_aefc .O [:32]){return nil ,nil ;};return _cca ,nil ;};
// AuthEvent is an event type that triggers authentication.
type AuthEvent string ;func _af (_ccc []byte )([]byte ,error ){_efeg :=_dc .New ();_efeg .Write (_ccc );return _efeg .Sum (nil ),nil ;};func (_eadc stdHandlerR4 )alg5 (_bbd []byte ,_eba []byte )([]byte ,error ){_ced :=_ea .New ();_ced .Write ([]byte (_bdf ));_ced .Write ([]byte (_eadc .ID0 ));_dcag :=_ced .Sum (nil );_a .Log .Trace ("\u0061\u006c\u0067\u0035");_a .Log .Trace ("\u0065k\u0065\u0079\u003a\u0020\u0025\u0020x",_bbd );_a .Log .Trace ("\u0049D\u003a\u0020\u0025\u0020\u0078",_eadc .ID0 );if len (_dcag )!=16{return nil ,_c .New ("\u0068a\u0073\u0068\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006eo\u0074\u0020\u0031\u0036\u0020\u0062\u0079\u0074\u0065\u0073");};_feg ,_bda :=_cd .NewCipher (_bbd );if _bda !=nil {return nil ,_c .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_efe :=make ([]byte ,16);_feg .XORKeyStream (_efe ,_dcag );_fac :=make ([]byte ,len (_bbd ));for _aaf :=0;_aaf < 19;_aaf ++{for _edg :=0;_edg < len (_bbd );_edg ++{_fac [_edg ]=_bbd [_edg ]^byte (_aaf +1);};_feg ,_bda =_cd .NewCipher (_fac );if _bda !=nil {return nil ,_c .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_feg .XORKeyStream (_efe ,_efe );_a .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u002c\u0020\u0065\u006b\u0065\u0079:\u0020\u0025\u0020\u0078",_aaf ,_fac );_a .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u0020\u002d\u003e\u0020\u0025\u0020\u0078",_aaf ,_efe );};_dd :=make ([]byte ,32);for _be :=0;_be < 16;_be ++{_dd [_be ]=_efe [_be ];};_ ,_bda =_ef .Read (_dd [16:32]);if _bda !=nil {return nil ,_c .New ("\u0066a\u0069\u006c\u0065\u0064 \u0074\u006f\u0020\u0067\u0065n\u0020r\u0061n\u0064\u0020\u006e\u0075\u006d\u0062\u0065r");};return _dd ,nil ;};func _dga (_cdf ,_cb string ,_gcc int ,_ab []byte )error {if len (_ab )< _gcc {return errInvalidField {Func :_cdf ,Field :_cb ,Exp :_gcc ,Got :len (_ab )};};return nil ;};
// Authenticate implements StdHandler interface.
func (_ged stdHandlerR6 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){return _ged .alg2a (d ,pass );};
// Permissions is a bitmask of access permissions for a PDF file.
type Permissions uint32 ;type stdHandlerR6 struct{};func _adea (_ac []byte )(_e .Block ,error ){_bcc ,_dfgd :=_f .NewCipher (_ac );if _dfgd !=nil {_a .Log .Error ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0063\u0069p\u0068\u0065r\u003a\u0020\u0025\u0076",_dfgd );return nil ,_dfgd ;};return _bcc ,nil ;};type ecb struct{_ad _e .Block ;_de int ;};func (_gef stdHandlerR6 )alg13 (_gebd *StdEncryptDict ,_aeeba []byte )error {if _caba :=_dga ("\u0061\u006c\u00671\u0033","\u004b\u0065\u0079",32,_aeeba );_caba !=nil {return _caba ;};if _eae :=_dga ("\u0061\u006c\u00671\u0033","\u0050\u0065\u0072m\u0073",16,_gebd .Perms );_eae !=nil {return _eae ;};_afc :=make ([]byte ,16);copy (_afc ,_gebd .Perms [:16]);_ffa ,_fefe :=_f .NewCipher (_aeeba [:32]);if _fefe !=nil {return _fefe ;};_ddg :=_aa (_ffa );_ddg .CryptBlocks (_afc ,_afc );if !_fa .Equal (_afc [9:12],[]byte ("\u0061\u0064\u0062")){return _c .New ("\u0064\u0065\u0063o\u0064\u0065\u0064\u0020p\u0065\u0072\u006d\u0069\u0073\u0073\u0069o\u006e\u0073\u0020\u0061\u0072\u0065\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};_dfb :=Permissions (_dca .LittleEndian .Uint32 (_afc [0:4]));if _dfb !=_gebd .P {return _c .New ("\u0070\u0065r\u006d\u0069\u0073\u0073\u0069\u006f\u006e\u0073\u0020\u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066\u0061il\u0065\u0064");};_dfbc :=true ;if _afc [8]=='T'{_dfbc =true ;}else if _afc [8]=='F'{_dfbc =false ;}else {return _c .New ("\u0064\u0065\u0063\u006f\u0064\u0065\u0064 \u006d\u0065\u0074a\u0064\u0061\u0074\u0061 \u0065\u006e\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e\u0020\u0066\u006c\u0061\u0067\u0020\u0069\u0073\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064");};if _dfbc !=_gebd .EncryptMetadata {return _c .New ("\u006d\u0065t\u0061\u0064\u0061\u0074a\u0020\u0065n\u0063\u0072\u0079\u0070\u0074\u0069\u006f\u006e \u0076\u0061\u006c\u0069\u0064\u0061\u0074\u0069\u006f\u006e\u0020\u0066a\u0069\u006c\u0065\u0064");};return nil ;};func (_debe stdHandlerR6 )alg2b (R int ,_agc ,_aegf ,_eab []byte )([]byte ,error ){if R ==5{return _af (_agc );};return _gge (_agc ,_aegf ,_eab );};
// Authenticate implements StdHandler interface.
func (_eda stdHandlerR4 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){_a .Log .Trace ("\u0044\u0065b\u0075\u0067\u0067\u0069n\u0067\u0020a\u0075\u0074\u0068\u0065\u006e\u0074\u0069\u0063a\u0074\u0069\u006f\u006e\u0020\u002d\u0020\u006f\u0077\u006e\u0065\u0072 \u0070\u0061\u0073\u0073");_cebd ,_ebg :=_eda .alg7 (d ,pass );if _ebg !=nil {return nil ,0,_ebg ;};if _cebd !=nil {_a .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _cebd ,PermOwner ,nil ;};_a .Log .Trace ("\u0044\u0065bu\u0067\u0067\u0069n\u0067\u0020\u0061\u0075the\u006eti\u0063\u0061\u0074\u0069\u006f\u006e\u0020- \u0075\u0073\u0065\u0072\u0020\u0070\u0061s\u0073");_cebd ,_ebg =_eda .alg6 (d ,pass );if _ebg !=nil {return nil ,0,_ebg ;};if _cebd !=nil {_a .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _cebd ,d .P ,nil ;};return nil ,0,nil ;};func (_bcg stdHandlerR4 )alg4 (_faf []byte ,_feb []byte )([]byte ,error ){_ade ,_gfc :=_cd .NewCipher (_faf );if _gfc !=nil {return nil ,_c .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_fc :=[]byte (_bdf );_gfcf :=make ([]byte ,len (_fc ));_ade .XORKeyStream (_gfcf ,_fc );return _gfcf ,nil ;};func (_egg stdHandlerR6 )alg11 (_bac *StdEncryptDict ,_abbe []byte )([]byte ,error ){if _cdb :=_dga ("\u0061\u006c\u00671\u0031","\u0055",48,_bac .U );_cdb !=nil {return nil ,_cdb ;};_fgf :=make ([]byte ,len (_abbe )+8);_efg :=copy (_fgf ,_abbe );_efg +=copy (_fgf [_efg :],_bac .U [32:40]);_fbf ,_afe :=_egg .alg2b (_bac .R ,_fgf ,_abbe ,nil );if _afe !=nil {return nil ,_afe ;};_fbf =_fbf [:32];if !_fa .Equal (_fbf ,_bac .U [:32]){return nil ,nil ;};return _fbf ,nil ;};const _bdf ="\x28\277\116\136\x4e\x75\x8a\x41\x64\000\x4e\x56\377"+"\xfa\001\010\056\x2e\x00\xb6\xd0\x68\076\x80\x2f\014"+"\251\xfe\x64\x53\x69\172";func (stdHandlerR4 )paddedPass (_df []byte )[]byte {_ca :=make ([]byte ,32);_bg :=copy (_ca ,_df );for ;_bg < 32;_bg ++{_ca [_bg ]=_bdf [_bg -len (_df )];};return _ca ;};var _ StdHandler =stdHandlerR6 {};func _ggg (_b _e .Block )_e .BlockMode {return (*ecbEncrypter )(_gg (_b ))};func (_abe stdHandlerR6 )alg10 (_fabb *StdEncryptDict ,_aab []byte )error {if _cfcc :=_dga ("\u0061\u006c\u00671\u0030","\u004b\u0065\u0079",32,_aab );_cfcc !=nil {return _cfcc ;};_dgae :=uint64 (uint32 (_fabb .P ))|(_ff .MaxUint32 <<32);Perms :=make ([]byte ,16);_dca .LittleEndian .PutUint64 (Perms [:8],_dgae );if _fabb .EncryptMetadata {Perms [8]='T';}else {Perms [8]='F';};copy (Perms [9:12],"\u0061\u0064\u0062");if _ ,_bfb :=_g .ReadFull (_ef .Reader ,Perms [12:16]);_bfb !=nil {return _bfb ;};_cgfc ,_aaac :=_adea (_aab [:32]);if _aaac !=nil {return _aaac ;};_fbg :=_ggg (_cgfc );_fbg .CryptBlocks (Perms ,Perms );_fabb .Perms =Perms [:16];return nil ;};
func (_bfe stdHandlerR4 )GenerateParams (d *StdEncryptDict ,opass ,upass []byte )([]byte ,error ){O ,_fdb :=_bfe .alg3 (d .R ,upass ,opass );if _fdb !=nil {_aa .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_fdb );return nil ,_fdb ;};d .O =O ;_aa .Log .Trace ("\u0067\u0065\u006e\u0020\u004f\u003a\u0020\u0025\u0020\u0078",O );_gca :=_bfe .alg2 (d ,upass );U ,_fdb :=_bfe .alg5 (_gca ,upass );if _fdb !=nil {_aa .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0045r\u0072\u006f\u0072\u0020\u0067\u0065\u006ee\u0072\u0061\u0074\u0069\u006e\u0067 \u004f\u0020\u0066\u006f\u0072\u0020\u0065\u006e\u0063\u0072\u0079p\u0074\u0069\u006f\u006e\u0020\u0028\u0025\u0073\u0029",_fdb );return nil ,_fdb ;};d .U =U ;_aa .Log .Trace ("\u0067\u0065\u006e\u0020\u0055\u003a\u0020\u0025\u0020\u0078",U );return _gca ,nil ;};type ecbEncrypter ecb ;func (_cda stdHandlerR6 )alg11 (_ffa *StdEncryptDict ,_aae []byte )([]byte ,error ){if _dgca :=_fg ("\u0061\u006c\u00671\u0031","\u0055",48,_ffa .U );_dgca !=nil {return nil ,_dgca ;};_efee :=make ([]byte ,len (_aae )+8);_decba :=copy (_efee ,_aae );_decba +=copy (_efee [_decba :],_ffa .U [32:40]);_adb ,_ffb :=_cda .alg2b (_ffa .R ,_efee ,_aae ,nil );if _ffb !=nil {return nil ,_ffb ;};_adb =_adb [:32];if !_gf .Equal (_adb ,_ffa .U [:32]){return nil ,nil ;};return _adb ,nil ;};func _gd (_aag _c .Block )*ecb {return &ecb {_ea :_aag ,_f :_aag .BlockSize ()}};func _egc (_bcg []byte )([]byte ,error ){_ebe :=_bd .New ();_ebe .Write (_bcg );return _ebe .Sum (nil ),nil ;};type ecb struct{_ea _c .Block ;_f int ;};func (_gfea stdHandlerR6 )alg8 (_bbf *StdEncryptDict ,_bcea []byte ,_ddc []byte )error {if _ddcb :=_fg ("\u0061\u006c\u0067\u0038","\u004b\u0065\u0079",32,_bcea );_ddcb !=nil {return _ddcb ;};var _efd [16]byte ;if _ ,_fbf :=_ce .ReadFull (_af .Reader ,_efd [:]);_fbf !=nil {return _fbf ;};_dac :=_efd [0:8];_adf :=_efd [8:16];_ebb :=make ([]byte ,len (_ddc )+len (_dac ));_ede :=copy (_ebb ,_ddc );_ede +=copy (_ebb [_ede :],_dac );_ccbg ,_eec :=_gfea .alg2b (_bbf .R ,_ebb ,_ddc ,nil );if _eec !=nil {return _eec ;};U :=make ([]byte ,len (_ccbg )+len (_dac )+len (_adf ));_ede =copy (U ,_ccbg [:32]);_ede +=copy (U [_ede :],_dac );_ede +=copy (U [_ede :],_adf );_bbf .U =U ;_ede =len (_ddc );_ede +=copy (_ebb [_ede :],_adf );_ccbg ,_eec =_gfea .alg2b (_bbf .R ,_ebb ,_ddc ,nil );if _eec !=nil {return _eec ;};_dbd ,_eec :=_eg (_ccbg [:32]);if _eec !=nil {return _eec ;};_gdda :=make ([]byte ,_g .BlockSize );_cfge :=_c .NewCBCEncrypter (_dbd ,_gdda );UE :=make ([]byte ,32);_cfge .CryptBlocks (UE ,_bcea [:32]);_bbf .UE =UE ;return nil ;};
// StdEncryptDict is a set of additional fields used in standard encryption dictionary.
type StdEncryptDict struct{R int ;P Permissions ;EncryptMetadata bool ;O ,U []byte ;OE ,UE []byte ;Perms []byte ;};func (_abb stdHandlerR4 )alg7 (_feac *StdEncryptDict ,_dcb []byte )([]byte ,error ){_aea :=_abb .alg3Key (_feac .R ,_dcb );_bba :=make ([]byte ,len (_feac .O ));if _feac .R ==2{_bf ,_aaff :=_cd .NewCipher (_aea );if _aaff !=nil {return nil ,_c .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_bf .XORKeyStream (_bba ,_feac .O );}else if _feac .R >=3{_baa :=append ([]byte {},_feac .O ...);for _ceb :=0;_ceb < 20;_ceb ++{_aee :=append ([]byte {},_aea ...);for _ffg :=0;_ffg < len (_aea );_ffg ++{_aee [_ffg ]^=byte (19-_ceb );};_egb ,_eada :=_cd .NewCipher (_aee );if _eada !=nil {return nil ,_c .New ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0063\u0069\u0070\u0068\u0065\u0072");};_egb .XORKeyStream (_bba ,_baa );_baa =append ([]byte {},_bba ...);};}else {return nil ,_c .New ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020R");};_ggb ,_deb :=_abb .alg6 (_feac ,_bba );if _deb !=nil {return nil ,nil ;};return _ggb ,nil ;};func (_fefd stdHandlerR6 )alg9 (_bfcf *StdEncryptDict ,_gggd []byte ,_ebb []byte )error {if _ddeb :=_dga ("\u0061\u006c\u0067\u0039","\u004b\u0065\u0079",32,_gggd );_ddeb !=nil {return _ddeb ;};if _fab :=_dga ("\u0061\u006c\u0067\u0039","\u0055",48,_bfcf .U );_fab !=nil {return _fab ;};var _eec [16]byte ;if _ ,_fcf :=_g .ReadFull (_ef .Reader ,_eec [:]);_fcf !=nil {return _fcf ;};_ggf :=_eec [0:8];_cbg :=_eec [8:16];_dgf :=_bfcf .U [:48];_ggfe :=make ([]byte ,len (_ebb )+len (_ggf )+len (_dgf ));_geb :=copy (_ggfe ,_ebb );_geb +=copy (_ggfe [_geb :],_ggf );_geb +=copy (_ggfe [_geb :],_dgf );_gfd ,_fcg :=_fefd .alg2b (_bfcf .R ,_ggfe ,_ebb ,_dgf );if _fcg !=nil {return _fcg ;};O :=make ([]byte ,len (_gfd )+len (_ggf )+len (_cbg ));_geb =copy (O ,_gfd [:32]);_geb +=copy (O [_geb :],_ggf );_geb +=copy (O [_geb :],_cbg );_bfcf .O =O ;_geb =len (_ebb );_geb +=copy (_ggfe [_geb :],_cbg );_gfd ,_fcg =_fefd .alg2b (_bfcf .R ,_ggfe ,_ebb ,_dgf );if _fcg !=nil {return _fcg ;};_acg ,_fcg :=_adea (_gfd [:32]);if _fcg !=nil {return _fcg ;};_fcec :=make ([]byte ,_f .BlockSize );_dba :=_e .NewCBCEncrypter (_acg ,_fcec );OE :=make ([]byte ,32);_dba .CryptBlocks (OE ,_gggd [:32]);_bfcf .OE =OE ;return nil ;};
type StdEncryptDict struct{R int ;P Permissions ;EncryptMetadata bool ;O ,U []byte ;OE ,UE []byte ;Perms []byte ;};
// NewHandlerR6 creates a new standard security handler for R=5 and R=6.
func NewHandlerR6 ()StdHandler {return stdHandlerR6 {}};
// Authenticate implements StdHandler interface.
func (_ccge stdHandlerR4 )Authenticate (d *StdEncryptDict ,pass []byte )([]byte ,Permissions ,error ){_aa .Log .Trace ("\u0044\u0065b\u0075\u0067\u0067\u0069n\u0067\u0020a\u0075\u0074\u0068\u0065\u006e\u0074\u0069\u0063a\u0074\u0069\u006f\u006e\u0020\u002d\u0020\u006f\u0077\u006e\u0065\u0072 \u0070\u0061\u0073\u0073");_gedd ,_bfd :=_ccge .alg7 (d ,pass );if _bfd !=nil {return nil ,0,_bfd ;};if _gedd !=nil {_aa .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _gedd ,PermOwner ,nil ;};_aa .Log .Trace ("\u0044\u0065bu\u0067\u0067\u0069n\u0067\u0020\u0061\u0075the\u006eti\u0063\u0061\u0074\u0069\u006f\u006e\u0020- \u0075\u0073\u0065\u0072\u0020\u0070\u0061s\u0073");_gedd ,_bfd =_ccge .alg6 (d ,pass );if _bfd !=nil {return nil ,0,_bfd ;};if _gedd !=nil {_aa .Log .Trace ("\u0074h\u0069\u0073\u002e\u0061u\u0074\u0068\u0065\u006e\u0074i\u0063a\u0074e\u0064\u0020\u003d\u0020\u0054\u0072\u0075e");return _gedd ,d .P ,nil ;};return nil ,0,nil ;};func _eg (_ecg []byte )(_c .Block ,error ){_daga ,_dfd :=_g .NewCipher (_ecg );if _dfd !=nil {_aa .Log .Error ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0063\u0072\u0065\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0063\u0069p\u0068\u0065r\u003a\u0020\u0025\u0076",_dfd );return nil ,_dfd ;};return _daga ,nil ;};func (_cea stdHandlerR4 )alg2 (_eae *StdEncryptDict ,_fgc []byte )[]byte {_aa .Log .Trace ("\u0061\u006c\u0067\u0032");_gcd :=_cea .paddedPass (_fgc );_cgc :=_afg .New ();_cgc .Write (_gcd );_cgc .Write (_eae .O );var _gfc [4]byte ;_bdc .LittleEndian .PutUint32 (_gfc [:],uint32 (_eae .P ));_cgc .Write (_gfc [:]);_aa .Log .Trace ("\u0067o\u0020\u0050\u003a\u0020\u0025\u0020x",_gfc );_cgc .Write ([]byte (_cea .ID0 ));_aa .Log .Trace ("\u0074\u0068\u0069\u0073\u002e\u0052\u0020\u003d\u0020\u0025d\u0020\u0065\u006e\u0063\u0072\u0079\u0070t\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061\u0020\u0025\u0076",_eae .R ,_eae .EncryptMetadata );if (_eae .R >=4)&&!_eae .EncryptMetadata {_cgc .Write ([]byte {0xff,0xff,0xff,0xff});};_ad :=_cgc .Sum (nil );if _eae .R >=3{_cgc =_afg .New ();for _ac :=0;_ac < 50;_ac ++{_cgc .Reset ();_cgc .Write (_ad [0:_cea .Length /8]);_ad =_cgc .Sum (nil );};};if _eae .R >=3{return _ad [0:_cea .Length /8];};return _ad [0:5];};func _fe (_cb _c .Block )_c .BlockMode {return (*ecbEncrypter )(_gd (_cb ))};const (EventDocOpen =AuthEvent ("\u0044o\u0063\u004f\u0070\u0065\u006e");EventEFOpen =AuthEvent ("\u0045\u0046\u004f\u0070\u0065\u006e"););func _egb (_dbc []byte ,_cbd int ){_dga :=_cbd ;for _dga < len (_dbc ){copy (_dbc [_dga :],_dbc [:_dga ]);_dga *=2;};};var _ StdHandler =stdHandlerR4 {};func (_ffc stdHandlerR6 )alg9 (_cab *StdEncryptDict ,_dcc []byte ,_bdb []byte )error {if _ecd :=_fg ("\u0061\u006c\u0067\u0039","\u004b\u0065\u0079",32,_dcc );_ecd !=nil {return _ecd ;};if _cge :=_fg ("\u0061\u006c\u0067\u0039","\u0055",48,_cab .U );_cge !=nil {return _cge ;};var _eff [16]byte ;if _ ,_eee :=_ce .ReadFull (_af .Reader ,_eff [:]);_eee !=nil {return _eee ;};_decb :=_eff [0:8];_cedb :=_eff [8:16];_bcbc :=_cab .U [:48];_fgge :=make ([]byte ,len (_bdb )+len (_decb )+len (_bcbc ));_cba :=copy (_fgge ,_bdb );_cba +=copy (_fgge [_cba :],_decb );_cba +=copy (_fgge [_cba :],_bcbc );_gdaa ,_dge :=_ffc .alg2b (_cab .R ,_fgge ,_bdb ,_bcbc );if _dge !=nil {return _dge ;};O :=make ([]byte ,len (_gdaa )+len (_decb )+len (_cedb ));_cba =copy (O ,_gdaa [:32]);_cba +=copy (O [_cba :],_decb );_cba +=copy (O [_cba :],_cedb );_cab .O =O ;_cba =len (_bdb );_cba +=copy (_fgge [_cba :],_cedb );_gdaa ,_dge =_ffc .alg2b (_cab .R ,_fgge ,_bdb ,_bcbc );if _dge !=nil {return _dge ;};_eeca ,_dge :=_eg (_gdaa [:32]);if _dge !=nil {return _dge ;};_afb :=make ([]byte ,_g .BlockSize );_gedc :=_c .NewCBCEncrypter (_eeca ,_afb );OE :=make ([]byte ,32);_gedc .CryptBlocks (OE ,_dcc [:32]);_cab .OE =OE ;return nil ;};func (_ed *ecbEncrypter )BlockSize ()int {return _ed ._f };
// Allowed checks if a set of permissions can be granted.
func (_fcc Permissions )Allowed (p2 Permissions )bool {return _fcc &p2 ==p2 };func (_fac stdHandlerR4 )alg3Key (R int ,_cgb []byte )[]byte {_bcb :=_afg .New ();_bdg :=_fac .paddedPass (_cgb );_bcb .Write (_bdg );if R >=3{for _fge :=0;_fge < 50;_fge ++{_fcd :=_bcb .Sum (nil );_bcb =_afg .New ();_bcb .Write (_fcd );};};_bcd :=_bcb .Sum (nil );if R ==2{_bcd =_bcd [0:5];}else {_bcd =_bcd [0:_fac .Length /8];};return _bcd ;};func _ef (_fc _c .Block )_c .BlockMode {return (*ecbDecrypter )(_gd (_fc ))};func (_cca errInvalidField )Error ()string {return _e .Sprintf ("\u0025s\u003a\u0020e\u0078\u0070\u0065\u0063t\u0065\u0064\u0020%\u0073\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0074o \u0062\u0065\u0020%\u0064\u0020b\u0079\u0074\u0065\u0073\u002c\u0020g\u006f\u0074 \u0025\u0064",_cca .Func ,_cca .Field ,_cca .Exp ,_cca .Got );};
// Permissions is a bitmask of access permissions for a PDF file.
type Permissions uint32 ;func (_bda stdHandlerR4 )alg5 (_fb []byte ,_cga []byte )([]byte ,error ){_cad :=_afg .New ();_cad .Write ([]byte (_abg ));_cad .Write ([]byte (_bda .ID0 ));_fgg :=_cad .Sum (nil );_aa .Log .Trace ("\u0061\u006c\u0067\u0035");_aa .Log .Trace ("\u0065k\u0065\u0079\u003a\u0020\u0025\u0020x",_fb );_aa .Log .Trace ("\u0049D\u003a\u0020\u0025\u0020\u0078",_bda .ID0 );if len (_fgg )!=16{return nil ,_ge .New ("\u0068a\u0073\u0068\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006eo\u0074\u0020\u0031\u0036\u0020\u0062\u0079\u0074\u0065\u0073");};_fbb ,_daf :=_ca .NewCipher (_fb );if _daf !=nil {return nil ,_ge .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_ccg :=make ([]byte ,16);_fbb .XORKeyStream (_ccg ,_fgg );_dag :=make ([]byte ,len (_fb ));for _ageg :=0;_ageg < 19;_ageg ++{for _df :=0;_df < len (_fb );_df ++{_dag [_df ]=_fb [_df ]^byte (_ageg +1);};_fbb ,_daf =_ca .NewCipher (_dag );if _daf !=nil {return nil ,_ge .New ("\u0066a\u0069l\u0065\u0064\u0020\u0072\u0063\u0034\u0020\u0063\u0069\u0070\u0068");};_fbb .XORKeyStream (_ccg ,_ccg );_aa .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u002c\u0020\u0065\u006b\u0065\u0079:\u0020\u0025\u0020\u0078",_ageg ,_dag );_aa .Log .Trace ("\u0069\u0020\u003d\u0020\u0025\u0064\u0020\u002d\u003e\u0020\u0025\u0020\u0078",_ageg ,_ccg );};_gdf :=make ([]byte ,32);for _ecf :=0;_ecf < 16;_ecf ++{_gdf [_ecf ]=_ccg [_ecf ];};_ ,_daf =_af .Read (_gdf [16:32]);if _daf !=nil {return nil ,_ge .New ("\u0066a\u0069\u006c\u0065\u0064 \u0074\u006f\u0020\u0067\u0065n\u0020r\u0061n\u0064\u0020\u006e\u0075\u006d\u0062\u0065r");};return _gdf ,nil ;};const (PermOwner =Permissions (_da .MaxUint32 );PermPrinting =Permissions (1<<2);PermModify =Permissions (1<<3);PermExtractGraphics =Permissions (1<<4);PermAnnotate =Permissions (1<<5);PermFillForms =Permissions (1<<8);PermDisabilityExtract =Permissions (1<<9);PermRotateInsert =Permissions (1<<10);PermFullPrintQuality =Permissions (1<<11););

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 (_g "encoding/json";_e "github.com/unidoc/unipdf/v3/core";_ea "github.com/unidoc/unipdf/v3/model";_fd "io";_f "os";);type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
package fjson ;import (_bd "encoding/json";_db "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";_d "io";_a "os";);
// FieldValues implements model.FieldValueProvider interface.
func (_cee *FieldData )FieldValues ()(map[string ]_db .PdfObject ,error ){_cba :=make (map[string ]_db .PdfObject );for _ ,_dcg :=range _cee ._ef {if len (_dcg .Value )> 0{_cba [_dcg .Name ]=_db .MakeString (_dcg .Value );};};return _cba ,nil ;};
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_bc ,_f :=_a .Open (filePath );if _f !=nil {return nil ,_f ;};defer _bc .Close ();return LoadFromJSON (_bc );};
// LoadFromJSON loads JSON form data from `r`.
func LoadFromJSON (r _d .Reader )(*FieldData ,error ){var _g FieldData ;_dd :=_bd .NewDecoder (r ).Decode (&_g ._ef );if _dd !=nil {return nil ,_dd ;};return &_g ,nil ;};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fgg ,_gde :=_a .Open (filePath );if _gde !=nil {return nil ,_gde ;};defer _fgg .Close ();return LoadFromPDF (_fgg );};
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_ef []fieldValue };
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _d .ReadSeeker )(*FieldData ,error ){_ac ,_c :=_e .NewPdfReader (rs );if _c !=nil {return nil ,_c ;};if _ac .AcroForm ==nil {return nil ,nil ;};var _da []fieldValue ;_ge :=_ac .AcroForm .AllFields ();for _ ,_ad :=range _ge {var _dfd []string ;_gg :=make (map[string ]struct{});_dda ,_eff :=_ad .FullName ();if _eff !=nil {return nil ,_eff ;};if _bg ,_gb :=_ad .V .(*_db .PdfObjectString );_gb {_da =append (_da ,fieldValue {Name :_dda ,Value :_bg .Decoded ()});continue ;};var _ggd string ;for _ ,_de :=range _ad .Annotations {_cc ,_eg :=_db .GetName (_de .AS );if _eg {_ggd =_cc .String ();};_bgb ,_cb :=_db .GetDict (_de .AP );if !_cb {continue ;};_ddd ,_ :=_db .GetDict (_bgb .Get ("\u004e"));for _ ,_egd :=range _ddd .Keys (){_ff :=_egd .String ();if _ ,_ea :=_gg [_ff ];!_ea {_dfd =append (_dfd ,_ff );_gg [_ff ]=struct{}{};};};_gd ,_ :=_db .GetDict (_bgb .Get ("\u0044"));for _ ,_ce :=range _gd .Keys (){_fac :=_ce .String ();if _ ,_cab :=_gg [_fac ];!_cab {_dfd =append (_dfd ,_fac );_gg [_fac ]=struct{}{};};};};_acf :=fieldValue {Name :_dda ,Value :_ggd ,Options :_dfd };_da =append (_da ,_acf );};_ddg :=FieldData {_ef :_da };return &_ddg ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
// Options lists allowed values if present.
Options []string `json:"options,omitempty"`;};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _fd .ReadSeeker )(*FieldData ,error ){_c ,_cc :=_ea .NewPdfReader (rs );if _cc !=nil {return nil ,_cc ;};if _c .AcroForm ==nil {return nil ,nil ;};var _fda []fieldValue ;_gb :=_c .AcroForm .AllFields ();for _ ,_bd :=range _gb {var _ab []string ;_gae :=make (map[string ]struct{});_db ,_cg :=_bd .FullName ();if _cg !=nil {return nil ,_cg ;};if _bg ,_fg :=_bd .V .(*_e .PdfObjectString );_fg {_fda =append (_fda ,fieldValue {Name :_db ,Value :_bg .Decoded ()});continue ;};var _bb string ;for _ ,_ead :=range _bd .Annotations {_ad ,_dc :=_e .GetName (_ead .AS );if _dc {_bb =_ad .String ();};_cd ,_ee :=_e .GetDict (_ead .AP );if !_ee {continue ;};_ca ,_ :=_e .GetDict (_cd .Get ("\u004e"));for _ ,_ef :=range _ca .Keys (){_efg :=_ef .String ();if _ ,_dbg :=_gae [_efg ];!_dbg {_ab =append (_ab ,_efg );_gae [_efg ]=struct{}{};};};_ae ,_ :=_e .GetDict (_cd .Get ("\u0044"));for _ ,_efb :=range _ae .Keys (){_ba :=_efb .String ();if _ ,_bf :=_gae [_ba ];!_bf {_ab =append (_ab ,_ba );_gae [_ba ]=struct{}{};};};};_ge :=fieldValue {Name :_db ,Value :_bb ,Options :_ab };_fda =append (_fda ,_ge );};_eaf :=FieldData {_fb :_fda };return &_eaf ,nil ;};
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_a ,_ga :=_f .Open (filePath );if _ga !=nil {return nil ,_ga ;};defer _a .Close ();return LoadFromJSON (_a );};
// FieldValues implements model.FieldValueProvider interface.
func (_bfd *FieldData )FieldValues ()(map[string ]_e .PdfObject ,error ){_gc :=make (map[string ]_e .PdfObject );for _ ,_af :=range _bfd ._fb {if len (_af .Value )> 0{_gc [_af .Name ]=_e .MakeString (_af .Value );};};return _gc ,nil ;};
// JSON returns the field data as a string in JSON format.
func (_bddc FieldData )JSON ()(string ,error ){_geb ,_bfe :=_g .MarshalIndent (_bddc ._fb ,"","\u0020\u0020\u0020\u0020");return string (_geb ),_bfe ;};
// LoadFromJSON loads JSON form data from `r`.
func LoadFromJSON (r _fd .Reader )(*FieldData ,error ){var _d FieldData ;_eg :=_g .NewDecoder (r ).Decode (&_d ._fb );if _eg !=nil {return nil ,_eg ;};return &_d ,nil ;};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fc ,_bfb :=_f .Open (filePath );if _bfb !=nil {return nil ,_bfb ;};defer _fc .Close ();return LoadFromPDF (_fc );};
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_fb []fieldValue };
func (_gdg FieldData )JSON ()(string ,error ){_adf ,_bcad :=_bd .MarshalIndent (_gdg ._ef ,"","\u0020\u0020\u0020\u0020");return string (_adf ),_bcad ;};

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

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 _g "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func (_d IntsMap )Add (key uint64 ,value int ){_d [key ]=append (_d [key ],value )};func (_gf *NumSlice )Add (v float32 ){*_gf =append (*_gf ,v )};func (_ca IntsMap )GetSlice (key uint64 )([]int ,bool ){_gb ,_e :=_ca [key ];if !_e {return nil ,false ;};return _gb ,true ;};func NewIntSlice (i int )*IntSlice {_dc :=IntSlice (make ([]int ,i ));return &_dc };func (_fd IntsMap )Delete (key uint64 ){delete (_fd ,key )};func (_a *IntSlice )Add (v int )error {if _a ==nil {return _g .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");};*_a =append (*_a ,v );return nil ;};type IntsMap map[uint64 ][]int ;func NewNumSlice (i int )*NumSlice {_ef :=NumSlice (make ([]float32 ,i ));return &_ef };func (_cb *Stack )Len ()int {return len (_cb .Data )};func (_fde NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_fde )-1{return 0,_g .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 _fde [i ],nil ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};type NumSlice []float32 ;func (_ad *Stack )Peek ()(_gde interface{},_ee bool ){return _ad .peek ()};func (_ce IntSlice )Size ()int {return len (_ce )};func (_efb *Stack )top ()int {return len (_efb .Data )-1};type IntSlice []int ;func (_aa *IntSlice )Copy ()*IntSlice {_ab :=IntSlice (make ([]int ,len (*_aa )));copy (_ab ,*_aa );return &_ab ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_dg IntsMap )Get (key uint64 )(int ,bool ){_de ,_f :=_dg [key ];if !_f {return 0,false ;};if len (_de )==0{return 0,false ;};return _de [0],true ;};func (_dd IntSlice )Get (index int )(int ,error ){if index > len (_dd )-1{return 0,_g .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 (_gcb *Stack )Push (v interface{}){_gcb .Data =append (_gcb .Data ,v )};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_efa *NumSlice )AddInt (v int ){*_efa =append (*_efa ,float32 (v ))};type Stack struct{Data []interface{};Aux *Stack ;};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_ae NumSlice )GetIntSlice ()[]int {_cc :=make ([]int ,len (_ae ));for _ge ,_gc :=range _ae {_cc [_ge ]=int (_gc );};return _cc ;};func (_gbf *Stack )Pop ()(_gcg interface{},_dge bool ){_gcg ,_dge =_gbf .peek ();if !_dge {return nil ,_dge ;};_gbf .Data =_gbf .Data [:_gbf .top ()];return _gcg ,true ;};func (_dcd NumSlice )GetInt (i int )(int ,error ){const _gd ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_dcd )-1{return 0,_g .Errorf (_gd ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_fg :=_dcd [i ];return int (_fg +Sign (_fg )*0.5),nil ;};func (_fe *Stack )peek ()(interface{},bool ){_dda :=_fe .top ();if _dda ==-1{return nil ,false ;};return _fe .Data [_dda ],true ;};
package basic ;import _c "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_fbd *Stack )Pop ()(_bg interface{},_bag bool ){_bg ,_bag =_fbd .peek ();if !_bag {return nil ,_bag ;};_fbd .Data =_fbd .Data [:_fbd .top ()];return _bg ,true ;};func (_be *Stack )Len ()int {return len (_be .Data )};func NewNumSlice (i int )*NumSlice {_efc :=NumSlice (make ([]float32 ,i ));return &_efc };func (_bc *IntSlice )Add (v int )error {if _bc ==nil {return _c .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");};*_bc =append (*_bc ,v );return nil ;};func (_fb IntsMap )Delete (key uint64 ){delete (_fb ,key )};type IntSlice []int ;func (_b IntsMap )GetSlice (key uint64 )([]int ,bool ){_ac ,_g :=_b [key ];if !_g {return nil ,false ;};return _ac ,true ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_d IntSlice )Get (index int )(int ,error ){if index > len (_d )-1{return 0,_c .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 _d [index ],nil ;};type Stack struct{Data []interface{};Aux *Stack ;};func (_bb *NumSlice )AddInt (v int ){*_bb =append (*_bb ,float32 (v ))};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_a IntsMap )Get (key uint64 )(int ,bool ){_ad ,_f :=_a [key ];if !_f {return 0,false ;};if len (_ad )==0{return 0,false ;};return _ad [0],true ;};type NumSlice []float32 ;func (_adb *Stack )top ()int {return len (_adb .Data )-1};func (_bcc NumSlice )GetInt (i int )(int ,error ){const _ag ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_bcc )-1{return 0,_c .Errorf (_ag ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cc :=_bcc [i ];return int (_cc +Sign (_cc )*0.5),nil ;};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_fg *Stack )Peek ()(_bd interface{},_da bool ){return _fg .peek ()};func (_ga NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ga )-1{return 0,_c .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 _ga [i ],nil ;};func (_fa *Stack )Push (v interface{}){_fa .Data =append (_fa .Data ,v )};func NewIntSlice (i int )*IntSlice {_efb :=IntSlice (make ([]int ,i ));return &_efb };func (_gf *IntSlice )Copy ()*IntSlice {_eb :=IntSlice (make ([]int ,len (*_gf )));copy (_eb ,*_gf );return &_eb ;};func (_faf *Stack )peek ()(interface{},bool ){_fgc :=_faf .top ();if _fgc ==-1{return nil ,false ;};return _faf .Data [_fgc ],true ;};func (_agf NumSlice )GetIntSlice ()[]int {_ca :=make ([]int ,len (_agf ));for _dc ,_ba :=range _agf {_ca [_dc ]=int (_ba );};return _ca ;};type IntsMap map[uint64 ][]int ;func (_gc IntSlice )Size ()int {return len (_gc )};func (_ef IntsMap )Add (key uint64 ,value int ){_ef [key ]=append (_ef [key ],value )};func (_aa *NumSlice )Add (v float32 ){*_aa =append (*_aa ,v )};

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";_ac "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_f "github.com/unidoc/unipdf/v3/internal/jbig2/document";_c "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_g "image";);func (_bd *Decoder )DecodePageImage (pageNumber int )(_g .Image ,error ){const _de ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bf ,_fg :=_bd .decodePageImage (pageNumber );if _fg !=nil {return nil ,_c .Wrap (_fg ,_de ,"");};return _bf ,nil ;};type Decoder struct{_b _a .StreamReader ;_gb *_f .Document ;_e int ;_ag Parameters ;};func (_aa *Decoder )DecodeNextPage ()([]byte ,error ){_aa ._e ++;_fb :=_aa ._e ;return _aa .decodePage (_fb );};type Parameters struct{UnpaddedData bool ;Color _ac .Color ;};func (_eg *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _eg .decodePage (pageNumber )};func (_af *Decoder )decodePageImage (_abf int )(_g .Image ,error ){const _egb ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _abf < 0{return nil ,_c .Errorf (_egb ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_abf );};if _abf > int (_af ._gb .NumberOfPages ){return nil ,_c .Errorf (_egb ,"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",_abf );};_ce ,_dg :=_af ._gb .GetPage (_abf );if _dg !=nil {return nil ,_c .Wrap (_dg ,_egb ,"");};_gbe ,_dg :=_ce .GetBitmap ();if _dg !=nil {return nil ,_c .Wrap (_dg ,_egb ,"");};return _gbe .ToImage (),nil ;};func (_bb *Decoder )decodePage (_bc int )([]byte ,error ){const _ec ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _bc < 0{return nil ,_c .Errorf (_ec ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_bc );};if _bc > int (_bb ._gb .NumberOfPages ){return nil ,_c .Errorf (_ec ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_bc );};_bbg ,_fgc :=_bb ._gb .GetPage (_bc );if _fgc !=nil {return nil ,_c .Wrap (_fgc ,_ec ,"");};_abc ,_fgc :=_bbg .GetBitmap ();if _fgc !=nil {return nil ,_c .Wrap (_fgc ,_ec ,"");};_abc .InverseData ();if !_bb ._ag .UnpaddedData {return _abc .Data ,nil ;};return _abc .GetUnpaddedData ();};func Decode (input []byte ,parameters Parameters ,globals *_f .Globals )(*Decoder ,error ){_gd :=_a .NewReader (input );_ge ,_fe :=_f .DecodeDocument (_gd ,globals );if _fe !=nil {return nil ,_fe ;};return &Decoder {_b :_gd ,_gb :_ge ,_ag :parameters },nil ;};func (_ab *Decoder )PageNumber ()(int ,error ){const _fd ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _ab ._gb ==nil {return 0,_c .Error (_fd ,"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 (_ab ._gb .NumberOfPages ),nil ;};
package decoder ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_bb "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_ae "github.com/unidoc/unipdf/v3/internal/jbig2/document";_bf "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_b "image";);type Decoder struct{_ag _g .StreamReader ;_aeg *_ae .Document ;_aa int ;_e Parameters ;};func (_be *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _be .decodePage (pageNumber )};func (_dg *Decoder )decodePageImage (_aacc int )(_b .Image ,error ){const _gf ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _aacc < 0{return nil ,_bf .Errorf (_gf ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_aacc );};if _aacc > int (_dg ._aeg .NumberOfPages ){return nil ,_bf .Errorf (_gf ,"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",_aacc );};_ba ,_bba :=_dg ._aeg .GetPage (_aacc );if _bba !=nil {return nil ,_bf .Wrap (_bba ,_gf ,"");};_fg ,_bba :=_ba .GetBitmap ();if _bba !=nil {return nil ,_bf .Wrap (_bba ,_gf ,"");};return _fg .ToImage (),nil ;};type Parameters struct{UnpaddedData bool ;Color _bb .Color ;};func (_bfb *Decoder )PageNumber ()(int ,error ){const _dc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _bfb ._aeg ==nil {return 0,_bf .Error (_dc ,"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 (_bfb ._aeg .NumberOfPages ),nil ;};func (_aac *Decoder )DecodePageImage (pageNumber int )(_b .Image ,error ){const _f ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bea ,_gc :=_aac .decodePageImage (pageNumber );if _gc !=nil {return nil ,_bf .Wrap (_gc ,_f ,"");};return _bea ,nil ;};func Decode (input []byte ,parameters Parameters ,globals *_ae .Globals )(*Decoder ,error ){_bfbb :=_g .NewReader (input );_ef ,_ac :=_ae .DecodeDocument (_bfbb ,globals );if _ac !=nil {return nil ,_ac ;};return &Decoder {_ag :_bfbb ,_aeg :_ef ,_e :parameters },nil ;};func (_d *Decoder )DecodeNextPage ()([]byte ,error ){_d ._aa ++;_c :=_d ._aa ;return _d .decodePage (_c )};func (_aga *Decoder )decodePage (_beb int )([]byte ,error ){const _de ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _beb < 0{return nil ,_bf .Errorf (_de ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_beb );};if _beb > int (_aga ._aeg .NumberOfPages ){return nil ,_bf .Errorf (_de ,"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",_beb );};_cg ,_fa :=_aga ._aeg .GetPage (_beb );if _fa !=nil {return nil ,_bf .Wrap (_fa ,_de ,"");};_cgd ,_fa :=_cg .GetBitmap ();if _fa !=nil {return nil ,_bf .Wrap (_fa ,_de ,"");};_cgd .InverseData ();if !_aga ._e .UnpaddedData {return _cgd .Data ,nil ;};return _cgd .GetUnpaddedData ();};

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 _a "fmt";func Error (processName ,message string )error {return _cc (message ,processName )};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _cg ,_eb :=err .(*processError );_eb {_cg ._af ="";};_d :=_cc (_a .Sprintf (message ,arguments ...),processName );_d ._b =err ;return _d ;};type processError struct{_af string ;_c string ;_e string ;_b error ;};func Wrap (err error ,processName ,message string )error {if _ea ,_ef :=err .(*processError );_ef {_ea ._af ="";};_afc :=_cc (message ,processName );_afc ._b =err ;return _afc ;};func (_ae *processError )Error ()string {var _g string ;if _ae ._af !=""{_g =_ae ._af ;};_g +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_ae ._c ;if _ae ._e !=""{_g +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_ae ._e ;};if _ae ._b !=nil {_g +="\u002e\u0020"+_ae ._b .Error ();};return _g ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _cc (_a .Sprintf (message ,arguments ...),processName );};func _cc (_ff ,_cd string )*processError {return &processError {_af :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_e :_ff ,_c :_cd };};
package errors ;import _g "fmt";func Errorf (processName ,message string ,arguments ...interface{})error {return _ab (_g .Sprintf (message ,arguments ...),processName );};type processError struct{_d string ;_bf string ;_a string ;_c error ;};func Wrap (err error ,processName ,message string )error {if _ef ,_adb :=err .(*processError );_adb {_ef ._d ="";};_f :=_ab (message ,processName );_f ._c =err ;return _f ;};func (_cg *processError )Error ()string {var _da string ;if _cg ._d !=""{_da =_cg ._d ;};_da +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_cg ._bf ;if _cg ._a !=""{_da +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_cg ._a ;};if _cg ._c !=nil {_da +="\u002e\u0020"+_cg ._c .Error ();};return _da ;};func Error (processName ,message string )error {return _ab (message ,processName )};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _dg ,_ea :=err .(*processError );_ea {_dg ._d ="";};_db :=_ab (_g .Sprintf (message ,arguments ...),processName );_db ._c =err ;return _db ;};func _ab (_e ,_ad string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_a :_e ,_bf :_ad };};

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 (_c "github.com/unidoc/unipdf/v3/internal/bitwise";_g "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_f "github.com/unidoc/unipdf/v3/internal/jbig2/document";_d "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_ca "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_ac "sort";);func DecodeBytes (encoded []byte ,parameters _g .Parameters ,globals ...Globals )([]byte ,error ){var _b Globals ;if len (globals )> 0{_b =globals [0];};_cad ,_bb :=_g .Decode (encoded ,parameters ,_b .ToDocumentGlobals ());if _bb !=nil {return nil ,_bb ;};return _cad .DecodeNextPage ();};type Globals map[int ]*_d .Header ;func (_gdc Globals )ToDocumentGlobals ()*_f .Globals {if _gdc ==nil {return nil ;};_cf :=[]*_d .Header {};for _ ,_gb :=range _gdc {_cf =append (_cf ,_gb );};_ac .Slice (_cf ,func (_cg ,_bbb int )bool {return _cf [_cg ].SegmentNumber < _cf [_bbb ].SegmentNumber });return &_f .Globals {Segments :_cf };};func DecodeGlobals (encoded []byte )(Globals ,error ){const _fa ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_af :=_c .NewReader (encoded );_gg ,_gd :=_f .DecodeDocument (_af ,nil );if _gd !=nil {return nil ,_ca .Wrap (_gd ,_fa ,"");};if _gg .GlobalSegments ==nil ||(_gg .GlobalSegments .Segments ==nil ){return nil ,_ca .Error (_fa ,"\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 _ ,_bc :=range _gg .GlobalSegments .Segments {_ad [int (_bc .SegmentNumber )]=_bc ;};return _ad ,nil ;};
package jbig2 ;import (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_bae "github.com/unidoc/unipdf/v3/internal/jbig2/document";_g "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_bg "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_ba "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _c ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_be :=_e .NewReader (encoded );_dc ,_ce :=_bae .DecodeDocument (_be ,nil );if _ce !=nil {return nil ,_bg .Wrap (_ce ,_c ,"");};if _dc .GlobalSegments ==nil ||(_dc .GlobalSegments .Segments ==nil ){return nil ,_bg .Error (_c ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_gf :=Globals {};for _ ,_cg :=range _dc .GlobalSegments .Segments {_gf [int (_cg .SegmentNumber )]=_cg ;};return _gf ,nil ;};func (_efd Globals )ToDocumentGlobals ()*_bae .Globals {if _efd ==nil {return nil ;};_f :=[]*_g .Header {};for _ ,_a :=range _efd {_f =append (_f ,_a );};_ba .Slice (_f ,func (_fe ,_ac int )bool {return _f [_fe ].SegmentNumber < _f [_ac ].SegmentNumber });return &_bae .Globals {Segments :_f };};type Globals map[int ]*_g .Header ;func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _bab Globals ;if len (globals )> 0{_bab =globals [0];};_eg ,_ef :=_d .Decode (encoded ,parameters ,_bab .ToDocumentGlobals ());if _ef !=nil {return nil ,_ef ;};return _eg .DecodeNextPage ();};

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 (_a "github.com/unidoc/unipdf/v3/internal/bitwise";_g "github.com/unidoc/unipdf/v3/internal/imageutil";_e "io";);func (_eg *Reader )ReadSamples (samples []uint32 )(_fd error ){for _c :=0;_c < len (samples );_c ++{samples [_c ],_fd =_eg .ReadSample ();if _fd !=nil {return _fd ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ff []uint32 ;_ab :=bitsPerSample ;var _ef uint32 ;var _ggd byte ;_bd :=0;_bf :=0;_ed :=0;for _ed < len (data ){if _bd > 0{_aff :=_bd ;if _ab < _aff {_aff =_ab ;};_ef =(_ef <<uint (_aff ))|uint32 (_ggd >>uint (8-_aff ));_bd -=_aff ;if _bd > 0{_ggd =_ggd <<uint (_aff );}else {_ggd =0;};_ab -=_aff ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};}else {_bb :=data [_ed ];_ed ++;_fef :=8;if _ab < _fef {_fef =_ab ;};_bd =8-_fef ;_ef =(_ef <<uint (_fef ))|uint32 (_bb >>uint (_bd ));if _fef < 8{_ggd =_bb <<uint (_fef );};_ab -=_fef ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};};};for _bd >=bitsPerSample {_ce :=_bd ;if _ab < _ce {_ce =_ab ;};_ef =(_ef <<uint (_ce ))|uint32 (_ggd >>uint (8-_ce ));_bd -=_ce ;if _bd > 0{_ggd =_ggd <<uint (_ce );}else {_ggd =0;};_ab -=_ce ;if _ab ==0{_ff =append (_ff ,_ef );_ab =bitsPerSample ;_ef =0;_bf ++;};};return _ff ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ea []uint32 )error ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _dd []uint32 ;_efe :=bitsPerOutputSample ;var _gd uint32 ;var _ca uint32 ;_ag :=0;_ae :=0;_db :=0;for _db < len (data ){if _ag > 0{_ege :=_ag ;if _efe < _ege {_ege =_efe ;};_gd =(_gd <<uint (_ege ))|uint32 (_ca >>uint (bitsPerInputSample -_ege ));_ag -=_ege ;if _ag > 0{_ca =_ca <<uint (_ege );}else {_ca =0;};_efe -=_ege ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};}else {_dg :=data [_db ];_db ++;_bbe :=bitsPerInputSample ;if _efe < _bbe {_bbe =_efe ;};_ag =bitsPerInputSample -_bbe ;_gd =(_gd <<uint (_bbe ))|uint32 (_dg >>uint (_ag ));if _bbe < bitsPerInputSample {_ca =_dg <<uint (_bbe );};_efe -=_bbe ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};};};for _ag >=bitsPerOutputSample {_eac :=_ag ;if _efe < _eac {_eac =_efe ;};_gd =(_gd <<uint (_eac ))|uint32 (_ca >>uint (bitsPerInputSample -_eac ));_ag -=_eac ;if _ag > 0{_ca =_ca <<uint (_eac );}else {_ca =0;};_efe -=_eac ;if _efe ==0{_dd =append (_dd ,_gd );_efe =bitsPerOutputSample ;_gd =0;_ae ++;};};if _efe > 0&&_efe < bitsPerOutputSample {_gd <<=uint (_efe );_dd =append (_dd ,_gd );};return _dd ;};func (_bbb *Writer )WriteSample (sample uint32 )error {if _ ,_geg :=_bbb ._cc .WriteBits (uint64 (sample ),_bbb ._afb .BitsPerComponent );_geg !=nil {return _geg ;};_bbb ._ggf --;if _bbb ._ggf ==0{_bbb ._ggf =_bbb ._afb .ColorComponents ;_bbb ._cec ++;};if _bbb ._cec ==_bbb ._afb .Width {if _bbb ._fbd {_bbb ._cc .FinishByte ();};_bbb ._cec =0;};return nil ;};type SampleWriter interface{WriteSample (_gdf uint32 )error ;WriteSamples (_ge []uint32 )error ;};func (_aa *Writer )WriteSamples (samples []uint32 )error {for _fbc :=0;_fbc < len (samples );_fbc ++{if _fed :=_aa .WriteSample (samples [_fbc ]);_fed !=nil {return _fed ;};};return nil ;};func NewReader (img _g .ImageBase )*Reader {return &Reader {_fe :_a .NewReader (img .Data ),_f :img ,_ga :img .ColorComponents ,_dc :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type Reader struct{_f _g .ImageBase ;_fe *_a .Reader ;_b ,_gg ,_ga int ;_dc bool ;};func (_fb *Reader )ReadSample ()(uint32 ,error ){if _fb ._gg ==_fb ._f .Height {return 0,_e .EOF ;};_fg ,_af :=_fb ._fe .ReadBits (byte (_fb ._f .BitsPerComponent ));if _af !=nil {return 0,_af ;};_fb ._ga --;if _fb ._ga ==0{_fb ._ga =_fb ._f .ColorComponents ;_fb ._b ++;};if _fb ._b ==_fb ._f .Width {if _fb ._dc {_fb ._fe .ConsumeRemainingBits ();};_fb ._b =0;_fb ._gg ++;};return uint32 (_fg ),nil ;};type Writer struct{_afb _g .ImageBase ;_cc *_a .Writer ;_cec ,_ggf int ;_fbd bool ;};func NewWriter (img _g .ImageBase )*Writer {return &Writer {_cc :_a .NewWriterMSB (img .Data ),_afb :img ,_ggf :img .ColorComponents ,_fbd :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};
package sampling ;import (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_eb "github.com/unidoc/unipdf/v3/internal/imageutil";_f "io";);func (_efg *Writer )WriteSample (sample uint32 )error {if _ ,_bea :=_efg ._ff .WriteBits (uint64 (sample ),_efg ._db .BitsPerComponent );_bea !=nil {return _bea ;};_efg ._dae --;if _efg ._dae ==0{_efg ._dae =_efg ._db .ColorComponents ;_efg ._fa ++;};if _efg ._fa ==_efg ._db .Width {if _efg ._beg {_efg ._ff .FinishByte ();};_efg ._fa =0;};return nil ;};func (_fe *Reader )ReadSample ()(uint32 ,error ){if _fe ._a ==_fe ._g .Height {return 0,_f .EOF ;};_eg ,_gg :=_fe ._d .ReadBits (byte (_fe ._g .BitsPerComponent ));if _gg !=nil {return 0,_gg ;};_fe ._ea --;if _fe ._ea ==0{_fe ._ea =_fe ._g .ColorComponents ;_fe ._gf ++;};if _fe ._gf ==_fe ._g .Width {if _fe ._ed {_fe ._d .ConsumeRemainingBits ();};_fe ._gf =0;_fe ._a ++;};return uint32 (_eg ),nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _dd []uint32 ;_ga :=bitsPerSample ;var _da uint32 ;var _fg byte ;_bc :=0;_fc :=0;_egf :=0;for _egf < len (data ){if _bc > 0{_bb :=_bc ;if _ga < _bb {_bb =_ga ;};_da =(_da <<uint (_bb ))|uint32 (_fg >>uint (8-_bb ));_bc -=_bb ;if _bc > 0{_fg =_fg <<uint (_bb );}else {_fg =0;};_ga -=_bb ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};}else {_ebb :=data [_egf ];_egf ++;_bf :=8;if _ga < _bf {_bf =_ga ;};_bc =8-_bf ;_da =(_da <<uint (_bf ))|uint32 (_ebb >>uint (_bc ));if _bf < 8{_fg =_ebb <<uint (_bf );};_ga -=_bf ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};};};for _bc >=bitsPerSample {_fed :=_bc ;if _ga < _fed {_fed =_ga ;};_da =(_da <<uint (_fed ))|uint32 (_fg >>uint (8-_fed ));_bc -=_fed ;if _bc > 0{_fg =_fg <<uint (_fed );}else {_fg =0;};_ga -=_fed ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};};return _dd ;};type Reader struct{_g _eb .ImageBase ;_d *_b .Reader ;_gf ,_a ,_ea int ;_ed bool ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _gd []uint32 ;_aa :=bitsPerOutputSample ;var _edd uint32 ;var _ggf uint32 ;_ag :=0;_gdb :=0;_ge :=0;for _ge < len (data ){if _ag > 0{_ggc :=_ag ;if _aa < _ggc {_ggc =_aa ;};_edd =(_edd <<uint (_ggc ))|uint32 (_ggf >>uint (bitsPerInputSample -_ggc ));_ag -=_ggc ;if _ag > 0{_ggf =_ggf <<uint (_ggc );}else {_ggf =0;};_aa -=_ggc ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};}else {_be :=data [_ge ];_ge ++;_df :=bitsPerInputSample ;if _aa < _df {_df =_aa ;};_ag =bitsPerInputSample -_df ;_edd =(_edd <<uint (_df ))|uint32 (_be >>uint (_ag ));if _df < bitsPerInputSample {_ggf =_be <<uint (_df );};_aa -=_df ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};};};for _ag >=bitsPerOutputSample {_de :=_ag ;if _aa < _de {_de =_aa ;};_edd =(_edd <<uint (_de ))|uint32 (_ggf >>uint (bitsPerInputSample -_de ));_ag -=_de ;if _ag > 0{_ggf =_ggf <<uint (_de );}else {_ggf =0;};_aa -=_de ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};};if _aa > 0&&_aa < bitsPerOutputSample {_edd <<=uint (_aa );_gd =append (_gd ,_edd );};return _gd ;};func NewReader (img _eb .ImageBase )*Reader {return &Reader {_d :_b .NewReader (img .Data ),_g :img ,_ea :img .ColorComponents ,_ed :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_beaf *Writer )WriteSamples (samples []uint32 )error {for _bbd :=0;_bbd < len (samples );_bbd ++{if _gb :=_beaf .WriteSample (samples [_bbd ]);_gb !=nil {return _gb ;};};return nil ;};func NewWriter (img _eb .ImageBase )*Writer {return &Writer {_ff :_b .NewWriterMSB (img .Data ),_db :img ,_dae :img .ColorComponents ,_beg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ec []uint32 )error ;};type SampleWriter interface{WriteSample (_bd uint32 )error ;WriteSamples (_gda []uint32 )error ;};type Writer struct{_db _eb .ImageBase ;_ff *_b .Writer ;_fa ,_dae int ;_beg bool ;};func (_ab *Reader )ReadSamples (samples []uint32 )(_ef error ){for _ebd :=0;_ebd < len (samples );_ebd ++{samples [_ebd ],_ef =_ab .ReadSample ();if _ef !=nil {return _ef ;};};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,43 +10,37 @@
// 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 (_g "bytes";_dd "crypto";_e "crypto/rand";_ab "crypto/rsa";_ag "crypto/x509";_fcd "crypto/x509/pkix";_ad "encoding/asn1";_gc "errors";_db "fmt";_ge "github.com/unidoc/pkcs7";_af "github.com/unidoc/timestamp";_bd "github.com/unidoc/unipdf/v3/core";_c "github.com/unidoc/unipdf/v3/model";_b "hash";_d "io";_fcg "io/ioutil";_fc "net/http";_f "time";);
package sighandler ;import (_eb "bytes";_eg "crypto";_af "crypto/rand";_ec "crypto/rsa";_gg "crypto/x509";_fc "crypto/x509/pkix";_aa "encoding/asn1";_ff "errors";_bg "fmt";_ggf "github.com/unidoc/pkcs7";_bgb "github.com/unidoc/timestamp";_d "github.com/unidoc/unipdf/v3/core";_fb "github.com/unidoc/unipdf/v3/model";_g "hash";_f "io";_bb "io/ioutil";_b "net/http";_a "time";);
// 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 *_ag .Certificate ,signFunc SignFunc )(_c .SignatureHandler ,error ){return &adobeX509RSASHA1 {_dea :certificate ,_dcd :signFunc },nil ;};
// NewEmptyAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached
// signature handler. The generated signature is empty and of size signatureLen.
// The signatureLen parameter can be 0 for the signature validation.
func NewEmptyAdobePKCS7Detached (signatureLen int )(_fb .SignatureHandler ,error ){return &adobePKCS7Detached {_c :true ,_aaf :signatureLen },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_ag *adobePKCS7Detached )IsApplicable (sig *_fb .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";};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// 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.
// 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 _eg .Hash )(_fb .SignatureHandler ,error ){return &docTimeStamp {_fbgb :timestampServerURL ,_ceb :hashAlgorithm },nil ;};
// NewDigest creates a new digest.
func (_fa *adobeX509RSASHA1 )NewDigest (sig *_c .PdfSignature )(_c .Hasher ,error ){_dba ,_dad :=_fa .getCertificate (sig );if _dad !=nil {return nil ,_dad ;};_fda ,_ :=_dgc (_dba .SignatureAlgorithm );return _fda .New (),nil ;};
func (_dfb *docTimeStamp )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){return _eb .NewBuffer (nil ),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 *_ab .PrivateKey ,certificate *_ag .Certificate )(_c .SignatureHandler ,error ){return &adobePKCS7Detached {_gg :certificate ,_fd :privateKey },nil ;};
// Validate validates PdfSignature.
func (_daa *adobeX509RSASHA1 )Validate (sig *_c .PdfSignature ,digest _c .Hasher )(_c .SignatureValidationResult ,error ){_fea ,_bcf :=_daa .getCertificate (sig );if _bcf !=nil {return _c .SignatureValidationResult {},_bcf ;};_ae :=sig .Contents .Bytes ();var _bcb []byte ;if _ ,_cfc :=_ad .Unmarshal (_ae ,&_bcb );_cfc !=nil {return _c .SignatureValidationResult {},_cfc ;};_aaf ,_ff :=digest .(_b .Hash );if !_ff {return _c .SignatureValidationResult {},_gc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_cgg ,_ :=_dgc (_fea .SignatureAlgorithm );if _bg :=_ab .VerifyPKCS1v15 (_fea .PublicKey .(*_ab .PublicKey ),_cgg ,_aaf .Sum (nil ),_bcb );_bg !=nil {return _c .SignatureValidationResult {},_bg ;};return _c .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// NewDigest creates a new digest.
func (_daga *docTimeStamp )NewDigest (sig *_c .PdfSignature )(_c .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
// Validate validates PdfSignature.
func (_dde *docTimeStamp )Validate (sig *_c .PdfSignature ,digest _c .Hasher )(_c .SignatureValidationResult ,error ){_fff :=sig .Contents .Bytes ();_bgg ,_fdg :=_ge .Parse (_fff );if _fdg !=nil {return _c .SignatureValidationResult {},_fdg ;};if _fdg =_bgg .Verify ();_fdg !=nil {return _c .SignatureValidationResult {},_fdg ;};var _bbf timestampInfo ;_ ,_fdg =_ad .Unmarshal (_bgg .Content ,&_bbf );if _fdg !=nil {return _c .SignatureValidationResult {},_fdg ;};_feaa ,_fdg :=_gfd (_bbf .MessageImprint .HashAlgorithm .Algorithm );if _fdg !=nil {return _c .SignatureValidationResult {},_fdg ;};_fbd :=_feaa .New ();_acd :=digest .(*_g .Buffer );_fbd .Write (_acd .Bytes ());_fcdc :=_fbd .Sum (nil );_bcfb :=_c .SignatureValidationResult {IsSigned :true ,IsVerified :_g .Equal (_fcdc ,_bbf .MessageImprint .HashedMessage ),GeneralizedTime :_bbf .GeneralizedTime };return _bcfb ,nil ;};
// InitSignature initialises the PdfSignature.
func (_da *adobeX509RSASHA1 )InitSignature (sig *_c .PdfSignature )error {if _da ._dea ==nil {return _gc .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 _da ._gd ==nil &&_da ._dcd ==nil {return _gc .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");};_cad :=*_da ;sig .Handler =&_cad ;sig .Filter =_bd .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_bd .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_bd .MakeString (string (_cad ._dea .Raw ));sig .Reference =nil ;_cadb ,_cc :=_cad .NewDigest (sig );if _cc !=nil {return _cc ;};_cadb .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 _cad .Sign (sig ,_cadb );};func (_efg *adobeX509RSASHA1 )getCertificate (_fcgc *_c .PdfSignature )(*_ag .Certificate ,error ){if _efg ._dea !=nil {return _efg ._dea ,nil ;};var _agf []byte ;switch _eg :=_fcgc .Cert .(type ){case *_bd .PdfObjectString :_agf =_eg .Bytes ();case *_bd .PdfObjectArray :if _eg .Len ()==0{return nil ,_gc .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 _ ,_feg :=range _eg .Elements (){_dag ,_ddg :=_bd .GetString (_feg );if !_ddg {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_feg );};_agf =append (_agf ,_dag .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_eg );};_bc ,_eaf :=_ag .ParseCertificates (_agf );if _eaf !=nil {return nil ,_eaf ;};return _bc [0],nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_ccc *adobeX509RSASHA1 )Sign (sig *_c .PdfSignature ,digest _c .Hasher )error {var _bae []byte ;var _ce error ;if _ccc ._dcd !=nil {_bae ,_ce =_ccc ._dcd (sig ,digest );if _ce !=nil {return _ce ;};}else {_adb ,_df :=digest .(_b .Hash );if !_df {return _gc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ddgc ,_ :=_dgc (_ccc ._dea .SignatureAlgorithm );_bae ,_ce =_ab .SignPKCS1v15 (_e .Reader ,_ccc ._gd ,_ddgc ,_adb .Sum (nil ));if _ce !=nil {return _ce ;};};_bae ,_ce =_ad .Marshal (_bae );if _ce !=nil {return _ce ;};sig .Contents =_bd .MakeHexString (string (_bae ));return nil ;};
// InitSignature initialises the PdfSignature.
func (_ea *adobePKCS7Detached )InitSignature (sig *_c .PdfSignature )error {if !_ea ._ga {if _ea ._gg ==nil {return _gc .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 _ea ._fd ==nil {return _gc .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");};};_adg :=*_ea ;sig .Handler =&_adg ;sig .Filter =_bd .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_bd .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_gga ,_bf :=_adg .NewDigest (sig );if _bf !=nil {return _bf ;};_gga .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 _adg .Sign (sig ,_gga );};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_gca *adobeX509RSASHA1 )IsApplicable (sig *_fb .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};
// Sign sets the Contents fields.
func (_dec *adobePKCS7Detached )Sign (sig *_c .PdfSignature ,digest _c .Hasher )error {if _dec ._ga {_dg :=_dec ._cg ;if _dg <=0{_dg =8192;};sig .Contents =_bd .MakeHexString (string (make ([]byte ,_dg )));return nil ;};_bfb :=digest .(*_g .Buffer );_gfg ,_afg :=_ge .NewSignedData (_bfb .Bytes ());if _afg !=nil {return _afg ;};if _ac :=_gfg .AddSigner (_dec ._gg ,_dec ._fd ,_ge .SignerInfoConfig {});_ac !=nil {return _ac ;};_gfg .Detach ();_abd ,_afg :=_gfg .Finish ();if _afg !=nil {return _afg ;};_ca :=make ([]byte ,8192);copy (_ca ,_abd );sig .Contents =_bd .MakeHexString (string (_ca ));return nil ;};type adobeX509RSASHA1 struct{_gd *_ab .PrivateKey ;_dea *_ag .Certificate ;_dcd SignFunc ;};
func (_ca *adobePKCS7Detached )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {if _ca ._c {_cc :=_ca ._aaf ;if _cc <=0{_cc =8192;};sig .Contents =_d .MakeHexString (string (make ([]byte ,_cc )));return nil ;};_ged :=digest .(*_eb .Buffer );_fd ,_ee :=_ggf .NewSignedData (_ged .Bytes ());if _ee !=nil {return _ee ;};if _cf :=_fd .AddSigner (_ca ._da ,_ca ._aaa ,_ggf .SignerInfoConfig {});_cf !=nil {return _cf ;};_fd .Detach ();_fe ,_ee :=_fd .Finish ();if _ee !=nil {return _ee ;};_daa :=make ([]byte ,8192);copy (_daa ,_fe );sig .Contents =_d .MakeHexString (string (_daa ));return nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_efe *_c .PdfSignature ,_ded _c .Hasher )([]byte ,error );
// Validate validates PdfSignature.
func (_ga *adobePKCS7Detached )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_eca :=sig .Contents .Bytes ();_dg ,_fgc :=_ggf .Parse (_eca );if _fgc !=nil {return _fb .SignatureValidationResult {},_fgc ;};_ba :=digest .(*_eb .Buffer );_dg .Content =_ba .Bytes ();if _fgc =_dg .Verify ();_fgc !=nil {return _fb .SignatureValidationResult {},_fgc ;};return _fb .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// DocTimeStampOpts defines options for configuring the timestamp handler.
type DocTimeStampOpts struct{
@ -58,50 +52,56 @@ type DocTimeStampOpts struct{
// signature.
SignatureSize int ;};
// InitSignature initialises the PdfSignature.
func (_fdb *adobeX509RSASHA1 )InitSignature (sig *_fb .PdfSignature )error {if _fdb ._bad ==nil {return _ff .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 _fdb ._fa ==nil &&_fdb ._df ==nil {return _ff .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");};_fbb :=*_fdb ;sig .Handler =&_fbb ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_d .MakeString (string (_fbb ._bad .Raw ));sig .Reference =nil ;_ae ,_dd :=_fbb .NewDigest (sig );if _dd !=nil {return _dd ;};_ae .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 _fbb .Sign (sig ,_ae );};type docTimeStamp struct{_fbgb string ;_ceb _eg .Hash ;_bab int ;};
// 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 *_gg .Certificate ,signFunc SignFunc )(_fb .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bad :certificate ,_df :signFunc },nil ;};
// InitSignature initialises the PdfSignature.
func (_ffa *adobePKCS7Detached )InitSignature (sig *_fb .PdfSignature )error {if !_ffa ._c {if _ffa ._da ==nil {return _ff .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 _ffa ._aaa ==nil {return _ff .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 :=*_ffa ;sig .Handler =&_cg ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_gc ,_fbg :=_cg .NewDigest (sig );if _fbg !=nil {return _fbg ;};_gc .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 ,_gc );};type adobePKCS7Detached struct{_aaa *_ec .PrivateKey ;_da *_gg .Certificate ;_c bool ;_aaf int ;};
// Validate validates PdfSignature.
func (_eed *docTimeStamp )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_gbg :=sig .Contents .Bytes ();_fdga ,_gfg :=_ggf .Parse (_gbg );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};if _gfg =_fdga .Verify ();_gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};var _ecg timestampInfo ;_ ,_gfg =_aa .Unmarshal (_fdga .Content ,&_ecg );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};_cd ,_gfg :=_afd (_ecg .MessageImprint .HashAlgorithm .Algorithm );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};_aac :=_cd .New ();_cgd :=digest .(*_eb .Buffer );_aac .Write (_cgd .Bytes ());_aag :=_aac .Sum (nil );_ccb :=_fb .SignatureValidationResult {IsSigned :true ,IsVerified :_eb .Equal (_aag ,_ecg .MessageImprint .HashedMessage ),GeneralizedTime :_ecg .GeneralizedTime };return _ccb ,nil ;};type adobeX509RSASHA1 struct{_fa *_ec .PrivateKey ;_bad *_gg .Certificate ;_df SignFunc ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_caa *docTimeStamp )IsApplicable (sig *_fb .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";};func (_ac *docTimeStamp )getCertificate (_gcb *_fb .PdfSignature )(*_gg .Certificate ,error ){var _fde []byte ;switch _ebc :=_gcb .Cert .(type ){case *_d .PdfObjectString :_fde =_ebc .Bytes ();case *_d .PdfObjectArray :if _ebc .Len ()==0{return nil ,_ff .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 _ ,_gbc :=range _ebc .Elements (){_bgc ,_daf :=_d .GetString (_gbc );if !_daf {return nil ,_bg .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",_gbc );};_fde =append (_fde ,_bgc .Bytes ()...);};default:return nil ,_bg .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",_ebc );};_gee ,_fbge :=_gg .ParseCertificates (_fde );if _fbge !=nil {return nil ,_fbge ;};return _gee [0],nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_bf *_fb .PdfSignature ,_aga _fb .Hasher )([]byte ,error );
// 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 *_ec .PrivateKey ,certificate *_gg .Certificate )(_fb .SignatureHandler ,error ){return &adobePKCS7Detached {_da :certificate ,_aaa :privateKey },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 _dd .Hash ,opts *DocTimeStampOpts )(_c .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_ed :timestampServerURL ,_ede :hashAlgorithm ,_abf :opts .SignatureSize },nil ;};type adobePKCS7Detached struct{_fd *_ab .PrivateKey ;_gg *_ag .Certificate ;_ga bool ;_cg int ;};
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _eg .Hash ,opts *DocTimeStampOpts )(_fb .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_fbgb :timestampServerURL ,_ceb :hashAlgorithm ,_bab :opts .SignatureSize },nil ;};
// NewDigest creates a new digest.
func (_bdc *adobeX509RSASHA1 )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){_eee ,_ega :=_bdc .getCertificate (sig );if _ega !=nil {return nil ,_ega ;};_ddf ,_ :=_ebe (_eee .SignatureAlgorithm );return _ddf .New (),nil ;};
// Validate validates PdfSignature.
func (_efc *adobePKCS7Detached )Validate (sig *_c .PdfSignature ,digest _c .Hasher )(_c .SignatureValidationResult ,error ){_bb :=sig .Contents .Bytes ();_dca ,_gf :=_ge .Parse (_bb );if _gf !=nil {return _c .SignatureValidationResult {},_gf ;};_fg :=digest .(*_g .Buffer );_dca .Content =_fg .Bytes ();if _gf =_dca .Verify ();_gf !=nil {return _c .SignatureValidationResult {},_gf ;};return _c .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};func (_bdc *adobePKCS7Detached )getCertificate (_de *_c .PdfSignature )(*_ag .Certificate ,error ){if _bdc ._gg !=nil {return _bdc ._gg ,nil ;};var _ef []byte ;switch _dc :=_de .Cert .(type ){case *_bd .PdfObjectString :_ef =_dc .Bytes ();case *_bd .PdfObjectArray :if _dc .Len ()==0{return nil ,_gc .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 _ ,_ec :=range _dc .Elements (){_cgd ,_gb :=_bd .GetString (_ec );if !_gb {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_ec );};_ef =append (_ef ,_cgd .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_dc );};_eac ,_cge :=_ag .ParseCertificates (_ef );if _cge !=nil {return nil ,_cge ;};return _eac [0],nil ;};func _dgc (_bbg _ag .SignatureAlgorithm )(_dd .Hash ,bool ){var _fe _dd .Hash ;switch _bbg {case _ag .SHA1WithRSA :_fe =_dd .SHA1 ;case _ag .SHA256WithRSA :_fe =_dd .SHA256 ;case _ag .SHA384WithRSA :_fe =_dd .SHA384 ;case _ag .SHA512WithRSA :_fe =_dd .SHA512 ;default:return _dd .SHA1 ,false ;};return _fe ,true ;};
// Sign sets the Contents fields for the PdfSignature.
func (_fcb *docTimeStamp )Sign (sig *_c .PdfSignature ,digest _c .Hasher )error {_eba :=digest .(*_g .Buffer );_fag :=_fcb ._ede .New ();if _ ,_afd :=_d .Copy (_fag ,_eba );_afd !=nil {return _afd ;};_aafg :=_af .Request {HashAlgorithm :_fcb ._ede ,HashedMessage :_fag .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_age ,_cdb :=_aafg .Marshal ();if _cdb !=nil {return _cdb ;};_fed ,_cdb :=_fc .Post (_fcb ._ed ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_g .NewBuffer (_age ));if _cdb !=nil {return _cdb ;};defer _fed .Body .Close ();_cef ,_cdb :=_fcg .ReadAll (_fed .Body );if _cdb !=nil {return _cdb ;};if _fed .StatusCode !=_fc .StatusOK {return _db .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_fed .StatusCode );};var _fbe struct{Version _ad .RawValue ;Content _ad .RawValue ;};if _ ,_cdb =_ad .Unmarshal (_cef ,&_fbe );_cdb !=nil {return _cdb ;};_cbe :=len (_fbe .Content .FullBytes );if _fcb ._abf > 0&&_cbe > _fcb ._abf {return _c .ErrSignNotEnoughSpace ;};if _cbe > 0{_fcb ._abf =_cbe +128;};sig .Contents =_bd .MakeHexString (string (_fbe .Content .FullBytes ));return nil ;};func (_afa *docTimeStamp )getCertificate (_geg *_c .PdfSignature )(*_ag .Certificate ,error ){var _eb []byte ;switch _bfd :=_geg .Cert .(type ){case *_bd .PdfObjectString :_eb =_bfd .Bytes ();case *_bd .PdfObjectArray :if _bfd .Len ()==0{return nil ,_gc .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 _ ,_cac :=range _bfd .Elements (){_fdb ,_dbc :=_bd .GetString (_cac );if !_dbc {return nil ,_db .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_cac );};_eb =append (_eb ,_fdb .Bytes ()...);};default:return nil ,_db .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bfd );};_cb ,_cd :=_ag .ParseCertificates (_eb );if _cd !=nil {return nil ,_cd ;};return _cb [0],nil ;};
func (_dba *adobeX509RSASHA1 )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_bfc ,_ebeg :=_dba .getCertificate (sig );if _ebeg !=nil {return _fb .SignatureValidationResult {},_ebeg ;};_cag :=sig .Contents .Bytes ();var _fcb []byte ;if _ ,_ffb :=_aa .Unmarshal (_cag ,&_fcb );_ffb !=nil {return _fb .SignatureValidationResult {},_ffb ;};_fdf ,_dae :=digest .(_g .Hash );if !_dae {return _fb .SignatureValidationResult {},_ff .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ea ,_ :=_ebe (_bfc .SignatureAlgorithm );if _ce :=_ec .VerifyPKCS1v15 (_bfc .PublicKey .(*_ec .PublicKey ),_ea ,_fdf .Sum (nil ),_fcb );_ce !=nil {return _fb .SignatureValidationResult {},_ce ;};return _fb .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};func (_cb *adobeX509RSASHA1 )getCertificate (_ed *_fb .PdfSignature )(*_gg .Certificate ,error ){if _cb ._bad !=nil {return _cb ._bad ,nil ;};var _bfe []byte ;switch _fbc :=_ed .Cert .(type ){case *_d .PdfObjectString :_bfe =_fbc .Bytes ();case *_d .PdfObjectArray :if _fbc .Len ()==0{return nil ,_ff .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 _ ,_gcd :=range _fbc .Elements (){_dbc ,_gf :=_d .GetString (_gcd );if !_gf {return nil ,_bg .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",_gcd );};_bfe =append (_bfe ,_dbc .Bytes ()...);};default:return nil ,_bg .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",_fbc );};_gfc ,_gbb :=_gg .ParseCertificates (_bfe );if _gbb !=nil {return nil ,_gbb ;};return _gfc [0],nil ;};func _afd (_aef _aa .ObjectIdentifier )(_eg .Hash ,error ){switch {case _aef .Equal (_ggf .OIDDigestAlgorithmSHA1 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA1 ),_aef .Equal (_ggf .OIDDigestAlgorithmDSA ),_aef .Equal (_ggf .OIDDigestAlgorithmDSASHA1 ),_aef .Equal (_ggf .OIDEncryptionAlgorithmRSA ):return _eg .SHA1 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA256 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA256 ):return _eg .SHA256 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA384 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA384 ):return _eg .SHA384 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA512 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA512 ):return _eg .SHA512 ,nil ;};return _eg .Hash (0),_ggf .ErrUnsupportedAlgorithm ;};
// 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 *_ab .PrivateKey ,certificate *_ag .Certificate )(_c .SignatureHandler ,error ){return &adobeX509RSASHA1 {_dea :certificate ,_gd :privateKey },nil ;};
func NewAdobeX509RSASHA1 (privateKey *_ec .PrivateKey ,certificate *_gg .Certificate )(_fb .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bad :certificate ,_fa :privateKey },nil ;};type timestampInfo struct{Version int ;Policy _aa .RawValue ;MessageImprint struct{HashAlgorithm _fc .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _aa .RawValue ;GeneralizedTime _a .Time ;};func _ebe (_age _gg .SignatureAlgorithm )(_eg .Hash ,bool ){var _fef _eg .Hash ;switch _age {case _gg .SHA1WithRSA :_fef =_eg .SHA1 ;case _gg .SHA256WithRSA :_fef =_eg .SHA256 ;case _gg .SHA384WithRSA :_fef =_eg .SHA384 ;case _gg .SHA512WithRSA :_fef =_eg .SHA512 ;default:return _eg .SHA1 ,false ;};return _fef ,true ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_cf *adobePKCS7Detached )IsApplicable (sig *_c .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};type timestampInfo struct{Version int ;Policy _ad .RawValue ;MessageImprint struct{HashAlgorithm _fcd .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _ad .RawValue ;GeneralizedTime _f .Time ;};
// Sign sets the Contents fields for the PdfSignature.
func (_agc *docTimeStamp )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {_bbe :=digest .(*_eb .Buffer );_aca :=_agc ._ceb .New ();if _ ,_bgd :=_f .Copy (_aca ,_bbe );_bgd !=nil {return _bgd ;};_egag :=_bgb .Request {HashAlgorithm :_agc ._ceb ,HashedMessage :_aca .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_gbe ,_eff :=_egag .Marshal ();if _eff !=nil {return _eff ;};_ffba ,_eff :=_b .Post (_agc ._fbgb ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_eb .NewBuffer (_gbe ));if _eff !=nil {return _eff ;};defer _ffba .Body .Close ();_cbf ,_eff :=_bb .ReadAll (_ffba .Body );if _eff !=nil {return _eff ;};if _ffba .StatusCode !=_b .StatusOK {return _bg .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",_ffba .StatusCode );};var _acg struct{Version _aa .RawValue ;Content _aa .RawValue ;};if _ ,_eff =_aa .Unmarshal (_cbf ,&_acg );_eff !=nil {return _eff ;};_bgcg :=len (_acg .Content .FullBytes );if _agc ._bab > 0&&_bgcg > _agc ._bab {return _fb .ErrSignNotEnoughSpace ;};if _bgcg > 0{_agc ._bab =_bgcg +128;};sig .Contents =_d .MakeHexString (string (_acg .Content .FullBytes ));return nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_cfb *adobeX509RSASHA1 )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {var _bbd []byte ;var _dgd error ;if _cfb ._df !=nil {_bbd ,_dgd =_cfb ._df (sig ,digest );if _dgd !=nil {return _dgd ;};}else {_ede ,_fdg :=digest .(_g .Hash );if !_fdg {return _ff .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_fbd ,_ :=_ebe (_cfb ._bad .SignatureAlgorithm );_bbd ,_dgd =_ec .SignPKCS1v15 (_af .Reader ,_cfb ._fa ,_fbd ,_ede .Sum (nil ));if _dgd !=nil {return _dgd ;};};_bbd ,_dgd =_aa .Marshal (_bbd );if _dgd !=nil {return _dgd ;};sig .Contents =_d .MakeHexString (string (_bbd ));return nil ;};
// InitSignature initialises the PdfSignature.
func (_fae *docTimeStamp )InitSignature (sig *_c .PdfSignature )error {_gge :=*_fae ;sig .Handler =&_gge ;sig .Filter =_bd .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_bd .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _fae ._abf > 0{sig .Contents =_bd .MakeHexString (string (make ([]byte ,_fae ._abf )));}else {_fb ,_gcd :=_fae .NewDigest (sig );if _gcd !=nil {return _gcd ;};_fb .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 _gcd =_gge .Sign (sig ,_fb );_gcd !=nil {return _gcd ;};_fae ._abf =_gge ._abf ;};return nil ;};
func (_ef *docTimeStamp )InitSignature (sig *_fb .PdfSignature )error {_edg :=*_ef ;sig .Handler =&_edg ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _ef ._bab > 0{sig .Contents =_d .MakeHexString (string (make ([]byte ,_ef ._bab )));}else {_bdf ,_bgf :=_ef .NewDigest (sig );if _bgf !=nil {return _bgf ;};_bdf .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 _bgf =_edg .Sign (sig ,_bdf );_bgf !=nil {return _bgf ;};_ef ._bab =_edg ._bab ;};return nil ;};func (_bc *adobePKCS7Detached )getCertificate (_egb *_fb .PdfSignature )(*_gg .Certificate ,error ){if _bc ._da !=nil {return _bc ._da ,nil ;};var _fg []byte ;switch _gb :=_egb .Cert .(type ){case *_d .PdfObjectString :_fg =_gb .Bytes ();case *_d .PdfObjectArray :if _gb .Len ()==0{return nil ,_ff .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 _ ,_ad :=range _gb .Elements (){_dc ,_gd :=_d .GetString (_ad );if !_gd {return nil ,_bg .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",_ad );};_fg =append (_fg ,_dc .Bytes ()...);};default:return nil ,_bg .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",_gb );};_dcd ,_dcdb :=_gg .ParseCertificates (_fg );if _dcdb !=nil {return nil ,_dcdb ;};return _dcd [0],nil ;};
// NewDigest creates a new digest.
func (_gbb *adobePKCS7Detached )NewDigest (sig *_c .PdfSignature )(_c .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// 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.
// 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 _dd .Hash )(_c .SignatureHandler ,error ){return &docTimeStamp {_ed :timestampServerURL ,_ede :hashAlgorithm },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_gfa *docTimeStamp )IsApplicable (sig *_c .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";};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_dbg *adobeX509RSASHA1 )IsApplicable (sig *_c .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 docTimeStamp struct{_ed string ;_ede _dd .Hash ;_abf int ;};
// 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 )(_c .SignatureHandler ,error ){return &adobePKCS7Detached {_ga :true ,_cg :signatureLen },nil ;};func _gfd (_be _ad .ObjectIdentifier )(_dd .Hash ,error ){switch {case _be .Equal (_ge .OIDDigestAlgorithmSHA1 ),_be .Equal (_ge .OIDDigestAlgorithmECDSASHA1 ),_be .Equal (_ge .OIDDigestAlgorithmDSA ),_be .Equal (_ge .OIDDigestAlgorithmDSASHA1 ),_be .Equal (_ge .OIDEncryptionAlgorithmRSA ):return _dd .SHA1 ,nil ;case _be .Equal (_ge .OIDDigestAlgorithmSHA256 ),_be .Equal (_ge .OIDDigestAlgorithmECDSASHA256 ):return _dd .SHA256 ,nil ;case _be .Equal (_ge .OIDDigestAlgorithmSHA384 ),_be .Equal (_ge .OIDDigestAlgorithmECDSASHA384 ):return _dd .SHA384 ,nil ;case _be .Equal (_ge .OIDDigestAlgorithmSHA512 ),_be .Equal (_ge .OIDDigestAlgorithmECDSASHA512 ):return _dd .SHA512 ,nil ;};return _dd .Hash (0),_ge .ErrUnsupportedAlgorithm ;};
func (_ge *adobePKCS7Detached )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){return _eb .NewBuffer (nil ),nil ;};

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 (_a "github.com/unidoc/unipdf/v3/common";_cd "github.com/unidoc/unipdf/v3/contentstream";_c "github.com/unidoc/unipdf/v3/contentstream/draw";_b "github.com/unidoc/unipdf/v3/model";);
package pdfutil ;import (_d "github.com/unidoc/unipdf/v3/common";_gg "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/contentstream/draw";_g "github.com/unidoc/unipdf/v3/model";);
// NormalizePage performs the following operations on the passed in page:
// - Normalize the page rotation.
@ -24,4 +24,4 @@ package pdfutil ;import (_a "github.com/unidoc/unipdf/v3/common";_cd "github.com
// The crop box of the page is updated based on the previous operations.
// After normalization, the page should look the same if openend using a
// PDF viewer.
func NormalizePage (page *_b .PdfPage )error {_cc ,_fd :=page .GetMediaBox ();if _fd !=nil {return _fd ;};_e ,_fd :=page .GetContentStreams ();if _fd !=nil {return _fd ;};_fdb :=page .Rotate ;_d :=_fdb !=nil &&*_fdb !=0&&*_fdb %90==0;_cc .Normalize ();_df ,_cdf ,_cg ,_be :=_cc .Llx ,_cc .Lly ,_cc .Width (),_cc .Height ();_g :=_df !=0||_cdf !=0;if !_d &&!_g {return nil ;};_fb :=func (_fbe ,_ab ,_cga float64 )_c .BoundingBox {return _c .Path {Points :[]_c .Point {_c .NewPoint (0,0).Rotate (_cga ),_c .NewPoint (_fbe ,0).Rotate (_cga ),_c .NewPoint (0,_ab ).Rotate (_cga ),_c .NewPoint (_fbe ,_ab ).Rotate (_cga )}}.GetBoundingBox ();};_db :=_cd .NewContentCreator ();var _bg float64 ;if _d {_bg =-float64 (*page .Rotate );_gg :=_fb (_cg ,_be ,_bg );_db .Translate ((_gg .Width -_cg )/2+_cg /2,(_gg .Height -_be )/2+_be /2);_db .RotateDeg (_bg );_db .Translate (-_cg /2,-_be /2);_cg ,_be =_gg .Width ,_gg .Height ;};if _g {_db .Translate (-_df ,-_cdf );};_bed :=_db .Operations ().String ();_e =append ([]string {_bed },_e ...);if _fd =page .SetContentStreams (_e ,nil );_fd !=nil {return _fd ;};*_cc =_b .PdfRectangle {Urx :_cg ,Ury :_be };if _ac :=page .CropBox ;_ac !=nil {_ac .Normalize ();_ga ,_fdbd ,_dfa ,_fg :=_ac .Llx -_df ,_ac .Lly -_cdf ,_ac .Width (),_ac .Height ();if _d {_gc :=_fb (_dfa ,_fg ,_bg );_dfa ,_fg =_gc .Width ,_gc .Height ;};*_ac =_b .PdfRectangle {Llx :_ga ,Lly :_fdbd ,Urx :_ga +_dfa ,Ury :_fdbd +_fg };};_a .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",_bg ,_bed ,_cc );page .Rotate =nil ;return nil ;};
func NormalizePage (page *_g .PdfPage )error {_f ,_fb :=page .GetMediaBox ();if _fb !=nil {return _fb ;};_be ,_fb :=page .GetContentStreams ();if _fb !=nil {return _fb ;};_gf :=page .Rotate ;_bg :=_gf !=nil &&*_gf %360!=0&&*_gf %90==0;_f .Normalize ();_ee ,_gge ,_bc ,_dc :=_f .Llx ,_f .Lly ,_f .Width (),_f .Height ();_a :=_ee !=0||_gge !=0;if !_bg &&!_a {return nil ;};_gd :=func (_fc ,_gdd ,_gfd float64 )_b .BoundingBox {return _b .Path {Points :[]_b .Point {_b .NewPoint (0,0).Rotate (_gfd ),_b .NewPoint (_fc ,0).Rotate (_gfd ),_b .NewPoint (0,_gdd ).Rotate (_gfd ),_b .NewPoint (_fc ,_gdd ).Rotate (_gfd )}}.GetBoundingBox ();};_c :=_gg .NewContentCreator ();var _ag float64 ;if _bg {_ag =-float64 (*page .Rotate );_eb :=_gd (_bc ,_dc ,_ag );_c .Translate ((_eb .Width -_bc )/2+_bc /2,(_eb .Height -_dc )/2+_dc /2);_c .RotateDeg (_ag );_c .Translate (-_bc /2,-_dc /2);_bc ,_dc =_eb .Width ,_eb .Height ;};if _a {_c .Translate (-_ee ,-_gge );};_ad :=_c .Operations ().String ();_be =append ([]string {_ad },_be ...);if _fb =page .SetContentStreams (_be ,nil );_fb !=nil {return _fb ;};*_f =_g .PdfRectangle {Urx :_bc ,Ury :_dc };if _dcc :=page .CropBox ;_dcc !=nil {_dcc .Normalize ();_gddg ,_ca ,_cd ,_dd :=_dcc .Llx -_ee ,_dcc .Lly -_gge ,_dcc .Width (),_dcc .Height ();if _bg {_eec :=_gd (_cd ,_dd ,_ag );_cd ,_dd =_eec .Width ,_eec .Height ;};*_dcc =_g .PdfRectangle {Llx :_gddg ,Lly :_ca ,Urx :_gddg +_cd ,Ury :_ca +_dd };};_d .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",_ag ,_ad ,_f );page .Rotate =nil ;return nil ;};

150
ps/ps.go
View File

@ -14,84 +14,46 @@
//
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
// for PDF function type 4.
package ps ;import (_c "bufio";_f "bytes";_e "errors";_dc "fmt";_cd "github.com/unidoc/unipdf/v3/common";_dce "github.com/unidoc/unipdf/v3/core";_d "io";_a "math";);
// 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 _fe []float64 ;for _ ,_ae :=range objects {if _ee ,_db :=_ae .(*PSInteger );_db {_fe =append (_fe ,float64 (_ee .Val ));}else if _eeb ,_af :=_ae .(*PSReal );_af {_fe =append (_fe ,_eeb .Val );}else {return nil ,ErrTypeCheck ;};};return _fe ,nil ;};
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_cbaa :=PSParser {};_fbg :=_f .NewBuffer (content );_cbaa ._dadg =_c .NewReader (_fbg );return &_cbaa ;};func (_fff *PSOperand )exp (_dbgf *PSStack )error {_ecg ,_aeg :=_dbgf .PopNumberAsFloat64 ();if _aeg !=nil {return _aeg ;};_ebd ,_aeg :=_dbgf .PopNumberAsFloat64 ();if _aeg !=nil {return _aeg ;};if _a .Abs (_ecg )< 1&&_ebd < 0{return ErrUndefinedResult ;};_ggd :=_a .Pow (_ebd ,_ecg );_aeg =_dbgf .Push (MakeReal (_ggd ));return _aeg ;};
// Exec executes the operand `op` in the state specified by `stack`.
func (_cga *PSOperand )Exec (stack *PSStack )error {_abf :=ErrUnsupportedOperand ;switch *_cga {case "\u0061\u0062\u0073":_abf =_cga .abs (stack );case "\u0061\u0064\u0064":_abf =_cga .add (stack );case "\u0061\u006e\u0064":_abf =_cga .and (stack );case "\u0061\u0074\u0061\u006e":_abf =_cga .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_abf =_cga .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_abf =_cga .ceiling (stack );case "\u0063\u006f\u0070\u0079":_abf =_cga .copy (stack );case "\u0063\u006f\u0073":_abf =_cga .cos (stack );case "\u0063\u0076\u0069":_abf =_cga .cvi (stack );case "\u0063\u0076\u0072":_abf =_cga .cvr (stack );case "\u0064\u0069\u0076":_abf =_cga .div (stack );case "\u0064\u0075\u0070":_abf =_cga .dup (stack );case "\u0065\u0071":_abf =_cga .eq (stack );case "\u0065\u0078\u0063\u0068":_abf =_cga .exch (stack );case "\u0065\u0078\u0070":_abf =_cga .exp (stack );case "\u0066\u006c\u006fo\u0072":_abf =_cga .floor (stack );case "\u0067\u0065":_abf =_cga .ge (stack );case "\u0067\u0074":_abf =_cga .gt (stack );case "\u0069\u0064\u0069\u0076":_abf =_cga .idiv (stack );case "\u0069\u0066":_abf =_cga .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_abf =_cga .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_abf =_cga .index (stack );case "\u006c\u0065":_abf =_cga .le (stack );case "\u006c\u006f\u0067":_abf =_cga .log (stack );case "\u006c\u006e":_abf =_cga .ln (stack );case "\u006c\u0074":_abf =_cga .lt (stack );case "\u006d\u006f\u0064":_abf =_cga .mod (stack );case "\u006d\u0075\u006c":_abf =_cga .mul (stack );case "\u006e\u0065":_abf =_cga .ne (stack );case "\u006e\u0065\u0067":_abf =_cga .neg (stack );case "\u006e\u006f\u0074":_abf =_cga .not (stack );case "\u006f\u0072":_abf =_cga .or (stack );case "\u0070\u006f\u0070":_abf =_cga .pop (stack );case "\u0072\u006f\u0075n\u0064":_abf =_cga .round (stack );case "\u0072\u006f\u006c\u006c":_abf =_cga .roll (stack );case "\u0073\u0069\u006e":_abf =_cga .sin (stack );case "\u0073\u0071\u0072\u0074":_abf =_cga .sqrt (stack );case "\u0073\u0075\u0062":_abf =_cga .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_abf =_cga .truncate (stack );case "\u0078\u006f\u0072":_abf =_cga .xor (stack );};return _abf ;};func (_bce *PSOperand )dup (_dcf *PSStack )error {_agd ,_ebca :=_dcf .Pop ();if _ebca !=nil {return _ebca ;};_ebca =_dcf .Push (_agd );if _ebca !=nil {return _ebca ;};_ebca =_dcf .Push (_agd .Duplicate ());return _ebca ;};func (_eb *PSOperand )String ()string {return _dc .Sprintf ("\u0025\u0073",*_eb )};func (_ega *PSOperand )eq (_eeg *PSStack )error {_bgf ,_adee :=_eeg .Pop ();if _adee !=nil {return _adee ;};_fgge ,_adee :=_eeg .Pop ();if _adee !=nil {return _adee ;};_eea ,_da :=_bgf .(*PSBoolean );_fec ,_dad :=_fgge .(*PSBoolean );if _da ||_dad {var _fbe error ;if _da &&_dad {_fbe =_eeg .Push (MakeBool (_eea .Val ==_fec .Val ));}else {_fbe =_eeg .Push (MakeBool (false ));};return _fbe ;};var _bcb float64 ;var _gcd float64 ;if _bd ,_bcgc :=_bgf .(*PSInteger );_bcgc {_bcb =float64 (_bd .Val );}else if _gbd ,_gab :=_bgf .(*PSReal );_gab {_bcb =_gbd .Val ;}else {return ErrTypeCheck ;};if _egbg ,_fgf :=_fgge .(*PSInteger );_fgf {_gcd =float64 (_egbg .Val );}else if _ceg ,_gdb :=_fgge .(*PSReal );_gdb {_gcd =_ceg .Val ;}else {return ErrTypeCheck ;};if _a .Abs (_gcd -_bcb )< _g {_adee =_eeg .Push (MakeBool (true ));}else {_adee =_eeg .Push (MakeBool (false ));};return _adee ;};func (_edga *PSParser )parseNumber ()(PSObject ,error ){_ggbd ,_bdcc :=_dce .ParseNumber (_edga ._dadg );if _bdcc !=nil {return nil ,_bdcc ;};switch _bef :=_ggbd .(type ){case *_dce .PdfObjectFloat :return MakeReal (float64 (*_bef )),nil ;case *_dce .PdfObjectInteger :return MakeInteger (int (*_bef )),nil ;};return nil ,_dc .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_ggbd );};
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;func (_ff *PSReal )Duplicate ()PSObject {_fc :=PSReal {};_fc .Val =_ff .Val ;return &_fc };func (_cbd *PSProgram )String ()string {_cda :="\u007b\u0020";for _ ,_bb :=range *_cbd {_cda +=_bb .String ();_cda +="\u0020";};_cda +="\u007d";return _cda ;};func (_eed *PSOperand )floor (_cceb *PSStack )error {_bbd ,_gga :=_cceb .Pop ();if _gga !=nil {return _gga ;};if _ecdg ,_fcfgd :=_bbd .(*PSReal );_fcfgd {_gga =_cceb .Push (MakeReal (_a .Floor (_ecdg .Val )));}else if _caa ,_abg :=_bbd .(*PSInteger );_abg {_gga =_cceb .Push (MakeInteger (_caa .Val ));}else {return ErrTypeCheck ;};return _gga ;};func (_baae *PSOperand )le (_cgac *PSStack )error {_gae ,_abb :=_cgac .PopNumberAsFloat64 ();if _abb !=nil {return _abb ;};_bgc ,_abb :=_cgac .PopNumberAsFloat64 ();if _abb !=nil {return _abb ;};if _a .Abs (_bgc -_gae )< _g {_fgb :=_cgac .Push (MakeBool (true ));return _fgb ;}else if _bgc < _gae {_cfbe :=_cgac .Push (MakeBool (true ));return _cfbe ;}else {_bdd :=_cgac .Push (MakeBool (false ));return _bdd ;};};var ErrStackOverflow =_e .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");func (_efeg *PSOperand )or (_ddec *PSStack )error {_ffee ,_bdda :=_ddec .Pop ();if _bdda !=nil {return _bdda ;};_cdf ,_bdda :=_ddec .Pop ();if _bdda !=nil {return _bdda ;};if _abbf ,_faf :=_ffee .(*PSBoolean );_faf {_cfg ,_ecab :=_cdf .(*PSBoolean );if !_ecab {return ErrTypeCheck ;};_bdda =_ddec .Push (MakeBool (_abbf .Val ||_cfg .Val ));return _bdda ;};if _efa ,_gdcb :=_ffee .(*PSInteger );_gdcb {_cdfe ,_cegf :=_cdf .(*PSInteger );if !_cegf {return ErrTypeCheck ;};_bdda =_ddec .Push (MakeInteger (_efa .Val |_cdfe .Val ));return _bdda ;};return ErrTypeCheck ;};func (_gbf *PSOperand )not (_afd *PSStack )error {_bbeg ,_dde :=_afd .Pop ();if _dde !=nil {return _dde ;};if _efc ,_ffa :=_bbeg .(*PSBoolean );_ffa {_dde =_afd .Push (MakeBool (!_efc .Val ));return _dde ;}else if _ccfg ,_ceffd :=_bbeg .(*PSInteger );_ceffd {_dde =_afd .Push (MakeInteger (^_ccfg .Val ));return _dde ;}else {return ErrTypeCheck ;};};func (_cb *PSBoolean )String ()string {return _dc .Sprintf ("\u0025\u0076",_cb .Val )};func (_ccf *PSOperand )cvr (_fcfg *PSStack )error {_ecf ,_gbg :=_fcfg .Pop ();if _gbg !=nil {return _gbg ;};if _dfb ,_abfc :=_ecf .(*PSReal );_abfc {_gbg =_fcfg .Push (MakeReal (_dfb .Val ));}else if _cfae ,_aac :=_ecf .(*PSInteger );_aac {_gbg =_fcfg .Push (MakeReal (float64 (_cfae .Val )));}else {return ErrTypeCheck ;};return _gbg ;};var ErrTypeCheck =_e .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");func (_gcgb *PSParser )parseFunction ()(*PSProgram ,error ){_afa ,_ :=_gcgb ._dadg .ReadByte ();if _afa !='{'{return nil ,_e .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_eada :=NewPSProgram ();for {_gcgb .skipSpaces ();_gegd ,_bgfg :=_gcgb ._dadg .Peek (2);if _bgfg !=nil {if _bgfg ==_d .EOF {break ;};return nil ,_bgfg ;};_cd .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_gegd ));if _gegd [0]=='}'{_cd .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_gcgb ._dadg .ReadByte ();break ;}else if _gegd [0]=='{'{_cd .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_gdea ,_dcc :=_gcgb .parseFunction ();if _dcc !=nil {return nil ,_dcc ;};_eada .Append (_gdea );}else if _dce .IsDecimalDigit (_gegd [0])||(_gegd [0]=='-'&&_dce .IsDecimalDigit (_gegd [1])){_cd .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_ebag ,_deca :=_gcgb .parseNumber ();if _deca !=nil {return nil ,_deca ;};_eada .Append (_ebag );}else {_cd .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_gegd ,_ =_gcgb ._dadg .Peek (5);_fbaa :=string (_gegd );_cd .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_fbaa );if (len (_fbaa )> 4)&&(_fbaa [:5]=="\u0066\u0061\u006cs\u0065"){_gecc ,_acf :=_gcgb .parseBool ();if _acf !=nil {return nil ,_acf ;};_eada .Append (_gecc );}else if (len (_fbaa )> 3)&&(_fbaa [:4]=="\u0074\u0072\u0075\u0065"){_ece ,_dace :=_gcgb .parseBool ();if _dace !=nil {return nil ,_dace ;};_eada .Append (_ece );}else {_abbd ,_ceb :=_gcgb .parseOperand ();if _ceb !=nil {return nil ,_ceb ;};_eada .Append (_abbd );};};};return _eada ,nil ;};
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_aef *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_ba :=range objects {_gg :=_aef .Stack .Push (_ba );if _gg !=nil {return nil ,_gg ;};};_fee :=_aef ._gc .Exec (_aef .Stack );if _fee !=nil {_cd .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_fee );return nil ,_fee ;};_cea :=[]PSObject (*_aef .Stack );_aef .Stack .Empty ();return _cea ,nil ;};func (_bgff *PSOperand )idiv (_cac *PSStack )error {_afg ,_eab :=_cac .Pop ();if _eab !=nil {return _eab ;};_dcg ,_eab :=_cac .Pop ();if _eab !=nil {return _eab ;};_eegc ,_cgf :=_afg .(*PSInteger );if !_cgf {return ErrTypeCheck ;};if _eegc .Val ==0{return ErrUndefinedResult ;};_gdg ,_cgf :=_dcg .(*PSInteger );if !_cgf {return ErrTypeCheck ;};_gcge :=_gdg .Val /_eegc .Val ;_eab =_cac .Push (MakeInteger (_gcge ));return _eab ;};func (_dgf *PSOperand )abs (_dbg *PSStack )error {_fb ,_eg :=_dbg .Pop ();if _eg !=nil {return _eg ;};if _dgfc ,_bf :=_fb .(*PSReal );_bf {_ebc :=_dgfc .Val ;if _ebc < 0{_eg =_dbg .Push (MakeReal (-_ebc ));}else {_eg =_dbg .Push (MakeReal (_ebc ));};}else if _egf ,_bea :=_fb .(*PSInteger );_bea {_ceac :=_egf .Val ;if _ceac < 0{_eg =_dbg .Push (MakeInteger (-_ceac ));}else {_eg =_dbg .Push (MakeInteger (_ceac ));};}else {return ErrTypeCheck ;};return _eg ;};func (_cce *PSOperand )atan (_ede *PSStack )error {_fdcc ,_dbea :=_ede .PopNumberAsFloat64 ();if _dbea !=nil {return _dbea ;};_ea ,_dbea :=_ede .PopNumberAsFloat64 ();if _dbea !=nil {return _dbea ;};if _fdcc ==0{var _gca error ;if _ea < 0{_gca =_ede .Push (MakeReal (270));}else {_gca =_ede .Push (MakeReal (90));};return _gca ;};_egc :=_ea /_fdcc ;_feb :=_a .Atan (_egc )*180/_a .Pi ;_dbea =_ede .Push (MakeReal (_feb ));return _dbea ;};func (_cdce *PSOperand )cos (_ebf *PSStack )error {_ag ,_abd :=_ebf .PopNumberAsFloat64 ();if _abd !=nil {return _abd ;};_febg :=_a .Cos (_ag *_a .Pi /180.0);_abd =_ebf .Push (MakeReal (_febg ));return _abd ;};
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct{Stack *PSStack ;_gc *PSProgram ;};func (_gcb *PSReal )String ()string {return _dc .Sprintf ("\u0025\u002e\u0035\u0066",_gcb .Val )};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_babb :=PSInteger {};_babb .Val =val ;return &_babb };func (_dbf *PSParser )skipSpaces ()(int ,error ){_gcc :=0;for {_fggc ,_ceea :=_dbf ._dadg .Peek (1);if _ceea !=nil {return 0,_ceea ;};if _dce .IsWhiteSpace (_fggc [0]){_dbf ._dadg .ReadByte ();_gcc ++;}else {break ;};};return _gcc ,nil ;};func (_eff *PSParser )parseOperand ()(*PSOperand ,error ){var _acgg []byte ;for {_gbged ,_dga :=_eff ._dadg .Peek (1);if _dga !=nil {if _dga ==_d .EOF {break ;};return nil ,_dga ;};if _dce .IsDelimiter (_gbged [0]){break ;};if _dce .IsWhiteSpace (_gbged [0]){break ;};_dgbd ,_ :=_eff ._dadg .ReadByte ();_acgg =append (_acgg ,_dgbd );};if len (_acgg )==0{return nil ,_e .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064\u0020\u0028\u0065\u006d\u0070\u0074\u0079\u0029");};return MakeOperand (string (_acgg )),nil ;};func (_cca *PSOperand )truncate (_gcea *PSStack )error {_cfe ,_dcef :=_gcea .Pop ();if _dcef !=nil {return _dcef ;};if _cde ,_bbcf :=_cfe .(*PSReal );_bbcf {_eef :=int (_cde .Val );_dcef =_gcea .Push (MakeReal (float64 (_eef )));}else if _dafg ,_cfca :=_cfe .(*PSInteger );_cfca {_dcef =_gcea .Push (MakeInteger (_dafg .Val ));}else {return ErrTypeCheck ;};return _dcef ;};func (_feec *PSBoolean )DebugString ()string {return _dc .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_feec .Val );};func (_aa *PSOperand )Duplicate ()PSObject {_fgg :=*_aa ;return &_fgg };func (_cfa *PSOperand )ceiling (_dced *PSStack )error {_edf ,_cbde :=_dced .Pop ();if _cbde !=nil {return _cbde ;};if _cba ,_edec :=_edf .(*PSReal );_edec {_cbde =_dced .Push (MakeReal (_a .Ceil (_cba .Val )));}else if _dba ,_fgd :=_edf .(*PSInteger );_fgd {_cbde =_dced .Push (MakeInteger (_dba .Val ));}else {_cbde =ErrTypeCheck ;};return _cbde ;};var ErrUnsupportedOperand =_e .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");
// Parse parses the postscript and store as a program that can be executed.
func (_agbef *PSParser )Parse ()(*PSProgram ,error ){_agbef .skipSpaces ();_gbfg ,_ffb :=_agbef ._dadg .Peek (2);if _ffb !=nil {return nil ,_ffb ;};if _gbfg [0]!='{'{return nil ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0053\u0020\u0050\u0072\u006f\u0067\u0072\u0061\u006d\u0020\u006e\u006f\u0074\u0020\u0073t\u0061\u0072\u0074\u0069\u006eg\u0020\u0077i\u0074\u0068\u0020\u007b");};_cab ,_ffb :=_agbef .parseFunction ();if _ffb !=nil &&_ffb !=_d .EOF {return nil ,_ffb ;};return _cab ,_ffb ;};func (_bg *PSReal )DebugString ()string {return _dc .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_bg .Val );};const _g =0.000001;
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};func (_be *PSOperand )DebugString ()string {return _dc .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_be );};func (_fac *PSOperand )ln (_ecda *PSStack )error {_cgcf ,_cbag :=_ecda .PopNumberAsFloat64 ();if _cbag !=nil {return _cbag ;};_bdc :=_a .Log (_cgcf );_cbag =_ecda .Push (MakeReal (_bdc ));return _cbag ;};func (_eega *PSOperand )neg (_daed *PSStack )error {_ccdb ,_ead :=_daed .Pop ();if _ead !=nil {return _ead ;};if _bfba ,_fbb :=_ccdb .(*PSReal );_fbb {_ead =_daed .Push (MakeReal (-_bfba .Val ));return _ead ;}else if _dbd ,_ecgg :=_ccdb .(*PSInteger );_ecgg {_ead =_daed .Push (MakeInteger (-_dbd .Val ));return _ead ;}else {return ErrTypeCheck ;};};func (_fdba *PSOperand )ge (_dff *PSStack )error {_ded ,_fda :=_dff .PopNumberAsFloat64 ();if _fda !=nil {return _fda ;};_ddb ,_fda :=_dff .PopNumberAsFloat64 ();if _fda !=nil {return _fda ;};if _a .Abs (_ddb -_ded )< _g {_gbbd :=_dff .Push (MakeBool (true ));return _gbbd ;}else if _ddb > _ded {_dfe :=_dff .Push (MakeBool (true ));return _dfe ;}else {_egff :=_dff .Push (MakeBool (false ));return _egff ;};};func (_bab *PSOperand )exch (_adb *PSStack )error {_aec ,_cfb :=_adb .Pop ();if _cfb !=nil {return _cfb ;};_eba ,_cfb :=_adb .Pop ();if _cfb !=nil {return _cfb ;};_cfb =_adb .Push (_aec );if _cfb !=nil {return _cfb ;};_cfb =_adb .Push (_eba );return _cfb ;};func (_fefe *PSOperand )sqrt (_daca *PSStack )error {_edg ,_ebg :=_daca .PopNumberAsFloat64 ();if _ebg !=nil {return _ebg ;};if _edg < 0{return ErrRangeCheck ;};_edb :=_a .Sqrt (_edg );_ebg =_daca .Push (MakeReal (_edb ));return _ebg ;};func (_dbc *PSOperand )roll (_ebec *PSStack )error {_faaa ,_facg :=_ebec .Pop ();if _facg !=nil {return _facg ;};_beae ,_facg :=_ebec .Pop ();if _facg !=nil {return _facg ;};_gff ,_ffc :=_faaa .(*PSInteger );if !_ffc {return ErrTypeCheck ;};_dca ,_ffc :=_beae .(*PSInteger );if !_ffc {return ErrTypeCheck ;};if _dca .Val < 0{return ErrRangeCheck ;};if _dca .Val ==0||_dca .Val ==1{return nil ;};if _dca .Val > len (*_ebec ){return ErrStackUnderflow ;};for _bec :=0;_bec < _dgad (_gff .Val );_bec ++{var _ggb []PSObject ;_ggb =(*_ebec )[len (*_ebec )-(_dca .Val ):len (*_ebec )];if _gff .Val > 0{_gba :=_ggb [len (_ggb )-1];_ggb =append ([]PSObject {_gba },_ggb [0:len (_ggb )-1]...);}else {_cbab :=_ggb [len (_ggb )-_dca .Val ];_ggb =append (_ggb [1:],_cbab );};_bfaf :=append ((*_ebec )[0:len (*_ebec )-_dca .Val ],_ggb ...);_ebec =&_bfaf ;};return nil ;};func (_efegb *PSOperand )sin (_ffec *PSStack )error {_cdaa ,_adbf :=_ffec .PopNumberAsFloat64 ();if _adbf !=nil {return _adbf ;};_ffca :=_a .Sin (_cdaa *_a .Pi /180.0);_adbf =_ffec .Push (MakeReal (_ffca ));return _adbf ;};func (_aaa *PSOperand )ifCondition (_efg *PSStack )error {_add ,_ggec :=_efg .Pop ();if _ggec !=nil {return _ggec ;};_gee ,_ggec :=_efg .Pop ();if _ggec !=nil {return _ggec ;};_bgb ,_daf :=_add .(*PSProgram );if !_daf {return ErrTypeCheck ;};_gfb ,_daf :=_gee .(*PSBoolean );if !_daf {return ErrTypeCheck ;};if _gfb .Val {_fbdg :=_bgb .Exec (_efg );return _fbdg ;};return nil ;};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;
// PSBoolean represents a boolean value.
type PSBoolean struct{Val bool ;};func (_bebb *PSOperand )log (_bagd *PSStack )error {_gcbf ,_faec :=_bagd .PopNumberAsFloat64 ();if _faec !=nil {return _faec ;};_bbg :=_a .Log10 (_gcbf );_faec =_bagd .Push (MakeReal (_bbg ));return _faec ;};
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_ggbf :=PSOperand (val );return &_ggbf };var ErrUndefinedResult =_e .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_gdf *PSOperand )copy (_edd *PSStack )error {_baa ,_ebbd :=_edd .PopInteger ();if _ebbd !=nil {return _ebbd ;};if _baa < 0{return ErrRangeCheck ;};if _baa > len (*_edd ){return ErrRangeCheck ;};*_edd =append (*_edd ,(*_edd )[len (*_edd )-_baa :]...);return nil ;};func (_eee *PSInteger )Duplicate ()PSObject {_ga :=PSInteger {};_ga .Val =_eee .Val ;return &_ga };func (_fg *PSInteger )String ()string {return _dc .Sprintf ("\u0025\u0064",_fg .Val )};
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_egg :=PSBoolean {};_egg .Val =val ;return &_egg };func (_gfd *PSOperand )div (_agfd *PSStack )error {_ffe ,_cec :=_agfd .Pop ();if _cec !=nil {return _cec ;};_deee ,_cec :=_agfd .Pop ();if _cec !=nil {return _cec ;};_gbgb ,_baf :=_ffe .(*PSReal );_aeb ,_cefb :=_ffe .(*PSInteger );if !_baf &&!_cefb {return ErrTypeCheck ;};if _baf &&_gbgb .Val ==0{return ErrUndefinedResult ;};if _cefb &&_aeb .Val ==0{return ErrUndefinedResult ;};_fbda ,_cad :=_deee .(*PSReal );_ac ,_agb :=_deee .(*PSInteger );if !_cad &&!_agb {return ErrTypeCheck ;};var _fcaf float64 =0;if _cad {_fcaf =_fbda .Val ;}else {_fcaf =float64 (_ac .Val );};if _baf {_fcaf /=_gbgb .Val ;}else {_fcaf /=float64 (_aeb .Val );};_cec =_agfd .Push (MakeReal (_fcaf ));return _cec ;};func (_ed *PSOperand )and (_df *PSStack )error {_ecc ,_afc :=_df .Pop ();if _afc !=nil {return _afc ;};_dee ,_afc :=_df .Pop ();if _afc !=nil {return _afc ;};if _bc ,_ged :=_ecc .(*PSBoolean );_ged {_fdc ,_geg :=_dee .(*PSBoolean );if !_geg {return ErrTypeCheck ;};_afc =_df .Push (MakeBool (_bc .Val &&_fdc .Val ));return _afc ;};if _ebb ,_ca :=_ecc .(*PSInteger );_ca {_cc ,_fcf :=_dee .(*PSInteger );if !_fcf {return ErrTypeCheck ;};_afc =_df .Push (MakeInteger (_ebb .Val &_cc .Val ));return _afc ;};return ErrTypeCheck ;};func (_bgfd *PSOperand )mod (_dec *PSStack )error {_bfa ,_bdba :=_dec .Pop ();if _bdba !=nil {return _bdba ;};_gbe ,_bdba :=_dec .Pop ();if _bdba !=nil {return _bdba ;};_ecdb ,_gbc :=_bfa .(*PSInteger );if !_gbc {return ErrTypeCheck ;};if _ecdb .Val ==0{return ErrUndefinedResult ;};_bfag ,_gbc :=_gbe .(*PSInteger );if !_gbc {return ErrTypeCheck ;};_caad :=_bfag .Val %_ecdb .Val ;_bdba =_dec .Push (MakeInteger (_caad ));return _bdba ;};func (_bac *PSBoolean )Duplicate ()PSObject {_cg :=PSBoolean {};_cg .Val =_bac .Val ;return &_cg };
// Append appends an object to the PSProgram.
func (_fd *PSProgram )Append (obj PSObject ){*_fd =append (*_fd ,obj )};func (_gce *PSInteger )DebugString ()string {return _dc .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_gce .Val );};func (_ffad *PSOperand )round (_ecae *PSStack )error {_abe ,_fdccf :=_ecae .Pop ();if _fdccf !=nil {return _fdccf ;};if _fbdc ,_bed :=_abe .(*PSReal );_bed {_fdccf =_ecae .Push (MakeReal (_a .Floor (_fbdc .Val +0.5)));}else if _bdbf ,_cead :=_abe .(*PSInteger );_cead {_fdccf =_ecae .Push (MakeInteger (_bdbf .Val ));}else {return ErrTypeCheck ;};return _fdccf ;};func (_gbge *PSOperand )index (_fae *PSStack )error {_ace ,_cfc :=_fae .Pop ();if _cfc !=nil {return _cfc ;};_fcad ,_gag :=_ace .(*PSInteger );if !_gag {return ErrTypeCheck ;};if _fcad .Val < 0{return ErrRangeCheck ;};if _fcad .Val > len (*_fae )-1{return ErrStackUnderflow ;};_bag :=(*_fae )[len (*_fae )-1-_fcad .Val ];_cfc =_fae .Push (_bag .Duplicate ());return _cfc ;};func (_bae *PSOperand )pop (_bba *PSStack )error {_ ,_ggae :=_bba .Pop ();if _ggae !=nil {return _ggae ;};return nil ;};func _dgad (_acd int )int {if _acd < 0{return -_acd ;};return _acd ;};
// Push pushes an object on top of the stack.
func (_bfc *PSStack )Push (obj PSObject )error {if len (*_bfc )> 100{return ErrStackOverflow ;};*_bfc =append (*_bfc ,obj );return nil ;};
// PSReal represents a real number.
type PSReal struct{Val float64 ;};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};
package ps ;import (_ee "bufio";_e "bytes";_df "errors";_b "fmt";_dc "github.com/unidoc/unipdf/v3/common";_ba "github.com/unidoc/unipdf/v3/core";_c "io";_ca "math";);
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
func (_fecf *PSStack )PopInteger ()(int ,error ){_adda ,_ggeg :=_fecf .Pop ();if _ggeg !=nil {return 0,_ggeg ;};if _ddgc ,_eag :=_adda .(*PSInteger );_eag {return _ddgc .Val ,nil ;};return 0,ErrTypeCheck ;};
func (_bfdb *PSStack )PopInteger ()(int ,error ){_acb ,_gfea :=_bfdb .Pop ();if _gfea !=nil {return 0,_gfea ;};if _eeg ,_cdcd :=_acb .(*PSInteger );_cdcd {return _eeg .Val ,nil ;};return 0,ErrTypeCheck ;};func (_ge *PSReal )Duplicate ()PSObject {_egc :=PSReal {};_egc .Val =_ge .Val ;return &_egc };
// 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 (_baeb *PSOperand )xor (_afcb *PSStack )error {_cfgd ,_gbg :=_afcb .Pop ();if _gbg !=nil {return _gbg ;};_fead ,_gbg :=_afcb .Pop ();if _gbg !=nil {return _gbg ;};if _fefg ,_fee :=_cfgd .(*PSBoolean );_fee {_eeb ,_ffed :=_fead .(*PSBoolean );if !_ffed {return ErrTypeCheck ;};_gbg =_afcb .Push (MakeBool (_fefg .Val !=_eeb .Val ));return _gbg ;};if _fce ,_dfgd :=_cfgd .(*PSInteger );_dfgd {_dcdag ,_bbcf :=_fead .(*PSInteger );if !_bbcf {return ErrTypeCheck ;};_gbg =_afcb .Push (MakeInteger (_fce .Val ^_dcdag .Val ));return _gbg ;};return ErrTypeCheck ;};
// String returns a string representation of the stack.
func (_dgbcd *PSStack )String ()string {_dgfe :="\u005b\u0020";for _ ,_gac :=range *_dgbcd {_dgfe +=_gac .String ();_dgfe +="\u0020";};_dgfe +="\u005d";return _dgfe ;};func (_deb *PSOperand )xor (_cee *PSStack )error {_gbbb ,_bddc :=_cee .Pop ();if _bddc !=nil {return _bddc ;};_beg ,_bddc :=_cee .Pop ();if _bddc !=nil {return _bddc ;};if _fea ,_aae :=_gbbb .(*PSBoolean );_aae {_afcg ,_deg :=_beg .(*PSBoolean );if !_deg {return ErrTypeCheck ;};_bddc =_cee .Push (MakeBool (_fea .Val !=_afcg .Val ));return _bddc ;};if _fdbe ,_agbe :=_gbbb .(*PSInteger );_agbe {_edgc ,_ccg :=_beg .(*PSInteger );if !_ccg {return ErrTypeCheck ;};_bddc =_cee .Push (MakeInteger (_fdbe .Val ^_edgc .Val ));return _bddc ;};return ErrTypeCheck ;};func (_fa *PSProgram )DebugString ()string {_gf :="\u007b\u0020";for _ ,_fge :=range *_fa {_gf +=_fge .DebugString ();_gf +="\u0020";};_gf +="\u007d";return _gf ;};func (_gde *PSOperand )add (_gge *PSStack )error {_ad ,_dd :=_gge .Pop ();if _dd !=nil {return _dd ;};_gcg ,_dd :=_gge .Pop ();if _dd !=nil {return _dd ;};_gcef ,_gb :=_ad .(*PSReal );_cgdc ,_fca :=_ad .(*PSInteger );if !_gb &&!_fca {return ErrTypeCheck ;};_gea ,_aefa :=_gcg .(*PSReal );_bbb ,_dge :=_gcg .(*PSInteger );if !_aefa &&!_dge {return ErrTypeCheck ;};if _fca &&_dge {_bbc :=_cgdc .Val +_bbb .Val ;_de :=_gge .Push (MakeInteger (_bbc ));return _de ;};var _eebb float64 =0;if _gb {_eebb =_gcef .Val ;}else {_eebb =float64 (_cgdc .Val );};if _aefa {_eebb +=_gea .Val ;}else {_eebb +=float64 (_bbb .Val );};_dd =_gge .Push (MakeReal (_eebb ));return _dd ;};
// Empty empties the stack.
func (_ddg *PSStack )Empty (){*_ddg =[]PSObject {}};
// PSOperand represents a Postscript operand (text string).
type PSOperand string ;func (_bafg *PSOperand )neg (_bad *PSStack )error {_ffb ,_fbcf :=_bad .Pop ();if _fbcf !=nil {return _fbcf ;};if _bace ,_agaa :=_ffb .(*PSReal );_agaa {_fbcf =_bad .Push (MakeReal (-_bace .Val ));return _fbcf ;}else if _bcad ,_bcee :=_ffb .(*PSInteger );_bcee {_fbcf =_bad .Push (MakeInteger (-_bcad .Val ));return _fbcf ;}else {return ErrTypeCheck ;};};
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
func NewPSExecutor (program *PSProgram )*PSExecutor {_ge :=&PSExecutor {};_ge .Stack =NewPSStack ();_ge ._gc =program ;return _ge ;};
func NewPSExecutor (program *PSProgram )*PSExecutor {_a :=&PSExecutor {};_a .Stack =NewPSStack ();_a ._f =program ;return _a ;};func (_cac *PSInteger )String ()string {return _b .Sprintf ("\u0025\u0064",_cac .Val )};func (_ab *PSOperand )DebugString ()string {return _b .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_ab );};func (_bcgd *PSOperand )idiv (_gda *PSStack )error {_ada ,_affd :=_gda .Pop ();if _affd !=nil {return _affd ;};_ccc ,_affd :=_gda .Pop ();if _affd !=nil {return _affd ;};_febd ,_fdf :=_ada .(*PSInteger );if !_fdf {return ErrTypeCheck ;};if _febd .Val ==0{return ErrUndefinedResult ;};_ccged ,_fdf :=_ccc .(*PSInteger );if !_fdf {return ErrTypeCheck ;};_ceae :=_ccged .Val /_febd .Val ;_affd =_gda .Push (MakeInteger (_ceae ));return _affd ;};func (_gce *PSOperand )String ()string {return _b .Sprintf ("\u0025\u0073",*_gce )};func _ffd (_egeg int )int {if _egeg < 0{return -_egeg ;};return _egeg ;};
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_dcb *PSStack )DebugString ()string {_cgg :="\u005b\u0020";for _ ,_bfab :=range *_dcb {_cgg +=_bfab .DebugString ();_cgg +="\u0020";};_cgg +="\u005d";return _cgg ;};
// Pop pops an object from the top of the stack.
func (_gcdg *PSStack )Pop ()(PSObject ,error ){if len (*_gcdg )< 1{return nil ,ErrStackUnderflow ;};_gbda :=(*_gcdg )[len (*_gcdg )-1];*_gcdg =(*_gcdg )[0:len (*_gcdg )-1];return _gbda ,nil ;};var ErrStackUnderflow =_e .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
func NewPSParser (content []byte )*PSParser {_ebdd :=PSParser {};_gfcc :=_e .NewBuffer (content );_ebdd ._aab =_ee .NewReader (_gfcc );return &_ebdd ;};func (_bb *PSBoolean )Duplicate ()PSObject {_dcb :=PSBoolean {};_dcb .Val =_bb .Val ;return &_dcb };var ErrStackUnderflow =_df .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");func (_dad *PSOperand )log (_fcba *PSStack )error {_fgff ,_ggd :=_fcba .PopNumberAsFloat64 ();if _ggd !=nil {return _ggd ;};_bcfc :=_ca .Log10 (_fgff );_ggd =_fcba .Push (MakeReal (_bcfc ));return _ggd ;};
// NewPSStack returns an initialized PSStack.
func NewPSStack ()*PSStack {return &PSStack {}};
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
// Real or integer only.
func (_aacg *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_acbe ,_dfea :=_aacg .Pop ();if _dfea !=nil {return 0,_dfea ;};if _faa ,_ced :=_acbe .(*PSReal );_ced {return _faa .Val ,nil ;}else if _acde ,_bcbf :=_acbe .(*PSInteger );_bcbf {return float64 (_acde .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_bcd *PSBoolean )String ()string {return _b .Sprintf ("\u0025\u0076",_bcd .Val )};func (_cea *PSOperand )floor (_ccge *PSStack )error {_fbb ,_agef :=_ccge .Pop ();if _agef !=nil {return _agef ;};if _cgd ,_gbc :=_fbb .(*PSReal );_gbc {_agef =_ccge .Push (MakeReal (_ca .Floor (_cgd .Val )));}else if _dfg ,_bcc :=_fbb .(*PSInteger );_bcc {_agef =_ccge .Push (MakeInteger (_dfg .Val ));}else {return ErrTypeCheck ;};return _agef ;};func (_bc *PSBoolean )DebugString ()string {return _b .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_bc .Val );};
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
type PSStack []PSObject ;func (_gbee *PSOperand )sqrt (_dadg *PSStack )error {_becg ,_adfb :=_dadg .PopNumberAsFloat64 ();if _adfb !=nil {return _adfb ;};if _becg < 0{return ErrRangeCheck ;};_acf :=_ca .Sqrt (_becg );_adfb =_dadg .Push (MakeReal (_acf ));return _adfb ;};func (_dba *PSOperand )div (_cdef *PSStack )error {_fa ,_fbea :=_cdef .Pop ();if _fbea !=nil {return _fbea ;};_cbg ,_fbea :=_cdef .Pop ();if _fbea !=nil {return _fbea ;};_dceb ,_dcf :=_fa .(*PSReal );_bagf ,_bcfa :=_fa .(*PSInteger );if !_dcf &&!_bcfa {return ErrTypeCheck ;};if _dcf &&_dceb .Val ==0{return ErrUndefinedResult ;};if _bcfa &&_bagf .Val ==0{return ErrUndefinedResult ;};_ccgg ,_fd :=_cbg .(*PSReal );_aae ,_dbd :=_cbg .(*PSInteger );if !_fd &&!_dbd {return ErrTypeCheck ;};var _bbcd float64 =0;if _fd {_bbcd =_ccgg .Val ;}else {_bbcd =float64 (_aae .Val );};if _dcf {_bbcd /=_dceb .Val ;}else {_bbcd /=float64 (_bagf .Val );};_fbea =_cdef .Push (MakeReal (_bbcd ));return _fbea ;};func (_gef *PSOperand )mul (_adaa *PSStack )error {_dae ,_fgfe :=_adaa .Pop ();if _fgfe !=nil {return _fgfe ;};_edb ,_fgfe :=_adaa .Pop ();if _fgfe !=nil {return _fgfe ;};_agda ,_edbe :=_dae .(*PSReal );_gfde ,_ffef :=_dae .(*PSInteger );if !_edbe &&!_ffef {return ErrTypeCheck ;};_decac ,_dde :=_edb .(*PSReal );_adfd ,_ebf :=_edb .(*PSInteger );if !_dde &&!_ebf {return ErrTypeCheck ;};if _ffef &&_ebf {_ebd :=_gfde .Val *_adfd .Val ;_daa :=_adaa .Push (MakeInteger (_ebd ));return _daa ;};var _adgad float64 =0;if _edbe {_adgad =_agda .Val ;}else {_adgad =float64 (_gfde .Val );};if _dde {_adgad *=_decac .Val ;}else {_adgad *=float64 (_adfd .Val );};_fgfe =_adaa .Push (MakeReal (_adgad ));return _fgfe ;};func (_dge *PSOperand )atan (_abe *PSStack )error {_cfb ,_eed :=_abe .PopNumberAsFloat64 ();if _eed !=nil {return _eed ;};_deg ,_eed :=_abe .PopNumberAsFloat64 ();if _eed !=nil {return _eed ;};if _cfb ==0{var _aga error ;if _deg < 0{_aga =_abe .Push (MakeReal (270));}else {_aga =_abe .Push (MakeReal (90));};return _aga ;};_cga :=_deg /_cfb ;_baa :=_ca .Atan (_cga )*180/_ca .Pi ;_eed =_abe .Push (MakeReal (_baa ));return _eed ;};func (_cfa *PSInteger )Duplicate ()PSObject {_dce :=PSInteger {};_dce .Val =_cfa .Val ;return &_dce };func (_aeff *PSParser )parseOperand ()(*PSOperand ,error ){var _gcge []byte ;for {_bbfd ,_ccac :=_aeff ._aab .Peek (1);if _ccac !=nil {if _ccac ==_c .EOF {break ;};return nil ,_ccac ;};if _ba .IsDelimiter (_bbfd [0]){break ;};if _ba .IsWhiteSpace (_bbfd [0]){break ;};_aebb ,_ :=_aeff ._aab .ReadByte ();_gcge =append (_gcge ,_aebb );};if len (_gcge )==0{return nil ,_df .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 (_gcge )),nil ;};
// Exec executes the operand `op` in the state specified by `stack`.
func (_cag *PSOperand )Exec (stack *PSStack )error {_agg :=ErrUnsupportedOperand ;switch *_cag {case "\u0061\u0062\u0073":_agg =_cag .abs (stack );case "\u0061\u0064\u0064":_agg =_cag .add (stack );case "\u0061\u006e\u0064":_agg =_cag .and (stack );case "\u0061\u0074\u0061\u006e":_agg =_cag .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_agg =_cag .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_agg =_cag .ceiling (stack );case "\u0063\u006f\u0070\u0079":_agg =_cag .copy (stack );case "\u0063\u006f\u0073":_agg =_cag .cos (stack );case "\u0063\u0076\u0069":_agg =_cag .cvi (stack );case "\u0063\u0076\u0072":_agg =_cag .cvr (stack );case "\u0064\u0069\u0076":_agg =_cag .div (stack );case "\u0064\u0075\u0070":_agg =_cag .dup (stack );case "\u0065\u0071":_agg =_cag .eq (stack );case "\u0065\u0078\u0063\u0068":_agg =_cag .exch (stack );case "\u0065\u0078\u0070":_agg =_cag .exp (stack );case "\u0066\u006c\u006fo\u0072":_agg =_cag .floor (stack );case "\u0067\u0065":_agg =_cag .ge (stack );case "\u0067\u0074":_agg =_cag .gt (stack );case "\u0069\u0064\u0069\u0076":_agg =_cag .idiv (stack );case "\u0069\u0066":_agg =_cag .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_agg =_cag .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_agg =_cag .index (stack );case "\u006c\u0065":_agg =_cag .le (stack );case "\u006c\u006f\u0067":_agg =_cag .log (stack );case "\u006c\u006e":_agg =_cag .ln (stack );case "\u006c\u0074":_agg =_cag .lt (stack );case "\u006d\u006f\u0064":_agg =_cag .mod (stack );case "\u006d\u0075\u006c":_agg =_cag .mul (stack );case "\u006e\u0065":_agg =_cag .ne (stack );case "\u006e\u0065\u0067":_agg =_cag .neg (stack );case "\u006e\u006f\u0074":_agg =_cag .not (stack );case "\u006f\u0072":_agg =_cag .or (stack );case "\u0070\u006f\u0070":_agg =_cag .pop (stack );case "\u0072\u006f\u0075n\u0064":_agg =_cag .round (stack );case "\u0072\u006f\u006c\u006c":_agg =_cag .roll (stack );case "\u0073\u0069\u006e":_agg =_cag .sin (stack );case "\u0073\u0071\u0072\u0074":_agg =_cag .sqrt (stack );case "\u0073\u0075\u0062":_agg =_cag .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_agg =_cag .truncate (stack );case "\u0078\u006f\u0072":_agg =_cag .xor (stack );};return _agg ;};
// PSObjectArrayToFloat64Array converts []PSObject into a []float64 array. Each PSObject must represent a number,
// otherwise a ErrTypeCheck error occurs.
func PSObjectArrayToFloat64Array (objects []PSObject )([]float64 ,error ){var _aa []float64 ;for _ ,_g :=range objects {if _fe ,_eb :=_g .(*PSInteger );_eb {_aa =append (_aa ,float64 (_fe .Val ));}else if _cf ,_bg :=_g .(*PSReal );_bg {_aa =append (_aa ,_cf .Val );}else {return nil ,ErrTypeCheck ;};};return _aa ,nil ;};func (_fga *PSOperand )pop (_aecg *PSStack )error {_ ,_gac :=_aecg .Pop ();if _gac !=nil {return _gac ;};return nil ;};func (_edf *PSOperand )index (_edfg *PSStack )error {_aef ,_adb :=_edfg .Pop ();if _adb !=nil {return _adb ;};_bec ,_babg :=_aef .(*PSInteger );if !_babg {return ErrTypeCheck ;};if _bec .Val < 0{return ErrRangeCheck ;};if _bec .Val > len (*_edfg )-1{return ErrStackUnderflow ;};_gffe :=(*_edfg )[len (*_edfg )-1-_bec .Val ];_adb =_edfg .Push (_gffe .Duplicate ());return _adb ;};func (_abd *PSOperand )gt (_bbce *PSStack )error {_ffec ,_cebb :=_bbce .PopNumberAsFloat64 ();if _cebb !=nil {return _cebb ;};_dfe ,_cebb :=_bbce .PopNumberAsFloat64 ();if _cebb !=nil {return _cebb ;};if _ca .Abs (_dfe -_ffec )< _cd {_feg :=_bbce .Push (MakeBool (false ));return _feg ;}else if _dfe > _ffec {_eef :=_bbce .Push (MakeBool (true ));return _eef ;}else {_geac :=_bbce .Push (MakeBool (false ));return _geac ;};};
// String returns a string representation of the stack.
func (_gcc *PSStack )String ()string {_dcbd :="\u005b\u0020";for _ ,_beef :=range *_gcc {_dcbd +=_beef .String ();_dcbd +="\u0020";};_dcbd +="\u005d";return _dcbd ;};func (_cdcc *PSOperand )round (_decf *PSStack )error {_bgb ,_gace :=_decf .Pop ();if _gace !=nil {return _gace ;};if _ggad ,_cad :=_bgb .(*PSReal );_cad {_gace =_decf .Push (MakeReal (_ca .Floor (_ggad .Val +0.5)));}else if _ceff ,_daf :=_bgb .(*PSInteger );_daf {_gace =_decf .Push (MakeInteger (_ceff .Val ));}else {return ErrTypeCheck ;};return _gace ;};
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
type PSExecutor struct{Stack *PSStack ;_f *PSProgram ;};func (_bfg *PSOperand )add (_bbe *PSStack )error {_ceee ,_cfd :=_bbe .Pop ();if _cfd !=nil {return _cfd ;};_baga ,_cfd :=_bbe .Pop ();if _cfd !=nil {return _cfd ;};_fff ,_gcg :=_ceee .(*PSReal );_ebaa ,_fbf :=_ceee .(*PSInteger );if !_gcg &&!_fbf {return ErrTypeCheck ;};_gg ,_cdd :=_baga .(*PSReal );_bga ,_ggf :=_baga .(*PSInteger );if !_cdd &&!_ggf {return ErrTypeCheck ;};if _fbf &&_ggf {_fg :=_ebaa .Val +_bga .Val ;_efd :=_bbe .Push (MakeInteger (_fg ));return _efd ;};var _fbg float64 =0;if _gcg {_fbg =_fff .Val ;}else {_fbg =float64 (_ebaa .Val );};if _cdd {_fbg +=_gg .Val ;}else {_fbg +=float64 (_bga .Val );};_cfd =_bbe .Push (MakeReal (_fbg ));return _cfd ;};var ErrRangeCheck =_df .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");
// PSObject represents a postscript object.
type PSObject interface{
@ -103,17 +65,55 @@ Duplicate ()PSObject ;
DebugString ()string ;
// String returns a string representation of the PSObject.
String ()string ;};func (_fef *PSOperand )lt (_bbbf *PSStack )error {_dae ,_aegb :=_bbbf .PopNumberAsFloat64 ();if _aegb !=nil {return _aegb ;};_gfg ,_aegb :=_bbbf .PopNumberAsFloat64 ();if _aegb !=nil {return _aegb ;};if _a .Abs (_gfg -_dae )< _g {_aab :=_bbbf .Push (MakeBool (false ));return _aab ;}else if _gfg < _dae {_ceff :=_bbbf .Push (MakeBool (true ));return _ceff ;}else {_faa :=_bbbf .Push (MakeBool (false ));return _faa ;};};func (_dfg *PSOperand )sub (_cadc *PSStack )error {_fba ,_gcgeg :=_cadc .Pop ();if _gcgeg !=nil {return _gcgeg ;};_fffa ,_gcgeg :=_cadc .Pop ();if _gcgeg !=nil {return _gcgeg ;};_eebf ,_efga :=_fba .(*PSReal );_egbe ,_gdag :=_fba .(*PSInteger );if !_efga &&!_gdag {return ErrTypeCheck ;};_aceg ,_dada :=_fffa .(*PSReal );_dcgc ,_ccfa :=_fffa .(*PSInteger );if !_dada &&!_ccfa {return ErrTypeCheck ;};if _gdag &&_ccfa {_ffff :=_dcgc .Val -_egbe .Val ;_bde :=_cadc .Push (MakeInteger (_ffff ));return _bde ;};var _edee float64 =0;if _dada {_edee =_aceg .Val ;}else {_edee =float64 (_dcgc .Val );};if _efga {_edee -=_eebf .Val ;}else {_edee -=float64 (_egbe .Val );};_gcgeg =_cadc .Push (MakeReal (_edee ));return _gcgeg ;};func (_fgde *PSParser )parseBool ()(*PSBoolean ,error ){_aaec ,_acg :=_fgde ._dadg .Peek (4);if _acg !=nil {return MakeBool (false ),_acg ;};if (len (_aaec )>=4)&&(string (_aaec [:4])=="\u0074\u0072\u0075\u0065"){_fgde ._dadg .Discard (4);return MakeBool (true ),nil ;};_aaec ,_acg =_fgde ._dadg .Peek (5);if _acg !=nil {return MakeBool (false ),_acg ;};if (len (_aaec )>=5)&&(string (_aaec [:5])=="\u0066\u0061\u006cs\u0065"){_fgde ._dadg .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_e .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};func (_cef *PSOperand )bitshift (_egb *PSStack )error {_efe ,_fbd :=_egb .PopInteger ();if _fbd !=nil {return _fbd ;};_fdb ,_fbd :=_egb .PopInteger ();if _fbd !=nil {return _fbd ;};var _gdcf int ;if _efe >=0{_gdcf =_fdb <<uint (_efe );}else {_gdcf =_fdb >>uint (-_efe );};_fbd =_egb .Push (MakeInteger (_gdcf ));return _fbd ;};func (_bdb *PSOperand )gt (_aca *PSStack )error {_cfbd ,_dfa :=_aca .PopNumberAsFloat64 ();if _dfa !=nil {return _dfa ;};_cgc ,_dfa :=_aca .PopNumberAsFloat64 ();if _dfa !=nil {return _dfa ;};if _a .Abs (_cgc -_cfbd )< _g {_ebff :=_aca .Push (MakeBool (false ));return _ebff ;}else if _cgc > _cfbd {_eac :=_aca .Push (MakeBool (true ));return _eac ;}else {_fgdc :=_aca .Push (MakeBool (false ));return _fgdc ;};};func (_eeea *PSProgram )Duplicate ()PSObject {_gec :=&PSProgram {};for _ ,_cdc :=range *_eeea {_gec .Append (_cdc .Duplicate ());};return _gec ;};
String ()string ;};func (_dgd *PSOperand )dup (_fgd *PSStack )error {_efdc ,_cce :=_fgd .Pop ();if _cce !=nil {return _cce ;};_cce =_fgd .Push (_efdc );if _cce !=nil {return _cce ;};_cce =_fgd .Push (_efdc .Duplicate ());return _cce ;};var ErrUndefinedResult =_df .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
// Real or integer only.
func (_bcf *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_abed ,_ggaa :=_bcf .Pop ();if _ggaa !=nil {return 0,_ggaa ;};if _age ,_cacf :=_abed .(*PSReal );_cacf {return _age .Val ,nil ;}else if _baba ,_gegb :=_abed .(*PSInteger );_gegb {return float64 (_baba .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_cdae *PSOperand )mul (_bfb *PSStack )error {_bcee ,_ebe :=_bfb .Pop ();if _ebe !=nil {return _ebe ;};_gdfb ,_ebe :=_bfb .Pop ();if _ebe !=nil {return _ebe ;};_gfe ,_aga :=_bcee .(*PSReal );_dffg ,_fgeb :=_bcee .(*PSInteger );if !_aga &&!_fgeb {return ErrTypeCheck ;};_aed ,_gcbfc :=_gdfb .(*PSReal );_addg ,_eaf :=_gdfb .(*PSInteger );if !_gcbfc &&!_eaf {return ErrTypeCheck ;};if _fgeb &&_eaf {_babe :=_dffg .Val *_addg .Val ;_agag :=_bfb .Push (MakeInteger (_babe ));return _agag ;};var _cfag float64 =0;if _aga {_cfag =_gfe .Val ;}else {_cfag =float64 (_dffg .Val );};if _gcbfc {_cfag *=_aed .Val ;}else {_cfag *=float64 (_addg .Val );};_ebe =_bfb .Push (MakeReal (_cfag ));return _ebe ;};
// Empty empties the stack.
func (_bcde *PSStack )Empty (){*_bcde =[]PSObject {}};func (_ffa *PSOperand )exch (_cff *PSStack )error {_cfea ,_gea :=_cff .Pop ();if _gea !=nil {return _gea ;};_fge ,_gea :=_cff .Pop ();if _gea !=nil {return _gea ;};_gea =_cff .Push (_cfea );if _gea !=nil {return _gea ;};_gea =_cff .Push (_fge );return _gea ;};func (_gdf *PSOperand )cvr (_efc *PSStack )error {_ggc ,_eec :=_efc .Pop ();if _eec !=nil {return _eec ;};if _aec ,_dbb :=_ggc .(*PSReal );_dbb {_eec =_efc .Push (MakeReal (_aec .Val ));}else if _add ,_bee :=_ggc .(*PSInteger );_bee {_eec =_efc .Push (MakeReal (float64 (_add .Val )));}else {return ErrTypeCheck ;};return _eec ;};func (_ffg *PSOperand )exp (_gad *PSStack )error {_gcb ,_dbe :=_gad .PopNumberAsFloat64 ();if _dbe !=nil {return _dbe ;};_bge ,_dbe :=_gad .PopNumberAsFloat64 ();if _dbe !=nil {return _dbe ;};if _ca .Abs (_gcb )< 1&&_bge < 0{return ErrUndefinedResult ;};_ffe :=_ca .Pow (_bge ,_gcb );_dbe =_gad .Push (MakeReal (_ffe ));return _dbe ;};func (_ceb *PSProgram )String ()string {_ac :="\u007b\u0020";for _ ,_ea :=range *_ceb {_ac +=_ea .String ();_ac +="\u0020";};_ac +="\u007d";return _ac ;};func (_bagac *PSOperand )ifCondition (_eda *PSStack )error {_fage ,_baf :=_eda .Pop ();if _baf !=nil {return _baf ;};_dfc ,_baf :=_eda .Pop ();if _baf !=nil {return _baf ;};_beac ,_afd :=_fage .(*PSProgram );if !_afd {return ErrTypeCheck ;};_gbe ,_afd :=_dfc .(*PSBoolean );if !_afd {return ErrTypeCheck ;};if _gbe .Val {_gaa :=_beac .Exec (_eda );return _gaa ;};return nil ;};func (_bdb *PSOperand )cos (_da *PSStack )error {_cc ,_baab :=_da .PopNumberAsFloat64 ();if _baab !=nil {return _baab ;};_aaa :=_ca .Cos (_cc *_ca .Pi /180.0);_baab =_da .Push (MakeReal (_aaa ));return _baab ;};
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
type PSProgram []PSObject ;func (_bab *PSOperand )abs (_bbc *PSStack )error {_fbe ,_bcdb :=_bbc .Pop ();if _bcdb !=nil {return _bcdb ;};if _dca ,_ef :=_fbe .(*PSReal );_ef {_bbd :=_dca .Val ;if _bbd < 0{_bcdb =_bbc .Push (MakeReal (-_bbd ));}else {_bcdb =_bbc .Push (MakeReal (_bbd ));};}else if _age ,_cfg :=_fbe .(*PSInteger );_cfg {_bcf :=_age .Val ;if _bcf < 0{_bcdb =_bbc .Push (MakeInteger (-_bcf ));}else {_bcdb =_bbc .Push (MakeInteger (_bcf ));};}else {return ErrTypeCheck ;};return _bcdb ;};
// Exec executes the program, typically leaving output values on the stack.
func (_cbf *PSProgram )Exec (stack *PSStack )error {for _ ,_fde :=range *_cbf {var _cgd error ;switch _ec :=_fde .(type ){case *PSInteger :_dgb :=_ec ;_cgd =stack .Push (_dgb );case *PSReal :_gdc :=_ec ;_cgd =stack .Push (_gdc );case *PSBoolean :_ecd :=_ec ;_cgd =stack .Push (_ecd );case *PSProgram :_ef :=_ec ;_cgd =stack .Push (_ef );case *PSOperand :_cf :=_ec ;_cgd =_cf .Exec (stack );default:return ErrTypeCheck ;};if _cgd !=nil {return _cgd ;};};return nil ;};func (_bga *PSOperand )cvi (_eca *PSStack )error {_fcg ,_beb :=_eca .Pop ();if _beb !=nil {return _beb ;};if _gbb ,_dgbc :=_fcg .(*PSReal );_dgbc {_agf :=int (_gbb .Val );_beb =_eca .Push (MakeInteger (_agf ));}else if _dgec ,_ade :=_fcg .(*PSInteger );_ade {_bcg :=_dgec .Val ;_beb =_eca .Push (MakeInteger (_bcg ));}else {return ErrTypeCheck ;};return _beb ;};func (_dac *PSOperand )ne (_dbb *PSStack )error {_agda :=_dac .eq (_dbb );if _agda !=nil {return _agda ;};_agda =_dac .not (_dbb );return _agda ;};
func (_dcd *PSProgram )Exec (stack *PSStack )error {for _ ,_dee :=range *_dcd {var _cbc error ;switch _cg :=_dee .(type ){case *PSInteger :_ed :=_cg ;_cbc =stack .Push (_ed );case *PSReal :_fea :=_cg ;_cbc =stack .Push (_fea );case *PSBoolean :_ag :=_cg ;_cbc =stack .Push (_ag );case *PSProgram :_ff :=_cg ;_cbc =stack .Push (_ff );case *PSOperand :_fb :=_cg ;_cbc =_fb .Exec (stack );default:return ErrTypeCheck ;};if _cbc !=nil {return _cbc ;};};return nil ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_dadg *_c .Reader };var ErrRangeCheck =_e .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_gdfa *PSOperand )ifelse (_cae *PSStack )error {_fgaf ,_cbb :=_cae .Pop ();if _cbb !=nil {return _cbb ;};_ccd ,_cbb :=_cae .Pop ();if _cbb !=nil {return _cbb ;};_gda ,_cbb :=_cae .Pop ();if _cbb !=nil {return _cbb ;};_ffeb ,_fgfg :=_fgaf .(*PSProgram );if !_fgfg {return ErrTypeCheck ;};_fgfb ,_fgfg :=_ccd .(*PSProgram );if !_fgfg {return ErrTypeCheck ;};_bbe ,_fgfg :=_gda .(*PSBoolean );if !_fgfg {return ErrTypeCheck ;};if _bbe .Val {_ada :=_fgfb .Exec (_cae );return _ada ;};_cbb =_ffeb .Exec (_cae );return _cbb ;};
// NewPSProgram returns an empty, initialized PSProgram.
func NewPSProgram ()*PSProgram {return &PSProgram {}};func (_gacd *PSOperand )sub (_edd *PSStack )error {_fegf ,_bfa :=_edd .Pop ();if _bfa !=nil {return _bfa ;};_fef ,_bfa :=_edd .Pop ();if _bfa !=nil {return _bfa ;};_eaf ,_eag :=_fegf .(*PSReal );_bgcg ,_cfc :=_fegf .(*PSInteger );if !_eag &&!_cfc {return ErrTypeCheck ;};_dcda ,_bdg :=_fef .(*PSReal );_fcd ,_afc :=_fef .(*PSInteger );if !_bdg &&!_afc {return ErrTypeCheck ;};if _cfc &&_afc {_caf :=_fcd .Val -_bgcg .Val ;_bcea :=_edd .Push (MakeInteger (_caf ));return _bcea ;};var _gebe float64 =0;if _bdg {_gebe =_dcda .Val ;}else {_gebe =float64 (_fcd .Val );};if _eag {_gebe -=_eaf .Val ;}else {_gebe -=float64 (_bgcg .Val );};_bfa =_edd .Push (MakeReal (_gebe ));return _bfa ;};
// MakeOperand returns a new PSOperand object based on string `val`.
func MakeOperand (val string )*PSOperand {_addf :=PSOperand (val );return &_addf };func (_cfbb *PSOperand )mod (_dfag *PSStack )error {_cfdg ,_cca :=_dfag .Pop ();if _cca !=nil {return _cca ;};_ece ,_cca :=_dfag .Pop ();if _cca !=nil {return _cca ;};_dcga ,_gab :=_cfdg .(*PSInteger );if !_gab {return ErrTypeCheck ;};if _dcga .Val ==0{return ErrUndefinedResult ;};_fdg ,_gab :=_ece .(*PSInteger );if !_gab {return ErrTypeCheck ;};_aed :=_fdg .Val %_dcga .Val ;_cca =_dfag .Push (MakeInteger (_aed ));return _cca ;};func (_eee *PSOperand )truncate (_cfca *PSStack )error {_dbee ,_gddf :=_cfca .Pop ();if _gddf !=nil {return _gddf ;};if _bage ,_fed :=_dbee .(*PSReal );_fed {_aeee :=int (_bage .Val );_gddf =_cfca .Push (MakeReal (float64 (_aeee )));}else if _ged ,_bfda :=_dbee .(*PSInteger );_bfda {_gddf =_cfca .Push (MakeInteger (_ged .Val ));}else {return ErrTypeCheck ;};return _gddf ;};
// Append appends an object to the PSProgram.
func (_bag *PSProgram )Append (obj PSObject ){*_bag =append (*_bag ,obj )};
// PSInteger represents an integer.
type PSInteger struct{Val int ;};func (_gdd *PSOperand )bitshift (_bde *PSStack )error {_ffc ,_cfed :=_bde .PopInteger ();if _cfed !=nil {return _cfed ;};_dec ,_cfed :=_bde .PopInteger ();if _cfed !=nil {return _cfed ;};var _edc int ;if _ffc >=0{_edc =_dec <<uint (_ffc );}else {_edc =_dec >>uint (-_ffc );};_cfed =_bde .Push (MakeInteger (_edc ));return _cfed ;};
// Push pushes an object on top of the stack.
func (_afdf *PSStack )Push (obj PSObject )error {if len (*_afdf )> 100{return ErrStackOverflow ;};*_afdf =append (*_afdf ,obj );return nil ;};func (_dbc *PSOperand )ge (_agc *PSStack )error {_dd ,_fac :=_agc .PopNumberAsFloat64 ();if _fac !=nil {return _fac ;};_bed ,_fac :=_agc .PopNumberAsFloat64 ();if _fac !=nil {return _fac ;};if _ca .Abs (_bed -_dd )< _cd {_aac :=_agc .Push (MakeBool (true ));return _aac ;}else if _bed > _dd {_cdg :=_agc .Push (MakeBool (true ));return _cdg ;}else {_gff :=_agc .Push (MakeBool (false ));return _gff ;};};var ErrStackOverflow =_df .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");func (_de *PSReal )String ()string {return _b .Sprintf ("\u0025\u002e\u0035\u0066",_de .Val )};var ErrUnsupportedOperand =_df .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_edce *PSOperand )not (_dcac *PSStack )error {_cab ,_cgaa :=_dcac .Pop ();if _cgaa !=nil {return _cgaa ;};if _gge ,_ffefg :=_cab .(*PSBoolean );_ffefg {_cgaa =_dcac .Push (MakeBool (!_gge .Val ));return _cgaa ;}else if _gddb ,_ddc :=_cab .(*PSInteger );_ddc {_cgaa =_dcac .Push (MakeInteger (^_gddb .Val ));return _cgaa ;}else {return ErrTypeCheck ;};};
// PSBoolean represents a boolean value.
type PSBoolean struct{Val bool ;};func (_fcdf *PSParser )skipSpaces ()(int ,error ){_edff :=0;for {_gbd ,_acd :=_fcdf ._aab .Peek (1);if _acd !=nil {return 0,_acd ;};if _ba .IsWhiteSpace (_gbd [0]){_fcdf ._aab .ReadByte ();_edff ++;}else {break ;};};return _edff ,nil ;};func (_feb *PSProgram )Duplicate ()PSObject {_gcf :=&PSProgram {};for _ ,_bdf :=range *_feb {_gcf .Append (_bdf .Duplicate ());};return _gcf ;};func (_ddf *PSOperand )ln (_fgb *PSStack )error {_edgd ,_ffee :=_fgb .PopNumberAsFloat64 ();if _ffee !=nil {return _ffee ;};_fab :=_ca .Log (_edgd );_ffee =_fgb .Push (MakeReal (_fab ));return _ffee ;};func (_bgdg *PSOperand )roll (_ggce *PSStack )error {_cec ,_dfeb :=_ggce .Pop ();if _dfeb !=nil {return _dfeb ;};_gfeg ,_dfeb :=_ggce .Pop ();if _dfeb !=nil {return _dfeb ;};_adgb ,_bdbc :=_cec .(*PSInteger );if !_bdbc {return ErrTypeCheck ;};_ecd ,_bdbc :=_gfeg .(*PSInteger );if !_bdbc {return ErrTypeCheck ;};if _ecd .Val < 0{return ErrRangeCheck ;};if _ecd .Val ==0||_ecd .Val ==1{return nil ;};if _ecd .Val > len (*_ggce ){return ErrStackUnderflow ;};for _bacdg :=0;_bacdg < _ffd (_adgb .Val );_bacdg ++{var _edbg []PSObject ;_edbg =(*_ggce )[len (*_ggce )-(_ecd .Val ):len (*_ggce )];if _adgb .Val > 0{_ega :=_edbg [len (_edbg )-1];_edbg =append ([]PSObject {_ega },_edbg [0:len (_edbg )-1]...);}else {_ccb :=_edbg [len (_edbg )-_ecd .Val ];_edbg =append (_edbg [1:],_ccb );};_aefd :=append ((*_ggce )[0:len (*_ggce )-_ecd .Val ],_edbg ...);_ggce =&_aefd ;};return nil ;};func (_dcg *PSProgram )DebugString ()string {_cee :="\u007b\u0020";for _ ,_dfa :=range *_dcg {_cee +=_dfa .DebugString ();_cee +="\u0020";};_cee +="\u007d";return _cee ;};func (_bcb *PSOperand )lt (_ec *PSStack )error {_cgdc ,_bgc :=_ec .PopNumberAsFloat64 ();if _bgc !=nil {return _bgc ;};_bfb ,_bgc :=_ec .PopNumberAsFloat64 ();if _bgc !=nil {return _bgc ;};if _ca .Abs (_bfb -_cgdc )< _cd {_fad :=_ec .Push (MakeBool (false ));return _fad ;}else if _bfb < _cgdc {_gga :=_ec .Push (MakeBool (true ));return _gga ;}else {_adag :=_ec .Push (MakeBool (false ));return _adag ;};};func (_ce *PSInteger )DebugString ()string {return _b .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_ce .Val );};func (_fggb *PSOperand )ifelse (_dege *PSStack )error {_bgda ,_eecc :=_dege .Pop ();if _eecc !=nil {return _eecc ;};_fcb ,_eecc :=_dege .Pop ();if _eecc !=nil {return _eecc ;};_acg ,_eecc :=_dege .Pop ();if _eecc !=nil {return _eecc ;};_adf ,_cge :=_bgda .(*PSProgram );if !_cge {return ErrTypeCheck ;};_dcef ,_cge :=_fcb .(*PSProgram );if !_cge {return ErrTypeCheck ;};_aaad ,_cge :=_acg .(*PSBoolean );if !_cge {return ErrTypeCheck ;};if _aaad .Val {_dbg :=_dcef .Exec (_dege );return _dbg ;};_eecc =_adf .Exec (_dege );return _eecc ;};
// MakeReal returns a new PSReal object initialized with `val`.
func MakeReal (val float64 )*PSReal {_fbac :=PSReal {};_fbac .Val =val ;return &_fbac };
func MakeReal (val float64 )*PSReal {_adgbf :=PSReal {};_adgbf .Val =val ;return &_adgbf };
// MakeBool returns a new PSBoolean object initialized with `val`.
func MakeBool (val bool )*PSBoolean {_fcf :=PSBoolean {};_fcf .Val =val ;return &_fcf };func (_cgb *PSOperand )le (_gdg *PSStack )error {_cgae ,_cef :=_gdg .PopNumberAsFloat64 ();if _cef !=nil {return _cef ;};_deca ,_cef :=_gdg .PopNumberAsFloat64 ();if _cef !=nil {return _cef ;};if _ca .Abs (_deca -_cgae )< _cd {_agee :=_gdg .Push (MakeBool (true ));return _agee ;}else if _deca < _cgae {_cbd :=_gdg .Push (MakeBool (true ));return _cbd ;}else {_cbb :=_gdg .Push (MakeBool (false ));return _cbb ;};};func (_gcgg *PSParser )parseFunction ()(*PSProgram ,error ){_ffab ,_ :=_gcgg ._aab .ReadByte ();if _ffab !='{'{return nil ,_df .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_afg :=NewPSProgram ();for {_gcgg .skipSpaces ();_badb ,_bbb :=_gcgg ._aab .Peek (2);if _bbb !=nil {if _bbb ==_c .EOF {break ;};return nil ,_bbb ;};_dc .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_badb ));if _badb [0]=='}'{_dc .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_gcgg ._aab .ReadByte ();break ;}else if _badb [0]=='{'{_dc .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_acc ,_afgg :=_gcgg .parseFunction ();if _afgg !=nil {return nil ,_afgg ;};_afg .Append (_acc );}else if _ba .IsDecimalDigit (_badb [0])||(_badb [0]=='-'&&_ba .IsDecimalDigit (_badb [1])){_dc .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_ggca ,_fba :=_gcgg .parseNumber ();if _fba !=nil {return nil ,_fba ;};_afg .Append (_ggca );}else {_dc .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_badb ,_ =_gcgg ._aab .Peek (5);_fdc :=string (_badb );_dc .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_fdc );if (len (_fdc )> 4)&&(_fdc [:5]=="\u0066\u0061\u006cs\u0065"){_bafd ,_caec :=_gcgg .parseBool ();if _caec !=nil {return nil ,_caec ;};_afg .Append (_bafd );}else if (len (_fdc )> 3)&&(_fdc [:4]=="\u0074\u0072\u0075\u0065"){_bff ,_fbga :=_gcgg .parseBool ();if _fbga !=nil {return nil ,_fbga ;};_afg .Append (_bff );}else {_becc ,_gbfb :=_gcgg .parseOperand ();if _gbfb !=nil {return nil ,_gbfb ;};_afg .Append (_becc );};};};return _afg ,nil ;};func (_ddg *PSParser )parseBool ()(*PSBoolean ,error ){_agb ,_ffff :=_ddg ._aab .Peek (4);if _ffff !=nil {return MakeBool (false ),_ffff ;};if (len (_agb )>=4)&&(string (_agb [:4])=="\u0074\u0072\u0075\u0065"){_ddg ._aab .Discard (4);return MakeBool (true ),nil ;};_agb ,_ffff =_ddg ._aab .Peek (5);if _ffff !=nil {return MakeBool (false ),_ffff ;};if (len (_agb )>=5)&&(string (_agb [:5])=="\u0066\u0061\u006cs\u0065"){_ddg ._aab .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_df .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};func (_bdd *PSOperand )copy (_adg *PSStack )error {_feab ,_bce :=_adg .PopInteger ();if _bce !=nil {return _bce ;};if _feab < 0{return ErrRangeCheck ;};if _feab > len (*_adg ){return ErrRangeCheck ;};*_adg =append (*_adg ,(*_adg )[len (*_adg )-_feab :]...);return nil ;};
// DebugString returns a descriptive string representation of the stack - intended for debugging.
func (_eeba *PSStack )DebugString ()string {_cbbb :="\u005b\u0020";for _ ,_cgec :=range *_eeba {_cbbb +=_cgec .DebugString ();_cbbb +="\u0020";};_cbbb +="\u005d";return _cbbb ;};func (_dab *PSOperand )or (_dfb *PSStack )error {_gdge ,_gaf :=_dfb .Pop ();if _gaf !=nil {return _gaf ;};_dgg ,_gaf :=_dfb .Pop ();if _gaf !=nil {return _gaf ;};if _gbf ,_ceeea :=_gdge .(*PSBoolean );_ceeea {_gafb ,_bdfg :=_dgg .(*PSBoolean );if !_bdfg {return ErrTypeCheck ;};_gaf =_dfb .Push (MakeBool (_gbf .Val ||_gafb .Val ));return _gaf ;};if _bfc ,_fbef :=_gdge .(*PSInteger );_fbef {_ddcc ,_bbf :=_dgg .(*PSInteger );if !_bbf {return ErrTypeCheck ;};_gaf =_dfb .Push (MakeInteger (_bfc .Val |_ddcc .Val ));return _gaf ;};return ErrTypeCheck ;};func (_cdb *PSOperand )Duplicate ()PSObject {_cae :=*_cdb ;return &_cae };func (_dggf *PSOperand )sin (_efg *PSStack )error {_aee ,_edcd :=_efg .PopNumberAsFloat64 ();if _edcd !=nil {return _edcd ;};_daed :=_ca .Sin (_aee *_ca .Pi /180.0);_edcd =_efg .Push (MakeReal (_daed ));return _edcd ;};
// Pop pops an object from the top of the stack.
func (_deb *PSStack )Pop ()(PSObject ,error ){if len (*_deb )< 1{return nil ,ErrStackUnderflow ;};_dgdf :=(*_deb )[len (*_deb )-1];*_deb =(*_deb )[0:len (*_deb )-1];return _dgdf ,nil ;};func (_gca *PSOperand )ceiling (_fffb *PSStack )error {_abc ,_cgc :=_fffb .Pop ();if _cgc !=nil {return _cgc ;};if _gcee ,_gb :=_abc .(*PSReal );_gb {_cgc =_fffb .Push (MakeReal (_ca .Ceil (_gcee .Val )));}else if _cgad ,_bfd :=_abc .(*PSInteger );_bfd {_cgc =_fffb .Push (MakeInteger (_cgad .Val ));}else {_cgc =ErrTypeCheck ;};return _cgc ;};func (_ead *PSOperand )and (_bcg *PSStack )error {_gf ,_cde :=_bcg .Pop ();if _cde !=nil {return _cde ;};_ad ,_cde :=_bcg .Pop ();if _cde !=nil {return _cde ;};if _bca ,_fgf :=_gf .(*PSBoolean );_fgf {_ebb ,_dg :=_ad .(*PSBoolean );if !_dg {return ErrTypeCheck ;};_cde =_bcg .Push (MakeBool (_bca .Val &&_ebb .Val ));return _cde ;};if _gd ,_cdc :=_gf .(*PSInteger );_cdc {_gfe ,_ga :=_ad .(*PSInteger );if !_ga {return ErrTypeCheck ;};_cde =_bcg .Push (MakeInteger (_gd .Val &_gfe .Val ));return _cde ;};return ErrTypeCheck ;};func (_bgf *PSReal )DebugString ()string {return _b .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_bgf .Val );};func (_cgdb *PSOperand )ne (_bbcc *PSStack )error {_bae :=_cgdb .eq (_bbcc );if _bae !=nil {return _bae ;};_bae =_cgdb .not (_bbcc );return _bae ;};const _cd =0.000001;var ErrTypeCheck =_df .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
func (_bf *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_eg :=range objects {_gc :=_bf .Stack .Push (_eg );if _gc !=nil {return nil ,_gc ;};};_db :=_bf ._f .Exec (_bf .Stack );if _db !=nil {_dc .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_db );return nil ,_db ;};_cfe :=[]PSObject (*_bf .Stack );_bf .Stack .Empty ();return _cfe ,nil ;};func (_ccd *PSParser )parseNumber ()(PSObject ,error ){_decc ,_cgbg :=_ba .ParseNumber (_ccd ._aab );if _cgbg !=nil {return nil ,_cgbg ;};switch _bdc :=_decc .(type ){case *_ba .PdfObjectFloat :return MakeReal (float64 (*_bdc )),nil ;case *_ba .PdfObjectInteger :return MakeInteger (int (*_bdc )),nil ;};return nil ,_b .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_decc );};
// Parse parses the postscript and store as a program that can be executed.
func (_bfbg *PSParser )Parse ()(*PSProgram ,error ){_bfbg .skipSpaces ();_gdc ,_bfgd :=_bfbg ._aab .Peek (2);if _bfgd !=nil {return nil ,_bfgd ;};if _gdc [0]!='{'{return nil ,_df .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");};_ffca ,_bfgd :=_bfbg .parseFunction ();if _bfgd !=nil &&_bfgd !=_c .EOF {return nil ,_bfgd ;};return _ffca ,_bfgd ;};
// MakeInteger returns a new PSInteger object initialized with `val`.
func MakeInteger (val int )*PSInteger {_ebdb :=PSInteger {};_ebdb .Val =val ;return &_ebdb };func (_egb *PSOperand )eq (_ege *PSStack )error {_edg ,_adga :=_ege .Pop ();if _adga !=nil {return _adga ;};_gfd ,_adga :=_ege .Pop ();if _adga !=nil {return _adga ;};_gfb ,_gfc :=_edg .(*PSBoolean );_efe ,_dgb :=_gfd .(*PSBoolean );if _gfc ||_dgb {var _geb error ;if _gfc &&_dgb {_geb =_ege .Push (MakeBool (_gfb .Val ==_efe .Val ));}else {_geb =_ege .Push (MakeBool (false ));};return _geb ;};var _fag float64 ;var _agd float64 ;if _bacd ,_fbd :=_edg .(*PSInteger );_fbd {_fag =float64 (_bacd .Val );}else if _ccef ,_cagg :=_edg .(*PSReal );_cagg {_fag =_ccef .Val ;}else {return ErrTypeCheck ;};if _fc ,_abcd :=_gfd .(*PSInteger );_abcd {_agd =float64 (_fc .Val );}else if _bea ,_eadc :=_gfd .(*PSReal );_eadc {_agd =_bea .Val ;}else {return ErrTypeCheck ;};if _ca .Abs (_agd -_fag )< _cd {_adga =_ege .Push (MakeBool (true ));}else {_adga =_ege .Push (MakeBool (false ));};return _adga ;};func (_bac *PSOperand )cvi (_ccg *PSStack )error {_fbc ,_cgf :=_ccg .Pop ();if _cgf !=nil {return _cgf ;};if _cdce ,_fgg :=_fbc .(*PSReal );_fgg {_cdf :=int (_cdce .Val );_cgf =_ccg .Push (MakeInteger (_cdf ));}else if _ae ,_aff :=_fbc .(*PSInteger );_aff {_ace :=_ae .Val ;_cgf =_ccg .Push (MakeInteger (_ace ));}else {return ErrTypeCheck ;};return _cgf ;};
// PSParser is a basic Postscript parser.
type PSParser struct{_aab *_ee .Reader };

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