mirror of
https://github.com/unidoc/unipdf.git
synced 2025-05-01 22:17:29 +08:00
Merge pull request #410 from unidoc-build/prep-rc-v3.11.1
Prepare release of UniPDF v3.11.1
This commit is contained in:
commit
13c908a7c9
File diff suppressed because one or more lines are too long
116
common/common.go
116
common/common.go
@ -10,7 +10,19 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package common contains common properties used by the subpackages.
|
||||
package common ;import (_a "fmt";_aa "io";_dc "os";_d "path/filepath";_f "runtime";_bg "time";);const _bgg ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
|
||||
package common ;import (_b "fmt";_fc "io";_f "os";_c "path/filepath";_e "runtime";_g "time";);
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_df WriterLogger )Warning (format string ,args ...interface{}){if _df .LogLevel >=LogLevelWarning {_bgd :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_df .logToWriter (_df .Output ,_bgd ,format ,args ...);};};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_cf ConsoleLogger )Trace (format string ,args ...interface{}){if _cf .LogLevel >=LogLevelTrace {_dac :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_cf .output (_f .Stdout ,_dac ,format ,args ...);};};const _ad =9;
|
||||
|
||||
// Error logs error message.
|
||||
func (_bgc ConsoleLogger )Error (format string ,args ...interface{}){if _bgc .LogLevel >=LogLevelError {_fb :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_bgc .output (_f .Stdout ,_fb ,format ,args ...);};};
|
||||
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};
|
||||
@ -19,84 +31,72 @@ func (DummyLogger )Error (format string ,args ...interface{}){};
|
||||
func (DummyLogger )Info (format string ,args ...interface{}){};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_bfc ConsoleLogger )Warning (format string ,args ...interface{}){if _bfc .LogLevel >=LogLevelWarning {_af :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_bfc .output (_dc .Stdout ,_af ,format ,args ...);};};
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _aa .Writer ;};
|
||||
func (_bac ConsoleLogger )Warning (format string ,args ...interface{}){if _bac .LogLevel >=LogLevelWarning {_fcb :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_bac .output (_f .Stdout ,_fcb ,format ,args ...);};};
|
||||
|
||||
// LogLevel is the verbosity level for logging.
|
||||
type LogLevel int ;
|
||||
type LogLevel int ;func _fbb (_gaac _fc .Writer ,_bed string ,_bdd string ,_dc ...interface{}){_ ,_edf ,_ebe ,_cfb :=_e .Caller (3);if !_cfb {_edf ="\u003f\u003f\u003f";_ebe =0;}else {_edf =_c .Base (_edf );};_gfe :=_b .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bed ,_edf ,_ebe )+_bdd +"\u000a";_b .Fprintf (_gaac ,_gfe ,_dc ...);};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_cb ConsoleLogger )Debug (format string ,args ...interface{}){if _cb .LogLevel >=LogLevelDebug {_edg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_cb .output (_dc .Stdout ,_edg ,format ,args ...);};};
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _fc .Writer )*WriterLogger {_dg :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_dg ;};func UtcTimeFormat (t _g .Time )string {return t .Format (_cag )+"\u0020\u0055\u0054\u0043"};
|
||||
|
||||
// IsLogLevel returns true from dummy logger.
|
||||
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
|
||||
|
||||
// Error logs error message.
|
||||
func (_ea ConsoleLogger )Error (format string ,args ...interface{}){if _ea .LogLevel >=LogLevelError {_bb :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ea .output (_dc .Stdout ,_bb ,format ,args ...);};};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// Info logs info message.
|
||||
func (_ff ConsoleLogger )Info (format string ,args ...interface{}){if _ff .LogLevel >=LogLevelInfo {_ca :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ff .output (_dc .Stdout ,_ca ,format ,args ...);};};const _gecb =18;
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_gf ConsoleLogger )Trace (format string ,args ...interface{}){if _gf .LogLevel >=LogLevelTrace {_dcc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gf .output (_dc .Stdout ,_dcc ,format ,args ...);};};
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_afa WriterLogger )IsLogLevel (level LogLevel )bool {return _afa .LogLevel >=level };
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_ed ConsoleLogger )Notice (format string ,args ...interface{}){if _ed .LogLevel >=LogLevelNotice {_fg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ed .output (_dc .Stdout ,_fg ,format ,args ...);};};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_bfca WriterLogger )Debug (format string ,args ...interface{}){if _bfca .LogLevel >=LogLevelDebug {_de :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_bfca .logToWriter (_bfca .Output ,_de ,format ,args ...);};};
|
||||
func (_ab WriterLogger )Notice (format string ,args ...interface{}){if _ab .LogLevel >=LogLevelNotice {_fde :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ab .logToWriter (_ab .Output ,_fde ,format ,args ...);};};
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const _cbee =9;
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_ac WriterLogger )Notice (format string ,args ...interface{}){if _ac .LogLevel >=LogLevelNotice {_dgf :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ac .logToWriter (_ac .Output ,_dgf ,format ,args ...);};};func (_cc ConsoleLogger )output (_dg _aa .Writer ,_fa string ,_gde string ,_agge ...interface{}){_fad (_dg ,_fa ,_gde ,_agge ...);};
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const _aed =8;
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_ee WriterLogger )Trace (format string ,args ...interface{}){if _ee .LogLevel >=LogLevelTrace {_ggc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ee .logToWriter (_ee .Output ,_ggc ,format ,args ...);};};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_cg WriterLogger )Warning (format string ,args ...interface{}){if _cg .LogLevel >=LogLevelWarning {_ge :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_cg .logToWriter (_cg .Output ,_ge ,format ,args ...);};};
|
||||
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_ba string ,_e ...interface{});Warning (_ag string ,_g ...interface{});Notice (_c string ,_cd ...interface{});Info (_agg string ,_gd ...interface{});Debug (_bc string ,_gdd ...interface{});Trace (_dcf string ,_bf ...interface{});IsLogLevel (_bfd LogLevel )bool ;};
|
||||
|
||||
// Error logs error message.
|
||||
func (_ead WriterLogger )Error (format string ,args ...interface{}){if _ead .LogLevel >=LogLevelError {_be :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ead .logToWriter (_ead .Output ,_be ,format ,args ...);};};
|
||||
func (_fbf WriterLogger )Trace (format string ,args ...interface{}){if _fbf .LogLevel >=LogLevelTrace {_ae :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_fbf .logToWriter (_fbf .Output ,_ae ,format ,args ...);};};
|
||||
|
||||
// Notice does nothing for dummy logger.
|
||||
func (DummyLogger )Notice (format string ,args ...interface{}){};
|
||||
|
||||
// Debug does nothing for dummy logger.
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};var Log Logger =DummyLogger {};const _gec =2020;const _gda =6;func (_da WriterLogger )logToWriter (_eb _aa .Writer ,_db string ,_bgd string ,_dae ...interface{}){_fad (_eb ,_db ,_bgd ,_dae );};
|
||||
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
|
||||
func SetLogger (logger Logger ){Log =logger };const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_fd ConsoleLogger )Debug (format string ,args ...interface{}){if _fd .LogLevel >=LogLevelDebug {_db :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_fd .output (_f .Stdout ,_db ,format ,args ...);};};
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_gg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _gg .LogLevel >=level };func UtcTimeFormat (t _bg .Time )string {return t .Format (_bgg )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_bg .Date (_gec ,_cbee ,_gda ,_gecb ,_eg ,0,0,_bg .UTC );
|
||||
func (_bfgf WriterLogger )IsLogLevel (level LogLevel )bool {return _bfgf .LogLevel >=level };const _dbg =2020;
|
||||
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _aa .Writer )*WriterLogger {_ga :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_ga ;};const Version ="\u0033\u002e\u0031\u0031\u002e\u0030";const _eg =50;
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_d string ,_bb ...interface{});Warning (_ga string ,_da ...interface{});Notice (_fa string ,_eg ...interface{});Info (_fg string ,_bg ...interface{});Debug (_cb string ,_ba ...interface{});Trace (_bd string ,_bf ...interface{});IsLogLevel (_eb LogLevel )bool ;};
|
||||
|
||||
// Info logs info message.
|
||||
func (_ge WriterLogger )Info (format string ,args ...interface{}){if _ge .LogLevel >=LogLevelInfo {_de :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ge .logToWriter (_ge .Output ,_de ,format ,args ...);};};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_fe WriterLogger )Debug (format string ,args ...interface{}){if _fe .LogLevel >=LogLevelDebug {_gd :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_fe .logToWriter (_fe .Output ,_gd ,format ,args ...);};};const _dge =50;
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_egg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _egg .LogLevel >=level };var ReleasedAt =_g .Date (_dbg ,_ad ,_gbg ,_aed ,_dge ,0,0,_g .UTC );
|
||||
|
||||
// Debug does nothing for dummy logger.
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};var Log Logger =DummyLogger {};
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _fc .Writer ;};func (_ed ConsoleLogger )output (_bfg _fc .Writer ,_ce string ,_ca string ,_fgg ...interface{}){_fbb (_bfg ,_ce ,_ca ,_fgg ...);};const Version ="\u0033\u002e\u0031\u0031\u002e\u0031";
|
||||
|
||||
// Error logs error message.
|
||||
func (_be WriterLogger )Error (format string ,args ...interface{}){if _be .LogLevel >=LogLevelError {_dga :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_be .logToWriter (_be .Output ,_dga ,format ,args ...);};};
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};
|
||||
|
||||
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
|
||||
type ConsoleLogger struct{LogLevel LogLevel ;};
|
||||
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};func _fad (_ace _aa .Writer ,_edb string ,_cga string ,_fd ...interface{}){_ ,_cae ,_ec ,_dbc :=_f .Caller (3);if !_dbc {_cae ="\u003f\u003f\u003f";_ec =0;}else {_cae =_d .Base (_cae );};_fge :=_a .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_edb ,_cae ,_ec )+_cga +"\u000a";_a .Fprintf (_ace ,_fge ,_fd ...);};
|
||||
|
||||
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
|
||||
func SetLogger (logger Logger ){Log =logger };
|
||||
// IsLogLevel returns true from dummy logger.
|
||||
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
|
||||
|
||||
// Info logs info message.
|
||||
func (_cba WriterLogger )Info (format string ,args ...interface{}){if _cba .LogLevel >=LogLevelInfo {_cbe :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cba .logToWriter (_cba .Output ,_cbe ,format ,args ...);};};
|
||||
func (_cbb ConsoleLogger )Info (format string ,args ...interface{}){if _cbb .LogLevel >=LogLevelInfo {_ef :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cbb .output (_f .Stdout ,_ef ,format ,args ...);};};const _gbg =14;const _cag ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";func (_gaa WriterLogger )logToWriter (_bc _fc .Writer ,_gf string ,_abc string ,_ea ...interface{}){_fbb (_bc ,_gf ,_abc ,_ea );};
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_gb ConsoleLogger )Notice (format string ,args ...interface{}){if _gb .LogLevel >=LogLevelNotice {_af :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_gb .output (_f .Stdout ,_af ,format ,args ...);};};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -14,204 +14,204 @@
|
||||
// page content streams and XObject forms and thus also in annotation appearance streams.
|
||||
//
|
||||
// Also defines utility functions for drawing common shapes such as rectangles, lines and circles (ovals).
|
||||
package draw ;import (_f "fmt";_b "github.com/unidoc/unipdf/v3/contentstream";_e "github.com/unidoc/unipdf/v3/core";_ee "github.com/unidoc/unipdf/v3/internal/transform";_fe "github.com/unidoc/unipdf/v3/model";_g "math";);
|
||||
package draw ;import (_ee "fmt";_df "github.com/unidoc/unipdf/v3/contentstream";_f "github.com/unidoc/unipdf/v3/core";_eb "github.com/unidoc/unipdf/v3/internal/transform";_a "github.com/unidoc/unipdf/v3/model";_e "math";);
|
||||
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_aac Vector )FlipY ()Vector {_aac .Dy =-_aac .Dy ;return _aac };
|
||||
|
||||
// DrawPathWithCreator makes the path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawPathWithCreator (path Path ,creator *_b .ContentCreator ){for _fdd ,_ffg :=range path .Points {if _fdd ==0{creator .Add_m (_ffg .X ,_ffg .Y );}else {creator .Add_l (_ffg .X ,_ffg .Y );};};};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_ga Vector )Rotate (phi float64 )Vector {_ccd :=_ga .Magnitude ();_aaa :=_ga .GetPolarAngle ();return NewVectorPolar (_ccd ,_aaa +phi );};
|
||||
|
||||
// NewCubicBezierCurve returns a new cubic Bezier curve.
|
||||
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_fea :=CubicBezierCurve {};_fea .P0 =NewPoint (x0 ,y0 );_fea .P1 =NewPoint (x1 ,y1 );_fea .P2 =NewPoint (x2 ,y2 );_fea .P3 =NewPoint (x3 ,y3 );return _fea ;};
|
||||
|
||||
// BoundingBox represents the smallest rectangular area that encapsulates an object.
|
||||
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_dgg BoundingBox )ToPdfRectangle ()*_fe .PdfRectangle {return &_fe .PdfRectangle {Llx :_dgg .X ,Lly :_dgg .Y ,Urx :_dgg .X +_dgg .Width ,Ury :_dgg .Y +_dgg .Height };};
|
||||
|
||||
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
|
||||
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_dg Path )GetBoundingBox ()BoundingBox {_cd :=BoundingBox {};_cgf :=0.0;_ce :=0.0;_dc :=0.0;_bb :=0.0;for _af ,_ea :=range _dg .Points {if _af ==0{_cgf =_ea .X ;_ce =_ea .X ;_dc =_ea .Y ;_bb =_ea .Y ;continue ;};if _ea .X < _cgf {_cgf =_ea .X ;};if _ea .X > _ce {_ce =_ea .X ;};if _ea .Y < _dc {_dc =_ea .Y ;};if _ea .Y > _bb {_bb =_ea .Y ;};};_cd .X =_cgf ;_cd .Y =_dc ;_cd .Width =_ce -_cgf ;_cd .Height =_bb -_dc ;return _cd ;};
|
||||
|
||||
// DrawBezierPathWithCreator makes the bezier path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_b .ContentCreator ){for _ebf ,_bcga :=range bpath .Curves {if _ebf ==0{creator .Add_m (_bcga .P0 .X ,_bcga .P0 .Y );};creator .Add_c (_bcga .P1 .X ,_bcga .P1 .Y ,_bcga .P2 .X ,_bcga .P2 .Y ,_bcga .P3 .X ,_bcga .P3 .Y );};};
|
||||
|
||||
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
|
||||
// or arrows at either end. The line also has a specified width, color and opacity.
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_ceb Vector )Scale (factor float64 )Vector {_ffc :=_ceb .Magnitude ();_ccc :=_ceb .GetPolarAngle ();_ceb .Dx =factor *_ffc *_g .Cos (_ccc );_ceb .Dy =factor *_ffc *_g .Sin (_ccc );return _ceb ;};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};func (_adb Point )String ()string {return _f .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_adb .X ,_adb .Y );};
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// PolyBezierCurve represents a composite curve that is the result of
|
||||
// joining multiple cubic Bezier curves.
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;};
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;};
|
||||
|
||||
// Draw draws the polyline. A graphics state name can be specified for
|
||||
// setting the polyline properties (e.g. setting the opacity). Otherwise leave
|
||||
// empty (""). Returns the content stream as a byte array and the polyline
|
||||
// bounding box.
|
||||
func (_edb Polyline )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){if _edb .LineColor ==nil {_edb .LineColor =_fe .NewPdfColorDeviceRGB (0,0,0);};_bagd :=NewPath ();for _ ,_bda :=range _edb .Points {_bagd =_bagd .AppendPoint (_bda );};_gfb :=_b .NewContentCreator ();_gfb .Add_q ();_gfb .Add_RG (_edb .LineColor .R (),_edb .LineColor .G (),_edb .LineColor .B ());_gfb .Add_w (_edb .LineWidth );if len (gsName )> 1{_gfb .Add_gs (_e .PdfObjectName (gsName ));};DrawPathWithCreator (_bagd ,_gfb );_gfb .Add_S ();_gfb .Add_Q ();return _gfb .Bytes (),_bagd .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_egab Vector )GetPolarAngle ()float64 {return _e .Atan2 (_egab .Dy ,_egab .Dx )};
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_de CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_de .Curves =append (_de .Curves ,curve );return _de ;};
|
||||
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_gde Vector )Magnitude ()float64 {return _g .Sqrt (_g .Pow (_gde .Dx ,2.0)+_g .Pow (_gde .Dy ,2.0))};
|
||||
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_fg CubicBezierPath )Copy ()CubicBezierPath {_aa :=CubicBezierPath {};_aa .Curves =[]CubicBezierCurve {};for _ ,_dd :=range _fg .Curves {_aa .Curves =append (_aa .Curves ,_dd );};return _aa ;};
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_eecg Vector )Flip ()Vector {_cbg :=_eecg .Magnitude ();_cgd :=_eecg .GetPolarAngle ();_eecg .Dx =_cbg *_g .Cos (_cgd +_g .Pi );_eecg .Dy =_cbg *_g .Sin (_cgd +_g .Pi );return _eecg ;};
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_fcb Path )RemovePoint (number int )Path {if number < 1||number > len (_fcb .Points ){return _fcb ;};_bcg :=number -1;_fcb .Points =append (_fcb .Points [:_bcg ],_fcb .Points [_bcg +1:]...);return _fcb ;};
|
||||
|
||||
// Draw draws the polygon. A graphics state name can be specified for
|
||||
// setting the polygon properties (e.g. setting the opacity). Otherwise leave
|
||||
// empty (""). Returns the content stream as a byte array and the polygon
|
||||
// bounding box.
|
||||
func (_afa Polygon )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_dcf :=_b .NewContentCreator ();_dcf .Add_q ();_afa .FillEnabled =_afa .FillEnabled &&_afa .FillColor !=nil ;if _afa .FillEnabled {_dcf .Add_rg (_afa .FillColor .R (),_afa .FillColor .G (),_afa .FillColor .B ());};_afa .BorderEnabled =_afa .BorderEnabled &&_afa .BorderColor !=nil ;if _afa .BorderEnabled {_dcf .Add_RG (_afa .BorderColor .R (),_afa .BorderColor .G (),_afa .BorderColor .B ());_dcf .Add_w (_afa .BorderWidth );};if len (gsName )> 1{_dcf .Add_gs (_e .PdfObjectName (gsName ));};_ead :=NewPath ();for _ ,_gff :=range _afa .Points {for _dff ,_edf :=range _gff {_ead =_ead .AppendPoint (_edf );if _dff ==0{_dcf .Add_m (_edf .X ,_edf .Y );}else {_dcf .Add_l (_edf .X ,_edf .Y );};};_dcf .Add_h ();};if _afa .FillEnabled &&_afa .BorderEnabled {_dcf .Add_B ();}else if _afa .FillEnabled {_dcf .Add_f ();}else if _afa .BorderEnabled {_dcf .Add_S ();};_dcf .Add_Q ();return _dcf .Bytes (),_ead .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
func (_ffe Polygon )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_ebc :=_df .NewContentCreator ();_ebc .Add_q ();_ffe .FillEnabled =_ffe .FillEnabled &&_ffe .FillColor !=nil ;if _ffe .FillEnabled {_ebc .Add_rg (_ffe .FillColor .R (),_ffe .FillColor .G (),_ffe .FillColor .B ());};_ffe .BorderEnabled =_ffe .BorderEnabled &&_ffe .BorderColor !=nil ;if _ffe .BorderEnabled {_ebc .Add_RG (_ffe .BorderColor .R (),_ffe .BorderColor .G (),_ffe .BorderColor .B ());_ebc .Add_w (_ffe .BorderWidth );};if len (gsName )> 1{_ebc .Add_gs (_f .PdfObjectName (gsName ));};_bfd :=NewPath ();for _ ,_fbd :=range _ffe .Points {for _bdc ,_eab :=range _fbd {_bfd =_bfd .AppendPoint (_eab );if _bdc ==0{_ebc .Add_m (_eab .X ,_eab .Y );}else {_ebc .Add_l (_eab .X ,_eab .Y );};};_ebc .Add_h ();};if _ffe .FillEnabled &&_ffe .BorderEnabled {_ebc .Add_B ();}else if _ffe .FillEnabled {_ebc .Add_f ();}else if _ffe .BorderEnabled {_ebc .Add_S ();};_ebc .Add_Q ();return _ebc .Bytes (),_bfd .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
|
||||
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
|
||||
// one occurred.
|
||||
func (_bf BasicLine )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_agd :=_bf .LineWidth ;_egd :=NewPath ();_egd =_egd .AppendPoint (NewPoint (_bf .X1 ,_bf .Y1 ));_egd =_egd .AppendPoint (NewPoint (_bf .X2 ,_bf .Y2 ));_fbe :=_b .NewContentCreator ();_bab :=_egd .GetBoundingBox ();DrawPathWithCreator (_egd ,_fbe );if _bf .LineStyle ==LineStyleDashed {_fbe .Add_d ([]int64 {1,1},0);};_fbe .Add_RG (_bf .LineColor .R (),_bf .LineColor .G (),_bf .LineColor .B ()).Add_w (_agd ).Add_S ().Add_Q ();return _fbe .Bytes (),_bab .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Copy returns a clone of the path.
|
||||
func (_fc Path )Copy ()Path {_ag :=Path {};_ag .Points =[]Point {};for _ ,_gga :=range _fc .Points {_ag .Points =append (_ag .Points ,_gga );};return _ag ;};
|
||||
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_fe .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
|
||||
// Length returns the number of points in the path.
|
||||
func (_bcg Path )Length ()int {return len (_bcg .Points )};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_efe CubicBezierPath )GetBoundingBox ()Rectangle {_gc :=Rectangle {};_cb :=0.0;_ddb :=0.0;_aeb :=0.0;_ca :=0.0;for _cf ,_ec :=range _efe .Curves {_db :=_ec .GetBounds ();if _cf ==0{_cb =_db .Llx ;_ddb =_db .Urx ;_aeb =_db .Lly ;_ca =_db .Ury ;continue ;};if _db .Llx < _cb {_cb =_db .Llx ;};if _db .Urx > _ddb {_ddb =_db .Urx ;};if _db .Lly < _aeb {_aeb =_db .Lly ;};if _db .Ury > _ca {_ca =_db .Ury ;};};_gc .X =_cb ;_gc .Y =_aeb ;_gc .Width =_ddb -_cb ;_gc .Height =_ca -_aeb ;return _gc ;};
|
||||
|
||||
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
||||
func (_cff Point )Add (dx ,dy float64 )Point {_cff .X +=dx ;_cff .Y +=dy ;return _cff };
|
||||
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_da :=CubicBezierPath {};_da .Curves =[]CubicBezierCurve {};return _da ;};
|
||||
|
||||
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
|
||||
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
|
||||
// if one occurred.
|
||||
func (_bcfe Line )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_eef ,_gd :=_bcfe .X1 ,_bcfe .X2 ;_gdf ,_efd :=_bcfe .Y1 ,_bcfe .Y2 ;_bcgf :=_efd -_gdf ;_eeg :=_gd -_eef ;_efa :=_g .Atan2 (_bcgf ,_eeg );L :=_g .Sqrt (_g .Pow (_eeg ,2.0)+_g .Pow (_bcgf ,2.0));_cdb :=_bcfe .LineWidth ;_afc :=_g .Pi ;_gfe :=1.0;if _eeg < 0{_gfe *=-1.0;};if _bcgf < 0{_gfe *=-1.0;};VsX :=_gfe *(-_cdb /2*_g .Cos (_efa +_afc /2));VsY :=_gfe *(-_cdb /2*_g .Sin (_efa +_afc /2)+_cdb *_g .Sin (_efa +_afc /2));V1X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2);V1Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2);V2X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2)+L *_g .Cos (_efa );V2Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2)+L *_g .Sin (_efa );V3X :=VsX +_cdb /2*_g .Cos (_efa +_afc /2)+L *_g .Cos (_efa )+_cdb *_g .Cos (_efa -_afc /2);V3Y :=VsY +_cdb /2*_g .Sin (_efa +_afc /2)+L *_g .Sin (_efa )+_cdb *_g .Sin (_efa -_afc /2);V4X :=VsX +_cdb /2*_g .Cos (_efa -_afc /2);V4Y :=VsY +_cdb /2*_g .Sin (_efa -_afc /2);_daa :=NewPath ();_daa =_daa .AppendPoint (NewPoint (V1X ,V1Y ));_daa =_daa .AppendPoint (NewPoint (V2X ,V2Y ));_daa =_daa .AppendPoint (NewPoint (V3X ,V3Y ));_daa =_daa .AppendPoint (NewPoint (V4X ,V4Y ));_ece :=_bcfe .LineEndingStyle1 ;_ebb :=_bcfe .LineEndingStyle2 ;_dge :=3*_cdb ;_ceg :=3*_cdb ;_ac :=(_ceg -_cdb )/2;if _ebb ==LineEndingStyleArrow {_affb :=_daa .GetPointNumber (2);_fde :=NewVectorPolar (_dge ,_efa +_afc );_dfe :=_affb .AddVector (_fde );_bgc :=NewVectorPolar (_ceg /2,_efa +_afc /2);_afag :=NewVectorPolar (_dge ,_efa );_ecc :=NewVectorPolar (_ac ,_efa +_afc /2);_dce :=_dfe .AddVector (_ecc );_cfg :=_afag .Add (_bgc .Flip ());_fb :=_dce .AddVector (_cfg );_cec :=_bgc .Scale (2).Flip ().Add (_cfg .Flip ());_fbb :=_fb .AddVector (_cec );_ba :=_dfe .AddVector (NewVectorPolar (_cdb ,_efa -_afc /2));_eec :=NewPath ();_eec =_eec .AppendPoint (_daa .GetPointNumber (1));_eec =_eec .AppendPoint (_dfe );_eec =_eec .AppendPoint (_dce );_eec =_eec .AppendPoint (_fb );_eec =_eec .AppendPoint (_fbb );_eec =_eec .AppendPoint (_ba );_eec =_eec .AppendPoint (_daa .GetPointNumber (4));_daa =_eec ;};if _ece ==LineEndingStyleArrow {_dffa :=_daa .GetPointNumber (1);_aab :=_daa .GetPointNumber (_daa .Length ());_cecc :=NewVectorPolar (_cdb /2,_efa +_afc +_afc /2);_cef :=_dffa .AddVector (_cecc );_gdc :=NewVectorPolar (_dge ,_efa ).Add (NewVectorPolar (_ceg /2,_efa +_afc /2));_gb :=_cef .AddVector (_gdc );_aec :=NewVectorPolar (_ac ,_efa -_afc /2);_bag :=_gb .AddVector (_aec );_gfed :=NewVectorPolar (_dge ,_efa );_bd :=_aab .AddVector (_gfed );_dee :=NewVectorPolar (_ac ,_efa +_afc +_afc /2);_dfg :=_bd .AddVector (_dee );_gda :=_cef ;_egb :=NewPath ();_egb =_egb .AppendPoint (_cef );_egb =_egb .AppendPoint (_gb );_egb =_egb .AppendPoint (_bag );for _ ,_fcb :=range _daa .Points [1:len (_daa .Points )-1]{_egb =_egb .AppendPoint (_fcb );};_egb =_egb .AppendPoint (_bd );_egb =_egb .AppendPoint (_dfg );_egb =_egb .AppendPoint (_gda );_daa =_egb ;};_ebc :=_b .NewContentCreator ();_ebc .Add_q ().Add_rg (_bcfe .LineColor .R (),_bcfe .LineColor .G (),_bcfe .LineColor .B ());if len (gsName )> 1{_ebc .Add_gs (_e .PdfObjectName (gsName ));};_daa =_daa .Offset (_bcfe .X1 ,_bcfe .Y1 );_dfa :=_daa .GetBoundingBox ();DrawPathWithCreator (_daa ,_ebc );if _bcfe .LineStyle ==LineStyleDashed {_ebc .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_ebc .Add_f ().Add_Q ();};return _ebc .Bytes (),_dfa .ToPdfRectangle (),nil ;};
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_cc CubicBezierPath )Copy ()CubicBezierPath {_ff :=CubicBezierPath {};_ff .Curves =[]CubicBezierCurve {};for _ ,_dc :=range _cc .Curves {_ff .Curves =append (_ff .Curves ,_dc );};return _ff ;};
|
||||
|
||||
// Point represents a two-dimensional point.
|
||||
type Point struct{X float64 ;Y float64 ;};
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_bac BoundingBox )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_bac .X ,Lly :_bac .Y ,Urx :_bac .X +_bac .Width ,Ury :_bac .Y +_bac .Height };};
|
||||
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_bgc Rectangle )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_bgc .X ,Lly :_bgc .Y ,Urx :_bgc .X +_bgc .Width ,Ury :_bgc .Y +_bgc .Height };};
|
||||
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_aa Point )Rotate (theta float64 )Point {_bgaa :=_eb .NewPoint (_aa .X ,_aa .Y ).Rotate (theta );return NewPoint (_bgaa .X ,_bgaa .Y );};func (_fcbb Point )String ()string {return _ee .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_fcbb .X ,_fcbb .Y );};
|
||||
|
||||
// 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 *_df .ContentCreator ){for _def ,_ebd :=range path .Points {if _def ==0{creator .Add_m (_ebd .X ,_ebd .Y );}else {creator .Add_l (_ebd .X ,_ebd .Y );};};};
|
||||
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_fe :=CubicBezierPath {};_fe .Curves =[]CubicBezierCurve {};return _fe ;};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_a .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
|
||||
// LineStyle refers to how the line will be created.
|
||||
type LineStyle int ;
|
||||
|
||||
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
|
||||
func (_dcg Rectangle )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_fed :=NewPath ();_fed =_fed .AppendPoint (NewPoint (0,0));_fed =_fed .AppendPoint (NewPoint (0,_dcg .Height ));_fed =_fed .AppendPoint (NewPoint (_dcg .Width ,_dcg .Height ));_fed =_fed .AppendPoint (NewPoint (_dcg .Width ,0));_fed =_fed .AppendPoint (NewPoint (0,0));if _dcg .X !=0||_dcg .Y !=0{_fed =_fed .Offset (_dcg .X ,_dcg .Y );};_ff :=_b .NewContentCreator ();_ff .Add_q ();if _dcg .FillEnabled {_ff .Add_rg (_dcg .FillColor .R (),_dcg .FillColor .G (),_dcg .FillColor .B ());};if _dcg .BorderEnabled {_ff .Add_RG (_dcg .BorderColor .R (),_dcg .BorderColor .G (),_dcg .BorderColor .B ());_ff .Add_w (_dcg .BorderWidth );};if len (gsName )> 1{_ff .Add_gs (_e .PdfObjectName (gsName ));};DrawPathWithCreator (_fed ,_ff );_ff .Add_h ();if _dcg .FillEnabled &&_dcg .BorderEnabled {_ff .Add_B ();}else if _dcg .FillEnabled {_ff .Add_f ();}else if _dcg .BorderEnabled {_ff .Add_S ();};_ff .Add_Q ();return _ff .Bytes (),_fed .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
// GetBounds returns the bounding box of the Bezier curve.
|
||||
func (_cg CubicBezierCurve )GetBounds ()_a .PdfRectangle {_db :=_cg .P0 .X ;_dg :=_cg .P0 .X ;_b :=_cg .P0 .Y ;_ad :=_cg .P0 .Y ;for _eg :=0.0;_eg <=1.0;_eg +=0.001{Rx :=_cg .P0 .X *_e .Pow (1-_eg ,3)+_cg .P1 .X *3*_eg *_e .Pow (1-_eg ,2)+_cg .P2 .X *3*_e .Pow (_eg ,2)*(1-_eg )+_cg .P3 .X *_e .Pow (_eg ,3);Ry :=_cg .P0 .Y *_e .Pow (1-_eg ,3)+_cg .P1 .Y *3*_eg *_e .Pow (1-_eg ,2)+_cg .P2 .Y *3*_e .Pow (_eg ,2)*(1-_eg )+_cg .P3 .Y *_e .Pow (_eg ,3);if Rx < _db {_db =Rx ;};if Rx > _dg {_dg =Rx ;};if Ry < _b {_b =Ry ;};if Ry > _ad {_ad =Ry ;};};_g :=_a .PdfRectangle {};_g .Llx =_db ;_g .Lly =_b ;_g .Urx =_dg ;_g .Ury =_ad ;return _g ;};
|
||||
|
||||
// CubicBezierPath represents a collection of cubic Bezier curves.
|
||||
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
|
||||
// NewCubicBezierCurve returns a new cubic Bezier curve.
|
||||
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_c :=CubicBezierCurve {};_c .P0 =NewPoint (x0 ,y0 );_c .P1 =NewPoint (x1 ,y1 );_c .P2 =NewPoint (x2 ,y2 );_c .P3 =NewPoint (x3 ,y3 );return _c ;};
|
||||
|
||||
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
|
||||
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
// Length returns the number of points in the path.
|
||||
func (_gf Path )Length ()int {return len (_gf .Points )};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_bga Point )AddVector (v Vector )Point {_bga .X +=v .Dx ;_bga .Y +=v .Dy ;return _bga };
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_cb Vector )Flip ()Vector {_gdb :=_cb .Magnitude ();_bfb :=_cb .GetPolarAngle ();_cb .Dx =_gdb *_e .Cos (_bfb +_e .Pi );_cb .Dy =_gdb *_e .Sin (_bfb +_e .Pi );return _cb ;};
|
||||
|
||||
// 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 (_ab Circle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_cga :=_ab .Width /2;_ge :=_ab .Height /2;if _ab .BorderEnabled {_cga -=_ab .BorderWidth /2;_ge -=_ab .BorderWidth /2;};_dfg :=0.551784;_dbb :=_cga *_dfg ;_ggad :=_ge *_dfg ;_de :=NewCubicBezierPath ();_de =_de .AppendCurve (NewCubicBezierCurve (-_cga ,0,-_cga ,_ggad ,-_dbb ,_ge ,0,_ge ));_de =_de .AppendCurve (NewCubicBezierCurve (0,_ge ,_dbb ,_ge ,_cga ,_ggad ,_cga ,0));_de =_de .AppendCurve (NewCubicBezierCurve (_cga ,0,_cga ,-_ggad ,_dbb ,-_ge ,0,-_ge ));_de =_de .AppendCurve (NewCubicBezierCurve (0,-_ge ,-_dbb ,-_ge ,-_cga ,-_ggad ,-_cga ,0));_de =_de .Offset (_cga ,_ge );if _ab .BorderEnabled {_de =_de .Offset (_ab .BorderWidth /2,_ab .BorderWidth /2);};if _ab .X !=0||_ab .Y !=0{_de =_de .Offset (_ab .X ,_ab .Y );};_ead :=_df .NewContentCreator ();_ead .Add_q ();if _ab .FillEnabled {_ead .Add_rg (_ab .FillColor .R (),_ab .FillColor .G (),_ab .FillColor .B ());};if _ab .BorderEnabled {_ead .Add_RG (_ab .BorderColor .R (),_ab .BorderColor .G (),_ab .BorderColor .B ());_ead .Add_w (_ab .BorderWidth );};if len (gsName )> 1{_ead .Add_gs (_f .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_de ,_ead );_ead .Add_h ();if _ab .FillEnabled &&_ab .BorderEnabled {_ead .Add_B ();}else if _ab .FillEnabled {_ead .Add_f ();}else if _ab .BorderEnabled {_ead .Add_S ();};_ead .Add_Q ();_dee :=_de .GetBoundingBox ();if _ab .BorderEnabled {_dee .Height +=_ab .BorderWidth ;_dee .Width +=_ab .BorderWidth ;_dee .X -=_ab .BorderWidth /2;_dee .Y -=_ab .BorderWidth /2;};return _ead .Bytes (),_dee .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 (_fgf Line )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_aff ,_dff :=_fgf .X1 ,_fgf .X2 ;_ged ,_dea :=_fgf .Y1 ,_fgf .Y2 ;_cge :=_dea -_ged ;_gc :=_dff -_aff ;_eba :=_e .Atan2 (_cge ,_gc );L :=_e .Sqrt (_e .Pow (_gc ,2.0)+_e .Pow (_cge ,2.0));_fa :=_fgf .LineWidth ;_dge :=_e .Pi ;_bace :=1.0;if _gc < 0{_bace *=-1.0;};if _cge < 0{_bace *=-1.0;};VsX :=_bace *(-_fa /2*_e .Cos (_eba +_dge /2));VsY :=_bace *(-_fa /2*_e .Sin (_eba +_dge /2)+_fa *_e .Sin (_eba +_dge /2));V1X :=VsX +_fa /2*_e .Cos (_eba +_dge /2);V1Y :=VsY +_fa /2*_e .Sin (_eba +_dge /2);V2X :=VsX +_fa /2*_e .Cos (_eba +_dge /2)+L *_e .Cos (_eba );V2Y :=VsY +_fa /2*_e .Sin (_eba +_dge /2)+L *_e .Sin (_eba );V3X :=VsX +_fa /2*_e .Cos (_eba +_dge /2)+L *_e .Cos (_eba )+_fa *_e .Cos (_eba -_dge /2);V3Y :=VsY +_fa /2*_e .Sin (_eba +_dge /2)+L *_e .Sin (_eba )+_fa *_e .Sin (_eba -_dge /2);V4X :=VsX +_fa /2*_e .Cos (_eba -_dge /2);V4Y :=VsY +_fa /2*_e .Sin (_eba -_dge /2);_dbad :=NewPath ();_dbad =_dbad .AppendPoint (NewPoint (V1X ,V1Y ));_dbad =_dbad .AppendPoint (NewPoint (V2X ,V2Y ));_dbad =_dbad .AppendPoint (NewPoint (V3X ,V3Y ));_dbad =_dbad .AppendPoint (NewPoint (V4X ,V4Y ));_eeb :=_fgf .LineEndingStyle1 ;_aba :=_fgf .LineEndingStyle2 ;_gb :=3*_fa ;_deee :=3*_fa ;_ggg :=(_deee -_fa )/2;if _aba ==LineEndingStyleArrow {_ca :=_dbad .GetPointNumber (2);_adbb :=NewVectorPolar (_gb ,_eba +_dge );_caf :=_ca .AddVector (_adbb );_gfg :=NewVectorPolar (_deee /2,_eba +_dge /2);_bff :=NewVectorPolar (_gb ,_eba );_dgg :=NewVectorPolar (_ggg ,_eba +_dge /2);_fgbe :=_caf .AddVector (_dgg );_gcf :=_bff .Add (_gfg .Flip ());_afa :=_fgbe .AddVector (_gcf );_fbde :=_gfg .Scale (2).Flip ().Add (_gcf .Flip ());_fec :=_afa .AddVector (_fbde );_ccd :=_caf .AddVector (NewVectorPolar (_fa ,_eba -_dge /2));_cfb :=NewPath ();_cfb =_cfb .AppendPoint (_dbad .GetPointNumber (1));_cfb =_cfb .AppendPoint (_caf );_cfb =_cfb .AppendPoint (_fgbe );_cfb =_cfb .AppendPoint (_afa );_cfb =_cfb .AppendPoint (_fec );_cfb =_cfb .AppendPoint (_ccd );_cfb =_cfb .AppendPoint (_dbad .GetPointNumber (4));_dbad =_cfb ;};if _eeb ==LineEndingStyleArrow {_cab :=_dbad .GetPointNumber (1);_bab :=_dbad .GetPointNumber (_dbad .Length ());_bba :=NewVectorPolar (_fa /2,_eba +_dge +_dge /2);_cfc :=_cab .AddVector (_bba );_fd :=NewVectorPolar (_gb ,_eba ).Add (NewVectorPolar (_deee /2,_eba +_dge /2));_ddd :=_cfc .AddVector (_fd );_faf :=NewVectorPolar (_ggg ,_eba -_dge /2);_dae :=_ddd .AddVector (_faf );_edc :=NewVectorPolar (_gb ,_eba );_ace :=_bab .AddVector (_edc );_fcg :=NewVectorPolar (_ggg ,_eba +_dge +_dge /2);_gbe :=_ace .AddVector (_fcg );_gba :=_cfc ;_aca :=NewPath ();_aca =_aca .AppendPoint (_cfc );_aca =_aca .AppendPoint (_ddd );_aca =_aca .AppendPoint (_dae );for _ ,_gd :=range _dbad .Points [1:len (_dbad .Points )-1]{_aca =_aca .AppendPoint (_gd );};_aca =_aca .AppendPoint (_ace );_aca =_aca .AppendPoint (_gbe );_aca =_aca .AppendPoint (_gba );_dbad =_aca ;};_fcbg :=_df .NewContentCreator ();_fcbg .Add_q ().Add_rg (_fgf .LineColor .R (),_fgf .LineColor .G (),_fgf .LineColor .B ());if len (gsName )> 1{_fcbg .Add_gs (_f .PdfObjectName (gsName ));};_dbad =_dbad .Offset (_fgf .X1 ,_fgf .Y1 );_fggb :=_dbad .GetBoundingBox ();DrawPathWithCreator (_dbad ,_fcbg );if _fgf .LineStyle ==LineStyleDashed {_fcbg .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_fcbg .Add_f ().Add_Q ();};return _fcbg .Bytes (),_fggb .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
||||
func (_gga Point )Add (dx ,dy float64 )Point {_gga .X +=dx ;_gga .Y +=dy ;return _gga };
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_aeb Vector )Rotate (phi float64 )Vector {_gbg :=_aeb .Magnitude ();_dfd :=_aeb .GetPolarAngle ();return NewVectorPolar (_gbg ,_dfd +phi );};
|
||||
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_fece Vector )FlipY ()Vector {_fece .Dy =-_fece .Dy ;return _fece };
|
||||
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_ae Path )GetPointNumber (number int )Point {if number < 1||number > len (_ae .Points ){return Point {};};return _ae .Points [number -1];};
|
||||
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_deg :=Vector {};_deg .Dx =length *_e .Cos (theta );_deg .Dy =length *_e .Sin (theta );return _deg ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_bc Path )AppendPoint (point Point )Path {_bc .Points =append (_bc .Points ,point );return _bc };
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_baa :=Vector {};_baa .Dx =dx ;_baa .Dy =dy ;return _baa };const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
|
||||
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
|
||||
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_ddf Vector )Add (other Vector )Vector {_ddf .Dx +=other .Dx ;_ddf .Dy +=other .Dy ;return _ddf };
|
||||
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_ac CubicBezierPath )GetBoundingBox ()Rectangle {_af :=Rectangle {};_ffa :=0.0;_ce :=0.0;_bb :=0.0;_bd :=0.0;for _dca ,_dba :=range _ac .Curves {_ba :=_dba .GetBounds ();if _dca ==0{_ffa =_ba .Llx ;_ce =_ba .Urx ;_bb =_ba .Lly ;_bd =_ba .Ury ;continue ;};if _ba .Llx < _ffa {_ffa =_ba .Llx ;};if _ba .Urx > _ce {_ce =_ba .Urx ;};if _ba .Lly < _bb {_bb =_ba .Lly ;};if _ba .Ury > _bd {_bd =_ba .Ury ;};};_af .X =_ffa ;_af .Y =_bb ;_af .Width =_ce -_ffa ;_af .Height =_bd -_bb ;return _af ;};
|
||||
|
||||
// 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 (_gea Polyline )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _gea .LineColor ==nil {_gea .LineColor =_a .NewPdfColorDeviceRGB (0,0,0);};_eac :=NewPath ();for _ ,_bbg :=range _gea .Points {_eac =_eac .AppendPoint (_bbg );};_gec :=_df .NewContentCreator ();_gec .Add_q ();_gec .Add_RG (_gea .LineColor .R (),_gea .LineColor .G (),_gea .LineColor .B ());_gec .Add_w (_gea .LineWidth );if len (gsName )> 1{_gec .Add_gs (_f .PdfObjectName (gsName ));};DrawPathWithCreator (_eac ,_gec );_gec .Add_S ();_gec .Add_Q ();return _gec .Bytes (),_eac .GetBoundingBox ().ToPdfRectangle (),nil ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
|
||||
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
|
||||
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
|
||||
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
|
||||
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_a .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
|
||||
// AddOffsetXY adds X,Y offset to all points on a curve.
|
||||
func (_fg CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_fg .P0 .X +=offX ;_fg .P1 .X +=offX ;_fg .P2 .X +=offX ;_fg .P3 .X +=offX ;_fg .P0 .Y +=offY ;_fg .P1 .Y +=offY ;_fg .P2 .Y +=offY ;_fg .P3 .Y +=offY ;return _fg ;};
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_bgb Vector )Scale (factor float64 )Vector {_bbge :=_bgb .Magnitude ();_ecc :=_bgb .GetPolarAngle ();_bgb .Dx =factor *_bbge *_e .Cos (_ecc );_bgb .Dy =factor *_bbge *_e .Sin (_ecc );return _bgb ;};
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_ag CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ag .Curves =append (_ag .Curves ,curve );return _ag ;};
|
||||
|
||||
// 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 (_fgb Rectangle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_bgf :=NewPath ();_bgf =_bgf .AppendPoint (NewPoint (0,0));_bgf =_bgf .AppendPoint (NewPoint (0,_fgb .Height ));_bgf =_bgf .AppendPoint (NewPoint (_fgb .Width ,_fgb .Height ));_bgf =_bgf .AppendPoint (NewPoint (_fgb .Width ,0));_bgf =_bgf .AppendPoint (NewPoint (0,0));if _fgb .X !=0||_fgb .Y !=0{_bgf =_bgf .Offset (_fgb .X ,_fgb .Y );};_feg :=_df .NewContentCreator ();_feg .Add_q ();if _fgb .FillEnabled {_feg .Add_rg (_fgb .FillColor .R (),_fgb .FillColor .G (),_fgb .FillColor .B ());};if _fgb .BorderEnabled {_feg .Add_RG (_fgb .BorderColor .R (),_fgb .BorderColor .G (),_fgb .BorderColor .B ());_feg .Add_w (_fgb .BorderWidth );};if len (gsName )> 1{_feg .Add_gs (_f .PdfObjectName (gsName ));};DrawPathWithCreator (_bgf ,_feg );_feg .Add_h ();if _fgb .FillEnabled &&_fgb .BorderEnabled {_feg .Add_B ();}else if _fgb .FillEnabled {_feg .Add_f ();}else if _fgb .BorderEnabled {_feg .Add_S ();};_feg .Add_Q ();return _feg .Bytes (),_bgf .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
|
||||
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// 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 (_ef BasicLine )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_fgc :=_ef .LineWidth ;_baf :=NewPath ();_baf =_baf .AppendPoint (NewPoint (_ef .X1 ,_ef .Y1 ));_baf =_baf .AppendPoint (NewPoint (_ef .X2 ,_ef .Y2 ));_ebac :=_df .NewContentCreator ();_fgd :=_baf .GetBoundingBox ();DrawPathWithCreator (_baf ,_ebac );if _ef .LineStyle ==LineStyleDashed {_ebac .Add_d ([]int64 {1,1},0);};_ebac .Add_RG (_ef .LineColor .R (),_ef .LineColor .G (),_ef .LineColor .B ()).Add_w (_fgc ).Add_S ().Add_Q ();return _ebac .Bytes (),_fgd .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_acac Vector )Magnitude ()float64 {return _e .Sqrt (_e .Pow (_acac .Dx ,2.0)+_e .Pow (_acac .Dy ,2.0));};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_fb Path )GetBoundingBox ()BoundingBox {_ecf :=BoundingBox {};_eed :=0.0;_cf :=0.0;_fgg :=0.0;_bg :=0.0;for _cd ,_ea :=range _fb .Points {if _cd ==0{_eed =_ea .X ;_cf =_ea .X ;_fgg =_ea .Y ;_bg =_ea .Y ;continue ;};if _ea .X < _eed {_eed =_ea .X ;};if _ea .X > _cf {_cf =_ea .X ;};if _ea .Y < _fgg {_fgg =_ea .Y ;};if _ea .Y > _bg {_bg =_ea .Y ;};};_ecf .X =_eed ;_ecf .Y =_fgg ;_ecf .Width =_cf -_eed ;_ecf .Height =_bg -_fgg ;return _ecf ;};
|
||||
|
||||
// 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 {_fgcc :=Vector {};_fgcc .Dx =b .X -a .X ;_fgcc .Dy =b .Y -a .Y ;return _fgcc ;};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
|
||||
// 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 *_df .ContentCreator ){for _gfd ,_gfc :=range bpath .Curves {if _gfd ==0{creator .Add_m (_gfc .P0 .X ,_gfc .P0 .Y );};creator .Add_c (_gfc .P1 .X ,_gfc .P1 .Y ,_gfc .P2 .X ,_gfc .P2 .Y ,_gfc .P3 .X ,_gfc .P3 .Y );};};
|
||||
|
||||
// Copy returns a clone of the path.
|
||||
func (_ccg Path )Copy ()Path {_gg :=Path {};_gg .Points =[]Point {};for _ ,_bcf :=range _ccg .Points {_gg .Points =append (_gg .Points ,_bcf );};return _gg ;};
|
||||
|
||||
// BoundingBox represents the smallest rectangular area that encapsulates an object.
|
||||
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
|
||||
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_bf Path )Offset (offX ,offY float64 )Path {for _fga ,_bde :=range _bf .Points {_bf .Points [_fga ]=_bde .Add (offX ,offY );};return _bf ;};
|
||||
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_dcg Vector )FlipX ()Vector {_dcg .Dx =-_dcg .Dx ;return _dcg };
|
||||
|
||||
// Offset shifts the Bezier path with the specified offsets.
|
||||
func (_bg CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _dad ,_cg :=range _bg .Curves {_bg .Curves [_dad ]=_cg .AddOffsetXY (offX ,offY );};return _bg ;};
|
||||
func (_ec CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _da ,_fc :=range _ec .Curves {_ec .Curves [_da ]=_fc .AddOffsetXY (offX ,offY );};return _ec ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
|
||||
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
|
||||
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
|
||||
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_fe .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_fe .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// GetBounds returns the bounding box of the Bezier curve.
|
||||
func (_d CubicBezierCurve )GetBounds ()_fe .PdfRectangle {_ggc :=_d .P0 .X ;_ae :=_d .P0 .X ;_ad :=_d .P0 .Y ;_eb :=_d .P0 .Y ;for _c :=0.0;_c <=1.0;_c +=0.001{Rx :=_d .P0 .X *_g .Pow (1-_c ,3)+_d .P1 .X *3*_c *_g .Pow (1-_c ,2)+_d .P2 .X *3*_g .Pow (_c ,2)*(1-_c )+_d .P3 .X *_g .Pow (_c ,3);Ry :=_d .P0 .Y *_g .Pow (1-_c ,3)+_d .P1 .Y *3*_c *_g .Pow (1-_c ,2)+_d .P2 .Y *3*_g .Pow (_c ,2)*(1-_c )+_d .P3 .Y *_g .Pow (_c ,3);if Rx < _ggc {_ggc =Rx ;};if Rx > _ae {_ae =Rx ;};if Ry < _ad {_ad =Ry ;};if Ry > _eb {_eb =Ry ;};};_ef :=_fe .PdfRectangle {};_ef .Llx =_ggc ;_ef .Lly =_ad ;_ef .Urx =_ae ;_ef .Ury =_eb ;return _ef ;};
|
||||
|
||||
// Draw draws the composite Bezier curve. A graphics state name can be
|
||||
// specified for setting the curve properties (e.g. setting the opacity).
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array and
|
||||
// the curve bounding box.
|
||||
func (_ge PolyBezierCurve )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){if _ge .BorderColor ==nil {_ge .BorderColor =_fe .NewPdfColorDeviceRGB (0,0,0);};_feb :=NewCubicBezierPath ();for _ ,_cc :=range _ge .Curves {_feb =_feb .AppendCurve (_cc );};_age :=_b .NewContentCreator ();_age .Add_q ();_ge .FillEnabled =_ge .FillEnabled &&_ge .FillColor !=nil ;if _ge .FillEnabled {_age .Add_rg (_ge .FillColor .R (),_ge .FillColor .G (),_ge .FillColor .B ());};_age .Add_RG (_ge .BorderColor .R (),_ge .BorderColor .G (),_ge .BorderColor .B ());_age .Add_w (_ge .BorderWidth );if len (gsName )> 1{_age .Add_gs (_e .PdfObjectName (gsName ));};for _ ,_ccf :=range _feb .Curves {_age .Add_m (_ccf .P0 .X ,_ccf .P0 .Y );_age .Add_c (_ccf .P1 .X ,_ccf .P1 .Y ,_ccf .P2 .X ,_ccf .P2 .Y ,_ccf .P3 .X ,_ccf .P3 .Y );};if _ge .FillEnabled {_age .Add_h ();_age .Add_B ();}else {_age .Add_S ();};_age .Add_Q ();return _age .Bytes (),_feb .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
func (_bda PolyBezierCurve )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _bda .BorderColor ==nil {_bda .BorderColor =_a .NewPdfColorDeviceRGB (0,0,0);};_aea :=NewCubicBezierPath ();for _ ,_bcb :=range _bda .Curves {_aea =_aea .AppendCurve (_bcb );};_dd :=_df .NewContentCreator ();_dd .Add_q ();_bda .FillEnabled =_bda .FillEnabled &&_bda .FillColor !=nil ;if _bda .FillEnabled {_dd .Add_rg (_bda .FillColor .R (),_bda .FillColor .G (),_bda .FillColor .B ());};_dd .Add_RG (_bda .BorderColor .R (),_bda .BorderColor .G (),_bda .BorderColor .B ());_dd .Add_w (_bda .BorderWidth );if len (gsName )> 1{_dd .Add_gs (_f .PdfObjectName (gsName ));};for _ ,_fce :=range _aea .Curves {_dd .Add_m (_fce .P0 .X ,_fce .P0 .Y );_dd .Add_c (_fce .P1 .X ,_fce .P1 .Y ,_fce .P2 .X ,_fce .P2 .Y ,_fce .P3 .X ,_fce .P3 .Y );};if _bda .FillEnabled {_dd .Add_h ();_dd .Add_B ();}else {_dd .Add_S ();};_dd .Add_Q ();return _dd .Bytes (),_aea .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_fe .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
|
||||
// or arrows at either end. The line also has a specified width, color and opacity.
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// NewVectorBetween returns a new vector with the direction specified by
|
||||
// the subtraction of point a from point b (b-a).
|
||||
func NewVectorBetween (a Point ,b Point )Vector {_bbc :=Vector {};_bbc .Dx =b .X -a .X ;_bbc .Dy =b .Y -a .Y ;return _bbc ;};
|
||||
// CubicBezierPath represents a collection of cubic Bezier curves.
|
||||
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_cce :=Vector {};_cce .Dx =dx ;_cce .Dy =dy ;return _cce };
|
||||
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_be Path )GetPointNumber (number int )Point {if number < 1||number > len (_be .Points ){return Point {};};return _be .Points [number -1];};
|
||||
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_ab Vector )Add (other Vector )Vector {_ab .Dx +=other .Dx ;_ab .Dy +=other .Dy ;return _ab };
|
||||
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_fa Point )Rotate (theta float64 )Point {_agg :=_ee .NewPoint (_fa .X ,_fa .Y ).Rotate (theta );return NewPoint (_agg .X ,_agg .Y );};
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
|
||||
// AddOffsetXY adds X,Y offset to all points on a curve.
|
||||
func (_gg CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_gg .P0 .X +=offX ;_gg .P1 .X +=offX ;_gg .P2 .X +=offX ;_gg .P3 .X +=offX ;_gg .P0 .Y +=offY ;_gg .P1 .Y +=offY ;_gg .P2 .Y +=offY ;_gg .P3 .Y +=offY ;return _gg ;};
|
||||
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_cfd Path )RemovePoint (number int )Path {if number < 1||number > len (_cfd .Points ){return _cfd ;};_add :=number -1;_cfd .Points =append (_cfd .Points [:_add ],_cfd .Points [_add +1:]...);return _cfd ;};
|
||||
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_cbd Path )AppendPoint (point Point )Path {_cbd .Points =append (_cbd .Points ,point );return _cbd };
|
||||
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_eeb :=Vector {};_eeb .Dx =length *_g .Cos (theta );_eeb .Dy =length *_g .Sin (theta );return _eeb ;};
|
||||
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_cgc Vector )FlipX ()Vector {_cgc .Dx =-_cgc .Dx ;return _cgc };
|
||||
|
||||
// Draw draws the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
|
||||
// Returns the content stream as a byte array, the bounding box and an error on failure.
|
||||
func (_ecd Circle )Draw (gsName string )([]byte ,*_fe .PdfRectangle ,error ){_bcf :=_ecd .Width /2;_gfg :=_ecd .Height /2;if _ecd .BorderEnabled {_bcf -=_ecd .BorderWidth /2;_gfg -=_ecd .BorderWidth /2;};_agb :=0.551784;_fce :=_bcf *_agb ;_fd :=_gfg *_agb ;_ggca :=NewCubicBezierPath ();_ggca =_ggca .AppendCurve (NewCubicBezierCurve (-_bcf ,0,-_bcf ,_fd ,-_fce ,_gfg ,0,_gfg ));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (0,_gfg ,_fce ,_gfg ,_bcf ,_fd ,_bcf ,0));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (_bcf ,0,_bcf ,-_fd ,_fce ,-_gfg ,0,-_gfg ));_ggca =_ggca .AppendCurve (NewCubicBezierCurve (0,-_gfg ,-_fce ,-_gfg ,-_bcf ,-_fd ,-_bcf ,0));_ggca =_ggca .Offset (_bcf ,_gfg );if _ecd .BorderEnabled {_ggca =_ggca .Offset (_ecd .BorderWidth /2,_ecd .BorderWidth /2);};if _ecd .X !=0||_ecd .Y !=0{_ggca =_ggca .Offset (_ecd .X ,_ecd .Y );};_dbg :=_b .NewContentCreator ();_dbg .Add_q ();if _ecd .FillEnabled {_dbg .Add_rg (_ecd .FillColor .R (),_ecd .FillColor .G (),_ecd .FillColor .B ());};if _ecd .BorderEnabled {_dbg .Add_RG (_ecd .BorderColor .R (),_ecd .BorderColor .G (),_ecd .BorderColor .B ());_dbg .Add_w (_ecd .BorderWidth );};if len (gsName )> 1{_dbg .Add_gs (_e .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_ggca ,_dbg );_dbg .Add_h ();if _ecd .FillEnabled &&_ecd .BorderEnabled {_dbg .Add_B ();}else if _ecd .FillEnabled {_dbg .Add_f ();}else if _ecd .BorderEnabled {_dbg .Add_S ();};_dbg .Add_Q ();_eg :=_ggca .GetBoundingBox ();if _ecd .BorderEnabled {_eg .Height +=_ecd .BorderWidth ;_eg .Width +=_ecd .BorderWidth ;_eg .X -=_ecd .BorderWidth /2;_eg .Y -=_ecd .BorderWidth /2;};return _dbg .Bytes (),_eg .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_gf Path )Offset (offX ,offY float64 )Path {for _df ,_ed :=range _gf .Points {_gf .Points [_df ]=_ed .Add (offX ,offY );};return _gf ;};
|
||||
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_gfa Rectangle )ToPdfRectangle ()*_fe .PdfRectangle {return &_fe .PdfRectangle {Llx :_gfa .X ,Lly :_gfa .Y ,Urx :_gfa .X +_gfa .Width ,Ury :_gfa .Y +_gfa .Height };};
|
||||
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_faf Vector )GetPolarAngle ()float64 {return _g .Atan2 (_faf .Dy ,_faf .Dx )};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_dac Point )AddVector (v Vector )Point {_dac .X +=v .Dx ;_dac .Y +=v .Dy ;return _dac };
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
1888
core/core.go
1888
core/core.go
File diff suppressed because one or more lines are too long
@ -9,49 +9,61 @@
|
||||
// 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 (_a "crypto/aes";_c "crypto/cipher";_d "crypto/md5";_e "crypto/rand";_aa "crypto/rc4";_g "fmt";_ee "github.com/unidoc/unipdf/v3/common";_ag "github.com/unidoc/unipdf/v3/core/security";_bc "io";);func init (){_bda ("\u0041\u0045\u0053V\u0032",_ad )};var _ Filter =filterV2 {};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
|
||||
package crypt ;import (_gd "crypto/aes";_b "crypto/cipher";_f "crypto/md5";_ac "crypto/rand";_e "crypto/rc4";_gc "fmt";_fb "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/core/security";_a "io";);func init (){_dce ("\u0041\u0045\u0053V\u0032",_c )};
|
||||
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _ag .AuthEvent ;Length int ;};func (filterIdentity )KeyLength ()int {return 0};func _ad (_af FilterDict )(Filter ,error ){if _af .Length ==128{_ee .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_af .Length );_af .Length /=8;};if _af .Length !=0&&_af .Length !=16{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_af .Length );};return filterAESV2 {},nil ;};func _ade (_gd FilterDict )(Filter ,error ){if _gd .Length ==256{_ee .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_gd .Length );_gd .Length /=8;};if _gd .Length !=0&&_gd .Length !=32{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_gd .Length );};return filterAESV3 {},nil ;};var (_gba =make (map[string ]filterFunc ););
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_fg ,_bfa :=_fec (FilterDict {Length :length });if _bfa !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_bfa );return filterV2 {_bb :length };};return _fg ;};
|
||||
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_da ,_ab :=_ad (FilterDict {});if _ab !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ab );return filterAESV2 {};};return _da ;};
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};
|
||||
|
||||
// NewIdentity creates an identity filter that bypasses all data without changes.
|
||||
func NewIdentity ()Filter {return filterIdentity {}};func init (){_bda ("\u0041\u0045\u0053V\u0033",_ade )};type filterAES struct{};
|
||||
func NewIdentity ()Filter {return filterIdentity {}};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func _fgf (_cba string )(filterFunc ,error ){_ccd :=_gba [string (_cba )];if _ccd ==nil {return nil ,_g .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_cba );};return _ccd ,nil ;};
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (_ead filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};
|
||||
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_ad ,_d :=_ec (FilterDict {});if _d !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_d );return filterAESV3 {};};return _ad ;};
|
||||
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_cfg ,_acd :=_fff (d .CFM );if _acd !=nil {return nil ,_acd ;};_dcg ,_acd :=_cfg (d );if _acd !=nil {return nil ,_acd ;};return _dcg ,nil ;};type filterAESV2 struct{filterAES };func (filterIdentity )KeyLength ()int {return 0};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};var _ Filter =filterAESV2 {};
|
||||
func (_gdc filterV2 )KeyLength ()int {return _gdc ._bb };func init (){_dce ("\u0041\u0045\u0053V\u0033",_ec )};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (_cfb filterV2 )KeyLength ()int {return _cfb ._fec };
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_gcb ,_gdf :=_c (FilterDict {});if _gdf !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_gdf );return filterAESV2 {};};return _gcb ;};func _fff (_ca string )(filterFunc ,error ){_bg :=_ada [string (_ca )];if _bg ==nil {return nil ,_gc .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_ca );};return _bg ,nil ;};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (_gaf filterV2 )PDFVersion ()[2]int {return [2]int {}};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};type filterFunc func (_cee FilterDict )(Filter ,error );type filterAESV3 struct{filterAES };
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gfg (objNum ,genNum ,ekey ,true );};
|
||||
// DecryptBytes implements Filter interface.
|
||||
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_dda ,_bdfa :=_e .NewCipher (okey );if _bdfa !=nil {return nil ,_bdfa ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_dda .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func _fec (_eac FilterDict )(Filter ,error ){if _eac .Length %8!=0{return nil ,_gc .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",_eac .Length );};if _eac .Length < 5||_eac .Length > 16{if _eac .Length ==40||_eac .Length ==64||_eac .Length ==128{_fb .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_eac .Length );_eac .Length /=8;}else {return nil ,_gc .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",_eac .Length );};};return filterV2 {_bb :_eac .Length },nil ;};func init (){_dce ("\u0056\u0032",_fec )};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
|
||||
|
||||
// DecryptBytes implements Filter interface.
|
||||
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_dc ,_cdc :=_aa .NewCipher (okey );if _cdc !=nil {return nil ,_cdc ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_dc .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ea ,_gf :=_a .NewCipher (okey );if _gf !=nil {return nil ,_gf ;};if len (buf )< 16{_ee .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_bg :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ee .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_bg ),_bg );_ee .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_bf :=_c .NewCBCDecrypter (_ea ,_bg );_ee .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ee .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_bf .CryptBlocks (buf ,buf );_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ee .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_ege :=int (buf [len (buf )-1]);if _ege > len (buf ){_ee .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_ege ,len (buf ));return buf ,_g .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ege ];return buf ,nil ;};type filterAESV2 struct{filterAES };func init (){_bda ("\u0056\u0032",_cg )};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ddf ,_gcg :=_e .NewCipher (okey );if _gcg !=nil {return nil ,_gcg ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ddf .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _ed .AuthEvent ;Length int ;};type filterAES struct{};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (_eff filterV2 )PDFVersion ()[2]int {return [2]int {}};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ff ,_afb :=_a .NewCipher (okey );if _afb !=nil {return nil ,_afb ;};_ee .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _eg =_a .BlockSize ;_ef :=_eg -len (buf )%_eg ;for _bcg :=0;_bcg < _ef ;_bcg ++{buf =append (buf ,byte (_ef ));};_ee .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_adf :=make ([]byte ,_eg +len (buf ));_cd :=_adf [:_eg ];if _ ,_gc :=_bc .ReadFull (_e .Reader ,_cd );_gc !=nil {return nil ,_gc ;};_fg :=_c .NewCBCEncrypter (_ff ,_cd );_fg .CryptBlocks (_adf [_eg :],buf );buf =_adf ;_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (_ffc filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _gfg (objNum ,genNum ,ekey ,false );};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};var _ Filter =filterV2 {};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterV2 )Name ()string {return "\u0056\u0032"};
|
||||
@ -73,36 +85,24 @@ 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 (_eee ,_gfgc uint32 ,_gcf []byte )([]byte ,error );
|
||||
MakeKey (_efc ,_be uint32 ,_ae []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 (_gga []byte ,_ga []byte )([]byte ,error );
|
||||
EncryptBytes (_aee []byte ,_ba []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 (_ffd []byte ,_eb []byte )([]byte ,error );};var _ Filter =filterAESV3 {};
|
||||
DecryptBytes (_eaa []byte ,_bae []byte )([]byte ,error );};type filterV2 struct{_bb int };func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_eb ,_ea :=_gd .NewCipher (okey );if _ea !=nil {return nil ,_ea ;};if len (buf )< 16{_fb .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_gc .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_dac :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_fb .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_dac ),_dac );_fb .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_gc .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 ));};_fc :=_b .NewCBCDecrypter (_eb ,_dac );_fb .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_fb .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_fc .CryptBlocks (buf ,buf );_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_fb .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_bd :=int (buf [len (buf )-1]);if _bd > len (buf ){_fb .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_bd ,len (buf ));return buf ,_gc .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_bd ];return buf ,nil ;};type filterIdentity struct{};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};var _ Filter =filterAESV2 {};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (_cga filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };type filterFunc func (_fcf FilterDict )(Filter ,error );type filterV2 struct{_fec int };
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};var _ Filter =filterAESV3 {};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ceg (objNum ,genNum ,ekey ,true );};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (_faa filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ceg (objNum ,genNum ,ekey ,false );};func _c (_bc FilterDict )(Filter ,error ){if _bc .Length ==128{_fb .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_bc .Length );_bc .Length /=8;};if _bc .Length !=0&&_bc .Length !=16{return nil ,_gc .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",_bc .Length );};return filterAESV2 {},nil ;};var (_ada =make (map[string ]filterFunc ););
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV3 )KeyLength ()int {return 256/8};
|
||||
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_adg ,_ge :=_ade (FilterDict {});if _ge !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ge );return filterAESV3 {};};return _adg ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func _bda (_gff string ,_efb filterFunc ){if _ ,_bfc :=_gba [_gff ];_bfc {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_gba [_gff ]=_efb ;};
|
||||
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_cge ,_cbd :=_fgf (d .CFM );if _cbd !=nil {return nil ,_cbd ;};_gbf ,_cbd :=_cge (d );if _cbd !=nil {return nil ,_cbd ;};return _gbf ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _gfg (_db ,_fff uint32 ,_gfge []byte ,_cb bool )([]byte ,error ){_bcb :=make ([]byte ,len (_gfge )+5);for _de :=0;_de < len (_gfge );_de ++{_bcb [_de ]=_gfge [_de ];};for _cf :=0;_cf < 3;_cf ++{_cda :=byte ((_db >>uint32 (8*_cf ))&0xff);_bcb [_cf +len (_gfge )]=_cda ;};for _fe :=0;_fe < 2;_fe ++{_bb :=byte ((_fff >>uint32 (8*_fe ))&0xff);_bcb [_fe +len (_gfge )+3]=_bb ;};if _cb {_bcb =append (_bcb ,0x73);_bcb =append (_bcb ,0x41);_bcb =append (_bcb ,0x6C);_bcb =append (_bcb ,0x54);};_ead :=_d .New ();_ead .Write (_bcb );_fcc :=_ead .Sum (nil );if len (_gfge )+5< 16{return _fcc [0:len (_gfge )+5],nil ;};return _fcc ,nil ;};type filterIdentity struct{};
|
||||
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gb ,_aaa :=_aa .NewCipher (okey );if _aaa !=nil {return nil ,_aaa ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_gb .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};type filterAESV3 struct{filterAES };func _cg (_be FilterDict )(Filter ,error ){if _be .Length %8!=0{return nil ,_g .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_be .Length );};if _be .Length < 5||_be .Length > 16{if _be .Length ==40||_be .Length ==64||_be .Length ==128{_ee .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_be .Length );_be .Length /=8;}else {return nil ,_g .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_be .Length );};};return filterV2 {_fec :_be .Length },nil ;};
|
||||
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_bde ,_cde :=_cg (FilterDict {Length :length });if _cde !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_cde );return filterV2 {_fec :length };};return _bde ;};
|
||||
func (filterAESV3 )KeyLength ()int {return 256/8};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _ceg (_cef ,_dc uint32 ,_fgb []byte ,_fcc bool )([]byte ,error ){_ee :=make ([]byte ,len (_fgb )+5);for _bcf :=0;_bcf < len (_fgb );_bcf ++{_ee [_bcf ]=_fgb [_bcf ];};for _ef :=0;_ef < 3;_ef ++{_gg :=byte ((_cef >>uint32 (8*_ef ))&0xff);_ee [_ef +len (_fgb )]=_gg ;};for _bdf :=0;_bdf < 2;_bdf ++{_fcd :=byte ((_dc >>uint32 (8*_bdf ))&0xff);_ee [_bdf +len (_fgb )+3]=_fcd ;};if _fcc {_ee =append (_ee ,0x73);_ee =append (_ee ,0x41);_ee =append (_ee ,0x6C);_ee =append (_ee ,0x54);};_eab :=_f .New ();_eab .Write (_ee );_efe :=_eab .Sum (nil );if len (_fgb )+5< 16{return _efe [0:len (_fgb )+5],nil ;};return _efe ,nil ;};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gce ,_bf :=_gd .NewCipher (okey );if _bf !=nil {return nil ,_bf ;};_fb .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _cf =_gd .BlockSize ;_fe :=_cf -len (buf )%_cf ;for _ff :=0;_ff < _fe ;_ff ++{buf =append (buf ,byte (_fe ));};_fb .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_edd :=make ([]byte ,_cf +len (buf ));_ccd :=_edd [:_cf ];if _ ,_fef :=_a .ReadFull (_ac .Reader ,_ccd );_fef !=nil {return nil ,_fef ;};_da :=_b .NewCBCEncrypter (_gce ,_ccd );_da .CryptBlocks (_edd [_cf :],buf );buf =_edd ;_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};func _ec (_cc FilterDict )(Filter ,error ){if _cc .Length ==256{_fb .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_cc .Length );_cc .Length /=8;};if _cc .Length !=0&&_cc .Length !=32{return nil ,_gc .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",_cc .Length );};return filterAESV3 {},nil ;};func _dce (_ag string ,_cfa filterFunc ){if _ ,_dae :=_ada [_ag ];_dae {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_ada [_ag ]=_cfa ;};
|
File diff suppressed because one or more lines are too long
2350
creator/creator.go
2350
creator/creator.go
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
26
fdf/fdf.go
26
fdf/fdf.go
File diff suppressed because one or more lines are too long
@ -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 (_e "encoding/json";_fe "github.com/unidoc/unipdf/v3/core";_fb "github.com/unidoc/unipdf/v3/model";_f "io";_aa "os";);type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
package fjson ;import (_b "encoding/json";_c "github.com/unidoc/unipdf/v3/core";_ef "github.com/unidoc/unipdf/v3/model";_e "io";_bc "os";);type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
||||
|
||||
// LoadFromJSON loads JSON form data from `r`.
|
||||
func LoadFromJSON (r _f .Reader )(*FieldData ,error ){var _d FieldData ;_ea :=_e .NewDecoder (r ).Decode (&_d ._c );if _ea !=nil {return nil ,_ea ;};return &_d ,nil ;};
|
||||
|
||||
// FieldData represents form field data loaded from JSON file.
|
||||
type FieldData struct{_c []fieldValue };
|
||||
|
||||
// LoadFromJSONFile loads form field data from a JSON file.
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_df ,_cb :=_aa .Open (filePath );if _cb !=nil {return nil ,_cb ;};defer _df .Close ();return LoadFromJSON (_df );};
|
||||
|
||||
// FieldValues implements model.FieldValueProvider interface.
|
||||
func (_ee *FieldData )FieldValues ()(map[string ]_fe .PdfObject ,error ){_ae :=make (map[string ]_fe .PdfObject );for _ ,_dd :=range _ee ._c {if len (_dd .Value )> 0{_ae [_dd .Name ]=_fe .MakeString (_dd .Value );};};return _ae ,nil ;};
|
||||
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_ag ,_acc :=_aa .Open (filePath );if _acc !=nil {return nil ,_acc ;};defer _ag .Close ();return LoadFromPDF (_ag );};
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _f .ReadSeeker )(*FieldData ,error ){_dfd ,_cf :=_fb .NewPdfReader (rs );if _cf !=nil {return nil ,_cf ;};if _dfd .AcroForm ==nil {return nil ,nil ;};var _g []fieldValue ;_b :=_dfd .AcroForm .AllFields ();for _ ,_be :=range _b {var _fd []string ;_cd :=make (map[string ]struct{});_de ,_gb :=_be .FullName ();if _gb !=nil {return nil ,_gb ;};if _cdf ,_gd :=_be .V .(*_fe .PdfObjectString );_gd {_g =append (_g ,fieldValue {Name :_de ,Value :_cdf .Decoded ()});continue ;};var _ec string ;for _ ,_cff :=range _be .Annotations {_cbf ,_gc :=_fe .GetName (_cff .AS );if _gc {_ec =_cbf .String ();};_ecb ,_ac :=_fe .GetDict (_cff .AP );if !_ac {continue ;};_cc ,_ :=_fe .GetDict (_ecb .Get ("\u004e"));for _ ,_cbg :=range _cc .Keys (){_fef :=_cbg .String ();if _ ,_ccb :=_cd [_fef ];!_ccb {_fd =append (_fd ,_fef );_cd [_fef ]=struct{}{};};};_bb ,_ :=_fe .GetDict (_ecb .Get ("\u0044"));for _ ,_fde :=range _bb .Keys (){_gdf :=_fde .String ();if _ ,_ff :=_cd [_gdf ];!_ff {_fd =append (_fd ,_gdf );_cd [_gdf ]=struct{}{};};};};_bd :=fieldValue {Name :_de ,Value :_ec ,Options :_fd };_g =append (_g ,_bd );};_aae :=FieldData {_c :_g };return &_aae ,nil ;};
|
||||
func LoadFromJSON (r _e .Reader )(*FieldData ,error ){var _dc FieldData ;_be :=_b .NewDecoder (r ).Decode (&_dc ._a );if _be !=nil {return nil ,_be ;};return &_dc ,nil ;};
|
||||
|
||||
// JSON returns the field data as a string in JSON format.
|
||||
func (_ecc FieldData )JSON ()(string ,error ){_eae ,_def :=_e .MarshalIndent (_ecc ._c ,"","\u0020\u0020\u0020\u0020");return string (_eae ),_def ;};
|
||||
func (_fed FieldData )JSON ()(string ,error ){_cb ,_ece :=_b .MarshalIndent (_fed ._a ,"","\u0020\u0020\u0020\u0020");return string (_cb ),_ece ;};
|
||||
|
||||
// LoadFromJSONFile loads form field data from a JSON file.
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_f ,_g :=_bc .Open (filePath );if _g !=nil {return nil ,_g ;};defer _f .Close ();return LoadFromJSON (_f );};
|
||||
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_cgg ,_aag :=_bc .Open (filePath );if _aag !=nil {return nil ,_aag ;};defer _cgg .Close ();return LoadFromPDF (_cgg );};
|
||||
|
||||
// FieldValues implements model.FieldValueProvider interface.
|
||||
func (_de *FieldData )FieldValues ()(map[string ]_c .PdfObject ,error ){_fec :=make (map[string ]_c .PdfObject );for _ ,_gea :=range _de ._a {if len (_gea .Value )> 0{_fec [_gea .Name ]=_c .MakeString (_gea .Value );};};return _fec ,nil ;};
|
||||
|
||||
// FieldData represents form field data loaded from JSON file.
|
||||
type FieldData struct{_a []fieldValue };
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _e .ReadSeeker )(*FieldData ,error ){_ge ,_geg :=_ef .NewPdfReader (rs );if _geg !=nil {return nil ,_geg ;};if _ge .AcroForm ==nil {return nil ,nil ;};var _cg []fieldValue ;_ec :=_ge .AcroForm .AllFields ();for _ ,_fc :=range _ec {var _bg []string ;_gg :=make (map[string ]struct{});_aa ,_fcg :=_fc .FullName ();if _fcg !=nil {return nil ,_fcg ;};if _aaa ,_bce :=_fc .V .(*_c .PdfObjectString );_bce {_cg =append (_cg ,fieldValue {Name :_aa ,Value :_aaa .Decoded ()});continue ;};var _ce string ;for _ ,_ca :=range _fc .Annotations {_df ,_cdf :=_c .GetName (_ca .AS );if _cdf {_ce =_df .String ();};_ea ,_dcg :=_c .GetDict (_ca .AP );if !_dcg {continue ;};_beg ,_ :=_c .GetDict (_ea .Get ("\u004e"));for _ ,_baa :=range _beg .Keys (){_dg :=_baa .String ();if _ ,_bga :=_gg [_dg ];!_bga {_bg =append (_bg ,_dg );_gg [_dg ]=struct{}{};};};_eg ,_ :=_c .GetDict (_ea .Get ("\u0044"));for _ ,_ae :=range _eg .Keys (){_bgf :=_ae .String ();if _ ,_fcd :=_gg [_bgf ];!_fcd {_bg =append (_bg ,_bgf );_gg [_bgf ]=struct{}{};};};};_fg :=fieldValue {Name :_aa ,Value :_ce ,Options :_bg };_cg =append (_cg ,_fg );};_gd :=FieldData {_a :_cg };return &_gd ,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
@ -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 (_g "encoding/binary";_gd "unsafe";);var (ByteOrder _g .ByteOrder ;_c bool ;);func init (){const _fb =int (_gd .Sizeof (0));_df :=1;_a :=(*[_fb ]byte )(_gd .Pointer (&_df ));if _a [0]==0{_c =true ;ByteOrder =_g .BigEndian ;}else {ByteOrder =_g .LittleEndian ;};};func IsBig ()bool {return _c };func IsLittle ()bool {return !_c };
|
||||
package endian ;import (_a "encoding/binary";_g "unsafe";);var (ByteOrder _a .ByteOrder ;_fd bool ;);func init (){const _gc =int (_g .Sizeof (0));_fa :=1;_gd :=(*[_gc ]byte )(_g .Pointer (&_fa ));if _gd [0]==0{_fd =true ;ByteOrder =_a .BigEndian ;}else {ByteOrder =_a .LittleEndian ;};};func IsLittle ()bool {return !_fd };func IsBig ()bool {return _fd };
|
File diff suppressed because one or more lines are too long
@ -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 _da "github.com/unidoc/unipdf/v3/internal/jbig2/errors";type Stack struct{Data []interface{};Aux *Stack ;};func (_gf IntSlice )Get (index int )(int ,error ){if index > len (_gf )-1{return 0,_da .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _gf [index ],nil ;};func (_ac NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ac )-1{return 0,_da .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _ac [i ],nil ;};func NewNumSlice (i int )*NumSlice {_ed :=NumSlice (make ([]float32 ,i ));return &_ed };func (_ee IntSlice )Size ()int {return len (_ee )};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_eeb NumSlice )GetIntSlice ()[]int {_cdd :=make ([]int ,len (_eeb ));for _gg ,_bb :=range _eeb {_cdd [_gg ]=int (_bb );};return _cdd ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_ad NumSlice )GetInt (i int )(int ,error ){const _fd ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_ad )-1{return 0,_da .Errorf (_fd ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cb :=_ad [i ];return int (_cb +Sign (_cb )*0.5),nil ;};func (_dcb *Stack )Pop ()(_gd interface{},_gfa bool ){_gd ,_gfa =_dcb .peek ();if !_gfa {return nil ,_gfa ;};_dcb .Data =_dcb .Data [:_dcb .top ()];return _gd ,true ;};func (_cd *NumSlice )Add (v float32 ){*_cd =append (*_cd ,v )};func (_ged *Stack )Push (v interface{}){_ged .Data =append (_ged .Data ,v )};type IntsMap map[uint64 ][]int ;func (_gb IntsMap )Delete (key uint64 ){delete (_gb ,key )};func (_b *IntSlice )Copy ()*IntSlice {_dc :=IntSlice (make ([]int ,len (*_b )));copy (_dc ,*_b );return &_dc ;};func (_ab *Stack )top ()int {return len (_ab .Data )-1};func (_e IntsMap )Add (key uint64 ,value int ){_e [key ]=append (_e [key ],value )};func (_gbc *Stack )Len ()int {return len (_gbc .Data )};func Min (x ,y int )int {if x < y {return x ;};return y ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_bd *Stack )peek ()(interface{},bool ){_cbg :=_bd .top ();if _cbg ==-1{return nil ,false ;};return _bd .Data [_cbg ],true ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_fc IntsMap )GetSlice (key uint64 )([]int ,bool ){_a ,_dad :=_fc [key ];if !_dad {return nil ,false ;};return _a ,true ;};type IntSlice []int ;func NewIntSlice (i int )*IntSlice {_dg :=IntSlice (make ([]int ,i ));return &_dg };func (_ff *IntSlice )Add (v int )error {if _ff ==nil {return _da .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_ff =append (*_ff ,v );return nil ;};func (_fdd *Stack )Peek ()(_be interface{},_eee bool ){return _fdd .peek ()};func (_f IntsMap )Get (key uint64 )(int ,bool ){_g ,_c :=_f [key ];if !_c {return 0,false ;};if len (_g )==0{return 0,false ;};return _g [0],true ;};func (_ge *NumSlice )AddInt (v int ){*_ge =append (*_ge ,float32 (v ))};type NumSlice []float32 ;
|
||||
package basic ;import _a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func (_ca *NumSlice )AddInt (v int ){*_ca =append (*_ca ,float32 (v ))};func (_fa NumSlice )GetInt (i int )(int ,error ){const _gec ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_fa )-1{return 0,_a .Errorf (_gec ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_ag :=_fa [i ];return int (_ag +Sign (_ag )*0.5),nil ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_e *IntSlice )Add (v int )error {if _e ==nil {return _a .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_e =append (*_e ,v );return nil ;};func (_cbg *Stack )Push (v interface{}){_cbg .Data =append (_cbg .Data ,v )};func (_gf *NumSlice )Add (v float32 ){*_gf =append (*_gf ,v )};func (_de *Stack )Len ()int {return len (_de .Data )};func (_afb *Stack )Peek ()(_aa interface{},_cge bool ){return _afb .peek ()};func (_gg IntsMap )Get (key uint64 )(int ,bool ){_b ,_c :=_gg [key ];if !_c {return 0,false ;};if len (_b )==0{return 0,false ;};return _b [0],true ;};type IntsMap map[uint64 ][]int ;type IntSlice []int ;func (_cd NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_cd )-1{return 0,_a .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _cd [i ],nil ;};type NumSlice []float32 ;func (_d IntsMap )Add (key uint64 ,value int ){_d [key ]=append (_d [key ],value )};func NewIntSlice (i int )*IntSlice {_dd :=IntSlice (make ([]int ,i ));return &_dd };func (_cg IntsMap )GetSlice (key uint64 )([]int ,bool ){_ge ,_f :=_cg [key ];if !_f {return nil ,false ;};return _ge ,true ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_ac *Stack )top ()int {return len (_ac .Data )-1};func NewNumSlice (i int )*NumSlice {_ed :=NumSlice (make ([]float32 ,i ));return &_ed };func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_ef *Stack )peek ()(interface{},bool ){_gfa :=_ef .top ();if _gfa ==-1{return nil ,false ;};return _ef .Data [_gfa ],true ;};func (_af NumSlice )GetIntSlice ()[]int {_fgg :=make ([]int ,len (_af ));for _gd ,_gc :=range _af {_fgg [_gd ]=int (_gc );};return _fgg ;};func (_ab IntsMap )Delete (key uint64 ){delete (_ab ,key )};func (_fb *IntSlice )Copy ()*IntSlice {_fg :=IntSlice (make ([]int ,len (*_fb )));copy (_fg ,*_fb );return &_fg ;};func (_bc IntSlice )Size ()int {return len (_bc )};func Abs (v int )int {if v > 0{return v ;};return -v ;};type Stack struct{Data []interface{};Aux *Stack ;};func (_ee *Stack )Pop ()(_ad interface{},_gfd bool ){_ad ,_gfd =_ee .peek ();if !_gfd {return nil ,_gfd ;};_ee .Data =_ee .Data [:_ee .top ()];return _ad ,true ;};func (_cb IntSlice )Get (index int )(int ,error ){if index > len (_cb )-1{return 0,_a .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _cb [index ],nil ;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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 (_c "github.com/unidoc/unipdf/v3/internal/bitwise";_e "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_b "github.com/unidoc/unipdf/v3/internal/jbig2/document";_f "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "image";);func (_bf *Decoder )DecodePageImage (pageNumber int )(_a .Image ,error ){const _fa ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bg ,_gb :=_bf .decodePageImage (pageNumber );if _gb !=nil {return nil ,_f .Wrap (_gb ,_fa ,"");};return _bg ,nil ;};func (_ga *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _ga .decodePage (pageNumber )};type Parameters struct{UnpaddedData bool ;Color _e .Color ;};type Decoder struct{_d _c .StreamReader ;_fg *_b .Document ;_ae int ;_eb Parameters ;};func (_ac *Decoder )PageNumber ()(int ,error ){const _af ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _ac ._fg ==nil {return 0,_f .Error (_af ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_ac ._fg .NumberOfPages ),nil ;};func (_aff *Decoder )decodePage (_ad int )([]byte ,error ){const _be ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _ad < 0{return nil ,_f .Errorf (_be ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_ad );};if _ad > int (_aff ._fg .NumberOfPages ){return nil ,_f .Errorf (_be ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_ad );};_fd ,_adb :=_aff ._fg .GetPage (_ad );if _adb !=nil {return nil ,_f .Wrap (_adb ,_be ,"");};_gd ,_adb :=_fd .GetBitmap ();if _adb !=nil {return nil ,_f .Wrap (_adb ,_be ,"");};_gd .InverseData ();if !_aff ._eb .UnpaddedData {return _gd .Data ,nil ;};return _gd .GetUnpaddedData ();};func (_fb *Decoder )DecodeNextPage ()([]byte ,error ){_fb ._ae ++;_gg :=_fb ._ae ;return _fb .decodePage (_gg );};func (_ca *Decoder )decodePageImage (_bc int )(_a .Image ,error ){const _da ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _bc < 0{return nil ,_f .Errorf (_da ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_bc );};if _bc > int (_ca ._fg .NumberOfPages ){return nil ,_f .Errorf (_da ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_bc );};_fe ,_dg :=_ca ._fg .GetPage (_bc );if _dg !=nil {return nil ,_f .Wrap (_dg ,_da ,"");};_fgf ,_dg :=_fe .GetBitmap ();if _dg !=nil {return nil ,_f .Wrap (_dg ,_da ,"");};return _fgf .ToImage (),nil ;};func Decode (input []byte ,parameters Parameters ,globals *_b .Globals )(*Decoder ,error ){_ada :=_c .NewReader (input );_fad ,_gc :=_b .DecodeDocument (_ada ,globals );if _gc !=nil {return nil ,_gc ;};return &Decoder {_d :_ada ,_fg :_fad ,_eb :parameters },nil ;};
|
||||
package decoder ;import (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_ef "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_ec "github.com/unidoc/unipdf/v3/internal/jbig2/document";_be "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "image";);func (_ab *Decoder )DecodeNextPage ()([]byte ,error ){_ab ._g ++;_cc :=_ab ._g ;return _ab .decodePage (_cc );};func (_d *Decoder )decodePage (_gf int )([]byte ,error ){const _dd ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _gf < 0{return nil ,_be .Errorf (_dd ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_gf );};if _gf > int (_d ._bf .NumberOfPages ){return nil ,_be .Errorf (_dd ,"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",_gf );};_ae ,_ea :=_d ._bf .GetPage (_gf );if _ea !=nil {return nil ,_be .Wrap (_ea ,_dd ,"");};_dc ,_ea :=_ae .GetBitmap ();if _ea !=nil {return nil ,_be .Wrap (_ea ,_dd ,"");};_dc .InverseData ();if !_d ._c .UnpaddedData {return _dc .Data ,nil ;};return _dc .GetUnpaddedData ();};func (_cf *Decoder )PageNumber ()(int ,error ){const _ag ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _cf ._bf ==nil {return 0,_be .Error (_ag ,"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 (_cf ._bf .NumberOfPages ),nil ;};func Decode (input []byte ,parameters Parameters ,globals *_ec .Globals )(*Decoder ,error ){_abb :=_e .NewReader (input );_aeg ,_eff :=_ec .DecodeDocument (_abb ,globals );if _eff !=nil {return nil ,_eff ;};return &Decoder {_ed :_abb ,_bf :_aeg ,_c :parameters },nil ;};func (_efb *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _efb .decodePage (pageNumber )};func (_af *Decoder )decodePageImage (_dcf int )(_a .Image ,error ){const _agb ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _dcf < 0{return nil ,_be .Errorf (_agb ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_dcf );};if _dcf > int (_af ._bf .NumberOfPages ){return nil ,_be .Errorf (_agb ,"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",_dcf );};_fac ,_bb :=_af ._bf .GetPage (_dcf );if _bb !=nil {return nil ,_be .Wrap (_bb ,_agb ,"");};_abd ,_bb :=_fac .GetBitmap ();if _bb !=nil {return nil ,_be .Wrap (_bb ,_agb ,"");};return _abd .ToImage (),nil ;};type Decoder struct{_ed _e .StreamReader ;_bf *_ec .Document ;_g int ;_c Parameters ;};func (_f *Decoder )DecodePageImage (pageNumber int )(_a .Image ,error ){const _bc ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_fa ,_bg :=_f .decodePageImage (pageNumber );if _bg !=nil {return nil ,_be .Wrap (_bg ,_bc ,"");};return _fa ,nil ;};type Parameters struct{UnpaddedData bool ;Color _ef .Color ;};
|
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
@ -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 _g "fmt";func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _fb ,_ba :=err .(*processError );_ba {_fb ._d ="";};_fbg :=_dd (_g .Sprintf (message ,arguments ...),processName );_fbg ._a =err ;return _fbg ;};func Wrap (err error ,processName ,message string )error {if _dg ,_ee :=err .(*processError );_ee {_dg ._d ="";};_ec :=_dd (message ,processName );_ec ._a =err ;return _ec ;};type processError struct{_d string ;_e string ;_f string ;_a error ;};func Error (processName ,message string )error {return _dd (message ,processName )};func (_da *processError )Error ()string {var _c string ;if _da ._d !=""{_c =_da ._d ;};_c +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_da ._e ;if _da ._f !=""{_c +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_da ._f ;};if _da ._a !=nil {_c +="\u002e\u0020"+_da ._a .Error ();};return _c ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _dd (_g .Sprintf (message ,arguments ...),processName );};func _dd (_df ,_bf string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_f :_df ,_e :_bf };};
|
||||
package errors ;import _d "fmt";func _gf (_b ,_ec string )*processError {return &processError {_ee :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_a :_b ,_dd :_ec };};func Wrap (err error ,processName ,message string )error {if _ecb ,_ed :=err .(*processError );_ed {_ecb ._ee ="";};_ef :=_gf (message ,processName );_ef ._ab =err ;return _ef ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _eca ,_efg :=err .(*processError );_efg {_eca ._ee ="";};_de :=_gf (_d .Sprintf (message ,arguments ...),processName );_de ._ab =err ;return _de ;};func (_g *processError )Error ()string {var _f string ;if _g ._ee !=""{_f =_g ._ee ;};_f +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_g ._dd ;if _g ._a !=""{_f +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_g ._a ;};if _g ._ab !=nil {_f +="\u002e\u0020"+_g ._ab .Error ();};return _f ;};func Error (processName ,message string )error {return _gf (message ,processName )};func Errorf (processName ,message string ,arguments ...interface{})error {return _gf (_d .Sprintf (message ,arguments ...),processName );};type processError struct{_ee string ;_dd string ;_a string ;_ab error ;};
|
@ -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 (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_df "github.com/unidoc/unipdf/v3/internal/jbig2/document";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_da "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_b "sort";);type Globals map[int ]*_c .Header ;func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _bd Globals ;if len (globals )> 0{_bd =globals [0];};_e ,_gd :=_d .Decode (encoded ,parameters ,_bd .ToDocumentGlobals ());if _gd !=nil {return nil ,_gd ;};return _e .DecodeNextPage ();};func DecodeGlobals (encoded []byte )(Globals ,error ){const _dc ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_a :=_g .NewReader (encoded );_bdd ,_ed :=_df .DecodeDocument (_a ,nil );if _ed !=nil {return nil ,_da .Wrap (_ed ,_dc ,"");};if _bdd .GlobalSegments ==nil ||(_bdd .GlobalSegments .Segments ==nil ){return nil ,_da .Error (_dc ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_ec :=Globals {};for _ ,_de :=range _bdd .GlobalSegments .Segments {_ec [int (_de .SegmentNumber )]=_de ;};return _ec ,nil ;};func (_af Globals )ToDocumentGlobals ()*_df .Globals {if _af ==nil {return nil ;};_eb :=[]*_c .Header {};for _ ,_ee :=range _af {_eb =append (_eb ,_ee );};_b .Slice (_eb ,func (_ae ,_bg int )bool {return _eb [_ae ].SegmentNumber < _eb [_bg ].SegmentNumber });return &_df .Globals {Segments :_eb };};
|
||||
package jbig2 ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_cc "github.com/unidoc/unipdf/v3/internal/jbig2/document";_f "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_gc "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_e "sort";);func DecodeBytes (encoded []byte ,parameters _a .Parameters ,globals ...Globals )([]byte ,error ){var _ge Globals ;if len (globals )> 0{_ge =globals [0];};_ad ,_d :=_a .Decode (encoded ,parameters ,_ge .ToDocumentGlobals ());if _d !=nil {return nil ,_d ;};return _ad .DecodeNextPage ();};func (_fc Globals )ToDocumentGlobals ()*_cc .Globals {if _fc ==nil {return nil ;};_ff :=[]*_f .Header {};for _ ,_ee :=range _fc {_ff =append (_ff ,_ee );};_e .Slice (_ff ,func (_cf ,_b int )bool {return _ff [_cf ].SegmentNumber < _ff [_b ].SegmentNumber });return &_cc .Globals {Segments :_ff };};func DecodeGlobals (encoded []byte )(Globals ,error ){const _dg ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_da :=_g .NewReader (encoded );_df ,_fb :=_cc .DecodeDocument (_da ,nil );if _fb !=nil {return nil ,_gc .Wrap (_fb ,_dg ,"");};if _df .GlobalSegments ==nil ||(_df .GlobalSegments .Segments ==nil ){return nil ,_gc .Error (_dg ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_fg :=Globals {};for _ ,_fbf :=range _df .GlobalSegments .Segments {_fg [int (_fbf .SegmentNumber )]=_fbf ;};return _fg ,nil ;};type Globals map[int ]*_f .Header ;
|
@ -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";_dc "github.com/unidoc/unipdf/v3/internal/imageutil";_f "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _bb []uint32 ;_ab :=bitsPerOutputSample ;var _gg uint32 ;var _df uint32 ;_fad :=0;_dbb :=0;_gc :=0;for _gc < len (data ){if _fad > 0{_dba :=_fad ;if _ab < _dba {_dba =_ab ;};_gg =(_gg <<uint (_dba ))|uint32 (_df >>uint (bitsPerInputSample -_dba ));_fad -=_dba ;if _fad > 0{_df =_df <<uint (_dba );}else {_df =0;};_ab -=_dba ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};}else {_bg :=data [_gc ];_gc ++;_fec :=bitsPerInputSample ;if _ab < _fec {_fec =_ab ;};_fad =bitsPerInputSample -_fec ;_gg =(_gg <<uint (_fec ))|uint32 (_bg >>uint (_fad ));if _fec < bitsPerInputSample {_df =_bg <<uint (_fec );};_ab -=_fec ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};};};for _fad >=bitsPerOutputSample {_ace :=_fad ;if _ab < _ace {_ace =_ab ;};_gg =(_gg <<uint (_ace ))|uint32 (_df >>uint (bitsPerInputSample -_ace ));_fad -=_ace ;if _fad > 0{_df =_df <<uint (_ace );}else {_df =0;};_ab -=_ace ;if _ab ==0{_bb =append (_bb ,_gg );_ab =bitsPerOutputSample ;_gg =0;_dbb ++;};};if _ab > 0&&_ab < bitsPerOutputSample {_gg <<=uint (_ab );_bb =append (_bb ,_gg );};return _bb ;};func (_bd *Writer )WriteSample (sample uint32 )error {if _ ,_bac :=_bd ._ca .WriteBits (uint64 (sample ),_bd ._gf .BitsPerComponent );_bac !=nil {return _bac ;};_bd ._bbg --;if _bd ._bbg ==0{_bd ._bbg =_bd ._gf .ColorComponents ;_bd ._ff ++;};if _bd ._ff ==_bd ._gf .Width {if _bd ._ef {_bd ._ca .FinishByte ();};_bd ._ff =0;};return nil ;};func NewReader (img _dc .ImageBase )*Reader {return &Reader {_fb :_a .NewReader (img .Data ),_c :img ,_fe :img .ColorComponents ,_cg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_da *Writer )WriteSamples (samples []uint32 )error {for _bf :=0;_bf < len (samples );_bf ++{if _cf :=_da .WriteSample (samples [_bf ]);_cf !=nil {return _cf ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ee []uint32 ;_eea :=bitsPerSample ;var _g uint32 ;var _ba byte ;_fa :=0;_ec :=0;_afb :=0;for _afb < len (data ){if _fa > 0{_fc :=_fa ;if _eea < _fc {_fc =_eea ;};_g =(_g <<uint (_fc ))|uint32 (_ba >>uint (8-_fc ));_fa -=_fc ;if _fa > 0{_ba =_ba <<uint (_fc );}else {_ba =0;};_eea -=_fc ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};}else {_fg :=data [_afb ];_afb ++;_bc :=8;if _eea < _bc {_bc =_eea ;};_fa =8-_bc ;_g =(_g <<uint (_bc ))|uint32 (_fg >>uint (_fa ));if _bc < 8{_ba =_fg <<uint (_bc );};_eea -=_bc ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};};};for _fa >=bitsPerSample {_aff :=_fa ;if _eea < _aff {_aff =_eea ;};_g =(_g <<uint (_aff ))|uint32 (_ba >>uint (8-_aff ));_fa -=_aff ;if _fa > 0{_ba =_ba <<uint (_aff );}else {_ba =0;};_eea -=_aff ;if _eea ==0{_ee =append (_ee ,_g );_eea =bitsPerSample ;_g =0;_ec ++;};};return _ee ;};type SampleWriter interface{WriteSample (_afbf uint32 )error ;WriteSamples (_afc []uint32 )error ;};type Reader struct{_c _dc .ImageBase ;_fb *_a .Reader ;_ac ,_cc ,_fe int ;_cg bool ;};func NewWriter (img _dc .ImageBase )*Writer {return &Writer {_ca :_a .NewWriterMSB (img .Data ),_gf :img ,_bbg :img .ColorComponents ,_ef :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_e []uint32 )error ;};type Writer struct{_gf _dc .ImageBase ;_ca *_a .Writer ;_ff ,_bbg int ;_ef bool ;};func (_b *Reader )ReadSample ()(uint32 ,error ){if _b ._cc ==_b ._c .Height {return 0,_f .EOF ;};_db ,_af :=_b ._fb .ReadBits (byte (_b ._c .BitsPerComponent ));if _af !=nil {return 0,_af ;};_b ._fe --;if _b ._fe ==0{_b ._fe =_b ._c .ColorComponents ;_b ._ac ++;};if _b ._ac ==_b ._c .Width {if _b ._cg {_b ._fb .ConsumeRemainingBits ();};_b ._ac =0;_b ._cc ++;};return uint32 (_db ),nil ;};func (_dg *Reader )ReadSamples (samples []uint32 )(_eg error ){for _de :=0;_de < len (samples );_de ++{samples [_de ],_eg =_dg .ReadSample ();if _eg !=nil {return _eg ;};};return nil ;};
|
||||
package sampling ;import (_d "github.com/unidoc/unipdf/v3/internal/bitwise";_b "github.com/unidoc/unipdf/v3/internal/imageutil";_e "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _ec []uint32 ;_dee :=bitsPerOutputSample ;var _ce uint32 ;var _af uint32 ;_fff :=0;_ab :=0;_dfc :=0;for _dfc < len (data ){if _fff > 0{_ed :=_fff ;if _dee < _ed {_ed =_dee ;};_ce =(_ce <<uint (_ed ))|uint32 (_af >>uint (bitsPerInputSample -_ed ));_fff -=_ed ;if _fff > 0{_af =_af <<uint (_ed );}else {_af =0;};_dee -=_ed ;if _dee ==0{_ec =append (_ec ,_ce );_dee =bitsPerOutputSample ;_ce =0;_ab ++;};}else {_gad :=data [_dfc ];_dfc ++;_fd :=bitsPerInputSample ;if _dee < _fd {_fd =_dee ;};_fff =bitsPerInputSample -_fd ;_ce =(_ce <<uint (_fd ))|uint32 (_gad >>uint (_fff ));if _fd < bitsPerInputSample {_af =_gad <<uint (_fd );};_dee -=_fd ;if _dee ==0{_ec =append (_ec ,_ce );_dee =bitsPerOutputSample ;_ce =0;_ab ++;};};};for _fff >=bitsPerOutputSample {_eb :=_fff ;if _dee < _eb {_eb =_dee ;};_ce =(_ce <<uint (_eb ))|uint32 (_af >>uint (bitsPerInputSample -_eb ));_fff -=_eb ;if _fff > 0{_af =_af <<uint (_eb );}else {_af =0;};_dee -=_eb ;if _dee ==0{_ec =append (_ec ,_ce );_dee =bitsPerOutputSample ;_ce =0;_ab ++;};};if _dee > 0&&_dee < bitsPerOutputSample {_ce <<=uint (_dee );_ec =append (_ec ,_ce );};return _ec ;};func NewWriter (img _b .ImageBase )*Writer {return &Writer {_eg :_d .NewWriterMSB (img .Data ),_aea :img ,_cd :img .ColorComponents ,_cg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _gg []uint32 ;_gfd :=bitsPerSample ;var _dc uint32 ;var _bd byte ;_gff :=0;_dd :=0;_df :=0;for _df < len (data ){if _gff > 0{_ae :=_gff ;if _gfd < _ae {_ae =_gfd ;};_dc =(_dc <<uint (_ae ))|uint32 (_bd >>uint (8-_ae ));_gff -=_ae ;if _gff > 0{_bd =_bd <<uint (_ae );}else {_bd =0;};_gfd -=_ae ;if _gfd ==0{_gg =append (_gg ,_dc );_gfd =bitsPerSample ;_dc =0;_dd ++;};}else {_gcc :=data [_df ];_df ++;_gd :=8;if _gfd < _gd {_gd =_gfd ;};_gff =8-_gd ;_dc =(_dc <<uint (_gd ))|uint32 (_gcc >>uint (_gff ));if _gd < 8{_bd =_gcc <<uint (_gd );};_gfd -=_gd ;if _gfd ==0{_gg =append (_gg ,_dc );_gfd =bitsPerSample ;_dc =0;_dd ++;};};};for _gff >=bitsPerSample {_fa :=_gff ;if _gfd < _fa {_fa =_gfd ;};_dc =(_dc <<uint (_fa ))|uint32 (_bd >>uint (8-_fa ));_gff -=_fa ;if _gff > 0{_bd =_bd <<uint (_fa );}else {_bd =0;};_gfd -=_fa ;if _gfd ==0{_gg =append (_gg ,_dc );_gfd =bitsPerSample ;_dc =0;_dd ++;};};return _gg ;};func (_gcd *Writer )WriteSamples (samples []uint32 )error {for _cea :=0;_cea < len (samples );_cea ++{if _gab :=_gcd .WriteSample (samples [_cea ]);_gab !=nil {return _gab ;};};return nil ;};func (_ff *Reader )ReadSample ()(uint32 ,error ){if _ff ._eae ==_ff ._c .Height {return 0,_e .EOF ;};_ga ,_gb :=_ff ._g .ReadBits (byte (_ff ._c .BitsPerComponent ));if _gb !=nil {return 0,_gb ;};_ff ._gc --;if _ff ._gc ==0{_ff ._gc =_ff ._c .ColorComponents ;_ff ._gf ++;};if _ff ._gf ==_ff ._c .Width {if _ff ._de {_ff ._g .ConsumeRemainingBits ();};_ff ._gf =0;_ff ._eae ++;};return uint32 (_ga ),nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ea []uint32 )error ;};func (_bg *Writer )WriteSample (sample uint32 )error {if _ ,_cfa :=_bg ._eg .WriteBits (uint64 (sample ),_bg ._aea .BitsPerComponent );_cfa !=nil {return _cfa ;};_bg ._cd --;if _bg ._cd ==0{_bg ._cd =_bg ._aea .ColorComponents ;_bg ._ffg ++;};if _bg ._ffg ==_bg ._aea .Width {if _bg ._cg {_bg ._eg .FinishByte ();};_bg ._ffg =0;};return nil ;};type Writer struct{_aea _b .ImageBase ;_eg *_d .Writer ;_ffg ,_cd int ;_cg bool ;};type Reader struct{_c _b .ImageBase ;_g *_d .Reader ;_gf ,_eae ,_gc int ;_de bool ;};func (_ca *Reader )ReadSamples (samples []uint32 )(_a error ){for _db :=0;_db < len (samples );_db ++{samples [_db ],_a =_ca .ReadSample ();if _a !=nil {return _a ;};};return nil ;};func NewReader (img _b .ImageBase )*Reader {return &Reader {_g :_d .NewReader (img .Data ),_c :img ,_gc :img .ColorComponents ,_de :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleWriter interface{WriteSample (_cf uint32 )error ;WriteSamples (_gffe []uint32 )error ;};
|
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
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package transform ;import (_cb "fmt";_a "github.com/unidoc/unipdf/v3/common";_g "math";);func (_gc *Matrix )Shear (x ,y float64 ){_gc .Concat (ShearMatrix (x ,y ))};func (_ad *Matrix )Scale (x ,y float64 ){_ad .Concat (ScaleMatrix (x ,y ))};func (_cc Point )Displace (delta Point )Point {return Point {_cc .X +delta .X ,_cc .Y +delta .Y }};func (_eafg *Point )Set (x ,y float64 ){_eafg .X ,_eafg .Y =x ,y };func (_db *Point )transformByMatrix (_fff Matrix ){_db .X ,_db .Y =_fff .Transform (_db .X ,_db .Y )};func (_bg Point )String ()string {return _cb .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_bg .X ,_bg .Y );};type Point struct{X float64 ;Y float64 ;};func (_ge *Matrix )Translation ()(float64 ,float64 ){return _ge [6],_ge [7]};func (_ac *Matrix )Concat (b Matrix ){*_ac =Matrix {b [0]*_ac [0]+b [1]*_ac [3],b [0]*_ac [1]+b [1]*_ac [4],0,b [3]*_ac [0]+b [4]*_ac [3],b [3]*_ac [1]+b [4]*_ac [4],0,b [6]*_ac [0]+b [7]*_ac [3]+_ac [6],b [6]*_ac [1]+b [7]*_ac [4]+_ac [7],1};_ac .clampRange ();};func (_geg *Matrix )ScalingFactorX ()float64 {return _g .Hypot (_geg [0],_geg [1])};func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};func (_ca *Matrix )Translate (x ,y float64 ){_ca .Concat (TranslationMatrix (x ,y ))};func (_df *Matrix )clampRange (){for _dd ,_caf :=range _df {if _caf > _ce {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_caf ,_ce );_df [_dd ]=_ce ;}else if _caf < -_ce {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_caf ,-_ce );_df [_dd ]=-_ce ;};};};func (_fb *Matrix )Angle ()float64 {_eaf :=_g .Atan2 (-_fb [1],_fb [0]);if _eaf < 0.0{_eaf +=2*_g .Pi ;};return _eaf /_g .Pi *180.0;};func (_fe *Matrix )Transform (x ,y float64 )(float64 ,float64 ){_ab :=x *_fe [0]+y *_fe [1]+_fe [6];_adb :=x *_fe [3]+y *_fe [4]+_fe [7];return _ab ,_adb ;};func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )};const _ggf =1.0e-6;func (_be *Matrix )Clone ()Matrix {return NewMatrix (_be [0],_be [1],_be [3],_be [4],_be [6],_be [7])};type Matrix [9]float64 ;func (_gcd Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_gcd .X +t *b .X ,Y :(1-t )*_gcd .Y +t *b .Y };};func (_ff *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_ff [0],_ff [1]=a ,b ;_ff [3],_ff [4]=c ,d ;_ff [6],_ff [7]=tx ,ty ;_ff .clampRange ();};func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_cg :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1};_cg .clampRange ();return _cg ;};func (_ga *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_gbd :=NewMatrix (a ,b ,c ,d ,tx ,ty );_ga .transformByMatrix (_gbd );};const _ce =1e9;func (_af Point )Distance (b Point )float64 {return _g .Hypot (_af .X -b .X ,_af .Y -b .Y )};func (_ced Point )Rotate (theta float64 )Point {_fa :=_g .Hypot (_ced .X ,_ced .Y );_ba :=_g .Atan2 (_ced .Y ,_ced .X );_dae ,_dad :=_g .Sincos (_ba +theta /180.0*_g .Pi );return Point {_fa *_dad ,_fa *_dae };};func (_d Matrix )String ()string {_ea ,_cgd ,_f ,_fd ,_fg ,_ee :=_d [0],_d [1],_d [3],_d [4],_d [6],_d [7];return _cb .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_ea ,_cgd ,_f ,_fd ,_fg ,_ee );};func IdentityMatrix ()Matrix {return NewMatrix (1,0,0,1,0,0)};const _cba =1e-6;func (_b *Matrix )Rotate (angle float64 ){_b .Concat (RotationMatrix (angle ))};func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};func (_dfb *Matrix )Unrealistic ()bool {_da ,_gg ,_fga ,_bd :=_g .Abs (_dfb [0]),_g .Abs (_dfb [1]),_g .Abs (_dfb [3]),_g .Abs (_dfb [4]);_ddc :=_da > _cba &&_bd > _cba ;_ed :=_gg > _cba &&_fga > _cba ;return !(_ddc ||_ed );};func RotationMatrix (angle float64 )Matrix {_e :=_g .Cos (angle );_ae :=_g .Sin (angle );return NewMatrix (_e ,_ae ,-_ae ,_e ,0,0);};func (_gb *Matrix )ScalingFactorY ()float64 {return _g .Hypot (_gb [3],_gb [4])};func (_dg Matrix )Mult (b Matrix )Matrix {_dg .Concat (b );return _dg };func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};
|
||||
package transform ;import (_a "fmt";_df "github.com/unidoc/unipdf/v3/common";_b "math";);func (_fbfg Matrix )Angle ()float64 {_cg :=_b .Atan2 (-_fbfg [1],_fbfg [0]);if _cg < 0.0{_cg +=2*_b .Pi ;};return _cg /_b .Pi *180.0;};func (_cc *Matrix )Shear (x ,y float64 ){_cc .Concat (ShearMatrix (x ,y ))};func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};func (_egbf *Point )transformByMatrix (_eba Matrix ){_egbf .X ,_egbf .Y =_eba .Transform (_egbf .X ,_egbf .Y );};func (_ed Point )Rotate (theta float64 )Point {_ba :=_b .Hypot (_ed .X ,_ed .Y );_abb :=_b .Atan2 (_ed .Y ,_ed .X );_edf ,_fda :=_b .Sincos (_abb +theta /180.0*_b .Pi );return Point {_ba *_fda ,_ba *_edf };};func (_f Matrix )Scale (xScale ,yScale float64 )Matrix {return _f .Mult (NewMatrix (xScale ,0,0,yScale ,0,0));};func (_cgg Matrix )Unrealistic ()bool {_feg ,_fd ,_ce ,_cag :=_b .Abs (_cgg [0]),_b .Abs (_cgg [1]),_b .Abs (_cgg [3]),_b .Abs (_cgg [4]);_gce :=_feg > _aff &&_cag > _aff ;_agg :=_fd > _aff &&_ce > _aff ;return !(_gce ||_agg );};func (_egb *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_gbd :=NewMatrix (a ,b ,c ,d ,tx ,ty );_egb .transformByMatrix (_gbd );};func (_ga *Matrix )Clone ()Matrix {return NewMatrix (_ga [0],_ga [1],_ga [3],_ga [4],_ga [6],_ga [7])};func (_fc Matrix )Mult (b Matrix )Matrix {_fc .Concat (b );return _fc };func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_eb :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1};_eb .clampRange ();return _eb ;};func (_dbd *Matrix )clampRange (){for _be ,_dea :=range _dbd {if _dea > _ef {_df .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_dea ,_ef );_dbd [_be ]=_ef ;}else if _dea < -_ef {_df .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_dea ,-_ef );_dbd [_be ]=-_ef ;};};};func (_fa Matrix )ScalingFactorY ()float64 {return _b .Hypot (_fa [3],_fa [4])};func (_efe Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_efe .X +t *b .X ,Y :(1-t )*_efe .Y +t *b .Y };};type Point struct{X float64 ;Y float64 ;};const _cd =1.0e-6;func (_fbb Point )Displace (delta Point )Point {return Point {_fbb .X +delta .X ,_fbb .Y +delta .Y }};func (_fbf *Matrix )Concat (b Matrix ){*_fbf =Matrix {b [0]*_fbf [0]+b [1]*_fbf [3],b [0]*_fbf [1]+b [1]*_fbf [4],0,b [3]*_fbf [0]+b [4]*_fbf [3],b [3]*_fbf [1]+b [4]*_fbf [4],0,b [6]*_fbf [0]+b [7]*_fbf [3]+_fbf [6],b [6]*_fbf [1]+b [7]*_fbf [4]+_fbf [7],1};_fbf .clampRange ();};func (_bc Matrix )ScalingFactorX ()float64 {return _b .Hypot (_bc [0],_bc [1])};func (_ebf *Point )Set (x ,y float64 ){_ebf .X ,_ebf .Y =x ,y };func (_c Matrix )String ()string {_ge ,_gea ,_cf ,_cfb ,_gc ,_gec :=_c [0],_c [1],_c [3],_c [4],_c [6],_c [7];return _a .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_ge ,_gea ,_cf ,_cfb ,_gc ,_gec );};func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )};func IdentityMatrix ()Matrix {return NewMatrix (1,0,0,1,0,0)};func (_afc Matrix )Inverse ()(Matrix ,bool ){_ab ,_eg :=_afc [0],_afc [1];_dc ,_bcf :=_afc [3],_afc [4];_bd ,_da :=_afc [6],_afc [7];_gebb :=_ab *_bcf -_eg *_dc ;if _b .Abs (_gebb )< _cd {return Matrix {},false ;};_ega ,_fe :=_bcf /_gebb ,-_eg /_gebb ;_egd ,_db :=-_dc /_gebb ,_ab /_gebb ;_gb :=-(_ega *_bd +_egd *_da );_bdd :=-(_fe *_bd +_db *_da );return NewMatrix (_ega ,_fe ,_egd ,_db ,_gb ,_bdd ),true ;};type Matrix [9]float64 ;func (_faa Point )String ()string {return _a .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_faa .X ,_faa .Y );};func RotationMatrix (angle float64 )Matrix {_e :=_b .Cos (angle );_g :=_b .Sin (angle );return NewMatrix (_e ,_g ,-_g ,_e ,0,0);};func (_dd Matrix )Rotate (theta float64 )Matrix {_de ,_ag :=_b .Sincos (theta /180.0*_b .Pi );return _dd .Mult (NewMatrix (_ag ,-_de ,_de ,_ag ,0,0));};func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};const _aff =1e-6;const _ef =1e9;func (_af Matrix )Translation ()(float64 ,float64 ){return _af [6],_af [7]};func (_fb *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_fb [0],_fb [1]=a ,b ;_fb [3],_fb [4]=c ,d ;_fb [6],_fb [7]=tx ,ty ;_fb .clampRange ();};func (_gcc Point )Distance (b Point )float64 {return _b .Hypot (_gcc .X -b .X ,_gcc .Y -b .Y )};func (_geb Matrix )Transform (x ,y float64 )(float64 ,float64 ){_bf :=x *_geb [0]+y *_geb [3]+_geb [6];_ca :=x *_geb [1]+y *_geb [4]+_geb [7];return _bf ,_ca ;};func (_bb Matrix )Translate (tx ,ty float64 )Matrix {return NewMatrix (_bb [0],_bb [1],_bb [3],_bb [4],_bb [6]+tx ,_bb [7]+ty );};func NewMatrixFromTransforms (xScale ,yScale ,theta ,tx ,ty float64 )Matrix {return IdentityMatrix ().Scale (xScale ,yScale ).Rotate (theta ).Translate (tx ,ty );};func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
File diff suppressed because one or more lines are too long
4624
model/model.go
4624
model/model.go
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -10,75 +10,75 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package sighandler implements digital signature handlers for PDF signature validation and signing.
|
||||
package sighandler ;import (_f "bytes";_e "crypto";_aab "crypto/rand";_dd "crypto/rsa";_cc "crypto/x509";_g "crypto/x509/pkix";_aa "encoding/asn1";_cf "errors";_eg "fmt";_cfb "github.com/unidoc/pkcs7";_dc "github.com/unidoc/timestamp";_dcb "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/model";_ca "hash";_c "io";_fg "io/ioutil";_ae "net/http";_a "time";);
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_bf *adobePKCS7Detached )InitSignature (sig *_b .PdfSignature )error {if !_bf ._ba {if _bf ._bd ==nil {return _cf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _bf ._ge ==nil {return _cf .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_de :=*_bf ;sig .Handler =&_de ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_eb ,_egb :=_de .NewDigest (sig );if _egb !=nil {return _egb ;};_eb .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _de .Sign (sig ,_eb );};func (_baf *adobePKCS7Detached )getCertificate (_aeb *_b .PdfSignature )(*_cc .Certificate ,error ){if _baf ._bd !=nil {return _baf ._bd ,nil ;};var _cb []byte ;switch _fe :=_aeb .Cert .(type ){case *_dcb .PdfObjectString :_cb =_fe .Bytes ();case *_dcb .PdfObjectArray :if _fe .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_da :=range _fe .Elements (){_af ,_cfbc :=_dcb .GetString (_da );if !_cfbc {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_da );};_cb =append (_cb ,_af .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_fe );};_bad ,_dce :=_cc .ParseCertificates (_cb );if _dce !=nil {return nil ,_dce ;};return _bad [0],nil ;};type docTimeStamp struct{_ecc string ;_bbc _e .Hash ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_bdc *adobePKCS7Detached )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};type timestampInfo struct{Version int ;Policy _aa .RawValue ;MessageImprint struct{HashAlgorithm _g .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _aa .RawValue ;GeneralizedTime _a .Time ;};type adobePKCS7Detached struct{_ge *_dd .PrivateKey ;_bd *_cc .Certificate ;_ba bool ;_ad int ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_ff *adobeX509RSASHA1 )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_gc ,_dee :=_ff .getCertificate (sig );if _dee !=nil {return _b .SignatureValidationResult {},_dee ;};_bdd :=sig .Contents .Bytes ();var _cce []byte ;if _ ,_cceb :=_aa .Unmarshal (_bdd ,&_cce );_cceb !=nil {return _b .SignatureValidationResult {},_cceb ;};_fega ,_gd :=digest .(_ca .Hash );if !_gd {return _b .SignatureValidationResult {},_cf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_bec ,_ :=_fede (_gc .SignatureAlgorithm );if _cbc :=_dd .VerifyPKCS1v15 (_gc .PublicKey .(*_dd .PublicKey ),_bec ,_fega .Sum (nil ),_cce );_cbc !=nil {return _b .SignatureValidationResult {},_cbc ;};return _b .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_efc *docTimeStamp )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_dag *adobeX509RSASHA1 )NewDigest (sig *_b .PdfSignature )(_b .Hasher ,error ){_gec ,_dbd :=_dag .getCertificate (sig );if _dbd !=nil {return nil ,_dbd ;};_ecf ,_ :=_fede (_gec .SignatureAlgorithm );return _ecf .New (),nil ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_cfe *docTimeStamp )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {_ddc :=digest .(*_f .Buffer );_ceef :=_cfe ._bbc .New ();if _ ,_ecb :=_c .Copy (_ceef ,_ddc );_ecb !=nil {return _ecb ;};_bc :=_ceef .Sum (nil );_edd :=_dc .Request {HashAlgorithm :_cfe ._bbc ,HashedMessage :_bc ,Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_ea ,_dcf :=_edd .Marshal ();if _dcf !=nil {return _dcf ;};_ac ,_dcf :=_ae .Post (_cfe ._ecc ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_f .NewBuffer (_ea ));if _dcf !=nil {return _dcf ;};defer _ac .Body .Close ();_gfe ,_dcf :=_fg .ReadAll (_ac .Body );if _dcf !=nil {return _dcf ;};if _ac .StatusCode !=_ae .StatusOK {return _eg .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_ac .StatusCode );};var _adf struct{Version _aa .RawValue ;Content _aa .RawValue ;};_ ,_dcf =_aa .Unmarshal (_gfe ,&_adf );if _dcf !=nil {return _dcf ;};sig .Contents =_dcb .MakeHexString (string (_adf .Content .FullBytes ));return nil ;};
|
||||
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_ebc *_b .PdfSignature ,_gb _b .Hasher )([]byte ,error );
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_fgaa *docTimeStamp )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_cfbb :=sig .Contents .Bytes ();_gee ,_abf :=_cfb .Parse (_cfbb );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};if _abf =_gee .Verify ();_abf !=nil {return _b .SignatureValidationResult {},_abf ;};var _gafg timestampInfo ;_ ,_abf =_aa .Unmarshal (_gee .Content ,&_gafg );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};_bfb ,_abf :=_gagc (_gafg .MessageImprint .HashAlgorithm .Algorithm );if _abf !=nil {return _b .SignatureValidationResult {},_abf ;};_bbd :=_bfb .New ();_beg :=digest .(*_f .Buffer );_bbd .Write (_beg .Bytes ());_cee :=_bbd .Sum (nil );_cac :=_b .SignatureValidationResult {IsSigned :true ,IsVerified :_f .Equal (_cee ,_gafg .MessageImprint .HashedMessage ),GeneralizedTime :_gafg .GeneralizedTime };return _cac ,nil ;};func _fede (_feg _cc .SignatureAlgorithm )(_e .Hash ,bool ){return _e .SHA1 ,true };
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_ebd *adobeX509RSASHA1 )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {var _cef []byte ;var _baa error ;if _ebd ._gac !=nil {_cef ,_baa =_ebd ._gac (sig ,digest );if _baa !=nil {return _baa ;};}else {_ceb ,_caa :=digest .(_ca .Hash );if !_caa {return _cf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_afd ,_ :=_fede (_ebd ._gag .SignatureAlgorithm );_cef ,_baa =_dd .SignPKCS1v15 (_aab .Reader ,_ebd ._ab ,_afd ,_ceb .Sum (nil ));if _baa !=nil {return _baa ;};};_cef ,_baa =_aa .Marshal (_cef );if _baa !=nil {return _baa ;};sig .Contents =_dcb .MakeHexString (string (_cef ));return nil ;};func (_fd *docTimeStamp )getCertificate (_fec *_b .PdfSignature )(*_cc .Certificate ,error ){var _gf []byte ;switch _bdcf :=_fec .Cert .(type ){case *_dcb .PdfObjectString :_gf =_bdcf .Bytes ();case *_dcb .PdfObjectArray :if _bdcf .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_geg :=range _bdcf .Elements (){_ebgd ,_dg :=_dcb .GetString (_geg );if !_dg {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_geg );};_gf =append (_gf ,_ebgd .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bdcf );};_cg ,_cfa :=_cc .ParseCertificates (_gf );if _cfa !=nil {return nil ,_cfa ;};return _cg [0],nil ;};
|
||||
|
||||
// Sign sets the Contents fields.
|
||||
func (_fa *adobePKCS7Detached )Sign (sig *_b .PdfSignature ,digest _b .Hasher )error {if _fa ._ba {_fed :=_fa ._ad ;if _fed <=0{_fed =8192;};sig .Contents =_dcb .MakeHexString (string (make ([]byte ,_fed )));return nil ;};_ga :=digest .(*_f .Buffer );_adg ,_ebg :=_cfb .NewSignedData (_ga .Bytes ());if _ebg !=nil {return _ebg ;};if _gae :=_adg .AddSigner (_fa ._bd ,_fa ._ge ,_cfb .SignerInfoConfig {});_gae !=nil {return _gae ;};_adg .Detach ();_ed ,_ebg :=_adg .Finish ();if _ebg !=nil {return _ebg ;};_cec :=make ([]byte ,8192);copy (_cec ,_ed );sig .Contents =_dcb .MakeHexString (string (_cec ));return nil ;};
|
||||
|
||||
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler
|
||||
// with a custom signing function. Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1Custom (certificate *_cc .Certificate ,signFunc SignFunc )(_b .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gag :certificate ,_gac :signFunc },nil ;};
|
||||
|
||||
// NewEmptyAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached
|
||||
// signature handler. The generated signature is empty and of size signatureLen.
|
||||
// The signatureLen parameter can be 0 for the signature validation.
|
||||
func NewEmptyAdobePKCS7Detached (signatureLen int )(_b .SignatureHandler ,error ){return &adobePKCS7Detached {_ba :true ,_ad :signatureLen },nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_ce *adobePKCS7Detached )Validate (sig *_b .PdfSignature ,digest _b .Hasher )(_b .SignatureValidationResult ,error ){_df :=sig .Contents .Bytes ();_ef ,_bfc :=_cfb .Parse (_df );if _bfc !=nil {return _b .SignatureValidationResult {},_bfc ;};_afg :=digest .(*_f .Buffer );_ef .Content =_afg .Bytes ();if _bfc =_ef .Verify ();_bfc !=nil {return _b .SignatureValidationResult {},_bfc ;};return _b .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_dcc *adobePKCS7Detached )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};
|
||||
|
||||
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobePKCS7Detached (privateKey *_dd .PrivateKey ,certificate *_cc .Certificate )(_b .SignatureHandler ,error ){return &adobePKCS7Detached {_bd :certificate ,_ge :privateKey },nil ;};
|
||||
package sighandler ;import (_b "bytes";_ce "crypto";_cea "crypto/rand";_fbe "crypto/rsa";_fd "crypto/x509";_be "crypto/x509/pkix";_gg "encoding/asn1";_gc "errors";_fe "fmt";_d "github.com/unidoc/pkcs7";_fg "github.com/unidoc/timestamp";_a "github.com/unidoc/unipdf/v3/core";_ec "github.com/unidoc/unipdf/v3/model";_fc "hash";_g "io";_e "io/ioutil";_fb "net/http";_c "time";);
|
||||
|
||||
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1 (privateKey *_dd .PrivateKey ,certificate *_cc .Certificate )(_b .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gag :certificate ,_ab :privateKey },nil ;};func _gagc (_fc _aa .ObjectIdentifier )(_e .Hash ,error ){switch {case _fc .Equal (_cfb .OIDDigestAlgorithmSHA1 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA1 ),_fc .Equal (_cfb .OIDDigestAlgorithmDSA ),_fc .Equal (_cfb .OIDDigestAlgorithmDSASHA1 ),_fc .Equal (_cfb .OIDEncryptionAlgorithmRSA ):return _e .SHA1 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA256 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA256 ):return _e .SHA256 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA384 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA384 ):return _e .SHA384 ,nil ;case _fc .Equal (_cfb .OIDDigestAlgorithmSHA512 ),_fc .Equal (_cfb .OIDDigestAlgorithmECDSASHA512 ):return _e .SHA512 ,nil ;};return _e .Hash (0),_cfb .ErrUnsupportedAlgorithm ;};
|
||||
func NewAdobeX509RSASHA1 (privateKey *_fbe .PrivateKey ,certificate *_fd .Certificate )(_ec .SignatureHandler ,error ){return &adobeX509RSASHA1 {_cbf :certificate ,_ccd :privateKey },nil ;};type timestampInfo struct{Version int ;Policy _gg .RawValue ;MessageImprint struct{HashAlgorithm _be .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _gg .RawValue ;GeneralizedTime _c .Time ;};type docTimeStamp struct{_dcf string ;_eff _ce .Hash ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_dbcf *adobeX509RSASHA1 )Sign (sig *_ec .PdfSignature ,digest _ec .Hasher )error {var _de []byte ;var _gac error ;if _dbcf ._gf !=nil {_de ,_gac =_dbcf ._gf (sig ,digest );if _gac !=nil {return _gac ;};}else {_ege ,_gfd :=digest .(_fc .Hash );if !_gfd {return _gc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_bgc ,_ :=_cfd (_dbcf ._cbf .SignatureAlgorithm );_de ,_gac =_fbe .SignPKCS1v15 (_cea .Reader ,_dbcf ._ccd ,_bgc ,_ege .Sum (nil ));if _gac !=nil {return _gac ;};};_de ,_gac =_gg .Marshal (_de );if _gac !=nil {return _gac ;};sig .Contents =_a .MakeHexString (string (_de ));return nil ;};
|
||||
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_cfe *_ec .PdfSignature ,_cae _ec .Hasher )([]byte ,error );
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_edg *docTimeStamp )NewDigest (sig *_ec .PdfSignature )(_ec .Hasher ,error ){return _b .NewBuffer (nil ),nil ;};
|
||||
|
||||
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler
|
||||
// with a custom signing function. Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1Custom (certificate *_fd .Certificate ,signFunc SignFunc )(_ec .SignatureHandler ,error ){return &adobeX509RSASHA1 {_cbf :certificate ,_gf :signFunc },nil ;};func (_bd *adobeX509RSASHA1 )getCertificate (_fbb *_ec .PdfSignature )(*_fd .Certificate ,error ){if _bd ._cbf !=nil {return _bd ._cbf ,nil ;};var _gga []byte ;switch _cca :=_fbb .Cert .(type ){case *_a .PdfObjectString :_gga =_cca .Bytes ();case *_a .PdfObjectArray :if _cca .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 _ ,_gb :=range _cca .Elements (){_cda ,_gce :=_a .GetString (_gb );if !_gce {return nil ,_fe .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",_gb );};_gga =append (_gga ,_cda .Bytes ()...);};default:return nil ,_fe .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",_cca );};_eed ,_ced :=_fd .ParseCertificates (_gga );if _ced !=nil {return nil ,_ced ;};return _eed [0],nil ;};
|
||||
|
||||
// Sign sets the Contents fields.
|
||||
func (_baab *adobePKCS7Detached )Sign (sig *_ec .PdfSignature ,digest _ec .Hasher )error {if _baab ._fcc {_ee :=_baab ._ae ;if _ee <=0{_ee =8192;};sig .Contents =_a .MakeHexString (string (make ([]byte ,_ee )));return nil ;};_dba :=digest .(*_b .Buffer );_ab ,_ecf :=_d .NewSignedData (_dba .Bytes ());if _ecf !=nil {return _ecf ;};if _fcd :=_ab .AddSigner (_baab ._df ,_baab ._ac ,_d .SignerInfoConfig {});_fcd !=nil {return _fcd ;};_ab .Detach ();_bc ,_ecf :=_ab .Finish ();if _ecf !=nil {return _ecf ;};_cbb :=make ([]byte ,8192);copy (_cbb ,_bc );sig .Contents =_a .MakeHexString (string (_cbb ));return nil ;};
|
||||
|
||||
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
|
||||
// The timestampServerURL parameter can be empty string for the signature validation.
|
||||
// The hashAlgorithm parameter can be crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _e .Hash )(_b .SignatureHandler ,error ){return &docTimeStamp {_ecc :timestampServerURL ,_bbc :hashAlgorithm },nil ;};
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _ce .Hash )(_ec .SignatureHandler ,error ){return &docTimeStamp {_dcf :timestampServerURL ,_eff :hashAlgorithm },nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_eef *adobeX509RSASHA1 )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};func (_ec *adobeX509RSASHA1 )getCertificate (_cfg *_b .PdfSignature )(*_cc .Certificate ,error ){if _ec ._gag !=nil {return _ec ._gag ,nil ;};var _gaf []byte ;switch _fgg :=_cfg .Cert .(type ){case *_dcb .PdfObjectString :_gaf =_fgg .Bytes ();case *_dcb .PdfObjectArray :if _fgg .Len ()==0{return nil ,_cf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_db :=range _fgg .Elements (){_gbe ,_gagg :=_dcb .GetString (_db );if !_gagg {return nil ,_eg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_db );};_gaf =append (_gaf ,_gbe .Bytes ()...);};default:return nil ,_eg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_fgg );};_ee ,_bg :=_cc .ParseCertificates (_gaf );if _bg !=nil {return nil ,_bg ;};return _ee [0],nil ;};type adobeX509RSASHA1 struct{_ab *_dd .PrivateKey ;_gag *_cc .Certificate ;_gac SignFunc ;};
|
||||
func (_dc *adobeX509RSASHA1 )IsApplicable (sig *_ec .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";};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_ggb *docTimeStamp )Validate (sig *_ec .PdfSignature ,digest _ec .Hasher )(_ec .SignatureValidationResult ,error ){_bdb :=sig .Contents .Bytes ();_cge ,_gdge :=_d .Parse (_bdb );if _gdge !=nil {return _ec .SignatureValidationResult {},_gdge ;};if _gdge =_cge .Verify ();_gdge !=nil {return _ec .SignatureValidationResult {},_gdge ;};var _bcc timestampInfo ;_ ,_gdge =_gg .Unmarshal (_cge .Content ,&_bcc );if _gdge !=nil {return _ec .SignatureValidationResult {},_gdge ;};_gbd ,_gdge :=_gdg (_bcc .MessageImprint .HashAlgorithm .Algorithm );if _gdge !=nil {return _ec .SignatureValidationResult {},_gdge ;};_dd :=_gbd .New ();_ace :=digest .(*_b .Buffer );_dd .Write (_ace .Bytes ());_fgdf :=_dd .Sum (nil );_eab :=_ec .SignatureValidationResult {IsSigned :true ,IsVerified :_b .Equal (_fgdf ,_bcc .MessageImprint .HashedMessage ),GeneralizedTime :_bcc .GeneralizedTime };return _eab ,nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_ea *docTimeStamp )InitSignature (sig *_ec .PdfSignature )error {_eba :=*_ea ;sig .Handler =&_eba ;sig .Filter =_a .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_a .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;_bbe ,_afc :=_ea .NewDigest (sig );if _afc !=nil {return _afc ;};_bbe .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 _eba .Sign (sig ,_bbe );};
|
||||
|
||||
// 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 *_fbe .PrivateKey ,certificate *_fd .Certificate )(_ec .SignatureHandler ,error ){return &adobePKCS7Detached {_df :certificate ,_ac :privateKey },nil ;};func (_cb *adobePKCS7Detached )getCertificate (_dg *_ec .PdfSignature )(*_fd .Certificate ,error ){if _cb ._df !=nil {return _cb ._df ,nil ;};var _eg []byte ;switch _aed :=_dg .Cert .(type ){case *_a .PdfObjectString :_eg =_aed .Bytes ();case *_a .PdfObjectArray :if _aed .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 _ ,_fee :=range _aed .Elements (){_db ,_ef :=_a .GetString (_fee );if !_ef {return nil ,_fe .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",_fee );};_eg =append (_eg ,_db .Bytes ()...);};default:return nil ,_fe .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",_aed );};_bb ,_gde :=_fd .ParseCertificates (_eg );if _gde !=nil {return nil ,_gde ;};return _bb [0],nil ;};type adobeX509RSASHA1 struct{_ccd *_fbe .PrivateKey ;_cbf *_fd .Certificate ;_gf SignFunc ;};func _cfd (_cfdd _fd .SignatureAlgorithm )(_ce .Hash ,bool ){var _fgd _ce .Hash ;switch _cfdd {case _fd .SHA1WithRSA :_fgd =_ce .SHA1 ;case _fd .SHA256WithRSA :_fgd =_ce .SHA256 ;case _fd .SHA384WithRSA :_fgd =_ce .SHA384 ;case _fd .SHA512WithRSA :_fgd =_ce .SHA512 ;default:return _ce .SHA1 ,false ;};return _fgd ,true ;};func (_ece *docTimeStamp )getCertificate (_gced *_ec .PdfSignature )(*_fd .Certificate ,error ){var _cbfc []byte ;switch _bgcg :=_gced .Cert .(type ){case *_a .PdfObjectString :_cbfc =_bgcg .Bytes ();case *_a .PdfObjectArray :if _bgcg .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 _ ,_gfe :=range _bgcg .Elements (){_fde ,_bdc :=_a .GetString (_gfe );if !_bdc {return nil ,_fe .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",_gfe );};_cbfc =append (_cbfc ,_fde .Bytes ()...);};default:return nil ,_fe .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",_bgcg );};_eee ,_cdg :=_fd .ParseCertificates (_cbfc );if _cdg !=nil {return nil ,_cdg ;};return _eee [0],nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_cg *adobePKCS7Detached )IsApplicable (sig *_ec .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};type adobePKCS7Detached struct{_ac *_fbe .PrivateKey ;_df *_fd .Certificate ;_fcc bool ;_ae int ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_fef *docTimeStamp )IsApplicable (sig *_b .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};
|
||||
func (_gag *docTimeStamp )IsApplicable (sig *_ec .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_ga *adobeX509RSASHA1 )NewDigest (sig *_ec .PdfSignature )(_ec .Hasher ,error ){_dbc ,_fcg :=_ga .getCertificate (sig );if _fcg !=nil {return nil ,_fcg ;};_gdb ,_ :=_cfd (_dbc .SignatureAlgorithm );return _gdb .New (),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 )(_ec .SignatureHandler ,error ){return &adobePKCS7Detached {_fcc :true ,_ae :signatureLen },nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_cd *adobePKCS7Detached )Validate (sig *_ec .PdfSignature ,digest _ec .Hasher )(_ec .SignatureValidationResult ,error ){_cc :=sig .Contents .Bytes ();_ff ,_dbd :=_d .Parse (_cc );if _dbd !=nil {return _ec .SignatureValidationResult {},_dbd ;};_ca :=digest .(*_b .Buffer );_ff .Content =_ca .Bytes ();if _dbd =_ff .Verify ();_dbd !=nil {return _ec .SignatureValidationResult {},_dbd ;};return _ec .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_baa *adobePKCS7Detached )NewDigest (sig *_ec .PdfSignature )(_ec .Hasher ,error ){return _b .NewBuffer (nil ),nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_cecd *adobeX509RSASHA1 )InitSignature (sig *_b .PdfSignature )error {if _cecd ._gag ==nil {return _cf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _cecd ._ab ==nil &&_cecd ._gac ==nil {return _cf .New ("\u006d\u0075\u0073\u0074\u0020\u0070\u0072o\u0076\u0069\u0064e\u0020\u0065\u0069t\u0068\u0065r\u0020\u0061\u0020\u0070\u0072\u0069v\u0061te\u0020\u006b\u0065\u0079\u0020\u006f\u0072\u0020\u0061\u0020\u0073\u0069\u0067\u006e\u0069\u006e\u0067\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_bb :=*_cecd ;sig .Handler =&_bb ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_dcb .MakeString (string (_bb ._gag .Raw ));sig .Reference =nil ;_ced ,_aaa :=_bb .NewDigest (sig );if _aaa !=nil {return _aaa ;};_ced .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _bb .Sign (sig ,_ced );};
|
||||
func (_fccd *adobeX509RSASHA1 )InitSignature (sig *_ec .PdfSignature )error {if _fccd ._cbf ==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 _fccd ._ccd ==nil &&_fccd ._gf ==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");};_eb :=*_fccd ;sig .Handler =&_eb ;sig .Filter =_a .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_a .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_a .MakeString (string (_eb ._cbf .Raw ));sig .Reference =nil ;_ed ,_dbe :=_eb .NewDigest (sig );if _dbe !=nil {return _dbe ;};_ed .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 _eb .Sign (sig ,_ed );};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_fff *adobeX509RSASHA1 )Validate (sig *_ec .PdfSignature ,digest _ec .Hasher )(_ec .SignatureValidationResult ,error ){_aa ,_bab :=_fff .getCertificate (sig );if _bab !=nil {return _ec .SignatureValidationResult {},_bab ;};_da :=sig .Contents .Bytes ();var _af []byte ;if _ ,_ebc :=_gg .Unmarshal (_da ,&_af );_ebc !=nil {return _ec .SignatureValidationResult {},_ebc ;};_dgg ,_ccc :=digest .(_fc .Hash );if !_ccc {return _ec .SignatureValidationResult {},_gc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_bg ,_ :=_cfd (_aa .SignatureAlgorithm );if _fbf :=_fbe .VerifyPKCS1v15 (_aa .PublicKey .(*_fbe .PublicKey ),_bg ,_dgg .Sum (nil ),_af );_fbf !=nil {return _ec .SignatureValidationResult {},_fbf ;};return _ec .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};func _gdg (_geg _gg .ObjectIdentifier )(_ce .Hash ,error ){switch {case _geg .Equal (_d .OIDDigestAlgorithmSHA1 ),_geg .Equal (_d .OIDDigestAlgorithmECDSASHA1 ),_geg .Equal (_d .OIDDigestAlgorithmDSA ),_geg .Equal (_d .OIDDigestAlgorithmDSASHA1 ),_geg .Equal (_d .OIDEncryptionAlgorithmRSA ):return _ce .SHA1 ,nil ;case _geg .Equal (_d .OIDDigestAlgorithmSHA256 ),_geg .Equal (_d .OIDDigestAlgorithmECDSASHA256 ):return _ce .SHA256 ,nil ;case _geg .Equal (_d .OIDDigestAlgorithmSHA384 ),_geg .Equal (_d .OIDDigestAlgorithmECDSASHA384 ):return _ce .SHA384 ,nil ;case _geg .Equal (_d .OIDDigestAlgorithmSHA512 ),_geg .Equal (_d .OIDDigestAlgorithmECDSASHA512 ):return _ce .SHA512 ,nil ;};return _ce .Hash (0),_d .ErrUnsupportedAlgorithm ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_ffc *docTimeStamp )Sign (sig *_ec .PdfSignature ,digest _ec .Hasher )error {_fgc :=digest .(*_b .Buffer );_agb :=_ffc ._eff .New ();if _ ,_aee :=_g .Copy (_agb ,_fgc );_aee !=nil {return _aee ;};_dae :=_agb .Sum (nil );_fbc :=_fg .Request {HashAlgorithm :_ffc ._eff ,HashedMessage :_dae ,Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_cega ,_caf :=_fbc .Marshal ();if _caf !=nil {return _caf ;};_daa ,_caf :=_fb .Post (_ffc ._dcf ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_b .NewBuffer (_cega ));if _caf !=nil {return _caf ;};defer _daa .Body .Close ();_gfdf ,_caf :=_e .ReadAll (_daa .Body );if _caf !=nil {return _caf ;};if _daa .StatusCode !=_fb .StatusOK {return _fe .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",_daa .StatusCode );};var _ad struct{Version _gg .RawValue ;Content _gg .RawValue ;};_ ,_caf =_gg .Unmarshal (_gfdf ,&_ad );if _caf !=nil {return _caf ;};sig .Contents =_a .MakeHexString (string (_ad .Content .FullBytes ));return nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_abe *docTimeStamp )InitSignature (sig *_b .PdfSignature )error {_fb :=*_abe ;sig .Handler =&_fb ;sig .Filter =_dcb .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_dcb .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;_dae ,_afe :=_abe .NewDigest (sig );if _afe !=nil {return _afe ;};_dae .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _fb .Sign (sig ,_dae );};
|
||||
func (_ba *adobePKCS7Detached )InitSignature (sig *_ec .PdfSignature )error {if !_ba ._fcc {if _ba ._df ==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 _ba ._ac ==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");};};_cf :=*_ba ;sig .Handler =&_cf ;sig .Filter =_a .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_a .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_cfc ,_fbed :=_cf .NewDigest (sig );if _fbed !=nil {return _fbed ;};_cfc .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 _cf .Sign (sig ,_cfc );};
|
19
pdfutil/pdfutil.go
Normal file
19
pdfutil/pdfutil.go
Normal file
@ -0,0 +1,19 @@
|
||||
//
|
||||
// Copyright 2020 FoxyUtils ehf. All rights reserved.
|
||||
//
|
||||
// This is a commercial product and requires a license to operate.
|
||||
// A trial license can be obtained at https://unidoc.io
|
||||
//
|
||||
// DO NOT EDIT: generated by unitwist Go source code obfuscator.
|
||||
//
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package pdfutil ;import (_a "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/contentstream";_ge "github.com/unidoc/unipdf/v3/contentstream/draw";_g "github.com/unidoc/unipdf/v3/model";);
|
||||
|
||||
// NormalizePage rotates the contents of the passed in page according to its
|
||||
// Rotate entry (i.e. flattens the rotation). If rotation is applied, the
|
||||
// Rotate entry of the page is set to nil.
|
||||
// After normalization, the page should look the same if openend using a
|
||||
// PDF viewer.
|
||||
func NormalizePage (page *_g .PdfPage )error {if _ae :=page .Rotate ;_ae ==nil ||*_ae ==0||*_ae %90!=0{return nil ;};_gg ,_f :=page .GetMediaBox ();if _f !=nil {return _f ;};_e ,_f :=page .GetContentStreams ();if _f !=nil {return _f ;};_gc ,_ff :=_gg .Width (),_gg .Height ();_ag :=-float64 (*page .Rotate );_cc :=_ge .Path {Points :[]_ge .Point {_ge .NewPoint (0,0).Rotate (_ag ),_ge .NewPoint (_gc ,0).Rotate (_ag ),_ge .NewPoint (0,_ff ).Rotate (_ag ),_ge .NewPoint (_gc ,_ff ).Rotate (_ag )}}.GetBoundingBox ();_bb :=-_gg .Llx +(_cc .Width -_gc )/2+_gc /2;_ef :=_gg .Lly +(_cc .Height -_ff )/2+_ff /2;_d :=_b .NewContentCreator ();_d .Translate (_bb ,_ef );_d .RotateDeg (_ag );_d .Translate (-_gc /2,-_ff /2);_fg :=_d .Operations ().String ();*_gg =_g .PdfRectangle {Urx :_cc .Width ,Ury :_cc .Height };_e =append ([]string {_fg },_e ...);if _f =page .SetContentStreams (_e ,nil );_f !=nil {return _f ;};_a .Log .Debug ("\u0052o\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u0025\u0071 \u006d\u0062\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ag ,_fg ,*_gg );page .Rotate =nil ;return nil ;};
|
152
ps/ps.go
152
ps/ps.go
@ -14,36 +14,35 @@
|
||||
//
|
||||
// Package ps implements various functionalities needed for handling Postscript for PDF uses, in particular
|
||||
// for PDF function type 4.
|
||||
package ps ;import (_fe "bufio";_d "bytes";_e "errors";_fg "fmt";_b "github.com/unidoc/unipdf/v3/common";_feb "github.com/unidoc/unipdf/v3/core";_ea "io";_eg "math";);func (_ffac *PSOperand )sin (_ddb *PSStack )error {_afgc ,_geea :=_ddb .PopNumberAsFloat64 ();if _geea !=nil {return _geea ;};_eafa :=_eg .Sin (_afgc *_eg .Pi /180.0);_geea =_ddb .Push (MakeReal (_eafa ));return _geea ;};func (_dbe *PSOperand )copy (_cddb *PSStack )error {_deg ,_gab :=_cddb .PopInteger ();if _gab !=nil {return _gab ;};if _deg < 0{return ErrRangeCheck ;};if _deg > len (*_cddb ){return ErrRangeCheck ;};*_cddb =append (*_cddb ,(*_cddb )[len (*_cddb )-_deg :]...);return nil ;};func (_cab *PSOperand )DebugString ()string {return _fg .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_cab );};
|
||||
package ps ;import (_df "bufio";_c "bytes";_d "errors";_e "fmt";_dfe "github.com/unidoc/unipdf/v3/common";_cd "github.com/unidoc/unipdf/v3/core";_b "io";_bb "math";);
|
||||
|
||||
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
|
||||
type PSExecutor struct{Stack *PSStack ;_fb *PSProgram ;};
|
||||
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
|
||||
func NewPSParser (content []byte )*PSParser {_facc :=PSParser {};_acc :=_c .NewBuffer (content );_facc ._acfg =_df .NewReader (_acc );return &_facc ;};var ErrTypeCheck =_d .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");
|
||||
|
||||
// MakeBool returns a new PSBoolean object initialized with `val`.
|
||||
func MakeBool (val bool )*PSBoolean {_ade :=PSBoolean {};_ade .Val =val ;return &_ade };func (_gdg *PSOperand )ifCondition (_caff *PSStack )error {_edc ,_afc :=_caff .Pop ();if _afc !=nil {return _afc ;};_aac ,_afc :=_caff .Pop ();if _afc !=nil {return _afc ;};_gbfd ,_abad :=_edc .(*PSProgram );if !_abad {return ErrTypeCheck ;};_cba ,_abad :=_aac .(*PSBoolean );if !_abad {return ErrTypeCheck ;};if _cba .Val {_eaf :=_gbfd .Exec (_caff );return _eaf ;};return nil ;};
|
||||
|
||||
// Exec executes the program, typically leaving output values on the stack.
|
||||
func (_cdd *PSProgram )Exec (stack *PSStack )error {for _ ,_fdf :=range *_cdd {var _fgd error ;switch _dcg :=_fdf .(type ){case *PSInteger :_cfd :=_dcg ;_fgd =stack .Push (_cfd );case *PSReal :_caa :=_dcg ;_fgd =stack .Push (_caa );case *PSBoolean :_fc :=_dcg ;_fgd =stack .Push (_fc );case *PSProgram :_egf :=_dcg ;_fgd =stack .Push (_egf );case *PSOperand :_geb :=_dcg ;_fgd =_geb .Exec (stack );default:return ErrTypeCheck ;};if _fgd !=nil {return _fgd ;};};return nil ;};func (_ge *PSInteger )Duplicate ()PSObject {_c :=PSInteger {};_c .Val =_ge .Val ;return &_c };func (_decc *PSOperand )sub (_fgdb *PSStack )error {_gce ,_gadb :=_fgdb .Pop ();if _gadb !=nil {return _gadb ;};_ddga ,_gadb :=_fgdb .Pop ();if _gadb !=nil {return _gadb ;};_agg ,_dcec :=_gce .(*PSReal );_badc ,_gefb :=_gce .(*PSInteger );if !_dcec &&!_gefb {return ErrTypeCheck ;};_efd ,_acg :=_ddga .(*PSReal );_aaa ,_fdd :=_ddga .(*PSInteger );if !_acg &&!_fdd {return ErrTypeCheck ;};if _gefb &&_fdd {_gca :=_aaa .Val -_badc .Val ;_ffef :=_fgdb .Push (MakeInteger (_gca ));return _ffef ;};var _bbcfb float64 =0;if _acg {_bbcfb =_efd .Val ;}else {_bbcfb =float64 (_aaa .Val );};if _dcec {_bbcfb -=_agg .Val ;}else {_bbcfb -=float64 (_badc .Val );};_gadb =_fgdb .Push (MakeReal (_bbcfb ));return _gadb ;};var ErrTypeCheck =_e .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");
|
||||
|
||||
// MakeOperand returns a new PSOperand object based on string `val`.
|
||||
func MakeOperand (val string )*PSOperand {_gfeea :=PSOperand (val );return &_gfeea };func (_cbe *PSOperand )gt (_cae *PSStack )error {_ded ,_gec :=_cae .PopNumberAsFloat64 ();if _gec !=nil {return _gec ;};_dbed ,_gec :=_cae .PopNumberAsFloat64 ();if _gec !=nil {return _gec ;};if _eg .Abs (_dbed -_ded )< _a {_eea :=_cae .Push (MakeBool (false ));return _eea ;}else if _dbed > _ded {_fda :=_cae .Push (MakeBool (true ));return _fda ;}else {_egb :=_cae .Push (MakeBool (false ));return _egb ;};};
|
||||
|
||||
// PSObjectArrayToFloat64Array converts []PSObject into a []float64 array. Each PSObject must represent a number,
|
||||
// otherwise a ErrTypeCheck error occurs.
|
||||
func PSObjectArrayToFloat64Array (objects []PSObject )([]float64 ,error ){var _ff []float64 ;for _ ,_ac :=range objects {if _acc ,_g :=_ac .(*PSInteger );_g {_ff =append (_ff ,float64 (_acc .Val ));}else if _eb ,_af :=_ac .(*PSReal );_af {_ff =append (_ff ,_eb .Val );}else {return nil ,ErrTypeCheck ;};};return _ff ,nil ;};func (_cag *PSOperand )add (_dac *PSStack )error {_bae ,_gcb :=_dac .Pop ();if _gcb !=nil {return _gcb ;};_baf ,_gcb :=_dac .Pop ();if _gcb !=nil {return _gcb ;};_bbd ,_dea :=_bae .(*PSReal );_ffg ,_df :=_bae .(*PSInteger );if !_dea &&!_df {return ErrTypeCheck ;};_dec ,_agf :=_baf .(*PSReal );_bdc ,_gbc :=_baf .(*PSInteger );if !_agf &&!_gbc {return ErrTypeCheck ;};if _df &&_gbc {_ffb :=_ffg .Val +_bdc .Val ;_gee :=_dac .Push (MakeInteger (_ffb ));return _gee ;};var _adg float64 =0;if _dea {_adg =_bbd .Val ;}else {_adg =float64 (_ffg .Val );};if _agf {_adg +=_dec .Val ;}else {_adg +=float64 (_bdc .Val );};_gcb =_dac .Push (MakeReal (_adg ));return _gcb ;};var ErrRangeCheck =_e .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_cce *PSOperand )lt (_cbfa *PSStack )error {_agcf ,_gag :=_cbfa .PopNumberAsFloat64 ();if _gag !=nil {return _gag ;};_fggb ,_gag :=_cbfa .PopNumberAsFloat64 ();if _gag !=nil {return _gag ;};if _eg .Abs (_fggb -_agcf )< _a {_cgc :=_cbfa .Push (MakeBool (false ));return _cgc ;}else if _fggb < _agcf {_dggb :=_cbfa .Push (MakeBool (true ));return _dggb ;}else {_bbdg :=_cbfa .Push (MakeBool (false ));return _bbdg ;};};func _abbb (_dfaa int )int {if _dfaa < 0{return -_dfaa ;};return _dfaa ;};var ErrUndefinedResult =_e .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_ag *PSProgram )DebugString ()string {_gb :="\u007b\u0020";for _ ,_ffc :=range *_ag {_gb +=_ffc .DebugString ();_gb +="\u0020";};_gb +="\u007d";return _gb ;};func (_agfa *PSOperand )div (_cda *PSStack )error {_dbd ,_dcge :=_cda .Pop ();if _dcge !=nil {return _dcge ;};_cdf ,_dcge :=_cda .Pop ();if _dcge !=nil {return _dcge ;};_bbcf ,_dd :=_dbd .(*PSReal );_acb ,_ada :=_dbd .(*PSInteger );if !_dd &&!_ada {return ErrTypeCheck ;};if _dd &&_bbcf .Val ==0{return ErrUndefinedResult ;};if _ada &&_acb .Val ==0{return ErrUndefinedResult ;};_fcg ,_bafe :=_cdf .(*PSReal );_eeb ,_gd :=_cdf .(*PSInteger );if !_bafe &&!_gd {return ErrTypeCheck ;};var _cca float64 =0;if _bafe {_cca =_fcg .Val ;}else {_cca =float64 (_eeb .Val );};if _dd {_cca /=_bbcf .Val ;}else {_cca /=float64 (_acb .Val );};_dcge =_cda .Push (MakeReal (_cca ));return _dcge ;};func (_ebab *PSOperand )mod (_fbd *PSStack )error {_adbe ,_gdgg :=_fbd .Pop ();if _gdgg !=nil {return _gdgg ;};_edg ,_gdgg :=_fbd .Pop ();if _gdgg !=nil {return _gdgg ;};_gfg ,_bcag :=_adbe .(*PSInteger );if !_bcag {return ErrTypeCheck ;};if _gfg .Val ==0{return ErrUndefinedResult ;};_ecc ,_bcag :=_edg .(*PSInteger );if !_bcag {return ErrTypeCheck ;};_cgdd :=_ecc .Val %_gfg .Val ;_gdgg =_fbd .Push (MakeInteger (_cgdd ));return _gdgg ;};func (_dcc *PSOperand )dup (_bcc *PSStack )error {_fgg ,_eggd :=_bcc .Pop ();if _eggd !=nil {return _eggd ;};_eggd =_bcc .Push (_fgg );if _eggd !=nil {return _eggd ;};_eggd =_bcc .Push (_fgg .Duplicate ());return _eggd ;};func (_ebd *PSOperand )bitshift (_dgb *PSStack )error {_dgf ,_ed :=_dgb .PopInteger ();if _ed !=nil {return _ed ;};_bgec ,_ed :=_dgb .PopInteger ();if _ed !=nil {return _ed ;};var _eca int ;if _dgf >=0{_eca =_bgec <<uint (_dgf );}else {_eca =_bgec >>uint (-_dgf );};_ed =_dgb .Push (MakeInteger (_eca ));return _ed ;};func (_cegf *PSOperand )atan (_dee *PSStack )error {_adb ,_aag :=_dee .PopNumberAsFloat64 ();if _aag !=nil {return _aag ;};_egg ,_aag :=_dee .PopNumberAsFloat64 ();if _aag !=nil {return _aag ;};if _adb ==0{var _bba error ;if _egg < 0{_bba =_dee .Push (MakeReal (270));}else {_bba =_dee .Push (MakeReal (90));};return _bba ;};_cdde :=_egg /_adb ;_dfgf :=_eg .Atan (_cdde )*180/_eg .Pi ;_aag =_dee .Push (MakeReal (_dfgf ));return _aag ;};
|
||||
// Pop pops an object from the top of the stack.
|
||||
func (_bcg *PSStack )Pop ()(PSObject ,error ){if len (*_bcg )< 1{return nil ,ErrStackUnderflow ;};_bdc :=(*_bcg )[len (*_bcg )-1];*_bcg =(*_bcg )[0:len (*_bcg )-1];return _bdc ,nil ;};func (_dba *PSProgram )String ()string {_ec :="\u007b\u0020";for _ ,_ag :=range *_dba {_ec +=_ag .String ();_ec +="\u0020";};_ec +="\u007d";return _ec ;};var ErrStackUnderflow =_d .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");
|
||||
|
||||
// PopNumberAsFloat64 pops and return the numeric value of the top of the stack as a float64.
|
||||
// Real or integer only.
|
||||
func (_ccea *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_ebc ,_gfa :=_ccea .Pop ();if _gfa !=nil {return 0,_gfa ;};if _bgfd ,_ffgd :=_ebc .(*PSReal );_ffgd {return _bgfd .Val ,nil ;}else if _gagc ,_ggd :=_ebc .(*PSInteger );_ggd {return float64 (_gagc .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_ebb *PSOperand )sqrt (_gbag *PSStack )error {_fcfe ,_dcaa :=_gbag .PopNumberAsFloat64 ();if _dcaa !=nil {return _dcaa ;};if _fcfe < 0{return ErrRangeCheck ;};_gad :=_eg .Sqrt (_fcfe );_dcaa =_gbag .Push (MakeReal (_gad ));return _dcaa ;};func (_dce *PSOperand )cvr (_gbf *PSStack )error {_bbc ,_ega :=_gbf .Pop ();if _ega !=nil {return _ega ;};if _baa ,_ebf :=_bbc .(*PSReal );_ebf {_ega =_gbf .Push (MakeReal (_baa .Val ));}else if _bdad ,_dead :=_bbc .(*PSInteger );_dead {_ega =_gbf .Push (MakeReal (float64 (_bdad .Val )));}else {return ErrTypeCheck ;};return _ega ;};
|
||||
func (_cecd *PSStack )PopNumberAsFloat64 ()(float64 ,error ){_acgg ,_eeec :=_cecd .Pop ();if _eeec !=nil {return 0,_eeec ;};if _aggd ,_ddbe :=_acgg .(*PSReal );_ddbe {return _aggd .Val ,nil ;}else if _acec ,_bfeg :=_acgg .(*PSInteger );_bfeg {return float64 (_acec .Val ),nil ;}else {return 0,ErrTypeCheck ;};};func (_bf *PSReal )Duplicate ()PSObject {_g :=PSReal {};_g .Val =_bf .Val ;return &_g };func (_beeg *PSOperand )roll (_gde *PSStack )error {_ged ,_abg :=_gde .Pop ();if _abg !=nil {return _abg ;};_ecd ,_abg :=_gde .Pop ();if _abg !=nil {return _abg ;};_caec ,_fdcf :=_ged .(*PSInteger );if !_fdcf {return ErrTypeCheck ;};_ecggb ,_fdcf :=_ecd .(*PSInteger );if !_fdcf {return ErrTypeCheck ;};if _ecggb .Val < 0{return ErrRangeCheck ;};if _ecggb .Val ==0||_ecggb .Val ==1{return nil ;};if _ecggb .Val > len (*_gde ){return ErrStackUnderflow ;};for _dbgf :=0;_dbgf < _dfg (_caec .Val );_dbgf ++{var _edd []PSObject ;_edd =(*_gde )[len (*_gde )-(_ecggb .Val ):len (*_gde )];if _caec .Val > 0{_gaed :=_edd [len (_edd )-1];_edd =append ([]PSObject {_gaed },_edd [0:len (_edd )-1]...);}else {_gfd :=_edd [len (_edd )-_ecggb .Val ];_edd =append (_edd [1:],_gfd );};_fcf :=append ((*_gde )[0:len (*_gde )-_ecggb .Val ],_edd ...);_gde =&_fcf ;};return nil ;};
|
||||
|
||||
// PSInteger represents an integer.
|
||||
type PSInteger struct{Val int ;};func (_bf *PSProgram )String ()string {_ca :="\u007b\u0020";for _ ,_afg :=range *_bf {_ca +=_afg .String ();_ca +="\u0020";};_ca +="\u007d";return _ca ;};func (_gae *PSOperand )ln (_edce *PSStack )error {_gdb ,_gacg :=_edce .PopNumberAsFloat64 ();if _gacg !=nil {return _gacg ;};_cabc :=_eg .Log (_gdb );_gacg =_edce .Push (MakeReal (_cabc ));return _gacg ;};
|
||||
// Exec executes the operand `op` in the state specified by `stack`.
|
||||
func (_cc *PSOperand )Exec (stack *PSStack )error {_bbc :=ErrUnsupportedOperand ;switch *_cc {case "\u0061\u0062\u0073":_bbc =_cc .abs (stack );case "\u0061\u0064\u0064":_bbc =_cc .add (stack );case "\u0061\u006e\u0064":_bbc =_cc .and (stack );case "\u0061\u0074\u0061\u006e":_bbc =_cc .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_bbc =_cc .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_bbc =_cc .ceiling (stack );case "\u0063\u006f\u0070\u0079":_bbc =_cc .copy (stack );case "\u0063\u006f\u0073":_bbc =_cc .cos (stack );case "\u0063\u0076\u0069":_bbc =_cc .cvi (stack );case "\u0063\u0076\u0072":_bbc =_cc .cvr (stack );case "\u0064\u0069\u0076":_bbc =_cc .div (stack );case "\u0064\u0075\u0070":_bbc =_cc .dup (stack );case "\u0065\u0071":_bbc =_cc .eq (stack );case "\u0065\u0078\u0063\u0068":_bbc =_cc .exch (stack );case "\u0065\u0078\u0070":_bbc =_cc .exp (stack );case "\u0066\u006c\u006fo\u0072":_bbc =_cc .floor (stack );case "\u0067\u0065":_bbc =_cc .ge (stack );case "\u0067\u0074":_bbc =_cc .gt (stack );case "\u0069\u0064\u0069\u0076":_bbc =_cc .idiv (stack );case "\u0069\u0066":_bbc =_cc .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_bbc =_cc .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_bbc =_cc .index (stack );case "\u006c\u0065":_bbc =_cc .le (stack );case "\u006c\u006f\u0067":_bbc =_cc .log (stack );case "\u006c\u006e":_bbc =_cc .ln (stack );case "\u006c\u0074":_bbc =_cc .lt (stack );case "\u006d\u006f\u0064":_bbc =_cc .mod (stack );case "\u006d\u0075\u006c":_bbc =_cc .mul (stack );case "\u006e\u0065":_bbc =_cc .ne (stack );case "\u006e\u0065\u0067":_bbc =_cc .neg (stack );case "\u006e\u006f\u0074":_bbc =_cc .not (stack );case "\u006f\u0072":_bbc =_cc .or (stack );case "\u0070\u006f\u0070":_bbc =_cc .pop (stack );case "\u0072\u006f\u0075n\u0064":_bbc =_cc .round (stack );case "\u0072\u006f\u006c\u006c":_bbc =_cc .roll (stack );case "\u0073\u0069\u006e":_bbc =_cc .sin (stack );case "\u0073\u0071\u0072\u0074":_bbc =_cc .sqrt (stack );case "\u0073\u0075\u0062":_bbc =_cc .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_bbc =_cc .truncate (stack );case "\u0078\u006f\u0072":_bbc =_cc .xor (stack );};return _bbc ;};
|
||||
|
||||
// Append appends an object to the PSProgram.
|
||||
func (_aa *PSProgram )Append (obj PSObject ){*_aa =append (*_aa ,obj )};func (_bbg *PSOperand )ne (_cfaa *PSStack )error {_bbgd :=_bbg .eq (_cfaa );if _bbgd !=nil {return _bbgd ;};_bbgd =_bbg .not (_cfaa );return _bbgd ;};func (_ga *PSProgram )Duplicate ()PSObject {_db :=&PSProgram {};for _ ,_caf :=range *_ga {_db .Append (_caf .Duplicate ());};return _db ;};
|
||||
// MakeInteger returns a new PSInteger object initialized with `val`.
|
||||
func MakeInteger (val int )*PSInteger {_ccdg :=PSInteger {};_ccdg .Val =val ;return &_ccdg };func (_gfca *PSOperand )exp (_gee *PSStack )error {_afc ,_fba :=_gee .PopNumberAsFloat64 ();if _fba !=nil {return _fba ;};_fabf ,_fba :=_gee .PopNumberAsFloat64 ();if _fba !=nil {return _fba ;};if _bb .Abs (_afc )< 1&&_fabf < 0{return ErrUndefinedResult ;};_egbf :=_bb .Pow (_fabf ,_afc );_fba =_gee .Push (MakeReal (_egbf ));return _fba ;};func (_eecb *PSOperand )ln (_ebbe *PSStack )error {_dag ,_adce :=_ebbe .PopNumberAsFloat64 ();if _adce !=nil {return _adce ;};_ccga :=_bb .Log (_dag );_adce =_ebbe .Push (MakeReal (_ccga ));return _adce ;};func (_abga *PSParser )parseNumber ()(PSObject ,error ){_bege ,_bfge :=_cd .ParseNumber (_abga ._acfg );if _bfge !=nil {return nil ,_bfge ;};switch _ddaf :=_bege .(type ){case *_cd .PdfObjectFloat :return MakeReal (float64 (*_ddaf )),nil ;case *_cd .PdfObjectInteger :return MakeInteger (int (*_ddaf )),nil ;};return nil ,_e .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_bege );};
|
||||
|
||||
// String returns a string representation of the stack.
|
||||
func (_gfee *PSStack )String ()string {_bdge :="\u005b\u0020";for _ ,_agfd :=range *_gfee {_bdge +=_agfd .String ();_bdge +="\u0020";};_bdge +="\u005d";return _bdge ;};
|
||||
// PSReal represents a real number.
|
||||
type PSReal struct{Val float64 ;};
|
||||
|
||||
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
|
||||
type PSProgram []PSObject ;
|
||||
|
||||
// PSBoolean represents a boolean value.
|
||||
type PSBoolean struct{Val bool ;};func (_eac *PSOperand )copy (_aed *PSStack )error {_eaa ,_cgf :=_aed .PopInteger ();if _cgf !=nil {return _cgf ;};if _eaa < 0{return ErrRangeCheck ;};if _eaa > len (*_aed ){return ErrRangeCheck ;};*_aed =append (*_aed ,(*_aed )[len (*_aed )-_eaa :]...);return nil ;};func _dfg (_ggb int )int {if _ggb < 0{return -_ggb ;};return _ggb ;};func (_bfce *PSOperand )mul (_gaf *PSStack )error {_bfbb ,_cdgf :=_gaf .Pop ();if _cdgf !=nil {return _cdgf ;};_cda ,_cdgf :=_gaf .Pop ();if _cdgf !=nil {return _cdgf ;};_ccc ,_afe :=_bfbb .(*PSReal );_gbd ,_bfcc :=_bfbb .(*PSInteger );if !_afe &&!_bfcc {return ErrTypeCheck ;};_ccd ,_bbbc :=_cda .(*PSReal );_ddd ,_gfg :=_cda .(*PSInteger );if !_bbbc &&!_gfg {return ErrTypeCheck ;};if _bfcc &&_gfg {_cge :=_gbd .Val *_ddd .Val ;_cce :=_gaf .Push (MakeInteger (_cge ));return _cce ;};var _dgd float64 =0;if _afe {_dgd =_ccc .Val ;}else {_dgd =float64 (_gbd .Val );};if _bbbc {_dgd *=_ccd .Val ;}else {_dgd *=float64 (_ddd .Val );};_cdgf =_gaf .Push (MakeReal (_dgd ));return _cdgf ;};
|
||||
|
||||
// NewPSStack returns an initialized PSStack.
|
||||
func NewPSStack ()*PSStack {return &PSStack {}};
|
||||
|
||||
// PSObject represents a postscript object.
|
||||
type PSObject interface{
|
||||
@ -56,64 +55,65 @@ Duplicate ()PSObject ;
|
||||
DebugString ()string ;
|
||||
|
||||
// String returns a string representation of the PSObject.
|
||||
String ()string ;};func (_ad *PSOperand )String ()string {return _fg .Sprintf ("\u0025\u0073",*_ad )};func (_gc *PSOperand )Duplicate ()PSObject {_fde :=*_gc ;return &_fde };func (_bbde *PSOperand )ceiling (_bda *PSStack )error {_decb ,_ace :=_bda .Pop ();if _ace !=nil {return _ace ;};if _efc ,_gef :=_decb .(*PSReal );_gef {_ace =_bda .Push (MakeReal (_eg .Ceil (_efc .Val )));}else if _deb ,_edb :=_decb .(*PSInteger );_edb {_ace =_bda .Push (MakeInteger (_deb .Val ));}else {_ace =ErrTypeCheck ;};return _ace ;};func (_bgge *PSParser )parseFunction ()(*PSProgram ,error ){_fge ,_ :=_bgge ._gde .ReadByte ();if _fge !='{'{return nil ,_e .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_gccd :=NewPSProgram ();for {_bgge .skipSpaces ();_fbdf ,_dbc :=_bgge ._gde .Peek (2);if _dbc !=nil {if _dbc ==_ea .EOF {break ;};return nil ,_dbc ;};_b .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_fbdf ));if _fbdf [0]=='}'{_b .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_bgge ._gde .ReadByte ();break ;}else if _fbdf [0]=='{'{_b .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_fce ,_faa :=_bgge .parseFunction ();if _faa !=nil {return nil ,_faa ;};_gccd .Append (_fce );}else if _feb .IsDecimalDigit (_fbdf [0])||(_fbdf [0]=='-'&&_feb .IsDecimalDigit (_fbdf [1])){_b .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_bbgg ,_gcaa :=_bgge .parseNumber ();if _gcaa !=nil {return nil ,_gcaa ;};_gccd .Append (_bbgg );}else {_b .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_fbdf ,_ =_bgge ._gde .Peek (5);_fafb :=string (_fbdf );_b .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_fafb );if (len (_fafb )> 4)&&(_fafb [:5]=="\u0066\u0061\u006cs\u0065"){_fbgc ,_abce :=_bgge .parseBool ();if _abce !=nil {return nil ,_abce ;};_gccd .Append (_fbgc );}else if (len (_fafb )> 3)&&(_fafb [:4]=="\u0074\u0072\u0075\u0065"){_afbf ,_baad :=_bgge .parseBool ();if _baad !=nil {return nil ,_baad ;};_gccd .Append (_afbf );}else {_aadb ,_cedb :=_bgge .parseOperand ();if _cedb !=nil {return nil ,_cedb ;};_gccd .Append (_aadb );};};};return _gccd ,nil ;};func (_dbdc *PSOperand )floor (_abc *PSStack )error {_cfa ,_gdd :=_abc .Pop ();if _gdd !=nil {return _gdd ;};if _cfe ,_cdbc :=_cfa .(*PSReal );_cdbc {_gdd =_abc .Push (MakeReal (_eg .Floor (_cfe .Val )));}else if _cac ,_ede :=_cfa .(*PSInteger );_ede {_gdd =_abc .Push (MakeInteger (_cac .Val ));}else {return ErrTypeCheck ;};return _gdd ;};const _a =0.000001;func (_gf *PSBoolean )String ()string {return _fg .Sprintf ("\u0025\u0076",_gf .Val )};func (_dbb *PSOperand )cvi (_dba *PSStack )error {_gabc ,_fgc :=_dba .Pop ();if _fgc !=nil {return _fgc ;};if _gebg ,_bef :=_gabc .(*PSReal );_bef {_afgb :=int (_gebg .Val );_fgc =_dba .Push (MakeInteger (_afgb ));}else if _cdbb ,_efa :=_gabc .(*PSInteger );_efa {_decd :=_cdbb .Val ;_fgc =_dba .Push (MakeInteger (_decd ));}else {return ErrTypeCheck ;};return _fgc ;};func (_gaa *PSOperand )roll (_gggf *PSStack )error {_caae ,_edcc :=_gggf .Pop ();if _edcc !=nil {return _edcc ;};_bcd ,_edcc :=_gggf .Pop ();if _edcc !=nil {return _edcc ;};_abae ,_ggae :=_caae .(*PSInteger );if !_ggae {return ErrTypeCheck ;};_bgag ,_ggae :=_bcd .(*PSInteger );if !_ggae {return ErrTypeCheck ;};if _bgag .Val < 0{return ErrRangeCheck ;};if _bgag .Val ==0||_bgag .Val ==1{return nil ;};if _bgag .Val > len (*_gggf ){return ErrStackUnderflow ;};for _fdb :=0;_fdb < _abbb (_abae .Val );_fdb ++{var _ggf []PSObject ;_ggf =(*_gggf )[len (*_gggf )-(_bgag .Val ):len (*_gggf )];if _abae .Val > 0{_ecee :=_ggf [len (_ggf )-1];_ggf =append ([]PSObject {_ecee },_ggf [0:len (_ggf )-1]...);}else {_cceb :=_ggf [len (_ggf )-_bgag .Val ];_ggf =append (_ggf [1:],_cceb );};_bgg :=append ((*_gggf )[0:len (*_gggf )-_bgag .Val ],_ggf ...);_gggf =&_bgg ;};return nil ;};
|
||||
|
||||
// DebugString returns a descriptive string representation of the stack - intended for debugging.
|
||||
func (_fdbd *PSStack )DebugString ()string {_dceca :="\u005b\u0020";for _ ,_bfcf :=range *_fdbd {_dceca +=_bfcf .DebugString ();_dceca +="\u0020";};_dceca +="\u005d";return _dceca ;};func (_gg *PSInteger )DebugString ()string {return _fg .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_gg .Val );};func (_dc *PSInteger )String ()string {return _fg .Sprintf ("\u0025\u0064",_dc .Val )};func (_affd *PSOperand )mul (_bdgc *PSStack )error {_egd ,_ege :=_bdgc .Pop ();if _ege !=nil {return _ege ;};_ggg ,_ege :=_bdgc .Pop ();if _ege !=nil {return _ege ;};_afa ,_ffdf :=_egd .(*PSReal );_gbfb ,_abac :=_egd .(*PSInteger );if !_ffdf &&!_abac {return ErrTypeCheck ;};_baee ,_acfc :=_ggg .(*PSReal );_bad ,_fbg :=_ggg .(*PSInteger );if !_acfc &&!_fbg {return ErrTypeCheck ;};if _abac &&_fbg {_befc :=_gbfb .Val *_bad .Val ;_ffa :=_bdgc .Push (MakeInteger (_befc ));return _ffa ;};var _fef float64 =0;if _ffdf {_fef =_afa .Val ;}else {_fef =float64 (_gbfb .Val );};if _acfc {_fef *=_baee .Val ;}else {_fef *=float64 (_bad .Val );};_ege =_bdgc .Push (MakeReal (_fef ));return _ege ;};
|
||||
|
||||
// PSBoolean represents a boolean value.
|
||||
type PSBoolean struct{Val bool ;};func (_bgf *PSOperand )abs (_gfd *PSStack )error {_gcc ,_bd :=_gfd .Pop ();if _bd !=nil {return _bd ;};if _ffe ,_ebe :=_gcc .(*PSReal );_ebe {_aca :=_ffe .Val ;if _aca < 0{_bd =_gfd .Push (MakeReal (-_aca ));}else {_bd =_gfd .Push (MakeReal (_aca ));};}else if _ece ,_fga :=_gcc .(*PSInteger );_fga {_gfe :=_ece .Val ;if _gfe < 0{_bd =_gfd .Push (MakeInteger (-_gfe ));}else {_bd =_gfd .Push (MakeInteger (_gfe ));};}else {return ErrTypeCheck ;};return _bd ;};func (_cga *PSOperand )exp (_aga *PSStack )error {_ced ,_bga :=_aga .PopNumberAsFloat64 ();if _bga !=nil {return _bga ;};_bcbf ,_bga :=_aga .PopNumberAsFloat64 ();if _bga !=nil {return _bga ;};if _eg .Abs (_ced )< 1&&_bcbf < 0{return ErrUndefinedResult ;};_dgg :=_eg .Pow (_bcbf ,_ced );_bga =_aga .Push (MakeReal (_dgg ));return _bga ;};func (_bb *PSReal )DebugString ()string {return _fg .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_bb .Val );};func (_eggb *PSParser )parseNumber ()(PSObject ,error ){_eaga ,_adffa :=_feb .ParseNumber (_eggb ._gde );if _adffa !=nil {return nil ,_adffa ;};switch _gage :=_eaga .(type ){case *_feb .PdfObjectFloat :return MakeReal (float64 (*_gage )),nil ;case *_feb .PdfObjectInteger :return MakeInteger (int (*_gage )),nil ;};return nil ,_fg .Errorf ("\u0075n\u0068\u0061\u006e\u0064\u006c\u0065\u0064\u0020\u006e\u0075\u006db\u0065\u0072\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_eaga );};var ErrUnsupportedOperand =_e .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_abcf *PSParser )parseOperand ()(*PSOperand ,error ){var _dfe []byte ;for {_fbcb ,_abb :=_abcf ._gde .Peek (1);if _abb !=nil {if _abb ==_ea .EOF {break ;};return nil ,_abb ;};if _feb .IsDelimiter (_fbcb [0]){break ;};if _feb .IsWhiteSpace (_fbcb [0]){break ;};_bdd ,_ :=_abcf ._gde .ReadByte ();_dfe =append (_dfe ,_bdd );};if len (_dfe )==0{return nil ,_e .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064\u0020\u0028\u0065\u006d\u0070\u0074\u0079\u0029");};return MakeOperand (string (_dfe )),nil ;};func (_gfde *PSOperand )log (_fgcc *PSStack )error {_cadb ,_ddg :=_fgcc .PopNumberAsFloat64 ();if _ddg !=nil {return _ddg ;};_bbe :=_eg .Log10 (_cadb );_ddg =_fgcc .Push (MakeReal (_bbe ));return _ddg ;};
|
||||
|
||||
// Parse parses the postscript and store as a program that can be executed.
|
||||
func (_bbdf *PSParser )Parse ()(*PSProgram ,error ){_bbdf .skipSpaces ();_dgff ,_dag :=_bbdf ._gde .Peek (2);if _dag !=nil {return nil ,_dag ;};if _dgff [0]!='{'{return nil ,_e .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0053\u0020\u0050\u0072\u006f\u0067\u0072\u0061\u006d\u0020\u006e\u006f\u0074\u0020\u0073t\u0061\u0072\u0074\u0069\u006eg\u0020\u0077i\u0074\u0068\u0020\u007b");};_abg ,_dag :=_bbdf .parseFunction ();if _dag !=nil &&_dag !=_ea .EOF {return nil ,_dag ;};return _abg ,_dag ;};func (_bea *PSOperand )ifelse (_aff *PSStack )error {_dbee ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_gbg ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_eba ,_dbda :=_aff .Pop ();if _dbda !=nil {return _dbda ;};_cea ,_gga :=_dbee .(*PSProgram );if !_gga {return ErrTypeCheck ;};_adf ,_gga :=_gbg .(*PSProgram );if !_gga {return ErrTypeCheck ;};_def ,_gga :=_eba .(*PSBoolean );if !_gga {return ErrTypeCheck ;};if _def .Val {_bebd :=_adf .Exec (_aff );return _bebd ;};_dbda =_cea .Exec (_aff );return _dbda ;};
|
||||
|
||||
// MakeInteger returns a new PSInteger object initialized with `val`.
|
||||
func MakeInteger (val int )*PSInteger {_aef :=PSInteger {};_aef .Val =val ;return &_aef };func (_ffd *PSBoolean )DebugString ()string {return _fg .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_ffd .Val );};func (_cbee *PSOperand )not (_bab *PSStack )error {_eccg ,_cgdg :=_bab .Pop ();if _cgdg !=nil {return _cgdg ;};if _aegg ,_cdbbg :=_eccg .(*PSBoolean );_cdbbg {_cgdg =_bab .Push (MakeBool (!_aegg .Val ));return _cgdg ;}else if _affe ,_bagf :=_eccg .(*PSInteger );_bagf {_cgdg =_bab .Push (MakeInteger (^_affe .Val ));return _cgdg ;}else {return ErrTypeCheck ;};};func (_edec *PSOperand )ge (_bage *PSStack )error {_bfe ,_bdg :=_bage .PopNumberAsFloat64 ();if _bdg !=nil {return _bdg ;};_adc ,_bdg :=_bage .PopNumberAsFloat64 ();if _bdg !=nil {return _bdg ;};if _eg .Abs (_adc -_bfe )< _a {_fad :=_bage .Push (MakeBool (true ));return _fad ;}else if _adc > _bfe {_fff :=_bage .Push (MakeBool (true ));return _fff ;}else {_cef :=_bage .Push (MakeBool (false ));return _cef ;};};func (_ee *PSReal )Duplicate ()PSObject {_aba :=PSReal {};_aba .Val =_ee .Val ;return &_aba };var ErrStackOverflow =_e .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");
|
||||
|
||||
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
|
||||
func NewPSExecutor (program *PSProgram )*PSExecutor {_de :=&PSExecutor {};_de .Stack =NewPSStack ();_de ._fb =program ;return _de ;};
|
||||
|
||||
// PSReal represents a real number.
|
||||
type PSReal struct{Val float64 ;};
|
||||
|
||||
// NewPSProgram returns an empty, initialized PSProgram.
|
||||
func NewPSProgram ()*PSProgram {return &PSProgram {}};func (_cd *PSReal )String ()string {return _fg .Sprintf ("\u0025\u002e\u0035\u0066",_cd .Val )};
|
||||
|
||||
// PSOperand represents a Postscript operand (text string).
|
||||
type PSOperand string ;
|
||||
|
||||
// Push pushes an object on top of the stack.
|
||||
func (_edee *PSStack )Push (obj PSObject )error {if len (*_edee )> 100{return ErrStackOverflow ;};*_edee =append (*_edee ,obj );return nil ;};
|
||||
|
||||
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
|
||||
func (_fd *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_bg :=range objects {_ec :=_fd .Stack .Push (_bg );if _ec !=nil {return nil ,_ec ;};};_bge :=_fd ._fb .Exec (_fd .Stack );if _bge !=nil {_b .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_bge );return nil ,_bge ;};_febb :=[]PSObject (*_fd .Stack );_fd .Stack .Empty ();return _febb ,nil ;};
|
||||
|
||||
// PSParser is a basic Postscript parser.
|
||||
type PSParser struct{_gde *_fe .Reader };func (_adff *PSOperand )or (_dcgb *PSStack )error {_befe ,_adac :=_dcgb .Pop ();if _adac !=nil {return _adac ;};_dca ,_adac :=_dcgb .Pop ();if _adac !=nil {return _adac ;};if _dgd ,_bgc :=_befe .(*PSBoolean );_bgc {_fbe ,_fcfb :=_dca .(*PSBoolean );if !_fcfb {return ErrTypeCheck ;};_adac =_dcgb .Push (MakeBool (_dgd .Val ||_fbe .Val ));return _adac ;};if _bgcg ,_faf :=_befe .(*PSInteger );_faf {_fbc ,_fdec :=_dca .(*PSInteger );if !_fdec {return ErrTypeCheck ;};_adac =_dcgb .Push (MakeInteger (_bgcg .Val |_fbc .Val ));return _adac ;};return ErrTypeCheck ;};func (_afe *PSParser )parseBool ()(*PSBoolean ,error ){_dcfb ,_fgef :=_afe ._gde .Peek (4);if _fgef !=nil {return MakeBool (false ),_fgef ;};if (len (_dcfb )>=4)&&(string (_dcfb [:4])=="\u0074\u0072\u0075\u0065"){_afe ._gde .Discard (4);return MakeBool (true ),nil ;};_dcfb ,_fgef =_afe ._gde .Peek (5);if _fgef !=nil {return MakeBool (false ),_fgef ;};if (len (_dcfb )>=5)&&(string (_dcfb [:5])=="\u0066\u0061\u006cs\u0065"){_afe ._gde .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_e .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};func (_fcc *PSOperand )le (_ecf *PSStack )error {_eebg ,_cedc :=_ecf .PopNumberAsFloat64 ();if _cedc !=nil {return _cedc ;};_dcce ,_cedc :=_ecf .PopNumberAsFloat64 ();if _cedc !=nil {return _cedc ;};if _eg .Abs (_dcce -_eebg )< _a {_bgd :=_ecf .Push (MakeBool (true ));return _bgd ;}else if _dcce < _eebg {_bfbf :=_ecf .Push (MakeBool (true ));return _bfbf ;}else {_bfc :=_ecf .Push (MakeBool (false ));return _bfc ;};};func (_be *PSOperand )cos (_abe *PSStack )error {_beb ,_gfb :=_abe .PopNumberAsFloat64 ();if _gfb !=nil {return _gfb ;};_bgee :=_eg .Cos (_beb *_eg .Pi /180.0);_gfb =_abe .Push (MakeReal (_bgee ));return _gfb ;};
|
||||
String ()string ;};func (_bfdb *PSOperand )ne (_daba *PSStack )error {_gcdf :=_bfdb .eq (_daba );if _gcdf !=nil {return _gcdf ;};_gcdf =_bfdb .not (_daba );return _gcdf ;};func (_aa *PSBoolean )Duplicate ()PSObject {_af :=PSBoolean {};_af .Val =_aa .Val ;return &_af };
|
||||
|
||||
// PopInteger specificially pops an integer from the top of the stack, returning the value as an int.
|
||||
func (_ddbg *PSStack )PopInteger ()(int ,error ){_ebbe ,_aed :=_ddbg .Pop ();if _aed !=nil {return 0,_aed ;};if _abd ,_fee :=_ebbe .(*PSInteger );_fee {return _abd .Val ,nil ;};return 0,ErrTypeCheck ;};
|
||||
|
||||
// Exec executes the operand `op` in the state specified by `stack`.
|
||||
func (_aad *PSOperand )Exec (stack *PSStack )error {_cc :=ErrUnsupportedOperand ;switch *_aad {case "\u0061\u0062\u0073":_cc =_aad .abs (stack );case "\u0061\u0064\u0064":_cc =_aad .add (stack );case "\u0061\u006e\u0064":_cc =_aad .and (stack );case "\u0061\u0074\u0061\u006e":_cc =_aad .atan (stack );case "\u0062\u0069\u0074\u0073\u0068\u0069\u0066\u0074":_cc =_aad .bitshift (stack );case "\u0063e\u0069\u006c\u0069\u006e\u0067":_cc =_aad .ceiling (stack );case "\u0063\u006f\u0070\u0079":_cc =_aad .copy (stack );case "\u0063\u006f\u0073":_cc =_aad .cos (stack );case "\u0063\u0076\u0069":_cc =_aad .cvi (stack );case "\u0063\u0076\u0072":_cc =_aad .cvr (stack );case "\u0064\u0069\u0076":_cc =_aad .div (stack );case "\u0064\u0075\u0070":_cc =_aad .dup (stack );case "\u0065\u0071":_cc =_aad .eq (stack );case "\u0065\u0078\u0063\u0068":_cc =_aad .exch (stack );case "\u0065\u0078\u0070":_cc =_aad .exp (stack );case "\u0066\u006c\u006fo\u0072":_cc =_aad .floor (stack );case "\u0067\u0065":_cc =_aad .ge (stack );case "\u0067\u0074":_cc =_aad .gt (stack );case "\u0069\u0064\u0069\u0076":_cc =_aad .idiv (stack );case "\u0069\u0066":_cc =_aad .ifCondition (stack );case "\u0069\u0066\u0065\u006c\u0073\u0065":_cc =_aad .ifelse (stack );case "\u0069\u006e\u0064e\u0078":_cc =_aad .index (stack );case "\u006c\u0065":_cc =_aad .le (stack );case "\u006c\u006f\u0067":_cc =_aad .log (stack );case "\u006c\u006e":_cc =_aad .ln (stack );case "\u006c\u0074":_cc =_aad .lt (stack );case "\u006d\u006f\u0064":_cc =_aad .mod (stack );case "\u006d\u0075\u006c":_cc =_aad .mul (stack );case "\u006e\u0065":_cc =_aad .ne (stack );case "\u006e\u0065\u0067":_cc =_aad .neg (stack );case "\u006e\u006f\u0074":_cc =_aad .not (stack );case "\u006f\u0072":_cc =_aad .or (stack );case "\u0070\u006f\u0070":_cc =_aad .pop (stack );case "\u0072\u006f\u0075n\u0064":_cc =_aad .round (stack );case "\u0072\u006f\u006c\u006c":_cc =_aad .roll (stack );case "\u0073\u0069\u006e":_cc =_aad .sin (stack );case "\u0073\u0071\u0072\u0074":_cc =_aad .sqrt (stack );case "\u0073\u0075\u0062":_cc =_aad .sub (stack );case "\u0074\u0072\u0075\u006e\u0063\u0061\u0074\u0065":_cc =_aad .truncate (stack );case "\u0078\u006f\u0072":_cc =_aad .xor (stack );};return _cc ;};
|
||||
|
||||
// PSProgram defines a Postscript program which is a series of PS objects (arguments, commands, programs etc).
|
||||
type PSProgram []PSObject ;func (_faga *PSOperand )round (_cddd *PSStack )error {_bfd ,_dfa :=_cddd .Pop ();if _dfa !=nil {return _dfa ;};if _gba ,_gbe :=_bfd .(*PSReal );_gbe {_dfa =_cddd .Push (MakeReal (_eg .Floor (_gba .Val +0.5)));}else if _eage ,_caef :=_bfd .(*PSInteger );_caef {_dfa =_cddd .Push (MakeInteger (_eage .Val ));}else {return ErrTypeCheck ;};return _dfa ;};func (_ce *PSOperand )and (_fec *PSStack )error {_fa ,_aaf :=_fec .Pop ();if _aaf !=nil {return _aaf ;};_bc ,_aaf :=_fec .Pop ();if _aaf !=nil {return _aaf ;};if _dg ,_bde :=_fa .(*PSBoolean );_bde {_bca ,_eeg :=_bc .(*PSBoolean );if !_eeg {return ErrTypeCheck ;};_aaf =_fec .Push (MakeBool (_dg .Val &&_bca .Val ));return _aaf ;};if _efb ,_ceg :=_fa .(*PSInteger );_ceg {_dfg ,_cdb :=_bc .(*PSInteger );if !_cdb {return ErrTypeCheck ;};_aaf =_fec .Push (MakeInteger (_efb .Val &_dfg .Val ));return _aaf ;};return ErrTypeCheck ;};func (_da *PSBoolean )Duplicate ()PSObject {_ef :=PSBoolean {};_ef .Val =_da .Val ;return &_ef };
|
||||
|
||||
// Pop pops an object from the top of the stack.
|
||||
func (_cbeg *PSStack )Pop ()(PSObject ,error ){if len (*_cbeg )< 1{return nil ,ErrStackUnderflow ;};_egec :=(*_cbeg )[len (*_cbeg )-1];*_cbeg =(*_cbeg )[0:len (*_cbeg )-1];return _egec ,nil ;};func (_eed *PSOperand )xor (_bee *PSStack )error {_ddc ,_debg :=_bee .Pop ();if _debg !=nil {return _debg ;};_ecg ,_debg :=_bee .Pop ();if _debg !=nil {return _debg ;};if _bdb ,_aec :=_ddc .(*PSBoolean );_aec {_dedd ,_aeec :=_ecg .(*PSBoolean );if !_aeec {return ErrTypeCheck ;};_debg =_bee .Push (MakeBool (_bdb .Val !=_dedd .Val ));return _debg ;};if _fffb ,_dga :=_ddc .(*PSInteger );_dga {_gabd ,_abada :=_ecg .(*PSInteger );if !_abada {return ErrTypeCheck ;};_debg =_bee .Push (MakeInteger (_fffb .Val ^_gabd .Val ));return _debg ;};return ErrTypeCheck ;};var ErrStackUnderflow =_e .New ("\u0073t\u0061c\u006b\u0020\u0075\u006e\u0064\u0065\u0072\u0066\u006c\u006f\u0077");func (_ccf *PSParser )skipSpaces ()(int ,error ){_bfde :=0;for {_gcf ,_acda :=_ccf ._gde .Peek (1);if _acda !=nil {return 0,_acda ;};if _feb .IsWhiteSpace (_gcf [0]){_ccf ._gde .ReadByte ();_bfde ++;}else {break ;};};return _bfde ,nil ;};func (_gge *PSOperand )truncate (_afce *PSStack )error {_cgf ,_ecb :=_afce .Pop ();if _ecb !=nil {return _ecb ;};if _acdb ,_gcbc :=_cgf .(*PSReal );_gcbc {_cde :=int (_acdb .Val );_ecb =_afce .Push (MakeReal (float64 (_cde )));}else if _gfcd ,_fbec :=_cgf .(*PSInteger );_fbec {_ecb =_afce .Push (MakeInteger (_gfcd .Val ));}else {return ErrTypeCheck ;};return _ecb ;};func (_edba *PSOperand )index (_eeab *PSStack )error {_fcf ,_cad :=_eeab .Pop ();if _cad !=nil {return _cad ;};_bcae ,_fagd :=_fcf .(*PSInteger );if !_fagd {return ErrTypeCheck ;};if _bcae .Val < 0{return ErrRangeCheck ;};if _bcae .Val > len (*_eeab )-1{return ErrStackUnderflow ;};_adfe :=(*_eeab )[len (*_eeab )-1-_bcae .Val ];_cad =_eeab .Push (_adfe .Duplicate ());return _cad ;};
|
||||
|
||||
// NewPSParser returns a new instance of the PDF Postscript parser from input data.
|
||||
func NewPSParser (content []byte )*PSParser {_bdab :=PSParser {};_bagd :=_d .NewBuffer (content );_bdab ._gde =_fe .NewReader (_bagd );return &_bdab ;};
|
||||
|
||||
// MakeReal returns a new PSReal object initialized with `val`.
|
||||
func MakeReal (val float64 )*PSReal {_dbdb :=PSReal {};_dbdb .Val =val ;return &_dbdb };func (_egc *PSOperand )idiv (_egfe *PSStack )error {_dae ,_acd :=_egfe .Pop ();if _acd !=nil {return _acd ;};_ggb ,_acd :=_egfe .Pop ();if _acd !=nil {return _acd ;};_bce ,_gebb :=_dae .(*PSInteger );if !_gebb {return ErrTypeCheck ;};if _bce .Val ==0{return ErrUndefinedResult ;};_dfc ,_gebb :=_ggb .(*PSInteger );if !_gebb {return ErrTypeCheck ;};_fea :=_dfc .Val /_bce .Val ;_acd =_egfe .Push (MakeInteger (_fea ));return _acd ;};func (_geffc *PSOperand )pop (_baeb *PSStack )error {_ ,_gdc :=_baeb .Pop ();if _gdc !=nil {return _gdc ;};return nil ;};
|
||||
func (_dcgb *PSStack )PopInteger ()(int ,error ){_ddff ,_gea :=_dcgb .Pop ();if _gea !=nil {return 0,_gea ;};if _ede ,_addb :=_ddff .(*PSInteger );_addb {return _ede .Val ,nil ;};return 0,ErrTypeCheck ;};
|
||||
|
||||
// PSStack defines a stack of PSObjects. PSObjects can be pushed on or pull from the stack.
|
||||
type PSStack []PSObject ;
|
||||
type PSStack []PSObject ;func (_ceca *PSOperand )exch (_cdbb *PSStack )error {_fabg ,_befc :=_cdbb .Pop ();if _befc !=nil {return _befc ;};_fdc ,_befc :=_cdbb .Pop ();if _befc !=nil {return _befc ;};_befc =_cdbb .Push (_fabg );if _befc !=nil {return _befc ;};_befc =_cdbb .Push (_fdc );return _befc ;};func (_cefg *PSOperand )round (_dbabg *PSStack )error {_gegg ,_gcaa :=_dbabg .Pop ();if _gcaa !=nil {return _gcaa ;};if _gaa ,_bbe :=_gegg .(*PSReal );_bbe {_gcaa =_dbabg .Push (MakeReal (_bb .Floor (_gaa .Val +0.5)));}else if _bdec ,_dfcd :=_gegg .(*PSInteger );_dfcd {_gcaa =_dbabg .Push (MakeInteger (_bdec .Val ));}else {return ErrTypeCheck ;};return _gcaa ;};func (_dgc *PSProgram )DebugString ()string {_bef :="\u007b\u0020";for _ ,_dge :=range *_dgc {_bef +=_dge .DebugString ();_bef +="\u0020";};_bef +="\u007d";return _bef ;};const _dg =0.000001;func (_gcg *PSOperand )dup (_eefa *PSStack )error {_acd ,_bfef :=_eefa .Pop ();if _bfef !=nil {return _bfef ;};_bfef =_eefa .Push (_acd );if _bfef !=nil {return _bfef ;};_bfef =_eefa .Push (_acd .Duplicate ());return _bfef ;};func (_bed *PSOperand )log (_dbec *PSStack )error {_eege ,_acef :=_dbec .PopNumberAsFloat64 ();if _acef !=nil {return _acef ;};_ebf :=_bb .Log10 (_eege );_acef =_dbec .Push (MakeReal (_ebf ));return _acef ;};func (_cef *PSOperand )eq (_cdb *PSStack )error {_efa ,_ecea :=_cdb .Pop ();if _ecea !=nil {return _ecea ;};_ebd ,_ecea :=_cdb .Pop ();if _ecea !=nil {return _ecea ;};_gfc ,_bdf :=_efa .(*PSBoolean );_gfcf ,_bfa :=_ebd .(*PSBoolean );if _bdf ||_bfa {var _cgfc error ;if _bdf &&_bfa {_cgfc =_cdb .Push (MakeBool (_gfc .Val ==_gfcf .Val ));}else {_cgfc =_cdb .Push (MakeBool (false ));};return _cgfc ;};var _ebbf float64 ;var _gdb float64 ;if _gddd ,_cded :=_efa .(*PSInteger );_cded {_ebbf =float64 (_gddd .Val );}else if _fab ,_fbc :=_efa .(*PSReal );_fbc {_ebbf =_fab .Val ;}else {return ErrTypeCheck ;};if _ffa ,_dea :=_ebd .(*PSInteger );_dea {_gdb =float64 (_ffa .Val );}else if _dbab ,_gegd :=_ebd .(*PSReal );_gegd {_gdb =_dbab .Val ;}else {return ErrTypeCheck ;};if _bb .Abs (_gdb -_ebbf )< _dg {_ecea =_cdb .Push (MakeBool (true ));}else {_ecea =_cdb .Push (MakeBool (false ));};return _ecea ;};
|
||||
|
||||
// PSInteger represents an integer.
|
||||
type PSInteger struct{Val int ;};func (_ff *PSOperand )Duplicate ()PSObject {_gd :=*_ff ;return &_gd };func (_bde *PSOperand )floor (_dbac *PSStack )error {_decf ,_ccf :=_dbac .Pop ();if _ccf !=nil {return _ccf ;};if _fdb ,_cae :=_decf .(*PSReal );_cae {_ccf =_dbac .Push (MakeReal (_bb .Floor (_fdb .Val )));}else if _daeb ,_fgf :=_decf .(*PSInteger );_fgf {_ccf =_dbac .Push (MakeInteger (_daeb .Val ));}else {return ErrTypeCheck ;};return _ccf ;};func (_dgb *PSOperand )bitshift (_dee *PSStack )error {_bfc ,_dcd :=_dee .PopInteger ();if _dcd !=nil {return _dcd ;};_ae ,_dcd :=_dee .PopInteger ();if _dcd !=nil {return _dcd ;};var _gc int ;if _bfc >=0{_gc =_ae <<uint (_bfc );}else {_gc =_ae >>uint (-_bfc );};_dcd =_dee .Push (MakeInteger (_gc ));return _dcd ;};func (_fd *PSInteger )String ()string {return _e .Sprintf ("\u0025\u0064",_fd .Val )};func (_becb *PSOperand )gt (_ddg *PSStack )error {_egbb ,_ceg :=_ddg .PopNumberAsFloat64 ();if _ceg !=nil {return _ceg ;};_dfcc ,_ceg :=_ddg .PopNumberAsFloat64 ();if _ceg !=nil {return _ceg ;};if _bb .Abs (_dfcc -_egbb )< _dg {_dgg :=_ddg .Push (MakeBool (false ));return _dgg ;}else if _dfcc > _egbb {_faaf :=_ddg .Push (MakeBool (true ));return _faaf ;}else {_bade :=_ddg .Push (MakeBool (false ));return _bade ;};};
|
||||
|
||||
// NewPSProgram returns an empty, initialized PSProgram.
|
||||
func NewPSProgram ()*PSProgram {return &PSProgram {}};func (_cf *PSInteger )Duplicate ()PSObject {_fbe :=PSInteger {};_fbe .Val =_cf .Val ;return &_fbe };func (_dbg *PSOperand )atan (_bad *PSStack )error {_dcf ,_ca :=_bad .PopNumberAsFloat64 ();if _ca !=nil {return _ca ;};_beb ,_ca :=_bad .PopNumberAsFloat64 ();if _ca !=nil {return _ca ;};if _dcf ==0{var _ed error ;if _beb < 0{_ed =_bad .Push (MakeReal (270));}else {_ed =_bad .Push (MakeReal (90));};return _ed ;};_aaa :=_beb /_dcf ;_fdg :=_bb .Atan (_aaa )*180/_bb .Pi ;_ca =_bad .Push (MakeReal (_fdg ));return _ca ;};func (_eee *PSOperand )String ()string {return _e .Sprintf ("\u0025\u0073",*_eee )};func (_dfd *PSOperand )sqrt (_cccf *PSStack )error {_gbgc ,_adfg :=_cccf .PopNumberAsFloat64 ();if _adfg !=nil {return _adfg ;};if _gbgc < 0{return ErrRangeCheck ;};_cccd :=_bb .Sqrt (_gbgc );_adfg =_cccf .Push (MakeReal (_cccd ));return _adfg ;};
|
||||
|
||||
// PSExecutor has its own execution stack and is used to executre a PS routine (program).
|
||||
type PSExecutor struct{Stack *PSStack ;_de *PSProgram ;};var ErrRangeCheck =_d .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");func (_aae *PSParser )parseBool ()(*PSBoolean ,error ){_cdae ,_bafe :=_aae ._acfg .Peek (4);if _bafe !=nil {return MakeBool (false ),_bafe ;};if (len (_cdae )>=4)&&(string (_cdae [:4])=="\u0074\u0072\u0075\u0065"){_aae ._acfg .Discard (4);return MakeBool (true ),nil ;};_cdae ,_bafe =_aae ._acfg .Peek (5);if _bafe !=nil {return MakeBool (false ),_bafe ;};if (len (_cdae )>=5)&&(string (_cdae [:5])=="\u0066\u0061\u006cs\u0065"){_aae ._acfg .Discard (5);return MakeBool (false ),nil ;};return MakeBool (false ),_d .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};var ErrStackOverflow =_d .New ("\u0073\u0074\u0061\u0063\u006b\u0020\u006f\u0076\u0065r\u0066\u006c\u006f\u0077");func (_bdbe *PSOperand )or (_gge *PSStack )error {_cadg ,_bga :=_gge .Pop ();if _bga !=nil {return _bga ;};_cgef ,_bga :=_gge .Pop ();if _bga !=nil {return _bga ;};if _bggb ,_agc :=_cadg .(*PSBoolean );_agc {_caed ,_ecc :=_cgef .(*PSBoolean );if !_ecc {return ErrTypeCheck ;};_bga =_gge .Push (MakeBool (_bggb .Val ||_caed .Val ));return _bga ;};if _cedg ,_ab :=_cadg .(*PSInteger );_ab {_eeea ,_gdac :=_cgef .(*PSInteger );if !_gdac {return ErrTypeCheck ;};_bga =_gge .Push (MakeInteger (_cedg .Val |_eeea .Val ));return _bga ;};return ErrTypeCheck ;};func (_gcd *PSOperand )idiv (_cdgg *PSStack )error {_fed ,_gcdg :=_cdgg .Pop ();if _gcdg !=nil {return _gcdg ;};_cgff ,_gcdg :=_cdgg .Pop ();if _gcdg !=nil {return _gcdg ;};_add ,_fbg :=_fed .(*PSInteger );if !_fbg {return ErrTypeCheck ;};if _add .Val ==0{return ErrUndefinedResult ;};_bab ,_fbg :=_cgff .(*PSInteger );if !_fbg {return ErrTypeCheck ;};_ccbfb :=_bab .Val /_add .Val ;_gcdg =_cdgg .Push (MakeInteger (_ccbfb ));return _gcdg ;};
|
||||
|
||||
// Parse parses the postscript and store as a program that can be executed.
|
||||
func (_dda *PSParser )Parse ()(*PSProgram ,error ){_dda .skipSpaces ();_daea ,_gbb :=_dda ._acfg .Peek (2);if _gbb !=nil {return nil ,_gbb ;};if _daea [0]!='{'{return nil ,_d .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");};_beeb ,_gbb :=_dda .parseFunction ();if _gbb !=nil &&_gbb !=_b .EOF {return nil ,_gbb ;};return _beeb ,_gbb ;};func (_dga *PSOperand )not (_gbde *PSStack )error {_aegb ,_gce :=_gbde .Pop ();if _gce !=nil {return _gce ;};if _bge ,_fgda :=_aegb .(*PSBoolean );_fgda {_gce =_gbde .Push (MakeBool (!_bge .Val ));return _gce ;}else if _gcf ,_cac :=_aegb .(*PSInteger );_cac {_gce =_gbde .Push (MakeInteger (^_gcf .Val ));return _gce ;}else {return ErrTypeCheck ;};};
|
||||
|
||||
// DebugString returns a descriptive string representation of the stack - intended for debugging.
|
||||
func (_babd *PSStack )DebugString ()string {_efg :="\u005b\u0020";for _ ,_bfdd :=range *_babd {_efg +=_bfdd .DebugString ();_efg +="\u0020";};_efg +="\u005d";return _efg ;};func (_fga *PSOperand )DebugString ()string {return _e .Sprintf ("\u006fp\u003a\u0027\u0025\u0073\u0027",*_fga );};func (_bbb *PSBoolean )DebugString ()string {return _e .Sprintf ("\u0062o\u006f\u006c\u003a\u0025\u0076",_bbb .Val );};var ErrUndefinedResult =_d .New ("\u0075\u006e\u0064\u0065fi\u006e\u0065\u0064\u0020\u0072\u0065\u0073\u0075\u006c\u0074\u0020\u0065\u0072\u0072o\u0072");func (_gg *PSOperand )cvr (_eb *PSStack )error {_dfaf ,_dfc :=_eb .Pop ();if _dfc !=nil {return _dfc ;};if _aef ,_cfg :=_dfaf .(*PSReal );_cfg {_dfc =_eb .Push (MakeReal (_aef .Val ));}else if _ace ,_cdg :=_dfaf .(*PSInteger );_cdg {_dfc =_eb .Push (MakeReal (float64 (_ace .Val )));}else {return ErrTypeCheck ;};return _dfc ;};func (_gfe *PSOperand )mod (_ebe *PSStack )error {_eegc ,_bdb :=_ebe .Pop ();if _bdb !=nil {return _bdb ;};_gcag ,_bdb :=_ebe .Pop ();if _bdb !=nil {return _bdb ;};_bgf ,_dde :=_eegc .(*PSInteger );if !_dde {return ErrTypeCheck ;};if _bgf .Val ==0{return ErrUndefinedResult ;};_ecb ,_dde :=_gcag .(*PSInteger );if !_dde {return ErrTypeCheck ;};_deac :=_ecb .Val %_bgf .Val ;_bdb =_ebe .Push (MakeInteger (_deac ));return _bdb ;};func (_dbde *PSOperand )sin (_febg *PSStack )error {_egcf ,_fcbc :=_febg .PopNumberAsFloat64 ();if _fcbc !=nil {return _fcbc ;};_cdf :=_bb .Sin (_egcf *_bb .Pi /180.0);_fcbc =_febg .Push (MakeReal (_cdf ));return _fcbc ;};
|
||||
|
||||
// PSOperand represents a Postscript operand (text string).
|
||||
type PSOperand string ;func (_febc *PSOperand )lt (_dcg *PSStack )error {_acb ,_fafe :=_dcg .PopNumberAsFloat64 ();if _fafe !=nil {return _fafe ;};_bcef ,_fafe :=_dcg .PopNumberAsFloat64 ();if _fafe !=nil {return _fafe ;};if _bb .Abs (_bcef -_acb )< _dg {_cba :=_dcg .Push (MakeBool (false ));return _cba ;}else if _bcef < _acb {_ced :=_dcg .Push (MakeBool (true ));return _ced ;}else {_cgd :=_dcg .Push (MakeBool (false ));return _cgd ;};};func (_dbfa *PSOperand )le (_eec *PSStack )error {_gef ,_ggff :=_eec .PopNumberAsFloat64 ();if _ggff !=nil {return _ggff ;};_effc ,_ggff :=_eec .PopNumberAsFloat64 ();if _ggff !=nil {return _ggff ;};if _bb .Abs (_effc -_gef )< _dg {_gdfd :=_eec .Push (MakeBool (true ));return _gdfd ;}else if _effc < _gef {_ddb :=_eec .Push (MakeBool (true ));return _ddb ;}else {_gdc :=_eec .Push (MakeBool (false ));return _gdc ;};};func (_bgcc *PSParser )parseFunction ()(*PSProgram ,error ){_bdeg ,_ :=_bgcc ._acfg .ReadByte ();if _bdeg !='{'{return nil ,_d .New ("\u0069\u006ev\u0061\u006c\u0069d\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_eaf :=NewPSProgram ();for {_bgcc .skipSpaces ();_bcb ,_bfde :=_bgcc ._acfg .Peek (2);if _bfde !=nil {if _bfde ==_b .EOF {break ;};return nil ,_bfde ;};_dfe .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_bcb ));if _bcb [0]=='}'{_dfe .Log .Trace ("\u0045\u004f\u0046 \u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");_bgcc ._acfg .ReadByte ();break ;}else if _bcb [0]=='{'{_dfe .Log .Trace ("\u0046u\u006e\u0063\u0074\u0069\u006f\u006e!");_ffg ,_ddf :=_bgcc .parseFunction ();if _ddf !=nil {return nil ,_ddf ;};_eaf .Append (_ffg );}else if _cd .IsDecimalDigit (_bcb [0])||(_bcb [0]=='-'&&_cd .IsDecimalDigit (_bcb [1])){_dfe .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_eeed ,_cadgg :=_bgcc .parseNumber ();if _cadgg !=nil {return nil ,_cadgg ;};_eaf .Append (_eeed );}else {_dfe .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_bcb ,_ =_bgcc ._acfg .Peek (5);_dgaa :=string (_bcb );_dfe .Log .Trace ("\u0050\u0065\u0065k\u0020\u0073\u0074\u0072\u003a\u0020\u0025\u0073",_dgaa );if (len (_dgaa )> 4)&&(_dgaa [:5]=="\u0066\u0061\u006cs\u0065"){_aaf ,_fdgb :=_bgcc .parseBool ();if _fdgb !=nil {return nil ,_fdgb ;};_eaf .Append (_aaf );}else if (len (_dgaa )> 3)&&(_dgaa [:4]=="\u0074\u0072\u0075\u0065"){_ffgd ,_fda :=_bgcc .parseBool ();if _fda !=nil {return nil ,_fda ;};_eaf .Append (_ffgd );}else {_gaef ,_fedb :=_bgcc .parseOperand ();if _fedb !=nil {return nil ,_fedb ;};_eaf .Append (_gaef );};};};return _eaf ,nil ;};func (_fgdd *PSOperand )ceiling (_bee *PSStack )error {_dec ,_eg :=_bee .Pop ();if _eg !=nil {return _eg ;};if _bfd ,_bfb :=_dec .(*PSReal );_bfb {_eg =_bee .Push (MakeReal (_bb .Ceil (_bfd .Val )));}else if _cfc ,_fag :=_dec .(*PSInteger );_fag {_eg =_bee .Push (MakeInteger (_cfc .Val ));}else {_eg =ErrTypeCheck ;};return _eg ;};func (_ccge *PSOperand )cos (_eff *PSStack )error {_cca ,_gae :=_eff .PopNumberAsFloat64 ();if _gae !=nil {return _gae ;};_aeg :=_bb .Cos (_cca *_bb .Pi /180.0);_gae =_eff .Push (MakeReal (_aeg ));return _gae ;};
|
||||
|
||||
// Exec executes the program, typically leaving output values on the stack.
|
||||
func (_cg *PSProgram )Exec (stack *PSStack )error {for _ ,_baa :=range *_cg {var _bac error ;switch _ge :=_baa .(type ){case *PSInteger :_ee :=_ge ;_bac =stack .Push (_ee );case *PSReal :_fgd :=_ge ;_bac =stack .Push (_fgd );case *PSBoolean :_cbg :=_ge ;_bac =stack .Push (_cbg );case *PSProgram :_geg :=_ge ;_bac =stack .Push (_geg );case *PSOperand :_ce :=_ge ;_bac =_ce .Exec (stack );default:return ErrTypeCheck ;};if _bac !=nil {return _bac ;};};return nil ;};func (_aebg *PSOperand )xor (_ddeg *PSStack )error {_dcb ,_afec :=_ddeg .Pop ();if _afec !=nil {return _afec ;};_fcbf ,_afec :=_ddeg .Pop ();if _afec !=nil {return _afec ;};if _effb ,_efd :=_dcb .(*PSBoolean );_efd {_ebfd ,_acf :=_fcbf .(*PSBoolean );if !_acf {return ErrTypeCheck ;};_afec =_ddeg .Push (MakeBool (_effb .Val !=_ebfd .Val ));return _afec ;};if _ddcb ,_cga :=_dcb .(*PSInteger );_cga {_bgfa ,_bbef :=_fcbf .(*PSInteger );if !_bbef {return ErrTypeCheck ;};_afec =_ddeg .Push (MakeInteger (_ddcb .Val ^_bgfa .Val ));return _afec ;};return ErrTypeCheck ;};func (_adbd *PSOperand )ge (_eab *PSStack )error {_bea ,_bgc :=_eab .PopNumberAsFloat64 ();if _bgc !=nil {return _bgc ;};_acgb ,_bgc :=_eab .PopNumberAsFloat64 ();if _bgc !=nil {return _bgc ;};if _bb .Abs (_acgb -_bea )< _dg {_gca :=_eab .Push (MakeBool (true ));return _gca ;}else if _acgb > _bea {_dbf :=_eab .Push (MakeBool (true ));return _dbf ;}else {_cbgf :=_eab .Push (MakeBool (false ));return _cbgf ;};};func (_dbe *PSOperand )ifCondition (_ceb *PSStack )error {_adde ,_dab :=_ceb .Pop ();if _dab !=nil {return _dab ;};_cfa ,_dab :=_ceb .Pop ();if _dab !=nil {return _dab ;};_fca ,_gda :=_adde .(*PSProgram );if !_gda {return ErrTypeCheck ;};_bdg ,_gda :=_cfa .(*PSBoolean );if !_gda {return ErrTypeCheck ;};if _bdg .Val {_ggf :=_fca .Exec (_ceb );return _ggf ;};return nil ;};func (_ddec *PSOperand )pop (_cea *PSStack )error {_ ,_fagb :=_cea .Pop ();if _fagb !=nil {return _fagb ;};return nil ;};func (_agg *PSOperand )div (_deed *PSStack )error {_ebb ,_efb :=_deed .Pop ();if _efb !=nil {return _efb ;};_badd ,_efb :=_deed .Pop ();if _efb !=nil {return _efb ;};_caa ,_ege :=_ebb .(*PSReal );_ecg ,_ebba :=_ebb .(*PSInteger );if !_ege &&!_ebba {return ErrTypeCheck ;};if _ege &&_caa .Val ==0{return ErrUndefinedResult ;};if _ebba &&_ecg .Val ==0{return ErrUndefinedResult ;};_cad ,_egb :=_badd .(*PSReal );_faf ,_cec :=_badd .(*PSInteger );if !_egb &&!_cec {return ErrTypeCheck ;};var _aeb float64 =0;if _egb {_aeb =_cad .Val ;}else {_aeb =float64 (_faf .Val );};if _ege {_aeb /=_caa .Val ;}else {_aeb /=float64 (_ecg .Val );};_efb =_deed .Push (MakeReal (_aeb ));return _efb ;};func (_bg *PSReal )String ()string {return _e .Sprintf ("\u0025\u002e\u0035\u0066",_bg .Val )};func (_cb *PSReal )DebugString ()string {return _e .Sprintf ("\u0072e\u0061\u006c\u003a\u0025\u002e\u0035f",_cb .Val );};
|
||||
|
||||
// NewPSExecutor returns an initialized PSExecutor for an input `program`.
|
||||
func NewPSExecutor (program *PSProgram )*PSExecutor {_dgf :=&PSExecutor {};_dgf .Stack =NewPSStack ();_dgf ._de =program ;return _dgf ;};func (_cefb *PSOperand )ifelse (_adcf *PSStack )error {_feb ,_gbee :=_adcf .Pop ();if _gbee !=nil {return _gbee ;};_ecgg ,_gbee :=_adcf .Pop ();if _gbee !=nil {return _gbee ;};_fea ,_gbee :=_adcf .Pop ();if _gbee !=nil {return _gbee ;};_gbc ,_gdf :=_feb .(*PSProgram );if !_gdf {return ErrTypeCheck ;};_afg ,_gdf :=_ecgg .(*PSProgram );if !_gdf {return ErrTypeCheck ;};_eeg ,_gdf :=_fea .(*PSBoolean );if !_gdf {return ErrTypeCheck ;};if _eeg .Val {_bba :=_afg .Exec (_adcf );return _bba ;};_gbee =_gbc .Exec (_adcf );return _gbee ;};func (_adf *PSOperand )index (_gfa *PSStack )error {_beab ,_egc :=_gfa .Pop ();if _egc !=nil {return _egc ;};_gga ,_bgcb :=_beab .(*PSInteger );if !_bgcb {return ErrTypeCheck ;};if _gga .Val < 0{return ErrRangeCheck ;};if _gga .Val > len (*_gfa )-1{return ErrStackUnderflow ;};_bgd :=(*_gfa )[len (*_gfa )-1-_gga .Val ];_egc =_gfa .Push (_bgd .Duplicate ());return _egc ;};func (_affa *PSParser )skipSpaces ()(int ,error ){_gec :=0;for {_gedg ,_bfg :=_affa ._acfg .Peek (1);if _bfg !=nil {return 0,_bfg ;};if _cd .IsWhiteSpace (_gedg [0]){_affa ._acfg .ReadByte ();_gec ++;}else {break ;};};return _gec ,nil ;};func (_aab *PSOperand )cvi (_dbd *PSStack )error {_acg ,_bfdf :=_dbd .Pop ();if _bfdf !=nil {return _bfdf ;};if _baae ,_adg :=_acg .(*PSReal );_adg {_gba :=int (_baae .Val );_bfdf =_dbd .Push (MakeInteger (_gba ));}else if _agb ,_afb :=_acg .(*PSInteger );_afb {_dbad :=_agb .Val ;_bfdf =_dbd .Push (MakeInteger (_dbad ));}else {return ErrTypeCheck ;};return _bfdf ;};
|
||||
|
||||
// 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 _db []float64 ;for _ ,_dbc :=range objects {if _da ,_dc :=_dbc .(*PSInteger );_dc {_db =append (_db ,float64 (_da .Val ));}else if _cdd ,_bc :=_dbc .(*PSReal );_bc {_db =append (_db ,_cdd .Val );}else {return nil ,ErrTypeCheck ;};};return _db ,nil ;};func (_bce *PSInteger )DebugString ()string {return _e .Sprintf ("\u0069\u006e\u0074\u003a\u0025\u0064",_bce .Val );};
|
||||
|
||||
// Empty empties the stack.
|
||||
func (_dcff *PSStack )Empty (){*_dcff =[]PSObject {}};func (_aee *PSOperand )neg (_ccgb *PSStack )error {_gdf ,_acde :=_ccgb .Pop ();if _acde !=nil {return _acde ;};if _agd ,_dbbd :=_gdf .(*PSReal );_dbbd {_acde =_ccgb .Push (MakeReal (-_agd .Val ));return _acde ;}else if _eaa ,_bfa :=_gdf .(*PSInteger );_bfa {_acde =_ccgb .Push (MakeInteger (-_eaa .Val ));return _acde ;}else {return ErrTypeCheck ;};};func (_cdfa *PSOperand )exch (_fag *PSStack )error {_aeg ,_acf :=_fag .Pop ();if _acf !=nil {return _acf ;};_beff ,_acf :=_fag .Pop ();if _acf !=nil {return _acf ;};_acf =_fag .Push (_aeg );if _acf !=nil {return _acf ;};_acf =_fag .Push (_beff );return _acf ;};
|
||||
func (_eed *PSStack )Empty (){*_eed =[]PSObject {}};func (_ceda *PSOperand )neg (_egg *PSStack )error {_gbg ,_fdbf :=_egg .Pop ();if _fdbf !=nil {return _fdbf ;};if _fdgg ,_cbc :=_gbg .(*PSReal );_cbc {_fdbf =_egg .Push (MakeReal (-_fdgg .Val ));return _fdbf ;}else if _bgcf ,_edb :=_gbg .(*PSInteger );_edb {_fdbf =_egg .Push (MakeInteger (-_bgcf .Val ));return _fdbf ;}else {return ErrTypeCheck ;};};
|
||||
|
||||
// NewPSStack returns an initialized PSStack.
|
||||
func NewPSStack ()*PSStack {return &PSStack {}};func (_bag *PSOperand )eq (_ccg *PSStack )error {_cgd ,_geff :=_ccg .Pop ();if _geff !=nil {return _geff ;};_bcb ,_geff :=_ccg .Pop ();if _geff !=nil {return _geff ;};_cb ,_ccag :=_cgd .(*PSBoolean );_gfc ,_gac :=_bcb .(*PSBoolean );if _ccag ||_gac {var _afgd error ;if _ccag &&_gac {_afgd =_ccg .Push (MakeBool (_cb .Val ==_gfc .Val ));}else {_afgd =_ccg .Push (MakeBool (false ));};return _afgd ;};var _edbg float64 ;var _gebe float64 ;if _cbf ,_ggc :=_cgd .(*PSInteger );_ggc {_edbg =float64 (_cbf .Val );}else if _ae ,_agc :=_cgd .(*PSReal );_agc {_edbg =_ae .Val ;}else {return ErrTypeCheck ;};if _dfd ,_acbc :=_bcb .(*PSInteger );_acbc {_gebe =float64 (_dfd .Val );}else if _gff ,_bfb :=_bcb .(*PSReal );_bfb {_gebe =_gff .Val ;}else {return ErrTypeCheck ;};if _eg .Abs (_gebe -_edbg )< _a {_geff =_ccg .Push (MakeBool (true ));}else {_geff =_ccg .Push (MakeBool (false ));};return _geff ;};
|
||||
// Execute executes the program for an input parameters `objects` and returns a slice of output objects.
|
||||
func (_ea *PSExecutor )Execute (objects []PSObject )([]PSObject ,error ){for _ ,_ac :=range objects {_be :=_ea .Stack .Push (_ac );if _be !=nil {return nil ,_be ;};};_fa :=_ea ._de .Exec (_ea .Stack );if _fa !=nil {_dfe .Log .Debug ("\u0045x\u0065c\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u003a\u0020\u0025\u0076",_fa );return nil ,_fa ;};_fg :=[]PSObject (*_ea .Stack );_ea .Stack .Empty ();return _fg ,nil ;};func (_cddb *PSOperand )abs (_fgg *PSStack )error {_eef ,_fe :=_fgg .Pop ();if _fe !=nil {return _fe ;};if _baaf ,_ef :=_eef .(*PSReal );_ef {_fc :=_baaf .Val ;if _fc < 0{_fe =_fgg .Push (MakeReal (-_fc ));}else {_fe =_fgg .Push (MakeReal (_fc ));};}else if _dfeg ,_bd :=_eef .(*PSInteger );_bd {_dcc :=_dfeg .Val ;if _dcc < 0{_fe =_fgg .Push (MakeInteger (-_dcc ));}else {_fe =_fgg .Push (MakeInteger (_dcc ));};}else {return ErrTypeCheck ;};return _fe ;};func (_egd *PSParser )parseOperand ()(*PSOperand ,error ){var _cdc []byte ;for {_cee ,_afd :=_egd ._acfg .Peek (1);if _afd !=nil {if _afd ==_b .EOF {break ;};return nil ,_afd ;};if _cd .IsDelimiter (_cee [0]){break ;};if _cd .IsWhiteSpace (_cee [0]){break ;};_aec ,_ :=_egd ._acfg .ReadByte ();_cdc =append (_cdc ,_aec );};if len (_cdc )==0{return nil ,_d .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 (_cdc )),nil ;};func (_bcec *PSOperand )sub (_bfca *PSStack )error {_baf ,_fce :=_bfca .Pop ();if _fce !=nil {return _fce ;};_fafa ,_fce :=_bfca .Pop ();if _fce !=nil {return _fce ;};_afee ,_dce :=_baf .(*PSReal );_eddf ,_gab :=_baf .(*PSInteger );if !_dce &&!_gab {return ErrTypeCheck ;};_dcdd ,_cege :=_fafa .(*PSReal );_adge ,_edc :=_fafa .(*PSInteger );if !_cege &&!_edc {return ErrTypeCheck ;};if _gab &&_edc {_eabg :=_adge .Val -_eddf .Val ;_dbdc :=_bfca .Push (MakeInteger (_eabg ));return _dbdc ;};var _gedd float64 =0;if _cege {_gedd =_dcdd .Val ;}else {_gedd =float64 (_adge .Val );};if _dce {_gedd -=_afee .Val ;}else {_gedd -=float64 (_eddf .Val );};_fce =_bfca .Push (MakeReal (_gedd ));return _fce ;};
|
||||
|
||||
// String returns a string representation of the stack.
|
||||
func (_cgaf *PSStack )String ()string {_beff :="\u005b\u0020";for _ ,_faag :=range *_cgaf {_beff +=_faag .String ();_beff +="\u0020";};_beff +="\u005d";return _beff ;};func (_cfe *PSProgram )Duplicate ()PSObject {_faa :=&PSProgram {};for _ ,_ga :=range *_cfe {_faa .Append (_ga .Duplicate ());};return _faa ;};
|
||||
|
||||
// PSParser is a basic Postscript parser.
|
||||
type PSParser struct{_acfg *_df .Reader };func (_ad *PSBoolean )String ()string {return _e .Sprintf ("\u0025\u0076",_ad .Val )};
|
||||
|
||||
// MakeReal returns a new PSReal object initialized with `val`.
|
||||
func MakeReal (val float64 )*PSReal {_gbdd :=PSReal {};_gbdd .Val =val ;return &_gbdd };func (_afa *PSOperand )truncate (_gebg *PSStack )error {_bgb ,_fac :=_gebg .Pop ();if _fac !=nil {return _fac ;};if _dgda ,_dbgb :=_bgb .(*PSReal );_dbgb {_bae :=int (_dgda .Val );_fac =_gebg .Push (MakeReal (float64 (_bae )));}else if _acde ,_bggg :=_bgb .(*PSInteger );_bggg {_fac =_gebg .Push (MakeInteger (_acde .Val ));}else {return ErrTypeCheck ;};return _fac ;};
|
||||
|
||||
// MakeBool returns a new PSBoolean object initialized with `val`.
|
||||
func MakeBool (val bool )*PSBoolean {_ecbg :=PSBoolean {};_ecbg .Val =val ;return &_ecbg };
|
||||
|
||||
// Push pushes an object on top of the stack.
|
||||
func (_aege *PSStack )Push (obj PSObject )error {if len (*_aege )> 100{return ErrStackOverflow ;};*_aege =append (*_aege ,obj );return nil ;};
|
||||
|
||||
// Append appends an object to the PSProgram.
|
||||
func (_dd *PSProgram )Append (obj PSObject ){*_dd =append (*_dd ,obj )};func (_fcg *PSOperand )and (_aff *PSStack )error {_ece ,_cbfg :=_aff .Pop ();if _cbfg !=nil {return _cbfg ;};_bgg ,_cbfg :=_aff .Pop ();if _cbfg !=nil {return _cbfg ;};if _eae ,_bfe :=_ece .(*PSBoolean );_bfe {_gbe ,_adb :=_bgg .(*PSBoolean );if !_adb {return ErrTypeCheck ;};_cbfg =_aff .Push (MakeBool (_eae .Val &&_gbe .Val ));return _cbfg ;};if _gdd ,_ffe :=_ece .(*PSInteger );_ffe {_ddc ,_def :=_bgg .(*PSInteger );if !_def {return ErrTypeCheck ;};_cbfg =_aff .Push (MakeInteger (_gdd .Val &_ddc .Val ));return _cbfg ;};return ErrTypeCheck ;};
|
||||
|
||||
// MakeOperand returns a new PSOperand object based on string `val`.
|
||||
func MakeOperand (val string )*PSOperand {_deacf :=PSOperand (val );return &_deacf };var ErrUnsupportedOperand =_d .New ("\u0075\u006e\u0073\u0075pp\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");func (_bec *PSOperand )add (_daf *PSStack )error {_adc ,_beg :=_daf .Pop ();if _beg !=nil {return _beg ;};_eca ,_beg :=_daf .Pop ();if _beg !=nil {return _beg ;};_gag ,_ccb :=_adc .(*PSReal );_ccg ,_geb :=_adc .(*PSInteger );if !_ccb &&!_geb {return ErrTypeCheck ;};_ccbf ,_fcb :=_eca .(*PSReal );_cgb ,_cde :=_eca .(*PSInteger );if !_fcb &&!_cde {return ErrTypeCheck ;};if _geb &&_cde {_fgc :=_ccg .Val +_cgb .Val ;_dfa :=_daf .Push (MakeInteger (_fgc ));return _dfa ;};var _cbf float64 =0;if _ccb {_cbf =_gag .Val ;}else {_cbf =float64 (_ccg .Val );};if _fcb {_cbf +=_ccbf .Val ;}else {_cbf +=float64 (_cgb .Val );};_beg =_daf .Push (MakeReal (_cbf ));return _beg ;};
|
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
Loading…
x
Reference in New Issue
Block a user