mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-24 13:48:49 +08:00
prepare release
This commit is contained in:
parent
5ddaeee7b2
commit
8b10191fd5
File diff suppressed because one or more lines are too long
132
common/common.go
132
common/common.go
@ -10,96 +10,96 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package common contains common properties used by the subpackages.
|
||||
package common ;import (_c "fmt";_bc "io";_fe "os";_a "path/filepath";_f "runtime";_bg "time";);
|
||||
package common ;import (_f "fmt";_af "io";_ab "os";_a "path/filepath";_d "runtime";_fc "time";);
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_dd ConsoleLogger )Notice (format string ,args ...interface{}){if _dd .LogLevel >=LogLevelNotice {_gfg :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_dd .output (_fe .Stdout ,_gfg ,format ,args ...);};};
|
||||
|
||||
// Error logs error message.
|
||||
func (_ae ConsoleLogger )Error (format string ,args ...interface{}){if _ae .LogLevel >=LogLevelError {_gf :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ae .output (_fe .Stdout ,_gf ,format ,args ...);};};
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
|
||||
|
||||
// UtcTimeFormat returns a formatted string describing a UTC timestamp.
|
||||
func UtcTimeFormat (t _bg .Time )string {return t .Format (_bb )+"\u0020\u0055\u0054\u0043"};
|
||||
|
||||
// Trace logs trace message.
|
||||
func (_fb WriterLogger )Trace (format string ,args ...interface{}){if _fb .LogLevel >=LogLevelTrace {_gdb :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_fb .logToWriter (_fb .Output ,_gdb ,format ,args ...);};};
|
||||
|
||||
// SetLogger sets 'logger' to be used by the unidoc unipdf library.
|
||||
func SetLogger (logger Logger ){Log =logger };const _beg =25;
|
||||
// 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{}){};
|
||||
|
||||
// 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 (_cbe ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cbe .LogLevel >=level };
|
||||
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};const _dbg =23;func (_gbf ConsoleLogger )output (_dba _bc .Writer ,_dde string ,_cb string ,_ff ...interface{}){_cga (_dba ,_dde ,_cb ,_ff ...);};
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_afa WriterLogger )Debug (format string ,args ...interface{}){if _afa .LogLevel >=LogLevelDebug {_bd :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_afa .logToWriter (_afa .Output ,_bd ,format ,args ...);};};func _cga (_bcd _bc .Writer ,_cgc string ,_bf string ,_agfc ...interface{}){_ ,_gdbf ,_ab ,_gc :=_f .Caller (3);if !_gc {_gdbf ="\u003f\u003f\u003f";_ab =0;}else {_gdbf =_a .Base (_gdbf );};_acd :=_c .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_cgc ,_gdbf ,_ab )+_bf +"\u000a";_c .Fprintf (_bcd ,_acd ,_agfc ...);};
|
||||
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _bc .Writer )*WriterLogger {_agf :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_agf ;};const _aac =2021;
|
||||
|
||||
// Debug logs debug message.
|
||||
func (_bcb ConsoleLogger )Debug (format string ,args ...interface{}){if _bcb .LogLevel >=LogLevelDebug {_ag :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_bcb .output (_fe .Stdout ,_ag ,format ,args ...);};};var ReleasedAt =_bg .Date (_aac ,_gbg ,_beg ,_dbg ,_gcf ,0,0,_bg .UTC );
|
||||
// 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 };
|
||||
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _bc .Writer ;};
|
||||
|
||||
// Logger is the interface used for logging in the unipdf package.
|
||||
type Logger interface{Error (_feb string ,_g ...interface{});Warning (_bga string ,_d ...interface{});Notice (_e string ,_gd ...interface{});Info (_dc string ,_fc ...interface{});Debug (_ec string ,_gb ...interface{});Trace (_ca string ,_fec ...interface{});IsLogLevel (_db LogLevel )bool ;};const _gbg =1;
|
||||
|
||||
// Info logs info message.
|
||||
func (_ac WriterLogger )Info (format string ,args ...interface{}){if _ac .LogLevel >=LogLevelInfo {_fd :="\u005bI\u004e\u0046\u004f\u005d\u0020";_ac .logToWriter (_ac .Output ,_fd ,format ,args ...);};};func (_cbe WriterLogger )logToWriter (_dcg _bc .Writer ,_aa string ,_gbe string ,_bcbc ...interface{}){_cga (_dcg ,_aa ,_gbe ,_bcbc );};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4;LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_ef ConsoleLogger )Warning (format string ,args ...interface{}){if _ef .LogLevel >=LogLevelWarning {_af :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_ef .output (_fe .Stdout ,_af ,format ,args ...);};};
|
||||
|
||||
// Warning does nothing for dummy logger.
|
||||
func (DummyLogger )Warning (format string ,args ...interface{}){};var Log Logger =DummyLogger {};
|
||||
|
||||
// ConsoleLogger is a logger that writes logs to the 'os.Stdout'
|
||||
type ConsoleLogger struct{LogLevel LogLevel ;};
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_fg ConsoleLogger )IsLogLevel (level LogLevel )bool {return _fg .LogLevel >=level };
|
||||
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 {_ed :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_ee .output (_fe .Stdout ,_ed ,format ,args ...);};};const Version ="\u0033\u002e\u0031\u0038\u002e\u0030";
|
||||
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{};
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};
|
||||
// LogLevel is the verbosity level for logging.
|
||||
type LogLevel int ;const _ac =16;
|
||||
|
||||
// IsLogLevel returns true if log level is greater or equal than `level`.
|
||||
// Can be used to avoid resource intensive calls to loggers.
|
||||
func (_cg WriterLogger )IsLogLevel (level LogLevel )bool {return _cg .LogLevel >=level };
|
||||
// Error does nothing for dummy logger.
|
||||
func (DummyLogger )Error (format string ,args ...interface{}){};
|
||||
|
||||
// Error logs error message.
|
||||
func (_eca WriterLogger )Error (format string ,args ...interface{}){if _eca .LogLevel >=LogLevelError {_ddc :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_eca .logToWriter (_eca .Output ,_ddc ,format ,args ...);};};
|
||||
// WriterLogger is the logger that writes data to the Output writer
|
||||
type WriterLogger struct{LogLevel LogLevel ;Output _af .Writer ;};
|
||||
|
||||
// Warning logs warning message.
|
||||
func (_gfa WriterLogger )Warning (format string ,args ...interface{}){if _gfa .LogLevel >=LogLevelWarning {_fa :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_gfa .logToWriter (_gfa .Output ,_fa ,format ,args ...);};};
|
||||
// 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 _bb ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034";const _gcf =30;
|
||||
func (DummyLogger )Debug (format string ,args ...interface{}){};const _ffa =2021;
|
||||
|
||||
// Info logs info message.
|
||||
func (_dbd ConsoleLogger )Info (format string ,args ...interface{}){if _dbd .LogLevel >=LogLevelInfo {_feg :="\u005bI\u004e\u0046\u004f\u005d\u0020";_dbd .output (_fe .Stdout ,_feg ,format ,args ...);};};
|
||||
// NewWriterLogger creates new 'writer' logger.
|
||||
func NewWriterLogger (logLevel LogLevel ,writer _af .Writer )*WriterLogger {_dfc :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_dfc ;};
|
||||
|
||||
// Notice logs notice message.
|
||||
func (_be WriterLogger )Notice (format string ,args ...interface{}){if _be .LogLevel >=LogLevelNotice {_aed :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_be .logToWriter (_be .Output ,_aed ,format ,args ...);};};
|
||||
// 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 ...);};};
|
||||
|
||||
// Info does nothing for dummy logger.
|
||||
func (DummyLogger )Info (format string ,args ...interface{}){};
|
||||
func (DummyLogger )Info (format string ,args ...interface{}){};
|
||||
|
||||
// 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 );
|
||||
|
||||
// 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 );};
|
||||
|
||||
// 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";
|
||||
|
||||
// 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 ...);};};
|
||||
|
||||
// NewConsoleLogger creates new console logger.
|
||||
func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }};
|
||||
|
||||
// Trace does nothing for dummy logger.
|
||||
func (DummyLogger )Trace (format string ,args ...interface{}){};var Log Logger =DummyLogger {};
|
||||
|
||||
// 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 ...);};
|
@ -10,24 +10,24 @@
|
||||
// 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 _ad "github.com/unidoc/unipdf/v3/internal/license";
|
||||
|
||||
// LicenseKey represents a loaded license key.
|
||||
type LicenseKey =_ad .LicenseKey ;
|
||||
|
||||
// SetLicenseKey sets and validates the license key.
|
||||
func SetLicenseKey (content string ,customerName string )error {return _ad .SetLicenseKey (content ,customerName );};const (LicenseTierUnlicensed =_ad .LicenseTierUnlicensed ;LicenseTierCommunity =_ad .LicenseTierCommunity ;LicenseTierIndividual =_ad .LicenseTierIndividual ;LicenseTierBusiness =_ad .LicenseTierBusiness ;);
|
||||
|
||||
// GetLicenseKey returns the currently loaded license key.
|
||||
func GetLicenseKey ()*LicenseKey {return _ad .GetLicenseKey ()};
|
||||
|
||||
// GetMeteredState checks the currently used metered document usage status,
|
||||
// documents used and credits available.
|
||||
func GetMeteredState ()(_ad .MeteredStatus ,error ){return _ad .GetMeteredState ()};
|
||||
|
||||
// MakeUnlicensedKey returns a default key.
|
||||
func MakeUnlicensedKey ()*LicenseKey {return _ad .MakeUnlicensedKey ()};
|
||||
package license ;import _aa "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 _ad .SetMeteredKey (apiKey )};
|
||||
func SetMeteredKey (apiKey string )error {return _aa .SetMeteredKey (apiKey )};
|
||||
|
||||
// GetMeteredState checks the currently used metered document usage status,
|
||||
// documents used and credits available.
|
||||
func GetMeteredState ()(_aa .MeteredStatus ,error ){return _aa .GetMeteredState ()};
|
||||
|
||||
// LicenseKey represents a loaded license key.
|
||||
type LicenseKey =_aa .LicenseKey ;
|
||||
|
||||
// GetLicenseKey returns the currently loaded license key.
|
||||
func GetLicenseKey ()*LicenseKey {return _aa .GetLicenseKey ()};
|
||||
|
||||
// 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 ()};
|
File diff suppressed because one or more lines are too long
@ -14,204 +14,204 @@
|
||||
// page content streams and XObject forms and thus also in annotation appearance streams.
|
||||
//
|
||||
// Also defines utility functions for drawing common shapes such as rectangles, lines and circles (ovals).
|
||||
package draw ;import (_c "fmt";_df "github.com/unidoc/unipdf/v3/contentstream";_cb "github.com/unidoc/unipdf/v3/core";_ae "github.com/unidoc/unipdf/v3/internal/transform";_a "github.com/unidoc/unipdf/v3/model";_d "math";);
|
||||
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 ;};
|
||||
|
||||
// Offset shifts the path with the specified offsets.
|
||||
func (_de Path )Offset (offX ,offY float64 )Path {for _ga ,_cc :=range _de .Points {_de .Points [_ga ]=_cc .Add (offX ,offY );};return _de ;};
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_ed :=CubicBezierPath {};_ed .Curves =[]CubicBezierCurve {};return _ed ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the Bezier path.
|
||||
func (_be CubicBezierPath )GetBoundingBox ()Rectangle {_cbg :=Rectangle {};_da :=0.0;_bf :=0.0;_fe :=0.0;_aag :=0.0;for _ff ,_adc :=range _be .Curves {_fa :=_adc .GetBounds ();if _ff ==0{_da =_fa .Llx ;_bf =_fa .Urx ;_fe =_fa .Lly ;_aag =_fa .Ury ;continue ;};if _fa .Llx < _da {_da =_fa .Llx ;};if _fa .Urx > _bf {_bf =_fa .Urx ;};if _fa .Lly < _fe {_fe =_fa .Lly ;};if _fa .Ury > _aag {_aag =_fa .Ury ;};};_cbg .X =_da ;_cbg .Y =_fe ;_cbg .Width =_bf -_da ;_cbg .Height =_aag -_fe ;return _cbg ;};
|
||||
// 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 (_ea Point )Add (dx ,dy float64 )Point {_ea .X +=dx ;_ea .Y +=dy ;return _ea };
|
||||
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 (_dg CubicBezierCurve )GetBounds ()_a .PdfRectangle {_ad :=_dg .P0 .X ;_aa :=_dg .P0 .X ;_b :=_dg .P0 .Y ;_eg :=_dg .P0 .Y ;for _g :=0.0;_g <=1.0;_g +=0.001{Rx :=_dg .P0 .X *_d .Pow (1-_g ,3)+_dg .P1 .X *3*_g *_d .Pow (1-_g ,2)+_dg .P2 .X *3*_d .Pow (_g ,2)*(1-_g )+_dg .P3 .X *_d .Pow (_g ,3);Ry :=_dg .P0 .Y *_d .Pow (1-_g ,3)+_dg .P1 .Y *3*_g *_d .Pow (1-_g ,2)+_dg .P2 .Y *3*_d .Pow (_g ,2)*(1-_g )+_dg .P3 .Y *_d .Pow (_g ,3);if Rx < _ad {_ad =Rx ;};if Rx > _aa {_aa =Rx ;};if Ry < _b {_b =Ry ;};if Ry > _eg {_eg =Ry ;};};_ag :=_a .PdfRectangle {};_ag .Llx =_ad ;_ag .Lly =_b ;_ag .Urx =_aa ;_ag .Ury =_eg ;return _ag ;};
|
||||
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 ;};
|
||||
|
||||
// Add adds the specified vector to the current one and returns the result.
|
||||
func (_gcd Vector )Add (other Vector )Vector {_gcd .Dx +=other .Dx ;_gcd .Dy +=other .Dy ;return _gcd };
|
||||
|
||||
// ToPdfRectangle returns the bounding box as a PDF rectangle.
|
||||
func (_ca BoundingBox )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_ca .X ,Lly :_ca .Y ,Urx :_ca .X +_ca .Width ,Ury :_ca .Y +_ca .Height };};
|
||||
// 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 (_afb Polygon )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_edeb :=_df .NewContentCreator ();_edeb .Add_q ();_afb .FillEnabled =_afb .FillEnabled &&_afb .FillColor !=nil ;if _afb .FillEnabled {_edeb .Add_rg (_afb .FillColor .R (),_afb .FillColor .G (),_afb .FillColor .B ());};_afb .BorderEnabled =_afb .BorderEnabled &&_afb .BorderColor !=nil ;if _afb .BorderEnabled {_edeb .Add_RG (_afb .BorderColor .R (),_afb .BorderColor .G (),_afb .BorderColor .B ());_edeb .Add_w (_afb .BorderWidth );};if len (gsName )> 1{_edeb .Add_gs (_cb .PdfObjectName (gsName ));};_afe :=NewPath ();for _ ,_aeg :=range _afb .Points {for _gcc ,_gd :=range _aeg {_afe =_afe .AppendPoint (_gd );if _gcc ==0{_edeb .Add_m (_gd .X ,_gd .Y );}else {_edeb .Add_l (_gd .X ,_gd .Y );};};_edeb .Add_h ();};if _afb .FillEnabled &&_afb .BorderEnabled {_edeb .Add_B ();}else if _afb .FillEnabled {_edeb .Add_f ();}else if _afb .BorderEnabled {_edeb .Add_S ();};_edeb .Add_Q ();return _edeb .Bytes (),_afe .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
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 ;};
|
||||
|
||||
// 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 (_dfc BasicLine )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_dbe :=_dfc .LineWidth ;_egf :=NewPath ();_egf =_egf .AppendPoint (NewPoint (_dfc .X1 ,_dfc .Y1 ));_egf =_egf .AppendPoint (NewPoint (_dfc .X2 ,_dfc .Y2 ));_aaf :=_df .NewContentCreator ();_fgd :=_egf .GetBoundingBox ();DrawPathWithCreator (_egf ,_aaf );if _dfc .LineStyle ==LineStyleDashed {_aaf .Add_d ([]int64 {1,1},0);};_aaf .Add_RG (_dfc .LineColor .R (),_dfc .LineColor .G (),_dfc .LineColor .B ()).Add_w (_dbe ).Add_S ().Add_Q ();return _aaf .Bytes (),_fgd .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 ;};
|
||||
|
||||
// NewPoint returns a new point with the coordinates x, y.
|
||||
func NewPoint (x ,y float64 )Point {return Point {X :x ,Y :y }};
|
||||
// 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 ;};
|
||||
|
||||
// GetBoundingBox returns the bounding box of the path.
|
||||
func (_ddg Path )GetBoundingBox ()BoundingBox {_cbgd :=BoundingBox {};_gca :=0.0;_bg :=0.0;_add :=0.0;_dbc :=0.0;for _gcad ,_adb :=range _ddg .Points {if _gcad ==0{_gca =_adb .X ;_bg =_adb .X ;_add =_adb .Y ;_dbc =_adb .Y ;continue ;};if _adb .X < _gca {_gca =_adb .X ;};if _adb .X > _bg {_bg =_adb .X ;};if _adb .Y < _add {_add =_adb .Y ;};if _adb .Y > _dbc {_dbc =_adb .Y ;};};_cbgd .X =_gca ;_cbgd .Y =_add ;_cbgd .Width =_bg -_gca ;_cbgd .Height =_dbc -_add ;return _cbgd ;};
|
||||
// FlipX flips the sign of the Dx component of the vector.
|
||||
func (_dce Vector )FlipX ()Vector {_dce .Dx =-_dce .Dx ;return _dce };
|
||||
|
||||
// GetPolarAngle returns the angle the magnitude of the vector forms with the
|
||||
// positive X-axis going counterclockwise.
|
||||
func (_cgc Vector )GetPolarAngle ()float64 {return _d .Atan2 (_cgc .Dy ,_cgc .Dx )};const (LineStyleSolid LineStyle =0;LineStyleDashed LineStyle =1;);
|
||||
// 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 };};
|
||||
|
||||
// Copy returns a clone of the path.
|
||||
func (_dd Path )Copy ()Path {_aga :=Path {};_aga .Points =append (_aga .Points ,_dd .Points ...);return _aga ;};
|
||||
|
||||
// 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 (_cff Rectangle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_bag :=NewPath ();_bag =_bag .AppendPoint (NewPoint (0,0));_bag =_bag .AppendPoint (NewPoint (0,_cff .Height ));_bag =_bag .AppendPoint (NewPoint (_cff .Width ,_cff .Height ));_bag =_bag .AppendPoint (NewPoint (_cff .Width ,0));_bag =_bag .AppendPoint (NewPoint (0,0));if _cff .X !=0||_cff .Y !=0{_bag =_bag .Offset (_cff .X ,_cff .Y );};_ge :=_df .NewContentCreator ();_ge .Add_q ();if _cff .FillEnabled {_ge .Add_rg (_cff .FillColor .R (),_cff .FillColor .G (),_cff .FillColor .B ());};if _cff .BorderEnabled {_ge .Add_RG (_cff .BorderColor .R (),_cff .BorderColor .G (),_cff .BorderColor .B ());_ge .Add_w (_cff .BorderWidth );};if len (gsName )> 1{_ge .Add_gs (_cb .PdfObjectName (gsName ));};DrawPathWithCreator (_bag ,_ge );_ge .Add_h ();if _cff .FillEnabled &&_cff .BorderEnabled {_ge .Add_B ();}else if _cff .FillEnabled {_ge .Add_f ();}else if _cff .BorderEnabled {_ge .Add_S ();};_ge .Add_Q ();return _ge .Bytes (),_bag .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 *_df .ContentCreator ){for _fea ,_gge :=range path .Points {if _fea ==0{creator .Add_m (_gge .X ,_gge .Y );}else {creator .Add_l (_gge .X ,_gge .Y );};};};
|
||||
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_db CubicBezierPath )Copy ()CubicBezierPath {_aae :=CubicBezierPath {};_aae .Curves =append (_aae .Curves ,_db .Curves ...);return _aae ;};
|
||||
|
||||
// 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 (_gea Line )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_ebf ,_cbd :=_gea .X1 ,_gea .X2 ;_ebb ,_dcf :=_gea .Y1 ,_gea .Y2 ;_gg :=_dcf -_ebb ;_effe :=_cbd -_ebf ;_agb :=_d .Atan2 (_gg ,_effe );L :=_d .Sqrt (_d .Pow (_effe ,2.0)+_d .Pow (_gg ,2.0));_ac :=_gea .LineWidth ;_egbg :=_d .Pi ;_ec :=1.0;if _effe < 0{_ec *=-1.0;};if _gg < 0{_ec *=-1.0;};VsX :=_ec *(-_ac /2*_d .Cos (_agb +_egbg /2));VsY :=_ec *(-_ac /2*_d .Sin (_agb +_egbg /2)+_ac *_d .Sin (_agb +_egbg /2));V1X :=VsX +_ac /2*_d .Cos (_agb +_egbg /2);V1Y :=VsY +_ac /2*_d .Sin (_agb +_egbg /2);V2X :=VsX +_ac /2*_d .Cos (_agb +_egbg /2)+L *_d .Cos (_agb );V2Y :=VsY +_ac /2*_d .Sin (_agb +_egbg /2)+L *_d .Sin (_agb );V3X :=VsX +_ac /2*_d .Cos (_agb +_egbg /2)+L *_d .Cos (_agb )+_ac *_d .Cos (_agb -_egbg /2);V3Y :=VsY +_ac /2*_d .Sin (_agb +_egbg /2)+L *_d .Sin (_agb )+_ac *_d .Sin (_agb -_egbg /2);V4X :=VsX +_ac /2*_d .Cos (_agb -_egbg /2);V4Y :=VsY +_ac /2*_d .Sin (_agb -_egbg /2);_abd :=NewPath ();_abd =_abd .AppendPoint (NewPoint (V1X ,V1Y ));_abd =_abd .AppendPoint (NewPoint (V2X ,V2Y ));_abd =_abd .AppendPoint (NewPoint (V3X ,V3Y ));_abd =_abd .AppendPoint (NewPoint (V4X ,V4Y ));_adbe :=_gea .LineEndingStyle1 ;_dbg :=_gea .LineEndingStyle2 ;_eba :=3*_ac ;_ddd :=3*_ac ;_fgc :=(_ddd -_ac )/2;if _dbg ==LineEndingStyleArrow {_fd :=_abd .GetPointNumber (2);_fac :=NewVectorPolar (_eba ,_agb +_egbg );_gcadf :=_fd .AddVector (_fac );_eab :=NewVectorPolar (_ddd /2,_agb +_egbg /2);_cbc :=NewVectorPolar (_eba ,_agb );_cd :=NewVectorPolar (_fgc ,_agb +_egbg /2);_ded :=_gcadf .AddVector (_cd );_cdf :=_cbc .Add (_eab .Flip ());_bgb :=_ded .AddVector (_cdf );_eda :=_eab .Scale (2).Flip ().Add (_cdf .Flip ());_bga :=_bgb .AddVector (_eda );_edc :=_gcadf .AddVector (NewVectorPolar (_ac ,_agb -_egbg /2));_cfd :=NewPath ();_cfd =_cfd .AppendPoint (_abd .GetPointNumber (1));_cfd =_cfd .AppendPoint (_gcadf );_cfd =_cfd .AppendPoint (_ded );_cfd =_cfd .AppendPoint (_bgb );_cfd =_cfd .AppendPoint (_bga );_cfd =_cfd .AppendPoint (_edc );_cfd =_cfd .AppendPoint (_abd .GetPointNumber (4));_abd =_cfd ;};if _adbe ==LineEndingStyleArrow {_gdb :=_abd .GetPointNumber (1);_deb :=_abd .GetPointNumber (_abd .Length ());_aca :=NewVectorPolar (_ac /2,_agb +_egbg +_egbg /2);_cbgg :=_gdb .AddVector (_aca );_fdc :=NewVectorPolar (_eba ,_agb ).Add (NewVectorPolar (_ddd /2,_agb +_egbg /2));_cea :=_cbgg .AddVector (_fdc );_cae :=NewVectorPolar (_fgc ,_agb -_egbg /2);_fef :=_cea .AddVector (_cae );_cdb :=NewVectorPolar (_eba ,_agb );_edag :=_deb .AddVector (_cdb );_gf :=NewVectorPolar (_fgc ,_agb +_egbg +_egbg /2);_ebcf :=_edag .AddVector (_gf );_bc :=_cbgg ;_aegd :=NewPath ();_aegd =_aegd .AppendPoint (_cbgg );_aegd =_aegd .AppendPoint (_cea );_aegd =_aegd .AppendPoint (_fef );for _ ,_gce :=range _abd .Points [1:len (_abd .Points )-1]{_aegd =_aegd .AppendPoint (_gce );};_aegd =_aegd .AppendPoint (_edag );_aegd =_aegd .AppendPoint (_ebcf );_aegd =_aegd .AppendPoint (_bc );_abd =_aegd ;};_eabf :=_df .NewContentCreator ();_eabf .Add_q ().Add_rg (_gea .LineColor .R (),_gea .LineColor .G (),_gea .LineColor .B ());if len (gsName )> 1{_eabf .Add_gs (_cb .PdfObjectName (gsName ));};_abd =_abd .Offset (_gea .X1 ,_gea .Y1 );_edce :=_abd .GetBoundingBox ();DrawPathWithCreator (_abd ,_eabf );if _gea .LineStyle ==LineStyleDashed {_eabf .Add_d ([]int64 {1,1},0).Add_S ().Add_f ().Add_Q ();}else {_eabf .Add_f ().Add_Q ();};return _eabf .Bytes (),_edce .ToPdfRectangle (),nil ;};
|
||||
|
||||
// NewVectorPolar returns a new vector calculated from the specified
|
||||
// magnitude and angle.
|
||||
func NewVectorPolar (length float64 ,theta float64 )Vector {_gfa :=Vector {};_gfa .Dx =length *_d .Cos (theta );_gfa .Dy =length *_d .Sin (theta );return _gfa ;};
|
||||
|
||||
// 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 (_effd Circle )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){_caa :=_effd .Width /2;_fg :=_effd .Height /2;if _effd .BorderEnabled {_caa -=_effd .BorderWidth /2;_fg -=_effd .BorderWidth /2;};_ddf :=0.551784;_cg :=_caa *_ddf ;_dgc :=_fg *_ddf ;_aac :=NewCubicBezierPath ();_aac =_aac .AppendCurve (NewCubicBezierCurve (-_caa ,0,-_caa ,_dgc ,-_cg ,_fg ,0,_fg ));_aac =_aac .AppendCurve (NewCubicBezierCurve (0,_fg ,_cg ,_fg ,_caa ,_dgc ,_caa ,0));_aac =_aac .AppendCurve (NewCubicBezierCurve (_caa ,0,_caa ,-_dgc ,_cg ,-_fg ,0,-_fg ));_aac =_aac .AppendCurve (NewCubicBezierCurve (0,-_fg ,-_cg ,-_fg ,-_caa ,-_dgc ,-_caa ,0));_aac =_aac .Offset (_caa ,_fg );if _effd .BorderEnabled {_aac =_aac .Offset (_effd .BorderWidth /2,_effd .BorderWidth /2);};if _effd .X !=0||_effd .Y !=0{_aac =_aac .Offset (_effd .X ,_effd .Y );};_ce :=_df .NewContentCreator ();_ce .Add_q ();if _effd .FillEnabled {_ce .Add_rg (_effd .FillColor .R (),_effd .FillColor .G (),_effd .FillColor .B ());};if _effd .BorderEnabled {_ce .Add_RG (_effd .BorderColor .R (),_effd .BorderColor .G (),_effd .BorderColor .B ());_ce .Add_w (_effd .BorderWidth );};if len (gsName )> 1{_ce .Add_gs (_cb .PdfObjectName (gsName ));};DrawBezierPathWithCreator (_aac ,_ce );_ce .Add_h ();if _effd .FillEnabled &&_effd .BorderEnabled {_ce .Add_B ();}else if _effd .FillEnabled {_ce .Add_f ();}else if _effd .BorderEnabled {_ce .Add_S ();};_ce .Add_Q ();_bff :=_aac .GetBoundingBox ();if _effd .BorderEnabled {_bff .Height +=_effd .BorderWidth ;_bff .Width +=_effd .BorderWidth ;_bff .X -=_effd .BorderWidth /2;_bff .Y -=_effd .BorderWidth /2;};return _ce .Bytes (),_bff .ToPdfRectangle (),nil ;};
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// Point represents a two-dimensional point.
|
||||
type Point struct{X float64 ;Y float64 ;};
|
||||
|
||||
// Line defines a line shape between point 1 (X1,Y1) and point 2 (X2,Y2). The line ending styles can be none (regular line),
|
||||
// or arrows at either end. The line also has a specified width, color and opacity.
|
||||
type Line struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineEndingStyle1 LineEndingStyle ;LineEndingStyle2 LineEndingStyle ;LineStyle LineStyle ;};
|
||||
|
||||
// AppendCurve appends the specified Bezier curve to the path.
|
||||
func (_ed CubicBezierPath )AppendCurve (curve CubicBezierCurve )CubicBezierPath {_ed .Curves =append (_ed .Curves ,curve );return _ed ;};
|
||||
|
||||
// Rotate returns a new Point at `p` rotated by `theta` degrees.
|
||||
func (_ef Point )Rotate (theta float64 )Point {_efd :=_ae .NewPoint (_ef .X ,_ef .Y ).Rotate (theta );return NewPoint (_efd .X ,_efd .Y );};func (_eff Point )String ()string {return _c .Sprintf ("(\u0025\u002e\u0031\u0066\u002c\u0025\u002e\u0031\u0066\u0029",_eff .X ,_eff .Y );};
|
||||
|
||||
// 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 (_cag PolyBezierCurve )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _cag .BorderColor ==nil {_cag .BorderColor =_a .NewPdfColorDeviceRGB (0,0,0);};_eb :=NewCubicBezierPath ();for _ ,_af :=range _cag .Curves {_eb =_eb .AppendCurve (_af );};_ebc :=_df .NewContentCreator ();_ebc .Add_q ();_cag .FillEnabled =_cag .FillEnabled &&_cag .FillColor !=nil ;if _cag .FillEnabled {_ebc .Add_rg (_cag .FillColor .R (),_cag .FillColor .G (),_cag .FillColor .B ());};_ebc .Add_RG (_cag .BorderColor .R (),_cag .BorderColor .G (),_cag .BorderColor .B ());_ebc .Add_w (_cag .BorderWidth );if len (gsName )> 1{_ebc .Add_gs (_cb .PdfObjectName (gsName ));};for _ ,_cf :=range _eb .Curves {_ebc .Add_m (_cf .P0 .X ,_cf .P0 .Y );_ebc .Add_c (_cf .P1 .X ,_cf .P1 .Y ,_cf .P2 .X ,_cf .P2 .Y ,_cf .P3 .X ,_cf .P3 .Y );};if _cag .FillEnabled {_ebc .Add_h ();_ebc .Add_B ();}else {_ebc .Add_S ();};_ebc .Add_Q ();return _ebc .Bytes (),_eb .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
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 ;};
|
||||
|
||||
// GetPointNumber returns the path point at the index specified by number.
|
||||
// The index is 1-based.
|
||||
func (_fed Path )GetPointNumber (number int )Point {if number < 1||number > len (_fed .Points ){return Point {};};return _fed .Points [number -1];};const (LineEndingStyleNone LineEndingStyle =0;LineEndingStyleArrow LineEndingStyle =1;LineEndingStyleButt LineEndingStyle =2;);
|
||||
// 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;);
|
||||
|
||||
// AppendPoint adds the specified point to the path.
|
||||
func (_adf Path )AppendPoint (point Point )Path {_adf .Points =append (_adf .Points ,point );return _adf };
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_bfa Vector )FlipY ()Vector {_bfa .Dy =-_bfa .Dy ;return _bfa };
|
||||
|
||||
// DrawBezierPathWithCreator makes the bezier path with the content creator.
|
||||
// Adds the PDF commands to draw the path to the creator instance.
|
||||
func DrawBezierPathWithCreator (bpath CubicBezierPath ,creator *_df .ContentCreator ){for _effg ,_dga :=range bpath .Curves {if _effg ==0{creator .Add_m (_dga .P0 .X ,_dga .P0 .Y );};creator .Add_c (_dga .P1 .X ,_dga .P1 .Y ,_dga .P2 .X ,_dga .P2 .Y ,_dga .P3 .X ,_dga .P3 .Y );};};
|
||||
// AddVector adds vector to a point.
|
||||
func (_fgb Point )AddVector (v Vector )Point {_fgb .X +=v .Dx ;_fgb .Y +=v .Dy ;return _fgb };
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// LineStyle refers to how the line will be created.
|
||||
type LineStyle int ;
|
||||
|
||||
// Flip changes the sign of the vector: -vector.
|
||||
func (_bfa Vector )Flip ()Vector {_egg :=_bfa .Magnitude ();_geg :=_bfa .GetPolarAngle ();_bfa .Dx =_egg *_d .Cos (_geg +_d .Pi );_bfa .Dy =_egg *_d .Sin (_geg +_d .Pi );return _bfa ;};
|
||||
// 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];};
|
||||
|
||||
// ToPdfRectangle returns the rectangle as a PDF rectangle.
|
||||
func (_aee Rectangle )ToPdfRectangle ()*_a .PdfRectangle {return &_a .PdfRectangle {Llx :_aee .X ,Lly :_aee .Y ,Urx :_aee .X +_aee .Width ,Ury :_aee .Y +_aee .Height };};
|
||||
// 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 ;};
|
||||
|
||||
// Offset shifts the Bezier path with the specified offsets.
|
||||
func (_abb CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _ede ,_dc :=range _abb .Curves {_abb .Curves [_ede ]=_dc .AddOffsetXY (offX ,offY );};return _abb ;};
|
||||
|
||||
// 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 {_aff :=Vector {};_aff .Dx =b .X -a .X ;_aff .Dy =b .Y -a .Y ;return _aff ;};
|
||||
|
||||
// NewCubicBezierPath returns a new empty cubic Bezier path.
|
||||
func NewCubicBezierPath ()CubicBezierPath {_gb :=CubicBezierPath {};_gb .Curves =[]CubicBezierCurve {};return _gb ;};
|
||||
|
||||
// AddOffsetXY adds X,Y offset to all points on a curve.
|
||||
func (_e CubicBezierCurve )AddOffsetXY (offX ,offY float64 )CubicBezierCurve {_e .P0 .X +=offX ;_e .P1 .X +=offX ;_e .P2 .X +=offX ;_e .P3 .X +=offX ;_e .P0 .Y +=offY ;_e .P1 .Y +=offY ;_e .P2 .Y +=offY ;_e .P3 .Y +=offY ;return _e ;};
|
||||
|
||||
// Scale scales the vector by the specified factor.
|
||||
func (_ebg Vector )Scale (factor float64 )Vector {_gda :=_ebg .Magnitude ();_dba :=_ebg .GetPolarAngle ();_ebg .Dx =factor *_gda *_d .Cos (_dba );_ebg .Dy =factor *_gda *_d .Sin (_dba );return _ebg ;};
|
||||
func (_fd CubicBezierPath )Offset (offX ,offY float64 )CubicBezierPath {for _fb ,_bb :=range _fd .Curves {_fd .Curves [_fb ]=_bb .AddOffsetXY (offX ,offY );};return _fd ;};
|
||||
|
||||
// PolyBezierCurve represents a composite curve that is the result of
|
||||
// joining multiple cubic Bezier curves.
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;};
|
||||
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
||||
|
||||
// Polygon is a multi-point shape that can be drawn to a PDF content stream.
|
||||
type Polygon struct{Points [][]Point ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderColor *_a .PdfColorDeviceRGB ;BorderWidth float64 ;};
|
||||
|
||||
// Path consists of straight line connections between each point defined in an array of points.
|
||||
type Path struct{Points []Point ;};
|
||||
type PolyBezierCurve struct{Curves []CubicBezierCurve ;BorderWidth float64 ;BorderColor *_eb .PdfColorDeviceRGB ;FillEnabled bool ;FillColor *_eb .PdfColorDeviceRGB ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// Vector represents a two-dimensional vector.
|
||||
type Vector struct{Dx float64 ;Dy float64 ;};
|
||||
// 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 };};
|
||||
|
||||
// AddVector adds vector to a point.
|
||||
func (_cba Point )AddVector (v Vector )Point {_cba .X +=v .Dx ;_cba .Y +=v .Dy ;return _cba };
|
||||
|
||||
// NewVector returns a new vector with the direction specified by dx and dy.
|
||||
func NewVector (dx ,dy float64 )Vector {_ega :=Vector {};_ega .Dx =dx ;_ega .Dy =dy ;return _ega };
|
||||
|
||||
// NewCubicBezierCurve returns a new cubic Bezier curve.
|
||||
func NewCubicBezierCurve (x0 ,y0 ,x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )CubicBezierCurve {_ab :=CubicBezierCurve {};_ab .P0 =NewPoint (x0 ,y0 );_ab .P1 =NewPoint (x1 ,y1 );_ab .P2 =NewPoint (x2 ,y2 );_ab .P3 =NewPoint (x3 ,y3 );return _ab ;};
|
||||
|
||||
// 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 (_fdb Vector )FlipX ()Vector {_fdb .Dx =-_fdb .Dx ;return _fdb };
|
||||
|
||||
// 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 (_edd Polyline )Draw (gsName string )([]byte ,*_a .PdfRectangle ,error ){if _edd .LineColor ==nil {_edd .LineColor =_a .NewPdfColorDeviceRGB (0,0,0);};_ece :=NewPath ();for _ ,_ffc :=range _edd .Points {_ece =_ece .AppendPoint (_ffc );};_aacf :=_df .NewContentCreator ();_aacf .Add_q ();_aacf .Add_RG (_edd .LineColor .R (),_edd .LineColor .G (),_edd .LineColor .B ());_aacf .Add_w (_edd .LineWidth );if len (gsName )> 1{_aacf .Add_gs (_cb .PdfObjectName (gsName ));};DrawPathWithCreator (_ece ,_aacf );_aacf .Add_S ();_aacf .Add_Q ();return _aacf .Bytes (),_ece .GetBoundingBox ().ToPdfRectangle (),nil ;};
|
||||
|
||||
// LineEndingStyle defines the line ending style for lines.
|
||||
// The currently supported line ending styles are None, Arrow (ClosedArrow) and Butt.
|
||||
type LineEndingStyle int ;
|
||||
|
||||
// FlipY flips the sign of the Dy component of the vector.
|
||||
func (_ccd Vector )FlipY ()Vector {_ccd .Dy =-_ccd .Dy ;return _ccd };
|
||||
// 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 );};};};
|
||||
|
||||
// Rotate rotates the vector by the specified angle.
|
||||
func (_cbge Vector )Rotate (phi float64 )Vector {_aeea :=_cbge .Magnitude ();_acae :=_cbge .GetPolarAngle ();return NewVectorPolar (_aeea ,_acae +phi );};
|
||||
func (_dcd Vector )Rotate (phi float64 )Vector {_cca :=_dcd .Magnitude ();_bec :=_dcd .GetPolarAngle ();return NewVectorPolar (_cca ,_bec +phi );};
|
||||
|
||||
// Polyline defines a slice of points that are connected as straight lines.
|
||||
type Polyline struct{Points []Point ;LineColor *_a .PdfColorDeviceRGB ;LineWidth float64 ;};
|
||||
// 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 ;};
|
||||
|
||||
// Magnitude returns the magnitude of the vector.
|
||||
func (_bgf Vector )Magnitude ()float64 {return _d .Sqrt (_d .Pow (_bgf .Dx ,2.0)+_d .Pow (_bgf .Dy ,2.0))};
|
||||
// Copy returns a clone of the Bezier path.
|
||||
func (_ddd CubicBezierPath )Copy ()CubicBezierPath {_dc :=CubicBezierPath {};_dc .Curves =append (_dc .Curves ,_ddd .Curves ...);return _dc ;};
|
||||
|
||||
// BasicLine defines a line between point 1 (X1,Y1) and point 2 (X2,Y2). The line has a specified width, color and opacity.
|
||||
type BasicLine struct{X1 float64 ;Y1 float64 ;X2 float64 ;Y2 float64 ;LineColor *_a .PdfColorDeviceRGB ;Opacity float64 ;LineWidth float64 ;LineStyle LineStyle ;};
|
||||
// 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 ;};
|
||||
|
||||
// Length returns the number of points in the path.
|
||||
func (_egb Path )Length ()int {return len (_egb .Points )};
|
||||
// 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 ;};
|
||||
|
||||
// Circle represents a circle shape with fill and border properties that can be drawn to a PDF content stream.
|
||||
type Circle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
// 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 };
|
||||
|
||||
// RemovePoint removes the point at the index specified by number from the
|
||||
// path. The index is 1-based.
|
||||
func (_daf Path )RemovePoint (number int )Path {if number < 1||number > len (_daf .Points ){return _daf ;};_gc :=number -1;_daf .Points =append (_daf .Points [:_gc ],_daf .Points [_gc +1:]...);return _daf ;};
|
||||
// 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 ;};
|
||||
|
||||
// Rectangle is a shape with a specified Width and Height and a lower left corner at (X,Y) that can be
|
||||
// drawn to a PDF content stream. The rectangle can optionally have a border and a filling color.
|
||||
// The Width/Height includes the border (if any specified), i.e. is positioned inside.
|
||||
type Rectangle struct{X float64 ;Y float64 ;Width float64 ;Height float64 ;FillEnabled bool ;FillColor *_a .PdfColorDeviceRGB ;BorderEnabled bool ;BorderWidth float64 ;BorderColor *_a .PdfColorDeviceRGB ;Opacity float64 ;};
|
||||
// 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 );};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// NewPath returns a new empty path.
|
||||
func NewPath ()Path {return Path {}};
|
1843
core/core.go
1843
core/core.go
File diff suppressed because one or more lines are too long
@ -9,40 +9,73 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package crypt ;import (_d "crypto/aes";_e "crypto/cipher";_g "crypto/md5";_c "crypto/rand";_fg "crypto/rc4";_ff "fmt";_fb "github.com/unidoc/unipdf/v3/common";_ed "github.com/unidoc/unipdf/v3/core/security";_b "io";);func init (){_gdg ("\u0041\u0045\u0053V\u0032",_ec )};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };
|
||||
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 )};
|
||||
|
||||
// NewFilter creates CryptFilter from a corresponding dictionary.
|
||||
func NewFilter (d FilterDict )(Filter ,error ){_ece ,_cga :=_ca (d .CFM );if _cga !=nil {return nil ,_cga ;};_gd ,_cga :=_ece (d );if _cga !=nil {return nil ,_cga ;};return _gd ,nil ;};func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_ge ,_cb :=_d .NewCipher (okey );if _cb !=nil {return nil ,_cb ;};if len (buf )< 16{_fb .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_ff .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf ));};_db :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_fb .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_db ),_db );_fb .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,_ff .Errorf ("\u0041\u0045\u0053\u0020\u0062\u0075\u0066\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006e\u006f\u0074\u0020\u006d\u0075\u006c\u0074\u0069p\u006c\u0065\u0020\u006f\u0066 \u0031\u0036 \u0028\u0025\u0064\u0029",len (buf ));};_fc :=_e .NewCBCDecrypter (_ge ,_db );_fb .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_fb .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf );_fc .CryptBlocks (buf ,buf );_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_fb .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067");return buf ,nil ;};_bc :=int (buf [len (buf )-1]);if _bc > len (buf ){_fb .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_bc ,len (buf ));return buf ,_ff .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_bc ];return buf ,nil ;};
|
||||
// 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 ;};
|
||||
|
||||
// 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 (_ged filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;};
|
||||
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 _ac (objNum ,genNum ,ekey ,true );};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}};type filterAESV3 struct{filterAES };func (filterIdentity )HandlerVersion ()(V ,R int ){return ;};
|
||||
func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ebc (objNum ,genNum ,ekey ,true );};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (_dgc filterV2 )KeyLength ()int {return _dgc ._efc };func init (){_gdg ("\u0041\u0045\u0053V\u0033",_bg )};var (_cg =make (map[string ]filterFunc ););func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };
|
||||
|
||||
// NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3).
|
||||
func NewFilterAESV3 ()Filter {_a ,_ecb :=_bg (FilterDict {});if _ecb !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ecb );return filterAESV3 {};};return _a ;};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV3 )KeyLength ()int {return 256/8};type filterAESV2 struct{filterAES };
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};type filterFunc func (_gc FilterDict )(Filter ,error );func _dg (_ba FilterDict )(Filter ,error ){if _ba .Length %8!=0{return nil ,_ff .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",_ba .Length );};if _ba .Length < 5||_ba .Length > 16{if _ba .Length ==40||_ba .Length ==64||_ba .Length ==128{_fb .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_ba .Length );_ba .Length /=8;}else {return nil ,_ff .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",_ba .Length );};};return filterV2 {_efc :_ba .Length },nil ;};
|
||||
|
||||
// Name implements Filter interface.
|
||||
func (filterV2 )Name ()string {return "\u0056\u0032"};
|
||||
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 ){_bab ,_bac :=_fg .NewCipher (okey );if _bac !=nil {return nil ,_bac ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bab .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _ec (_ede FilterDict )(Filter ,error ){if _ede .Length ==128{_fb .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_ede .Length );_ede .Length /=8;};if _ede .Length !=0&&_ede .Length !=16{return nil ,_ff .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",_ede .Length );};return filterAESV2 {},nil ;};
|
||||
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 (_gb filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ac (objNum ,genNum ,ekey ,false );};func init (){_gdg ("\u0056\u0032",_dg )};
|
||||
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 {};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// Filter is a common interface for crypt filter methods.
|
||||
type Filter interface{
|
||||
@ -61,48 +94,15 @@ 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 (_adb ,_dfc uint32 ,_gaa []byte )([]byte ,error );
|
||||
MakeKey (_gcb ,_bfb uint32 ,_gcbb []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 (_gafc []byte ,_aa []byte )([]byte ,error );
|
||||
EncryptBytes (_de []byte ,_bacd []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 (_bef []byte ,_ccg []byte )([]byte ,error );};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (_cba filterV2 )PDFVersion ()[2]int {return [2]int {}};func _ca (_ccc string )(filterFunc ,error ){_fcd :=_cg [_ccc ];if _fcd ==nil {return nil ,_ff .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",_ccc );};return _fcd ,nil ;};func _gdg (_bgg string ,_ag filterFunc ){if _ ,_ea :=_cg [_bgg ];_ea {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064");};_cg [_bgg ]=_ag ;};func (filterIdentity )KeyLength ()int {return 0};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};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"};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}};
|
||||
|
||||
// NewFilterV2 creates a RC4-based filter with a specified key length (in bytes).
|
||||
func NewFilterV2 (length int )Filter {_ab ,_ad :=_dg (FilterDict {Length :length });if _ad !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ad );return filterV2 {_efc :length };};return _ab ;};
|
||||
|
||||
// MakeKey implements Filter interface.
|
||||
func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil };
|
||||
|
||||
// FilterDict represents information from a CryptFilter dictionary.
|
||||
type FilterDict struct{CFM string ;AuthEvent _ed .AuthEvent ;Length int ;};func _ac (_gaf ,_feb uint32 ,_fa []byte ,_af bool )([]byte ,error ){_fd :=make ([]byte ,len (_fa )+5);for _eeb :=0;_eeb < len (_fa );_eeb ++{_fd [_eeb ]=_fa [_eeb ];};for _afd :=0;_afd < 3;_afd ++{_be :=byte ((_gaf >>uint32 (8*_afd ))&0xff);_fd [_afd +len (_fa )]=_be ;};for _egf :=0;_egf < 2;_egf ++{_dae :=byte ((_feb >>uint32 (8*_egf ))&0xff);_fd [_egf +len (_fa )+3]=_dae ;};if _af {_fd =append (_fd ,0x73);_fd =append (_fd ,0x41);_fd =append (_fd ,0x6C);_fd =append (_fd ,0x54);};_bff :=_g .New ();_bff .Write (_fd );_df :=_bff .Sum (nil );if len (_fa )+5< 16{return _df [0:len (_fa )+5],nil ;};return _df ,nil ;};var _ Filter =filterV2 {};
|
||||
|
||||
// PDFVersion implements Filter interface.
|
||||
func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};var _ Filter =filterAESV2 {};
|
||||
|
||||
// NewIdentity creates an identity filter that bypasses all data without changes.
|
||||
func NewIdentity ()Filter {return filterIdentity {}};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_dc ,_da :=_d .NewCipher (okey );if _da !=nil {return nil ,_da ;};_fb .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );const _bfa =_d .BlockSize ;_ecbe :=_bfa -len (buf )%_bfa ;for _dd :=0;_dd < _ecbe ;_dd ++{buf =append (buf ,byte (_ecbe ));};_fb .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_ga :=make ([]byte ,_bfa +len (buf ));_eg :=_ga [:_bfa ];if _ ,_fgb :=_b .ReadFull (_c .Reader ,_eg );_fgb !=nil {return nil ,_fgb ;};_cc :=_e .NewCBCEncrypter (_dc ,_eg );_cc .CryptBlocks (_ga [_bfa :],buf );buf =_ga ;_fb .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );return buf ,nil ;};type filterV2 struct{_efc int };var _ Filter =filterAESV3 {};type filterAES struct{};func _bg (_fe FilterDict )(Filter ,error ){if _fe .Length ==256{_fb .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_fe .Length );_fe .Length /=8;};if _fe .Length !=0&&_fe .Length !=32{return nil ,_ff .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",_fe .Length );};return filterAESV3 {},nil ;};
|
||||
DecryptBytes (_dae []byte ,_bbe []byte )([]byte ,error );};var _ Filter =filterAESV2 {};
|
||||
|
||||
// KeyLength implements Filter interface.
|
||||
func (filterAESV2 )KeyLength ()int {return 128/8};type filterIdentity struct{};
|
||||
|
||||
// HandlerVersion implements Filter interface.
|
||||
func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};
|
||||
|
||||
// EncryptBytes implements Filter interface.
|
||||
func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bd ,_cf :=_fg .NewCipher (okey );if _cf !=nil {return nil ,_cf ;};_fb .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf );_bd .XORKeyStream (buf ,buf );_fb .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};
|
||||
|
||||
// NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2).
|
||||
func NewFilterAESV2 ()Filter {_ef ,_ce :=_ec (FilterDict {});if _ce !=nil {_fb .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ce );return filterAESV2 {};};return _ef ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"};
|
||||
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 };
|
File diff suppressed because one or more lines are too long
2364
creator/creator.go
2364
creator/creator.go
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
34
fdf/fdf.go
34
fdf/fdf.go
File diff suppressed because one or more lines are too long
@ -10,28 +10,28 @@
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
// Package fjson provides support for loading PDF form field data from JSON data/files.
|
||||
package fjson ;import (_dd "encoding/json";_dc "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";_g "io";_dg "os";);
|
||||
|
||||
// FieldData represents form field data loaded from JSON file.
|
||||
type FieldData struct{_f []fieldValue };
|
||||
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 (_gfa FieldData )JSON ()(string ,error ){_dce ,_cab :=_dd .MarshalIndent (_gfa ._f ,"","\u0020\u0020\u0020\u0020");return string (_dce ),_cab ;};type fieldValue struct{Name string `json:"name"`;Value string `json:"value"`;
|
||||
func (_fd FieldData )JSON ()(string ,error ){_aaf ,_bdea :=_e .MarshalIndent (_fd ._ae ,"","\u0020\u0020\u0020\u0020");return string (_aaf ),_bdea ;};
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
||||
|
||||
// LoadFromPDF loads form field data from a PDF.
|
||||
func LoadFromPDF (rs _g .ReadSeeker )(*FieldData ,error ){_ga ,_ff :=_e .NewPdfReader (rs );if _ff !=nil {return nil ,_ff ;};if _ga .AcroForm ==nil {return nil ,nil ;};var _eg []fieldValue ;_ed :=_ga .AcroForm .AllFields ();for _ ,_ef :=range _ed {var _a []string ;_c :=make (map[string ]struct{});_bf ,_fc :=_ef .FullName ();if _fc !=nil {return nil ,_fc ;};if _fee ,_cb :=_ef .V .(*_dc .PdfObjectString );_cb {_eg =append (_eg ,fieldValue {Name :_bf ,Value :_fee .Decoded ()});continue ;};var _ae string ;for _ ,_ddc :=range _ef .Annotations {_ca ,_af :=_dc .GetName (_ddc .AS );if _af {_ae =_ca .String ();};_dge ,_cf :=_dc .GetDict (_ddc .AP );if !_cf {continue ;};_fcc ,_ :=_dc .GetDict (_dge .Get ("\u004e"));for _ ,_edb :=range _fcc .Keys (){_fef :=_edb .String ();if _ ,_bb :=_c [_fef ];!_bb {_a =append (_a ,_fef );_c [_fef ]=struct{}{};};};_db ,_ :=_dc .GetDict (_dge .Get ("\u0044"));for _ ,_ag :=range _db .Keys (){_fed :=_ag .String ();if _ ,_cd :=_c [_fed ];!_cd {_a =append (_a ,_fed );_c [_fed ]=struct{}{};};};};_cdd :=fieldValue {Name :_bf ,Value :_ae ,Options :_a };_eg =append (_eg ,_cdd );};_bba :=FieldData {_f :_eg };return &_bba ,nil ;};
|
||||
|
||||
// LoadFromPDFFile loads form field data from a PDF file.
|
||||
func LoadFromPDFFile (filePath string )(*FieldData ,error ){_efbe ,_fb :=_dg .Open (filePath );if _fb !=nil {return nil ,_fb ;};defer _efbe .Close ();return LoadFromPDF (_efbe );};
|
||||
|
||||
// LoadFromJSON loads JSON form data from `r`.
|
||||
func LoadFromJSON (r _g .Reader )(*FieldData ,error ){var _ge FieldData ;_fe :=_dd .NewDecoder (r ).Decode (&_ge ._f );if _fe !=nil {return nil ,_fe ;};return &_ge ,nil ;};
|
||||
|
||||
// FieldValues implements model.FieldValueProvider interface.
|
||||
func (_df *FieldData )FieldValues ()(map[string ]_dc .PdfObject ,error ){_fa :=make (map[string ]_dc .PdfObject );for _ ,_bbf :=range _df ._f {if len (_bbf .Value )> 0{_fa [_bbf .Name ]=_dc .MakeString (_bbf .Value );};};return _fa ,nil ;};
|
||||
// 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 ){_gd ,_b :=_dg .Open (filePath );if _b !=nil {return nil ,_b ;};defer _gd .Close ();return LoadFromJSON (_gd );};
|
||||
func LoadFromJSONFile (filePath string )(*FieldData ,error ){_c ,_gd :=_d .Open (filePath );if _gd !=nil {return nil ,_gd ;};defer _c .Close ();return LoadFromJSON (_c );};
|
||||
|
||||
// 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 );};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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"`;
|
||||
|
||||
// Options lists allowed values if present.
|
||||
Options []string `json:"options,omitempty"`;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package endian ;import (_e "encoding/binary";_g "unsafe";);var (ByteOrder _e .ByteOrder ;_d bool ;);func init (){const _c =int (_g .Sizeof (0));_gb :=1;_cc :=(*[_c ]byte )(_g .Pointer (&_gb ));if _cc [0]==0{_d =true ;ByteOrder =_e .BigEndian ;}else {ByteOrder =_e .LittleEndian ;};};func IsLittle ()bool {return !_d };func IsBig ()bool {return _d };
|
||||
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 ;);
|
File diff suppressed because one or more lines are too long
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package basic ;import _a "github.com/unidoc/unipdf/v3/internal/jbig2/errors";func (_cc *NumSlice )Add (v float32 ){*_cc =append (*_cc ,v )};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_aff NumSlice )GetIntSlice ()[]int {_fb :=make ([]int ,len (_aff ));for _fbc ,_cee :=range _aff {_fb [_fbc ]=int (_cee );};return _fb ;};func (_dgg *Stack )peek ()(interface{},bool ){_fad :=_dgg .top ();if _fad ==-1{return nil ,false ;};return _dgg .Data [_fad ],true ;};func (_c IntsMap )Add (key uint64 ,value int ){_c [key ]=append (_c [key ],value )};func (_da *Stack )Peek ()(_e interface{},_eb bool ){return _da .peek ()};func Max (x ,y int )int {if x > y {return x ;};return y ;};type IntsMap map[uint64 ][]int ;func NewIntSlice (i int )*IntSlice {_gg :=IntSlice (make ([]int ,i ));return &_gg };type NumSlice []float32 ;func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_f IntsMap )Get (key uint64 )(int ,bool ){_ag ,_ce :=_f [key ];if !_ce {return 0,false ;};if len (_ag )==0{return 0,false ;};return _ag [0],true ;};func (_gd IntSlice )Get (index int )(int ,error ){if index > len (_gd )-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 _gd [index ],nil ;};func (_fe IntSlice )Size ()int {return len (_fe )};func (_dg NumSlice )GetInt (i int )(int ,error ){const _bf ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_dg )-1{return 0,_a .Errorf (_bf ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i );};_af :=_dg [i ];return int (_af +Sign (_af )*0.5),nil ;};func (_gde *Stack )top ()int {return len (_gde .Data )-1};func (_b *IntSlice )Copy ()*IntSlice {_db :=IntSlice (make ([]int ,len (*_b )));copy (_db ,*_b );return &_db ;};func NewNumSlice (i int )*NumSlice {_be :=NumSlice (make ([]float32 ,i ));return &_be };func (_ac IntsMap )Delete (key uint64 ){delete (_ac ,key )};func Min (x ,y int )int {if x < y {return x ;};return y ;};func (_dd *Stack )Pop ()(_cf interface{},_fbd bool ){_cf ,_fbd =_dd .peek ();if !_fbd {return nil ,_fbd ;};_dd .Data =_dd .Data [:_dd .top ()];return _cf ,true ;};func (_gb *NumSlice )AddInt (v int ){*_gb =append (*_gb ,float32 (v ))};func (_fa IntsMap )GetSlice (key uint64 )([]int ,bool ){_d ,_dc :=_fa [key ];if !_dc {return nil ,false ;};return _d ,true ;};func (_gbg NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_gbg )-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 _gbg [i ],nil ;};func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_gf *Stack )Push (v interface{}){_gf .Data =append (_gf .Data ,v )};type Stack struct{Data []interface{};Aux *Stack ;};func (_fec *Stack )Len ()int {return len (_fec .Data )};type IntSlice []int ;func (_ab *IntSlice )Add (v int )error {if _ab ==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");};*_ab =append (*_ab ,v );return nil ;};
|
||||
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 )};
|
@ -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 tests ;
|
||||
package bench ;
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package decoder ;import (_ce "github.com/unidoc/unipdf/v3/internal/bitwise";_f "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_a "github.com/unidoc/unipdf/v3/internal/jbig2/document";_b "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_d "image";);type Parameters struct{UnpaddedData bool ;Color _f .Color ;};func (_fd *Decoder )DecodeNextPage ()([]byte ,error ){_fd ._bf ++;_gg :=_fd ._bf ;return _fd .decodePage (_gg );};type Decoder struct{_dd _ce .StreamReader ;_fa *_a .Document ;_bf int ;_cef Parameters ;};func (_fg *Decoder )decodePageImage (_eg int )(_d .Image ,error ){const _efe ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";if _eg < 0{return nil ,_b .Errorf (_efe ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_eg );};if _eg > int (_fg ._fa .NumberOfPages ){return nil ,_b .Errorf (_efe ,"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 );};_ec ,_ac :=_fg ._fa .GetPage (_eg );if _ac !=nil {return nil ,_b .Wrap (_ac ,_efe ,"");};_egc ,_ac :=_ec .GetBitmap ();if _ac !=nil {return nil ,_b .Wrap (_ac ,_efe ,"");};return _egc .ToImage (),nil ;};func Decode (input []byte ,parameters Parameters ,globals *_a .Globals )(*Decoder ,error ){_ae :=_ce .NewReader (input );_bfc ,_bfa :=_a .DecodeDocument (_ae ,globals );if _bfa !=nil {return nil ,_bfa ;};return &Decoder {_dd :_ae ,_fa :_bfc ,_cef :parameters },nil ;};func (_g *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _g .decodePage (pageNumber )};func (_e *Decoder )PageNumber ()(int ,error ){const _aa ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072";if _e ._fa ==nil {return 0,_b .Error (_aa ,"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 (_e ._fa .NumberOfPages ),nil ;};func (_ef *Decoder )decodePage (_df int )([]byte ,error ){const _bfe ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _df < 0{return nil ,_b .Errorf (_bfe ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_df );};if _df > int (_ef ._fa .NumberOfPages ){return nil ,_b .Errorf (_bfe ,"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",_df );};_aab ,_faa :=_ef ._fa .GetPage (_df );if _faa !=nil {return nil ,_b .Wrap (_faa ,_bfe ,"");};_aae ,_faa :=_aab .GetBitmap ();if _faa !=nil {return nil ,_b .Wrap (_faa ,_bfe ,"");};_aae .InverseData ();if !_ef ._cef .UnpaddedData {return _aae .Data ,nil ;};return _aae .GetUnpaddedData ();};func (_cf *Decoder )DecodePageImage (pageNumber int )(_d .Image ,error ){const _be ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065";_ad ,_fe :=_cf .decodePageImage (pageNumber );if _fe !=nil {return nil ,_b .Wrap (_fe ,_be ,"");};return _ad ,nil ;};
|
||||
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 ;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package errors ;import (_c "fmt";_cd "golang.org/x/xerrors";);func Error (processName ,message string )error {return _g (message ,processName )};func (_cfe *processError )Unwrap ()error {return _cfe ._d };func Errorf (processName ,message string ,arguments ...interface{})error {return _g (_c .Sprintf (message ,arguments ...),processName );};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _gd ,_b :=err .(*processError );_b {_gd ._ab ="";};_ef :=_g (_c .Sprintf (message ,arguments ...),processName );_ef ._d =err ;return _ef ;};func (_db *processError )Error ()string {var _abc string ;if _db ._ab !=""{_abc =_db ._ab ;};_abc +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_db ._cf ;if _db ._cb !=""{_abc +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_db ._cb ;};if _db ._d !=nil {_abc +="\u002e\u0020"+_db ._d .Error ();};return _abc ;};type processError struct{_ab string ;_cf string ;_cb string ;_d error ;};func Wrap (err error ,processName ,message string )error {if _e ,_aa :=err .(*processError );_aa {_e ._ab ="";};_ee :=_g (message ,processName );_ee ._d =err ;return _ee ;};var _ _cd .Wrapper =(*processError )(nil );func _g (_ac ,_abb string )*processError {return &processError {_ab :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_cb :_ac ,_cf :_abb };};
|
||||
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 };};
|
@ -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 _dc "errors";var ErrOOB =_dc .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064");
|
||||
package internal ;import _b "errors";var ErrOOB =_b .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064");
|
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package jbig2 ;import (_fa "github.com/unidoc/unipdf/v3/internal/bitwise";_d "github.com/unidoc/unipdf/v3/internal/jbig2/decoder";_dd "github.com/unidoc/unipdf/v3/internal/jbig2/document";_fe "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_ad "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_a "sort";);func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _e Globals ;if len (globals )> 0{_e =globals [0];};_g ,_eg :=_d .Decode (encoded ,parameters ,_e .ToDocumentGlobals ());if _eg !=nil {return nil ,_eg ;};return _g .DecodeNextPage ();};func (_feb Globals )ToDocumentGlobals ()*_dd .Globals {if _feb ==nil {return nil ;};_ee :=[]*_fe .Header {};for _ ,_dec :=range _feb {_ee =append (_ee ,_dec );};_a .Slice (_ee ,func (_bf ,_dc int )bool {return _ee [_bf ].SegmentNumber < _ee [_dc ].SegmentNumber });return &_dd .Globals {Segments :_ee };};type Globals map[int ]*_fe .Header ;func DecodeGlobals (encoded []byte )(Globals ,error ){const _ega ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_ge :=_fa .NewReader (encoded );_ga ,_adg :=_dd .DecodeDocument (_ge ,nil );if _adg !=nil {return nil ,_ad .Wrap (_adg ,_ega ,"");};if _ga .GlobalSegments ==nil ||(_ga .GlobalSegments .Segments ==nil ){return nil ,_ad .Error (_ega ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064");};_de :=Globals {};for _ ,_aa :=range _ga .GlobalSegments .Segments {_de [int (_aa .SegmentNumber )]=_aa ;};return _de ,nil ;};
|
||||
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 ;};
|
File diff suppressed because one or more lines are too long
@ -9,4 +9,4 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package sampling ;import (_d "github.com/unidoc/unipdf/v3/internal/bitwise";_a "github.com/unidoc/unipdf/v3/internal/imageutil";_fd "io";);func NewWriter (img _a .ImageBase )*Writer {return &Writer {_ad :_d .NewWriterMSB (img .Data ),_cf :img ,_ee :img .ColorComponents ,_dcf :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func (_db *Reader )ReadSamples (samples []uint32 )(_gd error ){for _cb :=0;_cb < len (samples );_cb ++{samples [_cb ],_gd =_db .ReadSample ();if _gd !=nil {return _gd ;};};return nil ;};func (_c *Reader )ReadSample ()(uint32 ,error ){if _c ._af ==_c ._e .Height {return 0,_fd .EOF ;};_ea ,_eb :=_c ._g .ReadBits (byte (_c ._e .BitsPerComponent ));if _eb !=nil {return 0,_eb ;};_c ._dg --;if _c ._dg ==0{_c ._dg =_c ._e .ColorComponents ;_c ._b ++;};if _c ._b ==_c ._e .Width {if _c ._dc {_c ._g .ConsumeRemainingBits ();};_c ._b =0;_c ._af ++;};return uint32 (_ea ),nil ;};func (_cca *Writer )WriteSamples (samples []uint32 )error {for _cd :=0;_cd < len (samples );_cd ++{if _fab :=_cca .WriteSample (samples [_cd ]);_fab !=nil {return _fab ;};};return nil ;};type SampleReader interface{ReadSample ()(uint32 ,error );ReadSamples (_ff []uint32 )error ;};type Writer struct{_cf _a .ImageBase ;_ad *_d .Writer ;_gde ,_ee int ;_dcf bool ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _fba []uint32 ;_dfe :=bitsPerOutputSample ;var _aba uint32 ;var _abg uint32 ;_bc :=0;_bg :=0;_gb :=0;for _gb < len (data ){if _bc > 0{_ac :=_bc ;if _dfe < _ac {_ac =_dfe ;};_aba =(_aba <<uint (_ac ))|(_abg >>uint (bitsPerInputSample -_ac ));_bc -=_ac ;if _bc > 0{_abg =_abg <<uint (_ac );}else {_abg =0;};_dfe -=_ac ;if _dfe ==0{_fba =append (_fba ,_aba );_dfe =bitsPerOutputSample ;_aba =0;_bg ++;};}else {_ge :=data [_gb ];_gb ++;_gdd :=bitsPerInputSample ;if _dfe < _gdd {_gdd =_dfe ;};_bc =bitsPerInputSample -_gdd ;_aba =(_aba <<uint (_gdd ))|(_ge >>uint (_bc ));if _gdd < bitsPerInputSample {_abg =_ge <<uint (_gdd );};_dfe -=_gdd ;if _dfe ==0{_fba =append (_fba ,_aba );_dfe =bitsPerOutputSample ;_aba =0;_bg ++;};};};for _bc >=bitsPerOutputSample {_bd :=_bc ;if _dfe < _bd {_bd =_dfe ;};_aba =(_aba <<uint (_bd ))|(_abg >>uint (bitsPerInputSample -_bd ));_bc -=_bd ;if _bc > 0{_abg =_abg <<uint (_bd );}else {_abg =0;};_dfe -=_bd ;if _dfe ==0{_fba =append (_fba ,_aba );_dfe =bitsPerOutputSample ;_aba =0;_bg ++;};};if _dfe > 0&&_dfe < bitsPerOutputSample {_aba <<=uint (_dfe );_fba =append (_fba ,_aba );};return _fba ;};func NewReader (img _a .ImageBase )*Reader {return &Reader {_g :_d .NewReader (img .Data ),_e :img ,_dg :img .ColorComponents ,_dc :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _ab []uint32 ;_df :=bitsPerSample ;var _fe uint32 ;var _fb byte ;_fbd :=0;_ba :=0;_eag :=0;for _eag < len (data ){if _fbd > 0{_eg :=_fbd ;if _df < _eg {_eg =_df ;};_fe =(_fe <<uint (_eg ))|uint32 (_fb >>uint (8-_eg ));_fbd -=_eg ;if _fbd > 0{_fb =_fb <<uint (_eg );}else {_fb =0;};_df -=_eg ;if _df ==0{_ab =append (_ab ,_fe );_df =bitsPerSample ;_fe =0;_ba ++;};}else {_ffd :=data [_eag ];_eag ++;_feb :=8;if _df < _feb {_feb =_df ;};_fbd =8-_feb ;_fe =(_fe <<uint (_feb ))|uint32 (_ffd >>uint (_fbd ));if _feb < 8{_fb =_ffd <<uint (_feb );};_df -=_feb ;if _df ==0{_ab =append (_ab ,_fe );_df =bitsPerSample ;_fe =0;_ba ++;};};};for _fbd >=bitsPerSample {_fa :=_fbd ;if _df < _fa {_fa =_df ;};_fe =(_fe <<uint (_fa ))|uint32 (_fb >>uint (8-_fa ));_fbd -=_fa ;if _fbd > 0{_fb =_fb <<uint (_fa );}else {_fb =0;};_df -=_fa ;if _df ==0{_ab =append (_ab ,_fe );_df =bitsPerSample ;_fe =0;_ba ++;};};return _ab ;};type Reader struct{_e _a .ImageBase ;_g *_d .Reader ;_b ,_af ,_dg int ;_dc bool ;};type SampleWriter interface{WriteSample (_ga uint32 )error ;WriteSamples (_cc []uint32 )error ;};func (_ged *Writer )WriteSample (sample uint32 )error {if _ ,_cff :=_ged ._ad .WriteBits (uint64 (sample ),_ged ._cf .BitsPerComponent );_cff !=nil {return _cff ;};_ged ._ee --;if _ged ._ee ==0{_ged ._ee =_ged ._cf .ColorComponents ;_ged ._gde ++;};if _ged ._gde ==_ged ._cf .Width {if _ged ._dcf {_ged ._ad .FinishByte ();};_ged ._gde =0;};return nil ;};
|
||||
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 ;};
|
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
4951
model/model.go
4951
model/model.go
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -10,24 +10,82 @@
|
||||
// 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 (_ga "bytes";_e "crypto";_ba "crypto/rand";_ge "crypto/rsa";_ce "crypto/x509";_c "crypto/x509/pkix";_dd "encoding/asn1";_bc "errors";_b "fmt";_cg "github.com/unidoc/pkcs7";_fd "github.com/unidoc/timestamp";_gf "github.com/unidoc/unipdf/v3/core";_da "github.com/unidoc/unipdf/v3/model";_cee "github.com/unidoc/unipdf/v3/model/sigutil";_f "hash";_d "time";);func _gfge (_dcc _ce .SignatureAlgorithm )(_e .Hash ,bool ){var _aff _e .Hash ;switch _dcc {case _ce .SHA1WithRSA :_aff =_e .SHA1 ;case _ce .SHA256WithRSA :_aff =_e .SHA256 ;case _ce .SHA384WithRSA :_aff =_e .SHA384 ;case _ce .SHA512WithRSA :_aff =_e .SHA512 ;default:return _e .SHA1 ,false ;};return _aff ,true ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_beb *adobeX509RSASHA1 )IsApplicable (sig *_da .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";};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_bca *adobeX509RSASHA1 )InitSignature (sig *_da .PdfSignature )error {if _bca ._bcg ==nil {return _bc .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 _bca ._baa ==nil &&_bca ._aeb ==nil {return _bc .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");};_geg :=*_bca ;sig .Handler =&_geg ;sig .Filter =_gf .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_gf .MakeName ("\u0061d\u0062e\u002e\u0078\u0035\u0030\u0039.\u0072\u0073a\u005f\u0073\u0068\u0061\u0031");sig .Cert =_gf .MakeString (string (_geg ._bcg .Raw ));sig .Reference =nil ;_af ,_cce :=_geg .NewDigest (sig );if _cce !=nil {return _cce ;};_af .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 _geg .sign (sig ,_af ,_bca ._eb );};func (_gge *adobeX509RSASHA1 )getCertificate (_gd *_da .PdfSignature )(*_ce .Certificate ,error ){if _gge ._bcg !=nil {return _gge ._bcg ,nil ;};_aeg ,_cd :=_gd .GetCerts ();if _cd !=nil {return nil ,_cd ;};return _aeg [0],nil ;};func (_dad *docTimeStamp )getCertificate (_cgc *_da .PdfSignature )(*_ce .Certificate ,error ){_fbg ,_fdd :=_cgc .GetCerts ();if _fdd !=nil {return nil ,_fdd ;};return _fbg [0],nil ;};type adobeX509RSASHA1 struct{_baa *_ge .PrivateKey ;_bcg *_ce .Certificate ;_aeb SignFunc ;_eb bool ;};
|
||||
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";);
|
||||
|
||||
// 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 )(_da .SignatureHandler ,error ){return &adobePKCS7Detached {_bac :true ,_ddg :signatureLen },nil ;};
|
||||
func NewEmptyAdobePKCS7Detached (signatureLen int )(_fe .SignatureHandler ,error ){return &adobePKCS7Detached {_fea :true ,_db :signatureLen },nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_ac *adobeX509RSASHA1 )Validate (sig *_da .PdfSignature ,digest _da .Hasher )(_da .SignatureValidationResult ,error ){_cbf ,_fb :=_ac .getCertificate (sig );if _fb !=nil {return _da .SignatureValidationResult {},_fb ;};_ebb :=sig .Contents .Bytes ();var _ccd []byte ;if _ ,_bg :=_dd .Unmarshal (_ebb ,&_ccd );_bg !=nil {return _da .SignatureValidationResult {},_bg ;};_ec ,_aege :=digest .(_f .Hash );if !_aege {return _da .SignatureValidationResult {},_bc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ecg ,_ :=_gfge (_cbf .SignatureAlgorithm );if _fgc :=_ge .VerifyPKCS1v15 (_cbf .PublicKey .(*_ge .PublicKey ),_ecg ,_ec .Sum (nil ),_ccd );_fgc !=nil {return _da .SignatureValidationResult {},_fgc ;};return _da .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};type adobePKCS7Detached struct{_ea *_ge .PrivateKey ;_fc *_ce .Certificate ;_bac bool ;_ddg int ;};
|
||||
// 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 (_bdb *docTimeStamp )Sign (sig *_da .PdfSignature ,digest _da .Hasher )error {_beff ,_ffff :=_cee .NewTimestampRequest (digest .(*_ga .Buffer ),&_fd .RequestOptions {Hash :_bdb ._gb ,Certificates :true });if _ffff !=nil {return _ffff ;};_bafb :=_cee .NewTimestampClient ();_fddc ,_ffff :=_bafb .GetEncodedToken (_bdb ._fbc ,_beff );if _ffff !=nil {return _ffff ;};_de :=len (_fddc );if _bdb ._aad > 0&&_de > _bdb ._aad {return _da .ErrSignNotEnoughSpace ;};if _de > 0{_bdb ._aad =_de +128;};sig .Contents =_gf .MakeHexString (string (_fddc ));return nil ;};
|
||||
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 ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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 _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 ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// 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 ;};
|
||||
|
||||
// AdobeX509RSASHA1Opts defines options for configuring the adbe.x509.rsa_sha1
|
||||
// signature handler.
|
||||
@ -39,47 +97,18 @@ type AdobeX509RSASHA1Opts struct{
|
||||
// call is made in order to estimate the size of the signature contents.
|
||||
EstimateSize bool ;};
|
||||
|
||||
// NewDocTimeStampWithOpts returns a new DocTimeStamp configured using the
|
||||
// specified options. If no options are provided, default options will be used.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
// signature validation.
|
||||
// The following hash algorithms are supported:
|
||||
// crypto.SHA1, crypto.SHA256, crypto.SHA384, crypto.SHA512.
|
||||
func NewDocTimeStampWithOpts (timestampServerURL string ,hashAlgorithm _e .Hash ,opts *DocTimeStampOpts )(_da .SignatureHandler ,error ){if opts ==nil {opts =&DocTimeStampOpts {};};if opts .SignatureSize <=0{opts .SignatureSize =4192;};return &docTimeStamp {_fbc :timestampServerURL ,_gb :hashAlgorithm ,_aad :opts .SignatureSize },nil ;};
|
||||
// DocTimeStampOpts defines options for configuring the timestamp handler.
|
||||
type DocTimeStampOpts struct{
|
||||
|
||||
// SignatureSize is the estimated size of the signature contents in bytes.
|
||||
// If not provided, a default signature size of 4192 is used.
|
||||
// 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 ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_ab *adobePKCS7Detached )NewDigest (sig *_da .PdfSignature )(_da .Hasher ,error ){return _ga .NewBuffer (nil ),nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_gg *adobePKCS7Detached )Validate (sig *_da .PdfSignature ,digest _da .Hasher )(_da .SignatureValidationResult ,error ){_dc :=sig .Contents .Bytes ();_bb ,_bf :=_cg .Parse (_dc );if _bf !=nil {return _da .SignatureValidationResult {},_bf ;};_ag :=digest .(*_ga .Buffer );_bb .Content =_ag .Bytes ();if _bf =_bb .Verify ();_bf !=nil {return _da .SignatureValidationResult {},_bf ;};return _da .SignatureValidationResult {IsSigned :true ,IsVerified :true },nil ;};
|
||||
|
||||
// Sign sets the Contents fields.
|
||||
func (_fab *adobePKCS7Detached )Sign (sig *_da .PdfSignature ,digest _da .Hasher )error {if _fab ._bac {_aa :=_fab ._ddg ;if _aa <=0{_aa =8192;};sig .Contents =_gf .MakeHexString (string (make ([]byte ,_aa )));return nil ;};_aag :=digest .(*_ga .Buffer );_be ,_gfg :=_cg .NewSignedData (_aag .Bytes ());if _gfg !=nil {return _gfg ;};if _ddd :=_be .AddSigner (_fab ._fc ,_fab ._ea ,_cg .SignerInfoConfig {});_ddd !=nil {return _ddd ;};_be .Detach ();_dcd ,_gfg :=_be .Finish ();if _gfg !=nil {return _gfg ;};_ae :=make ([]byte ,8192);copy (_ae ,_dcd );sig .Contents =_gf .MakeHexString (string (_ae ));return nil ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_bde *docTimeStamp )NewDigest (sig *_da .PdfSignature )(_da .Hasher ,error ){return _ga .NewBuffer (nil ),nil ;};type timestampInfo struct{Version int ;Policy _dd .RawValue ;MessageImprint struct{HashAlgorithm _c .AlgorithmIdentifier ;HashedMessage []byte ;};SerialNumber _dd .RawValue ;GeneralizedTime _d .Time ;};
|
||||
|
||||
// NewDigest creates a new digest.
|
||||
func (_bbb *adobeX509RSASHA1 )NewDigest (sig *_da .PdfSignature )(_da .Hasher ,error ){_ff ,_ef :=_bbb .getCertificate (sig );if _ef !=nil {return nil ,_ef ;};_bd ,_ :=_gfge (_ff .SignatureAlgorithm );return _bd .New (),nil ;};
|
||||
|
||||
// NewAdobePKCS7Detached creates a new Adobe.PPKMS/Adobe.PPKLite adbe.pkcs7.detached signature handler.
|
||||
// Both parameters may be nil for the signature validation.
|
||||
func NewAdobePKCS7Detached (privateKey *_ge .PrivateKey ,certificate *_ce .Certificate )(_da .SignatureHandler ,error ){return &adobePKCS7Detached {_fc :certificate ,_ea :privateKey },nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_fa *adobePKCS7Detached )InitSignature (sig *_da .PdfSignature )error {if !_fa ._bac {if _fa ._fc ==nil {return _bc .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 _fa ._ea ==nil {return _bc .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");};};_ca :=*_fa ;sig .Handler =&_ca ;sig .Filter =_gf .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_gf .MakeName ("\u0061\u0064\u0062\u0065.p\u006b\u0063\u0073\u0037\u002e\u0064\u0065\u0074\u0061\u0063\u0068\u0065\u0064");sig .Reference =nil ;_gfd ,_cc :=_ca .NewDigest (sig );if _cc !=nil {return _cc ;};_gfd .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 _ca .Sign (sig ,_gfd );};
|
||||
|
||||
// SignFunc represents a custom signing function. The function should return
|
||||
// the computed signature.
|
||||
type SignFunc func (_cb *_da .PdfSignature ,_ddc _da .Hasher )([]byte ,error );
|
||||
|
||||
// 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 *_ce .Certificate ,signFunc SignFunc )(_da .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bcg :certificate ,_aeb :signFunc },nil ;};
|
||||
func (_ged *adobePKCS7Detached )NewDigest (sig *_fe .PdfSignature )(_fe .Hasher ,error ){return _g .NewBuffer (nil ),nil ;};
|
||||
|
||||
// NewDocTimeStamp creates a new DocTimeStamp signature handler.
|
||||
// Both the timestamp server URL and the hash algorithm can be empty for the
|
||||
@ -89,41 +118,12 @@ func NewAdobeX509RSASHA1Custom (certificate *_ce .Certificate ,signFunc SignFunc
|
||||
// NOTE: the handler will do a mock Sign when initializing the signature
|
||||
// in order to estimate the signature size. Use NewDocTimeStampWithOpts
|
||||
// for providing the signature size.
|
||||
func NewDocTimeStamp (timestampServerURL string ,hashAlgorithm _e .Hash )(_da .SignatureHandler ,error ){return &docTimeStamp {_fbc :timestampServerURL ,_gb :hashAlgorithm },nil ;};
|
||||
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 ;};
|
||||
|
||||
// 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 *_ge .PrivateKey ,certificate *_ce .Certificate )(_da .SignatureHandler ,error ){return &adobeX509RSASHA1 {_bcg :certificate ,_baa :privateKey },nil ;};func _df (_fee _dd .ObjectIdentifier )(_e .Hash ,error ){switch {case _fee .Equal (_cg .OIDDigestAlgorithmSHA1 ),_fee .Equal (_cg .OIDDigestAlgorithmECDSASHA1 ),_fee .Equal (_cg .OIDDigestAlgorithmDSA ),_fee .Equal (_cg .OIDDigestAlgorithmDSASHA1 ),_fee .Equal (_cg .OIDEncryptionAlgorithmRSA ):return _e .SHA1 ,nil ;case _fee .Equal (_cg .OIDDigestAlgorithmSHA256 ),_fee .Equal (_cg .OIDDigestAlgorithmECDSASHA256 ):return _e .SHA256 ,nil ;case _fee .Equal (_cg .OIDDigestAlgorithmSHA384 ),_fee .Equal (_cg .OIDDigestAlgorithmECDSASHA384 ):return _e .SHA384 ,nil ;case _fee .Equal (_cg .OIDDigestAlgorithmSHA512 ),_fee .Equal (_cg .OIDDigestAlgorithmECDSASHA512 ):return _e .SHA512 ,nil ;};return _e .Hash (0),_cg .ErrUnsupportedAlgorithm ;};
|
||||
func NewAdobeX509RSASHA1 (privateKey *_df .PrivateKey ,certificate *_cc .Certificate )(_fe .SignatureHandler ,error ){return &adobeX509RSASHA1 {_aba :certificate ,_aa :privateKey },nil ;};
|
||||
|
||||
// Sign sets the Contents fields for the PdfSignature.
|
||||
func (_ggc *adobeX509RSASHA1 )Sign (sig *_da .PdfSignature ,digest _da .Hasher )error {var _baf []byte ;var _fea error ;if _ggc ._aeb !=nil {_baf ,_fea =_ggc ._aeb (sig ,digest );if _fea !=nil {return _fea ;};}else {_cge ,_dg :=digest .(_f .Hash );if !_dg {return _bc .New ("\u0068a\u0073h\u0020\u0074\u0079\u0070\u0065\u0020\u0065\u0072\u0072\u006f\u0072");};_ecb ,_ :=_gfge (_ggc ._bcg .SignatureAlgorithm );_baf ,_fea =_ge .SignPKCS1v15 (_ba .Reader ,_ggc ._baa ,_ecb ,_cge .Sum (nil ));if _fea !=nil {return _fea ;};};_baf ,_fea =_dd .Marshal (_baf );if _fea !=nil {return _fea ;};sig .Contents =_gf .MakeHexString (string (_baf ));return nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature.
|
||||
func (_ed *docTimeStamp )IsApplicable (sig *_da .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";};
|
||||
|
||||
// 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 *_ce .Certificate ,signFunc SignFunc ,opts *AdobeX509RSASHA1Opts )(_da .SignatureHandler ,error ){if opts ==nil {opts =&AdobeX509RSASHA1Opts {};};return &adobeX509RSASHA1 {_bcg :certificate ,_aeb :signFunc ,_eb :opts .EstimateSize },nil ;};type docTimeStamp struct{_fbc string ;_gb _e .Hash ;_aad int ;};
|
||||
|
||||
// DocTimeStampOpts defines options for configuring the timestamp handler.
|
||||
type DocTimeStampOpts struct{
|
||||
|
||||
// SignatureSize is the estimated size of the signature contents in bytes.
|
||||
// If not provided, a default signature size of 4192 is used.
|
||||
// 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 (_fe *adobePKCS7Detached )getCertificate (_a *_da .PdfSignature )(*_ce .Certificate ,error ){if _fe ._fc !=nil {return _fe ._fc ,nil ;};_bab ,_fg :=_a .GetCerts ();if _fg !=nil {return nil ,_fg ;};return _bab [0],nil ;};
|
||||
|
||||
// Validate validates PdfSignature.
|
||||
func (_cdd *docTimeStamp )Validate (sig *_da .PdfSignature ,digest _da .Hasher )(_da .SignatureValidationResult ,error ){_bcd :=sig .Contents .Bytes ();_fce ,_fag :=_cg .Parse (_bcd );if _fag !=nil {return _da .SignatureValidationResult {},_fag ;};if _fag =_fce .Verify ();_fag !=nil {return _da .SignatureValidationResult {},_fag ;};var _fff timestampInfo ;_ ,_fag =_dd .Unmarshal (_fce .Content ,&_fff );if _fag !=nil {return _da .SignatureValidationResult {},_fag ;};_aee ,_fag :=_df (_fff .MessageImprint .HashAlgorithm .Algorithm );if _fag !=nil {return _da .SignatureValidationResult {},_fag ;};_fffd :=_aee .New ();_ggf :=digest .(*_ga .Buffer );_fffd .Write (_ggf .Bytes ());_gegd :=_fffd .Sum (nil );_bdd :=_da .SignatureValidationResult {IsSigned :true ,IsVerified :_ga .Equal (_gegd ,_fff .MessageImprint .HashedMessage ),GeneralizedTime :_fff .GeneralizedTime };return _bdd ,nil ;};
|
||||
|
||||
// InitSignature initialises the PdfSignature.
|
||||
func (_fcb *docTimeStamp )InitSignature (sig *_da .PdfSignature )error {_gdc :=*_fcb ;sig .Handler =&_gdc ;sig .Filter =_gf .MakeName ("\u0041\u0064\u006f\u0062\u0065\u002e\u0050\u0050\u004b\u004c\u0069\u0074\u0065");sig .SubFilter =_gf .MakeName ("\u0045\u0054\u0053I\u002e\u0052\u0046\u0043\u0033\u0031\u0036\u0031");sig .Reference =nil ;if _fcb ._aad > 0{sig .Contents =_gf .MakeHexString (string (make ([]byte ,_fcb ._aad )));}else {_afad ,_gc :=_fcb .NewDigest (sig );if _gc !=nil {return _gc ;};_afad .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 _gc =_gdc .Sign (sig ,_afad );_gc !=nil {return _gc ;};_fcb ._aad =_gdc ._aad ;};return nil ;};
|
||||
|
||||
// IsApplicable returns true if the signature handler is applicable for the PdfSignature
|
||||
func (_bef *adobePKCS7Detached )IsApplicable (sig *_da .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 (_ccb *adobeX509RSASHA1 )sign (_ccg *_da .PdfSignature ,_bfg _da .Hasher ,_afe bool )error {if !_afe {return _ccb .Sign (_ccg ,_bfg );};_ead ,_eg :=_ccb ._bcg .PublicKey .(*_ge .PublicKey );if !_eg {return _b .Errorf ("i\u006e\u0076\u0061\u006c\u0069\u0064 \u0070\u0075\u0062\u006c\u0069\u0063\u0020\u006b\u0065y\u0020\u0074\u0079p\u0065:\u0020\u0025\u0054",_ead );};_db ,_bgc :=_dd .Marshal (make ([]byte ,_ead .Size ()));if _bgc !=nil {return _bgc ;};_ccg .Contents =_gf .MakeHexString (string (_db ));return 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 ;};
|
@ -9,39 +9,22 @@
|
||||
// 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 (_c "bytes";_e "crypto";_ag "crypto/x509";_g "encoding/asn1";_ee "encoding/pem";_eg "errors";_b "fmt";_aee "github.com/unidoc/timestamp";_aa "github.com/unidoc/unipdf/v3/common";_cg "golang.org/x/crypto/ocsp";_ae "io";_egc "io/ioutil";_cd "net/http";_f "time";);
|
||||
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";);
|
||||
|
||||
// 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 (_db *CRLClient )MakeRequest (serverURL string ,cert *_ag .Certificate )([]byte ,error ){if _db .HTTPClient ==nil {_db .HTTPClient =_cdc ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_eg .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];};_fb ,_dg :=_db .HTTPClient .Get (serverURL );if _dg !=nil {return nil ,_dg ;};defer _fb .Body .Close ();_gga ,_dg :=_egc .ReadAll (_fb .Body );if _dg !=nil {return nil ,_dg ;};if _agc ,_ :=_ee .Decode (_gga );_agc !=nil {_gga =_agc .Bytes ;};return _gga ,nil ;};
|
||||
|
||||
// NewTimestampRequest returns a new timestamp request based
|
||||
// on the specified options.
|
||||
func NewTimestampRequest (body _ae .Reader ,opts *_aee .RequestOptions )(*_aee .Request ,error ){if opts ==nil {opts =&_aee .RequestOptions {};};if opts .Hash ==0{opts .Hash =_e .SHA256 ;};if !opts .Hash .Available (){return nil ,_ag .ErrUnsupportedAlgorithm ;};_fc :=opts .Hash .New ();if _ ,_fcf :=_ae .Copy (_fc ,body );_fcf !=nil {return nil ,_fcf ;};return &_aee .Request {HashAlgorithm :opts .Hash ,HashedMessage :_fc .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ;};
|
||||
|
||||
// CertClient represents a X.509 certificate client. Its primary purpose
|
||||
// is to download certificates.
|
||||
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 *_cd .Client ;};
|
||||
|
||||
// Get retrieves the certificate at the specified URL.
|
||||
func (_gg *CertClient )Get (url string )(*_ag .Certificate ,error ){if _gg .HTTPClient ==nil {_gg .HTTPClient =_cdc ();};_ad ,_af :=_gg .HTTPClient .Get (url );if _af !=nil {return nil ,_af ;};defer _ad .Body .Close ();_ff ,_af :=_egc .ReadAll (_ad .Body );if _af !=nil {return nil ,_af ;};if _cf ,_ :=_ee .Decode (_ff );_cf !=nil {_ff =_cf .Bytes ;};_cga ,_af :=_ag .ParseCertificate (_ff );if _af !=nil {return nil ,_af ;};return _cga ,nil ;};
|
||||
// NewCertClient returns a new certificate client.
|
||||
func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_ee ()}};
|
||||
|
||||
// GetEncodedToken executes the timestamp request and returns the DER encoded
|
||||
// timestamp token bytes.
|
||||
func (_aaae *TimestampClient )GetEncodedToken (serverURL string ,req *_aee .Request )([]byte ,error ){if serverURL ==""{return nil ,_b .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 ,_b .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");};_cc ,_bg :=req .Marshal ();if _bg !=nil {return nil ,_bg ;};_fed :=_aaae .HTTPClient ;if _fed ==nil {_fed =_cdc ();};_dc ,_bg :=_fed .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 (_cc ));if _bg !=nil {return nil ,_bg ;};defer _dc .Body .Close ();_ef ,_bg :=_egc .ReadAll (_dc .Body );if _bg !=nil {return nil ,_bg ;};if _dc .StatusCode !=_cd .StatusOK {return nil ,_b .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",_dc .StatusCode );};var _abf struct{Version _g .RawValue ;Content _g .RawValue ;};if _ ,_bg =_g .Unmarshal (_ef ,&_abf );_bg !=nil {return nil ,_bg ;};return _abf .Content .FullBytes ,nil ;};
|
||||
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 ;};
|
||||
|
||||
// NewOCSPClient returns a new OCSP client.
|
||||
func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_cdc (),Hash :_e .SHA1 }};
|
||||
// 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 ;};
|
||||
|
||||
// NewCertClient returns a new certificate client.
|
||||
func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_cdc ()}};
|
||||
|
||||
// NewCRLClient returns a new CRL client.
|
||||
func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_cdc ()}};
|
||||
// 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.
|
||||
@ -49,18 +32,7 @@ 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 *_cd .Client ;};
|
||||
|
||||
// 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 (_dba *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_ag .Certificate )(*_cg .Response ,[]byte ,error ){if _dba .HTTPClient ==nil {_dba .HTTPClient =_cdc ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_eg .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];};_bcb ,_fge :=_cg .CreateRequest (cert ,issuer ,&_cg .RequestOptions {Hash :_dba .Hash });if _fge !=nil {return nil ,nil ,_fge ;};_ab ,_fge :=_dba .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 (_bcb ));if _fge !=nil {return nil ,nil ,_fge ;};defer _ab .Body .Close ();_aaa ,_fge :=_egc .ReadAll (_ab .Body );if _fge !=nil {return nil ,nil ,_fge ;};if _da ,_ :=_ee .Decode (_aaa );_da !=nil {_aaa =_da .Bytes ;};_ca ,_fge :=_cg .ParseResponseForCert (_aaa ,cert ,issuer );if _fge !=nil {return nil ,nil ,_fge ;};return _ca ,_aaa ,nil ;};
|
||||
|
||||
// NewTimestampClient returns a new timestamp client.
|
||||
func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_cdc ()}};
|
||||
|
||||
// IsCA returns true if the provided certificate appears to be a CA certificate.
|
||||
func (_ed *CertClient )IsCA (cert *_ag .Certificate )bool {return cert .IsCA &&_c .Equal (cert .RawIssuer ,cert .RawSubject );};func _cdc ()*_cd .Client {return &_cd .Client {Timeout :5*_f .Second }};
|
||||
HTTPClient *_d .Client ;};
|
||||
|
||||
// OCSPClient represents a OCSP (Online Certificate Status Protocol) client.
|
||||
// It is used to request revocation data from OCSP servers.
|
||||
@ -68,11 +40,42 @@ 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 *_cd .Client ;
|
||||
HTTPClient *_d .Client ;
|
||||
|
||||
// Hash is the hash function used when constructing the OCSP
|
||||
// requests. If zero, SHA-1 will be used.
|
||||
Hash _e .Hash ;};
|
||||
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 );};
|
||||
|
||||
// CertClient represents a X.509 certificate client. Its primary purpose
|
||||
// is to download certificates.
|
||||
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 }};
|
||||
|
||||
// CRLClient represents a CRL (Certificate revocation list) client.
|
||||
// It is used to request revocation data from CRL servers.
|
||||
@ -80,7 +83,4 @@ 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 *_cd .Client ;};
|
||||
|
||||
// GetIssuer retrieves the issuer of the provided certificate.
|
||||
func (_bf *CertClient )GetIssuer (cert *_ag .Certificate )(*_ag .Certificate ,error ){for _ ,_bc :=range cert .IssuingCertificateURL {_d ,_fg :=_bf .Get (_bc );if _fg !=nil {_aa .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 ,_fg );continue ;};return _d ,nil ;};return nil ,_b .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");};
|
||||
HTTPClient *_d .Client ;};
|
@ -9,7 +9,7 @@
|
||||
// Use of this source code is governed by the UniDoc End User License Agreement
|
||||
// terms that can be accessed at https://unidoc.io/eula/
|
||||
|
||||
package pdfutil ;import (_a "github.com/unidoc/unipdf/v3/common";_d "github.com/unidoc/unipdf/v3/contentstream";_ag "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_e "github.com/unidoc/unipdf/v3/model";);
|
||||
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";);
|
||||
|
||||
// NormalizePage performs the following operations on the passed in page:
|
||||
// - Normalize the page rotation.
|
||||
@ -26,4 +26,4 @@ package pdfutil ;import (_a "github.com/unidoc/unipdf/v3/common";_d "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 *_e .PdfPage )error {_ef ,_ad :=page .GetMediaBox ();if _ad !=nil {return _ad ;};_g :=page .Rotate ;_agf :=_g !=nil &&*_g %360!=0&&*_g %90==0;_ef .Normalize ();_gb ,_gf ,_gbb ,_ga :=_ef .Llx ,_ef .Lly ,_ef .Width (),_ef .Height ();_ab :=_gb !=0||_gf !=0;if !_agf &&!_ab {return nil ;};_be :=func (_eb ,_bb ,_ea float64 )_ag .BoundingBox {return _ag .Path {Points :[]_ag .Point {_ag .NewPoint (0,0).Rotate (_ea ),_ag .NewPoint (_eb ,0).Rotate (_ea ),_ag .NewPoint (0,_bb ).Rotate (_ea ),_ag .NewPoint (_eb ,_bb ).Rotate (_ea )}}.GetBoundingBox ();};_ge :=_d .NewContentCreator ();var _c float64 ;if _agf {_c =-float64 (*page .Rotate );_dd :=_be (_gbb ,_ga ,_c );_ge .Translate ((_dd .Width -_gbb )/2+_gbb /2,(_dd .Height -_ga )/2+_ga /2);_ge .RotateDeg (_c );_ge .Translate (-_gbb /2,-_ga /2);_gbb ,_ga =_dd .Width ,_dd .Height ;};if _ab {_ge .Translate (-_gb ,-_gf );};_ed :=_ge .Operations ();_da ,_ad :=_f .MakeStream (_ed .Bytes (),_f .NewFlateEncoder ());if _ad !=nil {return _ad ;};_age :=_f .MakeArray (_da );_age .Append (page .GetContentStreamObjs ()...);*_ef =_e .PdfRectangle {Urx :_gbb ,Ury :_ga };if _fg :=page .CropBox ;_fg !=nil {_fg .Normalize ();_ebd ,_af ,_eac ,_fc :=_fg .Llx -_gb ,_fg .Lly -_gf ,_fg .Width (),_fg .Height ();if _agf {_agg :=_be (_eac ,_fc ,_c );_eac ,_fc =_agg .Width ,_agg .Height ;};*_fg =_e .PdfRectangle {Llx :_ebd ,Lly :_af ,Urx :_ebd +_eac ,Ury :_af +_fc };};_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",_c ,_ed ,_ef );page .Contents =_age ;page .Rotate =nil ;return nil ;};
|
||||
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 ;};
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user