mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-26 13:48:55 +08:00
prepare release
This commit is contained in:
parent
11f32c83a3
commit
56a210342e
File diff suppressed because one or more lines are too long
134
common/common.go
134
common/common.go
@ -10,93 +10,93 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package common contains common properties used by the subpackages.
|
||||
package common ;import (_e "fmt";_fe "io";_b "os";_eb "path/filepath";_fg "runtime";_c "time";);const _ede =2020;func UtcTimeFormat (t _c .Time )string {return t .Format (_ff )+"\u0020\u0055\u0054\u0043"};
|
||||
|
||||
// Info logs info message.
|
||||
func (_fed ConsoleLogger )Info (format string ,args ...interface{}){if _fed .LogLevel >=LogLevelInfo {_gf :="\u005bI\u004e\u0046\u004f\u005d\u0020";_fed .output (_b .Stdout ,_gf ,format ,args ...);};};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_ab WriterLogger )Trace (format string ,args ...interface{}){if _ab .LogLevel >=LogLevelTrace {_bde :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ab .logToWriter (_ab .Output ,_bde ,format ,args ...);};};func (_fd ConsoleLogger )output (_ca _fe .Writer ,_ccf string ,_ga string ,_ec ...interface{}){_bb (_ca ,_ccf ,_ga ,_ec ...);};
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_bd WriterLogger )IsLogLevel (level LogLevel )bool {return _bd .LogLevel >=level };
|
||||
package common ;import (_c "fmt";_f "io";_e "os";_bf "path/filepath";_ca "runtime";_b "time";);
|
||||
|
||||
// Debug does nothing for dummy logger.
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};
|
||||
|
||||
// IsLogLevel returns true from dummy logger.
|
||||
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
|
||||
|
||||
// LogLevel is the verbosity level for logging.
|
||||
type LogLevel int ;
|
||||
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_baa ConsoleLogger )IsLogLevel (level LogLevel )bool {return _baa .LogLevel >=level };func _bb (_bag _fe .Writer ,_bdb string ,_fb string ,_ebc ...interface{}){_ ,_fbc ,_ecb ,_gbc :=_fg .Caller (3);if !_gbc {_fbc ="\u003f\u003f\u003f";_ecb =0;}else {_fbc =_eb .Base (_fbc );};_aaf :=_e .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bdb ,_fbc ,_ecb )+_fb +"\u000a";_e .Fprintf (_bag ,_aaf ,_ebc ...);};const _bba =18;
|
||||
func (_cg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cg .LogLevel >=level };
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_gec WriterLogger )Notice (format string ,args ...interface{}){if _gec .LogLevel >=LogLevelNotice {_cg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_gec .logToWriter (_gec .Output ,_cg ,format ,args ...);};};
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_ff string ,_ec ...interface{});Warning (_be string ,_bb ...interface{});Notice (_fg string ,_d ...interface{});Info (_beg string ,_ad ...interface{});Debug (_cc string ,_eb ...interface{});Trace (_cf string ,_g ...interface{});IsLogLevel (_fa LogLevel )bool ;};const _def =35;func (_ga ConsoleLogger )output (_da _f .Writer ,_ea string ,_bd string ,_cae ...interface{}){_cff (_da ,_ea ,_bd ,_cae ...);};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_ag ConsoleLogger )Debug (format string ,args ...interface{}){if _ag .LogLevel >=LogLevelDebug {_ae :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ag .output (_b .Stdout ,_ae ,format ,args ...);};};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_bf ConsoleLogger )Warning (format string ,args ...interface{}){if _bf .LogLevel >=LogLevelWarning {_dd :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_bf .output (_b .Stdout ,_dd ,format ,args ...);};};
|
||||
// Trace logs trace message.
|
||||
func (_ce ConsoleLogger )Trace (format string ,args ...interface{}){if _ce .LogLevel >=LogLevelTrace {_ed :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ce .output (_e .Stdout ,_ed ,format ,args ...);};};
|
||||
|
||||
// Info logs info message.
|
||||
func (_ecd WriterLogger )Info (format string ,args ...interface{}){if _ecd .LogLevel >=LogLevelInfo {_gd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ecd .logToWriter (_ecd .Output ,_gd ,format ,args ...);};};const _ff ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
|
||||
func (_eea WriterLogger )Info (format string ,args ...interface{}){if _eea .LogLevel >=LogLevelInfo {_de :="\u005bI\u004e\u0046\u004f\u005d\u0020";_eea .logToWriter (_eea .Output ,_de ,format ,args ...);};};
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_bae ConsoleLogger )Notice (format string ,args ...interface{}){if _bae .LogLevel >=LogLevelNotice {_de :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bae .output (_b .Stdout ,_de ,format ,args ...);};};func (_da WriterLogger )logToWriter (_cge _fe .Writer ,_fec string ,_aba string ,_gbg ...interface{}){_bb (_cge ,_fec ,_aba ,_gbg );};
|
||||
|
||||
// Notice does nothing for dummy logger.
|
||||
func (DummyLogger )Notice (format string ,args ...interface{}){};
|
||||
|
||||
// Error logs error message.
|
||||
func (_a ConsoleLogger )Error (format string ,args ...interface{}){if _a .LogLevel >=LogLevelError {_ceg :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_a .output (_b .Stdout ,_ceg ,format ,args ...);};};
|
||||
// Debug logs debug message.
|
||||
func (_ba WriterLogger )Debug (format string ,args ...interface{}){if _ba .LogLevel >=LogLevelDebug {_cge :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ba .logToWriter (_ba .Output ,_cge ,format ,args ...);};};
|
||||
|
||||
// Info does nothing for dummy logger.
|
||||
func (DummyLogger )Info (format string ,args ...interface{}){};
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_ccb WriterLogger )Warning (format string ,args ...interface{}){if _ccb .LogLevel >=LogLevelWarning {_ge :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ccb .logToWriter (_ccb .Output ,_ge ,format ,args ...);};};
|
||||
|
||||
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
|
||||
func SetLogger (logger Logger ){Log =logger };const _feg =45;
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_gb WriterLogger )Debug (format string ,args ...interface{}){if _gb .LogLevel >=LogLevelDebug {_ea :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_gb .logToWriter (_gb .Output ,_ea ,format ,args ...);};};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_dca ConsoleLogger )Trace (format string ,args ...interface{}){if _dca .LogLevel >=LogLevelTrace {_bab :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_dca .output (_b .Stdout ,_bab ,format ,args ...);};};
|
||||
func (_dc WriterLogger )Warning (format string ,args ...interface{}){if _dc .LogLevel >=LogLevelWarning {_fae :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_dc .logToWriter (_dc .Output ,_fae ,format ,args ...);};};
|
||||
|
||||
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
|
||||
type ConsoleLogger struct{LogLevel LogLevel ;};const Version ="\u0033\u002e\u0031\u0032\u002e\u0032";var ReleasedAt =_c .Date (_ede ,_ffc ,_be ,_bba ,_feg ,0,0,_c .UTC );
|
||||
type ConsoleLogger struct{LogLevel LogLevel ;};
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};
|
||||
|
||||
// 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 };
|
||||
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _fe .Writer )*WriterLogger {_fgd :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_fgd ;};const _ffc =10;var Log Logger =DummyLogger {};
|
||||
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_eg string ,_fea ...interface{});Warning (_ba string ,_g ...interface{});Notice (_fa string ,_fead ...interface{});Info (_ce string ,_fc ...interface{});Debug (_fga string ,_d ...interface{});Trace (_dc string ,_ed ...interface{});IsLogLevel (_cc LogLevel )bool ;};
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _fe .Writer ;};
|
||||
|
||||
// Error logs error message.
|
||||
func (_df WriterLogger )Error (format string ,args ...interface{}){if _df .LogLevel >=LogLevelError {_cd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_df .logToWriter (_df .Output ,_cd ,format ,args ...);};};
|
||||
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};const _be =5;
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _f .Writer )*WriterLogger {_gg :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_gg ;};
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};const _add ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
|
||||
|
||||
// Error logs error message.
|
||||
func (_gf ConsoleLogger )Error (format string ,args ...interface{}){if _gf .LogLevel >=LogLevelError {_bec :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gf .output (_e .Stdout ,_bec ,format ,args ...);};};func _cff (_bfc _f .Writer ,_bg string ,_fc string ,_df ...interface{}){_ ,_bda ,_ge ,_ebf :=_ca .Caller (3);if !_ebf {_bda ="\u003f\u003f\u003f";_ge =0;}else {_bda =_bf .Base (_bda );};_eeeg :=_c .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_bg ,_bda ,_ge )+_fc +"\u000a";_c .Fprintf (_bfc ,_eeeg ,_df ...);};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_cb ConsoleLogger )Warning (format string ,args ...interface{}){if _cb .LogLevel >=LogLevelWarning {_ccg :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_cb .output (_e .Stdout ,_ccg ,format ,args ...);};};
|
||||
|
||||
// Info logs info message.
|
||||
func (_fab ConsoleLogger )Info (format string ,args ...interface{}){if _fab .LogLevel >=LogLevelInfo {_aa :="\u005bI\u004e\u0046\u004f\u005d\u0020";_fab .output (_e .Stdout ,_aa ,format ,args ...);};};
|
||||
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};
|
||||
|
||||
// LogLevel is the verbosity level for logging.
|
||||
type LogLevel int ;
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_adc ConsoleLogger )Notice (format string ,args ...interface{}){if _adc .LogLevel >=LogLevelNotice {_eg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_adc .output (_e .Stdout ,_eg ,format ,args ...);};};
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _f .Writer ;};const Version ="\u0033\u002e\u0031\u0032\u002e\u0033";var Log Logger =DummyLogger {};const _fed =13;
|
||||
|
||||
// Error logs error message.
|
||||
func (_gc WriterLogger )Error (format string ,args ...interface{}){if _gc .LogLevel >=LogLevelError {_edb :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gc .logToWriter (_gc .Output ,_edb ,format ,args ...);};};
|
||||
|
||||
// Notice does nothing for dummy logger.
|
||||
func (DummyLogger )Notice (format string ,args ...interface{}){};var ReleasedAt =_b .Date (_egb ,_cgd ,_bdg ,_fed ,_def ,0,0,_b .UTC );func UtcTimeFormat (t _b .Time )string {return t .Format (_add )+"\u0020\u0055\u0054\u0043"};
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};func (_bbfa WriterLogger )logToWriter (_deb _f .Writer ,_ffc string ,_ded string ,_eee ...interface{}){_cff (_deb ,_ffc ,_ded ,_eee );};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_bbf WriterLogger )Trace (format string ,args ...interface{}){if _bbf .LogLevel >=LogLevelTrace {_dd :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_bbf .logToWriter (_bbf .Output ,_dd ,format ,args ...);};};
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_gb WriterLogger )Notice (format string ,args ...interface{}){if _gb .LogLevel >=LogLevelNotice {_fe :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_gb .logToWriter (_gb .Output ,_fe ,format ,args ...);};};
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};const _cgd =10;const _bdg =12;const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_ccb ConsoleLogger )Debug (format string ,args ...interface{}){if _ccb .LogLevel >=LogLevelDebug {_ee :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ccb .output (_e .Stdout ,_ee ,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 (_cgc WriterLogger )IsLogLevel (level LogLevel )bool {return _cgc .LogLevel >=level };const _egb =2020;
|
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 (_g "fmt";_c "github.com/unidoc/unipdf/v3/contentstream";_ba "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/internal/transform";_d "github.com/unidoc/unipdf/v3/model";_bd "math";);
|
||||
package draw ;import (_f "fmt";_b "github.com/unidoc/unipdf/v3/contentstream";_da "github.com/unidoc/unipdf/v3/core";_de "github.com/unidoc/unipdf/v3/internal/transform";_e "github.com/unidoc/unipdf/v3/model";_d "math";);
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_ac CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ac .Curves =append (_ac .Curves ,curve );return _ac ;};
|
||||
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_aea Rectangle )ToPdfRectangle ()*_e .PdfRectangle {return &_e .PdfRectangle {Llx :_aea .X ,Lly :_aea .Y ,Urx :_aea .X +_aea .Width ,Ury :_aea .Y +_aea .Height };};
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_dage :=Vector {};_dage .Dx =dx ;_dage .Dy =dy ;return _dage };
|
||||
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_dagf :=Vector {};_dagf .Dx =length *_d .Cos (theta );_dagf .Dy =length *_d .Sin (theta );return _dagf ;};
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_bd BoundingBox )ToPdfRectangle ()*_e .PdfRectangle {return &_e .PdfRectangle {Llx :_bd .X ,Lly :_bd .Y ,Urx :_bd .X +_bd .Width ,Ury :_bd .Y +_bd .Height };};
|
||||
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_ae Point )Rotate (theta float64 )Point {_ddb :=_de .NewPoint (_ae .X ,_ae .Y ).Rotate (theta );return NewPoint (_ddb .X ,_ddb .Y );};
|
||||
|
||||
// PolyBezierCurve represents a composite curve that is the result of
|
||||
// joining multiple cubic Bezier curves.
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_e .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_e .PdfColorDeviceRGB ;};
|
||||
|
||||
// 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 (_agc Line )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){_fg ,_bbc :=_agc .X1 ,_agc .X2 ;_acc ,_ecf :=_agc .Y1 ,_agc .Y2 ;_ecdb :=_ecf -_acc ;_ee :=_bbc -_fg ;_dag :=_d .Atan2 (_ecdb ,_ee );L :=_d .Sqrt (_d .Pow (_ee ,2.0)+_d .Pow (_ecdb ,2.0));_cabc :=_agc .LineWidth ;_bbcc :=_d .Pi ;_edc :=1.0;if _ee < 0{_edc *=-1.0;};if _ecdb < 0{_edc *=-1.0;};VsX :=_edc *(-_cabc /2*_d .Cos (_dag +_bbcc /2));VsY :=_edc *(-_cabc /2*_d .Sin (_dag +_bbcc /2)+_cabc *_d .Sin (_dag +_bbcc /2));V1X :=VsX +_cabc /2*_d .Cos (_dag +_bbcc /2);V1Y :=VsY +_cabc /2*_d .Sin (_dag +_bbcc /2);V2X :=VsX +_cabc /2*_d .Cos (_dag +_bbcc /2)+L *_d .Cos (_dag );V2Y :=VsY +_cabc /2*_d .Sin (_dag +_bbcc /2)+L *_d .Sin (_dag );V3X :=VsX +_cabc /2*_d .Cos (_dag +_bbcc /2)+L *_d .Cos (_dag )+_cabc *_d .Cos (_dag -_bbcc /2);V3Y :=VsY +_cabc /2*_d .Sin (_dag +_bbcc /2)+L *_d .Sin (_dag )+_cabc *_d .Sin (_dag -_bbcc /2);V4X :=VsX +_cabc /2*_d .Cos (_dag -_bbcc /2);V4Y :=VsY +_cabc /2*_d .Sin (_dag -_bbcc /2);_adfc :=NewPath ();_adfc =_adfc .AppendPoint (NewPoint (V1X ,V1Y ));_adfc =_adfc .AppendPoint (NewPoint (V2X ,V2Y ));_adfc =_adfc .AppendPoint (NewPoint (V3X ,V3Y ));_adfc =_adfc .AppendPoint (NewPoint (V4X ,V4Y ));_agce :=_agc .LineEndingStyle1 ;_gfc :=_agc .LineEndingStyle2 ;_bbb :=3*_cabc ;_cc :=3*_cabc ;_dga :=(_cc -_cabc )/2;if _gfc ==LineEndingStyleArrow {_aef :=_adfc .GetPointNumber (2);_bcc :=NewVectorPolar (_bbb ,_dag +_bbcc );_fdd :=_aef .AddVector (_bcc );_ega :=NewVectorPolar (_cc /2,_dag +_bbcc /2);_bga :=NewVectorPolar (_bbb ,_dag );_afg :=NewVectorPolar (_dga ,_dag +_bbcc /2);_bdf :=_fdd .AddVector (_afg );_afb :=_bga .Add (_ega .Flip ());_add :=_bdf .AddVector (_afb );_bf :=_ega .Scale (2).Flip ().Add (_afb .Flip ());_bba :=_add .AddVector (_bf );_aaf :=_fdd .AddVector (NewVectorPolar (_cabc ,_dag -_bbcc /2));_abc :=NewPath ();_abc =_abc .AppendPoint (_adfc .GetPointNumber (1));_abc =_abc .AppendPoint (_fdd );_abc =_abc .AppendPoint (_bdf );_abc =_abc .AppendPoint (_add );_abc =_abc .AppendPoint (_bba );_abc =_abc .AppendPoint (_aaf );_abc =_abc .AppendPoint (_adfc .GetPointNumber (4));_adfc =_abc ;};if _agce ==LineEndingStyleArrow {_fcd :=_adfc .GetPointNumber (1);_afef :=_adfc .GetPointNumber (_adfc .Length ());_geb :=NewVectorPolar (_cabc /2,_dag +_bbcc +_bbcc /2);_eeg :=_fcd .AddVector (_geb );_bcf :=NewVectorPolar (_bbb ,_dag ).Add (NewVectorPolar (_cc /2,_dag +_bbcc /2));_fca :=_eeg .AddVector (_bcf );_gd :=NewVectorPolar (_dga ,_dag -_bbcc /2);_baa :=_fca .AddVector (_gd );_ceb :=NewVectorPolar (_bbb ,_dag );_bcd :=_afef .AddVector (_ceb );_ggc :=NewVectorPolar (_dga ,_dag +_bbcc +_bbcc /2);_aec :=_bcd .AddVector (_ggc );_gfe :=_eeg ;_bbaf :=NewPath ();_bbaf =_bbaf .AppendPoint (_eeg );_bbaf =_bbaf .AppendPoint (_fca );_bbaf =_bbaf .AppendPoint (_baa );for _ ,_bggd :=range _adfc .Points [1:len (_adfc .Points )-1]{_bbaf =_bbaf .AppendPoint (_bggd );};_bbaf =_bbaf .AppendPoint (_bcd );_bbaf =_bbaf .AppendPoint (_aec );_bbaf =_bbaf .AppendPoint (_gfe );_adfc =_bbaf ;};_fda :=_b .NewContentCreator ();_fda .Add_q ().Add_rg (_agc .LineColor .R (),_agc .LineColor .G (),_agc .LineColor .B ());if len (gsName )> 1{_fda .Add_gs (_da .PdfObjectName (gsName ));};_adfc =_adfc .Offset (_agc .X1 ,_agc .Y1 );_afbe :=_adfc .GetBoundingBox ();DrawPathWithCreator (_adfc ,_fda );if _agc .LineStyle ==LineStyleDashed {_fda .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_fda .Add_f ().Add_Q ();};return _fda .Bytes (),_afbe .ToPdfRectangle (),nil ;};
|
||||
|
||||
// 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 *_e .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_e .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_cac Point )AddVector (v Vector )Point {_cac .X +=v .Dx ;_cac .Y +=v .Dy ;return _cac };
|
||||
|
||||
// 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 _cgb ,_aefd :=range path .Points {if _cgb ==0{creator .Add_m (_aefd .X ,_aefd .Y );}else {creator .Add_l (_aefd .X ,_aefd .Y );};};};func (_gf Point )String ()string {return _f .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_gf .X ,_gf .Y );};
|
||||
|
||||
// Copy returns a clone of the path.
|
||||
func (_eab Path )Copy ()Path {_ce :=Path {};_ce .Points =[]Point {};for _ ,_ggb :=range _eab .Points {_ce .Points =append (_ce .Points ,_ggb );};return _ce ;};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_e .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_ef CubicBezierPath )Copy ()CubicBezierPath {_fb :=CubicBezierPath {};_fb .Curves =[]CubicBezierCurve {};for _ ,_cg :=range _ef .Curves {_fb .Curves =append (_fb .Curves ,_cg );};return _fb ;};
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_efb Vector )Rotate (phi float64 )Vector {_gga :=_efb .Magnitude ();_bgf :=_efb .GetPolarAngle ();return NewVectorPolar (_gga ,_bgf +phi );};
|
||||
|
||||
// Length returns the number of points in the path.
|
||||
func (_eca Path )Length ()int {return len (_eca .Points )};
|
||||
|
||||
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
||||
func (_adf Point )Add (dx ,dy float64 )Point {_adf .X +=dx ;_adf .Y +=dy ;return _adf };
|
||||
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_cab Path )RemovePoint (number int )Path {if number < 1||number > len (_cab .Points ){return _cab ;};_dd :=number -1;_cab .Points =append (_cab .Points [:_dd ],_cab .Points [_dd +1:]...);return _cab ;};
|
||||
|
||||
// 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 {_dda :=Vector {};_dda .Dx =b .X -a .X ;_dda .Dy =b .Y -a .Y ;return _dda ;};
|
||||
|
||||
// GetBounds returns the bounding box of the Bezier curve.
|
||||
func (_g CubicBezierCurve )GetBounds ()_e .PdfRectangle {_bg :=_g .P0 .X ;_ba :=_g .P0 .X ;_be :=_g .P0 .Y ;_bb :=_g .P0 .Y ;for _a :=0.0;_a <=1.0;_a +=0.001{Rx :=_g .P0 .X *_d .Pow (1-_a ,3)+_g .P1 .X *3*_a *_d .Pow (1-_a ,2)+_g .P2 .X *3*_d .Pow (_a ,2)*(1-_a )+_g .P3 .X *_d .Pow (_a ,3);Ry :=_g .P0 .Y *_d .Pow (1-_a ,3)+_g .P1 .Y *3*_a *_d .Pow (1-_a ,2)+_g .P2 .Y *3*_d .Pow (_a ,2)*(1-_a )+_g .P3 .Y *_d .Pow (_a ,3);if Rx < _bg {_bg =Rx ;};if Rx > _ba {_ba =Rx ;};if Ry < _be {_be =Ry ;};if Ry > _bb {_bb =Ry ;};};_ad :=_e .PdfRectangle {};_ad .Llx =_bg ;_ad .Lly =_be ;_ad .Urx =_ba ;_ad .Ury =_bb ;return _ad ;};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_ccgc Vector )Magnitude ()float64 {return _d .Sqrt (_d .Pow (_ccgc .Dx ,2.0)+_d .Pow (_ccgc .Dy ,2.0));};
|
||||
|
||||
// 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 (_aefg BasicLine )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){_daef :=_aefg .LineWidth ;_fdbe :=NewPath ();_fdbe =_fdbe .AppendPoint (NewPoint (_aefg .X1 ,_aefg .Y1 ));_fdbe =_fdbe .AppendPoint (NewPoint (_aefg .X2 ,_aefg .Y2 ));_cf :=_b .NewContentCreator ();_ff :=_fdbe .GetBoundingBox ();DrawPathWithCreator (_fdbe ,_cf );if _aefg .LineStyle ==LineStyleDashed {_cf .Add_d ([]int64 {1,1},0);};_cf .Add_RG (_aefg .LineColor .R (),_aefg .LineColor .G (),_aefg .LineColor .B ()).Add_w (_daef ).Add_S ().Add_Q ();return _cf .Bytes (),_ff .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 *_e .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_e .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_bbf Path )AppendPoint (point Point )Path {_bbf .Points =append (_bbf .Points ,point );return _bbf };
|
||||
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_dg CubicBezierPath )GetBoundingBox ()Rectangle {_ecd :=Rectangle {};_gg :=0.0;_ace :=0.0;_efg :=0.0;_efgf :=0.0;for _eaf ,_cdf :=range _dg .Curves {_ab :=_cdf .GetBounds ();if _eaf ==0{_gg =_ab .Llx ;_ace =_ab .Urx ;_efg =_ab .Lly ;_efgf =_ab .Ury ;continue ;};if _ab .Llx < _gg {_gg =_ab .Llx ;};if _ab .Urx > _ace {_ace =_ab .Urx ;};if _ab .Lly < _efg {_efg =_ab .Lly ;};if _ab .Ury > _efgf {_efgf =_ab .Ury ;};};_ecd .X =_gg ;_ecd .Y =_efg ;_ecd .Width =_ace -_gg ;_ecd .Height =_efgf -_efg ;return _ecd ;};
|
||||
|
||||
// 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 (_cgd Circle )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){_ag :=_cgd .Width /2;_fbc :=_cgd .Height /2;if _cgd .BorderEnabled {_ag -=_cgd .BorderWidth /2;_fbc -=_cgd .BorderWidth /2;};_ed :=0.551784;_gac :=_ag *_ed ;_fea :=_fbc *_ed ;_dae :=NewCubicBezierPath ();_dae =_dae .AppendCurve (NewCubicBezierCurve (-_ag ,0,-_ag ,_fea ,-_gac ,_fbc ,0,_fbc ));_dae =_dae .AppendCurve (NewCubicBezierCurve (0,_fbc ,_gac ,_fbc ,_ag ,_fea ,_ag ,0));_dae =_dae .AppendCurve (NewCubicBezierCurve (_ag ,0,_ag ,-_fea ,_gac ,-_fbc ,0,-_fbc ));_dae =_dae .AppendCurve (NewCubicBezierCurve (0,-_fbc ,-_gac ,-_fbc ,-_ag ,-_fea ,-_ag ,0));_dae =_dae .Offset (_ag ,_fbc );if _cgd .BorderEnabled {_dae =_dae .Offset (_cgd .BorderWidth /2,_cgd .BorderWidth /2);};if _cgd .X !=0||_cgd .Y !=0{_dae =_dae .Offset (_cgd .X ,_cgd .Y );};_fa :=_b .NewContentCreator ();_fa .Add_q ();if _cgd .FillEnabled {_fa .Add_rg (_cgd .FillColor .R (),_cgd .FillColor .G (),_cgd .FillColor .B ());};if _cgd .BorderEnabled {_fa .Add_RG (_cgd .BorderColor .R (),_cgd .BorderColor .G (),_cgd .BorderColor .B ());_fa .Add_w (_cgd .BorderWidth );};if len (gsName )> 1{_fa .Add_gs (_da .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_dae ,_fa );_fa .Add_h ();if _cgd .FillEnabled &&_cgd .BorderEnabled {_fa .Add_B ();}else if _cgd .FillEnabled {_fa .Add_f ();}else if _cgd .BorderEnabled {_fa .Add_S ();};_fa .Add_Q ();_bgg :=_dae .GetBoundingBox ();if _cgd .BorderEnabled {_bgg .Height +=_cgd .BorderWidth ;_bgg .Width +=_cgd .BorderWidth ;_bgg .X -=_cgd .BorderWidth /2;_bgg .Y -=_cgd .BorderWidth /2;};return _fa .Bytes (),_bgg .ToPdfRectangle (),nil ;};
|
||||
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_cdd Vector )FlipX ()Vector {_cdd .Dx =-_cdd .Dx ;return _cdd };
|
||||
|
||||
// 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 (_beb PolyBezierCurve )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){if _beb .BorderColor ==nil {_beb .BorderColor =_e .NewPdfColorDeviceRGB (0,0,0);};_cee :=NewCubicBezierPath ();for _ ,_bgc :=range _beb .Curves {_cee =_cee .AppendCurve (_bgc );};_ggf :=_b .NewContentCreator ();_ggf .Add_q ();_beb .FillEnabled =_beb .FillEnabled &&_beb .FillColor !=nil ;if _beb .FillEnabled {_ggf .Add_rg (_beb .FillColor .R (),_beb .FillColor .G (),_beb .FillColor .B ());};_ggf .Add_RG (_beb .BorderColor .R (),_beb .BorderColor .G (),_beb .BorderColor .B ());_ggf .Add_w (_beb .BorderWidth );if len (gsName )> 1{_ggf .Add_gs (_da .PdfObjectName (gsName ));};for _ ,_afe :=range _cee .Curves {_ggf .Add_m (_afe .P0 .X ,_afe .P0 .Y );_ggf .Add_c (_afe .P1 .X ,_afe .P1 .Y ,_afe .P2 .X ,_afe .P2 .Y ,_afe .P3 .X ,_afe .P3 .Y );};if _beb .FillEnabled {_ggf .Add_h ();_ggf .Add_B ();}else {_ggf .Add_S ();};_ggf .Add_Q ();return _ggf .Bytes (),_cee .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
|
||||
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
|
||||
// or arrows at either end. The line also has a specified width, color and opacity.
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_d .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_e .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_caeg Vector )Add (other Vector )Vector {_caeg .Dx +=other .Dx ;_caeg .Dy +=other .Dy ;return _caeg ;};
|
||||
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_dc Vector )GetPolarAngle ()float64 {return _d .Atan2 (_dc .Dy ,_dc .Dx )};
|
||||
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_gcac Vector )FlipY ()Vector {_gcac .Dy =-_gcac .Dy ;return _gcac };
|
||||
// LineStyle refers to how the line will be created.
|
||||
type LineStyle int ;
|
||||
|
||||
// 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 {_fd :=CubicBezierCurve {};_fd .P0 =NewPoint (x0 ,y0 );_fd .P1 =NewPoint (x1 ,y1 );_fd .P2 =NewPoint (x2 ,y2 );_fd .P3 =NewPoint (x3 ,y3 );return _fd ;};
|
||||
|
||||
// Draw draws the polygon. A graphics state name can be specified for
|
||||
// setting the polygon properties (e.g. setting the opacity). Otherwise leave
|
||||
// empty (""). Returns the content stream as a byte array and the polygon
|
||||
// bounding box.
|
||||
func (_fga Polygon )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_ge :=_c .NewContentCreator ();_ge .Add_q ();_fga .FillEnabled =_fga .FillEnabled &&_fga .FillColor !=nil ;if _fga .FillEnabled {_ge .Add_rg (_fga .FillColor .R (),_fga .FillColor .G (),_fga .FillColor .B ());};_fga .BorderEnabled =_fga .BorderEnabled &&_fga .BorderColor !=nil ;if _fga .BorderEnabled {_ge .Add_RG (_fga .BorderColor .R (),_fga .BorderColor .G (),_fga .BorderColor .B ());_ge .Add_w (_fga .BorderWidth );};if len (gsName )> 1{_ge .Add_gs (_ba .PdfObjectName (gsName ));};_eec :=NewPath ();for _ ,_fge :=range _fga .Points {for _cegf ,_cf :=range _fge {_eec =_eec .AppendPoint (_cf );if _cegf ==0{_ge .Add_m (_cf .X ,_cf .Y );}else {_ge .Add_l (_cf .X ,_cf .Y );};};_ge .Add_h ();};if _fga .FillEnabled &&_fga .BorderEnabled {_ge .Add_B ();}else if _fga .FillEnabled {_ge .Add_f ();}else if _fga .BorderEnabled {_ge .Add_S ();};_ge .Add_Q ();return _ge .Bytes (),_eec .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
func (_ece Polygon )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){_dde :=_b .NewContentCreator ();_dde .Add_q ();_ece .FillEnabled =_ece .FillEnabled &&_ece .FillColor !=nil ;if _ece .FillEnabled {_dde .Add_rg (_ece .FillColor .R (),_ece .FillColor .G (),_ece .FillColor .B ());};_ece .BorderEnabled =_ece .BorderEnabled &&_ece .BorderColor !=nil ;if _ece .BorderEnabled {_dde .Add_RG (_ece .BorderColor .R (),_ece .BorderColor .G (),_ece .BorderColor .B ());_dde .Add_w (_ece .BorderWidth );};if len (gsName )> 1{_dde .Add_gs (_da .PdfObjectName (gsName ));};_cgf :=NewPath ();for _ ,_ede :=range _ece .Points {for _fc ,_bc :=range _ede {_cgf =_cgf .AppendPoint (_bc );if _fc ==0{_dde .Add_m (_bc .X ,_bc .Y );}else {_dde .Add_l (_bc .X ,_bc .Y );};};_dde .Add_h ();};if _ece .FillEnabled &&_ece .BorderEnabled {_dde .Add_B ();}else if _ece .FillEnabled {_dde .Add_f ();}else if _ece .BorderEnabled {_dde .Add_S ();};_dde .Add_Q ();return _dde .Bytes (),_cgf .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_d .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_eb Path )GetPointNumber (number int )Point {if number < 1||number > len (_eb .Points ){return Point {};};return _eb .Points [number -1];};
|
||||
|
||||
// LineStyle refers to how the line will be created.
|
||||
type LineStyle int ;
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_dab :=Vector {};_dab .Dx =dx ;_dab .Dy =dy ;return _dab };
|
||||
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_eb Path )RemovePoint (number int )Path {if number < 1||number > len (_eb .Points ){return _eb ;};_eeb :=number -1;_eb .Points =append (_eb .Points [:_eeb ],_eb .Points [_eeb +1:]...);return _eb ;};
|
||||
|
||||
// PolyBezierCurve represents a composite curve that is the result of
|
||||
// joining multiple cubic Bezier curves.
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_d .PdfColorDeviceRGB ;};
|
||||
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_ed Path )AppendPoint (point Point )Path {_ed .Points =append (_ed .Points ,point );return _ed };
|
||||
|
||||
// Offset shifts the Bezier path with the specified offsets.
|
||||
func (_ecf CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _dg ,_ca :=range _ecf .Curves {_ecf .Curves [_dg ]=_ca .AddOffsetXY (offX ,offY );};return _ecf ;};func (_gab Point )String ()string {return _g .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_gab .X ,_gab .Y );};
|
||||
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_bg :=CubicBezierPath {};_bg .Curves =[]CubicBezierCurve {};return _bg ;};
|
||||
|
||||
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
|
||||
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
|
||||
// if one occurred.
|
||||
func (_cgc Line )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_abe ,_aae :=_cgc .X1 ,_cgc .X2 ;_ecc ,_ad :=_cgc .Y1 ,_cgc .Y2 ;_fd :=_ad -_ecc ;_cce :=_aae -_abe ;_cee :=_bd .Atan2 (_fd ,_cce );L :=_bd .Sqrt (_bd .Pow (_cce ,2.0)+_bd .Pow (_fd ,2.0));_abec :=_cgc .LineWidth ;_fc :=_bd .Pi ;_cfe :=1.0;if _cce < 0{_cfe *=-1.0;};if _fd < 0{_cfe *=-1.0;};VsX :=_cfe *(-_abec /2*_bd .Cos (_cee +_fc /2));VsY :=_cfe *(-_abec /2*_bd .Sin (_cee +_fc /2)+_abec *_bd .Sin (_cee +_fc /2));V1X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2);V1Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2);V2X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2)+L *_bd .Cos (_cee );V2Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2)+L *_bd .Sin (_cee );V3X :=VsX +_abec /2*_bd .Cos (_cee +_fc /2)+L *_bd .Cos (_cee )+_abec *_bd .Cos (_cee -_fc /2);V3Y :=VsY +_abec /2*_bd .Sin (_cee +_fc /2)+L *_bd .Sin (_cee )+_abec *_bd .Sin (_cee -_fc /2);V4X :=VsX +_abec /2*_bd .Cos (_cee -_fc /2);V4Y :=VsY +_abec /2*_bd .Sin (_cee -_fc /2);_eee :=NewPath ();_eee =_eee .AppendPoint (NewPoint (V1X ,V1Y ));_eee =_eee .AppendPoint (NewPoint (V2X ,V2Y ));_eee =_eee .AppendPoint (NewPoint (V3X ,V3Y ));_eee =_eee .AppendPoint (NewPoint (V4X ,V4Y ));_cdg :=_cgc .LineEndingStyle1 ;_dba :=_cgc .LineEndingStyle2 ;_df :=3*_abec ;_edb :=3*_abec ;_cfc :=(_edb -_abec )/2;if _dba ==LineEndingStyleArrow {_ebe :=_eee .GetPointNumber (2);_cca :=NewVectorPolar (_df ,_cee +_fc );_fcc :=_ebe .AddVector (_cca );_ace :=NewVectorPolar (_edb /2,_cee +_fc /2);_dea :=NewVectorPolar (_df ,_cee );_gga :=NewVectorPolar (_cfc ,_cee +_fc /2);_ag :=_fcc .AddVector (_gga );_daf :=_dea .Add (_ace .Flip ());_dbe :=_ag .AddVector (_daf );_fdg :=_ace .Scale (2).Flip ().Add (_daf .Flip ());_dbd :=_dbe .AddVector (_fdg );_ccae :=_fcc .AddVector (NewVectorPolar (_abec ,_cee -_fc /2));_ebc :=NewPath ();_ebc =_ebc .AppendPoint (_eee .GetPointNumber (1));_ebc =_ebc .AppendPoint (_fcc );_ebc =_ebc .AppendPoint (_ag );_ebc =_ebc .AppendPoint (_dbe );_ebc =_ebc .AppendPoint (_dbd );_ebc =_ebc .AppendPoint (_ccae );_ebc =_ebc .AppendPoint (_eee .GetPointNumber (4));_eee =_ebc ;};if _cdg ==LineEndingStyleArrow {_dbg :=_eee .GetPointNumber (1);_aaea :=_eee .GetPointNumber (_eee .Length ());_gaa :=NewVectorPolar (_abec /2,_cee +_fc +_fc /2);_bac :=_dbg .AddVector (_gaa );_feaa :=NewVectorPolar (_df ,_cee ).Add (NewVectorPolar (_edb /2,_cee +_fc /2));_aga :=_bac .AddVector (_feaa );_cfed :=NewVectorPolar (_cfc ,_cee -_fc /2);_ceb :=_aga .AddVector (_cfed );_fdb :=NewVectorPolar (_df ,_cee );_adc :=_aaea .AddVector (_fdb );_gafd :=NewVectorPolar (_cfc ,_cee +_fc +_fc /2);_be :=_adc .AddVector (_gafd );_ccg :=_bac ;_ggg :=NewPath ();_ggg =_ggg .AppendPoint (_bac );_ggg =_ggg .AppendPoint (_aga );_ggg =_ggg .AppendPoint (_ceb );for _ ,_cfd :=range _eee .Points [1:len (_eee .Points )-1]{_ggg =_ggg .AppendPoint (_cfd );};_ggg =_ggg .AppendPoint (_adc );_ggg =_ggg .AppendPoint (_be );_ggg =_ggg .AppendPoint (_ccg );_eee =_ggg ;};_eff :=_c .NewContentCreator ();_eff .Add_q ().Add_rg (_cgc .LineColor .R (),_cgc .LineColor .G (),_cgc .LineColor .B ());if len (gsName )> 1{_eff .Add_gs (_ba .PdfObjectName (gsName ));};_eee =_eee .Offset (_cgc .X1 ,_cgc .Y1 );_ade :=_eee .GetBoundingBox ();DrawPathWithCreator (_eee ,_eff );if _cgc .LineStyle ==LineStyleDashed {_eff .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_eff .Add_f ().Add_Q ();};return _eff .Bytes (),_ade .ToPdfRectangle (),nil ;};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_aff Point )AddVector (v Vector )Point {_aff .X +=v .Dx ;_aff .Y +=v .Dy ;return _aff };const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_da BoundingBox )ToPdfRectangle ()*_d .PdfRectangle {return &_d .PdfRectangle {Llx :_da .X ,Lly :_da .Y ,Urx :_da .X +_da .Width ,Ury :_da .Y +_da .Height };};
|
||||
|
||||
// NewVectorBetween returns a new vector with the direction specified by
|
||||
// the subtraction of point a from point b (b-a).
|
||||
func NewVectorBetween (a Point ,b Point )Vector {_efd :=Vector {};_efd .Dx =b .X -a .X ;_efd .Dy =b .Y -a .Y ;return _efd ;};
|
||||
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_gce Vector )Scale (factor float64 )Vector {_gfa :=_gce .Magnitude ();_bae :=_gce .GetPolarAngle ();_gce .Dx =factor *_gfa *_bd .Cos (_bae );_gce .Dy =factor *_gfa *_bd .Sin (_bae );return _gce ;};
|
||||
// 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 _cga ,_fgd :=range bpath .Curves {if _cga ==0{creator .Add_m (_fgd .P0 .X ,_fgd .P0 .Y );};creator .Add_c (_fgd .P1 .X ,_fgd .P1 .Y ,_fgd .P2 .X ,_fgd .P2 .Y ,_fgd .P3 .X ,_fgd .P3 .Y );};};
|
||||
|
||||
// AddOffsetXY adds X,Y offset to all points on a curve.
|
||||
func (_ec CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_ec .P0 .X +=offX ;_ec .P1 .X +=offX ;_ec .P2 .X +=offX ;_ec .P3 .X +=offX ;_ec .P0 .Y +=offY ;_ec .P1 .Y +=offY ;_ec .P2 .Y +=offY ;_ec .P3 .Y +=offY ;return _ec ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_eee Vector )Flip ()Vector {_ccg :=_eee .Magnitude ();_gge :=_eee .GetPolarAngle ();_eee .Dx =_ccg *_d .Cos (_gge +_d .Pi );_eee .Dy =_ccg *_d .Sin (_gge +_d .Pi );return _eee ;};
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_gcb Vector )Scale (factor float64 )Vector {_dgd :=_gcb .Magnitude ();_cfa :=_gcb .GetPolarAngle ();_gcb .Dx =factor *_dgd *_d .Cos (_cfa );_gcb .Dy =factor *_dgd *_d .Sin (_cfa );return _gcb ;};
|
||||
|
||||
// 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 *_e .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
|
||||
// BoundingBox represents the smallest rectangular area that encapsulates an object.
|
||||
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
|
||||
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_ea Vector )FlipX ()Vector {_ea .Dx =-_ea .Dx ;return _ea };
|
||||
|
||||
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
|
||||
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
|
||||
// one occurred.
|
||||
func (_gffe BasicLine )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_dfd :=_gffe .LineWidth ;_bfa :=NewPath ();_bfa =_bfa .AppendPoint (NewPoint (_gffe .X1 ,_gffe .Y1 ));_bfa =_bfa .AppendPoint (NewPoint (_gffe .X2 ,_gffe .Y2 ));_beg :=_c .NewContentCreator ();_bdag :=_bfa .GetBoundingBox ();DrawPathWithCreator (_bfa ,_beg );if _gffe .LineStyle ==LineStyleDashed {_beg .Add_d ([]int64 {1,1},0);};_beg .Add_RG (_gffe .LineColor .R (),_gffe .LineColor .G (),_gffe .LineColor .B ()).Add_w (_dfd ).Add_S ().Add_Q ();return _beg .Bytes (),_bdag .ToPdfRectangle (),nil ;};
|
||||
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_cbe Rectangle )ToPdfRectangle ()*_d .PdfRectangle {return &_d .PdfRectangle {Llx :_cbe .X ,Lly :_cbe .Y ,Urx :_cbe .X +_cbe .Width ,Ury :_cbe .Y +_cbe .Height };};
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_ef CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ef .Curves =append (_ef .Curves ,curve );return _ef ;};
|
||||
|
||||
// Copy returns a clone of the path.
|
||||
func (_eg Path )Copy ()Path {_fg :=Path {};_fg .Points =[]Point {};for _ ,_ecd :=range _eg .Points {_fg .Points =append (_fg .Points ,_ecd );};return _fg ;};
|
||||
|
||||
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
|
||||
func (_gfe Rectangle )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_gaf :=NewPath ();_gaf =_gaf .AppendPoint (NewPoint (0,0));_gaf =_gaf .AppendPoint (NewPoint (0,_gfe .Height ));_gaf =_gaf .AppendPoint (NewPoint (_gfe .Width ,_gfe .Height ));_gaf =_gaf .AppendPoint (NewPoint (_gfe .Width ,0));_gaf =_gaf .AppendPoint (NewPoint (0,0));if _gfe .X !=0||_gfe .Y !=0{_gaf =_gaf .Offset (_gfe .X ,_gfe .Y );};_fea :=_c .NewContentCreator ();_fea .Add_q ();if _gfe .FillEnabled {_fea .Add_rg (_gfe .FillColor .R (),_gfe .FillColor .G (),_gfe .FillColor .B ());};if _gfe .BorderEnabled {_fea .Add_RG (_gfe .BorderColor .R (),_gfe .BorderColor .G (),_gfe .BorderColor .B ());_fea .Add_w (_gfe .BorderWidth );};if len (gsName )> 1{_fea .Add_gs (_ba .PdfObjectName (gsName ));};DrawPathWithCreator (_gaf ,_fea );_fea .Add_h ();if _gfe .FillEnabled &&_gfe .BorderEnabled {_fea .Add_B ();}else if _gfe .FillEnabled {_fea .Add_f ();}else if _gfe .BorderEnabled {_fea .Add_S ();};_fea .Add_Q ();return _fea .Bytes (),_gaf .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_bb Path )GetPointNumber (number int )Point {if number < 1||number > len (_bb .Points ){return Point {};};return _bb .Points [number -1];};
|
||||
|
||||
// Length returns the number of points in the path.
|
||||
func (_afe Path )Length ()int {return len (_afe .Points )};
|
||||
|
||||
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
|
||||
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
|
||||
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
|
||||
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_ab CubicBezierPath )GetBoundingBox ()Rectangle {_gad :=Rectangle {};_dd :=0.0;_efe :=0.0;_fed :=0.0;_fb :=0.0;for _cac ,_cb :=range _ab .Curves {_af :=_cb .GetBounds ();if _cac ==0{_dd =_af .Llx ;_efe =_af .Urx ;_fed =_af .Lly ;_fb =_af .Ury ;continue ;};if _af .Llx < _dd {_dd =_af .Llx ;};if _af .Urx > _efe {_efe =_af .Urx ;};if _af .Lly < _fed {_fed =_af .Lly ;};if _af .Ury > _fb {_fb =_af .Ury ;};};_gad .X =_dd ;_gad .Y =_fed ;_gad .Width =_efe -_dd ;_gad .Height =_fb -_fed ;return _gad ;};
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_gcc Vector )Rotate (phi float64 )Vector {_afea :=_gcc .Magnitude ();_eebd :=_gcc .GetPolarAngle ();return NewVectorPolar (_afea ,_eebd +phi );};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_d .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
|
||||
// Point represents a two-dimensional point.
|
||||
type Point struct{X float64 ;Y float64 ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_bc Path )GetBoundingBox ()BoundingBox {_cacb :=BoundingBox {};_ege :=0.0;_gc :=0.0;_gf :=0.0;_gca :=0.0;for _dc ,_gdg :=range _bc .Points {if _dc ==0{_ege =_gdg .X ;_gc =_gdg .X ;_gf =_gdg .Y ;_gca =_gdg .Y ;continue ;};if _gdg .X < _ege {_ege =_gdg .X ;};if _gdg .X > _gc {_gc =_gdg .X ;};if _gdg .Y < _gf {_gf =_gdg .Y ;};if _gdg .Y > _gca {_gca =_gdg .Y ;};};_cacb .X =_ege ;_cacb .Y =_gf ;_cacb .Width =_gc -_ege ;_cacb .Height =_gca -_gf ;return _cacb ;};
|
||||
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_bdagf Vector )Add (other Vector )Vector {_bdagf .Dx +=other .Dx ;_bdagf .Dy +=other .Dy ;return _bdagf ;};
|
||||
|
||||
// DrawBezierPathWithCreator makes the bezier path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_c .ContentCreator ){for _ffd ,_gcd :=range bpath .Curves {if _ffd ==0{creator .Add_m (_gcd .P0 .X ,_gcd .P0 .Y );};creator .Add_c (_gcd .P1 .X ,_gcd .P1 .Y ,_gcd .P2 .X ,_gcd .P2 .Y ,_gcd .P3 .X ,_gcd .P3 .Y );};};
|
||||
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_ga CubicBezierPath )Copy ()CubicBezierPath {_bf :=CubicBezierPath {};_bf .Curves =[]CubicBezierCurve {};for _ ,_cge :=range _ga .Curves {_bf .Curves =append (_bf .Curves ,_cge );};return _bf ;};
|
||||
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_ccaa :=Vector {};_ccaa .Dx =length *_bd .Cos (theta );_ccaa .Dy =length *_bd .Sin (theta );return _ccaa ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
|
||||
// GetBounds returns the bounding box of the Bezier curve.
|
||||
func (_a CubicBezierCurve )GetBounds ()_d .PdfRectangle {_de :=_a .P0 .X ;_ee :=_a .P0 .X ;_cg :=_a .P0 .Y ;_bda :=_a .P0 .Y ;for _cc :=0.0;_cc <=1.0;_cc +=0.001{Rx :=_a .P0 .X *_bd .Pow (1-_cc ,3)+_a .P1 .X *3*_cc *_bd .Pow (1-_cc ,2)+_a .P2 .X *3*_bd .Pow (_cc ,2)*(1-_cc )+_a .P3 .X *_bd .Pow (_cc ,3);Ry :=_a .P0 .Y *_bd .Pow (1-_cc ,3)+_a .P1 .Y *3*_cc *_bd .Pow (1-_cc ,2)+_a .P2 .Y *3*_bd .Pow (_cc ,2)*(1-_cc )+_a .P3 .Y *_bd .Pow (_cc ,3);if Rx < _de {_de =Rx ;};if Rx > _ee {_ee =Rx ;};if Ry < _cg {_cg =Ry ;};if Ry > _bda {_bda =Ry ;};};_fe :=_d .PdfRectangle {};_fe .Llx =_de ;_fe .Lly =_cg ;_fe .Urx =_ee ;_fe .Ury =_bda ;return _fe ;};
|
||||
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_ac Path )Offset (offX ,offY float64 )Path {for _gd ,_bgg :=range _ac .Points {_ac .Points [_gd ]=_bgg .Add (offX ,offY );};return _ac ;};
|
||||
|
||||
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
||||
func (_ceg Point )Add (dx ,dy float64 )Point {_ceg .X +=dx ;_ceg .Y +=dy ;return _ceg };
|
||||
|
||||
// DrawPathWithCreator makes the path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawPathWithCreator (path Path ,creator *_c .ContentCreator ){for _fa ,_baa :=range path .Points {if _fa ==0{creator .Add_m (_baa .X ,_baa .Y );}else {creator .Add_l (_baa .X ,_baa .Y );};};};
|
||||
|
||||
// CubicBezierCurve is defined by:
|
||||
// R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3
|
||||
// where P0 is the current point, P1, P2 control points and P3 the final point.
|
||||
type CubicBezierCurve struct{P0 Point ;P1 Point ;P2 Point ;P3 Point ;};
|
||||
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_fee Vector )Magnitude ()float64 {return _bd .Sqrt (_bd .Pow (_fee .Dx ,2.0)+_bd .Pow (_fee .Dy ,2.0));};
|
||||
|
||||
// Draw draws the polyline. A graphics state name can be specified for
|
||||
// setting the polyline properties (e.g. setting the opacity). Otherwise leave
|
||||
// empty (""). Returns the content stream as a byte array and the polyline
|
||||
// bounding box.
|
||||
func (_ecfg Polyline )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){if _ecfg .LineColor ==nil {_ecfg .LineColor =_d .NewPdfColorDeviceRGB (0,0,0);};_dggc :=NewPath ();for _ ,_fgd :=range _ecfg .Points {_dggc =_dggc .AppendPoint (_fgd );};_add :=_c .NewContentCreator ();_add .Add_q ();_add .Add_RG (_ecfg .LineColor .R (),_ecfg .LineColor .G (),_ecfg .LineColor .B ());_add .Add_w (_ecfg .LineWidth );if len (gsName )> 1{_add .Add_gs (_ba .PdfObjectName (gsName ));};DrawPathWithCreator (_dggc ,_add );_add .Add_S ();_add .Add_Q ();return _add .Bytes (),_dggc .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
func (_geg Polyline )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){if _geg .LineColor ==nil {_geg .LineColor =_e .NewPdfColorDeviceRGB (0,0,0);};_gegg :=NewPath ();for _ ,_cae :=range _geg .Points {_gegg =_gegg .AppendPoint (_cae );};_cge :=_b .NewContentCreator ();_cge .Add_q ();_cge .Add_RG (_geg .LineColor .R (),_geg .LineColor .G (),_geg .LineColor .B ());_cge .Add_w (_geg .LineWidth );if len (gsName )> 1{_cge .Add_gs (_da .PdfObjectName (gsName ));};DrawPathWithCreator (_gegg ,_cge );_cge .Add_S ();_cge .Add_Q ();return _cge .Bytes (),_gegg .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_e .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_e .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
|
||||
// CubicBezierPath represents a collection of cubic Bezier curves.
|
||||
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
|
||||
// Offset shifts the Bezier path with the specified offsets.
|
||||
func (_gc CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _cd ,_ca :=range _gc .Curves {_gc .Curves [_cd ]=_ca .AddOffsetXY (offX ,offY );};return _gc ;};
|
||||
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_dgeb Vector )GetPolarAngle ()float64 {return _bd .Atan2 (_dgeb .Dy ,_dgeb .Dx )};
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_af Path )Offset (offX ,offY float64 )Path {for _eg ,_ege :=range _af .Points {_af .Points [_eg ]=_ege .Add (offX ,offY );};return _af ;};
|
||||
|
||||
// Draw draws the composite Bezier curve. A graphics state name can be
|
||||
// specified for setting the curve properties (e.g. setting the opacity).
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array and
|
||||
// the curve bounding box.
|
||||
func (_gff PolyBezierCurve )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){if _gff .BorderColor ==nil {_gff .BorderColor =_d .NewPdfColorDeviceRGB (0,0,0);};_ede :=NewCubicBezierPath ();for _ ,_cgd :=range _gff .Curves {_ede =_ede .AppendCurve (_cgd );};_fbd :=_c .NewContentCreator ();_fbd .Add_q ();_gff .FillEnabled =_gff .FillEnabled &&_gff .FillColor !=nil ;if _gff .FillEnabled {_fbd .Add_rg (_gff .FillColor .R (),_gff .FillColor .G (),_gff .FillColor .B ());};_fbd .Add_RG (_gff .BorderColor .R (),_gff .BorderColor .G (),_gff .BorderColor .B ());_fbd .Add_w (_gff .BorderWidth );if len (gsName )> 1{_fbd .Add_gs (_ba .PdfObjectName (gsName ));};for _ ,_ffb :=range _ede .Curves {_fbd .Add_m (_ffb .P0 .X ,_ffb .P0 .Y );_fbd .Add_c (_ffb .P1 .X ,_ffb .P1 .Y ,_ffb .P2 .X ,_ffb .P2 .Y ,_ffb .P3 .X ,_ffb .P3 .Y );};if _gff .FillEnabled {_fbd .Add_h ();_fbd .Add_B ();}else {_fbd .Add_S ();};_fbd .Add_Q ();return _fbd .Bytes (),_ede .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
||||
|
||||
// Draw draws the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
|
||||
// Returns the content stream as a byte array, the bounding box and an error on failure.
|
||||
func (_fba Circle )Draw (gsName string )([]byte ,*_d .PdfRectangle ,error ){_cbd :=_fba .Width /2;_cd :=_fba .Height /2;if _fba .BorderEnabled {_cbd -=_fba .BorderWidth /2;_cd -=_fba .BorderWidth /2;};_bde :=0.551784;_bag :=_cbd *_bde ;_ddc :=_cd *_bde ;_aca :=NewCubicBezierPath ();_aca =_aca .AppendCurve (NewCubicBezierCurve (-_cbd ,0,-_cbd ,_ddc ,-_bag ,_cd ,0,_cd ));_aca =_aca .AppendCurve (NewCubicBezierCurve (0,_cd ,_bag ,_cd ,_cbd ,_ddc ,_cbd ,0));_aca =_aca .AppendCurve (NewCubicBezierCurve (_cbd ,0,_cbd ,-_ddc ,_bag ,-_cd ,0,-_cd ));_aca =_aca .AppendCurve (NewCubicBezierCurve (0,-_cd ,-_bag ,-_cd ,-_cbd ,-_ddc ,-_cbd ,0));_aca =_aca .Offset (_cbd ,_cd );if _fba .BorderEnabled {_aca =_aca .Offset (_fba .BorderWidth /2,_fba .BorderWidth /2);};if _fba .X !=0||_fba .Y !=0{_aca =_aca .Offset (_fba .X ,_fba .Y );};_gg :=_c .NewContentCreator ();_gg .Add_q ();if _fba .FillEnabled {_gg .Add_rg (_fba .FillColor .R (),_fba .FillColor .G (),_fba .FillColor .B ());};if _fba .BorderEnabled {_gg .Add_RG (_fba .BorderColor .R (),_fba .BorderColor .G (),_fba .BorderColor .B ());_gg .Add_w (_fba .BorderWidth );};if len (gsName )> 1{_gg .Add_gs (_ba .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_aca ,_gg );_gg .Add_h ();if _fba .FillEnabled &&_fba .BorderEnabled {_gg .Add_B ();}else if _fba .FillEnabled {_gg .Add_f ();}else if _fba .BorderEnabled {_gg .Add_S ();};_gg .Add_Q ();_dge :=_aca .GetBoundingBox ();if _fba .BorderEnabled {_dge .Height +=_fba .BorderWidth ;_dge .Width +=_fba .BorderWidth ;_dge .X -=_fba .BorderWidth /2;_dge .Y -=_fba .BorderWidth /2;};return _gg .Bytes (),_dge .ToPdfRectangle (),nil ;};
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_ga Path )GetBoundingBox ()BoundingBox {_fe :=BoundingBox {};_aa :=0.0;_bbd :=0.0;_eaba :=0.0;_abd :=0.0;for _gad ,_eaa :=range _ga .Points {if _gad ==0{_aa =_eaa .X ;_bbd =_eaa .X ;_eaba =_eaa .Y ;_abd =_eaa .Y ;continue ;};if _eaa .X < _aa {_aa =_eaa .X ;};if _eaa .X > _bbd {_bbd =_eaa .X ;};if _eaa .Y < _eaba {_eaba =_eaa .Y ;};if _eaa .Y > _abd {_abd =_eaa .Y ;};};_fe .X =_aa ;_fe .Y =_eaba ;_fe .Width =_bbd -_aa ;_fe .Height =_abd -_eaba ;return _fe ;};
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
// 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 (_egf Rectangle )Draw (gsName string )([]byte ,*_e .PdfRectangle ,error ){_gb :=NewPath ();_gb =_gb .AppendPoint (NewPoint (0,0));_gb =_gb .AppendPoint (NewPoint (0,_egf .Height ));_gb =_gb .AppendPoint (NewPoint (_egf .Width ,_egf .Height ));_gb =_gb .AppendPoint (NewPoint (_egf .Width ,0));_gb =_gb .AppendPoint (NewPoint (0,0));if _egf .X !=0||_egf .Y !=0{_gb =_gb .Offset (_egf .X ,_egf .Y );};_gce :=_b .NewContentCreator ();_gce .Add_q ();if _egf .FillEnabled {_gce .Add_rg (_egf .FillColor .R (),_egf .FillColor .G (),_egf .FillColor .B ());};if _egf .BorderEnabled {_gce .Add_RG (_egf .BorderColor .R (),_egf .BorderColor .G (),_egf .BorderColor .B ());_gce .Add_w (_egf .BorderWidth );};if len (gsName )> 1{_gce .Add_gs (_da .PdfObjectName (gsName ));};DrawPathWithCreator (_gb ,_gce );_gce .Add_h ();if _egf .FillEnabled &&_egf .BorderEnabled {_gce .Add_B ();}else if _egf .FillEnabled {_gce .Add_f ();}else if _egf .BorderEnabled {_gce .Add_S ();};_gce .Add_Q ();return _gce .Bytes (),_gb .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// NewCubicBezierCurve returns a new cubic Bezier curve.
|
||||
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_f :=CubicBezierCurve {};_f .P0 =NewPoint (x0 ,y0 );_f .P1 =NewPoint (x1 ,y1 );_f .P2 =NewPoint (x2 ,y2 );_f .P3 =NewPoint (x3 ,y3 );return _f ;};
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
|
||||
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_d .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_ebeg Vector )FlipY ()Vector {_ebeg .Dy =-_ebeg .Dy ;return _ebeg };
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_bdeg Vector )Flip ()Vector {_gcae :=_bdeg .Magnitude ();_gb :=_bdeg .GetPolarAngle ();_bdeg .Dx =_gcae *_bd .Cos (_gb +_bd .Pi );_bdeg .Dy =_gcae *_bd .Sin (_gb +_bd .Pi );return _bdeg ;};
|
||||
|
||||
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
|
||||
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_d .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_d .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_dgg Point )Rotate (theta float64 )Point {_bcb :=_e .NewPoint (_dgg .X ,_dgg .Y ).Rotate (theta );return NewPoint (_bcb .X ,_bcb .Y );};
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_def :=CubicBezierPath {};_def .Curves =[]CubicBezierCurve {};return _def ;};
|
1890
core/core.go
1890
core/core.go
File diff suppressed because one or more lines are too long
@ -9,76 +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 (_d "crypto/aes";_f "crypto/cipher";_gf "crypto/md5";_de "crypto/rand";_eg "crypto/rc4";_g "fmt";_gfe "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/core/security";_e "io";);func init (){_cd ("\u0041\u0045\u0053V\u0032",_c )};func _dc (_fbc ,_beb uint32 ,_gcc []byte ,_bbd bool )([]byte ,error ){_cg :=make ([]byte ,len (_gcc )+5);for _gfaf :=0;_gfaf < len (_gcc );_gfaf ++{_cg [_gfaf ]=_gcc [_gfaf ];};for _ec :=0;_ec < 3;_ec ++{_gcf :=byte ((_fbc >>uint32 (8*_ec ))&0xff);_cg [_ec +len (_gcc )]=_gcf ;};for _ba :=0;_ba < 2;_ba ++{_ddc :=byte ((_beb >>uint32 (8*_ba ))&0xff);_cg [_ba +len (_gcc )+3]=_ddc ;};if _bbd {_cg =append (_cg ,0x73);_cg =append (_cg ,0x41);_cg =append (_cg ,0x6C);_cg =append (_cg ,0x54);};_gab :=_gf .New ();_gab .Write (_cg );_cga :=_gab .Sum (nil );if len (_gcc )+5< 16{return _cga [0:len (_gcc )+5],nil ;};return _cga ,nil ;};type filterIdentity struct{};
|
||||
package crypt ;import (_c "crypto/aes";_gfd "crypto/cipher";_fe "crypto/md5";_gf "crypto/rand";_f "crypto/rc4";_b "fmt";_gfe "github.com/unidoc/unipdf/v3/common";_e "github.com/unidoc/unipdf/v3/core/security";_a "io";);func init (){_ffed ("\u0041\u0045\u0053V\u0032",_gc )};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};type filterAESV3 struct{filterAES };
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (_bg filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _dc (objNum ,genNum ,ekey ,false );};func _ee (_dg FilterDict )(Filter ,error ){if _dg .Length ==256{_gfe .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_dg .Length );_dg .Length /=8;};if _dg .Length !=0&&_dg .Length !=32{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_dg .Length );};return filterAESV3 {},nil ;};type filterV2 struct{_fg int };
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func init (){_cd ("\u0041\u0045\u0053V\u0033",_ee )};func _agc (_dec string )(filterFunc ,error ){_dege :=_bgb [string (_dec )];if _dege ==nil {return nil ,_g .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_dec );};return _dege ,nil ;};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };var (_bgb =make (map[string ]filterFunc ););
|
||||
|
||||
// DecryptBytes implements Filter interface.
|
||||
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gac ,_fcb :=_eg .NewCipher (okey );if _fcb !=nil {return nil ,_fcb ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_gac .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _fb (_gca FilterDict )(Filter ,error ){if _gca .Length %8!=0{return nil ,_g .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_gca .Length );};if _gca .Length < 5||_gca .Length > 16{if _gca .Length ==40||_gca .Length ==64||_gca .Length ==128{_gfe .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_gca .Length );_gca .Length /=8;}else {return nil ,_g .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_gca .Length );};};return filterV2 {_fg :_gca .Length },nil ;};type filterAESV2 struct{filterAES };
|
||||
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_ga ,_ega :=_c (FilterDict {});if _ega !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ega );return filterAESV2 {};};return _ga ;};
|
||||
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_db ,_cab :=_fb (FilterDict {Length :length });if _cab !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_cab );return filterV2 {_fg :length };};return _db ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_feb ,_bb :=_d .NewCipher (okey );if _bb !=nil {return nil ,_bb ;};if len (buf )< 16{_gfe .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_be :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_gfe .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_be ),_be );_gfe .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_gee :=_f .NewCBCDecrypter (_feb ,_be );_gfe .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_gfe .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_gee .CryptBlocks (buf ,buf );_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_gfe .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_caf :=int (buf [len (buf )-1]);if _caf > len (buf ){_gfe .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_caf ,len (buf ));return buf ,_g .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_caf ];return buf ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_gea ,_eed :=_eaf (d .CFM );if _eed !=nil {return nil ,_eed ;};_dea ,_eed :=_gea (d );if _eed !=nil {return nil ,_eed ;};return _dea ,nil ;};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};func init (){_cd ("\u0056\u0032",_fb )};func _cd (_cf string ,_ede filterFunc ){if _ ,_gbf :=_bgb [_cf ];_gbf {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_bgb [_cf ]=_ede ;};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (_gec filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_cc ,_be :=_fd (FilterDict {});if _be !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_be );return filterAESV3 {};};return _cc ;};type filterV2 struct{_bef int };
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV3 )KeyLength ()int {return 256/8};
|
||||
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _ed .AuthEvent ;Length int ;};var _ Filter =filterAESV3 {};
|
||||
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_ce ,_ge :=_ee (FilterDict {});if _ge !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ge );return filterAESV3 {};};return _ce ;};var _ Filter =filterV2 {};
|
||||
|
||||
// NewIdentity creates an identity filter that bypasses all data without changes.
|
||||
func NewIdentity ()Filter {return filterIdentity {}};func _c (_gfa FilterDict )(Filter ,error ){if _gfa .Length ==128{_gfe .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_gfa .Length );_gfa .Length /=8;};if _gfa .Length !=0&&_gfa .Length !=16{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_gfa .Length );};return filterAESV2 {},nil ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterV2 )Name ()string {return "\u0056\u0032"};type filterFunc func (_ecd FilterDict )(Filter ,error );func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _dc (objNum ,genNum ,ekey ,true );};type filterAES struct{};
|
||||
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_ece ,_deg :=_agc (d .CFM );if _deg !=nil {return nil ,_deg ;};_fa ,_deg :=_ece (d );if _deg !=nil {return nil ,_deg ;};return _fa ,nil ;};
|
||||
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_af ,_cabe :=_eg .NewCipher (okey );if _cabe !=nil {return nil ,_cabe ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_af .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (_gccc filterV2 )KeyLength ()int {return _gccc ._fg };func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};func (filterIdentity )KeyLength ()int {return 0};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};type filterFunc func (_ee FilterDict )(Filter ,error );
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (_geg filterV2 )PDFVersion ()[2]int {return [2]int {}};var _ Filter =filterAESV2 {};
|
||||
func (_ggb filterV2 )PDFVersion ()[2]int {return [2]int {}};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _bf (objNum ,genNum ,ekey ,true );};func init (){_ffed ("\u0041\u0045\u0053V\u0033",_fd )};
|
||||
|
||||
// DecryptBytes implements Filter interface.
|
||||
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_edc ,_fda :=_f .NewCipher (okey );if _fda !=nil {return nil ,_fda ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_edc .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func _gc (_ef FilterDict )(Filter ,error ){if _ef .Length ==128{_gfe .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_ef .Length );_ef .Length /=8;};if _ef .Length !=0&&_ef .Length !=16{return nil ,_b .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",_ef .Length );};return filterAESV2 {},nil ;};
|
||||
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _e .AuthEvent ;Length int ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func _ad (_bg FilterDict )(Filter ,error ){if _bg .Length %8!=0{return nil ,_b .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",_bg .Length );};if _bg .Length < 5||_bg .Length > 16{if _bg .Length ==40||_bg .Length ==64||_bg .Length ==128{_gfe .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_bg .Length );_bg .Length /=8;}else {return nil ,_b .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",_bg .Length );};};return filterV2 {_bef :_bg .Length },nil ;};func _eaf (_eb string )(filterFunc ,error ){_adgb :=_faf [string (_eb )];if _adgb ==nil {return nil ,_b .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",_eb );};return _adgb ,nil ;};
|
||||
|
||||
// NewIdentity creates an identity filter that bypasses all data without changes.
|
||||
func NewIdentity ()Filter {return filterIdentity {}};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterIdentity )KeyLength ()int {return 0};
|
||||
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_bd ,_gff :=_ad (FilterDict {Length :length });if _gff !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_gff );return filterV2 {_bef :length };};return _bd ;};func init (){_ffed ("\u0056\u0032",_ad )};
|
||||
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_ed ,_ba :=_gc (FilterDict {});if _ba !=nil {_gfe .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ba );return filterAESV2 {};};return _ed ;};func _fd (_fag FilterDict )(Filter ,error ){if _fag .Length ==256{_gfe .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_fag .Length );_fag .Length /=8;};if _fag .Length !=0&&_fag .Length !=32{return nil ,_b .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",_fag .Length );};return filterAESV3 {},nil ;};var _ Filter =filterAESV2 {};type filterIdentity struct{};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterV2 )Name ()string {return "\u0056\u0032"};
|
||||
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ffa ,_dc :=_f .NewCipher (okey );if _dc !=nil {return nil ,_dc ;};_gfe .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ffa .XORKeyStream (buf ,buf );_gfe .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};var (_faf =make (map[string ]filterFunc ););
|
||||
|
||||
// Filter is a common interface for crypt filter methods.
|
||||
type Filter interface{
|
||||
@ -97,12 +82,27 @@ 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 (_gae ,_da uint32 ,_cb []byte )([]byte ,error );
|
||||
MakeKey (_fb ,_acg uint32 ,_gfdc []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 (_aac []byte ,_baa []byte )([]byte ,error );
|
||||
EncryptBytes (_dd []byte ,_eg []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 (_eea []byte ,_dbg []byte )([]byte ,error );};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fc ,_gc :=_d .NewCipher (okey );if _gc !=nil {return nil ,_gc ;};_gfe .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _efc =_d .BlockSize ;_a :=_efc -len (buf )%_efc ;for _ag :=0;_ag < _a ;_ag ++{buf =append (buf ,byte (_a ));};_gfe .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_ca :=make ([]byte ,_efc +len (buf ));_dda :=_ca [:_efc ];if _ ,_gb :=_e .ReadFull (_de .Reader ,_dda );_gb !=nil {return nil ,_gb ;};_ff :=_f .NewCBCEncrypter (_fc ,_dda );_ff .CryptBlocks (_ca [_efc :],buf );buf =_ca ;_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
|
||||
DecryptBytes (_edd []byte ,_adg []byte )([]byte ,error );};type filterAESV2 struct{filterAES };type filterAESV3 struct{filterAES };func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_d ,_fad :=_c .NewCipher (okey );if _fad !=nil {return nil ,_fad ;};_gfe .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _cd =_c .BlockSize ;_ca :=_cd -len (buf )%_cd ;for _fae :=0;_fae < _ca ;_fae ++{buf =append (buf ,byte (_ca ));};_gfe .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_ac :=make ([]byte ,_cd +len (buf ));_efc :=_ac [:_cd ];if _ ,_fg :=_a .ReadFull (_gf .Reader ,_efc );_fg !=nil {return nil ,_fg ;};_cb :=_gfd .NewCBCEncrypter (_d ,_efc );_cb .CryptBlocks (_ac [_cd :],buf );buf =_ac ;_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};func _bf (_ea ,_gg uint32 ,_ccb []byte ,_cf bool )([]byte ,error ){_ge :=make ([]byte ,len (_ccb )+5);for _bc :=0;_bc < len (_ccb );_bc ++{_ge [_bc ]=_ccb [_bc ];};for _de :=0;_de < 3;_de ++{_cbg :=byte ((_ea >>uint32 (8*_de ))&0xff);_ge [_de +len (_ccb )]=_cbg ;};for _ead :=0;_ead < 2;_ead ++{_gge :=byte ((_gg >>uint32 (8*_ead ))&0xff);_ge [_ead +len (_ccb )+3]=_gge ;};if _cf {_ge =append (_ge ,0x73);_ge =append (_ge ,0x41);_ge =append (_ge ,0x6C);_ge =append (_ge ,0x54);};_gca :=_fe .New ();_gca .Write (_ge );_dfe :=_gca .Sum (nil );if len (_ccb )+5< 16{return _dfe [0:len (_ccb )+5],nil ;};return _dfe ,nil ;};var _ Filter =filterV2 {};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};var _ Filter =filterAESV3 {};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ff ,_ec :=_c .NewCipher (okey );if _ec !=nil {return nil ,_ec ;};if len (buf )< 16{_gfe .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_b .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_ga :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_gfe .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_ga ),_ga );_gfe .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_b .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 ));};_fec :=_gfd .NewCBCDecrypter (_ff ,_ga );_gfe .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_gfe .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_fec .CryptBlocks (buf ,buf );_gfe .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_gfe .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_df :=int (buf [len (buf )-1]);if _df > len (buf ){_gfe .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_df ,len (buf ));return buf ,_b .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_df ];return buf ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (_cfbg filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _bf (objNum ,genNum ,ekey ,false );};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (_fgb filterV2 )KeyLength ()int {return _fgb ._bef };func _ffed (_gcd string ,_agg filterFunc ){if _ ,_dfb :=_faf [_gcd ];_dfb {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_faf [_gcd ]=_agg ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (_ffe filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};type filterAES struct{};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
|
File diff suppressed because one or more lines are too long
2558
creator/creator.go
2558
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
34
fdf/fdf.go
34
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 (_bd "encoding/json";_db "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";_d "io";_a "os";);
|
||||
|
||||
// FieldValues implements model.FieldValueProvider interface.
|
||||
func (_cee *FieldData )FieldValues ()(map[string ]_db .PdfObject ,error ){_cba :=make (map[string ]_db .PdfObject );for _ ,_dcg :=range _cee ._ef {if len (_dcg .Value )> 0{_cba [_dcg .Name ]=_db .MakeString (_dcg .Value );};};return _cba ,nil ;};
|
||||
|
||||
// LoadFromJSONFile loads form field data from a JSON file.
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_bc ,_f :=_a .Open (filePath );if _f !=nil {return nil ,_f ;};defer _bc .Close ();return LoadFromJSON (_bc );};
|
||||
|
||||
// LoadFromJSON loads JSON form data from `r`.
|
||||
func LoadFromJSON (r _d .Reader )(*FieldData ,error ){var _g FieldData ;_dd :=_bd .NewDecoder (r ).Decode (&_g ._ef );if _dd !=nil {return nil ,_dd ;};return &_g ,nil ;};
|
||||
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fgg ,_gde :=_a .Open (filePath );if _gde !=nil {return nil ,_gde ;};defer _fgg .Close ();return LoadFromPDF (_fgg );};
|
||||
package fjson ;import (_e "encoding/json";_g "github.com/unidoc/unipdf/v3/core";_gg "github.com/unidoc/unipdf/v3/model";_c "io";_dc "os";);
|
||||
|
||||
// FieldData represents form field data loaded from JSON file.
|
||||
type FieldData struct{_ef []fieldValue };
|
||||
type FieldData struct{_a []fieldValue };
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _d .ReadSeeker )(*FieldData ,error ){_ac ,_c :=_e .NewPdfReader (rs );if _c !=nil {return nil ,_c ;};if _ac .AcroForm ==nil {return nil ,nil ;};var _da []fieldValue ;_ge :=_ac .AcroForm .AllFields ();for _ ,_ad :=range _ge {var _dfd []string ;_gg :=make (map[string ]struct{});_dda ,_eff :=_ad .FullName ();if _eff !=nil {return nil ,_eff ;};if _bg ,_gb :=_ad .V .(*_db .PdfObjectString );_gb {_da =append (_da ,fieldValue {Name :_dda ,Value :_bg .Decoded ()});continue ;};var _ggd string ;for _ ,_de :=range _ad .Annotations {_cc ,_eg :=_db .GetName (_de .AS );if _eg {_ggd =_cc .String ();};_bgb ,_cb :=_db .GetDict (_de .AP );if !_cb {continue ;};_ddd ,_ :=_db .GetDict (_bgb .Get ("\u004e"));for _ ,_egd :=range _ddd .Keys (){_ff :=_egd .String ();if _ ,_ea :=_gg [_ff ];!_ea {_dfd =append (_dfd ,_ff );_gg [_ff ]=struct{}{};};};_gd ,_ :=_db .GetDict (_bgb .Get ("\u0044"));for _ ,_ce :=range _gd .Keys (){_fac :=_ce .String ();if _ ,_cab :=_gg [_fac ];!_cab {_dfd =append (_dfd ,_fac );_gg [_fac ]=struct{}{};};};};_acf :=fieldValue {Name :_dda ,Value :_ggd ,Options :_dfd };_da =append (_da ,_acf );};_ddg :=FieldData {_ef :_da };return &_ddg ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_ac ,_gdd :=_dc .Open (filePath );if _gdd !=nil {return nil ,_gdd ;};defer _ac .Close ();return LoadFromPDF (_ac );};
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
||||
// LoadFromJSONFile loads form field data from a JSON file.
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_ea ,_eab :=_dc .Open (filePath );if _eab !=nil {return nil ,_eab ;};defer _ea .Close ();return LoadFromJSON (_ea );};
|
||||
|
||||
// JSON returns the field data as a string in JSON format.
|
||||
func (_gdg FieldData )JSON ()(string ,error ){_adf ,_bcad :=_bd .MarshalIndent (_gdg ._ef ,"","\u0020\u0020\u0020\u0020");return string (_adf ),_bcad ;};
|
||||
func (_egb FieldData )JSON ()(string ,error ){_cd ,_fd :=_e .MarshalIndent (_egb ._a ,"","\u0020\u0020\u0020\u0020");return string (_cd ),_fd ;};
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _c .ReadSeeker )(*FieldData ,error ){_ead ,_gc :=_gg .NewPdfReader (rs );if _gc !=nil {return nil ,_gc ;};if _ead .AcroForm ==nil {return nil ,nil ;};var _f []fieldValue ;_de :=_ead .AcroForm .AllFields ();for _ ,_gce :=range _de {var _db []string ;_gb :=make (map[string ]struct{});_ef ,_df :=_gce .FullName ();if _df !=nil {return nil ,_df ;};if _cc ,_fc :=_gce .V .(*_g .PdfObjectString );_fc {_f =append (_f ,fieldValue {Name :_ef ,Value :_cc .Decoded ()});continue ;};var _gf string ;for _ ,_fb :=range _gce .Annotations {_ba ,_ffc :=_g .GetName (_fb .AS );if _ffc {_gf =_ba .String ();};_bag ,_gbc :=_g .GetDict (_fb .AP );if !_gbc {continue ;};_dg ,_ :=_g .GetDict (_bag .Get ("\u004e"));for _ ,_ae :=range _dg .Keys (){_dgc :=_ae .String ();if _ ,_bb :=_gb [_dgc ];!_bb {_db =append (_db ,_dgc );_gb [_dgc ]=struct{}{};};};_egd ,_ :=_g .GetDict (_bag .Get ("\u0044"));for _ ,_dea :=range _egd .Keys (){_gcd :=_dea .String ();if _ ,_gad :=_gb [_gcd ];!_gad {_db =append (_db ,_gcd );_gb [_gcd ]=struct{}{};};};};_ffca :=fieldValue {Name :_ef ,Value :_gf ,Options :_db };_f =append (_f ,_ffca );};_gd :=FieldData {_a :_f };return &_gd ,nil ;};
|
||||
|
||||
// LoadFromJSON loads JSON form data from `r`.
|
||||
func LoadFromJSON (r _c .Reader )(*FieldData ,error ){var _b FieldData ;_eg :=_e .NewDecoder (r ).Decode (&_b ._a );if _eg !=nil {return nil ,_eg ;};return &_b ,nil ;};
|
||||
|
||||
// FieldValues implements model.FieldValueProvider interface.
|
||||
func (_ccg *FieldData )FieldValues ()(map[string ]_g .PdfObject ,error ){_fdb :=make (map[string ]_g .PdfObject );for _ ,_fdg :=range _ccg ._a {if len (_fdg .Value )> 0{_fdb [_fdg .Name ]=_g .MakeString (_fdg .Value );};};return _fdb ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
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 (_c "encoding/binary";_d "unsafe";);func IsBig ()bool {return _a };func init (){const _ec =int (_d .Sizeof (0));_eb :=1;_b :=(*[_ec ]byte )(_d .Pointer (&_eb ));if _b [0]==0{_a =true ;ByteOrder =_c .BigEndian ;}else {ByteOrder =_c .LittleEndian ;};};var (ByteOrder _c .ByteOrder ;_a bool ;);func IsLittle ()bool {return !_a };
|
||||
package endian ;import (_a "encoding/binary";_cc "unsafe";);func IsLittle ()bool {return !_g };func init (){const _e =int (_cc .Sizeof (0));_fc :=1;_d :=(*[_e ]byte )(_cc .Pointer (&_fc ));if _d [0]==0{_g =true ;ByteOrder =_a .BigEndian ;}else {ByteOrder =_a .LittleEndian ;};};func IsBig ()bool {return _g };var (ByteOrder _a .ByteOrder ;_g bool ;);
|
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 _c "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_fbd *Stack )Pop ()(_bg interface{},_bag bool ){_bg ,_bag =_fbd .peek ();if !_bag {return nil ,_bag ;};_fbd .Data =_fbd .Data [:_fbd .top ()];return _bg ,true ;};func (_be *Stack )Len ()int {return len (_be .Data )};func NewNumSlice (i int )*NumSlice {_efc :=NumSlice (make ([]float32 ,i ));return &_efc };func (_bc *IntSlice )Add (v int )error {if _bc ==nil {return _c .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_bc =append (*_bc ,v );return nil ;};func (_fb IntsMap )Delete (key uint64 ){delete (_fb ,key )};type IntSlice []int ;func (_b IntsMap )GetSlice (key uint64 )([]int ,bool ){_ac ,_g :=_b [key ];if !_g {return nil ,false ;};return _ac ,true ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_d IntSlice )Get (index int )(int ,error ){if index > len (_d )-1{return 0,_c .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _d [index ],nil ;};type Stack struct{Data []interface{};Aux *Stack ;};func (_bb *NumSlice )AddInt (v int ){*_bb =append (*_bb ,float32 (v ))};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_a IntsMap )Get (key uint64 )(int ,bool ){_ad ,_f :=_a [key ];if !_f {return 0,false ;};if len (_ad )==0{return 0,false ;};return _ad [0],true ;};type NumSlice []float32 ;func (_adb *Stack )top ()int {return len (_adb .Data )-1};func (_bcc NumSlice )GetInt (i int )(int ,error ){const _ag ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_bcc )-1{return 0,_c .Errorf (_ag ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cc :=_bcc [i ];return int (_cc +Sign (_cc )*0.5),nil ;};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_fg *Stack )Peek ()(_bd interface{},_da bool ){return _fg .peek ()};func (_ga NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ga )-1{return 0,_c .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _ga [i ],nil ;};func (_fa *Stack )Push (v interface{}){_fa .Data =append (_fa .Data ,v )};func NewIntSlice (i int )*IntSlice {_efb :=IntSlice (make ([]int ,i ));return &_efb };func (_gf *IntSlice )Copy ()*IntSlice {_eb :=IntSlice (make ([]int ,len (*_gf )));copy (_eb ,*_gf );return &_eb ;};func (_faf *Stack )peek ()(interface{},bool ){_fgc :=_faf .top ();if _fgc ==-1{return nil ,false ;};return _faf .Data [_fgc ],true ;};func (_agf NumSlice )GetIntSlice ()[]int {_ca :=make ([]int ,len (_agf ));for _dc ,_ba :=range _agf {_ca [_dc ]=int (_ba );};return _ca ;};type IntsMap map[uint64 ][]int ;func (_gc IntSlice )Size ()int {return len (_gc )};func (_ef IntsMap )Add (key uint64 ,value int ){_ef [key ]=append (_ef [key ],value )};func (_aa *NumSlice )Add (v float32 ){*_aa =append (*_aa ,v )};
|
||||
package basic ;import _e "github.com/unidoc/unipdf/v3/internal/jbig2/errors";type NumSlice []float32 ;func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_ba IntSlice )Get (index int )(int ,error ){if index > len (_ba )-1{return 0,_e .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 _ba [index ],nil ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_d IntsMap )Add (key uint64 ,value int ){_d [key ]=append (_d [key ],value )};func NewNumSlice (i int )*NumSlice {_gd :=NumSlice (make ([]float32 ,i ));return &_gd };type IntsMap map[uint64 ][]int ;func Min (x ,y int )int {if x < y {return x ;};return y ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_dfb *Stack )Pop ()(_af interface{},_cfbf bool ){_af ,_cfbf =_dfb .peek ();if !_cfbf {return nil ,_cfbf ;};_dfb .Data =_dfb .Data [:_dfb .top ()];return _af ,true ;};func NewIntSlice (i int )*IntSlice {_cfb :=IntSlice (make ([]int ,i ));return &_cfb };func (_edg *Stack )Len ()int {return len (_edg .Data )};func (_ef *IntSlice )Copy ()*IntSlice {_b :=IntSlice (make ([]int ,len (*_ef )));copy (_b ,*_ef );return &_b ;};func (_ee IntSlice )Size ()int {return len (_ee )};type IntSlice []int ;func (_ed NumSlice )GetIntSlice ()[]int {_ce :=make ([]int ,len (_ed ));for _ff ,_be :=range _ed {_ce [_ff ]=int (_be );};return _ce ;};func (_ca *Stack )peek ()(interface{},bool ){_cdg :=_ca .top ();if _cdg ==-1{return nil ,false ;};return _ca .Data [_cdg ],true ;};func (_a IntsMap )GetSlice (key uint64 )([]int ,bool ){_da ,_cfg :=_a [key ];if !_cfg {return nil ,false ;};return _da ,true ;};func (_g *IntSlice )Add (v int )error {if _g ==nil {return _e .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");};*_g =append (*_g ,v );return nil ;};func (_eg IntsMap )Get (key uint64 )(int ,bool ){_cc ,_cf :=_eg [key ];if !_cf {return 0,false ;};if len (_cc )==0{return 0,false ;};return _cc [0],true ;};type Stack struct{Data []interface{};Aux *Stack ;};func (_de *NumSlice )Add (v float32 ){*_de =append (*_de ,v )};func (_f *NumSlice )AddInt (v int ){*_f =append (*_f ,float32 (v ))};func (_bcf *Stack )Peek ()(_cd interface{},_gc bool ){return _bcf .peek ()};func (_bc NumSlice )GetInt (i int )(int ,error ){const _cb ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_bc )-1{return 0,_e .Errorf (_cb ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_fc :=_bc [i ];return int (_fc +Sign (_fc )*0.5),nil ;};func (_dc *Stack )Push (v interface{}){_dc .Data =append (_dc .Data ,v )};func (_ab IntsMap )Delete (key uint64 ){delete (_ab ,key )};func (_df NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_df )-1{return 0,_e .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 _df [i ],nil ;};func (_efb *Stack )top ()int {return len (_efb .Data )-1};func Abs (v int )int {if v > 0{return v ;};return -v ;};
|
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 (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_bb "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_ae "github.com/unidoc/unipdf/v3/internal/jbig2/document";_bf "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_b "image";);type Decoder struct{_ag _g .StreamReader ;_aeg *_ae .Document ;_aa int ;_e Parameters ;};func (_be *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _be .decodePage (pageNumber )};func (_dg *Decoder )decodePageImage (_aacc int )(_b .Image ,error ){const _gf ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _aacc < 0{return nil ,_bf .Errorf (_gf ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_aacc );};if _aacc > int (_dg ._aeg .NumberOfPages ){return nil ,_bf .Errorf (_gf ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_aacc );};_ba ,_bba :=_dg ._aeg .GetPage (_aacc );if _bba !=nil {return nil ,_bf .Wrap (_bba ,_gf ,"");};_fg ,_bba :=_ba .GetBitmap ();if _bba !=nil {return nil ,_bf .Wrap (_bba ,_gf ,"");};return _fg .ToImage (),nil ;};type Parameters struct{UnpaddedData bool ;Color _bb .Color ;};func (_bfb *Decoder )PageNumber ()(int ,error ){const _dc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _bfb ._aeg ==nil {return 0,_bf .Error (_dc ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_bfb ._aeg .NumberOfPages ),nil ;};func (_aac *Decoder )DecodePageImage (pageNumber int )(_b .Image ,error ){const _f ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bea ,_gc :=_aac .decodePageImage (pageNumber );if _gc !=nil {return nil ,_bf .Wrap (_gc ,_f ,"");};return _bea ,nil ;};func Decode (input []byte ,parameters Parameters ,globals *_ae .Globals )(*Decoder ,error ){_bfbb :=_g .NewReader (input );_ef ,_ac :=_ae .DecodeDocument (_bfbb ,globals );if _ac !=nil {return nil ,_ac ;};return &Decoder {_ag :_bfbb ,_aeg :_ef ,_e :parameters },nil ;};func (_d *Decoder )DecodeNextPage ()([]byte ,error ){_d ._aa ++;_c :=_d ._aa ;return _d .decodePage (_c )};func (_aga *Decoder )decodePage (_beb int )([]byte ,error ){const _de ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _beb < 0{return nil ,_bf .Errorf (_de ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_beb );};if _beb > int (_aga ._aeg .NumberOfPages ){return nil ,_bf .Errorf (_de ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_beb );};_cg ,_fa :=_aga ._aeg .GetPage (_beb );if _fa !=nil {return nil ,_bf .Wrap (_fa ,_de ,"");};_cgd ,_fa :=_cg .GetBitmap ();if _fa !=nil {return nil ,_bf .Wrap (_fa ,_de ,"");};_cgd .InverseData ();if !_aga ._e .UnpaddedData {return _cgd .Data ,nil ;};return _cgd .GetUnpaddedData ();};
|
||||
package decoder ;import (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_ac "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_dd "github.com/unidoc/unipdf/v3/internal/jbig2/document";_g "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";);func (_df *Decoder )DecodePageImage (pageNumber int )(_d .Image ,error ){const _c ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_eg ,_ec :=_df .decodePageImage (pageNumber );if _ec !=nil {return nil ,_g .Wrap (_ec ,_c ,"");};return _eg ,nil ;};type Parameters struct{UnpaddedData bool ;Color _ac .Color ;};func (_ce *Decoder )decodePageImage (_db int )(_d .Image ,error ){const _ga ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _db < 0{return nil ,_g .Errorf (_ga ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_db );};if _db > int (_ce ._ad .NumberOfPages ){return nil ,_g .Errorf (_ga ,"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",_db );};_ag ,_ebf :=_ce ._ad .GetPage (_db );if _ebf !=nil {return nil ,_g .Wrap (_ebf ,_ga ,"");};_gae ,_ebf :=_ag .GetBitmap ();if _ebf !=nil {return nil ,_g .Wrap (_ebf ,_ga ,"");};return _gae .ToImage (),nil ;};func (_aa *Decoder )PageNumber ()(int ,error ){const _gd ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _aa ._ad ==nil {return 0,_g .Error (_gd ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_aa ._ad .NumberOfPages ),nil ;};func (_cf *Decoder )decodePage (_fa int )([]byte ,error ){const _fac ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _fa < 0{return nil ,_g .Errorf (_fac ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_fa );};if _fa > int (_cf ._ad .NumberOfPages ){return nil ,_g .Errorf (_fac ,"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",_fa );};_bg ,_ee :=_cf ._ad .GetPage (_fa );if _ee !=nil {return nil ,_g .Wrap (_ee ,_fac ,"");};_eb ,_ee :=_bg .GetBitmap ();if _ee !=nil {return nil ,_g .Wrap (_ee ,_fac ,"");};_eb .InverseData ();if !_cf ._f .UnpaddedData {return _eb .Data ,nil ;};return _eb .GetUnpaddedData ();};func (_gg *Decoder )DecodeNextPage ()([]byte ,error ){_gg ._ae ++;_gf :=_gg ._ae ;return _gg .decodePage (_gf );};type Decoder struct{_ba _b .StreamReader ;_ad *_dd .Document ;_ae int ;_f Parameters ;};func (_e *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _e .decodePage (pageNumber )};func Decode (input []byte ,parameters Parameters ,globals *_dd .Globals )(*Decoder ,error ){_fg :=_b .NewReader (input );_be ,_af :=_dd .DecodeDocument (_fg ,globals );if _af !=nil {return nil ,_af ;};return &Decoder {_ba :_fg ,_ad :_be ,_f :parameters },nil ;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -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 Errorf (processName ,message string ,arguments ...interface{})error {return _ab (_g .Sprintf (message ,arguments ...),processName );};type processError struct{_d string ;_bf string ;_a string ;_c error ;};func Wrap (err error ,processName ,message string )error {if _ef ,_adb :=err .(*processError );_adb {_ef ._d ="";};_f :=_ab (message ,processName );_f ._c =err ;return _f ;};func (_cg *processError )Error ()string {var _da string ;if _cg ._d !=""{_da =_cg ._d ;};_da +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_cg ._bf ;if _cg ._a !=""{_da +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_cg ._a ;};if _cg ._c !=nil {_da +="\u002e\u0020"+_cg ._c .Error ();};return _da ;};func Error (processName ,message string )error {return _ab (message ,processName )};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _dg ,_ea :=err .(*processError );_ea {_dg ._d ="";};_db :=_ab (_g .Sprintf (message ,arguments ...),processName );_db ._c =err ;return _db ;};func _ab (_e ,_ad string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_a :_e ,_bf :_ad };};
|
||||
package errors ;import _g "fmt";func (_cf *processError )Error ()string {var _cd string ;if _cf ._cg !=""{_cd =_cf ._cg ;};_cd +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_cf ._cgc ;if _cf ._f !=""{_cd +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_cf ._f ;};if _cf ._cc !=nil {_cd +="\u002e\u0020"+_cf ._cc .Error ();};return _cd ;};type processError struct{_cg string ;_cgc string ;_f string ;_cc error ;};func _a (_d ,_b string )*processError {return &processError {_cg :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_f :_d ,_cgc :_b };};func Errorf (processName ,message string ,arguments ...interface{})error {return _a (_g .Sprintf (message ,arguments ...),processName );};func Error (processName ,message string )error {return _a (message ,processName )};func Wrap (err error ,processName ,message string )error {if _ag ,_cb :=err .(*processError );_cb {_ag ._cg ="";};_cgg :=_a (message ,processName );_cgg ._cc =err ;return _cgg ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _af ,_ge :=err .(*processError );_ge {_af ._cg ="";};_dg :=_a (_g .Sprintf (message ,arguments ...),processName );_dg ._cc =err ;return _dg ;};
|
@ -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 (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_bae "github.com/unidoc/unipdf/v3/internal/jbig2/document";_g "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_bg "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_ba "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _c ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_be :=_e .NewReader (encoded );_dc ,_ce :=_bae .DecodeDocument (_be ,nil );if _ce !=nil {return nil ,_bg .Wrap (_ce ,_c ,"");};if _dc .GlobalSegments ==nil ||(_dc .GlobalSegments .Segments ==nil ){return nil ,_bg .Error (_c ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_gf :=Globals {};for _ ,_cg :=range _dc .GlobalSegments .Segments {_gf [int (_cg .SegmentNumber )]=_cg ;};return _gf ,nil ;};func (_efd Globals )ToDocumentGlobals ()*_bae .Globals {if _efd ==nil {return nil ;};_f :=[]*_g .Header {};for _ ,_a :=range _efd {_f =append (_f ,_a );};_ba .Slice (_f ,func (_fe ,_ac int )bool {return _f [_fe ].SegmentNumber < _f [_ac ].SegmentNumber });return &_bae .Globals {Segments :_f };};type Globals map[int ]*_g .Header ;func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _bab Globals ;if len (globals )> 0{_bab =globals [0];};_eg ,_ef :=_d .Decode (encoded ,parameters ,_bab .ToDocumentGlobals ());if _ef !=nil {return nil ,_ef ;};return _eg .DecodeNextPage ();};
|
||||
package jbig2 ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_b "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_cf "github.com/unidoc/unipdf/v3/internal/jbig2/document";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_d "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_gf "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _gc ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_cd :=_g .NewReader (encoded );_ea ,_f :=_cf .DecodeDocument (_cd ,nil );if _f !=nil {return nil ,_d .Wrap (_f ,_gc ,"");};if _ea .GlobalSegments ==nil ||(_ea .GlobalSegments .Segments ==nil ){return nil ,_d .Error (_gc ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_gfg :=Globals {};for _ ,_gd :=range _ea .GlobalSegments .Segments {_gfg [int (_gd .SegmentNumber )]=_gd ;};return _gfg ,nil ;};func DecodeBytes (encoded []byte ,parameters _b .Parameters ,globals ...Globals )([]byte ,error ){var _ef Globals ;if len (globals )> 0{_ef =globals [0];};_gfe ,_dc :=_b .Decode (encoded ,parameters ,_ef .ToDocumentGlobals ());if _dc !=nil {return nil ,_dc ;};return _gfe .DecodeNextPage ();};type Globals map[int ]*_c .Header ;func (_eb Globals )ToDocumentGlobals ()*_cf .Globals {if _eb ==nil {return nil ;};_gg :=[]*_c .Header {};for _ ,_a :=range _eb {_gg =append (_gg ,_a );};_gf .Slice (_gg ,func (_efc ,_fd int )bool {return _gg [_efc ].SegmentNumber < _gg [_fd ].SegmentNumber });return &_cf .Globals {Segments :_gg };};
|
@ -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 (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_eb "github.com/unidoc/unipdf/v3/internal/imageutil";_f "io";);func (_efg *Writer )WriteSample (sample uint32 )error {if _ ,_bea :=_efg ._ff .WriteBits (uint64 (sample ),_efg ._db .BitsPerComponent );_bea !=nil {return _bea ;};_efg ._dae --;if _efg ._dae ==0{_efg ._dae =_efg ._db .ColorComponents ;_efg ._fa ++;};if _efg ._fa ==_efg ._db .Width {if _efg ._beg {_efg ._ff .FinishByte ();};_efg ._fa =0;};return nil ;};func (_fe *Reader )ReadSample ()(uint32 ,error ){if _fe ._a ==_fe ._g .Height {return 0,_f .EOF ;};_eg ,_gg :=_fe ._d .ReadBits (byte (_fe ._g .BitsPerComponent ));if _gg !=nil {return 0,_gg ;};_fe ._ea --;if _fe ._ea ==0{_fe ._ea =_fe ._g .ColorComponents ;_fe ._gf ++;};if _fe ._gf ==_fe ._g .Width {if _fe ._ed {_fe ._d .ConsumeRemainingBits ();};_fe ._gf =0;_fe ._a ++;};return uint32 (_eg ),nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _dd []uint32 ;_ga :=bitsPerSample ;var _da uint32 ;var _fg byte ;_bc :=0;_fc :=0;_egf :=0;for _egf < len (data ){if _bc > 0{_bb :=_bc ;if _ga < _bb {_bb =_ga ;};_da =(_da <<uint (_bb ))|uint32 (_fg >>uint (8-_bb ));_bc -=_bb ;if _bc > 0{_fg =_fg <<uint (_bb );}else {_fg =0;};_ga -=_bb ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};}else {_ebb :=data [_egf ];_egf ++;_bf :=8;if _ga < _bf {_bf =_ga ;};_bc =8-_bf ;_da =(_da <<uint (_bf ))|uint32 (_ebb >>uint (_bc ));if _bf < 8{_fg =_ebb <<uint (_bf );};_ga -=_bf ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};};};for _bc >=bitsPerSample {_fed :=_bc ;if _ga < _fed {_fed =_ga ;};_da =(_da <<uint (_fed ))|uint32 (_fg >>uint (8-_fed ));_bc -=_fed ;if _bc > 0{_fg =_fg <<uint (_fed );}else {_fg =0;};_ga -=_fed ;if _ga ==0{_dd =append (_dd ,_da );_ga =bitsPerSample ;_da =0;_fc ++;};};return _dd ;};type Reader struct{_g _eb .ImageBase ;_d *_b .Reader ;_gf ,_a ,_ea int ;_ed bool ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _gd []uint32 ;_aa :=bitsPerOutputSample ;var _edd uint32 ;var _ggf uint32 ;_ag :=0;_gdb :=0;_ge :=0;for _ge < len (data ){if _ag > 0{_ggc :=_ag ;if _aa < _ggc {_ggc =_aa ;};_edd =(_edd <<uint (_ggc ))|uint32 (_ggf >>uint (bitsPerInputSample -_ggc ));_ag -=_ggc ;if _ag > 0{_ggf =_ggf <<uint (_ggc );}else {_ggf =0;};_aa -=_ggc ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};}else {_be :=data [_ge ];_ge ++;_df :=bitsPerInputSample ;if _aa < _df {_df =_aa ;};_ag =bitsPerInputSample -_df ;_edd =(_edd <<uint (_df ))|uint32 (_be >>uint (_ag ));if _df < bitsPerInputSample {_ggf =_be <<uint (_df );};_aa -=_df ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};};};for _ag >=bitsPerOutputSample {_de :=_ag ;if _aa < _de {_de =_aa ;};_edd =(_edd <<uint (_de ))|uint32 (_ggf >>uint (bitsPerInputSample -_de ));_ag -=_de ;if _ag > 0{_ggf =_ggf <<uint (_de );}else {_ggf =0;};_aa -=_de ;if _aa ==0{_gd =append (_gd ,_edd );_aa =bitsPerOutputSample ;_edd =0;_gdb ++;};};if _aa > 0&&_aa < bitsPerOutputSample {_edd <<=uint (_aa );_gd =append (_gd ,_edd );};return _gd ;};func NewReader (img _eb .ImageBase )*Reader {return &Reader {_d :_b .NewReader (img .Data ),_g :img ,_ea :img .ColorComponents ,_ed :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_beaf *Writer )WriteSamples (samples []uint32 )error {for _bbd :=0;_bbd < len (samples );_bbd ++{if _gb :=_beaf .WriteSample (samples [_bbd ]);_gb !=nil {return _gb ;};};return nil ;};func NewWriter (img _eb .ImageBase )*Writer {return &Writer {_ff :_b .NewWriterMSB (img .Data ),_db :img ,_dae :img .ColorComponents ,_beg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ec []uint32 )error ;};type SampleWriter interface{WriteSample (_bd uint32 )error ;WriteSamples (_gda []uint32 )error ;};type Writer struct{_db _eb .ImageBase ;_ff *_b .Writer ;_fa ,_dae int ;_beg bool ;};func (_ab *Reader )ReadSamples (samples []uint32 )(_ef error ){for _ebd :=0;_ebd < len (samples );_ebd ++{samples [_ebd ],_ef =_ab .ReadSample ();if _ef !=nil {return _ef ;};};return nil ;};
|
||||
package sampling ;import (_c "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/imageutil";_d "io";);func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _ec []uint32 ;_bbf :=bitsPerOutputSample ;var _bd uint32 ;var _db uint32 ;_cfg :=0;_bcd :=0;_da :=0;for _da < len (data ){if _cfg > 0{_ef :=_cfg ;if _bbf < _ef {_ef =_bbf ;};_bd =(_bd <<uint (_ef ))|uint32 (_db >>uint (bitsPerInputSample -_ef ));_cfg -=_ef ;if _cfg > 0{_db =_db <<uint (_ef );}else {_db =0;};_bbf -=_ef ;if _bbf ==0{_ec =append (_ec ,_bd );_bbf =bitsPerOutputSample ;_bd =0;_bcd ++;};}else {_fbf :=data [_da ];_da ++;_cec :=bitsPerInputSample ;if _bbf < _cec {_cec =_bbf ;};_cfg =bitsPerInputSample -_cec ;_bd =(_bd <<uint (_cec ))|uint32 (_fbf >>uint (_cfg ));if _cec < bitsPerInputSample {_db =_fbf <<uint (_cec );};_bbf -=_cec ;if _bbf ==0{_ec =append (_ec ,_bd );_bbf =bitsPerOutputSample ;_bd =0;_bcd ++;};};};for _cfg >=bitsPerOutputSample {_fa :=_cfg ;if _bbf < _fa {_fa =_bbf ;};_bd =(_bd <<uint (_fa ))|uint32 (_db >>uint (bitsPerInputSample -_fa ));_cfg -=_fa ;if _cfg > 0{_db =_db <<uint (_fa );}else {_db =0;};_bbf -=_fa ;if _bbf ==0{_ec =append (_ec ,_bd );_bbf =bitsPerOutputSample ;_bd =0;_bcd ++;};};if _bbf > 0&&_bbf < bitsPerOutputSample {_bd <<=uint (_bbf );_ec =append (_ec ,_bd );};return _ec ;};type Writer struct{_gf _a .ImageBase ;_dff *_c .Writer ;_agbe ,_eg int ;_cg bool ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_gc []uint32 )error ;};type SampleWriter interface{WriteSample (_bg uint32 )error ;WriteSamples (_ac []uint32 )error ;};func NewReader (img _a .ImageBase )*Reader {return &Reader {_f :_c .NewReader (img .Data ),_ad :img ,_fg :img .ColorComponents ,_ag :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _e []uint32 ;_cf :=bitsPerSample ;var _fb uint32 ;var _dfd byte ;_cdg :=0;_ed :=0;_cc :=0;for _cc < len (data ){if _cdg > 0{_gd :=_cdg ;if _cf < _gd {_gd =_cf ;};_fb =(_fb <<uint (_gd ))|uint32 (_dfd >>uint (8-_gd ));_cdg -=_gd ;if _cdg > 0{_dfd =_dfd <<uint (_gd );}else {_dfd =0;};_cf -=_gd ;if _cf ==0{_e =append (_e ,_fb );_cf =bitsPerSample ;_fb =0;_ed ++;};}else {_eb :=data [_cc ];_cc ++;_ff :=8;if _cf < _ff {_ff =_cf ;};_cdg =8-_ff ;_fb =(_fb <<uint (_ff ))|uint32 (_eb >>uint (_cdg ));if _ff < 8{_dfd =_eb <<uint (_ff );};_cf -=_ff ;if _cf ==0{_e =append (_e ,_fb );_cf =bitsPerSample ;_fb =0;_ed ++;};};};for _cdg >=bitsPerSample {_cea :=_cdg ;if _cf < _cea {_cea =_cf ;};_fb =(_fb <<uint (_cea ))|uint32 (_dfd >>uint (8-_cea ));_cdg -=_cea ;if _cdg > 0{_dfd =_dfd <<uint (_cea );}else {_dfd =0;};_cf -=_cea ;if _cf ==0{_e =append (_e ,_fb );_cf =bitsPerSample ;_fb =0;_ed ++;};};return _e ;};func (_dbg *Writer )WriteSample (sample uint32 )error {if _ ,_ea :=_dbg ._dff .WriteBits (uint64 (sample ),_dbg ._gf .BitsPerComponent );_ea !=nil {return _ea ;};_dbg ._eg --;if _dbg ._eg ==0{_dbg ._eg =_dbg ._gf .ColorComponents ;_dbg ._agbe ++;};if _dbg ._agbe ==_dbg ._gf .Width {if _dbg ._cg {_dbg ._dff .FinishByte ();};_dbg ._agbe =0;};return nil ;};func (_fc *Writer )WriteSamples (samples []uint32 )error {for _fe :=0;_fe < len (samples );_fe ++{if _ffd :=_fc .WriteSample (samples [_fe ]);_ffd !=nil {return _ffd ;};};return nil ;};func (_af *Reader )ReadSample ()(uint32 ,error ){if _af ._cd ==_af ._ad .Height {return 0,_d .EOF ;};_df ,_bb :=_af ._f .ReadBits (byte (_af ._ad .BitsPerComponent ));if _bb !=nil {return 0,_bb ;};_af ._fg --;if _af ._fg ==0{_af ._fg =_af ._ad .ColorComponents ;_af ._b ++;};if _af ._b ==_af ._ad .Width {if _af ._ag {_af ._f .ConsumeRemainingBits ();};_af ._b =0;_af ._cd ++;};return uint32 (_df ),nil ;};type Reader struct{_ad _a .ImageBase ;_f *_c .Reader ;_b ,_cd ,_fg int ;_ag bool ;};func (_bc *Reader )ReadSamples (samples []uint32 )(_agb error ){for _ce :=0;_ce < len (samples );_ce ++{samples [_ce ],_agb =_bc .ReadSample ();if _agb !=nil {return _agb ;};};return nil ;};func NewWriter (img _a .ImageBase )*Writer {return &Writer {_dff :_c .NewWriterMSB (img .Data ),_gf :img ,_eg :img .ColorComponents ,_cg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};
|
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
4795
model/model.go
4795
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,37 +10,24 @@
|
||||
// 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 (_eb "bytes";_eg "crypto";_af "crypto/rand";_ec "crypto/rsa";_gg "crypto/x509";_fc "crypto/x509/pkix";_aa "encoding/asn1";_ff "errors";_bg "fmt";_ggf "github.com/unidoc/pkcs7";_bgb "github.com/unidoc/timestamp";_d "github.com/unidoc/unipdf/v3/core";_fb "github.com/unidoc/unipdf/v3/model";_g "hash";_f "io";_bb "io/ioutil";_b "net/http";_a "time";);
|
||||
|
||||
// NewEmptyAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached
|
||||
// signature handler. The generated signature is empty and of size signatureLen.
|
||||
// The signatureLen parameter can be 0 for the signature validation.
|
||||
func NewEmptyAdobePKCS7Detached (signatureLen int )(_fb .SignatureHandler ,error ){return &adobePKCS7Detached {_c :true ,_aaf :signatureLen },nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_ag *adobePKCS7Detached )IsApplicable (sig *_fb .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};
|
||||
|
||||
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
// NOTE: the handler will do a mock Sign when initializing the signature
|
||||
// in order to estimate the signature size. Use NewDocTimeStampWithOpts
|
||||
// for providing the signature size.
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _eg .Hash )(_fb .SignatureHandler ,error ){return &docTimeStamp {_fbgb :timestampServerURL ,_ceb :hashAlgorithm },nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_dfb *docTimeStamp )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){return _eb .NewBuffer (nil ),nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_gca *adobeX509RSASHA1 )IsApplicable (sig *_fb .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};
|
||||
package sighandler ;import (_g "bytes";_e "crypto";_ea "crypto/rand";_b "crypto/rsa";_add "crypto/x509";_ec "crypto/x509/pkix";_aa "encoding/asn1";_dd "errors";_af "fmt";_adf "github.com/unidoc/pkcs7";_ba "github.com/unidoc/timestamp";_ge "github.com/unidoc/unipdf/v3/core";_ecd "github.com/unidoc/unipdf/v3/model";_cb "hash";_c "io";_ad "io/ioutil";_a "net/http";_f "time";);
|
||||
|
||||
// Sign sets the Contents fields.
|
||||
func (_ca *adobePKCS7Detached )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {if _ca ._c {_cc :=_ca ._aaf ;if _cc <=0{_cc =8192;};sig .Contents =_d .MakeHexString (string (make ([]byte ,_cc )));return nil ;};_ged :=digest .(*_eb .Buffer );_fd ,_ee :=_ggf .NewSignedData (_ged .Bytes ());if _ee !=nil {return _ee ;};if _cf :=_fd .AddSigner (_ca ._da ,_ca ._aaa ,_ggf .SignerInfoConfig {});_cf !=nil {return _cf ;};_fd .Detach ();_fe ,_ee :=_fd .Finish ();if _ee !=nil {return _ee ;};_daa :=make ([]byte ,8192);copy (_daa ,_fe );sig .Contents =_d .MakeHexString (string (_daa ));return nil ;};
|
||||
func (_cf *adobePKCS7Detached )Sign (sig *_ecd .PdfSignature ,digest _ecd .Hasher )error {if _cf ._eab {_gg :=_cf ._bf ;if _gg <=0{_gg =8192;};sig .Contents =_ge .MakeHexString (string (make ([]byte ,_gg )));return nil ;};_ac :=digest .(*_g .Buffer );_fg ,_ag :=_adf .NewSignedData (_ac .Bytes ());if _ag !=nil {return _ag ;};if _dg :=_fg .AddSigner (_cf ._fb ,_cf ._bc ,_adf .SignerInfoConfig {});_dg !=nil {return _dg ;};_fg .Detach ();_aae ,_ag :=_fg .Finish ();if _ag !=nil {return _ag ;};_feg :=make ([]byte ,8192);copy (_feg ,_aae );sig .Contents =_ge .MakeHexString (string (_feg ));return nil ;};func (_cbf *adobeX509RSASHA1 )getCertificate (_bag *_ecd .PdfSignature )(*_add .Certificate ,error ){if _cbf ._acc !=nil {return _cbf ._acc ,nil ;};var _fag []byte ;switch _dgg :=_bag .Cert .(type ){case *_ge .PdfObjectString :_fag =_dgg .Bytes ();case *_ge .PdfObjectArray :if _dgg .Len ()==0{return nil ,_dd .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 _ ,_fc :=range _dgg .Elements (){_ecc ,_eaa :=_ge .GetString (_fc );if !_eaa {return nil ,_af .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",_fc );};_fag =append (_fag ,_ecc .Bytes ()...);};default:return nil ,_af .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",_dgg );};_caa ,_efe :=_add .ParseCertificates (_fag );if _efe !=nil {return nil ,_efe ;};return _caa [0],nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_ga *adobePKCS7Detached )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_eca :=sig .Contents .Bytes ();_dg ,_fgc :=_ggf .Parse (_eca );if _fgc !=nil {return _fb .SignatureValidationResult {},_fgc ;};_ba :=digest .(*_eb .Buffer );_dg .Content =_ba .Bytes ();if _fgc =_dg .Verify ();_fgc !=nil {return _fb .SignatureValidationResult {},_fgc ;};return _fb .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_dc *_ecd .PdfSignature ,_de _ecd .Hasher )([]byte ,error );
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_acf *adobeX509RSASHA1 )InitSignature (sig *_ecd .PdfSignature )error {if _acf ._acc ==nil {return _dd .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 _acf ._ada ==nil &&_acf ._cfd ==nil {return _dd .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");};_dcb :=*_acf ;sig .Handler =&_dcb ;sig .Filter =_ge .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_ge .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_ge .MakeString (string (_dcb ._acc .Raw ));sig .Reference =nil ;_fa ,_bcc :=_dcb .NewDigest (sig );if _bcc !=nil {return _bcc ;};_fa .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 _dcb .Sign (sig ,_fa );};func (_baab *docTimeStamp )getCertificate (_cbfd *_ecd .PdfSignature )(*_add .Certificate ,error ){var _bfe []byte ;switch _efa :=_cbfd .Cert .(type ){case *_ge .PdfObjectString :_bfe =_efa .Bytes ();case *_ge .PdfObjectArray :if _efa .Len ()==0{return nil ,_dd .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 _ ,_edf :=range _efa .Elements (){_fd ,_aeb :=_ge .GetString (_edf );if !_aeb {return nil ,_af .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",_edf );};_bfe =append (_bfe ,_fd .Bytes ()...);};default:return nil ,_af .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",_efa );};_dfd ,_bfc :=_add .ParseCertificates (_bfe );if _bfc !=nil {return nil ,_bfc ;};return _dfd [0],nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_gc *docTimeStamp )NewDigest (sig *_ecd .PdfSignature )(_ecd .Hasher ,error ){return _g .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 *_add .Certificate ,signFunc SignFunc )(_ecd .SignatureHandler ,error ){return &adobeX509RSASHA1 {_acc :certificate ,_cfd :signFunc },nil ;};
|
||||
|
||||
// DocTimeStampOpts defines options for configuring the timestamp handler.
|
||||
type DocTimeStampOpts struct{
|
||||
@ -52,29 +39,11 @@ type DocTimeStampOpts struct{
|
||||
// signature.
|
||||
SignatureSize int ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_fdb *adobeX509RSASHA1 )InitSignature (sig *_fb .PdfSignature )error {if _fdb ._bad ==nil {return _ff .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _fdb ._fa ==nil &&_fdb ._df ==nil {return _ff .New ("\u006d\u0075\u0073\u0074\u0020\u0070\u0072o\u0076\u0069\u0064e\u0020\u0065\u0069t\u0068\u0065r\u0020\u0061\u0020\u0070\u0072\u0069v\u0061te\u0020\u006b\u0065\u0079\u0020\u006f\u0072\u0020\u0061\u0020\u0073\u0069\u0067\u006e\u0069\u006e\u0067\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_fbb :=*_fdb ;sig .Handler =&_fbb ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_d .MakeString (string (_fbb ._bad .Raw ));sig .Reference =nil ;_ae ,_dd :=_fbb .NewDigest (sig );if _dd !=nil {return _dd ;};_ae .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _fbb .Sign (sig ,_ae );};type docTimeStamp struct{_fbgb string ;_ceb _eg .Hash ;_bab int ;};
|
||||
|
||||
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler
|
||||
// with a custom signing function. Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1Custom (certificate *_gg .Certificate ,signFunc SignFunc )(_fb .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bad :certificate ,_df :signFunc },nil ;};
|
||||
// NewDigest creates a new digest.
|
||||
func (_baa *adobePKCS7Detached )NewDigest (sig *_ecd .PdfSignature )(_ecd .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_ffa *adobePKCS7Detached )InitSignature (sig *_fb .PdfSignature )error {if !_ffa ._c {if _ffa ._da ==nil {return _ff .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _ffa ._aaa ==nil {return _ff .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_cg :=*_ffa ;sig .Handler =&_cg ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_gc ,_fbg :=_cg .NewDigest (sig );if _fbg !=nil {return _fbg ;};_gc .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _cg .Sign (sig ,_gc );};type adobePKCS7Detached struct{_aaa *_ec .PrivateKey ;_da *_gg .Certificate ;_c bool ;_aaf int ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_eed *docTimeStamp )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_gbg :=sig .Contents .Bytes ();_fdga ,_gfg :=_ggf .Parse (_gbg );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};if _gfg =_fdga .Verify ();_gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};var _ecg timestampInfo ;_ ,_gfg =_aa .Unmarshal (_fdga .Content ,&_ecg );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};_cd ,_gfg :=_afd (_ecg .MessageImprint .HashAlgorithm .Algorithm );if _gfg !=nil {return _fb .SignatureValidationResult {},_gfg ;};_aac :=_cd .New ();_cgd :=digest .(*_eb .Buffer );_aac .Write (_cgd .Bytes ());_aag :=_aac .Sum (nil );_ccb :=_fb .SignatureValidationResult {IsSigned :true ,IsVerified :_eb .Equal (_aag ,_ecg .MessageImprint .HashedMessage ),GeneralizedTime :_ecg .GeneralizedTime };return _ccb ,nil ;};type adobeX509RSASHA1 struct{_fa *_ec .PrivateKey ;_bad *_gg .Certificate ;_df SignFunc ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_caa *docTimeStamp )IsApplicable (sig *_fb .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};func (_ac *docTimeStamp )getCertificate (_gcb *_fb .PdfSignature )(*_gg .Certificate ,error ){var _fde []byte ;switch _ebc :=_gcb .Cert .(type ){case *_d .PdfObjectString :_fde =_ebc .Bytes ();case *_d .PdfObjectArray :if _ebc .Len ()==0{return nil ,_ff .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_gbc :=range _ebc .Elements (){_bgc ,_daf :=_d .GetString (_gbc );if !_daf {return nil ,_bg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_gbc );};_fde =append (_fde ,_bgc .Bytes ()...);};default:return nil ,_bg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_ebc );};_gee ,_fbge :=_gg .ParseCertificates (_fde );if _fbge !=nil {return nil ,_fbge ;};return _gee [0],nil ;};
|
||||
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_bf *_fb .PdfSignature ,_aga _fb .Hasher )([]byte ,error );
|
||||
|
||||
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobePKCS7Detached (privateKey *_ec .PrivateKey ,certificate *_gg .Certificate )(_fb .SignatureHandler ,error ){return &adobePKCS7Detached {_da :certificate ,_aaa :privateKey },nil ;};
|
||||
func (_afd *adobePKCS7Detached )InitSignature (sig *_ecd .PdfSignature )error {if !_afd ._eab {if _afd ._fb ==nil {return _dd .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 _afd ._bc ==nil {return _dd .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");};};_bd :=*_afd ;sig .Handler =&_bd ;sig .Filter =_ge .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_ge .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_cba ,_ca :=_bd .NewDigest (sig );if _ca !=nil {return _ca ;};_cba .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 _bd .Sign (sig ,_cba );};
|
||||
|
||||
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
|
||||
// specified options. If no options are provided, default options will be used.
|
||||
@ -82,26 +51,57 @@ func NewAdobePKCS7Detached (privateKey *_ec .PrivateKey ,certificate *_gg .Certi
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _eg .Hash ,opts *DocTimeStampOpts )(_fb .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_fbgb :timestampServerURL ,_ceb :hashAlgorithm ,_bab :opts .SignatureSize },nil ;};
|
||||
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _e .Hash ,opts *DocTimeStampOpts )(_ecd .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_bcg :timestampServerURL ,_fec :hashAlgorithm ,_faa :opts .SignatureSize },nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_ee *adobePKCS7Detached )IsApplicable (sig *_ecd .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";};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_cbc *adobeX509RSASHA1 )IsApplicable (sig *_ecd .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_ae *adobeX509RSASHA1 )Sign (sig *_ecd .PdfSignature ,digest _ecd .Hasher )error {var _eef []byte ;var _ded error ;if _ae ._cfd !=nil {_eef ,_ded =_ae ._cfd (sig ,digest );if _ded !=nil {return _ded ;};}else {_acd ,_dde :=digest .(_cb .Hash );if !_dde {return _dd .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_cgc ,_ :=_ead (_ae ._acc .SignatureAlgorithm );_eef ,_ded =_b .SignPKCS1v15 (_ea .Reader ,_ae ._ada ,_cgc ,_acd .Sum (nil ));if _ded !=nil {return _ded ;};};_eef ,_ded =_aa .Marshal (_eef );if _ded !=nil {return _ded ;};sig .Contents =_ge .MakeHexString (string (_eef ));return nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_bdc *adobeX509RSASHA1 )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){_eee ,_ega :=_bdc .getCertificate (sig );if _ega !=nil {return nil ,_ega ;};_ddf ,_ :=_ebe (_eee .SignatureAlgorithm );return _ddf .New (),nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_dba *adobeX509RSASHA1 )Validate (sig *_fb .PdfSignature ,digest _fb .Hasher )(_fb .SignatureValidationResult ,error ){_bfc ,_ebeg :=_dba .getCertificate (sig );if _ebeg !=nil {return _fb .SignatureValidationResult {},_ebeg ;};_cag :=sig .Contents .Bytes ();var _fcb []byte ;if _ ,_ffb :=_aa .Unmarshal (_cag ,&_fcb );_ffb !=nil {return _fb .SignatureValidationResult {},_ffb ;};_fdf ,_dae :=digest .(_g .Hash );if !_dae {return _fb .SignatureValidationResult {},_ff .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ea ,_ :=_ebe (_bfc .SignatureAlgorithm );if _ce :=_ec .VerifyPKCS1v15 (_bfc .PublicKey .(*_ec .PublicKey ),_ea ,_fdf .Sum (nil ),_fcb );_ce !=nil {return _fb .SignatureValidationResult {},_ce ;};return _fb .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};func (_cb *adobeX509RSASHA1 )getCertificate (_ed *_fb .PdfSignature )(*_gg .Certificate ,error ){if _cb ._bad !=nil {return _cb ._bad ,nil ;};var _bfe []byte ;switch _fbc :=_ed .Cert .(type ){case *_d .PdfObjectString :_bfe =_fbc .Bytes ();case *_d .PdfObjectArray :if _fbc .Len ()==0{return nil ,_ff .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_gcd :=range _fbc .Elements (){_dbc ,_gf :=_d .GetString (_gcd );if !_gf {return nil ,_bg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_gcd );};_bfe =append (_bfe ,_dbc .Bytes ()...);};default:return nil ,_bg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_fbc );};_gfc ,_gbb :=_gg .ParseCertificates (_bfe );if _gbb !=nil {return nil ,_gbb ;};return _gfc [0],nil ;};func _afd (_aef _aa .ObjectIdentifier )(_eg .Hash ,error ){switch {case _aef .Equal (_ggf .OIDDigestAlgorithmSHA1 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA1 ),_aef .Equal (_ggf .OIDDigestAlgorithmDSA ),_aef .Equal (_ggf .OIDDigestAlgorithmDSASHA1 ),_aef .Equal (_ggf .OIDEncryptionAlgorithmRSA ):return _eg .SHA1 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA256 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA256 ):return _eg .SHA256 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA384 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA384 ):return _eg .SHA384 ,nil ;case _aef .Equal (_ggf .OIDDigestAlgorithmSHA512 ),_aef .Equal (_ggf .OIDDigestAlgorithmECDSASHA512 ):return _eg .SHA512 ,nil ;};return _eg .Hash (0),_ggf .ErrUnsupportedAlgorithm ;};
|
||||
func (_fbe *adobeX509RSASHA1 )NewDigest (sig *_ecd .PdfSignature )(_ecd .Hasher ,error ){_fbc ,_dca :=_fbe .getCertificate (sig );if _dca !=nil {return nil ,_dca ;};_bcf ,_ :=_ead (_fbc .SignatureAlgorithm );return _bcf .New (),nil ;};
|
||||
|
||||
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1 (privateKey *_ec .PrivateKey ,certificate *_gg .Certificate )(_fb .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bad :certificate ,_fa :privateKey },nil ;};type timestampInfo struct{Version int ;Policy _aa .RawValue ;MessageImprint struct{HashAlgorithm _fc .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _aa .RawValue ;GeneralizedTime _a .Time ;};func _ebe (_age _gg .SignatureAlgorithm )(_eg .Hash ,bool ){var _fef _eg .Hash ;switch _age {case _gg .SHA1WithRSA :_fef =_eg .SHA1 ;case _gg .SHA256WithRSA :_fef =_eg .SHA256 ;case _gg .SHA384WithRSA :_fef =_eg .SHA384 ;case _gg .SHA512WithRSA :_fef =_eg .SHA512 ;default:return _eg .SHA1 ,false ;};return _fef ,true ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_agc *docTimeStamp )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {_bbe :=digest .(*_eb .Buffer );_aca :=_agc ._ceb .New ();if _ ,_bgd :=_f .Copy (_aca ,_bbe );_bgd !=nil {return _bgd ;};_egag :=_bgb .Request {HashAlgorithm :_agc ._ceb ,HashedMessage :_aca .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_gbe ,_eff :=_egag .Marshal ();if _eff !=nil {return _eff ;};_ffba ,_eff :=_b .Post (_agc ._fbgb ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_eb .NewBuffer (_gbe ));if _eff !=nil {return _eff ;};defer _ffba .Body .Close ();_cbf ,_eff :=_bb .ReadAll (_ffba .Body );if _eff !=nil {return _eff ;};if _ffba .StatusCode !=_b .StatusOK {return _bg .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_ffba .StatusCode );};var _acg struct{Version _aa .RawValue ;Content _aa .RawValue ;};if _ ,_eff =_aa .Unmarshal (_cbf ,&_acg );_eff !=nil {return _eff ;};_bgcg :=len (_acg .Content .FullBytes );if _agc ._bab > 0&&_bgcg > _agc ._bab {return _fb .ErrSignNotEnoughSpace ;};if _bgcg > 0{_agc ._bab =_bgcg +128;};sig .Contents =_d .MakeHexString (string (_acg .Content .FullBytes ));return nil ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_cfb *adobeX509RSASHA1 )Sign (sig *_fb .PdfSignature ,digest _fb .Hasher )error {var _bbd []byte ;var _dgd error ;if _cfb ._df !=nil {_bbd ,_dgd =_cfb ._df (sig ,digest );if _dgd !=nil {return _dgd ;};}else {_ede ,_fdg :=digest .(_g .Hash );if !_fdg {return _ff .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_fbd ,_ :=_ebe (_cfb ._bad .SignatureAlgorithm );_bbd ,_dgd =_ec .SignPKCS1v15 (_af .Reader ,_cfb ._fa ,_fbd ,_ede .Sum (nil ));if _dgd !=nil {return _dgd ;};};_bbd ,_dgd =_aa .Marshal (_bbd );if _dgd !=nil {return _dgd ;};sig .Contents =_d .MakeHexString (string (_bbd ));return nil ;};
|
||||
func NewAdobeX509RSASHA1 (privateKey *_b .PrivateKey ,certificate *_add .Certificate )(_ecd .SignatureHandler ,error ){return &adobeX509RSASHA1 {_acc :certificate ,_ada :privateKey },nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_ef *docTimeStamp )InitSignature (sig *_fb .PdfSignature )error {_edg :=*_ef ;sig .Handler =&_edg ;sig .Filter =_d .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_d .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _ef ._bab > 0{sig .Contents =_d .MakeHexString (string (make ([]byte ,_ef ._bab )));}else {_bdf ,_bgf :=_ef .NewDigest (sig );if _bgf !=nil {return _bgf ;};_bdf .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));if _bgf =_edg .Sign (sig ,_bdf );_bgf !=nil {return _bgf ;};_ef ._bab =_edg ._bab ;};return nil ;};func (_bc *adobePKCS7Detached )getCertificate (_egb *_fb .PdfSignature )(*_gg .Certificate ,error ){if _bc ._da !=nil {return _bc ._da ,nil ;};var _fg []byte ;switch _gb :=_egb .Cert .(type ){case *_d .PdfObjectString :_fg =_gb .Bytes ();case *_d .PdfObjectArray :if _gb .Len ()==0{return nil ,_ff .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_ad :=range _gb .Elements (){_dc ,_gd :=_d .GetString (_ad );if !_gd {return nil ,_bg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_ad );};_fg =append (_fg ,_dc .Bytes ()...);};default:return nil ,_bg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_gb );};_dcd ,_dcdb :=_gg .ParseCertificates (_fg );if _dcdb !=nil {return nil ,_dcdb ;};return _dcd [0],nil ;};
|
||||
func (_cga *docTimeStamp )InitSignature (sig *_ecd .PdfSignature )error {_aca :=*_cga ;sig .Handler =&_aca ;sig .Filter =_ge .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_ge .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _cga ._faa > 0{sig .Contents =_ge .MakeHexString (string (make ([]byte ,_cga ._faa )));}else {_agb ,_ceb :=_cga .NewDigest (sig );if _ceb !=nil {return _ceb ;};_agb .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));if _ceb =_aca .Sign (sig ,_agb );_ceb !=nil {return _ceb ;};_cga ._faa =_aca ._faa ;};return nil ;};func _ead (_dcg _add .SignatureAlgorithm )(_e .Hash ,bool ){var _aad _e .Hash ;switch _dcg {case _add .SHA1WithRSA :_aad =_e .SHA1 ;case _add .SHA256WithRSA :_aad =_e .SHA256 ;case _add .SHA384WithRSA :_aad =_e .SHA384 ;case _add .SHA512WithRSA :_aad =_e .SHA512 ;default:return _e .SHA1 ,false ;};return _aad ,true ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_ge *adobePKCS7Detached )NewDigest (sig *_fb .PdfSignature )(_fb .Hasher ,error ){return _eb .NewBuffer (nil ),nil ;};
|
||||
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobePKCS7Detached (privateKey *_b .PrivateKey ,certificate *_add .Certificate )(_ecd .SignatureHandler ,error ){return &adobePKCS7Detached {_fb :certificate ,_bc :privateKey },nil ;};
|
||||
|
||||
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
// NOTE: the handler will do a mock Sign when initializing the signature
|
||||
// in order to estimate the signature size. Use NewDocTimeStampWithOpts
|
||||
// for providing the signature size.
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _e .Hash )(_ecd .SignatureHandler ,error ){return &docTimeStamp {_bcg :timestampServerURL ,_fec :hashAlgorithm },nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_gb *adobeX509RSASHA1 )Validate (sig *_ecd .PdfSignature ,digest _ecd .Hasher )(_ecd .SignatureValidationResult ,error ){_fgb ,_bb :=_gb .getCertificate (sig );if _bb !=nil {return _ecd .SignatureValidationResult {},_bb ;};_gd :=sig .Contents .Bytes ();var _ce []byte ;if _ ,_db :=_aa .Unmarshal (_gd ,&_ce );_db !=nil {return _ecd .SignatureValidationResult {},_db ;};_bfd ,_aadc :=digest .(_cb .Hash );if !_aadc {return _ecd .SignatureValidationResult {},_dd .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ff ,_ :=_ead (_fgb .SignatureAlgorithm );if _cee :=_b .VerifyPKCS1v15 (_fgb .PublicKey .(*_b .PublicKey ),_ff ,_bfd .Sum (nil ),_ce );_cee !=nil {return _ecd .SignatureValidationResult {},_cee ;};return _ecd .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};type docTimeStamp struct{_bcg string ;_fec _e .Hash ;_faa int ;};func (_ef *adobePKCS7Detached )getCertificate (_df *_ecd .PdfSignature )(*_add .Certificate ,error ){if _ef ._fb !=nil {return _ef ._fb ,nil ;};var _da []byte ;switch _cd :=_df .Cert .(type ){case *_ge .PdfObjectString :_da =_cd .Bytes ();case *_ge .PdfObjectArray :if _cd .Len ()==0{return nil ,_dd .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 _ ,_baf :=range _cd .Elements (){_daa ,_cg :=_ge .GetString (_baf );if !_cg {return nil ,_af .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",_baf );};_da =append (_da ,_daa .Bytes ()...);};default:return nil ,_af .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",_cd );};_aaa ,_dad :=_add .ParseCertificates (_da );if _dad !=nil {return nil ,_dad ;};return _aaa [0],nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_cgce *docTimeStamp )Validate (sig *_ecd .PdfSignature ,digest _ecd .Hasher )(_ecd .SignatureValidationResult ,error ){_adb :=sig .Contents .Bytes ();_eed ,_efb :=_adf .Parse (_adb );if _efb !=nil {return _ecd .SignatureValidationResult {},_efb ;};if _efb =_eed .Verify ();_efb !=nil {return _ecd .SignatureValidationResult {},_efb ;};var _fde timestampInfo ;_ ,_efb =_aa .Unmarshal (_eed .Content ,&_fde );if _efb !=nil {return _ecd .SignatureValidationResult {},_efb ;};_cfc ,_efb :=_bg (_fde .MessageImprint .HashAlgorithm .Algorithm );if _efb !=nil {return _ecd .SignatureValidationResult {},_efb ;};_bbb :=_cfc .New ();_fdf :=digest .(*_g .Buffer );_bbb .Write (_fdf .Bytes ());_adg :=_bbb .Sum (nil );_eb :=_ecd .SignatureValidationResult {IsSigned :true ,IsVerified :_g .Equal (_adg ,_fde .MessageImprint .HashedMessage ),GeneralizedTime :_fde .GeneralizedTime };return _eb ,nil ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_baaf *docTimeStamp )Sign (sig *_ecd .PdfSignature ,digest _ecd .Hasher )error {_gca :=digest .(*_g .Buffer );_ffg :=_baaf ._fec .New ();if _ ,_cbcb :=_c .Copy (_ffg ,_gca );_cbcb !=nil {return _cbcb ;};_efc :=_ba .Request {HashAlgorithm :_baaf ._fec ,HashedMessage :_ffg .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_ebe ,_feec :=_efc .Marshal ();if _feec !=nil {return _feec ;};_aee ,_feec :=_a .Post (_baaf ._bcg ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_g .NewBuffer (_ebe ));if _feec !=nil {return _feec ;};defer _aee .Body .Close ();_dcgb ,_feec :=_ad .ReadAll (_aee .Body );if _feec !=nil {return _feec ;};if _aee .StatusCode !=_a .StatusOK {return _af .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",_aee .StatusCode );};var _dge struct{Version _aa .RawValue ;Content _aa .RawValue ;};if _ ,_feec =_aa .Unmarshal (_dcgb ,&_dge );_feec !=nil {return _feec ;};_gbd :=len (_dge .Content .FullBytes );if _baaf ._faa > 0&&_gbd > _baaf ._faa {return _ecd .ErrSignNotEnoughSpace ;};if _gbd > 0{_baaf ._faa =_gbd +128;};sig .Contents =_ge .MakeHexString (string (_dge .Content .FullBytes ));return nil ;};type adobeX509RSASHA1 struct{_ada *_b .PrivateKey ;_acc *_add .Certificate ;_cfd SignFunc ;};type timestampInfo struct{Version int ;Policy _aa .RawValue ;MessageImprint struct{HashAlgorithm _ec .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _aa .RawValue ;GeneralizedTime _f .Time ;};func _bg (_eae _aa .ObjectIdentifier )(_e .Hash ,error ){switch {case _eae .Equal (_adf .OIDDigestAlgorithmSHA1 ),_eae .Equal (_adf .OIDDigestAlgorithmECDSASHA1 ),_eae .Equal (_adf .OIDDigestAlgorithmDSA ),_eae .Equal (_adf .OIDDigestAlgorithmDSASHA1 ),_eae .Equal (_adf .OIDEncryptionAlgorithmRSA ):return _e .SHA1 ,nil ;case _eae .Equal (_adf .OIDDigestAlgorithmSHA256 ),_eae .Equal (_adf .OIDDigestAlgorithmECDSASHA256 ):return _e .SHA256 ,nil ;case _eae .Equal (_adf .OIDDigestAlgorithmSHA384 ),_eae .Equal (_adf .OIDDigestAlgorithmECDSASHA384 ):return _e .SHA384 ,nil ;case _eae .Equal (_adf .OIDDigestAlgorithmSHA512 ),_eae .Equal (_adf .OIDDigestAlgorithmECDSASHA512 ):return _e .SHA512 ,nil ;};return _e .Hash (0),_adf .ErrUnsupportedAlgorithm ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_dea *docTimeStamp )IsApplicable (sig *_ecd .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";};
|
||||
|
||||
// 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 )(_ecd .SignatureHandler ,error ){return &adobePKCS7Detached {_eab :true ,_bf :signatureLen },nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_adfg *adobePKCS7Detached )Validate (sig *_ecd .PdfSignature ,digest _ecd .Hasher )(_ecd .SignatureValidationResult ,error ){_ed :=sig .Contents .Bytes ();_fe ,_fee :=_adf .Parse (_ed );if _fee !=nil {return _ecd .SignatureValidationResult {},_fee ;};_bae :=digest .(*_g .Buffer );_fe .Content =_bae .Bytes ();if _fee =_fe .Verify ();_fee !=nil {return _ecd .SignatureValidationResult {},_fee ;};return _ecd .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};type adobePKCS7Detached struct{_bc *_b .PrivateKey ;_fb *_add .Certificate ;_eab bool ;_bf int ;};
|
@ -9,7 +9,7 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package pdfutil ;import (_d "github.com/unidoc/unipdf/v3/common";_gg "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/contentstream/draw";_g "github.com/unidoc/unipdf/v3/model";);
|
||||
package pdfutil ;import (_g "github.com/unidoc/unipdf/v3/common";_gc "github.com/unidoc/unipdf/v3/contentstream";_ea "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";);
|
||||
|
||||
// NormalizePage performs the following operations on the passed in page:
|
||||
// - Normalize the page rotation.
|
||||
@ -24,4 +24,4 @@ package pdfutil ;import (_d "github.com/unidoc/unipdf/v3/common";_gg "github.com
|
||||
// The crop box of the page is updated based on the previous operations.
|
||||
// After normalization, the page should look the same if openend using a
|
||||
// PDF viewer.
|
||||
func NormalizePage (page *_g .PdfPage )error {_f ,_fb :=page .GetMediaBox ();if _fb !=nil {return _fb ;};_be ,_fb :=page .GetContentStreams ();if _fb !=nil {return _fb ;};_gf :=page .Rotate ;_bg :=_gf !=nil &&*_gf %360!=0&&*_gf %90==0;_f .Normalize ();_ee ,_gge ,_bc ,_dc :=_f .Llx ,_f .Lly ,_f .Width (),_f .Height ();_a :=_ee !=0||_gge !=0;if !_bg &&!_a {return nil ;};_gd :=func (_fc ,_gdd ,_gfd float64 )_b .BoundingBox {return _b .Path {Points :[]_b .Point {_b .NewPoint (0,0).Rotate (_gfd ),_b .NewPoint (_fc ,0).Rotate (_gfd ),_b .NewPoint (0,_gdd ).Rotate (_gfd ),_b .NewPoint (_fc ,_gdd ).Rotate (_gfd )}}.GetBoundingBox ();};_c :=_gg .NewContentCreator ();var _ag float64 ;if _bg {_ag =-float64 (*page .Rotate );_eb :=_gd (_bc ,_dc ,_ag );_c .Translate ((_eb .Width -_bc )/2+_bc /2,(_eb .Height -_dc )/2+_dc /2);_c .RotateDeg (_ag );_c .Translate (-_bc /2,-_dc /2);_bc ,_dc =_eb .Width ,_eb .Height ;};if _a {_c .Translate (-_ee ,-_gge );};_ad :=_c .Operations ().String ();_be =append ([]string {_ad },_be ...);if _fb =page .SetContentStreams (_be ,nil );_fb !=nil {return _fb ;};*_f =_g .PdfRectangle {Urx :_bc ,Ury :_dc };if _dcc :=page .CropBox ;_dcc !=nil {_dcc .Normalize ();_gddg ,_ca ,_cd ,_dd :=_dcc .Llx -_ee ,_dcc .Lly -_gge ,_dcc .Width (),_dcc .Height ();if _bg {_eec :=_gd (_cd ,_dd ,_ag );_cd ,_dd =_eec .Width ,_eec .Height ;};*_dcc =_g .PdfRectangle {Llx :_gddg ,Lly :_ca ,Urx :_gddg +_cd ,Ury :_ca +_dd };};_d .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ag ,_ad ,_f );page .Rotate =nil ;return nil ;};
|
||||
func NormalizePage (page *_e .PdfPage )error {_b ,_bg :=page .GetMediaBox ();if _bg !=nil {return _bg ;};_c :=page .Rotate ;_bd :=_c !=nil &&*_c %360!=0&&*_c %90==0;_b .Normalize ();_fe ,_eaa ,_cf ,_ba :=_b .Llx ,_b .Lly ,_b .Width (),_b .Height ();_gf :=_fe !=0||_eaa !=0;if !_bd &&!_gf {return nil ;};_bdd :=func (_bge ,_cd ,_fa float64 )_ea .BoundingBox {return _ea .Path {Points :[]_ea .Point {_ea .NewPoint (0,0).Rotate (_fa ),_ea .NewPoint (_bge ,0).Rotate (_fa ),_ea .NewPoint (0,_cd ).Rotate (_fa ),_ea .NewPoint (_bge ,_cd ).Rotate (_fa )}}.GetBoundingBox ();};_gd :=_gc .NewContentCreator ();var _db float64 ;if _bd {_db =-float64 (*page .Rotate );_a :=_bdd (_cf ,_ba ,_db );_gd .Translate ((_a .Width -_cf )/2+_cf /2,(_a .Height -_ba )/2+_ba /2);_gd .RotateDeg (_db );_gd .Translate (-_cf /2,-_ba /2);_cf ,_ba =_a .Width ,_a .Height ;};if _gf {_gd .Translate (-_fe ,-_eaa );};_ed :=_gd .Operations ();_bc ,_bg :=_f .MakeStream (_ed .Bytes (),_f .NewFlateEncoder ());if _bg !=nil {return _bg ;};_bag :=_f .MakeArray (_bc );_bag .Append (page .GetContentStreamObjs ()...);*_b =_e .PdfRectangle {Urx :_cf ,Ury :_ba };if _gb :=page .CropBox ;_gb !=nil {_gb .Normalize ();_eb ,_bad ,_aa ,_cg :=_gb .Llx -_fe ,_gb .Lly -_eaa ,_gb .Width (),_gb .Height ();if _bd {_bgb :=_bdd (_aa ,_cg ,_db );_aa ,_cg =_bgb .Width ,_bgb .Height ;};*_gb =_e .PdfRectangle {Llx :_eb ,Lly :_bad ,Urx :_eb +_aa ,Ury :_bad +_cg };};_g .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_db ,_ed ,_b );page .Contents =_bag ;page .Rotate =nil ;return nil ;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user