mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-24 13:48:49 +08:00
prepare release
This commit is contained in:
parent
83fe969889
commit
22540b937c
File diff suppressed because one or more lines are too long
128
common/common.go
128
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 (_c "fmt";_f "io";_e "os";_bf "path/filepath";_ca "runtime";_b "time";);
|
||||
package common ;import (_f "fmt";_e "io";_dd "os";_a "path/filepath";_fb "runtime";_b "time";);
|
||||
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};
|
||||
|
||||
// Info does nothing for dummy logger.
|
||||
func (DummyLogger )Info (format string ,args ...interface{}){};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_dbf ConsoleLogger )Trace (format string ,args ...interface{}){if _dbf .LogLevel >=LogLevelTrace {_ab :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_dbf .output (_dd .Stdout ,_ab ,format ,args ...);};};
|
||||
|
||||
// Info logs info message.
|
||||
func (_gdb WriterLogger )Info (format string ,args ...interface{}){if _gdb .LogLevel >=LogLevelInfo {_ddd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_gdb .logToWriter (_gdb .Output ,_ddd ,format ,args ...);};};const Version ="\u0033\u002e\u0031\u0033\u002e\u0030";var Log Logger =DummyLogger {};
|
||||
|
||||
// Debug does nothing for dummy logger.
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};func (_fe WriterLogger )logToWriter (_abf _e .Writer ,_feb string ,_gcf string ,_dbb ...interface{}){_eeb (_abf ,_feb ,_gcf ,_dbb );};func (_ba ConsoleLogger )output (_gg _e .Writer ,_baa string ,_fbb string ,_gc ...interface{}){_eeb (_gg ,_baa ,_fbb ,_gc ...);};var ReleasedAt =_b .Date (_cbd ,_geb ,_ac ,_bag ,_fbf ,0,0,_b .UTC );
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const _gff ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
|
||||
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _e .Writer )*WriterLogger {_ead :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_ead ;};
|
||||
|
||||
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
|
||||
type ConsoleLogger struct{LogLevel LogLevel ;};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_cg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cg .LogLevel >=level };
|
||||
|
||||
// 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 ...);};
|
||||
|
||||
// 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 (_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 ...);};};
|
||||
|
||||
// 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{}){};
|
||||
|
||||
// Warning logs warning message.
|
||||
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 ;};
|
||||
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};
|
||||
|
||||
// IsLogLevel returns true from dummy logger.
|
||||
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };const _bag =10;
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_cec WriterLogger )Debug (format string ,args ...interface{}){if _cec .LogLevel >=LogLevelDebug {_bfb :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_cec .logToWriter (_cec .Output ,_bfb ,format ,args ...);};};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_fa WriterLogger )Warning (format string ,args ...interface{}){if _fa .LogLevel >=LogLevelWarning {_ece :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_fa .logToWriter (_fa .Output ,_ece ,format ,args ...);};};const _geb =10;
|
||||
|
||||
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
|
||||
func SetLogger (logger Logger ){Log =logger };
|
||||
|
||||
// IsLogLevel returns true from dummy logger.
|
||||
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
|
||||
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
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{}){};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 (_ce WriterLogger )Error (format string ,args ...interface{}){if _ce .LogLevel >=LogLevelError {_bd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ce .logToWriter (_ce .Output ,_bd ,format ,args ...);};};const _ac =19;
|
||||
|
||||
// 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 ...);};
|
||||
func (_gde ConsoleLogger )Error (format string ,args ...interface{}){if _gde .LogLevel >=LogLevelError {_bf :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gde .output (_dd .Stdout ,_bf ,format ,args ...);};};
|
||||
|
||||
// Notice does nothing for dummy logger.
|
||||
func (DummyLogger )Notice (format string ,args ...interface{}){};
|
||||
|
||||
// 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 ...);};};
|
||||
func (_gf ConsoleLogger )Warning (format string ,args ...interface{}){if _gf .LogLevel >=LogLevelWarning {_ec :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_gf .output (_dd .Stdout ,_ec ,format ,args ...);};};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_efb ConsoleLogger )Debug (format string ,args ...interface{}){if _efb .LogLevel >=LogLevelDebug {_ee :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_efb .output (_dd .Stdout ,_ee ,format ,args ...);};};func UtcTimeFormat (t _b .Time )string {return t .Format (_gff )+"\u0020\u0055\u0054\u0043"};func _eeb (_cb _e .Writer ,_cdc string ,_ff string ,_bfg ...interface{}){_ ,_fba ,_gce ,_gda :=_fb .Caller (3);if !_gda {_fba ="\u003f\u003f\u003f";_gce =0;}else {_fba =_a .Base (_fba );};_bdg :=_f .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_cdc ,_fba ,_gce )+_ff +"\u000a";_f .Fprintf (_cb ,_bdg ,_bfg ...);};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_ebf WriterLogger )Trace (format string ,args ...interface{}){if _ebf .LogLevel >=LogLevelTrace {_aee :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ebf .logToWriter (_ebf .Output ,_aee ,format ,args ...);};};
|
||||
|
||||
// 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 ...);};};
|
||||
func (_ef ConsoleLogger )Info (format string ,args ...interface{}){if _ef .LogLevel >=LogLevelInfo {_cdg :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ef .output (_dd .Stdout ,_cdg ,format ,args ...);};};const _cbd =2020;
|
||||
|
||||
// DummyLogger does nothing.
|
||||
type DummyLogger struct{};
|
||||
// Notice logs notice message.
|
||||
func (_db ConsoleLogger )Notice (format string ,args ...interface{}){if _db .LogLevel >=LogLevelNotice {_ge :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_db .output (_dd .Stdout ,_ge ,format ,args ...);};};
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _e .Writer ;};const _fbf =15;
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_bc WriterLogger )IsLogLevel (level LogLevel )bool {return _bc .LogLevel >=level };
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};
|
||||
|
||||
// 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 ...);};};
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_aa string ,_df ...interface{});Warning (_eb string ,_g ...interface{});Notice (_ae string ,_c ...interface{});Info (_gd string ,_ad ...interface{});Debug (_ea string ,_cc ...interface{});Trace (_gb string ,_cd ...interface{});IsLogLevel (_bb LogLevel )bool ;};
|
||||
|
||||
// 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;
|
||||
func (_ca WriterLogger )Notice (format string ,args ...interface{}){if _ca .LogLevel >=LogLevelNotice {_bda :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_ca .logToWriter (_ca .Output ,_bda ,format ,args ...);};};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -14,204 +14,204 @@
|
||||
// page content streams and XObject forms and thus also in annotation appearance streams.
|
||||
//
|
||||
// Also defines utility functions for drawing common shapes such as rectangles, lines and circles (ovals).
|
||||
package draw ;import (_f "fmt";_b "github.com/unidoc/unipdf/v3/contentstream";_da "github.com/unidoc/unipdf/v3/core";_de "github.com/unidoc/unipdf/v3/internal/transform";_e "github.com/unidoc/unipdf/v3/model";_d "math";);
|
||||
package draw ;import (_f "fmt";_fb "github.com/unidoc/unipdf/v3/contentstream";_a "github.com/unidoc/unipdf/v3/core";_d "github.com/unidoc/unipdf/v3/internal/transform";_cf "github.com/unidoc/unipdf/v3/model";_ce "math";);
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_ac CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ac .Curves =append (_ac .Curves ,curve );return _ac ;};
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_fgg Path )Offset (offX ,offY float64 )Path {for _ee ,_cef :=range _fgg .Points {_fgg .Points [_ee ]=_cef .Add (offX ,offY );};return _fgg ;};
|
||||
|
||||
// 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 );};
|
||||
// AddOffsetXY adds X,Y offset to all points on a curve.
|
||||
func (_ea CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_ea .P0 .X +=offX ;_ea .P1 .X +=offX ;_ea .P2 .X +=offX ;_ea .P3 .X +=offX ;_ea .P0 .Y +=offY ;_ea .P1 .Y +=offY ;_ea .P2 .Y +=offY ;_ea .P3 .Y +=offY ;return _ea ;};
|
||||
|
||||
// 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 ;};
|
||||
func (_af Path )Copy ()Path {_df :=Path {};_df .Points =[]Point {};for _ ,_bea :=range _af .Points {_df .Points =append (_df .Points ,_bea );};return _df ;};
|
||||
|
||||
// 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 ;};
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_cf .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_efb Vector )Rotate (phi float64 )Vector {_gga :=_efb .Magnitude ();_bgf :=_efb .GetPolarAngle ();return NewVectorPolar (_gga ,_bgf +phi );};
|
||||
func (_defe Vector )Rotate (phi float64 )Vector {_bbe :=_defe .Magnitude ();_bec :=_defe .GetPolarAngle ();return NewVectorPolar (_bbe ,_bec +phi );};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
|
||||
// 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 ;};
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_dgg Vector )FlipY ()Vector {_dgg .Dy =-_dgg .Dy ;return _dgg };
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
|
||||
// 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 *_e .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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 )};
|
||||
|
||||
// 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 ;};
|
||||
// BoundingBox represents the smallest rectangular area that encapsulates an object.
|
||||
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
|
||||
|
||||
// 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 ;};
|
||||
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_e :=CubicBezierCurve {};_e .P0 =NewPoint (x0 ,y0 );_e .P1 =NewPoint (x1 ,y1 );_e .P2 =NewPoint (x2 ,y2 );_e .P3 =NewPoint (x3 ,y3 );return _e ;};
|
||||
|
||||
// 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
|
||||
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
|
||||
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
|
||||
// one occurred.
|
||||
func (_aed BasicLine )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_edg :=_aed .LineWidth ;_bbg :=NewPath ();_bbg =_bbg .AppendPoint (NewPoint (_aed .X1 ,_aed .Y1 ));_bbg =_bbg .AppendPoint (NewPoint (_aed .X2 ,_aed .Y2 ));_eda :=_fb .NewContentCreator ();_ebd :=_bbg .GetBoundingBox ();DrawPathWithCreator (_bbg ,_eda );if _aed .LineStyle ==LineStyleDashed {_eda .Add_d ([]int64 {1,1},0);};_eda .Add_RG (_aed .LineColor .R (),_aed .LineColor .G (),_aed .LineColor .B ()).Add_w (_edg ).Add_S ().Add_Q ();return _eda .Bytes (),_ebd .ToPdfRectangle (),nil ;};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_ccc Point )AddVector (v Vector )Point {_ccc .X +=v .Dx ;_ccc .Y +=v .Dy ;return _ccc };
|
||||
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// GetBounds returns the bounding box of the Bezier curve.
|
||||
func (_g CubicBezierCurve )GetBounds ()_cf .PdfRectangle {_dd :=_g .P0 .X ;_ddb :=_g .P0 .X ;_ca :=_g .P0 .Y ;_b :=_g .P0 .Y ;for _bc :=0.0;_bc <=1.0;_bc +=0.001{Rx :=_g .P0 .X *_ce .Pow (1-_bc ,3)+_g .P1 .X *3*_bc *_ce .Pow (1-_bc ,2)+_g .P2 .X *3*_ce .Pow (_bc ,2)*(1-_bc )+_g .P3 .X *_ce .Pow (_bc ,3);Ry :=_g .P0 .Y *_ce .Pow (1-_bc ,3)+_g .P1 .Y *3*_bc *_ce .Pow (1-_bc ,2)+_g .P2 .Y *3*_ce .Pow (_bc ,2)*(1-_bc )+_g .P3 .Y *_ce .Pow (_bc ,3);if Rx < _dd {_dd =Rx ;};if Rx > _ddb {_ddb =Rx ;};if Ry < _ca {_ca =Ry ;};if Ry > _b {_b =Ry ;};};_ad :=_cf .PdfRectangle {};_ad .Llx =_dd ;_ad .Lly =_ca ;_ad .Urx =_ddb ;_ad .Ury =_b ;return _ad ;};
|
||||
|
||||
// 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 (_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 ;};
|
||||
func (_ddbe Polyline )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){if _ddbe .LineColor ==nil {_ddbe .LineColor =_cf .NewPdfColorDeviceRGB (0,0,0);};_abfa :=NewPath ();for _ ,_edf :=range _ddbe .Points {_abfa =_abfa .AppendPoint (_edf );};_gge :=_fb .NewContentCreator ();_gge .Add_q ();_gge .Add_RG (_ddbe .LineColor .R (),_ddbe .LineColor .G (),_ddbe .LineColor .B ());_gge .Add_w (_ddbe .LineWidth );if len (gsName )> 1{_gge .Add_gs (_a .PdfObjectName (gsName ));};DrawPathWithCreator (_abfa ,_gge );_gge .Add_S ();_gge .Add_Q ();return _gge .Bytes (),_abfa .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// 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];};
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_gfa Vector )Magnitude ()float64 {return _ce .Sqrt (_ce .Pow (_gfa .Dx ,2.0)+_ce .Pow (_gfa .Dy ,2.0));};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
|
||||
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
|
||||
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
|
||||
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;};func (_ebb Point )String ()string {return _f .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_ebb .X ,_ebb .Y );};
|
||||
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_cd CubicBezierPath )Copy ()CubicBezierPath {_dc :=CubicBezierPath {};_dc .Curves =[]CubicBezierCurve {};for _ ,_ddg :=range _cd .Curves {_dc .Curves =append (_dc .Curves ,_ddg );};return _dc ;};
|
||||
|
||||
// Add shifts the coordinates of the point with dx, dy and returns the result.
|
||||
func (_ae Point )Add (dx ,dy float64 )Point {_ae .X +=dx ;_ae .Y +=dy ;return _ae };
|
||||
|
||||
// NewVectorBetween returns a new vector with the direction specified by
|
||||
// the subtraction of point a from point b (b-a).
|
||||
func NewVectorBetween (a Point ,b Point )Vector {_dad :=Vector {};_dad .Dx =b .X -a .X ;_dad .Dy =b .Y -a .Y ;return _dad ;};
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_acf :=Vector {};_acf .Dx =dx ;_acf .Dy =dy ;return _acf };
|
||||
|
||||
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
|
||||
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
|
||||
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
|
||||
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
|
||||
// if one occurred.
|
||||
func (_ece Line )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_fdg ,_eg :=_ece .X1 ,_ece .X2 ;_gcf ,_dfa :=_ece .Y1 ,_ece .Y2 ;_bg :=_dfa -_gcf ;_bfbd :=_eg -_fdg ;_abdb :=_ce .Atan2 (_bg ,_bfbd );L :=_ce .Sqrt (_ce .Pow (_bfbd ,2.0)+_ce .Pow (_bg ,2.0));_dac :=_ece .LineWidth ;_ag :=_ce .Pi ;_gbf :=1.0;if _bfbd < 0{_gbf *=-1.0;};if _bg < 0{_gbf *=-1.0;};VsX :=_gbf *(-_dac /2*_ce .Cos (_abdb +_ag /2));VsY :=_gbf *(-_dac /2*_ce .Sin (_abdb +_ag /2)+_dac *_ce .Sin (_abdb +_ag /2));V1X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2);V1Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2);V2X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2)+L *_ce .Cos (_abdb );V2Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2)+L *_ce .Sin (_abdb );V3X :=VsX +_dac /2*_ce .Cos (_abdb +_ag /2)+L *_ce .Cos (_abdb )+_dac *_ce .Cos (_abdb -_ag /2);V3Y :=VsY +_dac /2*_ce .Sin (_abdb +_ag /2)+L *_ce .Sin (_abdb )+_dac *_ce .Sin (_abdb -_ag /2);V4X :=VsX +_dac /2*_ce .Cos (_abdb -_ag /2);V4Y :=VsY +_dac /2*_ce .Sin (_abdb -_ag /2);_abg :=NewPath ();_abg =_abg .AppendPoint (NewPoint (V1X ,V1Y ));_abg =_abg .AppendPoint (NewPoint (V2X ,V2Y ));_abg =_abg .AppendPoint (NewPoint (V3X ,V3Y ));_abg =_abg .AppendPoint (NewPoint (V4X ,V4Y ));_fdd :=_ece .LineEndingStyle1 ;_eeac :=_ece .LineEndingStyle2 ;_fff :=3*_dac ;_egf :=3*_dac ;_eae :=(_egf -_dac )/2;if _eeac ==LineEndingStyleArrow {_egfc :=_abg .GetPointNumber (2);_bfg :=NewVectorPolar (_fff ,_abdb +_ag );_egc :=_egfc .AddVector (_bfg );_gda :=NewVectorPolar (_egf /2,_abdb +_ag /2);_cdae :=NewVectorPolar (_fff ,_abdb );_ceff :=NewVectorPolar (_eae ,_abdb +_ag /2);_abb :=_egc .AddVector (_ceff );_fgd :=_cdae .Add (_gda .Flip ());_cae :=_abb .AddVector (_fgd );_bgc :=_gda .Scale (2).Flip ().Add (_fgd .Flip ());_dab :=_cae .AddVector (_bgc );_ede :=_egc .AddVector (NewVectorPolar (_dac ,_abdb -_ag /2));_dfge :=NewPath ();_dfge =_dfge .AppendPoint (_abg .GetPointNumber (1));_dfge =_dfge .AppendPoint (_egc );_dfge =_dfge .AppendPoint (_abb );_dfge =_dfge .AppendPoint (_cae );_dfge =_dfge .AppendPoint (_dab );_dfge =_dfge .AppendPoint (_ede );_dfge =_dfge .AppendPoint (_abg .GetPointNumber (4));_abg =_dfge ;};if _fdd ==LineEndingStyleArrow {_ecd :=_abg .GetPointNumber (1);_geb :=_abg .GetPointNumber (_abg .Length ());_ebba :=NewVectorPolar (_dac /2,_abdb +_ag +_ag /2);_fggb :=_ecd .AddVector (_ebba );_fdc :=NewVectorPolar (_fff ,_abdb ).Add (NewVectorPolar (_egf /2,_abdb +_ag /2));_adb :=_fggb .AddVector (_fdc );_eaa :=NewVectorPolar (_eae ,_abdb -_ag /2);_bdg :=_adb .AddVector (_eaa );_dfe :=NewVectorPolar (_fff ,_abdb );_dg :=_geb .AddVector (_dfe );_gfc :=NewVectorPolar (_eae ,_abdb +_ag +_ag /2);_eec :=_dg .AddVector (_gfc );_fbg :=_fggb ;_eag :=NewPath ();_eag =_eag .AppendPoint (_fggb );_eag =_eag .AppendPoint (_adb );_eag =_eag .AppendPoint (_bdg );for _ ,_ba :=range _abg .Points [1:len (_abg .Points )-1]{_eag =_eag .AppendPoint (_ba );};_eag =_eag .AppendPoint (_dg );_eag =_eag .AppendPoint (_eec );_eag =_eag .AppendPoint (_fbg );_abg =_eag ;};_gg :=_fb .NewContentCreator ();_gg .Add_q ().Add_rg (_ece .LineColor .R (),_ece .LineColor .G (),_ece .LineColor .B ());if len (gsName )> 1{_gg .Add_gs (_a .PdfObjectName (gsName ));};_abg =_abg .Offset (_ece .X1 ,_ece .Y1 );_efe :=_abg .GetBoundingBox ();DrawPathWithCreator (_abg ,_gg );if _ece .LineStyle ==LineStyleDashed {_gg .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_gg .Add_f ().Add_Q ();};return _gg .Bytes (),_efe .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_gde Vector )Scale (factor float64 )Vector {_bfbc :=_gde .Magnitude ();_ddc :=_gde .GetPolarAngle ();_gde .Dx =factor *_bfbc *_ce .Cos (_ddc );_gde .Dy =factor *_bfbc *_ce .Sin (_ddc );return _gde ;};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_cf .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_bf BoundingBox )ToPdfRectangle ()*_cf .PdfRectangle {return &_cf .PdfRectangle {Llx :_bf .X ,Lly :_bf .Y ,Urx :_bf .X +_bf .Width ,Ury :_bf .Y +_bf .Height };};
|
||||
|
||||
// PolyBezierCurve represents a composite curve that is the result of
|
||||
// joining multiple cubic Bezier curves.
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_cf .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_cf .PdfColorDeviceRGB ;};
|
||||
|
||||
// Offset shifts the Bezier path with the specified offsets.
|
||||
func (_be CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _aa ,_ge :=range _be .Curves {_be .Curves [_aa ]=_ge .AddOffsetXY (offX ,offY );};return _be ;};
|
||||
|
||||
// DrawBezierPathWithCreator makes the bezier path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_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 );};};
|
||||
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_fb .ContentCreator ){for _fdb ,_fbf :=range bpath .Curves {if _fdb ==0{creator .Add_m (_fbf .P0 .X ,_fbf .P0 .Y );};creator .Add_c (_fbf .P1 .X ,_fbf .P1 .Y ,_fbf .P2 .X ,_fbf .P2 .Y ,_fbf .P3 .X ,_fbf .P3 .Y );};};
|
||||
|
||||
// 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 ;};
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_de :=CubicBezierPath {};_de .Curves =[]CubicBezierCurve {};return _de ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_deed Rectangle )ToPdfRectangle ()*_cf .PdfRectangle {return &_cf .PdfRectangle {Llx :_deed .X ,Lly :_deed .Y ,Urx :_deed .X +_deed .Width ,Ury :_deed .Y +_deed .Height };};
|
||||
|
||||
// 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 ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
|
||||
// Point represents a two-dimensional point.
|
||||
type Point struct{X float64 ;Y float64 ;};
|
||||
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
|
||||
func (_dda Rectangle )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_dbb :=NewPath ();_dbb =_dbb .AppendPoint (NewPoint (0,0));_dbb =_dbb .AppendPoint (NewPoint (0,_dda .Height ));_dbb =_dbb .AppendPoint (NewPoint (_dda .Width ,_dda .Height ));_dbb =_dbb .AppendPoint (NewPoint (_dda .Width ,0));_dbb =_dbb .AppendPoint (NewPoint (0,0));if _dda .X !=0||_dda .Y !=0{_dbb =_dbb .Offset (_dda .X ,_dda .Y );};_eac :=_fb .NewContentCreator ();_eac .Add_q ();if _dda .FillEnabled {_eac .Add_rg (_dda .FillColor .R (),_dda .FillColor .G (),_dda .FillColor .B ());};if _dda .BorderEnabled {_eac .Add_RG (_dda .BorderColor .R (),_dda .BorderColor .G (),_dda .BorderColor .B ());_eac .Add_w (_dda .BorderWidth );};if len (gsName )> 1{_eac .Add_gs (_a .PdfObjectName (gsName ));};DrawPathWithCreator (_dbb ,_eac );_eac .Add_h ();if _dda .FillEnabled &&_dda .BorderEnabled {_eac .Add_B ();}else if _dda .FillEnabled {_eac .Add_f ();}else if _dda .BorderEnabled {_eac .Add_S ();};_eac .Add_Q ();return _eac .Bytes (),_dbb .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// CubicBezierCurve is defined by:
|
||||
// R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3
|
||||
// where P0 is the current point, P1, P2 control points and P3 the final point.
|
||||
type CubicBezierCurve struct{P0 Point ;P1 Point ;P2 Point ;P3 Point ;};
|
||||
|
||||
// Draw draws the 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 (_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 ;};
|
||||
// Draw draws the circle. Can specify a graphics state (gsName) for setting opacity etc. Otherwise leave empty ("").
|
||||
// Returns the content stream as a byte array, the bounding box and an error on failure.
|
||||
func (_gc Circle )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_def :=_gc .Width /2;_ddf :=_gc .Height /2;if _gc .BorderEnabled {_def -=_gc .BorderWidth /2;_ddf -=_gc .BorderWidth /2;};_adf :=0.551784;_aab :=_def *_adf ;_cda :=_ddf *_adf ;_eea :=NewCubicBezierPath ();_eea =_eea .AppendCurve (NewCubicBezierCurve (-_def ,0,-_def ,_cda ,-_aab ,_ddf ,0,_ddf ));_eea =_eea .AppendCurve (NewCubicBezierCurve (0,_ddf ,_aab ,_ddf ,_def ,_cda ,_def ,0));_eea =_eea .AppendCurve (NewCubicBezierCurve (_def ,0,_def ,-_cda ,_aab ,-_ddf ,0,-_ddf ));_eea =_eea .AppendCurve (NewCubicBezierCurve (0,-_ddf ,-_aab ,-_ddf ,-_def ,-_cda ,-_def ,0));_eea =_eea .Offset (_def ,_ddf );if _gc .BorderEnabled {_eea =_eea .Offset (_gc .BorderWidth /2,_gc .BorderWidth /2);};if _gc .X !=0||_gc .Y !=0{_eea =_eea .Offset (_gc .X ,_gc .Y );};_acb :=_fb .NewContentCreator ();_acb .Add_q ();if _gc .FillEnabled {_acb .Add_rg (_gc .FillColor .R (),_gc .FillColor .G (),_gc .FillColor .B ());};if _gc .BorderEnabled {_acb .Add_RG (_gc .BorderColor .R (),_gc .BorderColor .G (),_gc .BorderColor .B ());_acb .Add_w (_gc .BorderWidth );};if len (gsName )> 1{_acb .Add_gs (_a .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_eea ,_acb );_acb .Add_h ();if _gc .FillEnabled &&_gc .BorderEnabled {_acb .Add_B ();}else if _gc .FillEnabled {_acb .Add_f ();}else if _gc .BorderEnabled {_acb .Add_S ();};_acb .Add_Q ();_gdg :=_eea .GetBoundingBox ();if _gc .BorderEnabled {_gdg .Height +=_gc .BorderWidth ;_gdg .Width +=_gc .BorderWidth ;_gdg .X -=_gc .BorderWidth /2;_gdg .Y -=_gc .BorderWidth /2;};return _acb .Bytes (),_gdg .ToPdfRectangle (),nil ;};
|
||||
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_e .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_e .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
|
||||
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
|
||||
// Offset shifts the 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 ;};
|
||||
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
|
||||
// or arrows at either end. The line also has a specified width, color and opacity.
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_cf .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// 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 ;};
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_dbd :=Vector {};_dbd .Dx =length *_ce .Cos (theta );_dbd .Dy =length *_ce .Sin (theta );return _dbd ;};
|
||||
|
||||
// CubicBezierPath represents a collection of cubic Bezier curves.
|
||||
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
|
||||
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_ffg Vector )Add (other Vector )Vector {_ffg .Dx +=other .Dx ;_ffg .Dy +=other .Dy ;return _ffg };
|
||||
|
||||
// Length returns the number of points in the path.
|
||||
func (_fd Path )Length ()int {return len (_fd .Points )};
|
||||
|
||||
// DrawPathWithCreator makes the path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawPathWithCreator (path Path ,creator *_fb .ContentCreator ){for _dgc ,_fba :=range path .Points {if _dgc ==0{creator .Add_m (_fba .X ,_fba .Y );}else {creator .Add_l (_fba .X ,_fba .Y );};};};
|
||||
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_ec Path )RemovePoint (number int )Path {if number < 1||number > len (_ec .Points ){return _ec ;};_bcg :=number -1;_ec .Points =append (_ec .Points [:_bcg ],_ec .Points [_bcg +1:]...);return _ec ;};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_gd Path )GetPointNumber (number int )Point {if number < 1||number > len (_gd .Points ){return Point {};};return _gd .Points [number -1];};
|
||||
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
||||
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_bgb Vector )GetPolarAngle ()float64 {return _ce .Atan2 (_bgb .Dy ,_bgb .Dx )};
|
||||
|
||||
// Draw draws the polygon. A graphics state name can be specified for
|
||||
// setting the polygon properties (e.g. setting the opacity). Otherwise leave
|
||||
// empty (""). Returns the content stream as a byte array and the polygon
|
||||
// bounding box.
|
||||
func (_fga Polygon )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){_gca :=_fb .NewContentCreator ();_gca .Add_q ();_fga .FillEnabled =_fga .FillEnabled &&_fga .FillColor !=nil ;if _fga .FillEnabled {_gca .Add_rg (_fga .FillColor .R (),_fga .FillColor .G (),_fga .FillColor .B ());};_fga .BorderEnabled =_fga .BorderEnabled &&_fga .BorderColor !=nil ;if _fga .BorderEnabled {_gca .Add_RG (_fga .BorderColor .R (),_fga .BorderColor .G (),_fga .BorderColor .B ());_gca .Add_w (_fga .BorderWidth );};if len (gsName )> 1{_gca .Add_gs (_a .PdfObjectName (gsName ));};_abd :=NewPath ();for _ ,_gcb :=range _fga .Points {for _cdf ,_efc :=range _gcb {_abd =_abd .AppendPoint (_efc );if _cdf ==0{_gca .Add_m (_efc .X ,_efc .Y );}else {_gca .Add_l (_efc .X ,_efc .Y );};};_gca .Add_h ();};if _fga .FillEnabled &&_fga .BorderEnabled {_gca .Add_B ();}else if _fga .FillEnabled {_gca .Add_f ();}else if _fga .BorderEnabled {_gca .Add_S ();};_gca .Add_Q ();return _gca .Bytes (),_abd .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// Draw draws the composite Bezier curve. A graphics state name can be
|
||||
// specified for setting the curve properties (e.g. setting the opacity).
|
||||
// Otherwise leave empty (""). Returns the content stream as a byte array and
|
||||
// the curve bounding box.
|
||||
func (_dfg PolyBezierCurve )Draw (gsName string )([]byte ,*_cf .PdfRectangle ,error ){if _dfg .BorderColor ==nil {_dfg .BorderColor =_cf .NewPdfColorDeviceRGB (0,0,0);};_eab :=NewCubicBezierPath ();for _ ,_dee :=range _dfg .Curves {_eab =_eab .AppendCurve (_dee );};_ab :=_fb .NewContentCreator ();_ab .Add_q ();_dfg .FillEnabled =_dfg .FillEnabled &&_dfg .FillColor !=nil ;if _dfg .FillEnabled {_ab .Add_rg (_dfg .FillColor .R (),_dfg .FillColor .G (),_dfg .FillColor .B ());};_ab .Add_RG (_dfg .BorderColor .R (),_dfg .BorderColor .G (),_dfg .BorderColor .B ());_ab .Add_w (_dfg .BorderWidth );if len (gsName )> 1{_ab .Add_gs (_a .PdfObjectName (gsName ));};for _ ,_bfb :=range _eab .Curves {_ab .Add_m (_bfb .P0 .X ,_bfb .P0 .Y );_ab .Add_c (_bfb .P1 .X ,_bfb .P1 .Y ,_bfb .P2 .X ,_bfb .P2 .Y ,_bfb .P3 .X ,_bfb .P3 .Y );};if _dfg .FillEnabled {_ab .Add_h ();_ab .Add_B ();}else {_ab .Add_S ();};_ab .Add_Q ();return _ab .Bytes (),_eab .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// LineStyle refers to how the line will be created.
|
||||
type LineStyle int ;
|
||||
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_cab Path )AppendPoint (point Point )Path {_cab .Points =append (_cab .Points ,point );return _cab };
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_ebbd Vector )FlipX ()Vector {_ebbd .Dx =-_ebbd .Dx ;return _ebbd };
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_gee Vector )Flip ()Vector {_ebe :=_gee .Magnitude ();_ffae :=_gee .GetPolarAngle ();_gee .Dx =_ebe *_ce .Cos (_ffae +_ce .Pi );_gee .Dy =_ebe *_ce .Sin (_ffae +_ce .Pi );return _gee ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_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 ;};
|
||||
func (_cgb Path )GetBoundingBox ()BoundingBox {_ef :=BoundingBox {};_gf :=0.0;_caf :=0.0;_bd :=0.0;_ed :=0.0;for _ffa ,_fa :=range _cgb .Points {if _ffa ==0{_gf =_fa .X ;_caf =_fa .X ;_bd =_fa .Y ;_ed =_fa .Y ;continue ;};if _fa .X < _gf {_gf =_fa .X ;};if _fa .X > _caf {_caf =_fa .X ;};if _fa .Y < _bd {_bd =_fa .Y ;};if _fa .Y > _ed {_ed =_fa .Y ;};};_ef .X =_gf ;_ef .Y =_bd ;_ef .Width =_caf -_gf ;_ef .Height =_ed -_bd ;return _ef ;};
|
||||
|
||||
// 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 ;};
|
||||
// Point represents a two-dimensional point.
|
||||
type Point struct{X float64 ;Y float64 ;};
|
||||
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_cdc Point )Rotate (theta float64 )Point {_fc :=_d .NewPoint (_cdc .X ,_cdc .Y ).Rotate (theta );return NewPoint (_fc .X ,_fc .Y );};
|
||||
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_ebeg Vector )FlipY ()Vector {_ebeg .Dy =-_ebeg .Dy ;return _ebeg };
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_fg CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_fg .Curves =append (_fg .Curves ,curve );return _fg ;};
|
||||
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_def :=CubicBezierPath {};_def .Curves =[]CubicBezierCurve {};return _def ;};
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_fbc CubicBezierPath )GetBoundingBox ()Rectangle {_bb :=Rectangle {};_cg :=0.0;_eb :=0.0;_gb :=0.0;_ac :=0.0;for _cea ,_da :=range _fbc .Curves {_gbb :=_da .GetBounds ();if _cea ==0{_cg =_gbb .Llx ;_eb =_gbb .Urx ;_gb =_gbb .Lly ;_ac =_gbb .Ury ;continue ;};if _gbb .Llx < _cg {_cg =_gbb .Llx ;};if _gbb .Urx > _eb {_eb =_gbb .Urx ;};if _gbb .Lly < _gb {_gb =_gbb .Lly ;};if _gbb .Ury > _ac {_ac =_gbb .Ury ;};};_bb .X =_cg ;_bb .Y =_gb ;_bb .Width =_eb -_cg ;_bb .Height =_ac -_gb ;return _bb ;};
|
1656
core/core.go
1656
core/core.go
File diff suppressed because one or more lines are too long
@ -9,61 +9,67 @@
|
||||
// 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 (_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 )};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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};
|
||||
|
||||
// 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 (_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 ;};
|
||||
package crypt ;import (_d "crypto/aes";_ed "crypto/cipher";_b "crypto/md5";_dc "crypto/rand";_fd "crypto/rc4";_a "fmt";_fb "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/core/security";_f "io";);func init (){_cfa ("\u0041\u0045\u0053V\u0032",_g )};func _fe (_gf FilterDict )(Filter ,error ){if _gf .Length ==256{_fb .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_gf .Length );_gf .Length /=8;};if _gf .Length !=0&&_gf .Length !=32{return nil ,_a .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_gf .Length );};return filterAESV3 {},nil ;};
|
||||
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _e .AuthEvent ;Length int ;};
|
||||
type FilterDict struct{CFM string ;AuthEvent _ec .AuthEvent ;Length int ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};type filterAESV3 struct{filterAES };
|
||||
|
||||
// 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};
|
||||
// KeyLength implements Filter interface.
|
||||
func (_bba filterV2 )KeyLength ()int {return _bba ._feba };func _db (_eg ,_feb uint32 ,_gdc []byte ,_efe bool )([]byte ,error ){_cgg :=make ([]byte ,len (_gdc )+5);for _ee :=0;_ee < len (_gdc );_ee ++{_cgg [_ee ]=_gdc [_ee ];};for _efg :=0;_efg < 3;_efg ++{_fce :=byte ((_eg >>uint32 (8*_efg ))&0xff);_cgg [_efg +len (_gdc )]=_fce ;};for _gfa :=0;_gfa < 2;_gfa ++{_bcc :=byte ((_feb >>uint32 (8*_gfa ))&0xff);_cgg [_gfa +len (_gdc )+3]=_bcc ;};if _efe {_cgg =append (_cgg ,0x73);_cgg =append (_cgg ,0x41);_cgg =append (_cgg ,0x6C);_cgg =append (_cgg ,0x54);};_egb :=_b .New ();_egb .Write (_cgg );_gff :=_egb .Sum (nil );if len (_gdc )+5< 16{return _gff [0:len (_gdc )+5],nil ;};return _gff ,nil ;};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
|
||||
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_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{};
|
||||
func NewFilterV2 (length int )Filter {_dad ,_ecb :=_ffg (FilterDict {Length :length });if _ecb !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ecb );return filterV2 {_feba :length };};return _dad ;};type filterAES struct{};func init (){_cfa ("\u0041\u0045\u0053V\u0033",_fe )};type filterFunc func (_aac FilterDict )(Filter ,error );func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fc ,_ab :=_d .NewCipher (okey );if _ab !=nil {return nil ,_ab ;};_fb .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _c =_d .BlockSize ;_ae :=_c -len (buf )%_c ;for _ff :=0;_ff < _ae ;_ff ++{buf =append (buf ,byte (_ae ));};_fb .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_cg :=make ([]byte ,_c +len (buf ));_gd :=_cg [:_c ];if _ ,_eda :=_f .ReadFull (_dc .Reader ,_gd );_eda !=nil {return nil ,_eda ;};_bg :=_ed .NewCBCEncrypter (_fc ,_gd );_bg .CryptBlocks (_cg [_c :],buf );buf =_cg ;_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterV2 )Name ()string {return "\u0056\u0032"};
|
||||
|
||||
// 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 };
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_ba ,_bd :=_fe (FilterDict {});if _bd !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_bd );return filterAESV3 {};};return _ba ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};var (_faf =make (map[string ]filterFunc ););
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};func (filterIdentity )KeyLength ()int {return 0};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};var (_gdf =make (map[string ]filterFunc ););type filterAESV2 struct{filterAES };
|
||||
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_bf ,_ef :=_g (FilterDict {});if _ef !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ef );return filterAESV2 {};};return _bf ;};var _ Filter =filterAESV3 {};func init (){_cfa ("\u0056\u0032",_ffg )};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
|
||||
|
||||
// NewIdentity creates an identity filter that bypasses all data without changes.
|
||||
func NewIdentity ()Filter {return filterIdentity {}};
|
||||
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bab ,_add :=_fd .NewCipher (okey );if _add !=nil {return nil ,_add ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bab .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _cfa (_ebe string ,_dcf filterFunc ){if _ ,_ea :=_gdf [_ebe ];_ea {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_gdf [_ebe ]=_dcf ;};type filterV2 struct{_feba int };func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV3 )KeyLength ()int {return 256/8};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
|
||||
|
||||
// DecryptBytes implements Filter interface.
|
||||
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bbe ,_fcc :=_fd .NewCipher (okey );if _fcc !=nil {return nil ,_fcc ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bbe .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};var _ Filter =filterAESV2 {};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};func _bde (_ca string )(filterFunc ,error ){_dg :=_gdf [string (_ca )];if _dg ==nil {return nil ,_a .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_ca );};return _dg ,nil ;};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _db (objNum ,genNum ,ekey ,true );};
|
||||
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_cf ,_bdg :=_bde (d .CFM );if _bdg !=nil {return nil ,_bdg ;};_aec ,_bdg :=_cf (d );if _bdg !=nil {return nil ,_bdg ;};return _aec ,nil ;};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (_ddad filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _db (objNum ,genNum ,ekey ,false );};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (_dda filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
|
||||
// Filter is a common interface for crypt filter methods.
|
||||
type Filter interface{
|
||||
@ -82,27 +88,21 @@ 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 (_fb ,_acg uint32 ,_gfdc []byte )([]byte ,error );
|
||||
MakeKey (_ac ,_ag uint32 ,_fea []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 (_dd []byte ,_eg []byte )([]byte ,error );
|
||||
EncryptBytes (_fef []byte ,_abf []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 (_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 {};
|
||||
DecryptBytes (_aacb []byte ,_abg []byte )([]byte ,error );};
|
||||
|
||||
// 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"};
|
||||
// PDFVersion implements Filter interface.
|
||||
func (_gcf filterV2 )PDFVersion ()[2]int {return [2]int {}};func _ffg (_fff FilterDict )(Filter ,error ){if _fff .Length %8!=0{return nil ,_a .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_fff .Length );};if _fff .Length < 5||_fff .Length > 16{if _fff .Length ==40||_fff .Length ==64||_fff .Length ==128{_fb .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_fff .Length );_fff .Length /=8;}else {return nil ,_a .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_fff .Length );};};return filterV2 {_feba :_fff .Length },nil ;};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};type filterIdentity struct{};
|
||||
|
||||
// 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 ;};
|
||||
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };var _ Filter =filterV2 {};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ecc ,_eb :=_d .NewCipher (okey );if _eb !=nil {return nil ,_eb ;};if len (buf )< 16{_fb .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_a .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_da :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_fb .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_da ),_da );_fb .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_a .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_gc :=_ed .NewCBCDecrypter (_ecc ,_da );_fb .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_fb .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_gc .CryptBlocks (buf ,buf );_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_fb .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_ad :=int (buf [len (buf )-1]);if _ad > len (buf ){_fb .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_ad ,len (buf ));return buf ,_a .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ad ];return buf ,nil ;};func _g (_bb FilterDict )(Filter ,error ){if _bb .Length ==128{_fb .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_bb .Length );_bb .Length /=8;};if _bb .Length !=0&&_bb .Length !=16{return nil ,_a .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_bb .Length );};return filterAESV2 {},nil ;};
|
File diff suppressed because one or more lines are too long
2458
creator/creator.go
2458
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
30
fdf/fdf.go
30
fdf/fdf.go
File diff suppressed because one or more lines are too long
@ -10,28 +10,28 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package fjson provides support for loading PDF form field data from JSON data/files.
|
||||
package fjson ;import (_e "encoding/json";_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{_a []fieldValue };
|
||||
|
||||
// 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 );};
|
||||
package fjson ;import (_f "encoding/json";_ge "github.com/unidoc/unipdf/v3/core";_geg "github.com/unidoc/unipdf/v3/model";_g "io";_c "os";);
|
||||
|
||||
// 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 );};
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_gd ,_fb :=_c .Open (filePath );if _fb !=nil {return nil ,_fb ;};defer _gd .Close ();return LoadFromJSON (_gd );};
|
||||
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_fd ,_gdb :=_c .Open (filePath );if _gdb !=nil {return nil ,_gdb ;};defer _fd .Close ();return LoadFromPDF (_fd );};
|
||||
|
||||
// JSON returns the field data as a string in JSON format.
|
||||
func (_egb FieldData )JSON ()(string ,error ){_cd ,_fd :=_e .MarshalIndent (_egb ._a ,"","\u0020\u0020\u0020\u0020");return string (_cd ),_fd ;};
|
||||
func (_gb FieldData )JSON ()(string ,error ){_eaf ,_dce :=_f .MarshalIndent (_gb ._a ,"","\u0020\u0020\u0020\u0020");return string (_eaf ),_dce ;};
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _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 ;};
|
||||
func LoadFromPDF (rs _g .ReadSeeker )(*FieldData ,error ){_ca ,_cf :=_geg .NewPdfReader (rs );if _cf !=nil {return nil ,_cf ;};if _ca .AcroForm ==nil {return nil ,nil ;};var _b []fieldValue ;_ad :=_ca .AcroForm .AllFields ();for _ ,_be :=range _ad {var _ed []string ;_ec :=make (map[string ]struct{});_ae ,_aeg :=_be .FullName ();if _aeg !=nil {return nil ,_aeg ;};if _ef ,_cg :=_be .V .(*_ge .PdfObjectString );_cg {_b =append (_b ,fieldValue {Name :_ae ,Value :_ef .Decoded ()});continue ;};var _gg string ;for _ ,_fbb :=range _be .Annotations {_ga ,_eaa :=_ge .GetName (_fbb .AS );if _eaa {_gg =_ga .String ();};_d ,_ggg :=_ge .GetDict (_fbb .AP );if !_ggg {continue ;};_de ,_ :=_ge .GetDict (_d .Get ("\u004e"));for _ ,_eg :=range _de .Keys (){_dc :=_eg .String ();if _ ,_bg :=_ec [_dc ];!_bg {_ed =append (_ed ,_dc );_ec [_dc ]=struct{}{};};};_gag ,_ :=_ge .GetDict (_d .Get ("\u0044"));for _ ,_gggd :=range _gag .Keys (){_bbf :=_gggd .String ();if _ ,_abg :=_ec [_bbf ];!_abg {_ed =append (_ed ,_bbf );_ec [_bbf ]=struct{}{};};};};_adb :=fieldValue {Name :_ae ,Value :_gg ,Options :_ed };_b =append (_b ,_adb );};_ee :=FieldData {_a :_b };return &_ee ,nil ;};
|
||||
|
||||
// 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 ;};
|
||||
func LoadFromJSON (r _g .Reader )(*FieldData ,error ){var _ea FieldData ;_ab :=_f .NewDecoder (r ).Decode (&_ea ._a );if _ab !=nil {return nil ,_ab ;};return &_ea ,nil ;};
|
||||
|
||||
// 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"`;
|
||||
func (_abgg *FieldData )FieldValues ()(map[string ]_ge .PdfObject ,error ){_ggc :=make (map[string ]_ge .PdfObject );for _ ,_ac :=range _abgg ._a {if len (_ac .Value )> 0{_ggc [_ac .Name ]=_ge .MakeString (_ac .Value );};};return _ggc ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
||||
Options []string `json:"options,omitempty"`;};
|
||||
|
||||
// FieldData represents form field data loaded from JSON file.
|
||||
type FieldData struct{_a []fieldValue };
|
10
go.mod
10
go.mod
@ -3,15 +3,15 @@ module github.com/unidoc/unipdf/v3
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/adrg/sysfont v0.1.0
|
||||
github.com/adrg/sysfont v0.1.1
|
||||
github.com/boombuler/barcode v1.0.0
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||
github.com/stretchr/testify v1.6.1
|
||||
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df
|
||||
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a
|
||||
github.com/unidoc/unitype v0.2.0
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b
|
||||
golang.org/x/text v0.3.2
|
||||
github.com/unidoc/unitype v0.2.1
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0
|
||||
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5
|
||||
golang.org/x/text v0.3.3
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1
|
||||
)
|
||||
|
15
go.sum
15
go.sum
@ -1,5 +1,5 @@
|
||||
github.com/adrg/strutil v0.1.0/go.mod h1:pXRr2+IyX5AEPAF5icj/EeTaiflPSD2hvGjnguilZgE=
|
||||
github.com/adrg/sysfont v0.1.0/go.mod h1:DzISco90USPZJ+lmtpuz1SOTn1fih6YyB0KG2TEP/0U=
|
||||
github.com/adrg/sysfont v0.1.1/go.mod h1:19nTHzfIn/HbngFMet+yNAvwSQYtOJYMI7vWexLWyNw=
|
||||
github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ=
|
||||
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
@ -22,12 +22,12 @@ github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8=
|
||||
github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw=
|
||||
github.com/unidoc/unitype v0.2.0 h1:N+ZKjwz8UDU0qa1IYzstDLffvQEctFo+bo6b6ZqW+9M=
|
||||
github.com/unidoc/unitype v0.2.0/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU=
|
||||
github.com/unidoc/unitype v0.2.1 h1:x0jMn7pB/tNrjEVjy3Ukpxo++HOBQaTCXcTYFA6BH3w=
|
||||
github.com/unidoc/unitype v0.2.1/go.mod h1:mafyug7zYmDOusqa7G0dJV45qp4b6TDAN+pHN7ZUIBU=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
|
||||
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
|
||||
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
|
||||
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
@ -35,8 +35,9 @@ golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4 h1:opSr2sbRXk5X5/givKrrKj9HXxFpW2sdCiP8MJSKLQY=
|
||||
golang.org/x/sys v0.0.0-20200413165638-669c56c373c4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
|
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 (_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 ;);
|
||||
package endian ;import (_e "encoding/binary";_bb "unsafe";);func IsBig ()bool {return _g };func init (){const _d =int (_bb .Sizeof (0));_c :=1;_dg :=(*[_d ]byte )(_bb .Pointer (&_c ));if _dg [0]==0{_g =true ;ByteOrder =_e .BigEndian ;}else {ByteOrder =_e .LittleEndian ;};};func IsLittle ()bool {return !_g };var (ByteOrder _e .ByteOrder ;_g bool ;);
|
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 _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 ;};
|
||||
package basic ;import _b "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func NewIntSlice (i int )*IntSlice {_ca :=IntSlice (make ([]int ,i ));return &_ca };func (_ac *Stack )Pop ()(_fed interface{},_bf bool ){_fed ,_bf =_ac .peek ();if !_bf {return nil ,_bf ;};_ac .Data =_ac .Data [:_ac .top ()];return _fed ,true ;};func (_ce *Stack )peek ()(interface{},bool ){_ddb :=_ce .top ();if _ddb ==-1{return nil ,false ;};return _ce .Data [_ddb ],true ;};func (_fea *IntSlice )Copy ()*IntSlice {_e :=IntSlice (make ([]int ,len (*_fea )));copy (_e ,*_fea );return &_e ;};func NewNumSlice (i int )*NumSlice {_gc :=NumSlice (make ([]float32 ,i ));return &_gc };func (_bg *NumSlice )Add (v float32 ){*_bg =append (*_bg ,v )};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_ag IntSlice )Size ()int {return len (_ag )};type Stack struct{Data []interface{};Aux *Stack ;};func (_dg *Stack )top ()int {return len (_dg .Data )-1};type NumSlice []float32 ;type IntsMap map[uint64 ][]int ;func (_ggd NumSlice )GetInt (i int )(int ,error ){const _be ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_ggd )-1{return 0,_b .Errorf (_be ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_ddg :=_ggd [i ];return int (_ddg +Sign (_ddg )*0.5),nil ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_a IntsMap )Add (key uint64 ,value int ){_a [key ]=append (_a [key ],value )};type IntSlice []int ;func (_aa NumSlice )GetIntSlice ()[]int {_ab :=make ([]int ,len (_aa ));for _ff ,_cd :=range _aa {_ab [_ff ]=int (_cd );};return _ab ;};func (_dd IntSlice )Get (index int )(int ,error ){if index > len (_dd )-1{return 0,_b .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _dd [index ],nil ;};func (_bgf NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_bgf )-1{return 0,_b .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _bgf [i ],nil ;};func (_ebe *Stack )Push (v interface{}){_ebe .Data =append (_ebe .Data ,v )};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_ae *IntSlice )Add (v int )error {if _ae ==nil {return _b .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_ae =append (*_ae ,v );return nil ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_c IntsMap )Get (key uint64 )(int ,bool ){_g ,_gg :=_c [key ];if !_gg {return 0,false ;};if len (_g )==0{return 0,false ;};return _g [0],true ;};func (_aae *Stack )Peek ()(_aga interface{},_eb bool ){return _aae .peek ()};func (_fg *Stack )Len ()int {return len (_fg .Data )};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_cb *NumSlice )AddInt (v int ){*_cb =append (*_cb ,float32 (v ))};func (_fe IntsMap )Delete (key uint64 ){delete (_fe ,key )};func (_d IntsMap )GetSlice (key uint64 )([]int ,bool ){_ad ,_bb :=_d [key ];if !_bb {return nil ,false ;};return _ad ,true ;};
|
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 (_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 ;};
|
||||
package decoder ;import (_a "github.com/unidoc/unipdf/v3/internal/bitwise";_e "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_b "github.com/unidoc/unipdf/v3/internal/jbig2/document";_g "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";);func (_cd *Decoder )decodePage (_aae int )([]byte ,error ){const _fa ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _aae < 0{return nil ,_g .Errorf (_fa ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_aae );};if _aae > int (_cd ._ef .NumberOfPages ){return nil ,_g .Errorf (_fa ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_aae );};_cca ,_aac :=_cd ._ef .GetPage (_aae );if _aac !=nil {return nil ,_g .Wrap (_aac ,_fa ,"");};_cda ,_aac :=_cca .GetBitmap ();if _aac !=nil {return nil ,_g .Wrap (_aac ,_fa ,"");};_cda .InverseData ();if !_cd ._de .UnpaddedData {return _cda .Data ,nil ;};return _cda .GetUnpaddedData ();};func (_ea *Decoder )DecodePageImage (pageNumber int )(_d .Image ,error ){const _ae ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_cbg ,_cf :=_ea .decodePageImage (pageNumber );if _cf !=nil {return nil ,_g .Wrap (_cf ,_ae ,"");};return _cbg ,nil ;};func (_f *Decoder )DecodeNextPage ()([]byte ,error ){_f ._cb ++;_cbb :=_f ._cb ;return _f .decodePage (_cbb );};func (_dg *Decoder )PageNumber ()(int ,error ){const _cc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _dg ._ef ==nil {return 0,_g .Error (_cc ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_dg ._ef .NumberOfPages ),nil ;};type Parameters struct{UnpaddedData bool ;Color _e .Color ;};func (_ed *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _ed .decodePage (pageNumber )};type Decoder struct{_aa _a .StreamReader ;_ef *_b .Document ;_cb int ;_de Parameters ;};func Decode (input []byte ,parameters Parameters ,globals *_b .Globals )(*Decoder ,error ){_ac :=_a .NewReader (input );_ff ,_cbbd :=_b .DecodeDocument (_ac ,globals );if _cbbd !=nil {return nil ,_cbbd ;};return &Decoder {_aa :_ac ,_ef :_ff ,_de :parameters },nil ;};func (_ce *Decoder )decodePageImage (_dd int )(_d .Image ,error ){const _dc ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _dd < 0{return nil ,_g .Errorf (_dc ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_dd );};if _dd > int (_ce ._ef .NumberOfPages ){return nil ,_g .Errorf (_dc ,"p\u0061\u0067\u0065\u003a\u0020\u0027%\u0064\u0027\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0069n\u0020\u0074\u0068\u0065\u0020\u0064\u0065\u0063\u006f\u0064e\u0072",_dd );};_deb ,_ceb :=_ce ._ef .GetPage (_dd );if _ceb !=nil {return nil ,_g .Wrap (_ceb ,_dc ,"");};_cg ,_ceb :=_deb .GetBitmap ();if _ceb !=nil {return nil ,_g .Wrap (_ceb ,_dc ,"");};return _cg .ToImage (),nil ;};
|
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 (_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 ;};
|
||||
package errors ;import _c "fmt";type processError struct{_d string ;_b string ;_f string ;_bb error ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _ga ,_ec :=err .(*processError );_ec {_ga ._d ="";};_gaf :=_e (_c .Sprintf (message ,arguments ...),processName );_gaf ._bb =err ;return _gaf ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _e (_c .Sprintf (message ,arguments ...),processName );};func Wrap (err error ,processName ,message string )error {if _bc ,_ac :=err .(*processError );_ac {_bc ._d ="";};_ce :=_e (message ,processName );_ce ._bb =err ;return _ce ;};func (_de *processError )Error ()string {var _da string ;if _de ._d !=""{_da =_de ._d ;};_da +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_de ._b ;if _de ._f !=""{_da +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_de ._f ;};if _de ._bb !=nil {_da +="\u002e\u0020"+_de ._bb .Error ();};return _da ;};func Error (processName ,message string )error {return _e (message ,processName )};func _e (_g ,_cf string )*processError {return &processError {_d :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_f :_g ,_b :_cf };};
|
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package jbig2 ;import (_g "github.com/unidoc/unipdf/v3/internal/bitwise";_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 };};
|
||||
package jbig2 ;import (_b "github.com/unidoc/unipdf/v3/internal/bitwise";_g "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document";_d "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_gb "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_e "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _db ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_dg :=_b .NewReader (encoded );_af ,_ff :=_c .DecodeDocument (_dg ,nil );if _ff !=nil {return nil ,_gb .Wrap (_ff ,_db ,"");};if _af .GlobalSegments ==nil ||(_af .GlobalSegments .Segments ==nil ){return nil ,_gb .Error (_db ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_ad :=Globals {};for _ ,_bf :=range _af .GlobalSegments .Segments {_ad [int (_bf .SegmentNumber )]=_bf ;};return _ad ,nil ;};func DecodeBytes (encoded []byte ,parameters _g .Parameters ,globals ...Globals )([]byte ,error ){var _a Globals ;if len (globals )> 0{_a =globals [0];};_aa ,_fe :=_g .Decode (encoded ,parameters ,_a .ToDocumentGlobals ());if _fe !=nil {return nil ,_fe ;};return _aa .DecodeNextPage ();};func (_gc Globals )ToDocumentGlobals ()*_c .Globals {if _gc ==nil {return nil ;};_de :=[]*_d .Header {};for _ ,_bg :=range _gc {_de =append (_de ,_bg );};_e .Slice (_de ,func (_ag ,_fdf int )bool {return _de [_ag ].SegmentNumber < _de [_fdf ].SegmentNumber });return &_c .Globals {Segments :_de };};type Globals map[int ]*_d .Header ;
|
@ -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 (_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 };};
|
||||
package sampling ;import (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_f "github.com/unidoc/unipdf/v3/internal/imageutil";_b "io";);type Writer struct{_dbc _f .ImageBase ;_ea *_e .Writer ;_cdf ,_fda int ;_beg bool ;};func (_gf *Writer )WriteSample (sample uint32 )error {if _ ,_ead :=_gf ._ea .WriteBits (uint64 (sample ),_gf ._dbc .BitsPerComponent );_ead !=nil {return _ead ;};_gf ._fda --;if _gf ._fda ==0{_gf ._fda =_gf ._dbc .ColorComponents ;_gf ._cdf ++;};if _gf ._cdf ==_gf ._dbc .Width {if _gf ._beg {_gf ._ea .FinishByte ();};_gf ._cdf =0;};return nil ;};func (_fb *Reader )ReadSample ()(uint32 ,error ){if _fb ._cg ==_fb ._g .Height {return 0,_b .EOF ;};_af ,_fa :=_fb ._bg .ReadBits (byte (_fb ._g .BitsPerComponent ));if _fa !=nil {return 0,_fa ;};_fb ._bb --;if _fb ._bb ==0{_fb ._bb =_fb ._g .ColorComponents ;_fb ._be ++;};if _fb ._be ==_fb ._g .Width {if _fb ._gb {_fb ._bg .ConsumeRemainingBits ();};_fb ._be =0;_fb ._cg ++;};return uint32 (_af ),nil ;};type Reader struct{_g _f .ImageBase ;_bg *_e .Reader ;_be ,_cg ,_bb int ;_gb bool ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ce []uint32 ;_ad :=bitsPerSample ;var _fbf uint32 ;var _bd byte ;_eg :=0;_ge :=0;_cge :=0;for _cge < len (data ){if _eg > 0{_d :=_eg ;if _ad < _d {_d =_ad ;};_fbf =(_fbf <<uint (_d ))|uint32 (_bd >>uint (8-_d ));_eg -=_d ;if _eg > 0{_bd =_bd <<uint (_d );}else {_bd =0;};_ad -=_d ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};}else {_ed :=data [_cge ];_cge ++;_ff :=8;if _ad < _ff {_ff =_ad ;};_eg =8-_ff ;_fbf =(_fbf <<uint (_ff ))|uint32 (_ed >>uint (_eg ));if _ff < 8{_bd =_ed <<uint (_ff );};_ad -=_ff ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};};};for _eg >=bitsPerSample {_fab :=_eg ;if _ad < _fab {_fab =_ad ;};_fbf =(_fbf <<uint (_fab ))|uint32 (_bd >>uint (8-_fab ));_eg -=_fab ;if _eg > 0{_bd =_bd <<uint (_fab );}else {_bd =0;};_ad -=_fab ;if _ad ==0{_ce =append (_ce ,_fbf );_ad =bitsPerSample ;_fbf =0;_ge ++;};};return _ce ;};func (_fad *Reader )ReadSamples (samples []uint32 )(_ba error ){for _cd :=0;_cd < len (samples );_cd ++{samples [_cd ],_ba =_fad .ReadSample ();if _ba !=nil {return _ba ;};};return nil ;};func NewWriter (img _f .ImageBase )*Writer {return &Writer {_ea :_e .NewWriterMSB (img .Data ),_dbc :img ,_fda :img .ColorComponents ,_beg :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func NewReader (img _f .ImageBase )*Reader {return &Reader {_bg :_e .NewReader (img .Data ),_g :img ,_bb :img .ColorComponents ,_gb :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _de []uint32 ;_da :=bitsPerOutputSample ;var _bbf uint32 ;var _db uint32 ;_bgg :=0;_cgc :=0;_fd :=0;for _fd < len (data ){if _bgg > 0{_eda :=_bgg ;if _da < _eda {_eda =_da ;};_bbf =(_bbf <<uint (_eda ))|uint32 (_db >>uint (bitsPerInputSample -_eda ));_bgg -=_eda ;if _bgg > 0{_db =_db <<uint (_eda );}else {_db =0;};_da -=_eda ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};}else {_ffe :=data [_fd ];_fd ++;_ede :=bitsPerInputSample ;if _da < _ede {_ede =_da ;};_bgg =bitsPerInputSample -_ede ;_bbf =(_bbf <<uint (_ede ))|uint32 (_ffe >>uint (_bgg ));if _ede < bitsPerInputSample {_db =_ffe <<uint (_ede );};_da -=_ede ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};};};for _bgg >=bitsPerOutputSample {_ef :=_bgg ;if _da < _ef {_ef =_da ;};_bbf =(_bbf <<uint (_ef ))|uint32 (_db >>uint (bitsPerInputSample -_ef ));_bgg -=_ef ;if _bgg > 0{_db =_db <<uint (_ef );}else {_db =0;};_da -=_ef ;if _da ==0{_de =append (_de ,_bbf );_da =bitsPerOutputSample ;_bbf =0;_cgc ++;};};if _da > 0&&_da < bitsPerOutputSample {_bbf <<=uint (_da );_de =append (_de ,_bbf );};return _de ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_c []uint32 )error ;};func (_cdg *Writer )WriteSamples (samples []uint32 )error {for _fg :=0;_fg < len (samples );_fg ++{if _cb :=_cdg .WriteSample (samples [_fg ]);_cb !=nil {return _cb ;};};return nil ;};type SampleWriter interface{WriteSample (_eff uint32 )error ;WriteSamples (_dbg []uint32 )error ;};
|
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
4490
model/model.go
4490
model/model.go
File diff suppressed because one or more lines are too long
@ -9,18 +9,73 @@
|
||||
// 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 optimize ;import (_fgd "bytes";_a "crypto/md5";_fa "errors";_df "fmt";_e "github.com/unidoc/unipdf/v3/common";_b "github.com/unidoc/unipdf/v3/contentstream";_f "github.com/unidoc/unipdf/v3/core";_ab "github.com/unidoc/unipdf/v3/extractor";_dg "github.com/unidoc/unipdf/v3/internal/textencoding";_fb "github.com/unidoc/unipdf/v3/model";_abg "github.com/unidoc/unitype";_fg "golang.org/x/image/draw";_gg "image";_d "math";);func _feg (_fed []_f .PdfObject )(_gc map[*_f .PdfObjectStream ]struct{},_db error ){_gc =map[*_f .PdfObjectStream ]struct{}{};_aac :=map[*_fb .PdfFont ]struct{}{};_faab :=_effb (_fed );for _ ,_dfbg :=range _faab ._gdeb {_ccf ,_bae :=_f .GetDict (_dfbg .PdfObject );if !_bae {continue ;};_af ,_bae :=_f .GetDict (_ccf .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));if !_bae {continue ;};_bda ,_ :=_ecab (_ccf .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_bcd ,_eff :=_fb .NewPdfPageResourcesFromDict (_af );if _eff !=nil {return nil ,_eff ;};_bbc :=[]content {{_fdg :_bda ,_ace :_bcd }};_cba :=_dbf (_ccf .Get ("\u0041\u006e\u006e\u006f\u0074\u0073"));if _cba !=nil {_bbc =append (_bbc ,_cba ...);};for _ ,_cbae :=range _bbc {_gd ,_gdc :=_ab .NewFromContents (_cbae ._fdg ,_cbae ._ace );if _gdc !=nil {return nil ,_gdc ;};_aae ,_ ,_ ,_gdc :=_gd .ExtractPageText ();if _gdc !=nil {return nil ,_gdc ;};for _ ,_bg :=range _aae .Marks ().Elements (){if _bg .Font ==nil {continue ;};if _ ,_cfb :=_aac [_bg .Font ];!_cfb {_aac [_bg .Font ]=struct{}{};};};};};_ad :=map[*_f .PdfObjectStream ][]*_fb .PdfFont {};for _gab :=range _aac {_cfe :=_gab .FontDescriptor ();if _cfe ==nil ||_cfe .FontFile2 ==nil {continue ;};_baeb ,_beb :=_f .GetStream (_cfe .FontFile2 );if !_beb {continue ;};_ad [_baeb ]=append (_ad [_baeb ],_gab );};for _fgee :=range _ad {var _gdf []rune ;var _baea []_abg .GlyphIndex ;for _ ,_gac :=range _ad [_fgee ]{switch _eba :=_gac .Encoder ().(type ){case *_dg .IdentityEncoder :_fege :=_eba .RegisteredRunes ();_efg :=make ([]_abg .GlyphIndex ,len (_fege ));for _fcb ,_fef :=range _fege {_efg [_fcb ]=_abg .GlyphIndex (_fef );};_baea =append (_baea ,_efg ...);case *_dg .TrueTypeFontEncoder :_eec :=_eba .RegisteredRunes ();_gdf =append (_gdf ,_eec ...);case _dg .SimpleEncoder :_gb :=_eba .Charcodes ();for _ ,_dgag :=range _gb {_ff ,_ada :=_eba .CharcodeToRune (_dgag );if !_ada {_e .Log .Debug ("\u0043\u0068a\u0072\u0063\u006f\u0064\u0065\u003c\u002d\u003e\u0072\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064: \u0025\u0064",_dgag );continue ;};_gdf =append (_gdf ,_ff );};};};_db =_bba (_fgee ,_gdf ,_baea );if _db !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0073\u0075\u0062\u0073\u0065\u0074\u0074\u0069\u006eg\u0020f\u006f\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u003a\u0020\u0025\u0076",_db );return nil ,_db ;};_gc [_fgee ]=struct{}{};};return _gc ,nil ;};
|
||||
package optimize ;import (_gf "bytes";_ega "crypto/md5";_g "errors";_bd "fmt";_ee "github.com/unidoc/unipdf/v3/common";_gb "github.com/unidoc/unipdf/v3/contentstream";_e "github.com/unidoc/unipdf/v3/core";_aa "github.com/unidoc/unipdf/v3/extractor";_bf "github.com/unidoc/unipdf/v3/internal/textencoding";_ae "github.com/unidoc/unipdf/v3/model";_f "github.com/unidoc/unitype";_eg "golang.org/x/image/draw";_c "image";_b "math";);func _gaaa (_cbbc *_e .PdfObjectStream ,_eccc float64 )error {_dfd ,_fbb :=_ae .NewXObjectImageFromStream (_cbbc );if _fbb !=nil {return _fbb ;};_aedae ,_fbb :=_dfd .ToImage ();if _fbb !=nil {return _fbb ;};_beg ,_fbb :=_aedae .ToGoImage ();if _fbb !=nil {return _fbb ;};_dded :=int (_b .RoundToEven (float64 (_aedae .Width )*_eccc ));_ggd :=int (_b .RoundToEven (float64 (_aedae .Height )*_eccc ));_eca :=_c .Rect (0,0,_dded ,_ggd );var _dbdg _eg .Image ;var _bbd func (_c .Image )(*_ae .Image ,error );switch _dfd .ColorSpace .String (){case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_dbdg =_c .NewRGBA (_eca );_bbd =_ae .ImageHandling .NewImageFromGoImage ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_dbdg =_c .NewGray (_eca );_bbd =_ae .ImageHandling .NewGrayImageFromGoImage ;default:return _bd .Errorf ("\u006f\u0070\u0074\u0069\u006d\u0069\u007a\u0061t\u0069\u006f\u006e i\u0073\u0020\u006e\u006f\u0074\u0020s\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065 \u0025\u0073",_dfd .ColorSpace .String ());};_eg .CatmullRom .Scale (_dbdg ,_dbdg .Bounds (),_beg ,_beg .Bounds (),_eg .Over ,&_eg .Options {});if _aedae ,_fbb =_bbd (_dbdg );_fbb !=nil {return _fbb ;};_ead :=_e .MakeDict ();_ead .Set ("\u0051u\u0061\u006c\u0069\u0074\u0079",_e .MakeInteger (100));_ead .Set ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr",_e .MakeInteger (1));_dfd .Filter .UpdateParams (_ead );if _fbb =_dfd .SetImage (_aedae ,nil );_fbb !=nil {return _fbb ;};_dfd .ToPdfObject ();return nil ;};
|
||||
|
||||
// Append appends optimizers to the chain.
|
||||
func (_d *Chain )Append (optimizers ..._ae .Optimizer ){_d ._ba =append (_d ._ba ,optimizers ...)};func _gbg (_dccc []_e .PdfObject )objectStructure {_gdd :=objectStructure {};_cgfe :=false ;for _ ,_gfee :=range _dccc {switch _fdc :=_gfee .(type ){case *_e .PdfIndirectObject :_fbdg ,_daa :=_e .GetDict (_fdc );if !_daa {continue ;};_eeff ,_daa :=_e .GetName (_fbdg .Get ("\u0054\u0079\u0070\u0065"));if !_daa {continue ;};switch _eeff .String (){case "\u0043a\u0074\u0061\u006c\u006f\u0067":_gdd ._efab =_fbdg ;_cgfe =true ;};};if _cgfe {break ;};};if !_cgfe {return _gdd ;};_bgca ,_fbeg :=_e .GetDict (_gdd ._efab .Get ("\u0050\u0061\u0067e\u0073"));if !_fbeg {return _gdd ;};_gdd ._afaf =_bgca ;_ecee ,_fbeg :=_e .GetArray (_bgca .Get ("\u004b\u0069\u0064\u0073"));if !_fbeg {return _gdd ;};for _ ,_deaga :=range _ecee .Elements (){_aeec ,_ceeb :=_e .GetIndirect (_deaga );if !_ceeb {break ;};_gdd ._dbce =append (_gdd ._dbce ,_aeec );};return _gdd ;};func _cdd (_cegf _e .PdfObject )[]content {if _cegf ==nil {return nil ;};_gfag ,_cdf :=_e .GetArray (_cegf );if !_cdf {_ee .Log .Debug ("\u0041\u006e\u006e\u006fts\u0020\u006e\u006f\u0074\u0020\u0061\u006e\u0020\u0061\u0072\u0072\u0061\u0079");return nil ;};var _cde []content ;for _ ,_efd :=range _gfag .Elements (){_aegg ,_cgf :=_e .GetDict (_efd );if !_cgf {_ee .Log .Debug ("I\u0067\u006e\u006f\u0072\u0069\u006eg\u0020\u006e\u006f\u006e\u002d\u0064i\u0063\u0074\u0020\u0065\u006c\u0065\u006de\u006e\u0074\u0020\u0069\u006e\u0020\u0041\u006e\u006e\u006ft\u0073");continue ;};_fgg ,_cgf :=_e .GetDict (_aegg .Get ("\u0041\u0050"));if !_cgf {_ee .Log .Debug ("\u004e\u006f\u0020\u0041P \u0065\u006e\u0074\u0072\u0079\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067");continue ;};_adg :=_e .TraceToDirectObject (_fgg .Get ("\u004e"));if _adg ==nil {_ee .Log .Debug ("N\u006f\u0020\u004e\u0020en\u0074r\u0079\u0020\u002d\u0020\u0073k\u0069\u0070\u0070\u0069\u006e\u0067");continue ;};var _cce *_e .PdfObjectStream ;switch _dbg :=_adg .(type ){case *_e .PdfObjectDictionary :_dea ,_fbc :=_e .GetName (_aegg .Get ("\u0041\u0053"));if !_fbc {_ee .Log .Debug ("\u004e\u006f\u0020\u0041S \u0065\u006e\u0074\u0072\u0079\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067");continue ;};_cce ,_fbc =_e .GetStream (_dbg .Get (*_dea ));if !_fbc {_ee .Log .Debug ("\u0046o\u0072\u006d\u0020\u006eo\u0074\u0020\u0066\u006f\u0075n\u0064 \u002d \u0073\u006b\u0069\u0070\u0070\u0069\u006eg");continue ;};case *_e .PdfObjectStream :_cce =_dbg ;};if _cce ==nil {_ee .Log .Debug ("\u0046\u006f\u0072m\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0028n\u0069\u006c\u0029\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067");continue ;};_gda ,_cee :=_ae .NewXObjectFormFromStream (_cce );if _cee !=nil {_ee .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020l\u006f\u0061\u0064\u0069\u006e\u0067\u0020\u0066\u006f\u0072\u006d\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_cee );continue ;};_eeb ,_cee :=_gda .GetContentStream ();if _cee !=nil {_ee .Log .Debug ("E\u0072\u0072\u006f\u0072\u0020\u0064e\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0063\u006fn\u0074\u0065\u006et\u0073:\u0020\u0025\u0076",_cee );continue ;};_cde =append (_cde ,content {_fbd :string (_eeb ),_gfba :_gda .Resources });};return _cde ;};func _bc (_ca *_gb .ContentStreamOperations )*_gb .ContentStreamOperations {if _ca ==nil {return nil ;};_ga :=_gb .ContentStreamOperations {};for _ ,_fa :=range *_ca {switch _fa .Operand {case "\u0042\u0044\u0043","\u0042\u004d\u0043","\u0045\u004d\u0043":continue ;case "\u0054\u006d":if len (_fa .Params )==6{if _aea ,_df :=_e .GetNumbersAsFloat (_fa .Params );_df ==nil {if _aea [0]==1&&_aea [1]==0&&_aea [2]==0&&_aea [3]==1{_fa =&_gb .ContentStreamOperation {Params :[]_e .PdfObject {_fa .Params [4],_fa .Params [5]},Operand :"\u0054\u0064"};};};};};_ga =append (_ga ,_fa );};return &_ga ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_gaa *ObjectStreams )Optimize (objects []_f .PdfObject )(_aecd []_f .PdfObject ,_aege error ){_adag :=&_f .PdfObjectStreams {};_affb :=make ([]_f .PdfObject ,0,len (objects ));for _ ,_bfef :=range objects {if _bce ,_gbbd :=_bfef .(*_f .PdfIndirectObject );_gbbd &&_bce .GenerationNumber ==0{_adag .Append (_bfef );}else {_affb =append (_affb ,_bfef );};};if _adag .Len ()==0{return _affb ,nil ;};_aecd =make ([]_f .PdfObject ,0,len (_affb )+_adag .Len ()+1);if _adag .Len ()> 1{_aecd =append (_aecd ,_adag );};_aecd =append (_aecd ,_adag .Elements ()...);_aecd =append (_aecd ,_affb ...);return _aecd ,nil ;};type content struct{_fdg string ;_ace *_fb .PdfPageResources ;};type objectStructure struct{_egg *_f .PdfObjectDictionary ;_gcgc *_f .PdfObjectDictionary ;_gdeb []*_f .PdfIndirectObject ;};
|
||||
func (_bead *ImagePPI )Optimize (objects []_e .PdfObject )(_afa []_e .PdfObject ,_bdga error ){if _bead .ImageUpperPPI <=0{return objects ,nil ;};_deag :=_caf (objects );if len (_deag )==0{return objects ,nil ;};_ffd :=make (map[_e .PdfObject ]struct{});for _ ,_edc :=range _deag {_ffcg :=_edc .Stream .PdfObjectDictionary .Get (_e .PdfObjectName ("\u0053\u004d\u0061s\u006b"));_ffd [_ffcg ]=struct{}{};};_gcf :=make (map[*_e .PdfObjectStream ]*imageInfo );for _ ,_bab :=range _deag {_gcf [_bab .Stream ]=_bab ;};var _fdbd *_e .PdfObjectDictionary ;for _ ,_ccg :=range objects {if _cbe ,_aeeaa :=_e .GetDict (_ccg );_fdbd ==nil &&_aeeaa {if _bfe ,_acc :=_e .GetName (_cbe .Get (_e .PdfObjectName ("\u0054\u0079\u0070\u0065")));_acc &&*_bfe =="\u0043a\u0074\u0061\u006c\u006f\u0067"{_fdbd =_cbe ;};};};if _fdbd ==nil {return objects ,nil ;};_cfd ,_gba :=_e .GetDict (_fdbd .Get (_e .PdfObjectName ("\u0050\u0061\u0067e\u0073")));if !_gba {return objects ,nil ;};_ecde ,_aece :=_e .GetArray (_cfd .Get (_e .PdfObjectName ("\u004b\u0069\u0064\u0073")));if !_aece {return objects ,nil ;};_gfe :=make (map[string ]*imageInfo );for _ ,_abf :=range _ecde .Elements (){_afdg ,_ccf :=_e .GetDict (_abf );if !_ccf {continue ;};_fcdb ,_eefe :=_e .GetArray (_afdg .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if !_eefe {continue ;};_cfe ,_bge :=_e .GetDict (_afdg .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));if !_bge {continue ;};_deb ,_efcbb :=_e .GetDict (_cfe .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));if !_efcbb {continue ;};_agg :=_deb .Keys ();for _ ,_cfc :=range _agg {if _cdda ,_ebg :=_e .GetStream (_deb .Get (_cfc ));_ebg {if _eedd ,_daf :=_gcf [_cdda ];_daf {_gfe [string (_cfc )]=_eedd ;};};};for _ ,_gfae :=range _fcdb .Elements (){if _debg ,_dgf :=_e .GetStream (_gfae );_dgf {_bee ,_fed :=_e .NewEncoderFromStream (_debg );if _fed !=nil {return nil ,_fed ;};_gbac ,_fed :=_bee .DecodeStream (_debg );if _fed !=nil {return nil ,_fed ;};_aecf :=_gb .NewContentStreamParser (string (_gbac ));_dcbb ,_fed :=_aecf .Parse ();if _fed !=nil {return nil ,_fed ;};_ggaf ,_bgb :=1.0,1.0;for _ ,_eee :=range *_dcbb {if _eee .Operand =="\u0051"{_ggaf ,_bgb =1.0,1.0;};if _eee .Operand =="\u0063\u006d"&&len (_eee .Params )==6{if _agc ,_ffb :=_e .GetFloatVal (_eee .Params [0]);_ffb {_ggaf =_ggaf *_agc ;};if _ffdd ,_dcd :=_e .GetFloatVal (_eee .Params [3]);_dcd {_bgb =_bgb *_ffdd ;};if _egdb ,_bbea :=_e .GetIntVal (_eee .Params [0]);_bbea {_ggaf =_ggaf *float64 (_egdb );};if _ecb ,_beeg :=_e .GetIntVal (_eee .Params [3]);_beeg {_bgb =_bgb *float64 (_ecb );};};if _eee .Operand =="\u0044\u006f"&&len (_eee .Params )==1{_ceec ,_gef :=_e .GetName (_eee .Params [0]);if !_gef {continue ;};if _ffab ,_gcbc :=_gfe [string (*_ceec )];_gcbc {_cfeb ,_cge :=_ggaf /72.0,_bgb /72.0;_bgee ,_fdbf :=float64 (_ffab .Width )/_cfeb ,float64 (_ffab .Height )/_cge ;if _cfeb ==0||_cge ==0{_bgee =72.0;_fdbf =72.0;};_ffab .PPI =_b .Max (_ffab .PPI ,_bgee );_ffab .PPI =_b .Max (_ffab .PPI ,_fdbf );};};};};};};for _ ,_gcg :=range _deag {if _ ,_bcg :=_ffd [_gcg .Stream ];_bcg {continue ;};if _gcg .PPI <=_bead .ImageUpperPPI {continue ;};_cdea :=_bead .ImageUpperPPI /_gcg .PPI ;if _dfeb :=_gaaa (_gcg .Stream ,_cdea );_dfeb !=nil {_ee .Log .Debug ("\u0045\u0072\u0072\u006f\u0072 \u0073\u0063\u0061\u006c\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u006be\u0065\u0070\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_dfeb );}else {if _bffg ,_deba :=_e .GetStream (_gcg .Stream .PdfObjectDictionary .Get (_e .PdfObjectName ("\u0053\u004d\u0061s\u006b")));_deba {if _bgd :=_gaaa (_bffg ,_cdea );_bgd !=nil {return nil ,_bgd ;};};};};return objects ,nil ;};
|
||||
|
||||
// Chain allows to use sequence of optimizers.
|
||||
// It implements interface model.Optimizer.
|
||||
type Chain struct{_ba []_ae .Optimizer };
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_ffc *CombineDuplicateStreams )Optimize (objects []_e .PdfObject )(_bcd []_e .PdfObject ,_acbf error ){_dbfa :=make (map[_e .PdfObject ]_e .PdfObject );_gggf :=make (map[_e .PdfObject ]struct{});_dc :=make (map[string ][]*_e .PdfObjectStream );for _ ,_fcd :=range objects {if _gggc ,_acba :=_fcd .(*_e .PdfObjectStream );_acba {_gcb :=_ega .New ();_gcb .Write ([]byte (_gggc .Stream ));_cfa :=string (_gcb .Sum (nil ));_dc [_cfa ]=append (_dc [_cfa ],_gggc );};};for _ ,_fdbc :=range _dc {if len (_fdbc )< 2{continue ;};_afbe :=_fdbc [0];for _eefc :=1;_eefc < len (_fdbc );_eefc ++{_eed :=_fdbc [_eefc ];_dbfa [_eed ]=_afbe ;_gggf [_eed ]=struct{}{};};};_bcd =make ([]_e .PdfObject ,0,len (objects )-len (_gggf ));for _ ,_gfbd :=range objects {if _ ,_efb :=_gggf [_gfbd ];_efb {continue ;};_bcd =append (_bcd ,_gfbd );};_aef (_bcd ,_dbfa );return _bcd ,nil ;};type content struct{_fbd string ;_gfba *_ae .PdfPageResources ;};func _cab (_dgab _e .PdfObject )(_dcgc string ,_gdb []_e .PdfObject ){var _baeg _gf .Buffer ;switch _bed :=_dgab .(type ){case *_e .PdfIndirectObject :_gdb =append (_gdb ,_bed );_dgab =_bed .PdfObject ;};switch _fegca :=_dgab .(type ){case *_e .PdfObjectStream :if _ffad ,_dfg :=_e .DecodeStream (_fegca );_dfg ==nil {_baeg .Write (_ffad );_gdb =append (_gdb ,_fegca );};case *_e .PdfObjectArray :for _ ,_bbfg :=range _fegca .Elements (){switch _ecae :=_bbfg .(type ){case *_e .PdfObjectStream :if _dee ,_eec :=_e .DecodeStream (_ecae );_eec ==nil {_baeg .Write (_dee );_gdb =append (_gdb ,_ecae );};};};};return _baeg .String (),_gdb ;};
|
||||
|
||||
// CombineIdenticalIndirectObjects combines identical indirect objects.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineIdenticalIndirectObjects struct{};
|
||||
|
||||
// CombineDuplicateDirectObjects combines duplicated direct objects by its data hash.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineDuplicateDirectObjects struct{};func _ag (_aed *_e .PdfObjectStream )error {_fg ,_gd :=_e .DecodeStream (_aed );if _gd !=nil {return _gd ;};_eb :=_gb .NewContentStreamParser (string (_fg ));_dfa ,_gd :=_eb .Parse ();if _gd !=nil {return _gd ;};_dfa =_bc (_dfa );_ac :=_dfa .Bytes ();if len (_ac )>=len (_fg ){return nil ;};_db ,_gd :=_e .MakeStream (_dfa .Bytes (),_e .NewFlateEncoder ());if _gd !=nil {return _gd ;};_aed .Stream =_db .Stream ;_aed .Merge (_db .PdfObjectDictionary );return nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_gaa *CombineIdenticalIndirectObjects )Optimize (objects []_e .PdfObject )(_dda []_e .PdfObject ,_afea error ){_eebb (objects );_dde :=make (map[_e .PdfObject ]_e .PdfObject );_ecc :=make (map[_e .PdfObject ]struct{});_bfg :=make (map[string ][]*_e .PdfIndirectObject );for _ ,_efbb :=range objects {_gbe ,_cegd :=_efbb .(*_e .PdfIndirectObject );if !_cegd {continue ;};if _ebeb ,_baa :=_gbe .PdfObject .(*_e .PdfObjectDictionary );_baa {if _eace ,_bef :=_ebeb .Get ("\u0054\u0079\u0070\u0065").(*_e .PdfObjectName );_bef &&*_eace =="\u0050\u0061\u0067\u0065"{continue ;};_dbb :=_ega .New ();_dbb .Write ([]byte (_ebeb .WriteString ()));_dcg :=string (_dbb .Sum (nil ));_bfg [_dcg ]=append (_bfg [_dcg ],_gbe );};};for _ ,_bbg :=range _bfg {if len (_bbg )< 2{continue ;};_dga :=_bbg [0];for _aeggc :=1;_aeggc < len (_bbg );_aeggc ++{_cag :=_bbg [_aeggc ];_dde [_cag ]=_dga ;_ecc [_cag ]=struct{}{};};};_dda =make ([]_e .PdfObject ,0,len (objects )-len (_ecc ));for _ ,_fgfg :=range objects {if _ ,_ccd :=_ecc [_fgfg ];_ccd {continue ;};_dda =append (_dda ,_fgfg );};_aef (_dda ,_dde );return _dda ,nil ;};
|
||||
|
||||
// Image optimizes images by rewrite images into JPEG format with quality equals to ImageQuality.
|
||||
// TODO(a5i): Add support for inline images.
|
||||
// It implements interface model.Optimizer.
|
||||
type Image struct{ImageQuality int ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_affb *ObjectStreams )Optimize (objects []_e .PdfObject )(_fegc []_e .PdfObject ,_afeg error ){_aecb :=&_e .PdfObjectStreams {};_abdf :=make ([]_e .PdfObject ,0,len (objects ));for _ ,_fbf :=range objects {if _gca ,_abdg :=_fbf .(*_e .PdfIndirectObject );_abdg &&_gca .GenerationNumber ==0{_aecb .Append (_fbf );}else {_abdf =append (_abdf ,_fbf );};};if _aecb .Len ()==0{return _abdf ,nil ;};_fegc =make ([]_e .PdfObject ,0,len (_abdf )+_aecb .Len ()+1);if _aecb .Len ()> 1{_fegc =append (_fegc ,_aecb );};_fegc =append (_fegc ,_aecb .Elements ()...);_fegc =append (_fegc ,_abdf ...);return _fegc ,nil ;};func _aef (_gceg []_e .PdfObject ,_bcdd map[_e .PdfObject ]_e .PdfObject ){if _bcdd ==nil ||len (_bcdd )==0{return ;};for _acae ,_cbaa :=range _gceg {if _dbe ,_bbf :=_bcdd [_cbaa ];_bbf {_gceg [_acae ]=_dbe ;continue ;};_bcdd [_cbaa ]=_cbaa ;switch _gcad :=_cbaa .(type ){case *_e .PdfObjectArray :_eab :=make ([]_e .PdfObject ,_gcad .Len ());copy (_eab ,_gcad .Elements ());_aef (_eab ,_bcdd );for _efbf ,_fcb :=range _eab {_gcad .Set (_efbf ,_fcb );};case *_e .PdfObjectStreams :_aef (_gcad .Elements (),_bcdd );case *_e .PdfObjectStream :_aeaf :=[]_e .PdfObject {_gcad .PdfObjectDictionary };_aef (_aeaf ,_bcdd );_gcad .PdfObjectDictionary =_aeaf [0].(*_e .PdfObjectDictionary );case *_e .PdfObjectDictionary :_egf :=_gcad .Keys ();_afc :=make ([]_e .PdfObject ,len (_egf ));for _bfef ,_egc :=range _egf {_afc [_bfef ]=_gcad .Get (_egc );};_aef (_afc ,_bcdd );for _cdegf ,_ggb :=range _egf {_gcad .Set (_ggb ,_afc [_cdegf ]);};case *_e .PdfIndirectObject :_geb :=[]_e .PdfObject {_gcad .PdfObject };_aef (_geb ,_bcdd );_gcad .PdfObject =_geb [0];};};};func _caf (_aace []_e .PdfObject )[]*imageInfo {_bac :=_e .PdfObjectName ("\u0053u\u0062\u0074\u0079\u0070\u0065");_cad :=make (map[*_e .PdfObjectStream ]struct{});var _dba error ;var _cdeg []*imageInfo ;for _ ,_ecdf :=range _aace {_fea ,_dcb :=_e .GetStream (_ecdf );if !_dcb {continue ;};if _ ,_aff :=_cad [_fea ];_aff {continue ;};_cad [_fea ]=struct{}{};_ece :=_fea .PdfObjectDictionary .Get (_bac );_abda ,_dcb :=_e .GetName (_ece );if !_dcb ||string (*_abda )!="\u0049\u006d\u0061g\u0065"{continue ;};_dbgg :=&imageInfo {BitsPerComponent :8,Stream :_fea };if _dbgg .ColorSpace ,_dba =_ae .DetermineColorspaceNameFromPdfObject (_fea .PdfObjectDictionary .Get ("\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065"));_dba !=nil {_ee .Log .Error ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u0025\u0073",_dba );continue ;};if _dca ,_gcee :=_e .GetIntVal (_fea .PdfObjectDictionary .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074"));_gcee {_dbgg .BitsPerComponent =_dca ;};if _beb ,_efa :=_e .GetIntVal (_fea .PdfObjectDictionary .Get ("\u0057\u0069\u0064t\u0068"));_efa {_dbgg .Width =_beb ;};if _eda ,_eae :=_e .GetIntVal (_fea .PdfObjectDictionary .Get ("\u0048\u0065\u0069\u0067\u0068\u0074"));_eae {_dbgg .Height =_eda ;};switch _dbgg .ColorSpace {case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_dbgg .ColorComponents =3;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_dbgg .ColorComponents =1;default:_ee .Log .Warning ("\u004f\u0070\u0074\u0069\u006d\u0069\u007a\u0061t\u0069\u006f\u006e i\u0073\u0020\u006e\u006f\u0074\u0020s\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065 \u0025\u0073",_dbgg .ColorSpace );continue ;};_cdeg =append (_cdeg ,_dbgg );};return _cdeg ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_ddb *CombineDuplicateDirectObjects )Optimize (objects []_e .PdfObject )(_fgf []_e .PdfObject ,_ed error ){_eebb (objects );_bcf :=make (map[string ][]*_e .PdfObjectDictionary );var _adc func (_baga *_e .PdfObjectDictionary );_adc =func (_fac *_e .PdfObjectDictionary ){for _ ,_bga :=range _fac .Keys (){_bfc :=_fac .Get (_bga );if _gggb ,_abg :=_bfc .(*_e .PdfObjectDictionary );_abg {_adb :=_ega .New ();_adb .Write ([]byte (_gggb .WriteString ()));_aee :=string (_adb .Sum (nil ));_bcf [_aee ]=append (_bcf [_aee ],_gggb );_adc (_gggb );};};};for _ ,_add :=range objects {_gcc ,_dfe :=_add .(*_e .PdfIndirectObject );if !_dfe {continue ;};if _fff ,_cef :=_gcc .PdfObject .(*_e .PdfObjectDictionary );_cef {_adc (_fff );};};_cbf :=make ([]_e .PdfObject ,0,len (_bcf ));_bde :=make (map[_e .PdfObject ]_e .PdfObject );for _ ,_ccac :=range _bcf {if len (_ccac )< 2{continue ;};_efcb :=_e .MakeDict ();_efcb .Merge (_ccac [0]);_aae :=_e .MakeIndirectObject (_efcb );_cbf =append (_cbf ,_aae );for _ffa :=0;_ffa < len (_ccac );_ffa ++{_ceed :=_ccac [_ffa ];_bde [_ceed ]=_aae ;};};_fgf =make ([]_e .PdfObject ,len (objects ));copy (_fgf ,objects );_fgf =append (_cbf ,_fgf ...);_aef (_fgf ,_bde );return _fgf ,nil ;};func _dbc (_cca []_e .PdfObject )(_afd map[*_e .PdfObjectStream ]struct{},_de error ){_afd =map[*_e .PdfObjectStream ]struct{}{};_fde :=map[*_ae .PdfFont ]struct{}{};_gad :=_gbg (_cca );for _ ,_aac :=range _gad ._dbce {_bag ,_ab :=_e .GetDict (_aac .PdfObject );if !_ab {continue ;};_aeg ,_ab :=_e .GetDict (_bag .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));if !_ab {continue ;};_ggc ,_ :=_cab (_bag .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_gdcc ,_gga :=_ae .NewPdfPageResourcesFromDict (_aeg );if _gga !=nil {return nil ,_gga ;};_cb :=[]content {{_fbd :_ggc ,_gfba :_gdcc }};_bea :=_cdd (_bag .Get ("\u0041\u006e\u006e\u006f\u0074\u0073"));if _bea !=nil {_cb =append (_cb ,_bea ...);};for _ ,_gdg :=range _cb {_gfa ,_cf :=_aa .NewFromContents (_gdg ._fbd ,_gdg ._gfba );if _cf !=nil {return nil ,_cf ;};_agd ,_ ,_ ,_cf :=_gfa .ExtractPageText ();if _cf !=nil {return nil ,_cf ;};for _ ,_da :=range _agd .Marks ().Elements (){if _da .Font ==nil {continue ;};if _ ,_egae :=_fde [_da .Font ];!_egae {_fde [_da .Font ]=struct{}{};};};};};_acd :=map[*_e .PdfObjectStream ][]*_ae .PdfFont {};for _efc :=range _fde {_acb :=_efc .FontDescriptor ();if _acb ==nil ||_acb .FontFile2 ==nil {continue ;};_fab ,_aeda :=_e .GetStream (_acb .FontFile2 );if !_aeda {continue ;};_acd [_fab ]=append (_acd [_fab ],_efc );};for _eac :=range _acd {var _gde []rune ;var _egd []_f .GlyphIndex ;for _ ,_ceg :=range _acd [_eac ]{switch _dbd :=_ceg .Encoder ().(type ){case *_bf .IdentityEncoder :_caef :=_dbd .RegisteredRunes ();_cbb :=make ([]_f .GlyphIndex ,len (_caef ));for _eef ,_bba :=range _caef {_cbb [_eef ]=_f .GlyphIndex (_bba );};_egd =append (_egd ,_cbb ...);case *_bf .TrueTypeFontEncoder :_ccc :=_dbd .RegisteredRunes ();_gde =append (_gde ,_ccc ...);case _bf .SimpleEncoder :_dff :=_dbd .Charcodes ();for _ ,_ebe :=range _dff {_gfb ,_ggcc :=_dbd .CharcodeToRune (_ebe );if !_ggcc {_ee .Log .Debug ("\u0043\u0068a\u0072\u0063\u006f\u0064\u0065\u003c\u002d\u003e\u0072\u0075\u006e\u0065\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064: \u0025\u0064",_ebe );continue ;};_gde =append (_gde ,_gfb );};};};_de =_fe (_eac ,_gde ,_egd );if _de !=nil {_ee .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020\u0073\u0075\u0062\u0073\u0065\u0074\u0074\u0069\u006eg\u0020f\u006f\u006e\u0074\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u003a\u0020\u0025\u0076",_de );return nil ,_de ;};_afd [_eac ]=struct{}{};};return _afd ,nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_ded *CompressStreams )Optimize (objects []_e .PdfObject )(_fabb []_e .PdfObject ,_efdb error ){_fabb =make ([]_e .PdfObject ,len (objects ));copy (_fabb ,objects );for _ ,_bcab :=range objects {_eebe ,_dcc :=_e .GetStream (_bcab );if !_dcc {continue ;};if _ace :=_eebe .Get ("\u0046\u0069\u006c\u0074\u0065\u0072");_ace !=nil {if _ ,_fec :=_e .GetName (_ace );_fec {continue ;};if _fbda ,_aebg :=_e .GetArray (_ace );_aebg &&_fbda .Len ()> 0{continue ;};};_bff :=_e .NewFlateEncoder ();var _fdbcg []byte ;_fdbcg ,_efdb =_bff .EncodeBytes (_eebe .Stream );if _efdb !=nil {return _fabb ,_efdb ;};_eafd :=_bff .MakeStreamDict ();if len (_fdbcg )+len (_eafd .WriteString ())< len (_eebe .Stream ){_eebe .Stream =_fdbcg ;_eebe .PdfObjectDictionary .Merge (_eafd );_eebe .PdfObjectDictionary .Set ("\u004c\u0065\u006e\u0067\u0074\u0068",_e .MakeInteger (int64 (len (_eebe .Stream ))));};};return _fabb ,nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_aca *CleanFonts )Optimize (objects []_e .PdfObject )(_dfbb []_e .PdfObject ,_abe error ){var _dgg map[*_e .PdfObjectStream ]struct{};if _aca .Subset {var _bbe error ;_dgg ,_bbe =_dbc (objects );if _bbe !=nil {return nil ,_bbe ;};};for _ ,_fc :=range objects {_eegf ,_bec :=_e .GetStream (_fc );if !_bec {continue ;};if _ ,_afga :=_dgg [_eegf ];_afga {continue ;};_gec ,_eea :=_e .NewEncoderFromStream (_eegf );if _eea !=nil {_ee .Log .Debug ("\u0045\u0052RO\u0052\u0020\u0067e\u0074\u0074\u0069\u006eg e\u006eco\u0064\u0065\u0072\u003a\u0020\u0025\u0076 -\u0020\u0069\u0067\u006e\u006f\u0072\u0069n\u0067",_eea );continue ;};_egdd ,_eea :=_gec .DecodeStream (_eegf );if _eea !=nil {_ee .Log .Debug ("\u0044\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0065r\u0072\u006f\u0072\u0020\u003a\u0020\u0025v\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069\u006e\u0067",_eea );continue ;};if len (_egdd )< 4{continue ;};_afb :=string (_egdd [:4]);if _afb =="\u004f\u0054\u0054\u004f"{continue ;};if _afb !="\u0000\u0001\u0000\u0000"&&_afb !="\u0074\u0072\u0075\u0065"{continue ;};_fcc ,_eea :=_f .Parse (_gf .NewReader (_egdd ));if _eea !=nil {_ee .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020P\u0061\u0072\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_eea );continue ;};_eea =_fcc .Optimize ();if _eea !=nil {continue ;};var _abdc _gf .Buffer ;_eea =_fcc .Write (&_abdc );if _eea !=nil {_ee .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020W\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_eea );continue ;};if _abdc .Len ()> len (_egdd ){_ee .Log .Debug ("\u0052\u0065-\u0077\u0072\u0069\u0074\u0074\u0065\u006e\u0020\u0066\u006f\u006e\u0074\u0020\u0069\u0073\u0020\u006c\u0061\u0072\u0067\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u002d\u0020\u0073\u006b\u0069\u0070");continue ;};_bdg ,_eea :=_e .MakeStream (_abdc .Bytes (),_e .NewFlateEncoder ());if _eea !=nil {continue ;};*_eegf =*_bdg ;_eegf .Set ("\u004ce\u006e\u0067\u0074\u0068\u0031",_e .MakeInteger (int64 (_abdc .Len ())));};return objects ,nil ;};
|
||||
|
||||
// ImagePPI optimizes images by scaling images such that the PPI (pixels per inch) is never higher than ImageUpperPPI.
|
||||
// TODO(a5i): Add support for inline images.
|
||||
// It implements interface model.Optimizer.
|
||||
type ImagePPI struct{ImageUpperPPI float64 ;};
|
||||
type ImagePPI struct{ImageUpperPPI float64 ;};func _eebb (_efaa []_e .PdfObject ){for _faa ,_fbe :=range _efaa {switch _bbc :=_fbe .(type ){case *_e .PdfIndirectObject :_bbc .ObjectNumber =int64 (_faa +1);_bbc .GenerationNumber =0;case *_e .PdfObjectStream :_bbc .ObjectNumber =int64 (_faa +1);_bbc .GenerationNumber =0;case *_e .PdfObjectStreams :_bbc .ObjectNumber =int64 (_faa +1);_bbc .GenerationNumber =0;};};};
|
||||
|
||||
// New creates a optimizers chain from options.
|
||||
func New (options Options )*Chain {_fbfc :=new (Chain );if options .CleanFonts ||options .SubsetFonts {_fbfc .Append (&CleanFonts {Subset :options .SubsetFonts });};if options .CleanContentstream {_fbfc .Append (new (CleanContentstream ));};if options .ImageUpperPPI > 0{_beaa :=new (ImagePPI );_beaa .ImageUpperPPI =options .ImageUpperPPI ;_fbfc .Append (_beaa );};if options .ImageQuality > 0{_ecf :=new (Image );_ecf .ImageQuality =options .ImageQuality ;_fbfc .Append (_ecf );};if options .CombineDuplicateDirectObjects {_fbfc .Append (new (CombineDuplicateDirectObjects ));};if options .CombineDuplicateStreams {_fbfc .Append (new (CombineDuplicateStreams ));};if options .CombineIdenticalIndirectObjects {_fbfc .Append (new (CombineIdenticalIndirectObjects ));};if options .UseObjectStreams {_fbfc .Append (new (ObjectStreams ));};if options .CompressStreams {_fbfc .Append (new (CompressStreams ));};return _fbfc ;};
|
||||
|
||||
// CombineDuplicateStreams combines duplicated streams by its data hash.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineDuplicateStreams struct{};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_abgg *ImagePPI )Optimize (objects []_f .PdfObject )(_efe []_f .PdfObject ,_daf error ){if _abgg .ImageUpperPPI <=0{return objects ,nil ;};_ggbc :=_beed (objects );if len (_ggbc )==0{return objects ,nil ;};_aaeg :=make (map[_f .PdfObject ]struct{});for _ ,_ecca :=range _ggbc {_fffa :=_ecca .Stream .PdfObjectDictionary .Get (_f .PdfObjectName ("\u0053\u004d\u0061s\u006b"));_aaeg [_fffa ]=struct{}{};};_aceb :=make (map[*_f .PdfObjectStream ]*imageInfo );for _ ,_cfa :=range _ggbc {_aceb [_cfa .Stream ]=_cfa ;};var _geb *_f .PdfObjectDictionary ;for _ ,_afe :=range objects {if _fgb ,_aca :=_f .GetDict (_afe );_geb ==nil &&_aca {if _agdf ,_aedg :=_f .GetName (_fgb .Get (_f .PdfObjectName ("\u0054\u0079\u0070\u0065")));_aedg &&*_agdf =="\u0043a\u0074\u0061\u006c\u006f\u0067"{_geb =_fgb ;};};};if _geb ==nil {return objects ,nil ;};_beff ,_cbc :=_f .GetDict (_geb .Get (_f .PdfObjectName ("\u0050\u0061\u0067e\u0073")));if !_cbc {return objects ,nil ;};_gebe ,_edgc :=_f .GetArray (_beff .Get (_f .PdfObjectName ("\u004b\u0069\u0064\u0073")));if !_edgc {return objects ,nil ;};_cbcg :=make (map[string ]*imageInfo );for _ ,_bca :=range _gebe .Elements (){_fdge ,_deb :=_f .GetDict (_bca );if !_deb {continue ;};_ccb ,_dbbc :=_f .GetArray (_fdge .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if !_dbbc {continue ;};_aebb ,_dafe :=_f .GetDict (_fdge .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));if !_dafe {continue ;};_cgf ,_fcgb :=_f .GetDict (_aebb .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));if !_fcgb {continue ;};_gfba :=_cgf .Keys ();for _ ,_eafb :=range _gfba {if _cfcb ,_cca :=_f .GetStream (_cgf .Get (_eafb ));_cca {if _eea ,_fbga :=_aceb [_cfcb ];_fbga {_cbcg [string (_eafb )]=_eea ;};};};for _ ,_abeb :=range _ccb .Elements (){if _agc ,_dcbe :=_f .GetStream (_abeb );_dcbe {_geg ,_gafe :=_f .NewEncoderFromStream (_agc );if _gafe !=nil {return nil ,_gafe ;};_fbce ,_gafe :=_geg .DecodeStream (_agc );if _gafe !=nil {return nil ,_gafe ;};_adcb :=_b .NewContentStreamParser (string (_fbce ));_fec ,_gafe :=_adcb .Parse ();if _gafe !=nil {return nil ,_gafe ;};_dgdd ,_aef :=1.0,1.0;for _ ,_ecgc :=range *_fec {if _ecgc .Operand =="\u0051"{_dgdd ,_aef =1.0,1.0;};if _ecgc .Operand =="\u0063\u006d"&&len (_ecgc .Params )==6{if _ecbg ,_acf :=_f .GetFloatVal (_ecgc .Params [0]);_acf {_dgdd =_dgdd *_ecbg ;};if _abdf ,_abf :=_f .GetFloatVal (_ecgc .Params [3]);_abf {_aef =_aef *_abdf ;};if _fgcg ,_egea :=_f .GetIntVal (_ecgc .Params [0]);_egea {_dgdd =_dgdd *float64 (_fgcg );};if _fecf ,_ebcb :=_f .GetIntVal (_ecgc .Params [3]);_ebcb {_aef =_aef *float64 (_fecf );};};if _ecgc .Operand =="\u0044\u006f"&&len (_ecgc .Params )==1{_ecac ,_bffc :=_f .GetName (_ecgc .Params [0]);if !_bffc {continue ;};if _edd ,_fga :=_cbcg [string (*_ecac )];_fga {_bffg ,_bfad :=_dgdd /72.0,_aef /72.0;_ccd ,_dee :=float64 (_edd .Width )/_bffg ,float64 (_edd .Height )/_bfad ;if _bffg ==0||_bfad ==0{_ccd =72.0;_dee =72.0;};_edd .PPI =_d .Max (_edd .PPI ,_ccd );_edd .PPI =_d .Max (_edd .PPI ,_dee );};};};};};};for _ ,_cdc :=range _ggbc {if _ ,_gdgc :=_aaeg [_cdc .Stream ];_gdgc {continue ;};if _cdc .PPI <=_abgg .ImageUpperPPI {continue ;};_cdedd :=_abgg .ImageUpperPPI /_cdc .PPI ;if _cbg :=_bbg (_cdc .Stream ,_cdedd );_cbg !=nil {_e .Log .Debug ("\u0045\u0072\u0072\u006f\u0072 \u0073\u0063\u0061\u006c\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u006be\u0065\u0070\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_cbg );}else {if _acgf ,_agcg :=_f .GetStream (_cdc .Stream .PdfObjectDictionary .Get (_f .PdfObjectName ("\u0053\u004d\u0061s\u006b")));_agcg {if _gad :=_bbg (_acgf ,_cdedd );_gad !=nil {return nil ,_gad ;};};};};return objects ,nil ;};
|
||||
func (_bfd *Chain )Optimize (objects []_e .PdfObject )(_gg []_e .PdfObject ,_ef error ){_gg =objects ;for _ ,_ec :=range _bfd ._ba {_gg ,_ef =_ec .Optimize (_gg );if _ef !=nil {return _gg ,_ef ;};};return _gg ,nil ;};type objectStructure struct{_efab *_e .PdfObjectDictionary ;_afaf *_e .PdfObjectDictionary ;_dbce []*_e .PdfIndirectObject ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_aga *Image )Optimize (objects []_e .PdfObject )(_efe []_e .PdfObject ,_dfce error ){if _aga .ImageQuality <=0{return objects ,nil ;};_deda :=_caf (objects );if len (_deda )==0{return objects ,nil ;};_fbg :=make (map[_e .PdfObject ]_e .PdfObject );_eacg :=make (map[_e .PdfObject ]struct{});for _ ,_fba :=range _deda {_dbff :=_fba .Stream .PdfObjectDictionary .Get (_e .PdfObjectName ("\u0053\u004d\u0061s\u006b"));_eacg [_dbff ]=struct{}{};};for _dge ,_aacg :=range _deda {_cba :=_aacg .Stream ;if _ ,_fbce :=_eacg [_cba ];_fbce {continue ;};_aag ,_abc :=_e .NewEncoderFromStream (_cba );if _abc !=nil {_ee .Log .Warning ("\u0045\u0072\u0072\u006f\u0072 \u0067\u0065\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0066o\u0072\u0020\u0074\u0068\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0025\u0073");continue ;};_aede ,_abc :=_aag .DecodeStream (_cba );if _abc !=nil {_ee .Log .Warning ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0074\u0068e\u0020i\u006d\u0061\u0067\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0025\u0073");continue ;};_aeea :=_e .NewDCTEncoder ();_aeea .ColorComponents =_aacg .ColorComponents ;_aeea .Quality =_aga .ImageQuality ;_aeea .BitsPerComponent =_aacg .BitsPerComponent ;_aeea .Width =_aacg .Width ;_aeea .Height =_aacg .Height ;_bae ,_abc :=_aeea .EncodeBytes (_aede );if _abc !=nil {_ee .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025v",_abc );return nil ,_abc ;};var _fbgd _e .StreamEncoder ;_fbgd =_aeea ;{_ceee :=_e .NewFlateEncoder ();_ecea :=_e .NewMultiEncoder ();_ecea .AddEncoder (_ceee );_ecea .AddEncoder (_aeea );_cegdc ,_ecef :=_ecea .EncodeBytes (_aede );if _ecef !=nil {return nil ,_ecef ;};if len (_cegdc )< len (_bae ){_ee .Log .Debug ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063\u0020\u0069\u006d\u0070\u0072\u006f\u0076\u0065\u0073\u003a\u0020\u0025\u0064\u0020\u0074o\u0020\u0025\u0064\u0020\u0028o\u0072\u0069g\u0020\u0025\u0064\u0029",len (_bae ),len (_cegdc ),len (_cba .Stream ));_bae =_cegdc ;_fbgd =_ecea ;};};_aedef :=len (_cba .Stream );if _aedef < len (_bae ){continue ;};_acbe :=&_e .PdfObjectStream {Stream :_bae };_acbe .PdfObjectReference =_cba .PdfObjectReference ;_acbe .PdfObjectDictionary =_e .MakeDict ();_acbe .Merge (_cba .PdfObjectDictionary );_acbe .Merge (_fbgd .MakeStreamDict ());_acbe .Set ("\u004c\u0065\u006e\u0067\u0074\u0068",_e .MakeInteger (int64 (len (_bae ))));_fbg [_cba ]=_acbe ;_deda [_dge ].Stream =_acbe ;};_efe =make ([]_e .PdfObject ,len (objects ));copy (_efe ,objects );_aef (_efe ,_fbg );return _efe ,nil ;};func _fe (_dbf *_e .PdfObjectStream ,_gbc []rune ,_ff []_f .GlyphIndex )error {_dbf ,_ge :=_e .GetStream (_dbf );if !_ge {_ee .Log .Debug ("\u0045\u006d\u0062\u0065\u0064\u0064\u0065\u0064\u0020\u0066\u006f\u006e\u0074\u0020\u006f\u0062\u006a\u0065c\u0074\u0020\u006e\u006f\u0074\u0020\u0066o\u0075\u006e\u0064\u0020\u002d\u002d\u0020\u0041\u0042\u004f\u0052T\u0020\u0073\u0075\u0062\u0073\u0065\u0074\u0074\u0069\u006e\u0067");return _g .New ("\u0066\u006f\u006e\u0074fi\u006c\u0065\u0032\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_ffg ,_afg :=_e .DecodeStream (_dbf );if _afg !=nil {_ee .Log .Debug ("\u0044\u0065c\u006f\u0064\u0065 \u0065\u0072\u0072\u006f\u0072\u003a\u0020\u0025\u0076",_afg );return _afg ;};_bfda ,_afg :=_f .Parse (_gf .NewReader (_ffg ));if _afg !=nil {_ee .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0070\u0061\u0072\u0073\u0069n\u0067\u0020\u0025\u0064\u0020\u0062\u0079\u0074\u0065\u0020f\u006f\u006e\u0074",len (_dbf .Stream ));return _afg ;};_ggae :=_ff ;if len (_gbc )> 0{_dfc :=_bfda .LookupRunes (_gbc );_ggae =append (_ggae ,_dfc ...);};_bfda ,_afg =_bfda .SubsetKeepIndices (_ggae );if _afg !=nil {_ee .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020s\u0075\u0062\u0073\u0065\u0074t\u0069n\u0067 \u0066\u006f\u006e\u0074\u003a\u0020\u0025v",_afg );return _afg ;};var _afdf _gf .Buffer ;_afg =_bfda .Write (&_afdf );if _afg !=nil {_ee .Log .Debug ("\u0045\u0052\u0052\u004fR \u0057\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076",_afg );return _afg ;};if _afdf .Len ()> len (_ffg ){_ee .Log .Debug ("\u0052\u0065-\u0077\u0072\u0069\u0074\u0074\u0065\u006e\u0020\u0066\u006f\u006e\u0074\u0020\u0069\u0073\u0020\u006c\u0061\u0072\u0067\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u002d\u0020\u0073\u006b\u0069\u0070");return nil ;};_aeb ,_afg :=_e .MakeStream (_afdf .Bytes (),_e .NewFlateEncoder ());if _afg !=nil {_ee .Log .Debug ("\u0045\u0052\u0052\u004fR \u0057\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076",_afg );return _afg ;};*_dbf =*_aeb ;_dbf .Set ("\u004ce\u006e\u0067\u0074\u0068\u0031",_e .MakeInteger (int64 (_afdf .Len ())));return nil ;};
|
||||
|
||||
// ObjectStreams groups PDF objects to object streams.
|
||||
// It implements interface model.Optimizer.
|
||||
type ObjectStreams struct{};
|
||||
|
||||
// Options describes PDF optimization parameters.
|
||||
type Options struct{CombineDuplicateStreams bool ;CombineDuplicateDirectObjects bool ;ImageUpperPPI float64 ;ImageQuality int ;UseObjectStreams bool ;CombineIdenticalIndirectObjects bool ;CompressStreams bool ;CleanFonts bool ;SubsetFonts bool ;CleanContentstream bool ;};
|
||||
|
||||
// CleanContentstream cleans up redundant operands in content streams, including Page and XObject Form
|
||||
// contents. This process includes:
|
||||
@ -30,70 +85,15 @@ func (_abgg *ImagePPI )Optimize (objects []_f .PdfObject )(_efe []_f .PdfObject
|
||||
type CleanContentstream struct{};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_fbc *Image )Optimize (objects []_f .PdfObject )(_ffb []_f .PdfObject ,_gcf error ){if _fbc .ImageQuality <=0{return objects ,nil ;};_bfa :=_beed (objects );if len (_bfa )==0{return objects ,nil ;};_cff :=make (map[_f .PdfObject ]_f .PdfObject );_daeb :=make (map[_f .PdfObject ]struct{});for _ ,_adeg :=range _bfa {_cee :=_adeg .Stream .PdfObjectDictionary .Get (_f .PdfObjectName ("\u0053\u004d\u0061s\u006b"));_daeb [_cee ]=struct{}{};};for _bbfd ,_fad :=range _bfa {_fea :=_fad .Stream ;if _ ,_dfd :=_daeb [_fea ];_dfd {continue ;};_ddbb ,_ggb :=_f .NewEncoderFromStream (_fea );if _ggb !=nil {_e .Log .Warning ("\u0045\u0072\u0072\u006f\u0072 \u0067\u0065\u0074\u0020\u0065\u006e\u0063\u006f\u0064\u0065\u0072\u0020\u0066o\u0072\u0020\u0074\u0068\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0025\u0073");continue ;};_aagc ,_ggb :=_ddbb .DecodeStream (_fea );if _ggb !=nil {_e .Log .Warning ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0074\u0068e\u0020i\u006d\u0061\u0067\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d\u0020\u0025\u0073");continue ;};_dbbg :=_f .NewDCTEncoder ();_dbbg .ColorComponents =_fad .ColorComponents ;_dbbg .Quality =_fbc .ImageQuality ;_dbbg .BitsPerComponent =_fad .BitsPerComponent ;_dbbg .Width =_fad .Width ;_dbbg .Height =_fad .Height ;_cfc ,_ggb :=_dbbg .EncodeBytes (_aagc );if _ggb !=nil {_e .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025v",_ggb );return nil ,_ggb ;};var _gfc _f .StreamEncoder ;_gfc =_dbbg ;{_eedb :=_f .NewFlateEncoder ();_bab :=_f .NewMultiEncoder ();_bab .AddEncoder (_eedb );_bab .AddEncoder (_dbbg );_ddagb ,_fgca :=_bab .EncodeBytes (_aagc );if _fgca !=nil {return nil ,_fgca ;};if len (_ddagb )< len (_cfc ){_e .Log .Debug ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063\u0020\u0069\u006d\u0070\u0072\u006f\u0076\u0065\u0073\u003a\u0020\u0025\u0064\u0020\u0074o\u0020\u0025\u0064\u0020\u0028o\u0072\u0069g\u0020\u0025\u0064\u0029",len (_cfc ),len (_ddagb ),len (_fea .Stream ));_cfc =_ddagb ;_gfc =_bab ;};};_egcg :=len (_fea .Stream );if _egcg < len (_cfc ){continue ;};_ggdd :=&_f .PdfObjectStream {Stream :_cfc };_ggdd .PdfObjectReference =_fea .PdfObjectReference ;_ggdd .PdfObjectDictionary =_f .MakeDict ();_ggdd .Merge (_fea .PdfObjectDictionary );_ggdd .Merge (_gfc .MakeStreamDict ());_ggdd .Set ("\u004c\u0065\u006e\u0067\u0074\u0068",_f .MakeInteger (int64 (len (_cfc ))));_cff [_fea ]=_ggdd ;_bfa [_bbfd ].Stream =_ggdd ;};_ffb =make ([]_f .PdfObject ,len (objects ));copy (_ffb ,objects );_bga (_ffb ,_cff );return _ffb ,nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_ebag *CleanFonts )Optimize (objects []_f .PdfObject )(_add []_f .PdfObject ,_ddb error ){var _aeb map[*_f .PdfObjectStream ]struct{};if _ebag .Subset {var _aff error ;_aeb ,_aff =_feg (objects );if _aff !=nil {return nil ,_aff ;};};for _ ,_ddd :=range objects {_bdag ,_ffc :=_f .GetStream (_ddd );if !_ffc {continue ;};if _ ,_faac :=_aeb [_bdag ];_faac {continue ;};_edf ,_dcdf :=_f .NewEncoderFromStream (_bdag );if _dcdf !=nil {_e .Log .Debug ("\u0045\u0052RO\u0052\u0020\u0067e\u0074\u0074\u0069\u006eg e\u006eco\u0064\u0065\u0072\u003a\u0020\u0025\u0076 -\u0020\u0069\u0067\u006e\u006f\u0072\u0069n\u0067",_dcdf );continue ;};_dcb ,_dcdf :=_edf .DecodeStream (_bdag );if _dcdf !=nil {_e .Log .Debug ("\u0044\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0065r\u0072\u006f\u0072\u0020\u003a\u0020\u0025v\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069\u006e\u0067",_dcdf );continue ;};if len (_dcb )< 4{continue ;};_cab :=string (_dcb [:4]);if _cab =="\u004f\u0054\u0054\u004f"{continue ;};if _cab !="\u0000\u0001\u0000\u0000"&&_cab !="\u0074\u0072\u0075\u0065"{continue ;};_dgga ,_dcdf :=_abg .Parse (_fgd .NewReader (_dcb ));if _dcdf !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020P\u0061\u0072\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_dcdf );continue ;};_dcdf =_dgga .Optimize ();if _dcdf !=nil {continue ;};var _dggc _fgd .Buffer ;_dcdf =_dgga .Write (&_dggc );if _dcdf !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u0020W\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_dcdf );continue ;};if _dggc .Len ()> len (_dcb ){_e .Log .Debug ("\u0052\u0065-\u0077\u0072\u0069\u0074\u0074\u0065\u006e\u0020\u0066\u006f\u006e\u0074\u0020\u0069\u0073\u0020\u006c\u0061\u0072\u0067\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u002d\u0020\u0073\u006b\u0069\u0070");continue ;};_gbg ,_dcdf :=_f .MakeStream (_dggc .Bytes (),_f .NewFlateEncoder ());if _dcdf !=nil {continue ;};*_bdag =*_gbg ;_bdag .Set ("\u004ce\u006e\u0067\u0074\u0068\u0031",_f .MakeInteger (int64 (_dggc .Len ())));};return objects ,nil ;};
|
||||
|
||||
// Image optimizes images by rewrite images into JPEG format with quality equals to ImageQuality.
|
||||
// TODO(a5i): Add support for inline images.
|
||||
// It implements interface model.Optimizer.
|
||||
type Image struct{ImageQuality int ;};func _bbg (_gdg *_f .PdfObjectStream ,_afff float64 )error {_bbfa ,_ddaf :=_fb .NewXObjectImageFromStream (_gdg );if _ddaf !=nil {return _ddaf ;};_gbb ,_ddaf :=_bbfa .ToImage ();if _ddaf !=nil {return _ddaf ;};_dec ,_ddaf :=_gbb .ToGoImage ();if _ddaf !=nil {return _ddaf ;};_fcbd :=int (_d .RoundToEven (float64 (_gbb .Width )*_afff ));_gaf :=int (_d .RoundToEven (float64 (_gbb .Height )*_afff ));_edff :=_gg .Rect (0,0,_fcbd ,_gaf );var _fag _fg .Image ;var _ccff func (_gg .Image )(*_fb .Image ,error );switch _bbfa .ColorSpace .String (){case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_fag =_gg .NewRGBA (_edff );_ccff =_fb .ImageHandling .NewImageFromGoImage ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_fag =_gg .NewGray (_edff );_ccff =_fb .ImageHandling .NewGrayImageFromGoImage ;default:return _df .Errorf ("\u006f\u0070\u0074\u0069\u006d\u0069\u007a\u0061t\u0069\u006f\u006e i\u0073\u0020\u006e\u006f\u0074\u0020s\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065 \u0025\u0073",_bbfa .ColorSpace .String ());};_fg .CatmullRom .Scale (_fag ,_fag .Bounds (),_dec ,_dec .Bounds (),_fg .Over ,&_fg .Options {});if _gbb ,_ddaf =_ccff (_fag );_ddaf !=nil {return _ddaf ;};_ccgb :=_f .MakeDict ();_ccgb .Set ("\u0051u\u0061\u006c\u0069\u0074\u0079",_f .MakeInteger (100));_ccgb .Set ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr",_f .MakeInteger (1));_bbfa .Filter .UpdateParams (_ccgb );if _ddaf =_bbfa .SetImage (_gbb ,nil );_ddaf !=nil {return _ddaf ;};_bbfa .ToPdfObject ();return nil ;};
|
||||
|
||||
// CombineIdenticalIndirectObjects combines identical indirect objects.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineIdenticalIndirectObjects struct{};func _effb (_edc []_f .PdfObject )objectStructure {_deg :=objectStructure {};_cdg :=false ;for _ ,_cgfd :=range _edc {switch _cdda :=_cgfd .(type ){case *_f .PdfIndirectObject :_dbcb ,_ddgc :=_f .GetDict (_cdda );if !_ddgc {continue ;};_gdeg ,_ddgc :=_f .GetName (_dbcb .Get ("\u0054\u0079\u0070\u0065"));if !_ddgc {continue ;};switch _gdeg .String (){case "\u0043a\u0074\u0061\u006c\u006f\u0067":_deg ._egg =_dbcb ;_cdg =true ;};};if _cdg {break ;};};if !_cdg {return _deg ;};_cddc ,_gded :=_f .GetDict (_deg ._egg .Get ("\u0050\u0061\u0067e\u0073"));if !_gded {return _deg ;};_deg ._gcgc =_cddc ;_cda ,_gded :=_f .GetArray (_cddc .Get ("\u004b\u0069\u0064\u0073"));if !_gded {return _deg ;};for _ ,_cea :=range _cda .Elements (){_beea ,_agb :=_f .GetIndirect (_cea );if !_agb {break ;};_deg ._gdeb =append (_deg ._gdeb ,_beea );};return _deg ;};func _ecbca (_fda []_f .PdfObject ){for _ged ,_cagg :=range _fda {switch _ddgg :=_cagg .(type ){case *_f .PdfIndirectObject :_ddgg .ObjectNumber =int64 (_ged +1);_ddgg .GenerationNumber =0;case *_f .PdfObjectStream :_ddgg .ObjectNumber =int64 (_ged +1);_ddgg .GenerationNumber =0;case *_f .PdfObjectStreams :_ddgg .ObjectNumber =int64 (_ged +1);_ddgg .GenerationNumber =0;};};};func _eg (_fgdb *_f .PdfObjectStream )error {_ege ,_cc :=_f .DecodeStream (_fgdb );if _cc !=nil {return _cc ;};_eb :=_b .NewContentStreamParser (string (_ege ));_ca ,_cc :=_eb .Parse ();if _cc !=nil {return _cc ;};_ca =_ag (_ca );_caf :=_ca .Bytes ();if len (_caf )>=len (_ege ){return nil ;};_dda ,_cc :=_f .MakeStream (_ca .Bytes (),_f .NewFlateEncoder ());if _cc !=nil {return _cc ;};_fgdb .Stream =_dda .Stream ;_fgdb .Merge (_dda .PdfObjectDictionary );return nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_ade *CompressStreams )Optimize (objects []_f .PdfObject )(_eaf []_f .PdfObject ,_cgd error ){_eaf =make ([]_f .PdfObject ,len (objects ));copy (_eaf ,objects );for _ ,_eca :=range objects {_ffcb ,_ggd :=_f .GetStream (_eca );if !_ggd {continue ;};if _dae :=_ffcb .Get ("\u0046\u0069\u006c\u0074\u0065\u0072");_dae !=nil {if _ ,_ddac :=_f .GetName (_dae );_ddac {continue ;};if _cdd ,_bgd :=_f .GetArray (_dae );_bgd &&_cdd .Len ()> 0{continue ;};};_gabd :=_f .NewFlateEncoder ();var _fcf []byte ;_fcf ,_cgd =_gabd .EncodeBytes (_ffcb .Stream );if _cgd !=nil {return _eaf ,_cgd ;};_bff :=_gabd .MakeStreamDict ();if len (_fcf )+len (_bff .WriteString ())< len (_ffcb .Stream ){_ffcb .Stream =_fcf ;_ffcb .PdfObjectDictionary .Merge (_bff );_ffcb .PdfObjectDictionary .Set ("\u004c\u0065\u006e\u0067\u0074\u0068",_f .MakeInteger (int64 (len (_ffcb .Stream ))));};};return _eaf ,nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_gabf *CombineIdenticalIndirectObjects )Optimize (objects []_f .PdfObject )(_cbbe []_f .PdfObject ,_gcce error ){_ecbca (objects );_gfb :=make (map[_f .PdfObject ]_f .PdfObject );_bge :=make (map[_f .PdfObject ]struct{});_ecc :=make (map[string ][]*_f .PdfIndirectObject );for _ ,_fce :=range objects {_ccfa ,_cac :=_fce .(*_f .PdfIndirectObject );if !_cac {continue ;};if _adcd ,_gfe :=_ccfa .PdfObject .(*_f .PdfObjectDictionary );_gfe {if _bfgg ,_ggg :=_adcd .Get ("\u0054\u0079\u0070\u0065").(*_f .PdfObjectName );_ggg &&*_bfgg =="\u0050\u0061\u0067\u0065"{continue ;};_edg :=_a .New ();_edg .Write ([]byte (_adcd .WriteString ()));_ea :=string (_edg .Sum (nil ));_ecc [_ea ]=append (_ecc [_ea ],_ccfa );};};for _ ,_cbbg :=range _ecc {if len (_cbbg )< 2{continue ;};_dea :=_cbbg [0];for _cg :=1;_cg < len (_cbbg );_cg ++{_fceb :=_cbbg [_cg ];_gfb [_fceb ]=_dea ;_bge [_fceb ]=struct{}{};};};_cbbe =make ([]_f .PdfObject ,0,len (objects )-len (_bge ));for _ ,_bgc :=range objects {if _ ,_gbf :=_bge [_bgc ];_gbf {continue ;};_cbbe =append (_cbbe ,_bgc );};_bga (_cbbe ,_gfb );return _cbbe ,nil ;};func _ag (_gga *_b .ContentStreamOperations )*_b .ContentStreamOperations {if _gga ==nil {return nil ;};_ba :=_b .ContentStreamOperations {};for _ ,_bd :=range *_gga {switch _bd .Operand {case "\u0042\u0044\u0043","\u0042\u004d\u0043","\u0045\u004d\u0043":continue ;case "\u0054\u006d":if len (_bd .Params )==6{if _ga ,_aba :=_f .GetNumbersAsFloat (_bd .Params );_aba ==nil {if _ga [0]==1&&_ga [1]==0&&_ga [2]==0&&_ga [3]==1{_bd =&_b .ContentStreamOperation {Params :[]_f .PdfObject {_bd .Params [4],_bd .Params [5]},Operand :"\u0054\u0064"};};};};};_ba =append (_ba ,_bd );};return &_ba ;};
|
||||
|
||||
// Append appends optimizers to the chain.
|
||||
func (_dd *Chain )Append (optimizers ..._fb .Optimizer ){_dd ._c =append (_dd ._c ,optimizers ...)};
|
||||
|
||||
// Options describes PDF optimization parameters.
|
||||
type Options struct{CombineDuplicateStreams bool ;CombineDuplicateDirectObjects bool ;ImageUpperPPI float64 ;ImageQuality int ;UseObjectStreams bool ;CombineIdenticalIndirectObjects bool ;CompressStreams bool ;CleanFonts bool ;SubsetFonts bool ;CleanContentstream bool ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_aedc *CombineDuplicateStreams )Optimize (objects []_f .PdfObject )(_ceb []_f .PdfObject ,_cded error ){_dfc :=make (map[_f .PdfObject ]_f .PdfObject );_cag :=make (map[_f .PdfObject ]struct{});_efa :=make (map[string ][]*_f .PdfObjectStream );for _ ,_dcda :=range objects {if _fgf ,_gfg :=_dcda .(*_f .PdfObjectStream );_gfg {_fde :=_a .New ();_fde .Write ([]byte (_fgf .Stream ));_daa :=string (_fde .Sum (nil ));_efa [_daa ]=append (_efa [_daa ],_fgf );};};for _ ,_aacg :=range _efa {if len (_aacg )< 2{continue ;};_gcd :=_aacg [0];for _ecg :=1;_ecg < len (_aacg );_ecg ++{_ccc :=_aacg [_ecg ];_dfc [_ccc ]=_gcd ;_cag [_ccc ]=struct{}{};};};_ceb =make ([]_f .PdfObject ,0,len (objects )-len (_cag ));for _ ,_efd :=range objects {if _ ,_gbe :=_cag [_efd ];_gbe {continue ;};_ceb =append (_ceb ,_efd );};_bga (_ceb ,_dfc );return _ceb ,nil ;};
|
||||
|
||||
// Chain allows to use sequence of optimizers.
|
||||
// It implements interface model.Optimizer.
|
||||
type Chain struct{_c []_fb .Optimizer };func _beed (_cge []_f .PdfObject )[]*imageInfo {_ddag :=_f .PdfObjectName ("\u0053u\u0062\u0074\u0079\u0070\u0065");_gge :=make (map[*_f .PdfObjectStream ]struct{});var _bbf error ;var _def []*imageInfo ;for _ ,_aeg :=range _cge {_ecbc ,_bfe :=_f .GetStream (_aeg );if !_bfe {continue ;};if _ ,_fdb :=_gge [_ecbc ];_fdb {continue ;};_gge [_ecbc ]=struct{}{};_agd :=_ecbc .PdfObjectDictionary .Get (_ddag );_abd ,_bfe :=_f .GetName (_agd );if !_bfe ||string (*_abd )!="\u0049\u006d\u0061g\u0065"{continue ;};_bgcg :=&imageInfo {BitsPerComponent :8,Stream :_ecbc };if _bgcg .ColorSpace ,_bbf =_fb .DetermineColorspaceNameFromPdfObject (_ecbc .PdfObjectDictionary .Get ("\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065"));_bbf !=nil {_e .Log .Error ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u0025\u0073",_bbf );continue ;};if _gee ,_cdb :=_f .GetIntVal (_ecbc .PdfObjectDictionary .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074"));_cdb {_bgcg .BitsPerComponent =_gee ;};if _ccg ,_cbaec :=_f .GetIntVal (_ecbc .PdfObjectDictionary .Get ("\u0057\u0069\u0064t\u0068"));_cbaec {_bgcg .Width =_ccg ;};if _dbgc ,_adcg :=_f .GetIntVal (_ecbc .PdfObjectDictionary .Get ("\u0048\u0065\u0069\u0067\u0068\u0074"));_adcg {_bgcg .Height =_dbgc ;};switch _bgcg .ColorSpace {case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_bgcg .ColorComponents =3;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_bgcg .ColorComponents =1;default:_e .Log .Warning ("\u004f\u0070\u0074\u0069\u006d\u0069\u007a\u0061t\u0069\u006f\u006e i\u0073\u0020\u006e\u006f\u0074\u0020s\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065 \u0025\u0073",_bgcg .ColorSpace );continue ;};_def =append (_def ,_bgcg );};return _def ;};func _bga (_dgae []_f .PdfObject ,_fca map[_f .PdfObject ]_f .PdfObject ){if _fca ==nil ||len (_fca )==0{return ;};for _dac ,_agg :=range _dgae {if _abc ,_fbgfa :=_fca [_agg ];_fbgfa {_dgae [_dac ]=_abc ;continue ;};_fca [_agg ]=_agg ;switch _adbc :=_agg .(type ){case *_f .PdfObjectArray :_fffd :=make ([]_f .PdfObject ,_adbc .Len ());copy (_fffd ,_adbc .Elements ());_bga (_fffd ,_fca );for _ceed ,_bgag :=range _fffd {_adbc .Set (_ceed ,_bgag );};case *_f .PdfObjectStreams :_bga (_adbc .Elements (),_fca );case *_f .PdfObjectStream :_bfeb :=[]_f .PdfObject {_adbc .PdfObjectDictionary };_bga (_bfeb ,_fca );_adbc .PdfObjectDictionary =_bfeb [0].(*_f .PdfObjectDictionary );case *_f .PdfObjectDictionary :_gef :=_adbc .Keys ();_bdd :=make ([]_f .PdfObject ,len (_gef ));for _dbgb ,_ebcba :=range _gef {_bdd [_dbgb ]=_adbc .Get (_ebcba );};_bga (_bdd ,_fca );for _ecd ,_dbfe :=range _gef {_adbc .Set (_dbfe ,_bdd [_ecd ]);};case *_f .PdfIndirectObject :_gbag :=[]_f .PdfObject {_adbc .PdfObject };_bga (_gbag ,_fca );_adbc .PdfObject =_gbag [0];};};};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_be *Chain )Optimize (objects []_f .PdfObject )(_gf []_f .PdfObject ,_bf error ){_gf =objects ;for _ ,_fc :=range _be ._c {_gf ,_bf =_fc .Optimize (_gf );if _bf !=nil {return _gf ,_bf ;};};return _gf ,nil ;};
|
||||
|
||||
// CombineDuplicateDirectObjects combines duplicated direct objects by its data hash.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineDuplicateDirectObjects struct{};
|
||||
|
||||
// CombineDuplicateStreams combines duplicated streams by its data hash.
|
||||
// It implements interface model.Optimizer.
|
||||
type CombineDuplicateStreams struct{};func _dbf (_bdgc _f .PdfObject )[]content {if _bdgc ==nil {return nil ;};_aaca ,_ebc :=_f .GetArray (_bdgc );if !_ebc {_e .Log .Debug ("\u0041\u006e\u006e\u006fts\u0020\u006e\u006f\u0074\u0020\u0061\u006e\u0020\u0061\u0072\u0072\u0061\u0079");return nil ;};var _adc []content ;for _ ,_aec :=range _aaca .Elements (){_befa ,_fae :=_f .GetDict (_aec );if !_fae {_e .Log .Debug ("I\u0067\u006e\u006f\u0072\u0069\u006eg\u0020\u006e\u006f\u006e\u002d\u0064i\u0063\u0074\u0020\u0065\u006c\u0065\u006de\u006e\u0074\u0020\u0069\u006e\u0020\u0041\u006e\u006e\u006ft\u0073");continue ;};_cce ,_fae :=_f .GetDict (_befa .Get ("\u0041\u0050"));if !_fae {_e .Log .Debug ("\u004e\u006f\u0020\u0041P \u0065\u006e\u0074\u0072\u0079\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067");continue ;};_ce :=_f .TraceToDirectObject (_cce .Get ("\u004e"));if _ce ==nil {_e .Log .Debug ("N\u006f\u0020\u004e\u0020en\u0074r\u0079\u0020\u002d\u0020\u0073k\u0069\u0070\u0070\u0069\u006e\u0067");continue ;};var _aab *_f .PdfObjectStream ;switch _gcc :=_ce .(type ){case *_f .PdfObjectDictionary :_aad ,_fdfd :=_f .GetName (_befa .Get ("\u0041\u0053"));if !_fdfd {_e .Log .Debug ("\u004e\u006f\u0020\u0041S \u0065\u006e\u0074\u0072\u0079\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069n\u0067");continue ;};_aab ,_fdfd =_f .GetStream (_gcc .Get (*_aad ));if !_fdfd {_e .Log .Debug ("\u0046o\u0072\u006d\u0020\u006eo\u0074\u0020\u0066\u006f\u0075n\u0064 \u002d \u0073\u006b\u0069\u0070\u0070\u0069\u006eg");continue ;};case *_f .PdfObjectStream :_aab =_gcc ;};if _aab ==nil {_e .Log .Debug ("\u0046\u006f\u0072m\u0020\u006e\u006f\u0074 \u0066\u006f\u0075\u006e\u0064\u0020\u0028n\u0069\u006c\u0029\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067");continue ;};_aaa ,_gce :=_fb .NewXObjectFormFromStream (_aab );if _gce !=nil {_e .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020l\u006f\u0061\u0064\u0069\u006e\u0067\u0020\u0066\u006f\u0072\u006d\u003a\u0020%\u0076\u0020\u002d\u0020\u0069\u0067\u006eo\u0072\u0069\u006e\u0067",_gce );continue ;};_abee ,_gce :=_aaa .GetContentStream ();if _gce !=nil {_e .Log .Debug ("E\u0072\u0072\u006f\u0072\u0020\u0064e\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0063\u006fn\u0074\u0065\u006et\u0073:\u0020\u0025\u0076",_gce );continue ;};_adc =append (_adc ,content {_fdg :string (_abee ),_ace :_aaa .Resources });};return _adc ;};
|
||||
|
||||
// New creates a optimizers chain from options.
|
||||
func New (options Options )*Chain {_fgfd :=new (Chain );if options .CleanFonts ||options .SubsetFonts {_fgfd .Append (&CleanFonts {Subset :options .SubsetFonts });};if options .CleanContentstream {_fgfd .Append (new (CleanContentstream ));};if options .ImageUpperPPI > 0{_cged :=new (ImagePPI );_cged .ImageUpperPPI =options .ImageUpperPPI ;_fgfd .Append (_cged );};if options .ImageQuality > 0{_dcbeb :=new (Image );_dcbeb .ImageQuality =options .ImageQuality ;_fgfd .Append (_dcbeb );};if options .CombineDuplicateDirectObjects {_fgfd .Append (new (CombineDuplicateDirectObjects ));};if options .CombineDuplicateStreams {_fgfd .Append (new (CombineDuplicateStreams ));};if options .CombineIdenticalIndirectObjects {_fgfd .Append (new (CombineIdenticalIndirectObjects ));};if options .UseObjectStreams {_fgfd .Append (new (ObjectStreams ));};if options .CompressStreams {_fgfd .Append (new (CompressStreams ));};return _fgfd ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_fgc *CleanContentstream )Optimize (objects []_f .PdfObject )(_bb []_f .PdfObject ,_fcg error ){_dc :=map[*_f .PdfObjectStream ]struct{}{};var _ebd []*_f .PdfObjectStream ;_dga :=func (_ef *_f .PdfObjectStream ){if _ ,_aa :=_dc [_ef ];!_aa {_dc [_ef ]=struct{}{};_ebd =append (_ebd ,_ef );};};for _ ,_ee :=range objects {switch _cd :=_ee .(type ){case *_f .PdfIndirectObject :switch _fd :=_cd .PdfObject .(type ){case *_f .PdfObjectDictionary :if _dcd ,_faa :=_f .GetName (_fd .Get ("\u0054\u0079\u0070\u0065"));!_faa ||_dcd .String ()!="\u0050\u0061\u0067\u0065"{continue ;};if _ae ,_egb :=_f .GetStream (_fd .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_egb {_dga (_ae );}else if _dfb ,_ge :=_f .GetArray (_fd .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_ge {for _ ,_ed :=range _dfb .Elements (){if _fe ,_cbb :=_f .GetStream (_ed );_cbb {_dga (_fe );};};};};case *_f .PdfObjectStream :if _cf ,_bee :=_f .GetName (_cd .Get ("\u0054\u0079\u0070\u0065"));!_bee ||_cf .String ()!="\u0058O\u0062\u006a\u0065\u0063\u0074"{continue ;};if _bc ,_aed :=_f .GetName (_cd .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));!_aed ||_bc .String ()!="\u0046\u006f\u0072\u006d"{continue ;};_dga (_cd );};};for _ ,_aag :=range _ebd {_fcg =_eg (_aag );if _fcg !=nil {return nil ,_fcg ;};};return objects ,nil ;};
|
||||
|
||||
// Optimize optimizes PDF objects to decrease PDF size.
|
||||
func (_bdf *CombineDuplicateDirectObjects )Optimize (objects []_f .PdfObject )(_ggac []_f .PdfObject ,_bcg error ){_ecbca (objects );_gfa :=make (map[string ][]*_f .PdfObjectDictionary );var _ffa func (_cde *_f .PdfObjectDictionary );_ffa =func (_ddg *_f .PdfObjectDictionary ){for _ ,_fff :=range _ddg .Keys (){_dgad :=_ddg .Get (_fff );if _beg ,_dddg :=_dgad .(*_f .PdfObjectDictionary );_dddg {_ddec :=_a .New ();_ddec .Write ([]byte (_beg .WriteString ()));_fbd :=string (_ddec .Sum (nil ));_gfa [_fbd ]=append (_gfa [_fbd ],_beg );_ffa (_beg );};};};for _ ,_bbb :=range objects {_eeg ,_bde :=_bbb .(*_f .PdfIndirectObject );if !_bde {continue ;};if _fbgf ,_de :=_eeg .PdfObject .(*_f .PdfObjectDictionary );_de {_ffa (_fbgf );};};_fac :=make ([]_f .PdfObject ,0,len (_gfa ));_bfg :=make (map[_f .PdfObject ]_f .PdfObject );for _ ,_da :=range _gfa {if len (_da )< 2{continue ;};_fbf :=_f .MakeDict ();_fbf .Merge (_da [0]);_bbd :=_f .MakeIndirectObject (_fbf );_fac =append (_fac ,_bbd );for _ecb :=0;_ecb < len (_da );_ecb ++{_caa :=_da [_ecb ];_bfg [_caa ]=_bbd ;};};_ggac =make ([]_f .PdfObject ,len (objects ));copy (_ggac ,objects );_ggac =append (_fac ,_ggac ...);_bga (_ggac ,_bfg );return _ggac ,nil ;};
|
||||
func (_fgd *CleanContentstream )Optimize (objects []_e .PdfObject )(_fd []_e .PdfObject ,_dg error ){_ecd :=map[*_e .PdfObjectStream ]struct{}{};var _gc []*_e .PdfObjectStream ;_bdc :=func (_ebd *_e .PdfObjectStream ){if _ ,_dgd :=_ecd [_ebd ];!_dgd {_ecd [_ebd ]=struct{}{};_gc =append (_gc ,_ebd );};};for _ ,_dd :=range objects {switch _agb :=_dd .(type ){case *_e .PdfIndirectObject :switch _bg :=_agb .PdfObject .(type ){case *_e .PdfObjectDictionary :if _ad ,_bb :=_e .GetName (_bg .Get ("\u0054\u0079\u0070\u0065"));!_bb ||_ad .String ()!="\u0050\u0061\u0067\u0065"{continue ;};if _ea ,_bca :=_e .GetStream (_bg .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_bca {_bdc (_ea );}else if _af ,_eaa :=_e .GetArray (_bg .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));_eaa {for _ ,_eaf :=range _af .Elements (){if _eeg ,_cd :=_e .GetStream (_eaf );_cd {_bdc (_eeg );};};};};case *_e .PdfObjectStream :if _cc ,_agbb :=_e .GetName (_agb .Get ("\u0054\u0079\u0070\u0065"));!_agbb ||_cc .String ()!="\u0058O\u0062\u006a\u0065\u0063\u0074"{continue ;};if _gac ,_afe :=_e .GetName (_agb .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));!_afe ||_gac .String ()!="\u0046\u006f\u0072\u006d"{continue ;};_bdc (_agb );};};for _ ,_cae :=range _gc {_dg =_ag (_cae );if _dg !=nil {return nil ,_dg ;};};return objects ,nil ;};
|
||||
|
||||
// CleanFonts cleans up embedded fonts, reducing font sizes.
|
||||
type CleanFonts struct{
|
||||
|
||||
// Subset embedded fonts if encountered (if true).
|
||||
// Otherwise attempts to reduce the font program.
|
||||
Subset bool ;};func _bba (_gba *_f .PdfObjectStream ,_dbb []rune ,_ec []_abg .GlyphIndex )error {_gba ,_ecf :=_f .GetStream (_gba );if !_ecf {_e .Log .Debug ("\u0045\u006d\u0062\u0065\u0064\u0064\u0065\u0064\u0020\u0066\u006f\u006e\u0074\u0020\u006f\u0062\u006a\u0065c\u0074\u0020\u006e\u006f\u0074\u0020\u0066o\u0075\u006e\u0064\u0020\u002d\u002d\u0020\u0041\u0042\u004f\u0052T\u0020\u0073\u0075\u0062\u0073\u0065\u0074\u0074\u0069\u006e\u0067");return _fa .New ("\u0066\u006f\u006e\u0074fi\u006c\u0065\u0032\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064");};_aee ,_cae :=_f .DecodeStream (_gba );if _cae !=nil {_e .Log .Debug ("\u0044\u0065c\u006f\u0064\u0065 \u0065\u0072\u0072\u006f\u0072\u003a\u0020\u0025\u0076",_cae );return _cae ;};_acc ,_cae :=_abg .Parse (_fgd .NewReader (_aee ));if _cae !=nil {_e .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0070\u0061\u0072\u0073\u0069n\u0067\u0020\u0025\u0064\u0020\u0062\u0079\u0074\u0065\u0020f\u006f\u006e\u0074",len (_gba .Stream ));return _cae ;};_gde :=_ec ;if len (_dbb )> 0{_bdg :=_acc .LookupRunes (_dbb );_gde =append (_gde ,_bdg ...);};_acc ,_cae =_acc .SubsetKeepIndices (_gde );if _cae !=nil {_e .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020s\u0075\u0062\u0073\u0065\u0074t\u0069n\u0067 \u0066\u006f\u006e\u0074\u003a\u0020\u0025v",_cae );return _cae ;};var _fegf _fgd .Buffer ;_cae =_acc .Write (&_fegf );if _cae !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004fR \u0057\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076",_cae );return _cae ;};if _fegf .Len ()> len (_aee ){_e .Log .Debug ("\u0052\u0065-\u0077\u0072\u0069\u0074\u0074\u0065\u006e\u0020\u0066\u006f\u006e\u0074\u0020\u0069\u0073\u0020\u006c\u0061\u0072\u0067\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u006f\u0072\u0069\u0067\u0069\u006e\u0061\u006c\u0020\u002d\u0020\u0073\u006b\u0069\u0070");return nil ;};_dgg ,_cae :=_f .MakeStream (_fegf .Bytes (),_f .NewFlateEncoder ());if _cae !=nil {_e .Log .Debug ("\u0045\u0052\u0052\u004fR \u0057\u0072\u0069\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u003a\u0020%\u0076",_cae );return _cae ;};*_gba =*_dgg ;_gba .Set ("\u004ce\u006e\u0067\u0074\u0068\u0031",_f .MakeInteger (int64 (_fegf .Len ())));return nil ;};func _ecab (_effba _f .PdfObject )(_eab string ,_feaa []_f .PdfObject ){var _egf _fgd .Buffer ;switch _cfd :=_effba .(type ){case *_f .PdfIndirectObject :_feaa =append (_feaa ,_cfd );_effba =_cfd .PdfObject ;};switch _gadf :=_effba .(type ){case *_f .PdfObjectStream :if _bed ,_ded :=_f .DecodeStream (_gadf );_ded ==nil {_egf .Write (_bed );_feaa =append (_feaa ,_gadf );};case *_f .PdfObjectArray :for _ ,_fcd :=range _gadf .Elements (){switch _cfde :=_fcd .(type ){case *_f .PdfObjectStream :if _dge ,_ggeg :=_f .DecodeStream (_cfde );_ggeg ==nil {_egf .Write (_dge );_feaa =append (_feaa ,_cfde );};};};};return _egf .String (),_feaa ;};type imageInfo struct{ColorSpace _f .PdfObjectName ;BitsPerComponent int ;ColorComponents int ;Width int ;Height int ;Stream *_f .PdfObjectStream ;PPI float64 ;};
|
||||
Subset bool ;};
|
||||
|
||||
// CompressStreams compresses uncompressed streams.
|
||||
// It implements interface model.Optimizer.
|
||||
type CompressStreams struct{};
|
||||
|
||||
// ObjectStreams groups PDF objects to object streams.
|
||||
// It implements interface model.Optimizer.
|
||||
type ObjectStreams struct{};
|
||||
type CompressStreams struct{};type imageInfo struct{ColorSpace _e .PdfObjectName ;BitsPerComponent int ;ColorComponents int ;Width int ;Height int ;Stream *_e .PdfObjectStream ;PPI float64 ;};
|
@ -10,24 +10,26 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package sighandler implements digital signature handlers for PDF signature validation and signing.
|
||||
package sighandler ;import (_g "bytes";_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";);
|
||||
package sighandler ;import (_f "bytes";_gd "crypto";_ge "crypto/rand";_fd "crypto/rsa";_ddb "crypto/x509";_de "crypto/x509/pkix";_b "encoding/asn1";_ddf "errors";_gdg "fmt";_gg "github.com/unidoc/pkcs7";_bg "github.com/unidoc/timestamp";_fce "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";_dd "hash";_a "io";_c "io/ioutil";_g "net/http";_fc "time";);
|
||||
|
||||
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobePKCS7Detached (privateKey *_fd .PrivateKey ,certificate *_ddb .Certificate )(_e .SignatureHandler ,error ){return &adobePKCS7Detached {_fg :certificate ,_fe :privateKey },nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_ebb *adobeX509RSASHA1 )IsApplicable (sig *_e .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};func (_dc *adobePKCS7Detached )getCertificate (_cf *_e .PdfSignature )(*_ddb .Certificate ,error ){if _dc ._fg !=nil {return _dc ._fg ,nil ;};var _fa []byte ;switch _bb :=_cf .Cert .(type ){case *_fce .PdfObjectString :_fa =_bb .Bytes ();case *_fce .PdfObjectArray :if _bb .Len ()==0{return nil ,_ddf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_be :=range _bb .Elements (){_bde ,_bf :=_fce .GetString (_be );if !_bf {return nil ,_gdg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_be );};_fa =append (_fa ,_bde .Bytes ()...);};default:return nil ,_gdg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bb );};_ggb ,_fb :=_ddb .ParseCertificates (_fa );if _fb !=nil {return nil ,_fb ;};return _ggb [0],nil ;};
|
||||
|
||||
// Sign sets the Contents fields.
|
||||
func (_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 ;};
|
||||
func (_ef *adobePKCS7Detached )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {if _ef ._gdgd {_dcc :=_ef ._fdc ;if _dcc <=0{_dcc =8192;};sig .Contents =_fce .MakeHexString (string (make ([]byte ,_dcc )));return nil ;};_ded :=digest .(*_f .Buffer );_ab ,_ggbd :=_gg .NewSignedData (_ded .Bytes ());if _ggbd !=nil {return _ggbd ;};if _ae :=_ab .AddSigner (_ef ._fg ,_ef ._fe ,_gg .SignerInfoConfig {});_ae !=nil {return _ae ;};_ab .Detach ();_fed ,_ggbd :=_ab .Finish ();if _ggbd !=nil {return _ggbd ;};_bdf :=make ([]byte ,8192);copy (_bdf ,_fed );sig .Contents =_fce .MakeHexString (string (_bdf ));return nil ;};
|
||||
|
||||
// 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 ;};
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_efe *docTimeStamp )IsApplicable (sig *_e .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_gc *docTimeStamp )NewDigest (sig *_ecd .PdfSignature )(_ecd .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
|
||||
func (_eb *adobePKCS7Detached )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){return _f .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 ;};
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_gacg *docTimeStamp )InitSignature (sig *_e .PdfSignature )error {_dfc :=*_gacg ;sig .Handler =&_dfc ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _gacg ._da > 0{sig .Contents =_fce .MakeHexString (string (make ([]byte ,_gacg ._da )));}else {_bbb ,_fae :=_gacg .NewDigest (sig );if _fae !=nil {return _fae ;};_bbb .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));if _fae =_dfc .Sign (sig ,_bbb );_fae !=nil {return _fae ;};_gacg ._da =_dfc ._da ;};return nil ;};type adobeX509RSASHA1 struct{_gf *_fd .PrivateKey ;_gdgdb *_ddb .Certificate ;_fad SignFunc ;};
|
||||
|
||||
// DocTimeStampOpts defines options for configuring the timestamp handler.
|
||||
type DocTimeStampOpts struct{
|
||||
@ -39,42 +41,32 @@ type DocTimeStampOpts struct{
|
||||
// signature.
|
||||
SignatureSize int ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_gee *docTimeStamp )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_dad :=sig .Contents .Bytes ();_ebdbb ,_def :=_gg .Parse (_dad );if _def !=nil {return _e .SignatureValidationResult {},_def ;};if _def =_ebdbb .Verify ();_def !=nil {return _e .SignatureValidationResult {},_def ;};var _cb timestampInfo ;_ ,_def =_b .Unmarshal (_ebdbb .Content ,&_cb );if _def !=nil {return _e .SignatureValidationResult {},_def ;};_ebf ,_def :=_db (_cb .MessageImprint .HashAlgorithm .Algorithm );if _def !=nil {return _e .SignatureValidationResult {},_def ;};_cca :=_ebf .New ();_dgd :=digest .(*_f .Buffer );_cca .Write (_dgd .Bytes ());_ccf :=_cca .Sum (nil );_bge :=_e .SignatureValidationResult {IsSigned :true ,IsVerified :_f .Equal (_ccf ,_cb .MessageImprint .HashedMessage ),GeneralizedTime :_cb .GeneralizedTime };return _bge ,nil ;};func _db (_aed _b .ObjectIdentifier )(_gd .Hash ,error ){switch {case _aed .Equal (_gg .OIDDigestAlgorithmSHA1 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA1 ),_aed .Equal (_gg .OIDDigestAlgorithmDSA ),_aed .Equal (_gg .OIDDigestAlgorithmDSASHA1 ),_aed .Equal (_gg .OIDEncryptionAlgorithmRSA ):return _gd .SHA1 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA256 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA256 ):return _gd .SHA256 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA384 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA384 ):return _gd .SHA384 ,nil ;case _aed .Equal (_gg .OIDDigestAlgorithmSHA512 ),_aed .Equal (_gg .OIDDigestAlgorithmECDSASHA512 ):return _gd .SHA512 ,nil ;};return _gd .Hash (0),_gg .ErrUnsupportedAlgorithm ;};type timestampInfo struct{Version int ;Policy _b .RawValue ;MessageImprint struct{HashAlgorithm _de .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _b .RawValue ;GeneralizedTime _fc .Time ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_baa *adobePKCS7Detached )NewDigest (sig *_ecd .PdfSignature )(_ecd .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
|
||||
func (_bee *docTimeStamp )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){return _f .NewBuffer (nil ),nil ;};
|
||||
|
||||
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler
|
||||
// with a custom signing function. Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1Custom (certificate *_ddb .Certificate ,signFunc SignFunc )(_e .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gdgdb :certificate ,_fad :signFunc },nil ;};
|
||||
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_dfg *_e .PdfSignature ,_ddc _e .Hasher )([]byte ,error );
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
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.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _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";};
|
||||
func (_fee *adobeX509RSASHA1 )InitSignature (sig *_e .PdfSignature )error {if _fee ._gdgdb ==nil {return _ddf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _fee ._gf ==nil &&_fee ._fad ==nil {return _ddf .New ("\u006d\u0075\u0073\u0074\u0020\u0070\u0072o\u0076\u0069\u0064e\u0020\u0065\u0069t\u0068\u0065r\u0020\u0061\u0020\u0070\u0072\u0069v\u0061te\u0020\u006b\u0065\u0079\u0020\u006f\u0072\u0020\u0061\u0020\u0073\u0069\u0067\u006e\u0069\u006e\u0067\u0020\u0066\u0075\u006e\u0063\u0074\u0069\u006f\u006e");};_ebd :=*_fee ;sig .Handler =&_ebd ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_fce .MakeString (string (_ebd ._gdgdb .Raw ));sig .Reference =nil ;_ga ,_faa :=_ebd .NewDigest (sig );if _faa !=nil {return _faa ;};_ga .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _ebd .Sign (sig ,_ga );};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_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 (_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 ;};
|
||||
func (_acg *docTimeStamp )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {_adf :=digest .(*_f .Buffer );_gacd :=_acg ._ffg .New ();if _ ,_fde :=_a .Copy (_gacd ,_adf );_fde !=nil {return _fde ;};_cdc :=_bg .Request {HashAlgorithm :_acg ._ffg ,HashedMessage :_gacd .Sum (nil ),Certificates :true ,Extensions :nil ,ExtraExtensions :nil };_ggfg ,_feg :=_cdc .Marshal ();if _feg !=nil {return _feg ;};_agg ,_feg :=_g .Post (_acg ._cd ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_f .NewBuffer (_ggfg ));if _feg !=nil {return _feg ;};defer _agg .Body .Close ();_ffae ,_feg :=_c .ReadAll (_agg .Body );if _feg !=nil {return _feg ;};if _agg .StatusCode !=_g .StatusOK {return _gdg .Errorf ("\u0068\u0074\u0074\u0070\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064e\u0020n\u006f\u0074\u0020\u006f\u006b\u0020\u0028\u0067\u006f\u0074\u0020\u0025\u0064\u0029",_agg .StatusCode );};var _gff struct{Version _b .RawValue ;Content _b .RawValue ;};if _ ,_feg =_b .Unmarshal (_ffae ,&_gff );_feg !=nil {return _feg ;};_afc :=len (_gff .Content .FullBytes );if _acg ._da > 0&&_afc > _acg ._da {return _e .ErrSignNotEnoughSpace ;};if _afc > 0{_acg ._da =_afc +128;};sig .Contents =_fce .MakeHexString (string (_gff .Content .FullBytes ));return nil ;};func (_aa *adobeX509RSASHA1 )getCertificate (_gac *_e .PdfSignature )(*_ddb .Certificate ,error ){if _aa ._gdgdb !=nil {return _aa ._gdgdb ,nil ;};var _gfg []byte ;switch _cfc :=_gac .Cert .(type ){case *_fce .PdfObjectString :_gfg =_cfc .Bytes ();case *_fce .PdfObjectArray :if _cfc .Len ()==0{return nil ,_ddf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_efb :=range _cfc .Elements (){_gace ,_gec :=_fce .GetString (_efb );if !_gec {return nil ,_gdg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_efb );};_gfg =append (_gfg ,_gace .Bytes ()...);};default:return nil ,_gdg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_cfc );};_ad ,_ce :=_ddb .ParseCertificates (_gfg );if _ce !=nil {return nil ,_ce ;};return _ad [0],nil ;};
|
||||
|
||||
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite adbe.x509.rsa_sha1 signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobeX509RSASHA1 (privateKey *_b .PrivateKey ,certificate *_add .Certificate )(_ecd .SignatureHandler ,error ){return &adobeX509RSASHA1 {_acc :certificate ,_ada :privateKey },nil ;};
|
||||
func NewAdobeX509RSASHA1 (privateKey *_fd .PrivateKey ,certificate *_ddb .Certificate )(_e .SignatureHandler ,error ){return &adobeX509RSASHA1 {_gdgdb :certificate ,_gf :privateKey },nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
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 ;};
|
||||
|
||||
// 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 ;};
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_ggf *adobeX509RSASHA1 )Sign (sig *_e .PdfSignature ,digest _e .Hasher )error {var _ebdb []byte ;var _ba error ;if _ggf ._fad !=nil {_ebdb ,_ba =_ggf ._fad (sig ,digest );if _ba !=nil {return _ba ;};}else {_fbe ,_afa :=digest .(_dd .Hash );if !_afa {return _ddf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_dg ,_ :=_aca (_ggf ._gdgdb .SignatureAlgorithm );_ebdb ,_ba =_fd .SignPKCS1v15 (_ge .Reader ,_ggf ._gf ,_dg ,_fbe .Sum (nil ));if _ba !=nil {return _ba ;};};_ebdb ,_ba =_b .Marshal (_ebdb );if _ba !=nil {return _ba ;};sig .Contents =_fce .MakeHexString (string (_ebdb ));return nil ;};type docTimeStamp struct{_cd string ;_ffg _gd .Hash ;_da int ;};
|
||||
|
||||
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
@ -84,24 +76,32 @@ func NewAdobePKCS7Detached (privateKey *_b .PrivateKey ,certificate *_add .Certi
|
||||
// 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 ;};
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _gd .Hash )(_e .SignatureHandler ,error ){return &docTimeStamp {_cd :timestampServerURL ,_ffg :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";};
|
||||
func (_ff *adobePKCS7Detached )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_df :=sig .Contents .Bytes ();_ea ,_ee :=_gg .Parse (_df );if _ee !=nil {return _e .SignatureValidationResult {},_ee ;};_bdg :=digest .(*_f .Buffer );_ea .Content =_bdg .Bytes ();if _ee =_ea .Verify ();_ee !=nil {return _e .SignatureValidationResult {},_ee ;};return _e .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
|
||||
// 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 ;};
|
||||
func NewEmptyAdobePKCS7Detached (signatureLen int )(_e .SignatureHandler ,error ){return &adobePKCS7Detached {_gdgd :true ,_fdc :signatureLen },nil ;};
|
||||
|
||||
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
|
||||
// specified options. If no options are provided, default options will be used.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _gd .Hash ,opts *DocTimeStampOpts )(_e .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_cd :timestampServerURL ,_ffg :hashAlgorithm ,_da :opts .SignatureSize },nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_bd *adobePKCS7Detached )InitSignature (sig *_e .PdfSignature )error {if !_bd ._gdgd {if _bd ._fg ==nil {return _ddf .New ("c\u0065\u0072\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u006d\u0075\u0073\u0074\u0020n\u006f\u0074\u0020b\u0065 \u006e\u0069\u006c");};if _bd ._fe ==nil {return _ddf .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_cg :=*_bd ;sig .Handler =&_cg ;sig .Filter =_fce .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_fce .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_ac ,_cge :=_cg .NewDigest (sig );if _cge !=nil {return _cge ;};_ac .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));return _cg .Sign (sig ,_ac );};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_dcg *adobePKCS7Detached )IsApplicable (sig *_e .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_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 ;};
|
||||
func (_cc *adobeX509RSASHA1 )Validate (sig *_e .PdfSignature ,digest _e .Hasher )(_e .SignatureValidationResult ,error ){_af ,_eg :=_cc .getCertificate (sig );if _eg !=nil {return _e .SignatureValidationResult {},_eg ;};_fdcb :=sig .Contents .Bytes ();var _fgg []byte ;if _ ,_ffa :=_b .Unmarshal (_fdcb ,&_fgg );_ffa !=nil {return _e .SignatureValidationResult {},_ffa ;};_bca ,_fcg :=digest .(_dd .Hash );if !_fcg {return _e .SignatureValidationResult {},_ddf .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_eaa ,_ :=_aca (_af .SignatureAlgorithm );if _gc :=_fd .VerifyPKCS1v15 (_af .PublicKey .(*_fd .PublicKey ),_eaa ,_bca .Sum (nil ),_fgg );_gc !=nil {return _e .SignatureValidationResult {},_gc ;};return _e .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};type adobePKCS7Detached struct{_fe *_fd .PrivateKey ;_fg *_ddb .Certificate ;_gdgd bool ;_fdc int ;};func _aca (_beb _ddb .SignatureAlgorithm )(_gd .Hash ,bool ){var _ca _gd .Hash ;switch _beb {case _ddb .SHA1WithRSA :_ca =_gd .SHA1 ;case _ddb .SHA256WithRSA :_ca =_gd .SHA256 ;case _ddb .SHA384WithRSA :_ca =_gd .SHA384 ;case _ddb .SHA512WithRSA :_ca =_gd .SHA512 ;default:return _gd .SHA1 ,false ;};return _ca ,true ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_aad *adobeX509RSASHA1 )NewDigest (sig *_e .PdfSignature )(_e .Hasher ,error ){_gab ,_gdf :=_aad .getCertificate (sig );if _gdf !=nil {return nil ,_gdf ;};_fff ,_ :=_aca (_gab .SignatureAlgorithm );return _fff .New (),nil ;};func (_daa *docTimeStamp )getCertificate (_ag *_e .PdfSignature )(*_ddb .Certificate ,error ){var _dfa []byte ;switch _bfg :=_ag .Cert .(type ){case *_fce .PdfObjectString :_dfa =_bfg .Bytes ();case *_fce .PdfObjectArray :if _bfg .Len ()==0{return nil ,_ddf .New ("\u006e\u006f\u0020s\u0069\u0067\u006e\u0061t\u0075\u0072\u0065\u0020\u0063\u0065\u0072t\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};for _ ,_bba :=range _bfg .Elements (){_agb ,_fab :=_fce .GetString (_bba );if !_fab {return nil ,_gdg .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0074\u0079p\u0065\u0020\u0069\u006e\u0020\u0073\u0069\u0067\u006e\u0061\u0074\u0075\u0072\u0065 \u0063\u0065r\u0074\u0069\u0066\u0069c\u0061\u0074\u0065\u0020\u0063h\u0061\u0069\u006e\u003a\u0020\u0025\u0054",_bba );};_dfa =append (_dfa ,_agb .Bytes ()...);};default:return nil ,_gdg .Errorf ("\u0069n\u0076\u0061l\u0069\u0064\u0020s\u0069\u0067\u006e\u0061\u0074\u0075\u0072e\u0020\u0063\u0065\u0072\u0074\u0069f\u0069\u0063\u0061\u0074\u0065\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0074\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bfg );};_afe ,_ddcb :=_ddb .ParseCertificates (_dfa );if _ddcb !=nil {return nil ,_ddcb ;};return _afe [0],nil ;};
|
@ -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 (_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";);
|
||||
package pdfutil ;import (_ef "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/contentstream";_bd "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/model";);
|
||||
|
||||
// NormalizePage performs the following operations on the passed in page:
|
||||
// - Normalize the page rotation.
|
||||
@ -24,4 +24,6 @@ package pdfutil ;import (_g "github.com/unidoc/unipdf/v3/common";_gc "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 *_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 ;};
|
||||
// NOTE: This function does not normalize annotations, outlines other parts
|
||||
// that are not part of the basic geometry and page content streams.
|
||||
func NormalizePage (page *_b .PdfPage )error {_fg ,_ecc :=page .GetMediaBox ();if _ecc !=nil {return _ecc ;};_bb :=page .Rotate ;_a :=_bb !=nil &&*_bb %360!=0&&*_bb %90==0;_fg .Normalize ();_ee ,_eg ,_bda ,_bg :=_fg .Llx ,_fg .Lly ,_fg .Width (),_fg .Height ();_af :=_ee !=0||_eg !=0;if !_a &&!_af {return nil ;};_c :=func (_d ,_eb ,_ab float64 )_bd .BoundingBox {return _bd .Path {Points :[]_bd .Point {_bd .NewPoint (0,0).Rotate (_ab ),_bd .NewPoint (_d ,0).Rotate (_ab ),_bd .NewPoint (0,_eb ).Rotate (_ab ),_bd .NewPoint (_d ,_eb ).Rotate (_ab )}}.GetBoundingBox ();};_g :=_ec .NewContentCreator ();var _ebb float64 ;if _a {_ebb =-float64 (*page .Rotate );_ce :=_c (_bda ,_bg ,_ebb );_g .Translate ((_ce .Width -_bda )/2+_bda /2,(_ce .Height -_bg )/2+_bg /2);_g .RotateDeg (_ebb );_g .Translate (-_bda /2,-_bg /2);_bda ,_bg =_ce .Width ,_ce .Height ;};if _af {_g .Translate (-_ee ,-_eg );};_de :=_g .Operations ();_cg ,_ecc :=_f .MakeStream (_de .Bytes (),_f .NewFlateEncoder ());if _ecc !=nil {return _ecc ;};_bdf :=_f .MakeArray (_cg );_bdf .Append (page .GetContentStreamObjs ()...);*_fg =_b .PdfRectangle {Urx :_bda ,Ury :_bg };if _ga :=page .CropBox ;_ga !=nil {_ga .Normalize ();_ebbd ,_ea ,_gg ,_gc :=_ga .Llx -_ee ,_ga .Lly -_eg ,_ga .Width (),_ga .Height ();if _a {_aa :=_c (_gg ,_gc ,_ebb );_gg ,_gc =_aa .Width ,_aa .Height ;};*_ga =_b .PdfRectangle {Llx :_ebbd ,Lly :_ea ,Urx :_ebbd +_gg ,Ury :_ea +_gc };};_ef .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ebb ,_de ,_fg );page .Contents =_bdf ;page .Rotate =nil ;return nil ;};
|
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