prepare release

This commit is contained in:
UniDoc Build 2021-02-22 02:29:48 +00:00
parent 2183fc2b02
commit ec7f5e55c3
48 changed files with 13245 additions and 5914 deletions

File diff suppressed because one or more lines are too long

View File

@ -10,96 +10,100 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package common contains common properties used by the subpackages.
package common ;import (_f "fmt";_af "io";_ab "os";_a "path/filepath";_d "runtime";_fc "time";);
package common ;import (_fa "fmt";_c "io";_b "os";_dc "path/filepath";_d "runtime";_e "time";);
// Debug logs debug message.
func (_da ConsoleLogger )Debug (format string ,args ...interface{}){if _da .LogLevel >=LogLevelDebug {_ea :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_da .output (_ab .Stdout ,_ea ,format ,args ...);};};
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (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 (_cbe ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cbe .LogLevel >=level };
// Notice logs notice message.
func (_dd ConsoleLogger )Notice (format string ,args ...interface{}){if _dd .LogLevel >=LogLevelNotice {_ae :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_dd .output (_ab .Stdout ,_ae ,format ,args ...);};};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_dgc WriterLogger )IsLogLevel (level LogLevel )bool {return _dgc .LogLevel >=level };
// Warning logs warning message.
func (_fd WriterLogger )Warning (format string ,args ...interface{}){if _fd .LogLevel >=LogLevelWarning {_de :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_fd .logToWriter (_fd .Output ,_de ,format ,args ...);};};
// Warning logs warning message.
func (_gaf ConsoleLogger )Warning (format string ,args ...interface{}){if _gaf .LogLevel >=LogLevelWarning {_dfb :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_gaf .output (_ab .Stdout ,_dfb ,format ,args ...);};};const _bde ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Debug logs debug message.
func (_fa WriterLogger )Debug (format string ,args ...interface{}){if _fa .LogLevel >=LogLevelDebug {_ba :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_fa .logToWriter (_fa .Output ,_ba ,format ,args ...);};};
// Trace logs trace message.
func (_ee ConsoleLogger )Trace (format string ,args ...interface{}){if _ee .LogLevel >=LogLevelTrace {_dcg :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ee .output (_ab .Stdout ,_dcg ,format ,args ...);};};const _gbc =2;const _ccb =30;
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };
// Error logs error message.
func (_ece WriterLogger )Error (format string ,args ...interface{}){if _ece .LogLevel >=LogLevelError {_bfd :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ece .logToWriter (_ece .Output ,_bfd ,format ,args ...);};};
// DummyLogger does nothing.
type DummyLogger struct{};
// LogLevel is the verbosity level for logging.
type LogLevel int ;const _ac =16;
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};
// WriterLogger is the logger that writes data to the Output writer
type WriterLogger struct{LogLevel LogLevel ;Output _af .Writer ;};
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
// UtcTimeFormat returns a formatted string describing a UTC timestamp.
func UtcTimeFormat (t _fc .Time )string {return t .Format (_bde )+"\u0020\u0055\u0054\u0043"};
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};const _ffa =2021;
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _af .Writer )*WriterLogger {_dfc :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_dfc ;};
// Error logs error message.
func (_ec ConsoleLogger )Error (format string ,args ...interface{}){if _ec .LogLevel >=LogLevelError {_fg :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ec .output (_ab .Stdout ,_fg ,format ,args ...);};};
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};
// Info does nothing for dummy logger.
func (DummyLogger )Info (format string ,args ...interface{}){};
func (DummyLogger )Info (format string ,args ...interface{}){};const _beb ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_e string ,_dc ...interface{});Warning (_c string ,_cc ...interface{});Notice (_ff string ,_g ...interface{});Info (_ca string ,_db ...interface{});Debug (_ga string ,_cb ...interface{});Trace (_df string ,_dff ...interface{});IsLogLevel (_bf LogLevel )bool ;};var ReleasedAt =_fc .Date (_ffa ,_gbc ,_aa ,_ac ,_ccb ,0,0,_fc .UTC );
// Warning logs warning message.
func (_da WriterLogger )Warning (format string ,args ...interface{}){if _da .LogLevel >=LogLevelWarning {_af :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_da .logToWriter (_da .Output ,_af ,format ,args ...);};};const _ed =21;
// Trace logs trace message.
func (_fee WriterLogger )Trace (format string ,args ...interface{}){if _fee .LogLevel >=LogLevelTrace {_bb :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_fee .logToWriter (_fee .Output ,_bb ,format ,args ...);};};const _aa =10;func _ffe (_gg _af .Writer ,_fff string ,_afc string ,_gf ...interface{}){_ ,_ggd ,_bdf ,_aec :=_d .Caller (3);if !_aec {_ggd ="\u003f\u003f\u003f";_bdf =0;}else {_ggd =_a .Base (_ggd );};_ag :=_f .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_fff ,_ggd ,_bdf )+_afc +"\u000a";_f .Fprintf (_gg ,_ag ,_gf ...);};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);func (_gb WriterLogger )logToWriter (_ge _af .Writer ,_gag string ,_fde string ,_def ...interface{}){_ffe (_ge ,_gag ,_fde ,_def );};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;
);
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
type ConsoleLogger struct{LogLevel LogLevel ;};
// Notice logs notice message.
func (_dde WriterLogger )Notice (format string ,args ...interface{}){if _dde .LogLevel >=LogLevelNotice {_ecc :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_dde .logToWriter (_dde .Output ,_ecc ,format ,args ...);};};const Version ="\u0033\u002e\u0031\u0039\u002e\u0030";
func (_fd ConsoleLogger )Notice (format string ,args ...interface{}){if _fd .LogLevel >=LogLevelNotice {_ea :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_fd .output (_b .Stdout ,_ea ,format ,args ...);};};
// Logger is the interface used for logging in the unipdf package.
type Logger interface{Error (_de string ,_fe ...interface{});Warning (_ce string ,_dd ...interface{});Notice (_ee string ,_cb ...interface{});Info (_g string ,_cg ...interface{});Debug (_ba string ,_bd ...interface{});Trace (_fg string ,_cf ...interface{});
IsLogLevel (_bg LogLevel )bool ;};
// IsLogLevel returns true from dummy logger.
func (DummyLogger )IsLogLevel (level LogLevel )bool {return true };
// Info logs info message.
func (_cf WriterLogger )Info (format string ,args ...interface{}){if _cf .LogLevel >=LogLevelInfo {_gac :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cf .logToWriter (_cf .Output ,_gac ,format ,args ...);};};
func (_bfb WriterLogger )Info (format string ,args ...interface{}){if _bfb .LogLevel >=LogLevelInfo {_db :="\u005bI\u004e\u0046\u004f\u005d\u0020";_bfb .logToWriter (_bfb .Output ,_db ,format ,args ...);};};
// NewConsoleLogger creates new console logger.
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
// Error logs error message.
func (_a ConsoleLogger )Error (format string ,args ...interface{}){if _a .LogLevel >=LogLevelError {_ae :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_a .output (_b .Stdout ,_ae ,format ,args ...);};};
// Trace does nothing for dummy logger.
func (DummyLogger )Trace (format string ,args ...interface{}){};var Log Logger =DummyLogger {};
// Notice does nothing for dummy logger.
func (DummyLogger )Notice (format string ,args ...interface{}){};var ReleasedAt =_e .Date (_dfc ,_abb ,_ed ,_baa ,_ac ,0,0,_e .UTC );
// Debug does nothing for dummy logger.
func (DummyLogger )Debug (format string ,args ...interface{}){};const _abb =2;var Log Logger =DummyLogger {};
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
func SetLogger (logger Logger ){Log =logger };const _baa =16;
// WriterLogger is the logger that writes data to the Output writer
type WriterLogger struct{LogLevel LogLevel ;Output _c .Writer ;};
// Info logs info message.
func (_dg ConsoleLogger )Info (format string ,args ...interface{}){if _dg .LogLevel >=LogLevelInfo {_fe :="\u005bI\u004e\u0046\u004f\u005d\u0020";_dg .output (_ab .Stdout ,_fe ,format ,args ...);};};func (_eg ConsoleLogger )output (_ef _af .Writer ,_dfa string ,_bd string ,_gc ...interface{}){_ffe (_ef ,_dfa ,_bd ,_gc ...);};
func (_gd ConsoleLogger )Info (format string ,args ...interface{}){if _gd .LogLevel >=LogLevelInfo {_ab :="\u005bI\u004e\u0046\u004f\u005d\u0020";_gd .output (_b .Stdout ,_ab ,format ,args ...);};};const _dfc =2021;
// Error does nothing for dummy logger.
func (DummyLogger )Error (format string ,args ...interface{}){};
// Notice logs notice message.
func (_agf WriterLogger )Notice (format string ,args ...interface{}){if _agf .LogLevel >=LogLevelNotice {_bf :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_agf .logToWriter (_agf .Output ,_bf ,format ,args ...);};};
// UtcTimeFormat returns a formatted string describing a UTC timestamp.
func UtcTimeFormat (t _e .Time )string {return t .Format (_beb )+"\u0020\u0055\u0054\u0043"};func _gae (_afa _c .Writer ,_deb string ,_fgc string ,_dag ...interface{}){_ ,_eae ,_fbf ,_agfa :=_d .Caller (3);if !_agfa {_eae ="\u003f\u003f\u003f";_fbf =0;
}else {_eae =_dc .Base (_eae );};_aaa :=_fa .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_deb ,_eae ,_fbf )+_fgc +"\u000a";_fa .Fprintf (_afa ,_aaa ,_dag ...);};
// NewWriterLogger creates new 'writer' logger.
func NewWriterLogger (logLevel LogLevel ,writer _c .Writer )*WriterLogger {_gf :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_gf ;};
// Trace logs trace message.
func (_be ConsoleLogger )Trace (format string ,args ...interface{}){if _be .LogLevel >=LogLevelTrace {_fc :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_be .output (_b .Stdout ,_fc ,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 (_feb WriterLogger )IsLogLevel (level LogLevel )bool {return _feb .LogLevel >=level };func (_dg ConsoleLogger )output (_fga _c .Writer ,_cfb string ,_cgb string ,_dcf ...interface{}){_gae (_fga ,_cfb ,_cgb ,_dcf ...);};func (_eb WriterLogger )logToWriter (_dee _c .Writer ,_df string ,_fcg string ,_bb ...interface{}){_gae (_dee ,_df ,_fcg ,_bb );
};const Version ="\u0033\u002e\u0031\u0039\u002e\u0031";
// Debug logs debug message.
func (_fbg WriterLogger )Debug (format string ,args ...interface{}){if _fbg .LogLevel >=LogLevelDebug {_fbe :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_fbg .logToWriter (_fbg .Output ,_fbe ,format ,args ...);};};
// LogLevel is the verbosity level for logging.
type LogLevel int ;
// IsLogLevel returns true if log level is greater or equal than `level`.
// Can be used to avoid resource intensive calls to loggers.
func (_fb ConsoleLogger )IsLogLevel (level LogLevel )bool {return _fb .LogLevel >=level };
// Debug logs debug message.
func (_ga ConsoleLogger )Debug (format string ,args ...interface{}){if _ga .LogLevel >=LogLevelDebug {_aa :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ga .output (_b .Stdout ,_aa ,format ,args ...);};};
// Trace logs trace message.
func (_gfg WriterLogger )Trace (format string ,args ...interface{}){if _gfg .LogLevel >=LogLevelTrace {_afg :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_gfg .logToWriter (_gfg .Output ,_afg ,format ,args ...);};};
// Warning does nothing for dummy logger.
func (DummyLogger )Warning (format string ,args ...interface{}){};
// Error logs error message.
func (_gg WriterLogger )Error (format string ,args ...interface{}){if _gg .LogLevel >=LogLevelError {_ef :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_gg .logToWriter (_gg .Output ,_ef ,format ,args ...);};};
// Warning logs warning message.
func (_ag ConsoleLogger )Warning (format string ,args ...interface{}){if _ag .LogLevel >=LogLevelWarning {_bdc :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ag .output (_b .Stdout ,_bdc ,format ,args ...);};};
// DummyLogger does nothing.
type DummyLogger struct{};const _ac =30;

View File

@ -10,24 +10,25 @@
// terms that can be accessed at https://unidoc.io/eula/
// Package license helps manage commercial licenses and check if they are valid for the version of unipdf used.
package license ;import _aa "github.com/unidoc/unipdf/v3/internal/license";
package license ;import _e "github.com/unidoc/unipdf/v3/internal/license";
// SetMeteredKey sets the metered API key required for SaaS operation.
// Document usage is reported periodically for the product to function correctly.
func SetMeteredKey (apiKey string )error {return _aa .SetMeteredKey (apiKey )};
func SetMeteredKey (apiKey string )error {return _e .SetMeteredKey (apiKey )};
// GetLicenseKey returns the currently loaded license key.
func GetLicenseKey ()*LicenseKey {return _e .GetLicenseKey ()};
// MakeUnlicensedKey returns a default key.
func MakeUnlicensedKey ()*LicenseKey {return _e .MakeUnlicensedKey ()};
// GetMeteredState checks the currently used metered document usage status,
// documents used and credits available.
func GetMeteredState ()(_aa .MeteredStatus ,error ){return _aa .GetMeteredState ()};
func GetMeteredState ()(_e .MeteredStatus ,error ){return _e .GetMeteredState ()};const (LicenseTierUnlicensed =_e .LicenseTierUnlicensed ;LicenseTierCommunity =_e .LicenseTierCommunity ;LicenseTierIndividual =_e .LicenseTierIndividual ;LicenseTierBusiness =_e .LicenseTierBusiness ;
);
// LicenseKey represents a loaded license key.
type LicenseKey =_aa .LicenseKey ;
// GetLicenseKey returns the currently loaded license key.
func GetLicenseKey ()*LicenseKey {return _aa .GetLicenseKey ()};
type LicenseKey =_e .LicenseKey ;
// SetLicenseKey sets and validates the license key.
func SetLicenseKey (content string ,customerName string )error {return _aa .SetLicenseKey (content ,customerName );};const (LicenseTierUnlicensed =_aa .LicenseTierUnlicensed ;LicenseTierCommunity =_aa .LicenseTierCommunity ;LicenseTierIndividual =_aa .LicenseTierIndividual ;LicenseTierBusiness =_aa .LicenseTierBusiness ;);
// MakeUnlicensedKey returns a default key.
func MakeUnlicensedKey ()*LicenseKey {return _aa .MakeUnlicensedKey ()};
func SetLicenseKey (content string ,customerName string )error {return _e .SetLicenseKey (content ,customerName );};

File diff suppressed because one or more lines are too long

View File

@ -14,204 +14,242 @@
// 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 (_a "fmt";_ab "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/core";_af "github.com/unidoc/unipdf/v3/internal/transform";_eb "github.com/unidoc/unipdf/v3/model";_f "math";);
// 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 (_bfe Polyline )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){if _bfe .LineColor ==nil {_bfe .LineColor =_eb .NewPdfColorDeviceRGB (0,0,0);};_dgc :=NewPath ();for _ ,_cgb :=range _bfe .Points {_dgc =_dgc .AppendPoint (_cgb );};_bbc :=_ab .NewContentCreator ();_bbc .Add_q ();_bbc .Add_RG (_bfe .LineColor .R (),_bfe .LineColor .G (),_bfe .LineColor .B ());_bbc .Add_w (_bfe .LineWidth );if len (gsName )> 1{_bbc .Add_gs (_b .PdfObjectName (gsName ));};DrawPathWithCreator (_dgc ,_bbc );_bbc .Add_S ();_bbc .Add_Q ();return _bbc .Bytes (),_dgc .GetBoundingBox ().ToPdfRectangle (),nil ;};
// AppendPoint adds the specified point to the path.
func (_eba Path )AppendPoint (point Point )Path {_eba .Points =append (_eba .Points ,point );return _eba };
// 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 *_eb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// AppendCurve appends the specified Bezier curve to the path.
func (_bd CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_bd .Curves =append (_bd .Curves ,curve );return _bd ;};
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_ed :=CubicBezierPath {};_ed .Curves =[]CubicBezierCurve {};return _ed ;};
package draw ;import (_c "fmt";_d "github.com/unidoc/unipdf/v3/contentstream";_bf "github.com/unidoc/unipdf/v3/core";_ce "github.com/unidoc/unipdf/v3/internal/transform";_cg "github.com/unidoc/unipdf/v3/model";_e "math";);
// Length returns the number of points in the path.
func (_de Path )Length ()int {return len (_de .Points )};
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_eb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_c :=CubicBezierCurve {};_c .P0 =NewPoint (x0 ,y0 );_c .P1 =NewPoint (x1 ,y1 );_c .P2 =NewPoint (x2 ,y2 );_c .P3 =NewPoint (x3 ,y3 );return _c ;};
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_gbg Point )Add (dx ,dy float64 )Point {_gbg .X +=dx ;_gbg .Y +=dy ;return _gbg };
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_adc Vector )GetPolarAngle ()float64 {return _f .Atan2 (_adc .Dy ,_adc .Dx )};
// GetBoundingBox returns the bounding box of the path.
func (_gd Path )GetBoundingBox ()BoundingBox {_fc :=BoundingBox {};_gf :=0.0;_gdc :=0.0;_cb :=0.0;_dgb :=0.0;for _fgc ,_gg :=range _gd .Points {if _fgc ==0{_gf =_gg .X ;_gdc =_gg .X ;_cb =_gg .Y ;_dgb =_gg .Y ;continue ;};if _gg .X < _gf {_gf =_gg .X ;};if _gg .X > _gdc {_gdc =_gg .X ;};if _gg .Y < _cb {_cb =_gg .Y ;};if _gg .Y > _dgb {_dgb =_gg .Y ;};};_fc .X =_gf ;_fc .Y =_cb ;_fc .Width =_gdc -_gf ;_fc .Height =_dgb -_cb ;return _fc ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// 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 (_cbef BasicLine )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){_afb :=_cbef .LineWidth ;_bggg :=NewPath ();_bggg =_bggg .AppendPoint (NewPoint (_cbef .X1 ,_cbef .Y1 ));_bggg =_bggg .AppendPoint (NewPoint (_cbef .X2 ,_cbef .Y2 ));_gbf :=_ab .NewContentCreator ();_ag :=_bggg .GetBoundingBox ();DrawPathWithCreator (_bggg ,_gbf );if _cbef .LineStyle ==LineStyleDashed {_gbf .Add_d ([]int64 {1,1},0);};_gbf .Add_RG (_cbef .LineColor .R (),_cbef .LineColor .G (),_cbef .LineColor .B ()).Add_w (_afb ).Add_S ().Add_Q ();return _gbf .Bytes (),_ag .ToPdfRectangle (),nil ;};
// Copy returns a clone of the path.
func (_eeb Path )Copy ()Path {_dddb :=Path {};_dddb .Points =append (_dddb .Points ,_eeb .Points ...);return _dddb ;};
// Offset shifts the path with the specified offsets.
func (_gc Path )Offset (offX ,offY float64 )Path {for _fe ,_gb :=range _gc .Points {_gc .Points [_fe ]=_gb .Add (offX ,offY );};return _gc ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_eb .PdfColorDeviceRGB ;LineWidth float64 ;};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// 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 (_aa Rectangle )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){_ea :=NewPath ();_ea =_ea .AppendPoint (NewPoint (0,0));_ea =_ea .AppendPoint (NewPoint (0,_aa .Height ));_ea =_ea .AppendPoint (NewPoint (_aa .Width ,_aa .Height ));_ea =_ea .AppendPoint (NewPoint (_aa .Width ,0));_ea =_ea .AppendPoint (NewPoint (0,0));if _aa .X !=0||_aa .Y !=0{_ea =_ea .Offset (_aa .X ,_aa .Y );};_dddd :=_ab .NewContentCreator ();_dddd .Add_q ();if _aa .FillEnabled {_dddd .Add_rg (_aa .FillColor .R (),_aa .FillColor .G (),_aa .FillColor .B ());};if _aa .BorderEnabled {_dddd .Add_RG (_aa .BorderColor .R (),_aa .BorderColor .G (),_aa .BorderColor .B ());_dddd .Add_w (_aa .BorderWidth );};if len (gsName )> 1{_dddd .Add_gs (_b .PdfObjectName (gsName ));};DrawPathWithCreator (_ea ,_dddd );_dddd .Add_h ();if _aa .FillEnabled &&_aa .BorderEnabled {_dddd .Add_B ();}else if _aa .FillEnabled {_dddd .Add_f ();}else if _aa .BorderEnabled {_dddd .Add_S ();};_dddd .Add_Q ();return _dddd .Bytes (),_ea .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 *_ab .ContentCreator ){for _cdge ,_ddc :=range bpath .Curves {if _cdge ==0{creator .Add_m (_ddc .P0 .X ,_ddc .P0 .Y );};creator .Add_c (_ddc .P1 .X ,_ddc .P1 .Y ,_ddc .P2 .X ,_ddc .P2 .Y ,_ddc .P3 .X ,_ddc .P3 .Y );};};func (_ebg Point )String ()string {return _a .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_ebg .X ,_ebg .Y );};
// GetBounds returns the bounding box of the Bezier curve.
func (_d CubicBezierCurve )GetBounds ()_eb .PdfRectangle {_dd :=_d .P0 .X ;_df :=_d .P0 .X ;_ee :=_d .P0 .Y ;_bc :=_d .P0 .Y ;for _dg :=0.0;_dg <=1.0;_dg +=0.001{Rx :=_d .P0 .X *_f .Pow (1-_dg ,3)+_d .P1 .X *3*_dg *_f .Pow (1-_dg ,2)+_d .P2 .X *3*_f .Pow (_dg ,2)*(1-_dg )+_d .P3 .X *_f .Pow (_dg ,3);Ry :=_d .P0 .Y *_f .Pow (1-_dg ,3)+_d .P1 .Y *3*_dg *_f .Pow (1-_dg ,2)+_d .P2 .Y *3*_f .Pow (_dg ,2)*(1-_dg )+_d .P3 .Y *_f .Pow (_dg ,3);if Rx < _dd {_dd =Rx ;};if Rx > _df {_df =Rx ;};if Ry < _ee {_ee =Ry ;};if Ry > _bc {_bc =Ry ;};};_ca :=_eb .PdfRectangle {};_ca .Llx =_dd ;_ca .Lly =_ee ;_ca .Urx =_df ;_ca .Ury =_bc ;return _ca ;};
// Magnitude returns the magnitude of the vector.
func (_ga Vector )Magnitude ()float64 {return _f .Sqrt (_f .Pow (_ga .Dx ,2.0)+_f .Pow (_ga .Dy ,2.0))};
// 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 (_gfe Polygon )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){_cbb :=_ab .NewContentCreator ();_cbb .Add_q ();_gfe .FillEnabled =_gfe .FillEnabled &&_gfe .FillColor !=nil ;if _gfe .FillEnabled {_cbb .Add_rg (_gfe .FillColor .R (),_gfe .FillColor .G (),_gfe .FillColor .B ());};_gfe .BorderEnabled =_gfe .BorderEnabled &&_gfe .BorderColor !=nil ;if _gfe .BorderEnabled {_cbb .Add_RG (_gfe .BorderColor .R (),_gfe .BorderColor .G (),_gfe .BorderColor .B ());_cbb .Add_w (_gfe .BorderWidth );};if len (gsName )> 1{_cbb .Add_gs (_b .PdfObjectName (gsName ));};_gca :=NewPath ();for _ ,_ce :=range _gfe .Points {for _bee ,_bgg :=range _ce {_gca =_gca .AppendPoint (_bgg );if _bee ==0{_cbb .Add_m (_bgg .X ,_bgg .Y );}else {_cbb .Add_l (_bgg .X ,_bgg .Y );};};_cbb .Add_h ();};if _gfe .FillEnabled &&_gfe .BorderEnabled {_cbb .Add_B ();}else if _gfe .FillEnabled {_cbb .Add_f ();}else if _gfe .BorderEnabled {_cbb .Add_S ();};_cbb .Add_Q ();return _cbb .Bytes (),_gca .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 {_aea :=Vector {};_aea .Dx =b .X -a .X ;_aea .Dy =b .Y -a .Y ;return _aea ;};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_eef Path )RemovePoint (number int )Path {if number < 1||number > len (_eef .Points ){return _eef ;};_cf :=number -1;_eef .Points =append (_eef .Points [:_cf ],_eef .Points [_cf +1:]...);return _eef ;};
// FlipX flips the sign of the Dx component of the vector.
func (_dce Vector )FlipX ()Vector {_dce .Dx =-_dce .Dx ;return _dce };
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_bcf Rectangle )ToPdfRectangle ()*_eb .PdfRectangle {return &_eb .PdfRectangle {Llx :_bcf .X ,Lly :_bcf .Y ,Urx :_bcf .X +_bcf .Width ,Ury :_bcf .Y +_bcf .Height };};
func (_ef Path )Length ()int {return len (_ef .Points )};
// LineEndingStyle defines the line ending style for lines.
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
type LineEndingStyle int ;
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
// ToPdfRectangle returns the rectangle as a PDF rectangle.
func (_fcb Rectangle )ToPdfRectangle ()*_cg .PdfRectangle {return &_cg .PdfRectangle {Llx :_fcb .X ,Lly :_fcb .Y ,Urx :_fcb .X +_fcb .Width ,Ury :_fcb .Y +_fcb .Height };};
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_dfb BoundingBox )ToPdfRectangle ()*_cg .PdfRectangle {return &_cg .PdfRectangle {Llx :_dfb .X ,Lly :_dfb .Y ,Urx :_dfb .X +_dfb .Width ,Ury :_dfb .Y +_dfb .Height };};
// Copy returns a clone of the Bezier path.
func (_fd CubicBezierPath )Copy ()CubicBezierPath {_df :=CubicBezierPath {};_df .Curves =append (_df .Curves ,_fd .Curves ...);return _df ;};
// Offset shifts the path with the specified offsets.
func (_eaa Path )Offset (offX ,offY float64 )Path {for _cge ,_fdcg :=range _eaa .Points {_eaa .Points [_cge ]=_fdcg .Add (offX ,offY );};return _eaa ;};
// Point represents a two-dimensional point.
type Point struct{X float64 ;Y float64 ;};
// Draw draws the composite Bezier curve. A graphics state name can be
// specified for setting the curve properties (e.g. setting the opacity).
// Otherwise leave empty (""). Returns the content stream as a byte array and
// the curve bounding box.
func (_bce PolyBezierCurve )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){if _bce .BorderColor ==nil {_bce .BorderColor =_eb .NewPdfColorDeviceRGB (0,0,0);};_ae :=NewCubicBezierPath ();for _ ,_cag :=range _bce .Curves {_ae =_ae .AppendCurve (_cag );};_bf :=_ab .NewContentCreator ();_bf .Add_q ();_bce .FillEnabled =_bce .FillEnabled &&_bce .FillColor !=nil ;if _bce .FillEnabled {_bf .Add_rg (_bce .FillColor .R (),_bce .FillColor .G (),_bce .FillColor .B ());};_bf .Add_RG (_bce .BorderColor .R (),_bce .BorderColor .G (),_bce .BorderColor .B ());_bf .Add_w (_bce .BorderWidth );if len (gsName )> 1{_bf .Add_gs (_b .PdfObjectName (gsName ));};for _ ,_cbea :=range _ae .Curves {_bf .Add_m (_cbea .P0 .X ,_cbea .P0 .Y );_bf .Add_c (_cbea .P1 .X ,_cbea .P1 .Y ,_cbea .P2 .X ,_cbea .P2 .Y ,_cbea .P3 .X ,_cbea .P3 .Y );};if _bce .FillEnabled {_bf .Add_h ();_bf .Add_B ();}else {_bf .Add_S ();};_bf .Add_Q ();return _bf .Bytes (),_ae .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 {_ff :=Vector {};_ff .Dx =b .X -a .X ;_ff .Dy =b .Y -a .Y ;return _ff ;};
// CubicBezierPath represents a collection of cubic Bezier curves.
type CubicBezierPath struct{Curves []CubicBezierCurve ;};
// FlipX flips the sign of the Dx component of the vector.
func (_gfb Vector )FlipX ()Vector {_gfb .Dx =-_gfb .Dx ;return _gfb };
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_cg .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_cg .PdfColorDeviceRGB ;};
// NewCubicBezierPath returns a new empty cubic Bezier path.
func NewCubicBezierPath ()CubicBezierPath {_gd :=CubicBezierPath {};_gd .Curves =[]CubicBezierCurve {};return _gd ;};
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_eg Path )GetPointNumber (number int )Point {if number < 1||number > len (_eg .Points ){return Point {};};return _eg .Points [number -1];};
// Scale scales the vector by the specified factor.
func (_edd Vector )Scale (factor float64 )Vector {_eae :=_edd .Magnitude ();_acb :=_edd .GetPolarAngle ();_edd .Dx =factor *_eae *_f .Cos (_acb );_edd .Dy =factor *_eae *_f .Sin (_acb );return _edd ;};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
func (_egbc Vector )Scale (factor float64 )Vector {_dac :=_egbc .Magnitude ();_egg :=_egbc .GetPolarAngle ();_egbc .Dx =factor *_dac *_e .Cos (_egg );_egbc .Dy =factor *_dac *_e .Sin (_egg );return _egbc ;};
// FlipY flips the sign of the Dy component of the vector.
func (_bfa Vector )FlipY ()Vector {_bfa .Dy =-_bfa .Dy ;return _bfa };
// Add shifts the coordinates of the point with dx, dy and returns the result.
func (_ba Point )Add (dx ,dy float64 )Point {_ba .X +=dx ;_ba .Y +=dy ;return _ba };
// AddVector adds vector to a point.
func (_fgb Point )AddVector (v Vector )Point {_fgb .X +=v .Dx ;_fgb .Y +=v .Dy ;return _fgb };
// Magnitude returns the magnitude of the vector.
func (_cfge Vector )Magnitude ()float64 {return _e .Sqrt (_e .Pow (_cfge .Dx ,2.0)+_e .Pow (_cfge .Dy ,2.0));};
// 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 (_ggfa Line )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){_bde ,_dfa :=_ggfa .X1 ,_ggfa .X2 ;_cdg ,_ef :=_ggfa .Y1 ,_ggfa .Y2 ;_egf :=_ef -_cdg ;_ceb :=_dfa -_bde ;_fea :=_f .Atan2 (_egf ,_ceb );L :=_f .Sqrt (_f .Pow (_ceb ,2.0)+_f .Pow (_egf ,2.0));_dec :=_ggfa .LineWidth ;_fgba :=_f .Pi ;_db :=1.0;if _ceb < 0{_db *=-1.0;};if _egf < 0{_db *=-1.0;};VsX :=_db *(-_dec /2*_f .Cos (_fea +_fgba /2));VsY :=_db *(-_dec /2*_f .Sin (_fea +_fgba /2)+_dec *_f .Sin (_fea +_fgba /2));V1X :=VsX +_dec /2*_f .Cos (_fea +_fgba /2);V1Y :=VsY +_dec /2*_f .Sin (_fea +_fgba /2);V2X :=VsX +_dec /2*_f .Cos (_fea +_fgba /2)+L *_f .Cos (_fea );V2Y :=VsY +_dec /2*_f .Sin (_fea +_fgba /2)+L *_f .Sin (_fea );V3X :=VsX +_dec /2*_f .Cos (_fea +_fgba /2)+L *_f .Cos (_fea )+_dec *_f .Cos (_fea -_fgba /2);V3Y :=VsY +_dec /2*_f .Sin (_fea +_fgba /2)+L *_f .Sin (_fea )+_dec *_f .Sin (_fea -_fgba /2);V4X :=VsX +_dec /2*_f .Cos (_fea -_fgba /2);V4Y :=VsY +_dec /2*_f .Sin (_fea -_fgba /2);_bcg :=NewPath ();_bcg =_bcg .AppendPoint (NewPoint (V1X ,V1Y ));_bcg =_bcg .AppendPoint (NewPoint (V2X ,V2Y ));_bcg =_bcg .AppendPoint (NewPoint (V3X ,V3Y ));_bcg =_bcg .AppendPoint (NewPoint (V4X ,V4Y ));_gdf :=_ggfa .LineEndingStyle1 ;_cg :=_ggfa .LineEndingStyle2 ;_ba :=3*_dec ;_bbe :=3*_dec ;_gfd :=(_bbe -_dec )/2;if _cg ==LineEndingStyleArrow {_bab :=_bcg .GetPointNumber (2);_fdg :=NewVectorPolar (_ba ,_fea +_fgba );_ad :=_bab .AddVector (_fdg );_egg :=NewVectorPolar (_bbe /2,_fea +_fgba /2);_dbc :=NewVectorPolar (_ba ,_fea );_bfd :=NewVectorPolar (_gfd ,_fea +_fgba /2);_ec :=_ad .AddVector (_bfd );_decg :=_dbc .Add (_egg .Flip ());_afa :=_ec .AddVector (_decg );_fdc :=_egg .Scale (2).Flip ().Add (_decg .Flip ());_cbc :=_afa .AddVector (_fdc );_fgcc :=_ad .AddVector (NewVectorPolar (_dec ,_fea -_fgba /2));_dcf :=NewPath ();_dcf =_dcf .AppendPoint (_bcg .GetPointNumber (1));_dcf =_dcf .AppendPoint (_ad );_dcf =_dcf .AppendPoint (_ec );_dcf =_dcf .AppendPoint (_afa );_dcf =_dcf .AppendPoint (_cbc );_dcf =_dcf .AppendPoint (_fgcc );_dcf =_dcf .AppendPoint (_bcg .GetPointNumber (4));_bcg =_dcf ;};if _gdf ==LineEndingStyleArrow {_bcb :=_bcg .GetPointNumber (1);_aee :=_bcg .GetPointNumber (_bcg .Length ());_abd :=NewVectorPolar (_dec /2,_fea +_fgba +_fgba /2);_ace :=_bcb .AddVector (_abd );_deg :=NewVectorPolar (_ba ,_fea ).Add (NewVectorPolar (_bbe /2,_fea +_fgba /2));_gce :=_ace .AddVector (_deg );_dege :=NewVectorPolar (_gfd ,_fea -_fgba /2);_cc :=_gce .AddVector (_dege );_bfc :=NewVectorPolar (_ba ,_fea );_cbd :=_aee .AddVector (_bfc );_bgf :=NewVectorPolar (_gfd ,_fea +_fgba +_fgba /2);_cab :=_cbd .AddVector (_bgf );_eed :=_ace ;_edg :=NewPath ();_edg =_edg .AppendPoint (_ace );_edg =_edg .AppendPoint (_gce );_edg =_edg .AppendPoint (_cc );for _ ,_dee :=range _bcg .Points [1:len (_bcg .Points )-1]{_edg =_edg .AppendPoint (_dee );};_edg =_edg .AppendPoint (_cbd );_edg =_edg .AppendPoint (_cab );_edg =_edg .AppendPoint (_eed );_bcg =_edg ;};_cff :=_ab .NewContentCreator ();_cff .Add_q ().Add_rg (_ggfa .LineColor .R (),_ggfa .LineColor .G (),_ggfa .LineColor .B ());if len (gsName )> 1{_cff .Add_gs (_b .PdfObjectName (gsName ));};_bcg =_bcg .Offset (_ggfa .X1 ,_ggfa .Y1 );_fcdg :=_bcg .GetBoundingBox ();DrawPathWithCreator (_bcg ,_cff );if _ggfa .LineStyle ==LineStyleDashed {_cff .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_cff .Add_f ().Add_Q ();};return _cff .Bytes (),_fcdg .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 *_cg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_cg .PdfColorDeviceRGB ;BorderWidth float64 ;};
// Add adds the specified vector to the current one and returns the result.
func (_aeac Vector )Add (other Vector )Vector {_aeac .Dx +=other .Dx ;_aeac .Dy +=other .Dy ;return _aeac ;};
// GetPolarAngle returns the angle the magnitude of the vector forms with the
// positive X-axis going counterclockwise.
func (_ffd Vector )GetPolarAngle ()float64 {return _e .Atan2 (_ffd .Dy ,_ffd .Dx )};
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_bcd :=Vector {};_bcd .Dx =length *_e .Cos (theta );_bcd .Dy =length *_e .Sin (theta );return _bcd ;};
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_eg CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_eg .P0 .X +=offX ;_eg .P1 .X +=offX ;_eg .P2 .X +=offX ;_eg .P3 .X +=offX ;_eg .P0 .Y +=offY ;_eg .P1 .Y +=offY ;_eg .P2 .Y +=offY ;_eg .P3 .Y +=offY ;return _eg ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_dba :=Vector {};_dba .Dx =dx ;_dba .Dy =dy ;return _dba };
// 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 (_bcc Circle )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){_bed :=_bcc .Width /2;_ga :=_bcc .Height /2;if _bcc .BorderEnabled {_bed -=_bcc .BorderWidth /2;_ga -=_bcc .BorderWidth /2;};_fe :=0.551784;_bbg :=_bed *_fe ;_dcb :=_ga *_fe ;
_gdf :=NewCubicBezierPath ();_gdf =_gdf .AppendCurve (NewCubicBezierCurve (-_bed ,0,-_bed ,_dcb ,-_bbg ,_ga ,0,_ga ));_gdf =_gdf .AppendCurve (NewCubicBezierCurve (0,_ga ,_bbg ,_ga ,_bed ,_dcb ,_bed ,0));_gdf =_gdf .AppendCurve (NewCubicBezierCurve (_bed ,0,_bed ,-_dcb ,_bbg ,-_ga ,0,-_ga ));
_gdf =_gdf .AppendCurve (NewCubicBezierCurve (0,-_ga ,-_bbg ,-_ga ,-_bed ,-_dcb ,-_bed ,0));_gdf =_gdf .Offset (_bed ,_ga );if _bcc .BorderEnabled {_gdf =_gdf .Offset (_bcc .BorderWidth /2,_bcc .BorderWidth /2);};if _bcc .X !=0||_bcc .Y !=0{_gdf =_gdf .Offset (_bcc .X ,_bcc .Y );
};_bcg :=_d .NewContentCreator ();_bcg .Add_q ();if _bcc .FillEnabled {_bcg .Add_rg (_bcc .FillColor .R (),_bcc .FillColor .G (),_bcc .FillColor .B ());};if _bcc .BorderEnabled {_bcg .Add_RG (_bcc .BorderColor .R (),_bcc .BorderColor .G (),_bcc .BorderColor .B ());
_bcg .Add_w (_bcc .BorderWidth );};if len (gsName )> 1{_bcg .Add_gs (_bf .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_gdf ,_bcg );_bcg .Add_h ();if _bcc .FillEnabled &&_bcc .BorderEnabled {_bcg .Add_B ();}else if _bcc .FillEnabled {_bcg .Add_f ();
}else if _bcc .BorderEnabled {_bcg .Add_S ();};_bcg .Add_Q ();_ae :=_gdf .GetBoundingBox ();if _bcc .BorderEnabled {_ae .Height +=_bcc .BorderWidth ;_ae .Width +=_bcc .BorderWidth ;_ae .X -=_bcc .BorderWidth /2;_ae .Y -=_bcc .BorderWidth /2;};return _bcg .Bytes (),_ae .ToPdfRectangle (),nil ;
};
// LineStyle refers to how the line will be created.
type LineStyle int ;
// GetPointNumber returns the path point at the index specified by number.
// The index is 1-based.
func (_dgd Path )GetPointNumber (number int )Point {if number < 1||number > len (_dgd .Points ){return Point {};};return _dgd .Points [number -1];};
// 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 *_cg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cg .PdfColorDeviceRGB ;Opacity float64 ;};
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
// or arrows at either end. The line also has a specified width, color and opacity.
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_eb .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// Copy returns a clone of the path.
func (_cf Path )Copy ()Path {_cb :=Path {};_cb .Points =append (_cb .Points ,_cf .Points ...);return _cb ;};
// Polyline defines a slice of points that are connected as straight lines.
type Polyline struct{Points []Point ;LineColor *_cg .PdfColorDeviceRGB ;LineWidth float64 ;};
// NewCubicBezierCurve returns a new cubic Bezier curve.
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_dg :=CubicBezierCurve {};_dg .P0 =NewPoint (x0 ,y0 );_dg .P1 =NewPoint (x1 ,y1 );_dg .P2 =NewPoint (x2 ,y2 );_dg .P3 =NewPoint (x3 ,y3 );return _dg ;};
// NewPoint returns a new point with the coordinates x, y.
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
// Offset shifts the Bezier path with the specified offsets.
func (_fd CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _fb ,_bb :=range _fd .Curves {_fd .Curves [_fb ]=_bb .AddOffsetXY (offX ,offY );};return _fd ;};
func (_ad CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _be ,_ee :=range _ad .Curves {_ad .Curves [_be ]=_ee .AddOffsetXY (offX ,offY );};return _ad ;};
// PolyBezierCurve represents a composite curve that is the result of
// joining multiple cubic Bezier curves.
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_eb .PdfColorDeviceRGB ;};
// Draw draws the polyline. A graphics state name can be specified for
// setting the polyline properties (e.g. setting the opacity). Otherwise leave
// empty (""). Returns the content stream as a byte array and the polyline
// bounding box.
func (_cda Polyline )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){if _cda .LineColor ==nil {_cda .LineColor =_cg .NewPdfColorDeviceRGB (0,0,0);};_bgc :=NewPath ();for _ ,_ddd :=range _cda .Points {_bgc =_bgc .AppendPoint (_ddd );};_cce :=_d .NewContentCreator ();
_cce .Add_q ();_cce .Add_RG (_cda .LineColor .R (),_cda .LineColor .G (),_cda .LineColor .B ());_cce .Add_w (_cda .LineWidth );if len (gsName )> 1{_cce .Add_gs (_bf .PdfObjectName (gsName ));};DrawPathWithCreator (_bgc ,_cce );_cce .Add_S ();_cce .Add_Q ();
return _cce .Bytes (),_bgc .GetBoundingBox ().ToPdfRectangle (),nil ;};
// DrawBezierPathWithCreator makes the bezier path with the content creator.
// Adds the PDF commands to draw the path to the creator instance.
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_d .ContentCreator ){for _ged ,_eeb :=range bpath .Curves {if _ged ==0{creator .Add_m (_eeb .P0 .X ,_eeb .P0 .Y );};creator .Add_c (_eeb .P1 .X ,_eeb .P1 .Y ,_eeb .P2 .X ,_eeb .P2 .Y ,_eeb .P3 .X ,_eeb .P3 .Y );
};};
// CubicBezierCurve is defined by:
// R(t) = P0*(1-t)^3 + P1*3*t*(1-t)^2 + P2*3*t^2*(1-t) + P3*t^3
// where P0 is the current point, P1, P2 control points and P3 the final point.
type CubicBezierCurve struct{P0 Point ;P1 Point ;P2 Point ;P3 Point ;};
// ToPdfRectangle returns the bounding box as a PDF rectangle.
func (_ebab BoundingBox )ToPdfRectangle ()*_eb .PdfRectangle {return &_eb .PdfRectangle {Llx :_ebab .X ,Lly :_ebab .Y ,Urx :_ebab .X +_ebab .Width ,Ury :_ebab .Y +_ebab .Height };};
// GetBoundingBox returns the bounding box of the path.
func (_gc Path )GetBoundingBox ()BoundingBox {_dc :=BoundingBox {};_eea :=0.0;_aad :=0.0;_ega :=0.0;_gcc :=0.0;for _ec ,_fb :=range _gc .Points {if _ec ==0{_eea =_fb .X ;_aad =_fb .X ;_ega =_fb .Y ;_gcc =_fb .Y ;continue ;};if _fb .X < _eea {_eea =_fb .X ;
};if _fb .X > _aad {_aad =_fb .X ;};if _fb .Y < _ega {_ega =_fb .Y ;};if _fb .Y > _gcc {_gcc =_fb .Y ;};};_dc .X =_eea ;_dc .Y =_ega ;_dc .Width =_aad -_eea ;_dc .Height =_gcc -_ega ;return _dc ;};
// AddVector adds vector to a point.
func (_bd Point )AddVector (v Vector )Point {_bd .X +=v .Dx ;_bd .Y +=v .Dy ;return _bd };const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
// 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 *_cg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
// 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 (_ggg PolyBezierCurve )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){if _ggg .BorderColor ==nil {_ggg .BorderColor =_cg .NewPdfColorDeviceRGB (0,0,0);};_fdee :=NewCubicBezierPath ();for _ ,_gdg :=range _ggg .Curves {_fdee =_fdee .AppendCurve (_gdg );
};_gccd :=_d .NewContentCreator ();_gccd .Add_q ();_ggg .FillEnabled =_ggg .FillEnabled &&_ggg .FillColor !=nil ;if _ggg .FillEnabled {_gccd .Add_rg (_ggg .FillColor .R (),_ggg .FillColor .G (),_ggg .FillColor .B ());};_gccd .Add_RG (_ggg .BorderColor .R (),_ggg .BorderColor .G (),_ggg .BorderColor .B ());
_gccd .Add_w (_ggg .BorderWidth );if len (gsName )> 1{_gccd .Add_gs (_bf .PdfObjectName (gsName ));};for _ ,_gggb :=range _fdee .Curves {_gccd .Add_m (_gggb .P0 .X ,_gggb .P0 .Y );_gccd .Add_c (_gggb .P1 .X ,_gggb .P1 .Y ,_gggb .P2 .X ,_gggb .P2 .Y ,_gggb .P3 .X ,_gggb .P3 .Y );
};if _ggg .FillEnabled {_gccd .Add_h ();_gccd .Add_B ();}else {_gccd .Add_S ();};_gccd .Add_Q ();return _gccd .Bytes (),_fdee .GetBoundingBox ().ToPdfRectangle (),nil ;};
// 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 *_ab .ContentCreator ){for _caa ,_deb :=range path .Points {if _caa ==0{creator .Add_m (_deb .X ,_deb .Y );}else {creator .Add_l (_deb .X ,_deb .Y );};};};
func DrawPathWithCreator (path Path ,creator *_d .ContentCreator ){for _bag ,_eba :=range path .Points {if _bag ==0{creator .Add_m (_eba .X ,_eba .Y );}else {creator .Add_l (_eba .X ,_eba .Y );};};};
// Rotate rotates the vector by the specified angle.
func (_dcd Vector )Rotate (phi float64 )Vector {_cca :=_dcd .Magnitude ();_bec :=_dcd .GetPolarAngle ();return NewVectorPolar (_cca ,_bec +phi );};
// AppendCurve appends the specified Bezier curve to the path.
func (_f CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_f .Curves =append (_f .Curves ,curve );return _f ;};
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_eb .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_eb .PdfColorDeviceRGB ;BorderWidth float64 ;};
// Path consists of straight line connections between each point defined in an array of points.
type Path struct{Points []Point ;};
// Copy returns a clone of the Bezier path.
func (_ddd CubicBezierPath )Copy ()CubicBezierPath {_dc :=CubicBezierPath {};_dc .Curves =append (_dc .Curves ,_ddd .Curves ...);return _dc ;};
// 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 (_gfc Circle )Draw (gsName string )([]byte ,*_eb .PdfRectangle ,error ){_abg :=_gfc .Width /2;_cbe :=_gfc .Height /2;if _gfc .BorderEnabled {_abg -=_gfc .BorderWidth /2;_cbe -=_gfc .BorderWidth /2;};_fcd :=0.551784;_fde :=_abg *_fcd ;_gfb :=_cbe *_fcd ;_ff :=NewCubicBezierPath ();_ff =_ff .AppendCurve (NewCubicBezierCurve (-_abg ,0,-_abg ,_gfb ,-_fde ,_cbe ,0,_cbe ));_ff =_ff .AppendCurve (NewCubicBezierCurve (0,_cbe ,_fde ,_cbe ,_abg ,_gfb ,_abg ,0));_ff =_ff .AppendCurve (NewCubicBezierCurve (_abg ,0,_abg ,-_gfb ,_fde ,-_cbe ,0,-_cbe ));_ff =_ff .AppendCurve (NewCubicBezierCurve (0,-_cbe ,-_fde ,-_cbe ,-_abg ,-_gfb ,-_abg ,0));_ff =_ff .Offset (_abg ,_cbe );if _gfc .BorderEnabled {_ff =_ff .Offset (_gfc .BorderWidth /2,_gfc .BorderWidth /2);};if _gfc .X !=0||_gfc .Y !=0{_ff =_ff .Offset (_gfc .X ,_gfc .Y );};_abc :=_ab .NewContentCreator ();_abc .Add_q ();if _gfc .FillEnabled {_abc .Add_rg (_gfc .FillColor .R (),_gfc .FillColor .G (),_gfc .FillColor .B ());};if _gfc .BorderEnabled {_abc .Add_RG (_gfc .BorderColor .R (),_gfc .BorderColor .G (),_gfc .BorderColor .B ());_abc .Add_w (_gfc .BorderWidth );};if len (gsName )> 1{_abc .Add_gs (_b .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_ff ,_abc );_abc .Add_h ();if _gfc .FillEnabled &&_gfc .BorderEnabled {_abc .Add_B ();}else if _gfc .FillEnabled {_abc .Add_f ();}else if _gfc .BorderEnabled {_abc .Add_S ();};_abc .Add_Q ();_feg :=_ff .GetBoundingBox ();if _gfc .BorderEnabled {_feg .Height +=_gfc .BorderWidth ;_feg .Width +=_gfc .BorderWidth ;_feg .X -=_gfc .BorderWidth /2;_feg .Y -=_gfc .BorderWidth /2;};return _abc .Bytes (),_feg .ToPdfRectangle (),nil ;};
// GetBoundingBox returns the bounding box of the Bezier path.
func (_fg CubicBezierPath )GetBoundingBox ()Rectangle {_g :=Rectangle {};_afc :=0.0;_fba :=0.0;_fbg :=0.0;_dde :=0.0;for _be ,_cd :=range _fg .Curves {_dfc :=_cd .GetBounds ();if _be ==0{_afc =_dfc .Llx ;_fba =_dfc .Urx ;_fbg =_dfc .Lly ;_dde =_dfc .Ury ;continue ;};if _dfc .Llx < _afc {_afc =_dfc .Llx ;};if _dfc .Urx > _fba {_fba =_dfc .Urx ;};if _dfc .Lly < _fbg {_fbg =_dfc .Lly ;};if _dfc .Ury > _dde {_dde =_dfc .Ury ;};};_g .X =_afc ;_g .Y =_fbg ;_g .Width =_fba -_afc ;_g .Height =_dde -_fbg ;return _g ;};
// NewVector returns a new vector with the direction specified by dx and dy.
func NewVector (dx ,dy float64 )Vector {_bfb :=Vector {};_bfb .Dx =dx ;_bfb .Dy =dy ;return _bfb };
// AddOffsetXY adds X,Y offset to all points on a curve.
func (_bc CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_bc .P0 .X +=offX ;_bc .P1 .X +=offX ;_bc .P2 .X +=offX ;_bc .P3 .X +=offX ;_bc .P0 .Y +=offY ;_bc .P1 .Y +=offY ;_bc .P2 .Y +=offY ;_bc .P3 .Y +=offY ;return _bc ;};
// Flip changes the sign of the vector: -vector.
func (_ebgg Vector )Flip ()Vector {_cef :=_ebgg .Magnitude ();_fbf :=_ebgg .GetPolarAngle ();_ebgg .Dx =_cef *_f .Cos (_fbf +_f .Pi );_ebgg .Dy =_cef *_f .Sin (_fbf +_f .Pi );return _ebgg ;};
func (_bgb Vector )Flip ()Vector {_cfcb :=_bgb .Magnitude ();_dgg :=_bgb .GetPolarAngle ();_bgb .Dx =_cfcb *_e .Cos (_dgg +_e .Pi );_bgb .Dy =_cfcb *_e .Sin (_dgg +_e .Pi );return _bgb ;};func (_gg Point )String ()string {return _c .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_gg .X ,_gg .Y );
};
// FlipY flips the sign of the Dy component of the vector.
func (_gga Vector )FlipY ()Vector {_gga .Dy =-_gga .Dy ;return _gga };
// Add adds the specified vector to the current one and returns the result.
func (_fbb Vector )Add (other Vector )Vector {_fbb .Dx +=other .Dx ;_fbb .Dy +=other .Dy ;return _fbb };
// 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 *_cg .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
// GetBounds returns the bounding box of the Bezier curve.
func (_a CubicBezierCurve )GetBounds ()_cg .PdfRectangle {_bg :=_a .P0 .X ;_bb :=_a .P0 .X ;_cd :=_a .P0 .Y ;_g :=_a .P0 .Y ;for _cea :=0.0;_cea <=1.0;_cea +=0.001{Rx :=_a .P0 .X *_e .Pow (1-_cea ,3)+_a .P1 .X *3*_cea *_e .Pow (1-_cea ,2)+_a .P2 .X *3*_e .Pow (_cea ,2)*(1-_cea )+_a .P3 .X *_e .Pow (_cea ,3);
Ry :=_a .P0 .Y *_e .Pow (1-_cea ,3)+_a .P1 .Y *3*_cea *_e .Pow (1-_cea ,2)+_a .P2 .Y *3*_e .Pow (_cea ,2)*(1-_cea )+_a .P3 .Y *_e .Pow (_cea ,3);if Rx < _bg {_bg =Rx ;};if Rx > _bb {_bb =Rx ;};if Ry < _cd {_cd =Ry ;};if Ry > _g {_g =Ry ;};};_ed :=_cg .PdfRectangle {};
_ed .Llx =_bg ;_ed .Lly =_cd ;_ed .Urx =_bb ;_ed .Ury =_g ;return _ed ;};
// Rotate rotates the vector by the specified angle.
func (_fbee Vector )Rotate (phi float64 )Vector {_dfd :=_fbee .Magnitude ();_fed :=_fbee .GetPolarAngle ();return NewVectorPolar (_dfd ,_fed +phi );};
// 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 (_gdfg Polygon )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){_cfg :=_d .NewContentCreator ();_cfg .Add_q ();_gdfg .FillEnabled =_gdfg .FillEnabled &&_gdfg .FillColor !=nil ;if _gdfg .FillEnabled {_cfg .Add_rg (_gdfg .FillColor .R (),_gdfg .FillColor .G (),_gdfg .FillColor .B ());
};_gdfg .BorderEnabled =_gdfg .BorderEnabled &&_gdfg .BorderColor !=nil ;if _gdfg .BorderEnabled {_cfg .Add_RG (_gdfg .BorderColor .R (),_gdfg .BorderColor .G (),_gdfg .BorderColor .B ());_cfg .Add_w (_gdfg .BorderWidth );};if len (gsName )> 1{_cfg .Add_gs (_bf .PdfObjectName (gsName ));
};_egb :=NewPath ();for _ ,_feg :=range _gdfg .Points {for _bfd ,_fg :=range _feg {_egb =_egb .AppendPoint (_fg );if _bfd ==0{_cfg .Add_m (_fg .X ,_fg .Y );}else {_cfg .Add_l (_fg .X ,_fg .Y );};};_cfg .Add_h ();};if _gdfg .FillEnabled &&_gdfg .BorderEnabled {_cfg .Add_B ();
}else if _gdfg .FillEnabled {_cfg .Add_f ();}else if _gdfg .BorderEnabled {_cfg .Add_S ();};_cfg .Add_Q ();return _cfg .Bytes (),_egb .GetBoundingBox ().ToPdfRectangle (),nil ;};
// AppendPoint adds the specified point to the path.
func (_eef Path )AppendPoint (point Point )Path {_eef .Points =append (_eef .Points ,point );return _eef };
// GetBoundingBox returns the bounding box of the Bezier path.
func (_db CubicBezierPath )GetBoundingBox ()Rectangle {_ea :=Rectangle {};_fa :=0.0;_aa :=0.0;_fdc :=0.0;_gf :=0.0;for _fc ,_fab :=range _db .Curves {_bca :=_fab .GetBounds ();if _fc ==0{_fa =_bca .Llx ;_aa =_bca .Urx ;_fdc =_bca .Lly ;_gf =_bca .Ury ;
continue ;};if _bca .Llx < _fa {_fa =_bca .Llx ;};if _bca .Urx > _aa {_aa =_bca .Urx ;};if _bca .Lly < _fdc {_fdc =_bca .Lly ;};if _bca .Ury > _gf {_gf =_bca .Ury ;};};_ea .X =_fa ;_ea .Y =_fdc ;_ea .Width =_aa -_fa ;_ea .Height =_gf -_fdc ;return _ea ;
};
// Draw draws the basic line to PDF. Generates the content stream which can be used in page contents or appearance
// stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error if
// one occurred.
func (_gb BasicLine )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){_dff :=_gb .LineWidth ;_cad :=NewPath ();_cad =_cad .AppendPoint (NewPoint (_gb .X1 ,_gb .Y1 ));_cad =_cad .AppendPoint (NewPoint (_gb .X2 ,_gb .Y2 ));_gaa :=_d .NewContentCreator ();
_baeb :=_cad .GetBoundingBox ();DrawPathWithCreator (_cad ,_gaa );if _gb .LineStyle ==LineStyleDashed {_gaa .Add_d ([]int64 {1,1},0);};_gaa .Add_RG (_gb .LineColor .R (),_gb .LineColor .G (),_gb .LineColor .B ()).Add_w (_dff ).Add_S ().Add_Q ();return _gaa .Bytes (),_baeb .ToPdfRectangle (),nil ;
};
// Draw draws the line to PDF contentstream. Generates the content stream which can be used in page contents or
// appearance stream of annotation. Returns the stream content, XForm bounding box (local), bounding box and an error
// if one occurred.
func (_ag Line )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){_fdg ,_bbe :=_ag .X1 ,_ag .X2 ;_fbe ,_ca :=_ag .Y1 ,_ag .Y2 ;_edb :=_ca -_fbe ;_feb :=_bbe -_fdg ;_gag :=_e .Atan2 (_edb ,_feb );L :=_e .Sqrt (_e .Pow (_feb ,2.0)+_e .Pow (_edb ,2.0));
_dd :=_ag .LineWidth ;_af :=_e .Pi ;_cgb :=1.0;if _feb < 0{_cgb *=-1.0;};if _edb < 0{_cgb *=-1.0;};VsX :=_cgb *(-_dd /2*_e .Cos (_gag +_af /2));VsY :=_cgb *(-_dd /2*_e .Sin (_gag +_af /2)+_dd *_e .Sin (_gag +_af /2));V1X :=VsX +_dd /2*_e .Cos (_gag +_af /2);
V1Y :=VsY +_dd /2*_e .Sin (_gag +_af /2);V2X :=VsX +_dd /2*_e .Cos (_gag +_af /2)+L *_e .Cos (_gag );V2Y :=VsY +_dd /2*_e .Sin (_gag +_af /2)+L *_e .Sin (_gag );V3X :=VsX +_dd /2*_e .Cos (_gag +_af /2)+L *_e .Cos (_gag )+_dd *_e .Cos (_gag -_af /2);V3Y :=VsY +_dd /2*_e .Sin (_gag +_af /2)+L *_e .Sin (_gag )+_dd *_e .Sin (_gag -_af /2);
V4X :=VsX +_dd /2*_e .Cos (_gag -_af /2);V4Y :=VsY +_dd /2*_e .Sin (_gag -_af /2);_bae :=NewPath ();_bae =_bae .AppendPoint (NewPoint (V1X ,V1Y ));_bae =_bae .AppendPoint (NewPoint (V2X ,V2Y ));_bae =_bae .AppendPoint (NewPoint (V3X ,V3Y ));_bae =_bae .AppendPoint (NewPoint (V4X ,V4Y ));
_aee :=_ag .LineEndingStyle1 ;_eeg :=_ag .LineEndingStyle2 ;_cae :=3*_dd ;_eb :=3*_dd ;_fbf :=(_eb -_dd )/2;if _eeg ==LineEndingStyleArrow {_dfc :=_bae .GetPointNumber (2);_cfe :=NewVectorPolar (_cae ,_gag +_af );_bfb :=_dfc .AddVector (_cfe );_gac :=NewVectorPolar (_eb /2,_gag +_af /2);
_fea :=NewVectorPolar (_cae ,_gag );_fdd :=NewVectorPolar (_fbf ,_gag +_af /2);_eec :=_bfb .AddVector (_fdd );_da :=_fea .Add (_gac .Flip ());_add :=_eec .AddVector (_da );_fgc :=_gac .Scale (2).Flip ().Add (_da .Flip ());_gdff :=_add .AddVector (_fgc );
_gfd :=_bfb .AddVector (NewVectorPolar (_dd ,_gag -_af /2));_gccb :=NewPath ();_gccb =_gccb .AppendPoint (_bae .GetPointNumber (1));_gccb =_gccb .AppendPoint (_bfb );_gccb =_gccb .AppendPoint (_eec );_gccb =_gccb .AppendPoint (_add );_gccb =_gccb .AppendPoint (_gdff );
_gccb =_gccb .AppendPoint (_gfd );_gccb =_gccb .AppendPoint (_bae .GetPointNumber (4));_bae =_gccb ;};if _aee ==LineEndingStyleArrow {_agf :=_bae .GetPointNumber (1);_ceb :=_bae .GetPointNumber (_bae .Length ());_edd :=NewVectorPolar (_dd /2,_gag +_af +_af /2);
_egf :=_agf .AddVector (_edd );_agb :=NewVectorPolar (_cae ,_gag ).Add (NewVectorPolar (_eb /2,_gag +_af /2));_edg :=_egf .AddVector (_agb );_cfd :=NewVectorPolar (_fbf ,_gag -_af /2);_bdg :=_edg .AddVector (_cfd );_ebb :=NewVectorPolar (_cae ,_gag );_fgd :=_ceb .AddVector (_ebb );
_fac :=NewVectorPolar (_fbf ,_gag +_af +_af /2);_fgb :=_fgd .AddVector (_fac );_dab :=_egf ;_gcb :=NewPath ();_gcb =_gcb .AppendPoint (_egf );_gcb =_gcb .AppendPoint (_edg );_gcb =_gcb .AppendPoint (_bdg );for _ ,_ebba :=range _bae .Points [1:len (_bae .Points )-1]{_gcb =_gcb .AppendPoint (_ebba );
};_gcb =_gcb .AppendPoint (_fgd );_gcb =_gcb .AppendPoint (_fgb );_gcb =_gcb .AppendPoint (_dab );_bae =_gcb ;};_dcg :=_d .NewContentCreator ();_dcg .Add_q ().Add_rg (_ag .LineColor .R (),_ag .LineColor .G (),_ag .LineColor .B ());if len (gsName )> 1{_dcg .Add_gs (_bf .PdfObjectName (gsName ));
};_bae =_bae .Offset (_ag .X1 ,_ag .Y1 );_cbe :=_bae .GetBoundingBox ();DrawPathWithCreator (_bae ,_dcg );if _ag .LineStyle ==LineStyleDashed {_dcg .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_dcg .Add_f ().Add_Q ();};return _dcg .Bytes (),_cbe .ToPdfRectangle (),nil ;
};
// Draw draws the rectangle. Can specify a graphics state (gsName) for setting opacity etc.
// Otherwise leave empty (""). Returns the content stream as a byte array, bounding box and an error on failure.
func (_cfc Rectangle )Draw (gsName string )([]byte ,*_cg .PdfRectangle ,error ){_ab :=NewPath ();_ab =_ab .AppendPoint (NewPoint (0,0));_ab =_ab .AppendPoint (NewPoint (0,_cfc .Height ));_ab =_ab .AppendPoint (NewPoint (_cfc .Width ,_cfc .Height ));_ab =_ab .AppendPoint (NewPoint (_cfc .Width ,0));
_ab =_ab .AppendPoint (NewPoint (0,0));if _cfc .X !=0||_cfc .Y !=0{_ab =_ab .Offset (_cfc .X ,_cfc .Y );};_cbb :=_d .NewContentCreator ();_cbb .Add_q ();if _cfc .FillEnabled {_cbb .Add_rg (_cfc .FillColor .R (),_cfc .FillColor .G (),_cfc .FillColor .B ());
};if _cfc .BorderEnabled {_cbb .Add_RG (_cfc .BorderColor .R (),_cfc .BorderColor .G (),_cfc .BorderColor .B ());_cbb .Add_w (_cfc .BorderWidth );};if len (gsName )> 1{_cbb .Add_gs (_bf .PdfObjectName (gsName ));};DrawPathWithCreator (_ab ,_cbb );_cbb .Add_h ();
if _cfc .FillEnabled &&_cfc .BorderEnabled {_cbb .Add_B ();}else if _cfc .FillEnabled {_cbb .Add_f ();}else if _cfc .BorderEnabled {_cbb .Add_S ();};_cbb .Add_Q ();return _cbb .Bytes (),_ab .GetBoundingBox ().ToPdfRectangle (),nil ;};
// Rotate returns a new Point at `p` rotated by `theta` degrees.
func (_bg Point )Rotate (theta float64 )Point {_fa :=_af .NewPoint (_bg .X ,_bg .Y ).Rotate (theta );return NewPoint (_fa .X ,_fa .Y );};
func (_ac Point )Rotate (theta float64 )Point {_cec :=_ce .NewPoint (_ac .X ,_ac .Y ).Rotate (theta );return NewPoint (_cec .X ,_cec .Y );};
// NewVectorPolar returns a new vector calculated from the specified
// magnitude and angle.
func NewVectorPolar (length float64 ,theta float64 )Vector {_aeb :=Vector {};_aeb .Dx =length *_f .Cos (theta );_aeb .Dy =length *_f .Sin (theta );return _aeb ;};
// RemovePoint removes the point at the index specified by number from the
// path. The index is 1-based.
func (_bgd Path )RemovePoint (number int )Path {if number < 1||number > len (_bgd .Points ){return _bgd ;};_fde :=number -1;_bgd .Points =append (_bgd .Points [:_fde ],_bgd .Points [_fde +1:]...);return _bgd ;};
// NewPath returns a new empty path.
func NewPath ()Path {return Path {}};
// Vector represents a two-dimensional vector.
type Vector struct{Dx float64 ;Dy float64 ;};
// BoundingBox represents the smallest rectangular area that encapsulates an object.
type BoundingBox struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;};
// 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 *_cg .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_cg .PdfColorDeviceRGB ;Opacity float64 ;};

File diff suppressed because one or more lines are too long

View File

@ -9,73 +9,53 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package crypt ;import (_a "crypto/aes";_g "crypto/cipher";_c "crypto/md5";_ea "crypto/rand";_bac "crypto/rc4";_ba "fmt";_ed "github.com/unidoc/unipdf/v3/common";_ac "github.com/unidoc/unipdf/v3/core/security";_e "io";);func init (){_abd ("\u0041\u0045\u0053V\u0032",_gc )};
package crypt ;import (_b "crypto/aes";_fe "crypto/cipher";_be "crypto/md5";_a "crypto/rand";_c "crypto/rc4";_g "fmt";_aa "github.com/unidoc/unipdf/v3/common";_ba "github.com/unidoc/unipdf/v3/core/security";_fc "io";);func init (){_bea ("\u0041\u0045\u0053V\u0032",_af )};
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_ff ,_gg :=_gce (FilterDict {Length :length });if _gg !=nil {_ed .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",_gg );return filterV2 {_da :length };};return _ff ;};
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_eee ,_gcd :=_c .NewCipher (okey );if _gcd !=nil {return nil ,_gcd ;};_aa .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );
_eee .XORKeyStream (buf ,buf );_aa .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_gc ,_bf :=_cf (FilterDict {});if _bf !=nil {_aa .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",_bf );
return filterAESV3 {};};return _gc ;};var _ Filter =filterAESV2 {};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};type filterAESV3 struct{filterAES };func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };func init (){_bea ("\u0041\u0045\u0053V\u0033",_cf )};
// 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 };
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _aaf (objNum ,genNum ,ekey ,true );};func _fed (_gdd string )(filterFunc ,error ){_bcg :=_fcf [_gdd ];if _bcg ==nil {return nil ,_g .Errorf ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u0072\u0079p\u0074 \u0066\u0069\u006c\u0074\u0065\u0072\u003a \u0025\u0071",_gdd );
};return _bcg ,nil ;};func _cf (_bd FilterDict )(Filter ,error ){if _bd .Length ==256{_aa .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",_bd .Length );
_bd .Length /=8;};if _bd .Length !=0&&_bd .Length !=32{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0033\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_bd .Length );
};return filterAESV3 {},nil ;};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func _bea (_gb string ,_gba filterFunc ){if _ ,_fdf :=_fcf [_gb ];_fdf {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_fcf [_gb ]=_gba ;
};
// MakeKey implements Filter interface.
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
// Name implements Filter interface.
func (filterV2 )Name ()string {return "\u0056\u0032"};type filterAES struct{};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func _ab (_d FilterDict )(Filter ,error ){if _d .Length ==256{_ed .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",_d .Length );_d .Length /=8;};if _d .Length !=0&&_d .Length !=32{return nil ,_ba .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",_d .Length );};return filterAESV3 {},nil ;};var (_acb =make (map[string ]filterFunc ););
// MakeKey implements Filter interface.
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ebc (objNum ,genNum ,ekey ,true );};
// KeyLength implements Filter interface.
func (filterAESV3 )KeyLength ()int {return 256/8};func init (){_abd ("\u0041\u0045\u0053V\u0033",_ab )};func _aadf (_cad string )(filterFunc ,error ){_ceg :=_acb [_cad ];if _ceg ==nil {return nil ,_ba .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",_cad );};return _ceg ,nil ;};
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gfdd ,_eab :=_bac .NewCipher (okey );if _eab !=nil {return nil ,_eab ;};_ed .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_gfdd .XORKeyStream (buf ,buf );_ed .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _gc (_gb FilterDict )(Filter ,error ){if _gb .Length ==128{_ed .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",_gb .Length );_gb .Length /=8;};if _gb .Length !=0&&_gb .Length !=16{return nil ,_ba .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",_gb .Length );};return filterAESV2 {},nil ;};
// EncryptBytes implements Filter interface.
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ddg ,_gfd :=_bac .NewCipher (okey );if _gfd !=nil {return nil ,_gfd ;};_ed .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ddg .XORKeyStream (buf ,buf );_ed .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// PDFVersion implements Filter interface.
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ga ,_ag :=_a .NewCipher (okey );if _ag !=nil {return nil ,_ag ;};if len (buf )< 16{_ed .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 ,_ba .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_edc :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ed .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_edc ),_edc );_ed .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_ba .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 ));};_gba :=_g .NewCBCDecrypter (_ga ,_edc );_ed .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ed .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 );_gba .CryptBlocks (buf ,buf );_ed .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ed .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 ;};_ec :=int (buf [len (buf )-1]);if _ec > len (buf ){_ed .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",_ec ,len (buf ));return buf ,_ba .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ec ];return buf ,nil ;};
// PDFVersion implements Filter interface.
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};type filterAESV3 struct{filterAES };
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
func NewFilterAESV3 ()Filter {_be ,_gcf :=_ab (FilterDict {});if _gcf !=nil {_ed .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",_gcf );return filterAESV3 {};};return _be ;};
// MakeKey implements Filter interface.
func (_cge filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ebc (objNum ,genNum ,ekey ,false );};
// KeyLength implements Filter interface.
func (_ccf filterV2 )KeyLength ()int {return _ccf ._da };func init (){_abd ("\u0056\u0032",_gce )};
// NewIdentity creates an identity filter that bypasses all data without changes.
func NewIdentity ()Filter {return filterIdentity {}};var _ Filter =filterV2 {};func _gce (_bcf FilterDict )(Filter ,error ){if _bcf .Length %8!=0{return nil ,_ba .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",_bcf .Length );};if _bcf .Length < 5||_bcf .Length > 16{if _bcf .Length ==40||_bcf .Length ==64||_bcf .Length ==128{_ed .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",_bcf .Length );_bcf .Length /=8;}else {return nil ,_ba .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",_bcf .Length );};};return filterV2 {_da :_bcf .Length },nil ;};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};
// Name implements Filter interface.
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};func _abd (_dbd string ,_aac filterFunc ){if _ ,_age :=_acb [_dbd ];_age {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_acb [_dbd ]=_aac ;};type filterAESV2 struct{filterAES };func (filterIdentity )KeyLength ()int {return 0};
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};
// PDFVersion implements Filter interface.
func (_bce filterV2 )PDFVersion ()[2]int {return [2]int {}};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
// HandlerVersion implements Filter interface.
func (_bae filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_fg ,_eac :=_aadf (d .CFM );if _eac !=nil {return nil ,_eac ;};_cb ,_eac :=_fg (d );if _eac !=nil {return nil ,_eac ;};return _cb ,nil ;};
// FilterDict represents information from a CryptFilter dictionary.
type FilterDict struct{CFM string ;AuthEvent _ac .AuthEvent ;Length int ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};type filterIdentity struct{};var _ Filter =filterAESV3 {};
type FilterDict struct{CFM string ;AuthEvent _ba .AuthEvent ;Length int ;};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_ad ,_ef :=_gc (FilterDict {});if _ef !=nil {_ed .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 _ad ;};func _ebc (_cf ,_dc uint32 ,_gga []byte ,_db bool )([]byte ,error ){_aad :=make ([]byte ,len (_gga )+5);for _gbd :=0;_gbd < len (_gga );_gbd ++{_aad [_gbd ]=_gga [_gbd ];};for _cd :=0;_cd < 3;_cd ++{_ggf :=byte ((_cf >>uint32 (8*_cd ))&0xff);_aad [_cd +len (_gga )]=_ggf ;};for _ebb :=0;_ebb < 2;_ebb ++{_gd :=byte ((_dc >>uint32 (8*_ebb ))&0xff);_aad [_ebb +len (_gga )+3]=_gd ;};if _db {_aad =append (_aad ,0x73);_aad =append (_aad ,0x41);_aad =append (_aad ,0x6C);_aad =append (_aad ,0x54);};_bba :=_c .New ();_bba .Write (_aad );_gfc :=_bba .Sum (nil );if len (_gga )+5< 16{return _gfc [0:len (_gga )+5],nil ;};return _gfc ,nil ;};
// Name implements Filter interface.
func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};type filterIdentity struct{};
// HandlerVersion implements Filter interface.
func (_dc filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};func init (){_bea ("\u0056\u0032",_bdd )};
// KeyLength implements Filter interface.
func (_dg filterV2 )KeyLength ()int {return _dg ._geg };
// Filter is a common interface for crypt filter methods.
type Filter interface{
@ -94,15 +74,62 @@ 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 (_gcb ,_bfb uint32 ,_gcbb []byte )([]byte ,error );
MakeKey (_gagb ,_cbc uint32 ,_gdc []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 (_de []byte ,_bacd []byte )([]byte ,error );
EncryptBytes (_bb []byte ,_aaa []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 (_dae []byte ,_bbe []byte )([]byte ,error );};var _ Filter =filterAESV2 {};
DecryptBytes (_bfc []byte ,_cd []byte )([]byte ,error );};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};var _ Filter =filterAESV3 {};
// MakeKey implements Filter interface.
func (_aad filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _aaf (objNum ,genNum ,ekey ,false );};
// PDFVersion implements Filter interface.
func (_aaff filterV2 )PDFVersion ()[2]int {return [2]int {}};func (filterIdentity )KeyLength ()int {return 0};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_fb ,_cg :=_b .NewCipher (okey );if _cg !=nil {return nil ,_cg ;};if len (buf )< 16{_aa .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );
return buf ,_g .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_beg :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_aa .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_beg ),_beg );
_aa .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_g .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));
};_fee :=_fe .NewCBCDecrypter (_fb ,_beg );_aa .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_aa .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 );
_fee .CryptBlocks (buf ,buf );_aa .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_aa .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 ;};_ef :=int (buf [len (buf )-1]);if _ef > len (buf ){_aa .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",_ef ,len (buf ));
return buf ,_g .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_ef ];return buf ,nil ;};
// HandlerVersion implements Filter interface.
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func _bdd (_eb FilterDict )(Filter ,error ){if _eb .Length %8!=0{return nil ,_g .Errorf ("\u0063\u0072\u0079p\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069\u0070\u006c\u0065\u0020o\u0066\u0020\u0038\u0020\u0028\u0025\u0064\u0029",_eb .Length );
};if _eb .Length < 5||_eb .Length > 16{if _eb .Length ==40||_eb .Length ==64||_eb .Length ==128{_aa .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",_eb .Length );
_eb .Length /=8;}else {return nil ,_g .Errorf ("\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006c\u0065\u006e\u0067\u0074h\u0020\u006e\u006f\u0074\u0020\u0069\u006e \u0072\u0061\u006e\u0067\u0065\u0020\u0034\u0030\u0020\u002d\u00201\u0032\u0038\u0020\u0062\u0069\u0074\u0020\u0028\u0025\u0064\u0029",_eb .Length );
};};return filterV2 {_geg :_eb .Length },nil ;};
// NewFilter creates CryptFilter from a corresponding dictionary.
func NewFilter (d FilterDict )(Filter ,error ){_bcce ,_ff :=_fed (d .CFM );if _ff !=nil {return nil ,_ff ;};_fce ,_ff :=_bcce (d );if _ff !=nil {return nil ,_ff ;};return _fce ,nil ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
type filterAESV2 struct{filterAES };
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
func NewFilterV2 (length int )Filter {_gg ,_cgc :=_bdd (FilterDict {Length :length });if _cgc !=nil {_aa .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",_cgc );
return filterV2 {_geg :length };};return _gg ;};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ee ,_gd :=_b .NewCipher (okey );if _gd !=nil {return nil ,_gd ;};_aa .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );
const _agc =_b .BlockSize ;_gdb :=_agc -len (buf )%_agc ;for _ga :=0;_ga < _gdb ;_ga ++{buf =append (buf ,byte (_gdb ));};_aa .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_eef :=make ([]byte ,_agc +len (buf ));
_fg :=_eef [:_agc ];if _ ,_gag :=_fc .ReadFull (_a .Reader ,_fg );_gag !=nil {return nil ,_gag ;};_bc :=_fe .NewCBCEncrypter (_ee ,_fg );_bc .CryptBlocks (_eef [_agc :],buf );buf =_eef ;_aa .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );
return buf ,nil ;};
// HandlerVersion implements Filter interface.
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_aa ,_cc :=_a .NewCipher (okey );if _cc !=nil {return nil ,_cc ;};_ed .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _bf =_a .BlockSize ;_f :=_bf -len (buf )%_bf ;for _ca :=0;_ca < _f ;_ca ++{buf =append (buf ,byte (_f ));};_ed .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_af :=make ([]byte ,_bf +len (buf ));_bb :=_af [:_bf ];if _ ,_fe :=_e .ReadFull (_ea .Reader ,_bb );_fe !=nil {return nil ,_fe ;};_gf :=_g .NewCBCEncrypter (_aa ,_bb );_gf .CryptBlocks (_af [_bf :],buf );buf =_af ;_ed .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};type filterV2 struct{_da int };type filterFunc func (_ffe FilterDict )(Filter ,error );func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
func (filterAESV3 )KeyLength ()int {return 256/8};var _ Filter =filterV2 {};type filterFunc func (_ggd FilterDict )(Filter ,error );
// DecryptBytes implements Filter interface.
func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ea ,_cc :=_c .NewCipher (okey );if _cc !=nil {return nil ,_cc ;};_aa .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_ea .XORKeyStream (buf ,buf );
_aa .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};var (_fcf =make (map[string ]filterFunc ););func _aaf (_ad ,_bcc uint32 ,_adc []byte ,_bae bool )([]byte ,error ){_fd :=make ([]byte ,len (_adc )+5);for _bfb :=0;_bfb < len (_adc );
_bfb ++{_fd [_bfb ]=_adc [_bfb ];};for _fca :=0;_fca < 3;_fca ++{_eg :=byte ((_ad >>uint32 (8*_fca ))&0xff);_fd [_fca +len (_adc )]=_eg ;};for _cb :=0;_cb < 2;_cb ++{_aafg :=byte ((_bcc >>uint32 (8*_cb ))&0xff);_fd [_cb +len (_adc )+3]=_aafg ;};if _bae {_fd =append (_fd ,0x73);
_fd =append (_fd ,0x41);_fd =append (_fd ,0x6C);_fd =append (_fd ,0x54);};_efb :=_be .New ();_efb .Write (_fd );_cgcc :=_efb .Sum (nil );if len (_adc )+5< 16{return _cgcc [0:len (_adc )+5],nil ;};return _cgcc ,nil ;};
// KeyLength implements Filter interface.
func (filterAESV2 )KeyLength ()int {return 128/8};type filterV2 struct{_geg int };func _af (_aab FilterDict )(Filter ,error ){if _aab .Length ==128{_aa .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",_aab .Length );
_aab .Length /=8;};if _aab .Length !=0&&_aab .Length !=16{return nil ,_g .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0041\u0045\u0053\u0056\u0032\u0020\u0063\u0072\u0079\u0070\u0074\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006c\u0065\u006eg\u0074\u0068 \u0028\u0025\u0064\u0029",_aab .Length );
};return filterAESV2 {},nil ;};
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
func NewFilterAESV2 ()Filter {_ge ,_ac :=_af (FilterDict {});if _ac !=nil {_aa .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",_ac );
return filterAESV2 {};};return _ge ;};type filterAES struct{};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,28 +10,32 @@
// 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";_a "github.com/unidoc/unipdf/v3/core";_ab "github.com/unidoc/unipdf/v3/model";_g "io";_d "os";);
// JSON returns the field data as a string in JSON format.
func (_fd FieldData )JSON ()(string ,error ){_aaf ,_bdea :=_e .MarshalIndent (_fd ._ae ,"","\u0020\u0020\u0020\u0020");return string (_aaf ),_bdea ;};
// FieldData represents form field data loaded from JSON file.
type FieldData struct{_ae []fieldValue };
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_c ,_gd :=_d .Open (filePath );if _gd !=nil {return nil ,_gd ;};defer _c .Close ();return LoadFromJSON (_c );};
package fjson ;import (_g "encoding/json";_ga "github.com/unidoc/unipdf/v3/core";_ba "github.com/unidoc/unipdf/v3/model";_c "io";_e "os";);
// LoadFromJSON loads JSON form data from `r`.
func LoadFromJSON (r _g .Reader )(*FieldData ,error ){var _bg FieldData ;_ee :=_e .NewDecoder (r ).Decode (&_bg ._ae );if _ee !=nil {return nil ,_ee ;};return &_bg ,nil ;};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_cb ,_cd :=_d .Open (filePath );if _cd !=nil {return nil ,_cd ;};defer _cb .Close ();return LoadFromPDF (_cb );};
func LoadFromJSON (r _c .Reader )(*FieldData ,error ){var _cd FieldData ;_ee :=_g .NewDecoder (r ).Decode (&_cd ._a );if _ee !=nil {return nil ,_ee ;};return &_cd ,nil ;};
// LoadFromPDF loads form field data from a PDF.
func LoadFromPDF (rs _g .ReadSeeker )(*FieldData ,error ){_df ,_bb :=_ab .NewPdfReader (rs );if _bb !=nil {return nil ,_bb ;};if _df .AcroForm ==nil {return nil ,nil ;};var _ca []fieldValue ;_cc :=_df .AcroForm .AllFields ();for _ ,_cab :=range _cc {var _f []string ;_ac :=make (map[string ]struct{});_bac ,_bf :=_cab .FullName ();if _bf !=nil {return nil ,_bf ;};if _de ,_gde :=_cab .V .(*_a .PdfObjectString );_gde {_ca =append (_ca ,fieldValue {Name :_bac ,Value :_de .Decoded ()});continue ;};var _gf string ;for _ ,_gc :=range _cab .Annotations {_ef ,_fe :=_a .GetName (_gc .AS );if _fe {_gf =_ef .String ();};_cg ,_ad :=_a .GetDict (_gc .AP );if !_ad {continue ;};_da ,_ :=_a .GetDict (_cg .Get ("\u004e"));for _ ,_dg :=range _da .Keys (){_adb :=_dg .String ();if _ ,_aa :=_ac [_adb ];!_aa {_f =append (_f ,_adb );_ac [_adb ]=struct{}{};};};_af ,_ :=_a .GetDict (_cg .Get ("\u0044"));for _ ,_dc :=range _af .Keys (){_ge :=_dc .String ();if _ ,_bde :=_ac [_ge ];!_bde {_f =append (_f ,_ge );_ac [_ge ]=struct{}{};};};};_dff :=fieldValue {Name :_bac ,Value :_gf ,Options :_f };_ca =append (_ca ,_dff );};_eee :=FieldData {_ae :_ca };return &_eee ,nil ;};
func LoadFromPDF (rs _c .ReadSeeker )(*FieldData ,error ){_f ,_ae :=_ba .NewPdfReader (rs );if _ae !=nil {return nil ,_ae ;};if _f .AcroForm ==nil {return nil ,nil ;};var _d []fieldValue ;_gcd :=_f .AcroForm .AllFields ();for _ ,_be :=range _gcd {var _cg []string ;
_fe :=make (map[string ]struct{});_ad ,_ag :=_be .FullName ();if _ag !=nil {return nil ,_ag ;};if _bc ,_ef :=_be .V .(*_ga .PdfObjectString );_ef {_d =append (_d ,fieldValue {Name :_ad ,Value :_bc .Decoded ()});continue ;};var _eb string ;for _ ,_abb :=range _be .Annotations {_bed ,_gb :=_ga .GetName (_abb .AS );
if _gb {_eb =_bed .String ();};_gcda ,_ca :=_ga .GetDict (_abb .AP );if !_ca {continue ;};_ac ,_ :=_ga .GetDict (_gcda .Get ("\u004e"));for _ ,_cbd :=range _ac .Keys (){_ebf :=_cbd .String ();if _ ,_dc :=_fe [_ebf ];!_dc {_cg =append (_cg ,_ebf );_fe [_ebf ]=struct{}{};
};};_ce ,_ :=_ga .GetDict (_gcda .Get ("\u0044"));for _ ,_fa :=range _ce .Keys (){_gbf :=_fa .String ();if _ ,_cc :=_fe [_gbf ];!_cc {_cg =append (_cg ,_gbf );_fe [_gbf ]=struct{}{};};};};_ec :=fieldValue {Name :_ad ,Value :_eb ,Options :_cg };_d =append (_d ,_ec );
};_ge :=FieldData {_a :_d };return &_ge ,nil ;};
// LoadFromJSONFile loads form field data from a JSON file.
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_ab ,_gc :=_e .Open (filePath );if _gc !=nil {return nil ,_gc ;};defer _ab .Close ();return LoadFromJSON (_ab );};
// FieldValues implements model.FieldValueProvider interface.
func (_dgc *FieldData )FieldValues ()(map[string ]_a .PdfObject ,error ){_gb :=make (map[string ]_a .PdfObject );for _ ,_fb :=range _dgc ._ae {if len (_fb .Value )> 0{_gb [_fb .Name ]=_a .MakeString (_fb .Value );};};return _gb ,nil ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
func (_cad *FieldData )FieldValues ()(map[string ]_ga .PdfObject ,error ){_ecc :=make (map[string ]_ga .PdfObject );for _ ,_gce :=range _cad ._a {if len (_gce .Value )> 0{_ecc [_gce .Name ]=_ga .MakeString (_gce .Value );};};return _ecc ,nil ;};
// LoadFromPDFFile loads form field data from a PDF file.
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_ebd ,_da :=_e .Open (filePath );if _da !=nil {return nil ,_da ;};defer _ebd .Close ();return LoadFromPDF (_ebd );};
// JSON returns the field data as a string in JSON format.
func (_cdf FieldData )JSON ()(string ,error ){_feg ,_bgd :=_g .MarshalIndent (_cdf ._a ,"","\u0020\u0020\u0020\u0020");return string (_feg ),_bgd ;};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 };

20
go.sum
View File

@ -1,20 +1,32 @@
github.com/adrg/strutil v0.1.0 h1:IOQnSOAjbE17+7l1lw4rXgX6JuSeJGdZa7BucTMV3Qg=
github.com/adrg/strutil v0.1.0/go.mod h1:pXRr2+IyX5AEPAF5icj/EeTaiflPSD2hvGjnguilZgE=
github.com/adrg/sysfont v0.1.0 h1:vOk13USVkciGOJj9sPT9Gl9zfHUT2HZgsBnwS1Je4Q8=
github.com/adrg/sysfont v0.1.0/go.mod h1:DzISco90USPZJ+lmtpuz1SOTn1fih6YyB0KG2TEP/0U=
github.com/adrg/sysfont v0.1.1 h1:l9WKJNHsIpsfOhYIm1oSj+77837r/vls1MH17SH6gp0=
github.com/adrg/sysfont v0.1.1/go.mod h1:19nTHzfIn/HbngFMet+yNAvwSQYtOJYMI7vWexLWyNw=
github.com/adrg/xdg v0.2.1 h1:VSVdnH7cQ7V+B33qSJHTCRlNgra1607Q8PzEmnvb2Ic=
github.com/adrg/xdg v0.2.1/go.mod h1:ZuOshBmzV4Ta+s23hdfFZnBsdzmoR3US0d7ErpqSbTQ=
github.com/boombuler/barcode v1.0.0 h1:s1TvRnXwL2xJRaccrdcBQMZxq6X7DvsMogtmJeHDdrc=
github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/sirupsen/logrus v1.5.0 h1:1N5EYkVAPEywqZRJd7cwnRtCb6xJx7NH3T3WUTF980Q=
github.com/sirupsen/logrus v1.5.0/go.mod h1:+F7Ogzej0PZc/94MaYx/nvG9jOFMD2osvC3s+Squfpo=
github.com/stretchr/objx v0.1.0 h1:4G4v2dO3VZwixGIRoQ5Lfboy6nUhCyYzaqnIAPPhYs4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
@ -27,8 +39,12 @@ github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZV
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 h1:58fnuSXlxZmFdJyvtTFVmVhcMLU6v5fEb/ok4wyqtNU=
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0 h1:hb9wdF1z5waM+dSIICn1l0DkLVDT3hqhhQsDNUmHPRE=
golang.org/x/crypto v0.0.0-20201002170205-7f63de1d35b0/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b h1:VHyIDlv3XkfCa5/a81uzaoDkHH4rr81Z62g+xlnO8uM=
golang.org/x/image v0.0.0-20181116024801-cd38e8056d9b/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs=
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=
@ -37,14 +53,18 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
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 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
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=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,5 @@
// 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 (_ab "encoding/binary";_abd "unsafe";);func IsBig ()bool {return _f };func init (){const _e =int (_abd .Sizeof (0));_c :=1;_b :=(*[_e ]byte )(_abd .Pointer (&_c ));if _b [0]==0{_f =true ;ByteOrder =_ab .BigEndian ;}else {ByteOrder =_ab .LittleEndian ;};};func IsLittle ()bool {return !_f };var (ByteOrder _ab .ByteOrder ;_f bool ;);
package endian ;import (_c "encoding/binary";_b "unsafe";);var (ByteOrder _c .ByteOrder ;_f bool ;);func init (){const _ad =int (_b .Sizeof (0));_af :=1;_d :=(*[_ad ]byte )(_b .Pointer (&_af ));if _d [0]==0{_f =true ;ByteOrder =_c .BigEndian ;}else {ByteOrder =_c .LittleEndian ;
};};func IsLittle ()bool {return !_f };func IsBig ()bool {return _f };

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,15 @@
// 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 _a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";type IntsMap map[uint64 ][]int ;func (_bd NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_bd )-1{return 0,_a .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};return _bd [i ],nil ;};func (_ac IntSlice )Get (index int )(int ,error ){if index > len (_ac )-1{return 0,_a .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );};return _ac [index ],nil ;};type Stack struct{Data []interface{};Aux *Stack ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_dgc *Stack )top ()int {return len (_dgc .Data )-1};func (_bdf *Stack )Push (v interface{}){_bdf .Data =append (_bdf .Data ,v )};func (_aa IntsMap )GetSlice (key uint64 )([]int ,bool ){_e ,_eg :=_aa [key ];if !_eg {return nil ,false ;};return _e ,true ;};func (_gc *IntSlice )Add (v int )error {if _gc ==nil {return _a .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");};*_gc =append (*_gc ,v );return nil ;};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_dg IntSlice )Size ()int {return len (_dg )};type IntSlice []int ;func (_ag IntsMap )Get (key uint64 )(int ,bool ){_d ,_bc :=_ag [key ];if !_bc {return 0,false ;};if len (_d )==0{return 0,false ;};return _d [0],true ;};func (_b IntsMap )Add (key uint64 ,value int ){_b [key ]=append (_b [key ],value )};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_f *NumSlice )AddInt (v int ){*_f =append (*_f ,float32 (v ))};func (_fg *Stack )Pop ()(_ba interface{},_agb bool ){_ba ,_agb =_fg .peek ();if !_agb {return nil ,_agb ;};_fg .Data =_fg .Data [:_fg .top ()];return _ba ,true ;};func (_c NumSlice )GetInt (i int )(int ,error ){const _egf ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_c )-1{return 0,_a .Errorf (_egf ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_cb :=_c [i ];return int (_cb +Sign (_cb )*0.5),nil ;};func (_af *Stack )peek ()(interface{},bool ){_cg :=_af .top ();if _cg ==-1{return nil ,false ;};return _af .Data [_cg ],true ;};func (_ad *IntSlice )Copy ()*IntSlice {_ec :=IntSlice (make ([]int ,len (*_ad )));copy (_ec ,*_ad );return &_ec ;};func NewNumSlice (i int )*NumSlice {_gfe :=NumSlice (make ([]float32 ,i ));return &_gfe };func Max (x ,y int )int {if x > y {return x ;};return y ;};func NewIntSlice (i int )*IntSlice {_gf :=IntSlice (make ([]int ,i ));return &_gf };func (_fc *Stack )Len ()int {return len (_fc .Data )};func (_ecb NumSlice )GetIntSlice ()[]int {_eb :=make ([]int ,len (_ecb ));for _ef ,_ca :=range _ecb {_eb [_ef ]=int (_ca );};return _eb ;};type NumSlice []float32 ;func (_bb IntsMap )Delete (key uint64 ){delete (_bb ,key )};func (_bg *Stack )Peek ()(_bf interface{},_agd bool ){return _bg .peek ()};func (_ece *NumSlice )Add (v float32 ){*_ece =append (*_ece ,v )};
package basic ;import _a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};type IntsMap map[uint64 ][]int ;
func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_bb NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_bb )-1{return 0,_a .Errorf ("\u004e\u0075\u006dS\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );
};return _bb [i ],nil ;};func (_ba *IntSlice )Add (v int )error {if _ba ==nil {return _a .Error ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0041\u0064\u0064","\u0073\u006c\u0069\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064");
};*_ba =append (*_ba ,v );return nil ;};func (_bf IntsMap )GetSlice (key uint64 )([]int ,bool ){_bc ,_gc :=_bf [key ];if !_gc {return nil ,false ;};return _bc ,true ;};func (_cca *Stack )Pop ()(_baa interface{},_bae bool ){_baa ,_bae =_cca .peek ();if !_bae {return nil ,_bae ;
};_cca .Data =_cca .Data [:_cca .top ()];return _baa ,true ;};func (_bac *IntSlice )Copy ()*IntSlice {_cc :=IntSlice (make ([]int ,len (*_bac )));copy (_cc ,*_bac );return &_cc ;};func (_b IntsMap )Get (key uint64 )(int ,bool ){_ge ,_ac :=_b [key ];if !_ac {return 0,false ;
};if len (_ge )==0{return 0,false ;};return _ge [0],true ;};func (_f *Stack )Len ()int {return len (_f .Data )};func (_c IntsMap )Add (key uint64 ,value int ){_c [key ]=append (_c [key ],value )};func NewIntSlice (i int )*IntSlice {_bg :=IntSlice (make ([]int ,i ));
return &_bg };func (_cb *NumSlice )AddInt (v int ){*_cb =append (*_cb ,float32 (v ))};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_ab *Stack )peek ()(interface{},bool ){_gbe :=_ab .top ();if _gbe ==-1{return nil ,false ;};
return _ab .Data [_gbe ],true ;};func (_aec NumSlice )GetIntSlice ()[]int {_acd :=make ([]int ,len (_aec ));for _dc ,_cbc :=range _aec {_acd [_dc ]=int (_cbc );};return _acd ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};type Stack struct{Data []interface{};
Aux *Stack ;};func (_bba *Stack )Peek ()(_bce interface{},_gd bool ){return _bba .peek ()};func (_gb IntsMap )Delete (key uint64 ){delete (_gb ,key )};func (_dg NumSlice )GetInt (i int )(int ,error ){const _acb ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_dg )-1{return 0,_a .Errorf (_acb ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );
};_dd :=_dg [i ];return int (_dd +Sign (_dd )*0.5),nil ;};func (_cce *NumSlice )Add (v float32 ){*_cce =append (*_cce ,v )};type NumSlice []float32 ;func NewNumSlice (i int )*NumSlice {_ccg :=NumSlice (make ([]float32 ,i ));return &_ccg };func Min (x ,y int )int {if x < y {return x ;
};return y ;};func (_bca *Stack )top ()int {return len (_bca .Data )-1};type IntSlice []int ;func (_ae IntSlice )Size ()int {return len (_ae )};func (_d IntSlice )Get (index int )(int ,error ){if index > len (_d )-1{return 0,_a .Errorf ("\u0049\u006e\u0074S\u006c\u0069\u0063\u0065\u002e\u0047\u0065\u0074","\u0069\u006e\u0064\u0065x:\u0020\u0025\u0064\u0020\u006f\u0075\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006eg\u0065",index );
};return _d [index ],nil ;};func (_ad *Stack )Push (v interface{}){_ad .Data =append (_ad .Data ,v )};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,14 @@
// 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 (_ba "github.com/unidoc/unipdf/v3/internal/bitwise";_c "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_bg "github.com/unidoc/unipdf/v3/internal/jbig2/document";_a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_e "image";);func (_d *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _d .decodePage (pageNumber )};type Decoder struct{_ef _ba .StreamReader ;_ea *_bg .Document ;_ed int ;_g Parameters ;};func (_bge *Decoder )DecodeNextPage ()([]byte ,error ){_bge ._ed ++;_eb :=_bge ._ed ;return _bge .decodePage (_eb );};func (_ac *Decoder )PageNumber ()(int ,error ){const _bc ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _ac ._ea ==nil {return 0,_a .Error (_bc ,"d\u0065\u0063\u006f\u0064\u0065\u0072 \u006e\u006f\u0074\u0020\u0069\u006e\u0069\u0074\u0069a\u006c\u0069\u007ae\u0064 \u0079\u0065\u0074");};return int (_ac ._ea .NumberOfPages ),nil ;};func Decode (input []byte ,parameters Parameters ,globals *_bg .Globals )(*Decoder ,error ){_ad :=_ba .NewReader (input );_bf ,_edc :=_bg .DecodeDocument (_ad ,globals );if _edc !=nil {return nil ,_edc ;};return &Decoder {_ef :_ad ,_ea :_bf ,_g :parameters },nil ;};type Parameters struct{UnpaddedData bool ;Color _c .Color ;};func (_dg *Decoder )DecodePageImage (pageNumber int )(_e .Image ,error ){const _df ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_bag ,_f :=_dg .decodePageImage (pageNumber );if _f !=nil {return nil ,_a .Wrap (_f ,_df ,"");};return _bag ,nil ;};func (_dc *Decoder )decodePage (_fg int )([]byte ,error ){const _dcd ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _fg < 0{return nil ,_a .Errorf (_dcd ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_fg );};if _fg > int (_dc ._ea .NumberOfPages ){return nil ,_a .Errorf (_dcd ,"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",_fg );};_be ,_fb :=_dc ._ea .GetPage (_fg );if _fb !=nil {return nil ,_a .Wrap (_fb ,_dcd ,"");};_bed ,_fb :=_be .GetBitmap ();if _fb !=nil {return nil ,_a .Wrap (_fb ,_dcd ,"");};_bed .InverseData ();if !_dc ._g .UnpaddedData {return _bed .Data ,nil ;};return _bed .GetUnpaddedData ();};func (_ag *Decoder )decodePageImage (_ee int )(_e .Image ,error ){const _fe ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _ee < 0{return nil ,_a .Errorf (_fe ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_ee );};if _ee > int (_ag ._ea .NumberOfPages ){return nil ,_a .Errorf (_fe ,"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",_ee );};_beb ,_ce :=_ag ._ea .GetPage (_ee );if _ce !=nil {return nil ,_a .Wrap (_ce ,_fe ,"");};_dfc ,_ce :=_beb .GetBitmap ();if _ce !=nil {return nil ,_a .Wrap (_ce ,_fe ,"");};_dfc .InverseData ();return _dfc .ToImage (),nil ;};
package decoder ;import (_e "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_d "github.com/unidoc/unipdf/v3/internal/jbig2/document";_gb "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_b "image";
);func (_db *Decoder )decodePage (_eg int )([]byte ,error ){const _fd ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _eg < 0{return nil ,_gb .Errorf (_fd ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_eg );
};if _eg > int (_db ._ag .NumberOfPages ){return nil ,_gb .Errorf (_fd ,"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",_eg );
};_ce ,_ab :=_db ._ag .GetPage (_eg );if _ab !=nil {return nil ,_gb .Wrap (_ab ,_fd ,"");};_ee ,_ab :=_ce .GetBitmap ();if _ab !=nil {return nil ,_gb .Wrap (_ab ,_fd ,"");};_ee .InverseData ();if !_db ._gbf .UnpaddedData {return _ee .Data ,nil ;};return _ee .GetUnpaddedData ();
};func (_bg *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _bg .decodePage (pageNumber )};func (_f *Decoder )DecodePageImage (pageNumber int )(_b .Image ,error ){const _ga ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";
_c ,_gg :=_f .decodePageImage (pageNumber );if _gg !=nil {return nil ,_gb .Wrap (_gg ,_ga ,"");};return _c ,nil ;};func Decode (input []byte ,parameters Parameters ,globals *_d .Globals )(*Decoder ,error ){_acg :=_e .NewReader (input );_abe ,_bc :=_d .DecodeDocument (_acg ,globals );
if _bc !=nil {return nil ,_bc ;};return &Decoder {_ba :_acg ,_ag :_abe ,_gbf :parameters },nil ;};func (_cb *Decoder )DecodeNextPage ()([]byte ,error ){_cb ._ac ++;_acd :=_cb ._ac ;return _cb .decodePage (_acd );};func (_bb *Decoder )decodePageImage (_bgb int )(_b .Image ,error ){const _cea ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";
if _bgb < 0{return nil ,_gb .Errorf (_cea ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_bgb );};if _bgb > int (_bb ._ag .NumberOfPages ){return nil ,_gb .Errorf (_cea ,"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",_bgb );
};_da ,_ggd :=_bb ._ag .GetPage (_bgb );if _ggd !=nil {return nil ,_gb .Wrap (_ggd ,_cea ,"");};_ea ,_ggd :=_da .GetBitmap ();if _ggd !=nil {return nil ,_gb .Wrap (_ggd ,_cea ,"");};_ea .InverseData ();return _ea .ToImage (),nil ;};type Parameters struct{UnpaddedData bool ;
Color _a .Color ;};type Decoder struct{_ba _e .StreamReader ;_ag *_d .Document ;_ac int ;_gbf Parameters ;};func (_de *Decoder )PageNumber ()(int ,error ){const _cg ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";
if _de ._ag ==nil {return 0,_gb .Error (_cg ,"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 (_de ._ag .NumberOfPages ),nil ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,8 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package errors ;import (_c "fmt";_a "golang.org/x/xerrors";);func Errorf (processName ,message string ,arguments ...interface{})error {return _gae (_c .Sprintf (message ,arguments ...),processName );};func (_b *processError )Unwrap ()error {return _b ._cc };type processError struct{_g string ;_f string ;_ed string ;_cc error ;};func Wrap (err error ,processName ,message string )error {if _ce ,_fa :=err .(*processError );_fa {_ce ._g ="";};_ba :=_gae (message ,processName );_ba ._cc =err ;return _ba ;};func (_ef *processError )Error ()string {var _ga string ;if _ef ._g !=""{_ga =_ef ._g ;};_ga +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_ef ._f ;if _ef ._ed !=""{_ga +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_ef ._ed ;};if _ef ._cc !=nil {_ga +="\u002e\u0020"+_ef ._cc .Error ();};return _ga ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _ec ,_ag :=err .(*processError );_ag {_ec ._g ="";};_dg :=_gae (_c .Sprintf (message ,arguments ...),processName );_dg ._cc =err ;return _dg ;};var _ _a .Wrapper =(*processError )(nil );func Error (processName ,message string )error {return _gae (message ,processName )};func _gae (_bb ,_gd string )*processError {return &processError {_g :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_ed :_bb ,_f :_gd };};
package errors ;import (_a "fmt";_fg "golang.org/x/xerrors";);func Wrap (err error ,processName ,message string )error {if _bgf ,_cb :=err .(*processError );_cb {_bgf ._ae ="";};_d :=_gf (message ,processName );_d ._c =err ;return _d ;};func Errorf (processName ,message string ,arguments ...interface{})error {return _gf (_a .Sprintf (message ,arguments ...),processName );
};func (_fgg *processError )Unwrap ()error {return _fgg ._c };func (_g *processError )Error ()string {var _ac string ;if _g ._ae !=""{_ac =_g ._ae ;};_ac +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_g ._b ;if _g ._e !=""{_ac +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_g ._e ;
};if _g ._c !=nil {_ac +="\u002e\u0020"+_g ._c .Error ();};return _ac ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _df ,_db :=err .(*processError );_db {_df ._ae ="";};_dc :=_gf (_a .Sprintf (message ,arguments ...),processName );
_dc ._c =err ;return _dc ;};type processError struct{_ae string ;_b string ;_e string ;_c error ;};func Error (processName ,message string )error {return _gf (message ,processName )};func _gf (_bg ,_gg string )*processError {return &processError {_ae :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_e :_bg ,_b :_gg };
};var _ _fg .Wrapper =(*processError )(nil );

View File

@ -9,4 +9,4 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package internal ;import _b "errors";var ErrOOB =_b .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064");
package internal ;import _d "errors";var ErrOOB =_d .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064");

View File

@ -9,4 +9,9 @@
// 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 (_ce "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_b "github.com/unidoc/unipdf/v3/internal/jbig2/document";_db "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_e "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "sort";);type Globals map[int ]*_db .Header ;func DecodeBytes (encoded []byte ,parameters _a .Parameters ,globals ...Globals )([]byte ,error ){var _g Globals ;if len (globals )> 0{_g =globals [0];};_f ,_dg :=_a .Decode (encoded ,parameters ,_g .ToDocumentGlobals ());if _dg !=nil {return nil ,_dg ;};return _f .DecodeNextPage ();};func (_fa Globals )ToDocumentGlobals ()*_b .Globals {if _fa ==nil {return nil ;};_bb :=[]*_db .Header {};for _ ,_cb :=range _fa {_bb =append (_bb ,_cb );};_d .Slice (_bb ,func (_ad ,_de int )bool {return _bb [_ad ].SegmentNumber < _bb [_de ].SegmentNumber });return &_b .Globals {Segments :_bb };};func DecodeGlobals (encoded []byte )(Globals ,error ){const _ab ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_cd :=_ce .NewReader (encoded );_cg ,_ef :=_b .DecodeDocument (_cd ,nil );if _ef !=nil {return nil ,_e .Wrap (_ef ,_ab ,"");};if _cg .GlobalSegments ==nil ||(_cg .GlobalSegments .Segments ==nil ){return nil ,_e .Error (_ab ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_ff :=Globals {};for _ ,_dc :=range _cg .GlobalSegments .Segments {_ff [int (_dc .SegmentNumber )]=_dc ;};return _ff ,nil ;};
package jbig2 ;import (_d "github.com/unidoc/unipdf/v3/internal/bitwise";_dg "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_c "github.com/unidoc/unipdf/v3/internal/jbig2/document";_ac "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";
_eb "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _f ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_ae :=_d .NewReader (encoded );_cec ,_ec :=_c .DecodeDocument (_ae ,nil );
if _ec !=nil {return nil ,_eb .Wrap (_ec ,_f ,"");};if _cec .GlobalSegments ==nil ||(_cec .GlobalSegments .Segments ==nil ){return nil ,_eb .Error (_f ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");
};_aa :=Globals {};for _ ,_cc :=range _cec .GlobalSegments .Segments {_aa [int (_cc .SegmentNumber )]=_cc ;};return _aa ,nil ;};func (_b Globals )ToDocumentGlobals ()*_c .Globals {if _b ==nil {return nil ;};_aef :=[]*_ac .Header {};for _ ,_dfc :=range _b {_aef =append (_aef ,_dfc );
};_a .Slice (_aef ,func (_ecf ,_cf int )bool {return _aef [_ecf ].SegmentNumber < _aef [_cf ].SegmentNumber });return &_c .Globals {Segments :_aef };};type Globals map[int ]*_ac .Header ;func DecodeBytes (encoded []byte ,parameters _dg .Parameters ,globals ...Globals )([]byte ,error ){var _df Globals ;
if len (globals )> 0{_df =globals [0];};_ce ,_dff :=_dg .Decode (encoded ,parameters ,_df .ToDocumentGlobals ());if _dff !=nil {return nil ,_dff ;};return _ce .DecodeNextPage ();};

File diff suppressed because one or more lines are too long

View File

@ -9,4 +9,19 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package sampling ;import (_a "github.com/unidoc/unipdf/v3/internal/bitwise";_ga "github.com/unidoc/unipdf/v3/internal/imageutil";_g "io";);type SampleWriter interface{WriteSample (_gg uint32 )error ;WriteSamples (_af []uint32 )error ;};func NewWriter (img _ga .ImageBase )*Writer {return &Writer {_ad :_a .NewWriterMSB (img .Data ),_gd :img ,_gdb :img .ColorComponents ,_gae :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_gda *Writer )WriteSamples (samples []uint32 )error {for _bbd :=0;_bbd < len (samples );_bbd ++{if _fbg :=_gda .WriteSample (samples [_bbd ]);_fbg !=nil {return _fbg ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _deb []uint32 ;_fd :=bitsPerSample ;var _fe uint32 ;var _fea byte ;_gcg :=0;_ead :=0;_dd :=0;for _dd < len (data ){if _gcg > 0{_faf :=_gcg ;if _fd < _faf {_faf =_fd ;};_fe =(_fe <<uint (_faf ))|uint32 (_fea >>uint (8-_faf ));_gcg -=_faf ;if _gcg > 0{_fea =_fea <<uint (_faf );}else {_fea =0;};_fd -=_faf ;if _fd ==0{_deb =append (_deb ,_fe );_fd =bitsPerSample ;_fe =0;_ead ++;};}else {_bf :=data [_dd ];_dd ++;_baa :=8;if _fd < _baa {_baa =_fd ;};_gcg =8-_baa ;_fe =(_fe <<uint (_baa ))|uint32 (_bf >>uint (_gcg ));if _baa < 8{_fea =_bf <<uint (_baa );};_fd -=_baa ;if _fd ==0{_deb =append (_deb ,_fe );_fd =bitsPerSample ;_fe =0;_ead ++;};};};for _gcg >=bitsPerSample {_ec :=_gcg ;if _fd < _ec {_ec =_fd ;};_fe =(_fe <<uint (_ec ))|uint32 (_fea >>uint (8-_ec ));_gcg -=_ec ;if _gcg > 0{_fea =_fea <<uint (_ec );}else {_fea =0;};_fd -=_ec ;if _fd ==0{_deb =append (_deb ,_fe );_fd =bitsPerSample ;_fe =0;_ead ++;};};return _deb ;};type Writer struct{_gd _ga .ImageBase ;_ad *_a .Writer ;_cg ,_gdb int ;_gae bool ;};func (_beg *Writer )WriteSample (sample uint32 )error {if _ ,_gf :=_beg ._ad .WriteBits (uint64 (sample ),_beg ._gd .BitsPerComponent );_gf !=nil {return _gf ;};_beg ._gdb --;if _beg ._gdb ==0{_beg ._gdb =_beg ._gd .ColorComponents ;_beg ._cg ++;};if _beg ._cg ==_beg ._gd .Width {if _beg ._gae {_beg ._ad .FinishByte ();};_beg ._cg =0;};return nil ;};func (_b *Reader )ReadSamples (samples []uint32 )(_de error ){for _ba :=0;_ba < len (samples );_ba ++{samples [_ba ],_de =_b .ReadSample ();if _de !=nil {return _de ;};};return nil ;};func NewReader (img _ga .ImageBase )*Reader {return &Reader {_d :_a .NewReader (img .Data ),_fa :img ,_fac :img .ColorComponents ,_df :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_db *Reader )ReadSample ()(uint32 ,error ){if _db ._ea ==_db ._fa .Height {return 0,_g .EOF ;};_ac ,_gc :=_db ._d .ReadBits (byte (_db ._fa .BitsPerComponent ));if _gc !=nil {return 0,_gc ;};_db ._fac --;if _db ._fac ==0{_db ._fac =_db ._fa .ColorComponents ;_db ._e ++;};if _db ._e ==_db ._fa .Width {if _db ._df {_db ._d .ConsumeRemainingBits ();};_db ._e =0;_db ._ea ++;};return uint32 (_ac ),nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_gag []uint32 )error ;};type Reader struct{_fa _ga .ImageBase ;_d *_a .Reader ;_e ,_ea ,_fac int ;_df bool ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _def []uint32 ;_fb :=bitsPerOutputSample ;var _be uint32 ;var _ge uint32 ;_dfc :=0;_c :=0;_ecc :=0;for _ecc < len (data ){if _dfc > 0{_cd :=_dfc ;if _fb < _cd {_cd =_fb ;};_be =(_be <<uint (_cd ))|(_ge >>uint (bitsPerInputSample -_cd ));_dfc -=_cd ;if _dfc > 0{_ge =_ge <<uint (_cd );}else {_ge =0;};_fb -=_cd ;if _fb ==0{_def =append (_def ,_be );_fb =bitsPerOutputSample ;_be =0;_c ++;};}else {_bb :=data [_ecc ];_ecc ++;_da :=bitsPerInputSample ;if _fb < _da {_da =_fb ;};_dfc =bitsPerInputSample -_da ;_be =(_be <<uint (_da ))|(_bb >>uint (_dfc ));if _da < bitsPerInputSample {_ge =_bb <<uint (_da );};_fb -=_da ;if _fb ==0{_def =append (_def ,_be );_fb =bitsPerOutputSample ;_be =0;_c ++;};};};for _dfc >=bitsPerOutputSample {_ed :=_dfc ;if _fb < _ed {_ed =_fb ;};_be =(_be <<uint (_ed ))|(_ge >>uint (bitsPerInputSample -_ed ));_dfc -=_ed ;if _dfc > 0{_ge =_ge <<uint (_ed );}else {_ge =0;};_fb -=_ed ;if _fb ==0{_def =append (_def ,_be );_fb =bitsPerOutputSample ;_be =0;_c ++;};};if _fb > 0&&_fb < bitsPerOutputSample {_be <<=uint (_fb );_def =append (_def ,_be );};return _def ;};
package sampling ;import (_d "github.com/unidoc/unipdf/v3/internal/bitwise";_ca "github.com/unidoc/unipdf/v3/internal/imageutil";_e "io";);func NewWriter (img _ca .ImageBase )*Writer {return &Writer {_eed :_d .NewWriterMSB (img .Data ),_bca :img ,_gg :img .ColorComponents ,_fgc :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _gb []uint32 ;_fa :=bitsPerOutputSample ;var _ag uint32 ;var _dd uint32 ;_fg :=0;_db :=0;_gf :=0;for _gf < len (data ){if _fg > 0{_gdg :=_fg ;if _fa < _gdg {_gdg =_fa ;
};_ag =(_ag <<uint (_gdg ))|(_dd >>uint (bitsPerInputSample -_gdg ));_fg -=_gdg ;if _fg > 0{_dd =_dd <<uint (_gdg );}else {_dd =0;};_fa -=_gdg ;if _fa ==0{_gb =append (_gb ,_ag );_fa =bitsPerOutputSample ;_ag =0;_db ++;};}else {_dbd :=data [_gf ];_gf ++;
_dbc :=bitsPerInputSample ;if _fa < _dbc {_dbc =_fa ;};_fg =bitsPerInputSample -_dbc ;_ag =(_ag <<uint (_dbc ))|(_dbd >>uint (_fg ));if _dbc < bitsPerInputSample {_dd =_dbd <<uint (_dbc );};_fa -=_dbc ;if _fa ==0{_gb =append (_gb ,_ag );_fa =bitsPerOutputSample ;
_ag =0;_db ++;};};};for _fg >=bitsPerOutputSample {_fe :=_fg ;if _fa < _fe {_fe =_fa ;};_ag =(_ag <<uint (_fe ))|(_dd >>uint (bitsPerInputSample -_fe ));_fg -=_fe ;if _fg > 0{_dd =_dd <<uint (_fe );}else {_dd =0;};_fa -=_fe ;if _fa ==0{_gb =append (_gb ,_ag );
_fa =bitsPerOutputSample ;_ag =0;_db ++;};};if _fa > 0&&_fa < bitsPerOutputSample {_ag <<=uint (_fa );_gb =append (_gb ,_ag );};return _gb ;};func NewReader (img _ca .ImageBase )*Reader {return &Reader {_eb :_d .NewReader (img .Data ),_cb :img ,_g :img .ColorComponents ,_b :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };
};func (_bb *Reader )ReadSample ()(uint32 ,error ){if _bb ._a ==_bb ._cb .Height {return 0,_e .EOF ;};_cc ,_dc :=_bb ._eb .ReadBits (byte (_bb ._cb .BitsPerComponent ));if _dc !=nil {return 0,_dc ;};_bb ._g --;if _bb ._g ==0{_bb ._g =_bb ._cb .ColorComponents ;
_bb ._da ++;};if _bb ._da ==_bb ._cb .Width {if _bb ._b {_bb ._eb .ConsumeRemainingBits ();};_bb ._da =0;_bb ._a ++;};return uint32 (_cc ),nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_f []uint32 )error ;};type SampleWriter interface{WriteSample (_dcb uint32 )error ;
WriteSamples (_bc []uint32 )error ;};type Writer struct{_bca _ca .ImageBase ;_eed *_d .Writer ;_eg ,_gg int ;_fgc bool ;};func (_gbf *Writer )WriteSamples (samples []uint32 )error {for _bd :=0;_bd < len (samples );_bd ++{if _ec :=_gbf .WriteSample (samples [_bd ]);
_ec !=nil {return _ec ;};};return nil ;};type Reader struct{_cb _ca .ImageBase ;_eb *_d .Reader ;_da ,_a ,_g int ;_b bool ;};func (_cf *Writer )WriteSample (sample uint32 )error {if _ ,_afd :=_cf ._eed .WriteBits (uint64 (sample ),_cf ._bca .BitsPerComponent );
_afd !=nil {return _afd ;};_cf ._gg --;if _cf ._gg ==0{_cf ._gg =_cf ._bca .ColorComponents ;_cf ._eg ++;};if _cf ._eg ==_cf ._bca .Width {if _cf ._fgc {_cf ._eed .FinishByte ();};_cf ._eg =0;};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _dag []uint32 ;
_gd :=bitsPerSample ;var _dab uint32 ;var _ab byte ;_ff :=0;_eeg :=0;_cgf :=0;for _cgf < len (data ){if _ff > 0{_ebf :=_ff ;if _gd < _ebf {_ebf =_gd ;};_dab =(_dab <<uint (_ebf ))|uint32 (_ab >>uint (8-_ebf ));_ff -=_ebf ;if _ff > 0{_ab =_ab <<uint (_ebf );
}else {_ab =0;};_gd -=_ebf ;if _gd ==0{_dag =append (_dag ,_dab );_gd =bitsPerSample ;_dab =0;_eeg ++;};}else {_fc :=data [_cgf ];_cgf ++;_fd :=8;if _gd < _fd {_fd =_gd ;};_ff =8-_fd ;_dab =(_dab <<uint (_fd ))|uint32 (_fc >>uint (_ff ));if _fd < 8{_ab =_fc <<uint (_fd );
};_gd -=_fd ;if _gd ==0{_dag =append (_dag ,_dab );_gd =bitsPerSample ;_dab =0;_eeg ++;};};};for _ff >=bitsPerSample {_af :=_ff ;if _gd < _af {_af =_gd ;};_dab =(_dab <<uint (_af ))|uint32 (_ab >>uint (8-_af ));_ff -=_af ;if _ff > 0{_ab =_ab <<uint (_af );
}else {_ab =0;};_gd -=_af ;if _gd ==0{_dag =append (_dag ,_dab );_gd =bitsPerSample ;_dab =0;_eeg ++;};};return _dag ;};func (_cg *Reader )ReadSamples (samples []uint32 )(_ee error ){for _ccf :=0;_ccf < len (samples );_ccf ++{samples [_ccf ],_ee =_cg .ReadSample ();
if _ee !=nil {return _ee ;};};return nil ;};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -10,82 +10,58 @@
// 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";_dg "crypto";_af "crypto/rand";_df "crypto/rsa";_cc "crypto/x509";_f "crypto/x509/pkix";_b "encoding/asn1";_eg "errors";_c "fmt";_ccd "github.com/unidoc/pkcs7";_da "github.com/unidoc/timestamp";_be "github.com/unidoc/unipdf/v3/core";_fe "github.com/unidoc/unipdf/v3/model";_daa "github.com/unidoc/unipdf/v3/model/sigutil";_a "hash";_e "time";);
package sighandler ;import (_bc "bytes";_d "crypto";_ec "crypto/rand";_da "crypto/rsa";_cb "crypto/x509";_bd "crypto/x509/pkix";_c "encoding/asn1";_ed "errors";_a "fmt";_cf "github.com/unidoc/pkcs7";_aa "github.com/unidoc/timestamp";_ca "github.com/unidoc/unipdf/v3/core";
_cg "github.com/unidoc/unipdf/v3/model";_g "github.com/unidoc/unipdf/v3/model/sigutil";_e "hash";_f "time";);
// NewEmptyAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached
// signature handler. The generated signature is empty and of size signatureLen.
// The signatureLen parameter can be 0 for the signature validation.
func NewEmptyAdobePKCS7Detached (signatureLen int )(_fe .SignatureHandler ,error ){return &adobePKCS7Detached {_fea :true ,_db :signatureLen },nil ;};
// NewDigest creates a new digest.
func (_dge *docTimeStamp )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){return _bc .NewBuffer (nil ),nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_ace *adobeX509RSASHA1 )IsApplicable (sig *_fe .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";};
// Sign sets the Contents fields for the PdfSignature.
func (_dfc *adobeX509RSASHA1 )Sign (sig *_fe .PdfSignature ,digest _fe .Hasher )error {var _efc []byte ;var _ceg error ;if _dfc ._ag !=nil {_efc ,_ceg =_dfc ._ag (sig ,digest );if _ceg !=nil {return _ceg ;};}else {_cce ,_fbg :=digest .(_a .Hash );if !_fbg {return _eg .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_aab ,_ :=_bgf (_dfc ._aba .SignatureAlgorithm );_efc ,_ceg =_df .SignPKCS1v15 (_af .Reader ,_dfc ._aa ,_aab ,_cce .Sum (nil ));if _ceg !=nil {return _ceg ;};};_efc ,_ceg =_b .Marshal (_efc );if _ceg !=nil {return _ceg ;};sig .Contents =_be .MakeHexString (string (_efc ));return nil ;};
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler with a custom signing function. Both the
// certificate and the sign function can be nil for the signature validation.
// NOTE: the handler will do a mock Sign when initializing the signature in
// order to estimate the signature size. Use NewAdobeX509RSASHA1CustomWithOpts
// for configuring the handler to estimate the signature size.
func NewAdobeX509RSASHA1Custom (certificate *_cc .Certificate ,signFunc SignFunc )(_fe .SignatureHandler ,error ){return &adobeX509RSASHA1 {_aba :certificate ,_ag :signFunc },nil ;};
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler. Both the private key and the
// certificate can be nil for the signature validation.
func NewAdobeX509RSASHA1 (privateKey *_da .PrivateKey ,certificate *_cb .Certificate )(_cg .SignatureHandler ,error ){return &adobeX509RSASHA1 {_cbb :certificate ,_efc :privateKey },nil ;};func (_ffa *adobePKCS7Detached )getCertificate (_bca *_cg .PdfSignature )(*_cb .Certificate ,error ){if _ffa ._df !=nil {return _ffa ._df ,nil ;
};_dfc ,_fa :=_bca .GetCerts ();if _fa !=nil {return nil ,_fa ;};return _dfc [0],nil ;};func _db (_bcg _cb .SignatureAlgorithm )(_d .Hash ,bool ){var _dbd _d .Hash ;switch _bcg {case _cb .SHA1WithRSA :_dbd =_d .SHA1 ;case _cb .SHA256WithRSA :_dbd =_d .SHA256 ;
case _cb .SHA384WithRSA :_dbd =_d .SHA384 ;case _cb .SHA512WithRSA :_dbd =_d .SHA512 ;default:return _d .SHA1 ,false ;};return _dbd ,true ;};type timestampInfo struct{Version int ;Policy _c .RawValue ;MessageImprint struct{HashAlgorithm _bd .AlgorithmIdentifier ;
HashedMessage []byte ;};SerialNumber _c .RawValue ;GeneralizedTime _f .Time ;};
// InitSignature initialises the PdfSignature.
func (_afb *adobeX509RSASHA1 )InitSignature (sig *_fe .PdfSignature )error {if _afb ._aba ==nil {return _eg .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 _afb ._aa ==nil &&_afb ._ag ==nil {return _eg .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");};_dd :=*_afb ;sig .Handler =&_dd ;sig .Filter =_be .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_be .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_be .MakeString (string (_dd ._aba .Raw ));sig .Reference =nil ;_dc ,_bd :=_dd .NewDigest (sig );if _bd !=nil {return _bd ;};_dc .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 _dd .sign (sig ,_dc ,_afb ._feb );};type adobePKCS7Detached struct{_bg *_df .PrivateKey ;_ec *_cc .Certificate ;_fea bool ;_db int ;};
func (_gc *adobePKCS7Detached )InitSignature (sig *_cg .PdfSignature )error {if !_gc ._ce {if _gc ._df ==nil {return _ed .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 _gc ._ag ==nil {return _ed .New ("\u0070\u0072\u0069\u0076\u0061\u0074\u0065\u004b\u0065\u0079\u0020m\u0075\u0073\u0074\u0020\u006e\u006f\u0074\u0020\u0062\u0065 \u006e\u0069\u006c");};};_de :=*_gc ;sig .Handler =&_de ;sig .Filter =_ca .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");
sig .SubFilter =_ca .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_ff ,_gg :=_de .NewDigest (sig );if _gg !=nil {return _gg ;};_ff .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));
return _de .Sign (sig ,_ff );};
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
// specified options. If no options are provided, default options will be used.
// Sign sets the Contents fields.
func (_ef *adobePKCS7Detached )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {if _ef ._ce {_fe :=_ef ._fc ;if _fe <=0{_fe =8192;};sig .Contents =_ca .MakeHexString (string (make ([]byte ,_fe )));return nil ;};_be :=digest .(*_bc .Buffer );_ac ,_gd :=_cf .NewSignedData (_be .Bytes ());
if _gd !=nil {return _gd ;};if _cag :=_ac .AddSigner (_ef ._df ,_ef ._ag ,_cf .SignerInfoConfig {});_cag !=nil {return _cag ;};_ac .Detach ();_fad ,_gd :=_ac .Finish ();if _gd !=nil {return _gd ;};_dfe :=make ([]byte ,8192);copy (_dfe ,_fad );sig .Contents =_ca .MakeHexString (string (_dfe ));
return nil ;};type adobePKCS7Detached struct{_ag *_da .PrivateKey ;_df *_cb .Certificate ;_ce bool ;_fc int ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_ebf *docTimeStamp )IsApplicable (sig *_cg .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031";
};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// Both the timestamp server URL and the hash algorithm can be empty for the
// signature validation.
// The following hash algorithms are supported:
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _dg .Hash ,opts *DocTimeStampOpts )(_fe .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_dbd :timestampServerURL ,_abe :hashAlgorithm ,_ddf :opts .SignatureSize },nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_fc *docTimeStamp )IsApplicable (sig *_fe .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 _abc (_adf _b .ObjectIdentifier )(_dg .Hash ,error ){switch {case _adf .Equal (_ccd .OIDDigestAlgorithmSHA1 ),_adf .Equal (_ccd .OIDDigestAlgorithmECDSASHA1 ),_adf .Equal (_ccd .OIDDigestAlgorithmDSA ),_adf .Equal (_ccd .OIDDigestAlgorithmDSASHA1 ),_adf .Equal (_ccd .OIDEncryptionAlgorithmRSA ):return _dg .SHA1 ,nil ;case _adf .Equal (_ccd .OIDDigestAlgorithmSHA256 ),_adf .Equal (_ccd .OIDDigestAlgorithmECDSASHA256 ):return _dg .SHA256 ,nil ;case _adf .Equal (_ccd .OIDDigestAlgorithmSHA384 ),_adf .Equal (_ccd .OIDDigestAlgorithmECDSASHA384 ):return _dg .SHA384 ,nil ;case _adf .Equal (_ccd .OIDDigestAlgorithmSHA512 ),_adf .Equal (_ccd .OIDDigestAlgorithmECDSASHA512 ):return _dg .SHA512 ,nil ;};return _dg .Hash (0),_ccd .ErrUnsupportedAlgorithm ;};
// InitSignature initialises the PdfSignature.
func (_gc *adobePKCS7Detached )InitSignature (sig *_fe .PdfSignature )error {if !_gc ._fea {if _gc ._ec ==nil {return _eg .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 _gc ._bg ==nil {return _eg .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");};};_bf :=*_gc ;sig .Handler =&_bf ;sig .Filter =_be .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_be .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_ef ,_cb :=_bf .NewDigest (sig );if _cb !=nil {return _cb ;};_ef .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 _bf .Sign (sig ,_ef );};
// 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 *_df .PrivateKey ,certificate *_cc .Certificate )(_fe .SignatureHandler ,error ){return &adobePKCS7Detached {_ec :certificate ,_bg :privateKey },nil ;};
// 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 _d .Hash )(_cg .SignatureHandler ,error ){return &docTimeStamp {_beb :timestampServerURL ,_dce :hashAlgorithm },nil ;};
// NewAdobeX509RSASHA1CustomWithOpts creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler with a custom signing function. The
// handler is configured based on the provided options. If no options are
// provided, default options will be used. Both the certificate and the sign
// function can be nil for the signature validation.
func NewAdobeX509RSASHA1CustomWithOpts (certificate *_cc .Certificate ,signFunc SignFunc ,opts *AdobeX509RSASHA1Opts )(_fe .SignatureHandler ,error ){if opts ==nil {opts =&AdobeX509RSASHA1Opts {};};return &adobeX509RSASHA1 {_aba :certificate ,_ag :signFunc ,_feb :opts .EstimateSize },nil ;};func (_cfd *adobeX509RSASHA1 )sign (_ebb *_fe .PdfSignature ,_agc _fe .Hasher ,_ac bool )error {if !_ac {return _cfd .Sign (_ebb ,_agc );};_gg ,_ee :=_cfd ._aba .PublicKey .(*_df .PublicKey );if !_ee {return _c .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u006b\u0065y\u0020\u0074\u0079p\u0065:\u0020\u0025\u0054",_gg );};_cge ,_aea :=_b .Marshal (make ([]byte ,_gg .Size ()));if _aea !=nil {return _aea ;};_ebb .Contents =_be .MakeHexString (string (_cge ));return nil ;};
// NewDigest creates a new digest.
func (_fd *docTimeStamp )NewDigest (sig *_fe .PdfSignature )(_fe .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_ff *_fe .PdfSignature ,_fb _fe .Hasher )([]byte ,error );
// InitSignature initialises the PdfSignature.
func (_dgc *docTimeStamp )InitSignature (sig *_fe .PdfSignature )error {_aabb :=*_dgc ;sig .Handler =&_aabb ;sig .Filter =_be .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_be .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _dgc ._ddf > 0{sig .Contents =_be .MakeHexString (string (make ([]byte ,_dgc ._ddf )));}else {_eeb ,_cdc :=_dgc .NewDigest (sig );if _cdc !=nil {return _cdc ;};_eeb .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 _cdc =_aabb .Sign (sig ,_eeb );_cdc !=nil {return _cdc ;};_dgc ._ddf =_aabb ._ddf ;};return nil ;};
// NewDigest creates a new digest.
func (_eb *adobeX509RSASHA1 )NewDigest (sig *_fe .PdfSignature )(_fe .Hasher ,error ){_gee ,_ade :=_eb .getCertificate (sig );if _ade !=nil {return nil ,_ade ;};_aacf ,_ :=_bgf (_gee .SignatureAlgorithm );return _aacf .New (),nil ;};
func NewAdobeX509RSASHA1CustomWithOpts (certificate *_cb .Certificate ,signFunc SignFunc ,opts *AdobeX509RSASHA1Opts )(_cg .SignatureHandler ,error ){if opts ==nil {opts =&AdobeX509RSASHA1Opts {};};return &adobeX509RSASHA1 {_cbb :certificate ,_gf :signFunc ,_ge :opts .EstimateSize },nil ;
};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
func (_gdf *adobePKCS7Detached )IsApplicable (sig *_fe .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 (_cca *docTimeStamp )Validate (sig *_fe .PdfSignature ,digest _fe .Hasher )(_fe .SignatureValidationResult ,error ){_febd :=sig .Contents .Bytes ();_ced ,_bff :=_ccd .Parse (_febd );if _bff !=nil {return _fe .SignatureValidationResult {},_bff ;};if _bff =_ced .Verify ();_bff !=nil {return _fe .SignatureValidationResult {},_bff ;};var _abb timestampInfo ;_ ,_bff =_b .Unmarshal (_ced .Content ,&_abb );if _bff !=nil {return _fe .SignatureValidationResult {},_bff ;};_ed ,_bff :=_abc (_abb .MessageImprint .HashAlgorithm .Algorithm );if _bff !=nil {return _fe .SignatureValidationResult {},_bff ;};_cdg :=_ed .New ();_ebe :=digest .(*_g .Buffer );_cdg .Write (_ebe .Bytes ());_ddc :=_cdg .Sum (nil );_feg :=_fe .SignatureValidationResult {IsSigned :true ,IsVerified :_g .Equal (_ddc ,_abb .MessageImprint .HashedMessage ),GeneralizedTime :_abb .GeneralizedTime };return _feg ,nil ;};type adobeX509RSASHA1 struct{_aa *_df .PrivateKey ;_aba *_cc .Certificate ;_ag SignFunc ;_feb bool ;};
// Validate validates PdfSignature.
func (_bc *adobePKCS7Detached )Validate (sig *_fe .PdfSignature ,digest _fe .Hasher )(_fe .SignatureValidationResult ,error ){_fgb :=sig .Contents .Bytes ();_gd ,_efa :=_ccd .Parse (_fgb );if _efa !=nil {return _fe .SignatureValidationResult {},_efa ;};_fef :=digest .(*_g .Buffer );_gd .Content =_fef .Bytes ();if _efa =_gd .Verify ();_efa !=nil {return _fe .SignatureValidationResult {},_efa ;};return _fe .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// Sign sets the Contents fields for the PdfSignature.
func (_agd *docTimeStamp )Sign (sig *_fe .PdfSignature ,digest _fe .Hasher )error {_cad ,_fbb :=_daa .NewTimestampRequest (digest .(*_g .Buffer ),&_da .RequestOptions {Hash :_agd ._abe ,Certificates :true });if _fbb !=nil {return _fbb ;};_cgb :=_daa .NewTimestampClient ();_baf ,_fbb :=_cgb .GetEncodedToken (_agd ._dbd ,_cad );if _fbb !=nil {return _fbb ;};_bbfg :=len (_baf );if _agd ._ddf > 0&&_bbfg > _agd ._ddf {return _fe .ErrSignNotEnoughSpace ;};if _bbfg > 0{_agd ._ddf =_bbfg +128;};sig .Contents =_be .MakeHexString (string (_baf ));return nil ;};func (_cf *adobePKCS7Detached )getCertificate (_ge *_fe .PdfSignature )(*_cc .Certificate ,error ){if _cf ._ec !=nil {return _cf ._ec ,nil ;};_fg ,_cg :=_ge .GetCerts ();if _cg !=nil {return nil ,_cg ;};return _fg [0],nil ;};type docTimeStamp struct{_dbd string ;_abe _dg .Hash ;_ddf int ;};
// Validate validates PdfSignature.
func (_cfb *adobeX509RSASHA1 )Validate (sig *_fe .PdfSignature ,digest _fe .Hasher )(_fe .SignatureValidationResult ,error ){_dde ,_cfa :=_cfb .getCertificate (sig );if _cfa !=nil {return _fe .SignatureValidationResult {},_cfa ;};_gcd :=sig .Contents .Bytes ();var _dacb []byte ;if _ ,_bgd :=_b .Unmarshal (_gcd ,&_dacb );_bgd !=nil {return _fe .SignatureValidationResult {},_bgd ;};_bb ,_ce :=digest .(_a .Hash );if !_ce {return _fe .SignatureValidationResult {},_eg .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_dbe ,_ :=_bgf (_dde .SignatureAlgorithm );if _cfc :=_df .VerifyPKCS1v15 (_dde .PublicKey .(*_df .PublicKey ),_dbe ,_bb .Sum (nil ),_dacb );_cfc !=nil {return _fe .SignatureValidationResult {},_cfc ;};return _fe .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
func (_fg *adobePKCS7Detached )IsApplicable (sig *_cg .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064";
};func (_gce *adobeX509RSASHA1 )getCertificate (_bg *_cg .PdfSignature )(*_cb .Certificate ,error ){if _gce ._cbb !=nil {return _gce ._cbb ,nil ;};_cfe ,_caa :=_bg .GetCerts ();if _caa !=nil {return nil ,_caa ;};return _cfe [0],nil ;};func _acg (_ggd _c .ObjectIdentifier )(_d .Hash ,error ){switch {case _ggd .Equal (_cf .OIDDigestAlgorithmSHA1 ),_ggd .Equal (_cf .OIDDigestAlgorithmECDSASHA1 ),_ggd .Equal (_cf .OIDDigestAlgorithmDSA ),_ggd .Equal (_cf .OIDDigestAlgorithmDSASHA1 ),_ggd .Equal (_cf .OIDEncryptionAlgorithmRSA ):return _d .SHA1 ,nil ;
case _ggd .Equal (_cf .OIDDigestAlgorithmSHA256 ),_ggd .Equal (_cf .OIDDigestAlgorithmECDSASHA256 ):return _d .SHA256 ,nil ;case _ggd .Equal (_cf .OIDDigestAlgorithmSHA384 ),_ggd .Equal (_cf .OIDDigestAlgorithmECDSASHA384 ):return _d .SHA384 ,nil ;case _ggd .Equal (_cf .OIDDigestAlgorithmSHA512 ),_ggd .Equal (_cf .OIDDigestAlgorithmECDSASHA512 ):return _d .SHA512 ,nil ;
};return _d .Hash (0),_cf .ErrUnsupportedAlgorithm ;};
// AdobeX509RSASHA1Opts defines options for configuring the adbe.x509.rsa_sha1
// signature handler.
@ -97,6 +73,69 @@ type AdobeX509RSASHA1Opts struct{
// call is made in order to estimate the size of the signature contents.
EstimateSize bool ;};
// 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 *_da .PrivateKey ,certificate *_cb .Certificate )(_cg .SignatureHandler ,error ){return &adobePKCS7Detached {_df :certificate ,_ag :privateKey },nil ;};
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
// specified options. If no options are provided, default options will be used.
// Both the timestamp server URL and the hash algorithm can be empty for the
// signature validation.
// The following hash algorithms are supported:
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _d .Hash ,opts *DocTimeStampOpts )(_cg .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_beb :timestampServerURL ,_dce :hashAlgorithm ,_abbc :opts .SignatureSize },nil ;
};
// InitSignature initialises the PdfSignature.
func (_cbc *docTimeStamp )InitSignature (sig *_cg .PdfSignature )error {_gde :=*_cbc ;sig .Handler =&_gde ;sig .Filter =_ca .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_ca .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");
sig .Reference =nil ;if _cbc ._abbc > 0{sig .Contents =_ca .MakeHexString (string (make ([]byte ,_cbc ._abbc )));}else {_caac ,_ddb :=_cbc .NewDigest (sig );if _ddb !=nil {return _ddb ;};_caac .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 _ddb =_gde .Sign (sig ,_caac );_ddb !=nil {return _ddb ;};_cbc ._abbc =_gde ._abbc ;};return nil ;};type docTimeStamp struct{_beb string ;_dce _d .Hash ;_abbc int ;};
// Sign sets the Contents fields for the PdfSignature.
func (_gcc *docTimeStamp )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {_edc ,_eg :=_g .NewTimestampRequest (digest .(*_bc .Buffer ),&_aa .RequestOptions {Hash :_gcc ._dce ,Certificates :true });if _eg !=nil {return _eg ;};_gge :=_g .NewTimestampClient ();
_geb ,_eg :=_gge .GetEncodedToken (_gcc ._beb ,_edc );if _eg !=nil {return _eg ;};_cfee :=len (_geb );if _gcc ._abbc > 0&&_cfee > _gcc ._abbc {return _cg .ErrSignNotEnoughSpace ;};if _cfee > 0{_gcc ._abbc =_cfee +128;};sig .Contents =_ca .MakeHexString (string (_geb ));
return nil ;};type adobeX509RSASHA1 struct{_efc *_da .PrivateKey ;_cbb *_cb .Certificate ;_gf SignFunc ;_ge bool ;};
// Validate validates PdfSignature.
func (_aga *docTimeStamp )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_aee :=sig .Contents .Bytes ();_ggc ,_dga :=_cf .Parse (_aee );if _dga !=nil {return _cg .SignatureValidationResult {},_dga ;};if _dga =_ggc .Verify ();
_dga !=nil {return _cg .SignatureValidationResult {},_dga ;};var _gfb timestampInfo ;_ ,_dga =_c .Unmarshal (_ggc .Content ,&_gfb );if _dga !=nil {return _cg .SignatureValidationResult {},_dga ;};_bgdg ,_dga :=_acg (_gfb .MessageImprint .HashAlgorithm .Algorithm );
if _dga !=nil {return _cg .SignatureValidationResult {},_dga ;};_dbg :=_bgdg .New ();_eb :=digest .(*_bc .Buffer );_dbg .Write (_eb .Bytes ());_aea :=_dbg .Sum (nil );_afe :=_cg .SignatureValidationResult {IsSigned :true ,IsVerified :_bc .Equal (_aea ,_gfb .MessageImprint .HashedMessage ),GeneralizedTime :_gfb .GeneralizedTime };
return _afe ,nil ;};
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
func (_beg *adobeX509RSASHA1 )IsApplicable (sig *_cg .PdfSignature )bool {if sig ==nil ||sig .Filter ==nil ||sig .SubFilter ==nil {return false ;};return (*sig .Filter =="A\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004d\u0053"||*sig .Filter =="\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065")&&*sig .SubFilter =="\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031";
};
// Sign sets the Contents fields for the PdfSignature.
func (_bb *adobeX509RSASHA1 )Sign (sig *_cg .PdfSignature ,digest _cg .Hasher )error {var _bf []byte ;var _gbde error ;if _bb ._gf !=nil {_bf ,_gbde =_bb ._gf (sig ,digest );if _gbde !=nil {return _gbde ;};}else {_efd ,_ggb :=digest .(_e .Hash );if !_ggb {return _ed .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");
};_dde ,_ :=_db (_bb ._cbb .SignatureAlgorithm );_bf ,_gbde =_da .SignPKCS1v15 (_ec .Reader ,_bb ._efc ,_dde ,_efd .Sum (nil ));if _gbde !=nil {return _gbde ;};};_bf ,_gbde =_c .Marshal (_bf );if _gbde !=nil {return _gbde ;};sig .Contents =_ca .MakeHexString (string (_bf ));
return nil ;};
// SignFunc represents a custom signing function. The function should return
// the computed signature.
type SignFunc func (_agb *_cg .PdfSignature ,_gbd _cg .Hasher )([]byte ,error );
// NewDigest creates a new digest.
func (_aab *adobePKCS7Detached )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){return _bc .NewBuffer (nil ),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 )(_cg .SignatureHandler ,error ){return &adobePKCS7Detached {_ce :true ,_fc :signatureLen },nil ;};
// InitSignature initialises the PdfSignature.
func (_cbf *adobeX509RSASHA1 )InitSignature (sig *_cg .PdfSignature )error {if _cbf ._cbb ==nil {return _ed .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 _cbf ._efc ==nil &&_cbf ._gf ==nil {return _ed .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");
};_cba :=*_cbf ;sig .Handler =&_cba ;sig .Filter =_ca .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_ca .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");
sig .Cert =_ca .MakeString (string (_cba ._cbb .Raw ));sig .Reference =nil ;_bdf ,_deb :=_cba .NewDigest (sig );if _deb !=nil {return _deb ;};_bdf .Write ([]byte ("\u0063\u0061\u006c\u0063\u0075\u006ca\u0074\u0065\u0020\u0074\u0068\u0065\u0020\u0043\u006f\u006e\u0074\u0065\u006et\u0073\u0020\u0066\u0069\u0065\u006c\u0064 \u0073\u0069\u007a\u0065"));
return _cba .sign (sig ,_bdf ,_cbf ._ge );};
// Validate validates PdfSignature.
func (_dc *adobeX509RSASHA1 )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_dbc ,_bcd :=_dc .getCertificate (sig );if _bcd !=nil {return _cg .SignatureValidationResult {},_bcd ;};_dad :=sig .Contents .Bytes ();
var _cc []byte ;if _ ,_aad :=_c .Unmarshal (_dad ,&_cc );_aad !=nil {return _cg .SignatureValidationResult {},_aad ;};_bgd ,_af :=digest .(_e .Hash );if !_af {return _cg .SignatureValidationResult {},_ed .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");
};_dfb ,_ :=_db (_dbc .SignatureAlgorithm );if _fbg :=_da .VerifyPKCS1v15 (_dbc .PublicKey .(*_da .PublicKey ),_dfb ,_bgd .Sum (nil ),_cc );_fbg !=nil {return _cg .SignatureValidationResult {},_fbg ;};return _cg .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;
};
// DocTimeStampOpts defines options for configuring the timestamp handler.
type DocTimeStampOpts struct{
@ -105,25 +144,22 @@ type DocTimeStampOpts struct{
// The signing process will report the model.ErrSignNotEnoughSpace error
// if the estimated signature size is smaller than the actual size of the
// signature.
SignatureSize int ;};func (_cgd *adobeX509RSASHA1 )getCertificate (_gda *_fe .PdfSignature )(*_cc .Certificate ,error ){if _cgd ._aba !=nil {return _cgd ._aba ,nil ;};_aac ,_ca :=_gda .GetCerts ();if _ca !=nil {return nil ,_ca ;};return _aac [0],nil ;};
SignatureSize int ;};
// NewDigest creates a new digest.
func (_ged *adobePKCS7Detached )NewDigest (sig *_fe .PdfSignature )(_fe .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
func (_bgb *adobeX509RSASHA1 )NewDigest (sig *_cg .PdfSignature )(_cg .Hasher ,error ){_cbaa ,_gef :=_bgb .getCertificate (sig );if _gef !=nil {return nil ,_gef ;};_ffb ,_ :=_db (_cbaa .SignatureAlgorithm );return _ffb .New (),nil ;};
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
// Both the timestamp server URL and the hash algorithm can be empty for the
// signature validation.
// The following hash algorithms are supported:
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
// NOTE: the handler will do a mock Sign when initializing the signature
// in order to estimate the signature size. Use NewDocTimeStampWithOpts
// for providing the signature size.
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _dg .Hash )(_fe .SignatureHandler ,error ){return &docTimeStamp {_dbd :timestampServerURL ,_abe :hashAlgorithm },nil ;};func (_eed *docTimeStamp )getCertificate (_ea *_fe .PdfSignature )(*_cc .Certificate ,error ){_bbf ,_gbb :=_ea .GetCerts ();if _gbb !=nil {return nil ,_gbb ;};return _bbf [0],nil ;};
// Validate validates PdfSignature.
func (_dd *adobePKCS7Detached )Validate (sig *_cg .PdfSignature ,digest _cg .Hasher )(_cg .SignatureValidationResult ,error ){_dg :=sig .Contents .Bytes ();_gb ,_bcf :=_cf .Parse (_dg );if _bcf !=nil {return _cg .SignatureValidationResult {},_bcf ;};_bce :=digest .(*_bc .Buffer );
_gb .Content =_bce .Bytes ();if _bcf =_gb .Verify ();_bcf !=nil {return _cg .SignatureValidationResult {},_bcf ;};return _cg .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
// NewAdobeX509RSASHA1 creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler. Both the private key and the
// certificate can be nil for the signature validation.
func NewAdobeX509RSASHA1 (privateKey *_df .PrivateKey ,certificate *_cc .Certificate )(_fe .SignatureHandler ,error ){return &adobeX509RSASHA1 {_aba :certificate ,_aa :privateKey },nil ;};
// Sign sets the Contents fields.
func (_ad *adobePKCS7Detached )Sign (sig *_fe .PdfSignature ,digest _fe .Hasher )error {if _ad ._fea {_cgc :=_ad ._db ;if _cgc <=0{_cgc =8192;};sig .Contents =_be .MakeHexString (string (make ([]byte ,_cgc )));return nil ;};_fa :=digest .(*_g .Buffer );_ba ,_dac :=_ccd .NewSignedData (_fa .Bytes ());if _dac !=nil {return _dac ;};if _cfg :=_ba .AddSigner (_ad ._ec ,_ad ._bg ,_ccd .SignerInfoConfig {});_cfg !=nil {return _cfg ;};_ba .Detach ();_ab ,_dac :=_ba .Finish ();if _dac !=nil {return _dac ;};_fga :=make ([]byte ,8192);copy (_fga ,_ab );sig .Contents =_be .MakeHexString (string (_fga ));return nil ;};func _bgf (_afbg _cc .SignatureAlgorithm )(_dg .Hash ,bool ){var _gb _dg .Hash ;switch _afbg {case _cc .SHA1WithRSA :_gb =_dg .SHA1 ;case _cc .SHA256WithRSA :_gb =_dg .SHA256 ;case _cc .SHA384WithRSA :_gb =_dg .SHA384 ;case _cc .SHA512WithRSA :_gb =_dg .SHA512 ;default:return _dg .SHA1 ,false ;};return _gb ,true ;};type timestampInfo struct{Version int ;Policy _b .RawValue ;MessageImprint struct{HashAlgorithm _f .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _b .RawValue ;GeneralizedTime _e .Time ;};
// NewAdobeX509RSASHA1Custom creates a new Adobe.PPKMS/Adobe.PPKLite
// adbe.x509.rsa_sha1 signature handler with a custom signing function. Both the
// certificate and the sign function can be nil for the signature validation.
// NOTE: the handler will do a mock Sign when initializing the signature in
// order to estimate the signature size. Use NewAdobeX509RSASHA1CustomWithOpts
// for configuring the handler to estimate the signature size.
func NewAdobeX509RSASHA1Custom (certificate *_cb .Certificate ,signFunc SignFunc )(_cg .SignatureHandler ,error ){return &adobeX509RSASHA1 {_cbb :certificate ,_gf :signFunc },nil ;};func (_dfed *docTimeStamp )getCertificate (_ga *_cg .PdfSignature )(*_cb .Certificate ,error ){_bcff ,_cgc :=_ga .GetCerts ();
if _cgc !=nil {return nil ,_cgc ;};return _bcff [0],nil ;};func (_ede *adobeX509RSASHA1 )sign (_bfd *_cg .PdfSignature ,_ddd _cg .Hasher ,_bfg bool )error {if !_bfg {return _ede .Sign (_bfd ,_ddd );};_dba ,_fgc :=_ede ._cbb .PublicKey .(*_da .PublicKey );
if !_fgc {return _a .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u006b\u0065y\u0020\u0074\u0079p\u0065:\u0020\u0025\u0054",_dba );};_abb ,_fbc :=_c .Marshal (make ([]byte ,_dba .Size ()));if _fbc !=nil {return _fbc ;
};_bfd .Contents =_ca .MakeHexString (string (_abb ));return nil ;};

View File

@ -9,62 +9,29 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package sigutil ;import (_gg "bytes";_af "crypto";_ab "crypto/x509";_ga "encoding/asn1";_gd "encoding/pem";_e "errors";_f "fmt";_fe "github.com/unidoc/timestamp";_c "github.com/unidoc/unipdf/v3/common";_b "golang.org/x/crypto/ocsp";_a "io";_da "io/ioutil";_d "net/http";_ggb "time";);
package sigutil ;import (_c "bytes";_a "crypto";_ac "crypto/x509";_bc "encoding/asn1";_cf "encoding/pem";_gb "errors";_bf "fmt";_ae "github.com/unidoc/timestamp";_d "github.com/unidoc/unipdf/v3/common";_de "golang.org/x/crypto/ocsp";_e "io";_ad "io/ioutil";
_f "net/http";_b "time";);
// IsCA returns true if the provided certificate appears to be a CA certificate.
func (_bg *CertClient )IsCA (cert *_ac .Certificate )bool {return cert .IsCA &&_c .Equal (cert .RawIssuer ,cert .RawSubject );};
// Get retrieves the certificate at the specified URL.
func (_dd *CertClient )Get (url string )(*_ac .Certificate ,error ){if _dd .HTTPClient ==nil {_dd .HTTPClient =_ba ();};_ga ,_ab :=_dd .HTTPClient .Get (url );if _ab !=nil {return nil ,_ab ;};defer _ga .Body .Close ();_eb ,_ab :=_ad .ReadAll (_ga .Body );
if _ab !=nil {return nil ,_ab ;};if _ea ,_ :=_cf .Decode (_eb );_ea !=nil {_eb =_ea .Bytes ;};_ff ,_ab :=_ac .ParseCertificate (_eb );if _ab !=nil {return nil ,_ab ;};return _ff ,nil ;};
// NewCertClient returns a new certificate client.
func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_ee ()}};
func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_ba ()}};
// GetEncodedToken executes the timestamp request and returns the DER encoded
// timestamp token bytes.
func (_ba *TimestampClient )GetEncodedToken (serverURL string ,req *_fe .Request )([]byte ,error ){if serverURL ==""{return nil ,_f .Errorf ("\u006d\u0075\u0073\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0020\u0074\u0069\u006d\u0065\u0073\u0074\u0061m\u0070\u0020\u0073\u0065\u0072\u0076\u0065r\u0020\u0055\u0052\u004c");};if req ==nil {return nil ,_f .Errorf ("\u0074\u0069\u006de\u0073\u0074\u0061\u006dp\u0020\u0072\u0065\u0071\u0075\u0065\u0073t\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_de ,_ec :=req .Marshal ();if _ec !=nil {return nil ,_ec ;};_ca :=_ba .HTTPClient ;if _ca ==nil {_ca =_ee ();};_ecd ,_ec :=_ca .Post (serverURL ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_gg .NewBuffer (_de ));if _ec !=nil {return nil ,_ec ;};defer _ecd .Body .Close ();_ffc ,_ec :=_da .ReadAll (_ecd .Body );if _ec !=nil {return nil ,_ec ;};if _ecd .StatusCode !=_d .StatusOK {return nil ,_f .Errorf ("\u0075\u006e\u0065x\u0070\u0065\u0063\u0074e\u0064\u0020\u0048\u0054\u0054\u0050\u0020s\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0064",_ecd .StatusCode );};var _dbb struct{Version _ga .RawValue ;Content _ga .RawValue ;};if _ ,_ec =_ga .Unmarshal (_ffc ,&_dbb );_ec !=nil {return nil ,_ec ;};return _dbb .Content .FullBytes ,nil ;};
// NewCRLClient returns a new CRL client.
func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_ba ()}};
// MakeRequest makes a OCSP request to the specified server and returns
// the parsed and raw responses. If a server URL is not provided, it is
// extracted from the certificate.
func (_dfe *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_ab .Certificate )(*_b .Response ,[]byte ,error ){if _dfe .HTTPClient ==nil {_dfe .HTTPClient =_ee ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_e .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063a\u0074\u0065\u0020\u0064\u006f\u0065\u0073 \u006e\u006f\u0074\u0020\u0073\u0070e\u0063\u0069\u0066\u0079\u0020\u0061\u006e\u0079\u0020\u004f\u0043S\u0050\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0073");};serverURL =cert .OCSPServer [0];};_dff ,_dd :=_b .CreateRequest (cert ,issuer ,&_b .RequestOptions {Hash :_dfe .Hash });if _dd !=nil {return nil ,nil ,_dd ;};_cf ,_dd :=_dfe .HTTPClient .Post (serverURL ,"\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u006fc\u0073\u0070\u002d\u0072\u0065\u0071\u0075\u0065\u0073\u0074",_gg .NewReader (_dff ));if _dd !=nil {return nil ,nil ,_dd ;};defer _cf .Body .Close ();_gdd ,_dd :=_da .ReadAll (_cf .Body );if _dd !=nil {return nil ,nil ,_dd ;};if _gde ,_ :=_gd .Decode (_gdd );_gde !=nil {_gdd =_gde .Bytes ;};_cfe ,_dd :=_b .ParseResponseForCert (_gdd ,cert ,issuer );if _dd !=nil {return nil ,nil ,_dd ;};return _cfe ,_gdd ,nil ;};
// NewTimestampClient returns a new timestamp client.
func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_ee ()}};
// TimestampClient represents a RFC 3161 timestamp client.
// It is used to obtain signed tokens from timestamp authority servers.
type TimestampClient struct{
// HTTPClient is the HTTP client used to make timestamp requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_d .Client ;};
// OCSPClient represents a OCSP (Online Certificate Status Protocol) client.
// It is used to request revocation data from OCSP servers.
type OCSPClient struct{
// HTTPClient is the HTTP client used to make OCSP requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_d .Client ;
// Hash is the hash function used when constructing the OCSP
// requests. If zero, SHA-1 will be used.
Hash _af .Hash ;};func _ee ()*_d .Client {return &_d .Client {Timeout :5*_ggb .Second }};
// NewTimestampRequest returns a new timestamp request based
// on the specified options.
func NewTimestampRequest (body _a .Reader ,opts *_fe .RequestOptions )(*_fe .Request ,error ){if opts ==nil {opts =&_fe .RequestOptions {};};if opts .Hash ==0{opts .Hash =_af .SHA256 ;};if !opts .Hash .Available (){return nil ,_ab .ErrUnsupportedAlgorithm ;};_gdc :=opts .Hash .New ();if _ ,_be :=_a .Copy (_gdc ,body );_be !=nil {return nil ,_be ;};return &_fe .Request {HashAlgorithm :opts .Hash ,HashedMessage :_gdc .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ;};
// GetIssuer retrieves the issuer of the provided certificate.
func (_df *CertClient )GetIssuer (cert *_ab .Certificate )(*_ab .Certificate ,error ){for _ ,_afc :=range cert .IssuingCertificateURL {_fg ,_aa :=_df .Get (_afc );if _aa !=nil {_c .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074 \u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u0020\u0069\u0073\u0073\u0075e\u0072\u0020\u0066\u006f\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066ic\u0061\u0074\u0065\u0020\u0025\u0076\u003a\u0020\u0025\u0076",cert .Subject .CommonName ,_aa );continue ;};return _fg ,nil ;};return nil ,_f .Errorf ("\u0069\u0073\u0073\u0075e\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063a\u0074e\u0020\u006e\u006f\u0074\u0020\u0066\u006fu\u006e\u0064");};
// Get retrieves the certificate at the specified URL.
func (_bg *CertClient )Get (url string )(*_ab .Certificate ,error ){if _bg .HTTPClient ==nil {_bg .HTTPClient =_ee ();};_cc ,_ef :=_bg .HTTPClient .Get (url );if _ef !=nil {return nil ,_ef ;};defer _cc .Body .Close ();_ff ,_ef :=_da .ReadAll (_cc .Body );if _ef !=nil {return nil ,_ef ;};if _fb ,_ :=_gd .Decode (_ff );_fb !=nil {_ff =_fb .Bytes ;};_dg ,_ef :=_ab .ParseCertificate (_ff );if _ef !=nil {return nil ,_ef ;};return _dg ,nil ;};
// MakeRequest makes a CRL request to the specified server and returns the
// response. If a server URL is not provided, it is extracted from the certificate.
func (_ad *CRLClient )MakeRequest (serverURL string ,cert *_ab .Certificate )([]byte ,error ){if _ad .HTTPClient ==nil {_ad .HTTPClient =_ee ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_e .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063\u0061t\u0065\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0070ec\u0069\u0066\u0079 \u0061\u006ey\u0020\u0043\u0052\u004c\u0020\u0073e\u0072\u0076e\u0072\u0073");};serverURL =cert .CRLDistributionPoints [0];};_cb ,_bgb :=_ad .HTTPClient .Get (serverURL );if _bgb !=nil {return nil ,_bgb ;};defer _cb .Body .Close ();_db ,_bgb :=_da .ReadAll (_cb .Body );if _bgb !=nil {return nil ,_bgb ;};if _dfd ,_ :=_gd .Decode (_db );_dfd !=nil {_db =_dfd .Bytes ;};return _db ,nil ;};
// NewCRLClient returns a new CRL client.
func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_ee ()}};
// IsCA returns true if the provided certificate appears to be a CA certificate.
func (_ac *CertClient )IsCA (cert *_ab .Certificate )bool {return cert .IsCA &&_gg .Equal (cert .RawIssuer ,cert .RawSubject );};
func (_da *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_ac .Certificate )(*_de .Response ,[]byte ,error ){if _da .HTTPClient ==nil {_da .HTTPClient =_ba ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_gb .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063a\u0074\u0065\u0020\u0064\u006f\u0065\u0073 \u006e\u006f\u0074\u0020\u0073\u0070e\u0063\u0069\u0066\u0079\u0020\u0061\u006e\u0079\u0020\u004f\u0043S\u0050\u0020\u0073\u0065\u0072\u0076\u0065\u0072\u0073");
};serverURL =cert .OCSPServer [0];};_bd ,_bcc :=_de .CreateRequest (cert ,issuer ,&_de .RequestOptions {Hash :_da .Hash });if _bcc !=nil {return nil ,nil ,_bcc ;};_ag ,_bcc :=_da .HTTPClient .Post (serverURL ,"\u0061p\u0070\u006c\u0069\u0063\u0061\u0074\u0069\u006f\u006e\u002f\u006fc\u0073\u0070\u002d\u0072\u0065\u0071\u0075\u0065\u0073\u0074",_c .NewReader (_bd ));
if _bcc !=nil {return nil ,nil ,_bcc ;};defer _ag .Body .Close ();_fc ,_bcc :=_ad .ReadAll (_ag .Body );if _bcc !=nil {return nil ,nil ,_bcc ;};if _abc ,_ :=_cf .Decode (_fc );_abc !=nil {_fc =_abc .Bytes ;};_deb ,_bcc :=_de .ParseResponseForCert (_fc ,cert ,issuer );
if _bcc !=nil {return nil ,nil ,_bcc ;};return _deb ,_fc ,nil ;};
// CertClient represents a X.509 certificate client. Its primary purpose
// is to download certificates.
@ -72,10 +39,7 @@ type CertClient struct{
// HTTPClient is the HTTP client used to make certificate requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_d .Client ;};
// NewOCSPClient returns a new OCSP client.
func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_ee (),Hash :_af .SHA1 }};
HTTPClient *_f .Client ;};
// CRLClient represents a CRL (Certificate revocation list) client.
// It is used to request revocation data from CRL servers.
@ -83,4 +47,55 @@ type CRLClient struct{
// HTTPClient is the HTTP client used to make CRL requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_d .Client ;};
HTTPClient *_f .Client ;};
// OCSPClient represents a OCSP (Online Certificate Status Protocol) client.
// It is used to request revocation data from OCSP servers.
type OCSPClient struct{
// HTTPClient is the HTTP client used to make OCSP requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_f .Client ;
// Hash is the hash function used when constructing the OCSP
// requests. If zero, SHA-1 will be used.
Hash _a .Hash ;};
// NewTimestampRequest returns a new timestamp request based
// on the specified options.
func NewTimestampRequest (body _e .Reader ,opts *_ae .RequestOptions )(*_ae .Request ,error ){if opts ==nil {opts =&_ae .RequestOptions {};};if opts .Hash ==0{opts .Hash =_a .SHA256 ;};if !opts .Hash .Available (){return nil ,_ac .ErrUnsupportedAlgorithm ;
};_ffb :=opts .Hash .New ();if _ ,_aac :=_e .Copy (_ffb ,body );_aac !=nil {return nil ,_aac ;};return &_ae .Request {HashAlgorithm :opts .Hash ,HashedMessage :_ffb .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ;
};
// NewTimestampClient returns a new timestamp client.
func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_ba ()}};
// GetEncodedToken executes the timestamp request and returns the DER encoded
// timestamp token bytes.
func (_gg *TimestampClient )GetEncodedToken (serverURL string ,req *_ae .Request )([]byte ,error ){if serverURL ==""{return nil ,_bf .Errorf ("\u006d\u0075\u0073\u0074\u0020\u0070r\u006f\u0076\u0069\u0064\u0065\u0020\u0074\u0069\u006d\u0065\u0073\u0074\u0061m\u0070\u0020\u0073\u0065\u0072\u0076\u0065r\u0020\u0055\u0052\u004c");
};if req ==nil {return nil ,_bf .Errorf ("\u0074\u0069\u006de\u0073\u0074\u0061\u006dp\u0020\u0072\u0065\u0071\u0075\u0065\u0073t\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};_aeca ,_ggf :=req .Marshal ();if _ggf !=nil {return nil ,_ggf ;
};_gad :=_gg .HTTPClient ;if _gad ==nil {_gad =_ba ();};_fcg ,_ggf :=_gad .Post (serverURL ,"a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079",_c .NewBuffer (_aeca ));
if _ggf !=nil {return nil ,_ggf ;};defer _fcg .Body .Close ();_bed ,_ggf :=_ad .ReadAll (_fcg .Body );if _ggf !=nil {return nil ,_ggf ;};if _fcg .StatusCode !=_f .StatusOK {return nil ,_bf .Errorf ("\u0075\u006e\u0065x\u0070\u0065\u0063\u0074e\u0064\u0020\u0048\u0054\u0054\u0050\u0020s\u0074\u0061\u0074\u0075\u0073\u0020\u0063\u006f\u0064\u0065\u003a\u0020\u0025\u0064",_fcg .StatusCode );
};var _eg struct{Version _bc .RawValue ;Content _bc .RawValue ;};if _ ,_ggf =_bc .Unmarshal (_bed ,&_eg );_ggf !=nil {return nil ,_ggf ;};return _eg .Content .FullBytes ,nil ;};
// NewOCSPClient returns a new OCSP client.
func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_ba (),Hash :_a .SHA1 }};
// MakeRequest makes a CRL request to the specified server and returns the
// response. If a server URL is not provided, it is extracted from the certificate.
func (_cb *CRLClient )MakeRequest (serverURL string ,cert *_ac .Certificate )([]byte ,error ){if _cb .HTTPClient ==nil {_cb .HTTPClient =_ba ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_gb .New ("\u0063e\u0072\u0074i\u0066\u0069\u0063\u0061t\u0065\u0020\u0064o\u0065\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0070ec\u0069\u0066\u0079 \u0061\u006ey\u0020\u0043\u0052\u004c\u0020\u0073e\u0072\u0076e\u0072\u0073");
};serverURL =cert .CRLDistributionPoints [0];};_ge ,_cfg :=_cb .HTTPClient .Get (serverURL );if _cfg !=nil {return nil ,_cfg ;};defer _ge .Body .Close ();_acf ,_cfg :=_ad .ReadAll (_ge .Body );if _cfg !=nil {return nil ,_cfg ;};if _ebf ,_ :=_cf .Decode (_acf );
_ebf !=nil {_acf =_ebf .Bytes ;};return _acf ,nil ;};
// GetIssuer retrieves the issuer of the provided certificate.
func (_bca *CertClient )GetIssuer (cert *_ac .Certificate )(*_ac .Certificate ,error ){for _ ,_ffa :=range cert .IssuingCertificateURL {_aec ,_ee :=_bca .Get (_ffa );if _ee !=nil {_d .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074 \u0064\u006f\u0077\u006e\u006c\u006f\u0061\u0064\u0020\u0069\u0073\u0073\u0075e\u0072\u0020\u0066\u006f\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066ic\u0061\u0074\u0065\u0020\u0025\u0076\u003a\u0020\u0025\u0076",cert .Subject .CommonName ,_ee );
continue ;};return _aec ,nil ;};return nil ,_bf .Errorf ("\u0069\u0073\u0073\u0075e\u0072\u0020\u0063\u0065\u0072\u0074\u0069\u0066\u0069\u0063a\u0074e\u0020\u006e\u006f\u0074\u0020\u0066\u006fu\u006e\u0064");};func _ba ()*_f .Client {return &_f .Client {Timeout :5*_b .Second }};
// TimestampClient represents a RFC 3161 timestamp client.
// It is used to obtain signed tokens from timestamp authority servers.
type TimestampClient struct{
// HTTPClient is the HTTP client used to make timestamp requests.
// By default, an HTTP client with a 5 second timeout per request is used.
HTTPClient *_f .Client ;};

View File

@ -9,7 +9,7 @@
// Use of this source code is governed by the UniDoc End User License Agreement
// terms that can be accessed at https://unidoc.io/eula/
package pdfutil ;import (_de "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/contentstream/draw";_c "github.com/unidoc/unipdf/v3/core";_a "github.com/unidoc/unipdf/v3/model";);
package pdfutil ;import (_a "github.com/unidoc/unipdf/v3/common";_ff "github.com/unidoc/unipdf/v3/contentstream";_fg "github.com/unidoc/unipdf/v3/contentstream/draw";_c "github.com/unidoc/unipdf/v3/core";_f "github.com/unidoc/unipdf/v3/model";);
// NormalizePage performs the following operations on the passed in page:
// - Normalize the page rotation.
@ -26,4 +26,10 @@ package pdfutil ;import (_de "github.com/unidoc/unipdf/v3/common";_g "github.com
// PDF viewer.
// NOTE: This function does not normalize annotations, outlines other parts
// that are not part of the basic geometry and page content streams.
func NormalizePage (page *_a .PdfPage )error {_bf ,_e :=page .GetMediaBox ();if _e !=nil {return _e ;};_dee :=page .Rotate ;_ae :=_dee !=nil &&*_dee %360!=0&&*_dee %90==0;_bf .Normalize ();_ab ,_f ,_ff ,_cf :=_bf .Llx ,_bf .Lly ,_bf .Width (),_bf .Height ();_bc :=_ab !=0||_f !=0;if !_ae &&!_bc {return nil ;};_eg :=func (_deb ,_ca ,_be float64 )_b .BoundingBox {return _b .Path {Points :[]_b .Point {_b .NewPoint (0,0).Rotate (_be ),_b .NewPoint (_deb ,0).Rotate (_be ),_b .NewPoint (0,_ca ).Rotate (_be ),_b .NewPoint (_deb ,_ca ).Rotate (_be )}}.GetBoundingBox ();};_ea :=_g .NewContentCreator ();var _aa float64 ;if _ae {_aa =-float64 (*page .Rotate );_ge :=_eg (_ff ,_cf ,_aa );_ea .Translate ((_ge .Width -_ff )/2+_ff /2,(_ge .Height -_cf )/2+_cf /2);_ea .RotateDeg (_aa );_ea .Translate (-_ff /2,-_cf /2);_ff ,_cf =_ge .Width ,_ge .Height ;};if _bc {_ea .Translate (-_ab ,-_f );};_ga :=_ea .Operations ();_ac ,_e :=_c .MakeStream (_ga .Bytes (),_c .NewFlateEncoder ());if _e !=nil {return _e ;};_cd :=_c .MakeArray (_ac );_cd .Append (page .GetContentStreamObjs ()...);*_bf =_a .PdfRectangle {Urx :_ff ,Ury :_cf };if _ffd :=page .CropBox ;_ffd !=nil {_ffd .Normalize ();_df ,_eb ,_bca ,_bfe :=_ffd .Llx -_ab ,_ffd .Lly -_f ,_ffd .Width (),_ffd .Height ();if _ae {_ffa :=_eg (_bca ,_bfe ,_aa );_bca ,_bfe =_ffa .Width ,_ffa .Height ;};*_ffd =_a .PdfRectangle {Llx :_df ,Lly :_eb ,Urx :_df +_bca ,Ury :_eb +_bfe };};_de .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",_aa ,_ga ,_bf );page .Contents =_cd ;page .Rotate =nil ;return nil ;};
func NormalizePage (page *_f .PdfPage )error {_e ,_ee :=page .GetMediaBox ();if _ee !=nil {return _ee ;};_cc :=page .Rotate ;_b :=_cc !=nil &&*_cc %360!=0&&*_cc %90==0;_e .Normalize ();_ccd ,_ea ,_d ,_ge :=_e .Llx ,_e .Lly ,_e .Width (),_e .Height ();_ec :=_ccd !=0||_ea !=0;
if !_b &&!_ec {return nil ;};_cb :=func (_gf ,_ed ,_dc float64 )_fg .BoundingBox {return _fg .Path {Points :[]_fg .Point {_fg .NewPoint (0,0).Rotate (_dc ),_fg .NewPoint (_gf ,0).Rotate (_dc ),_fg .NewPoint (0,_ed ).Rotate (_dc ),_fg .NewPoint (_gf ,_ed ).Rotate (_dc )}}.GetBoundingBox ();
};_be :=_ff .NewContentCreator ();var _eb float64 ;if _b {_eb =-float64 (*page .Rotate );_ac :=_cb (_d ,_ge ,_eb );_be .Translate ((_ac .Width -_d )/2+_d /2,(_ac .Height -_ge )/2+_ge /2);_be .RotateDeg (_eb );_be .Translate (-_d /2,-_ge /2);_d ,_ge =_ac .Width ,_ac .Height ;
};if _ec {_be .Translate (-_ccd ,-_ea );};_gg :=_be .Operations ();_df ,_ee :=_c .MakeStream (_gg .Bytes (),_c .NewFlateEncoder ());if _ee !=nil {return _ee ;};_aa :=_c .MakeArray (_df );_aa .Append (page .GetContentStreamObjs ()...);*_e =_f .PdfRectangle {Urx :_d ,Ury :_ge };
if _cd :=page .CropBox ;_cd !=nil {_cd .Normalize ();_dd ,_eg ,_fd ,_ddb :=_cd .Llx -_ccd ,_cd .Lly -_ea ,_cd .Width (),_cd .Height ();if _b {_ag :=_cb (_fd ,_ddb ,_eb );_fd ,_ddb =_ag .Width ,_ag .Height ;};*_cd =_f .PdfRectangle {Llx :_dd ,Lly :_eg ,Urx :_dd +_fd ,Ury :_eg +_ddb };
};_a .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_eb ,_gg ,_e );page .Contents =_aa ;page .Rotate =nil ;
return nil ;};

257
ps/ps.go

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