├── LICENSE.md ├── internal ├── jbig2 │ ├── bench │ │ └── bench.go │ ├── internal │ │ └── internal.go │ ├── errors │ │ └── errors.go │ ├── jbig2.go │ ├── decoder │ │ ├── decoder.go │ │ ├── arithmetic │ │ │ └── arithmetic.go │ │ ├── huffman │ │ │ └── huffman.go │ │ └── mmr │ │ │ └── mmr.go │ ├── basic │ │ └── basic.go │ └── encoder │ │ └── arithmetic │ │ └── arithmetic.go ├── precision │ └── precision.go ├── endian │ └── endian.go ├── uuid │ └── uuid.go ├── timeutils │ └── timeutils.go ├── sampling │ └── sampling.go ├── transform │ └── transform.go ├── strutils │ └── strutils.go ├── textencoding │ └── internal │ │ └── syncmap │ │ └── syncmap.go ├── testutils │ └── testutils.go ├── integrations │ └── unichart │ │ └── unichart.go └── bitwise │ └── bitwise.go ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── workflows │ └── greetings.yml ├── model ├── optimize │ └── tests │ │ └── tests.go ├── xmputil │ └── pdfaid │ │ └── pdfaid.go ├── sigutil │ └── sigutil.go └── internal │ └── docutil │ └── docutil.go ├── textshaping └── textshaping.go ├── go.mod ├── common ├── license │ └── license.go └── common.go ├── unipdf.go ├── fjson └── fjson.go ├── README.md ├── go.sum ├── sanitize └── sanitize.go ├── render └── internal │ └── context │ └── context.go ├── ocr └── ocr.go └── core └── security └── crypt └── crypt.go /LICENSE.md: -------------------------------------------------------------------------------- 1 | ## Licensing Information 2 | 3 | This software package is a commercial product and requires a license 4 | code to operate. 5 | 6 | The use of this software package is governed by the end-user license agreement 7 | (EULA) available at: https://unidoc.io/eula/ 8 | 9 | To obtain a Trial license code to evaluate the software, please visit 10 | https://unidoc.io/ 11 | -------------------------------------------------------------------------------- /internal/jbig2/bench/bench.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package bench ; -------------------------------------------------------------------------------- /internal/jbig2/internal/internal.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package internal ;import _d "errors";var ErrOOB =_d .New ("o\u0075\u0074\u0020\u006f\u0066\u0020\u0062\u0061\u006e\u0064"); -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | ## Description 11 | A clear and concise description of what the bug is. 12 | 13 | ## Expected Behavior 14 | A clear and concise description of what you expected to happen. 15 | 16 | ## Actual Behavior 17 | Steps to reproduce the behavior: 18 | 1. Go to '...' 19 | 2. Click on '....' 20 | 3. Scroll down to '....' 21 | 4. See error 22 | 23 | ## Attachments 24 | Include a self-contained reproducible code snippet and PDF file that demonstrates the issue. 25 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: "[FEATURE]" 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /model/optimize/tests/tests.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package tests provides integration tests for the UniPDF optimizer. The test requires environment variable 13 | // UNIDOC_OPTIMIZE_TESTDATA to be set for the directory with `.pdf` files, otherwise the test is skipped. 14 | package tests ; -------------------------------------------------------------------------------- /internal/precision/precision.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package precision ;import _e "math";const (DefaultPrecision =4;);func RoundDefault (value float64 )float64 {return RoundFloat (value ,DefaultPrecision )};func RoundFloat (value float64 ,precision int )float64 {_a :=_e .Pow (10,float64 (precision ));return _e .Round (value *_a )/_a ; 13 | }; -------------------------------------------------------------------------------- /internal/endian/endian.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package endian ;import (_f "encoding/binary";_e "unsafe";);func IsBig ()bool {return _c };func init (){const _d =int (_e .Sizeof (0));_eg :=1;_cb :=(*[_d ]byte )(_e .Pointer (&_eg ));if _cb [0]==0{_c =true ;ByteOrder =_f .BigEndian ;}else {ByteOrder =_f .LittleEndian ; 13 | };};func IsLittle ()bool {return !_c };var (ByteOrder _f .ByteOrder ;_c bool ;); -------------------------------------------------------------------------------- /textshaping/textshaping.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package textshaping ;import (_g "github.com/unidoc/garabic";_gg "golang.org/x/text/unicode/bidi";_f "strings";); 13 | 14 | // ArabicShape returns shaped arabic glyphs string. 15 | func ArabicShape (text string )(string ,error ){_fe :=_gg .Paragraph {};_fe .SetString (text );_e ,_eb :=_fe .Order ();if _eb !=nil {return "",_eb ;};for _ef :=0;_ef < _e .NumRuns ();_ef ++{_fa :=_e .Run (_ef );_ed :=_fa .String ();if _fa .Direction ()==_gg .RightToLeft {var (_dc =_g .Shape (_ed ); 16 | _a =[]rune (_dc );_ge =make ([]rune ,len (_a )););_ec :=0;for _b :=len (_a )-1;_b >=0;_b --{_ge [_ec ]=_a [_b ];_ec ++;};_ed =string (_ge );text =_f .Replace (text ,_f .TrimSpace (_fa .String ()),_ed ,1);};};return text ,nil ;}; -------------------------------------------------------------------------------- /internal/uuid/uuid.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package uuid ;import (_b "crypto/rand";_ag "encoding/hex";_e "io";);func MustUUID ()UUID {uuid ,_bg :=NewUUID ();if _bg !=nil {panic (_bg );};return uuid ;};var _d UUID ;func (_ef UUID )String ()string {var _ba [36]byte ;_eef (_ba [:],_ef );return string (_ba [:])}; 13 | func _eef (_ed []byte ,_bf UUID ){_ag .Encode (_ed ,_bf [:4]);_ed [8]='-';_ag .Encode (_ed [9:13],_bf [4:6]);_ed [13]='-';_ag .Encode (_ed [14:18],_bf [6:8]);_ed [18]='-';_ag .Encode (_ed [19:23],_bf [8:10]);_ed [23]='-';_ag .Encode (_ed [24:],_bf [10:]); 14 | };func NewUUID ()(UUID ,error ){var uuid UUID ;_ ,_aa :=_e .ReadFull (_g ,uuid [:]);if _aa !=nil {return _d ,_aa ;};uuid [6]=(uuid [6]&0x0f)|0x40;uuid [8]=(uuid [8]&0x3f)|0x80;return uuid ,nil ;};var Nil =_d ;var _g =_b .Reader ;type UUID [16]byte ; -------------------------------------------------------------------------------- /.github/workflows/greetings.yml: -------------------------------------------------------------------------------- 1 | name: Greetings 2 | 3 | on: [issues] 4 | 5 | jobs: 6 | greeting: 7 | runs-on: ubuntu-latest 8 | steps: 9 | - uses: actions/first-interaction@v1 10 | with: 11 | repo-token: ${{ secrets.GITHUB_TOKEN }} 12 | issue-message: > 13 | Welcome! Thanks for posting your first issue. The way things work here is that while customer issues are prioritized, 14 | other issues go into our backlog where they are assessed and fitted into the roadmap when suitable. 15 | If you need to get this done, consider buying a license which also enables you to use it in your commercial products. 16 | More information can be found on https://unidoc.io/ 17 | pr-message: > 18 | Thanks for posting your first PR. Please be sure to sign the CLA and make sure that the 19 | the Developer Guidelines https://github.com/unidoc/unipdf/wiki/UniPDF-Developer-Guide were followed. 20 | You can expect that we will review the PR and post comments. The timeframe fpr this can vary depending 21 | on various factors, including which issue(s) the PR addresses and where it fits in the roadmap. 22 | Note also that customer PRs are prioritized. 23 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module github.com/unidoc/unipdf/v4 2 | 3 | go 1.23.0 4 | 5 | require ( 6 | github.com/adrg/sysfont v0.1.2 7 | github.com/boombuler/barcode v1.0.2 8 | github.com/go-text/typesetting v0.3.0 9 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 10 | github.com/h2non/filetype v1.1.3 11 | github.com/stretchr/testify v1.11.1 12 | github.com/trimmer-io/go-xmp v1.0.0 13 | github.com/unidoc/freetype v0.2.3 14 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 15 | github.com/unidoc/pkcs7 v0.3.0 16 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a 17 | github.com/unidoc/unichart v0.5.1 18 | github.com/unidoc/unitype v0.5.1 19 | golang.org/x/crypto v0.41.0 20 | golang.org/x/image v0.30.0 21 | golang.org/x/net v0.43.0 22 | golang.org/x/text v0.28.0 23 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da 24 | software.sslmate.com/src/go-pkcs12 v0.6.0 25 | ) 26 | 27 | require ( 28 | github.com/adrg/strutil v0.3.1 // indirect 29 | github.com/adrg/xdg v0.5.3 // indirect 30 | github.com/davecgh/go-spew v1.1.1 // indirect 31 | github.com/kr/text v0.2.0 // indirect 32 | github.com/pmezard/go-difflib v1.0.0 // indirect 33 | github.com/sirupsen/logrus v1.9.3 // indirect 34 | github.com/stretchr/objx v0.5.2 // indirect 35 | golang.org/x/sys v0.35.0 // indirect 36 | gopkg.in/yaml.v3 v3.0.1 // indirect 37 | ) 38 | -------------------------------------------------------------------------------- /internal/jbig2/errors/errors.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package errors ;import (_e "fmt";_a "golang.org/x/xerrors";);func _aa (_fc ,_cb string )*processError {return &processError {_gd :"\u005b\u0055\u006e\u0069\u0050\u0044\u0046\u005d",_ag :_fc ,_c :_cb };};var _ _a .Wrapper =(*processError )(nil );func Errorf (processName ,message string ,arguments ...interface{})error {return _aa (_e .Sprintf (message ,arguments ...),processName ); 13 | };func (_ab *processError )Unwrap ()error {return _ab ._ed };func (_gg *processError )Error ()string {var _af string ;if _gg ._gd !=""{_af =_gg ._gd ;};_af +="\u0050r\u006f\u0063\u0065\u0073\u0073\u003a "+_gg ._c ;if _gg ._ag !=""{_af +="\u0020\u004d\u0065\u0073\u0073\u0061\u0067\u0065\u003a\u0020"+_gg ._ag ; 14 | };if _gg ._ed !=nil {_af +="\u002e\u0020"+_gg ._ed .Error ();};return _af ;};type processError struct{_gd string ;_c string ;_ag string ;_ed error ;};func Wrapf (err error ,processName ,message string ,arguments ...interface{})error {if _cc ,_d :=err .(*processError ); 15 | _d {_cc ._gd ="";};_edb :=_aa (_e .Sprintf (message ,arguments ...),processName );_edb ._ed =err ;return _edb ;};func Wrap (err error ,processName ,message string )error {if _b ,_fb :=err .(*processError );_fb {_b ._gd ="";};_fa :=_aa (message ,processName ); 16 | _fa ._ed =err ;return _fa ;};func Error (processName ,message string )error {return _aa (message ,processName )}; -------------------------------------------------------------------------------- /internal/jbig2/jbig2.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package jbig2 ;import (_e "github.com/unidoc/unipdf/v4/internal/bitwise";_d "github.com/unidoc/unipdf/v4/internal/jbig2/decoder";_cb "github.com/unidoc/unipdf/v4/internal/jbig2/document";_cc "github.com/unidoc/unipdf/v4/internal/jbig2/document/segments"; 13 | _g "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_c "sort";);func DecodeGlobals (encoded []byte )(Globals ,error ){const _cd ="\u0044\u0065\u0063\u006f\u0064\u0065\u0047\u006c\u006f\u0062\u0061\u006c\u0073";_b :=_e .NewReader (encoded );_af ,_f :=_cb .DecodeDocument (_b ,nil ); 14 | if _f !=nil {return nil ,_g .Wrap (_f ,_cd ,"");};if _af .GlobalSegments ==nil ||(_af .GlobalSegments .Segments ==nil ){return nil ,_g .Error (_cd ,"\u006eo\u0020\u0067\u006c\u006f\u0062\u0061\u006c\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0075\u006e\u0064"); 15 | };_dcd :=Globals {};for _ ,_ce :=range _af .GlobalSegments .Segments {_dcd [int (_ce .SegmentNumber )]=_ce ;};return _dcd ,nil ;};func DecodeBytes (encoded []byte ,parameters _d .Parameters ,globals ...Globals )([]byte ,error ){var _ec Globals ;if len (globals )> 0{_ec =globals [0]; 16 | };_dc ,_gc :=_d .Decode (encoded ,parameters ,_ec .ToDocumentGlobals ());if _gc !=nil {return nil ,_gc ;};return _dc .DecodeNextPage ();};type Globals map[int ]*_cc .Header ;func (_fa Globals )ToDocumentGlobals ()*_cb .Globals {if _fa ==nil {return nil ; 17 | };_eg :=[]*_cc .Header {};for _ ,_ea :=range _fa {_eg =append (_eg ,_ea );};_c .Slice (_eg ,func (_cg ,_ed int )bool {return _eg [_cg ].SegmentNumber < _eg [_ed ].SegmentNumber });return &_cb .Globals {Segments :_eg };}; -------------------------------------------------------------------------------- /common/license/license.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package license helps manage commercial licenses and check if they are valid for the version of unipdf used. 13 | package license ;import _ed "github.com/unidoc/unipdf/v4/internal/license"; 14 | 15 | // GetLicenseKey returns the currently loaded license key. 16 | func GetLicenseKey ()*LicenseKey {return _ed .GetLicenseKey ()}; 17 | 18 | // GetMeteredState checks the currently used metered document usage status, 19 | // documents used and credits available. 20 | func GetMeteredState ()(_ed .MeteredStatus ,error ){return _ed .GetMeteredState ()}; 21 | 22 | // SetMeteredKey sets the metered API key required for SaaS operation. 23 | // Document usage is reported periodically for the product to function correctly. 24 | func SetMeteredKey (apiKey string )error {return _ed .SetMeteredKey (apiKey )}; 25 | 26 | // LicenseKey represents a loaded license key. 27 | type LicenseKey =_ed .LicenseKey ; 28 | 29 | // SetLicenseKey sets and validates the license key. 30 | func SetLicenseKey (content string ,customerName string )error {return _ed .SetLicenseKey (content ,customerName );}; 31 | 32 | // SetMeteredKeyPersistentCache sets the metered License API Key persistent cache. 33 | // Default value 'true', set to `false` will report the usage immediately to license server, 34 | // this can be used when there's no access to persistent data storage. 35 | func SetMeteredKeyPersistentCache (val bool ){_ed .SetMeteredKeyPersistentCache (val )};func SetMeteredKeyUsageLogVerboseMode (val bool ){_ed .SetMeteredKeyUsageLogVerboseMode (val )}; 36 | 37 | // MakeUnlicensedKey returns a default key. 38 | func MakeUnlicensedKey ()*LicenseKey {return _ed .MakeUnlicensedKey ()};const (LicenseTierUnlicensed =_ed .LicenseTierUnlicensed ;LicenseTierCommunity =_ed .LicenseTierCommunity ;LicenseTierIndividual =_ed .LicenseTierIndividual ;LicenseTierBusiness =_ed .LicenseTierBusiness ; 39 | ); -------------------------------------------------------------------------------- /unipdf.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package unipdf is a comprehensive PDF library for Go (golang). The library has advanced capabilities for generating, 13 | // processing and modifying PDFs. UniPDF is written and supported by the owners of the 14 | // FoxyUtils.com website, where the library is used to power many of the PDF services offered. 15 | // 16 | // # Getting More Information 17 | // 18 | // Check out the Getting Started and Example sections, which showcase how to install unipdf and provide numerous 19 | // examples of using unipdf to generate, process or modify PDF files. 20 | // https://unidoc.io/examples/getting_started/ 21 | // 22 | // The GoDoc for unipdf provides a detailed breakdown of the API and documentation for packages, types and methods. 23 | // https://godoc.org/github.com/unidoc/unipdf 24 | // 25 | // # Overview of Major Packages 26 | // 27 | // The API is composed of a few major packages: 28 | // 29 | // - common: Provides common shared types such as Logger and utilities to check 30 | // license validity. 31 | // 32 | // - core: The core package defines the primitive PDF object types and handles 33 | // the file reading I/O and parsing the primitive objects. 34 | // 35 | // - model: The model package builds on the core package, to represent the PDF as 36 | // a structured model of the PDF primitive types. It has a reader and a writer to 37 | // read and process a PDF file based on the structured model. This serves as a basis 38 | // to perform a number of numerous tasks and can be used to work with a PDF in a 39 | // medium to high level interface, although it does require an understanding of the 40 | // PDF format and structure. 41 | // 42 | // - creator: The PDF creator makes it easy to create new PDFs or modify existing 43 | // PDFs. It can also enable loading a template PDF, adding text/images and 44 | // generating an output PDF. It can be used to add text, images, and generate text 45 | // and graphical reports. It is designed with simplicity in mind, with the goal of 46 | // making it easy to create reports without needing any knowledge about the PDF 47 | // format or specifications. 48 | // 49 | // - extractor: Package extractor is used for quickly extracting PDF content 50 | // through a simple interface. Currently offers functionality for extracting textual 51 | // content. 52 | package unipdf ; -------------------------------------------------------------------------------- /internal/timeutils/timeutils.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package timeutils ;import (_d "errors";_f "fmt";_g "regexp";_de "strconv";_b "time";);func ParsePdfTime (pdfTime string )(_b .Time ,error ){_dg :=_cf .FindAllStringSubmatch (pdfTime ,1);if len (_dg )< 1{if len (pdfTime )> 0&&pdfTime [0]!='D'{pdfTime =_f .Sprintf ("\u0044\u003a\u0025\u0073",pdfTime ); 13 | return ParsePdfTime (pdfTime );};return _b .Time {},_f .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0064\u0061\u0074\u0065\u0020s\u0074\u0072\u0069\u006e\u0067\u0020\u0028\u0025\u0073\u0029",pdfTime );};if len (_dg [0])!=10{return _b .Time {},_d .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0072\u0065\u0067\u0065\u0078p\u0020\u0067\u0072\u006f\u0075\u0070 \u006d\u0061\u0074\u0063\u0068\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020!\u003d\u0020\u0031\u0030"); 14 | };_ea ,_ :=_de .ParseInt (_dg [0][1],10,32);_c ,_ :=_de .ParseInt (_dg [0][2],10,32);_ef ,_ :=_de .ParseInt (_dg [0][3],10,32);_ff ,_ :=_de .ParseInt (_dg [0][4],10,32);_aa ,_ :=_de .ParseInt (_dg [0][5],10,32);_af ,_ :=_de .ParseInt (_dg [0][6],10,32); 15 | var (_dd byte ;_ae int64 ;_da int64 ;);_dd ='+';if len (_dg [0][7])> 0{if _dg [0][7]=="\u002d"{_dd ='-';}else if _dg [0][7]=="\u005a"{_dd ='Z';};};if len (_dg [0][8])> 0{_ae ,_ =_de .ParseInt (_dg [0][8],10,32);}else {_ae =0;};if len (_dg [0][9])> 0{_da ,_ =_de .ParseInt (_dg [0][9],10,32); 16 | }else {_da =0;};_fe :=int (_ae *60*60+_da *60);switch _dd {case '-':_fe =-_fe ;case 'Z':_fe =0;};_ffb :=_f .Sprintf ("\u0055\u0054\u0043\u0025\u0063\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064",_dd ,_ae ,_da );_ged :=_b .FixedZone (_ffb ,_fe );return _b .Date (int (_ea ),_b .Month (_c ),int (_ef ),int (_ff ),int (_aa ),int (_af ),0,_ged ),nil ; 17 | };var _cf =_g .MustCompile ("\u005cs\u002a\u0044\u005cs\u002a\u003a\u005cs\u002a(\\\u0064\u007b\u0034\u007d\u0029\u0028\u005cd\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064\u007b\u0032\u007d\u0029\u0028\u005c\u0064{2\u007d)\u003f\u0028\u005b\u002b\u002d\u005a]\u0029\u003f\u0028\u005c\u0064{\u0032\u007d\u0029\u003f\u0027\u003f\u0028\u005c\u0064\u007b\u0032}\u0029\u003f"); 18 | func FormatPdfTime (in _b .Time )string {_gc :=in .Format ("\u002d\u0030\u0037\u003a\u0030\u0030");_gg ,_ :=_de .ParseInt (_gc [1:3],10,32);_ggf ,_ :=_de .ParseInt (_gc [4:6],10,32);_gcf :=int64 (in .Year ());_fd :=int64 (in .Month ());_eec :=int64 (in .Day ()); 19 | _eb :=int64 (in .Hour ());_a :=int64 (in .Minute ());_fc :=int64 (in .Second ());_ge :=_gc [0];return _f .Sprintf ("\u0044\u003a\u0025\u002e\u0034\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e\u0032\u0064\u0025\u002e2\u0064\u0025\u0063\u0025\u002e2\u0064\u0027%\u002e\u0032\u0064\u0027",_gcf ,_fd ,_eec ,_eb ,_a ,_fc ,_ge ,_gg ,_ggf ); 20 | }; -------------------------------------------------------------------------------- /internal/jbig2/decoder/decoder.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package decoder ;import (_g "github.com/unidoc/unipdf/v4/internal/bitwise";_ec "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_a "github.com/unidoc/unipdf/v4/internal/jbig2/document";_ee "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_f "image"; 13 | );func Decode (input []byte ,parameters Parameters ,globals *_a .Globals )(*Decoder ,error ){_fd :=_g .NewReader (input );_ac ,_eea :=_a .DecodeDocument (_fd ,globals );if _eea !=nil {return nil ,_eea ;};return &Decoder {_eca :_fd ,_b :_ac ,_eb :parameters },nil ; 14 | };func (_dg *Decoder )DecodeNextPage ()([]byte ,error ){_dg ._ef ++;_bf :=_dg ._ef ;return _dg .decodePage (_bf );};func (_fg *Decoder )PageNumber ()(int ,error ){const _ea ="\u0044e\u0063o\u0064\u0065\u0072\u002e\u0050a\u0067\u0065N\u0075\u006d\u0062\u0065\u0072"; 15 | if _fg ._b ==nil {return 0,_ee .Error (_ea ,"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 (_fg ._b .NumberOfPages ),nil ;};func (_ebd *Decoder )DecodePageImage (pageNumber int )(_f .Image ,error ){const _d ="\u0064\u0065\u0063od\u0065\u0072\u002e\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065"; 16 | _gd ,_af :=_ebd .decodePageImage (pageNumber );if _af !=nil {return nil ,_ee .Wrap (_af ,_d ,"");};return _gd ,nil ;};type Decoder struct{_eca *_g .Reader ;_b *_a .Document ;_ef int ;_eb Parameters ;};type Parameters struct{UnpaddedData bool ;Color _ec .Color ; 17 | };func (_ff *Decoder )decodePage (_ab int )([]byte ,error ){const _aa ="\u0064\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0067\u0065";if _ab < 0{return nil ,_ee .Errorf (_aa ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_ab ); 18 | };if _ab > int (_ff ._b .NumberOfPages ){return nil ,_ee .Errorf (_aa ,"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",_ab ); 19 | };_gc ,_fa :=_ff ._b .GetPage (_ab );if _fa !=nil {return nil ,_ee .Wrap (_fa ,_aa ,"");};_df ,_fa :=_gc .GetBitmap ();if _fa !=nil {return nil ,_ee .Wrap (_fa ,_aa ,"");};_df .InverseData ();if !_ff ._eb .UnpaddedData {return _df .Data ,nil ;};return _df .GetUnpaddedData (); 20 | };func (_c *Decoder )DecodePage (pageNumber int )([]byte ,error ){return _c .decodePage (pageNumber )};func (_ae *Decoder )decodePageImage (_cg int )(_f .Image ,error ){const _bg ="\u0064e\u0063o\u0064\u0065\u0050\u0061\u0067\u0065\u0049\u006d\u0061\u0067\u0065"; 21 | if _cg < 0{return nil ,_ee .Errorf (_bg ,"\u0069n\u0076\u0061\u006c\u0069d\u0020\u0070\u0061\u0067\u0065 \u006eu\u006db\u0065\u0072\u003a\u0020\u0027\u0025\u0064'",_cg );};if _cg > int (_ae ._b .NumberOfPages ){return nil ,_ee .Errorf (_bg ,"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",_cg ); 22 | };_ga ,_dfa :=_ae ._b .GetPage (_cg );if _dfa !=nil {return nil ,_ee .Wrap (_dfa ,_bg ,"");};_ag ,_dfa :=_ga .GetBitmap ();if _dfa !=nil {return nil ,_ee .Wrap (_dfa ,_bg ,"");};_ag .InverseData ();return _ag .ToImage (),nil ;}; -------------------------------------------------------------------------------- /model/xmputil/pdfaid/pdfaid.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package pdfaid ;import (_d "fmt";_a "github.com/trimmer-io/go-xmp/xmp";_dc "github.com/unidoc/unipdf/v4/model/xmputil/pdfaextension";); 13 | 14 | // SyncToXMP implements xmp.Model interface. 15 | func (_eg *Model )SyncToXMP (d *_a .Document )error {return nil };func init (){_a .Register (Namespace ,_a .XmpMetadata );_dc .RegisterSchema (Namespace ,&Schema )}; 16 | 17 | // Can implements xmp.Model interface. 18 | func (_cf *Model )Can (nsName string )bool {return Namespace .GetName ()==nsName }; 19 | 20 | // SetTag implements xmp.Model interface. 21 | func (_feb *Model )SetTag (tag ,value string )error {if _ca :=_a .SetNativeField (_feb ,tag ,value );_ca !=nil {return _d .Errorf ("\u0025\u0073\u003a\u0020\u0025\u0076",Namespace .GetName (),_ca );};return nil ;};var Namespace =_a .NewNamespace ("\u0070\u0064\u0066\u0061\u0069\u0064","\u0068\u0074\u0074p\u003a\u002f\u002f\u0077w\u0077\u002e\u0061\u0069\u0069\u006d\u002eo\u0072\u0067\u002f\u0070\u0064\u0066\u0061\u002f\u006e\u0073\u002f\u0069\u0064\u002f",NewModel ); 22 | 23 | 24 | // NewModel creates a new model. 25 | func NewModel (name string )_a .Model {return &Model {}}; 26 | 27 | // Namespaces implements xmp.Model interface. 28 | func (_ag *Model )Namespaces ()_a .NamespaceList {return _a .NamespaceList {Namespace }}; 29 | 30 | // Model is the XMP model for the PdfA metadata. 31 | type Model struct{Part int `xmp:"pdfaid:part"`;Conformance string `xmp:"pdfaid:conformance"`;Rev int `xmp:"pdfaid:rev"`;}; 32 | 33 | // SyncFromXMP implements xmp.Model interface. 34 | func (_ef *Model )SyncFromXMP (d *_a .Document )error {return nil };var _ _a .Model =(*Model )(nil ); 35 | 36 | // SyncModel implements xmp.Model interface. 37 | func (_g *Model )SyncModel (d *_a .Document )error {return nil }; 38 | 39 | // MakeModel gets or create sa new model for PDF/A ID namespace. 40 | func MakeModel (d *_a .Document )(*Model ,error ){_ed ,_f :=d .MakeModel (Namespace );if _f !=nil {return nil ,_f ;};return _ed .(*Model ),nil ;}; 41 | 42 | // CanTag implements xmp.Model interface. 43 | func (_edg *Model )CanTag (tag string )bool {_ ,_b :=_a .GetNativeField (_edg ,tag );return _b ==nil }; 44 | 45 | // GetTag implements xmp.Model interface. 46 | func (_fe *Model )GetTag (tag string )(string ,error ){_eeg ,_cd :=_a .GetNativeField (_fe ,tag );if _cd !=nil {return "",_d .Errorf ("\u0025\u0073\u003a\u0020\u0025\u0076",Namespace .GetName (),_cd );};return _eeg ,nil ;};var Schema =_dc .Schema {NamespaceURI :Namespace .URI ,Prefix :Namespace .Name ,Schema :"\u0050D\u0046/\u0041\u0020\u0049\u0044\u0020\u0053\u0063\u0068\u0065\u006d\u0061",Property :[]_dc .Property {{Category :_dc .PropertyCategoryInternal ,Description :"\u0050\u0061\u0072\u0074 o\u0066\u0020\u0050\u0044\u0046\u002f\u0041\u0020\u0073\u0074\u0061\u006e\u0064\u0061r\u0064",Name :"\u0070\u0061\u0072\u0074",ValueType :_dc .ValueTypeNameInteger },{Category :_dc .PropertyCategoryInternal ,Description :"A\u006d\u0065\u006e\u0064\u006d\u0065n\u0074\u0020\u006f\u0066\u0020\u0050\u0044\u0046\u002fA\u0020\u0073\u0074a\u006ed\u0061\u0072\u0064",Name :"\u0061\u006d\u0064",ValueType :_dc .ValueTypeNameText },{Category :_dc .PropertyCategoryInternal ,Description :"C\u006f\u006e\u0066\u006f\u0072\u006da\u006e\u0063\u0065\u0020\u006c\u0065v\u0065\u006c\u0020\u006f\u0066\u0020\u0050D\u0046\u002f\u0041\u0020\u0073\u0074\u0061\u006e\u0064\u0061r\u0064",Name :"c\u006f\u006e\u0066\u006f\u0072\u006d\u0061\u006e\u0063\u0065",ValueType :_dc .ValueTypeNameText }},ValueType :nil }; 47 | -------------------------------------------------------------------------------- /internal/jbig2/basic/basic.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package basic ;import _g "github.com/unidoc/unipdf/v4/internal/jbig2/errors";func (_ceg *Stack )Pop ()(_bbg interface{},_gaf bool ){_bbg ,_gaf =_ceg .peek ();if !_gaf {return nil ,_gaf ;};_ceg .Data =_ceg .Data [:_ceg .top ()];return _bbg ,true ;};func (_bb NumSlice )GetIntSlice ()[]int {_dg :=make ([]int ,len (_bb )); 13 | for _gc ,_ag :=range _bb {_dg [_gc ]=int (_ag );};return _dg ;};func (_gd IntSlice )Size ()int {return len (_gd )};func Sign (v float32 )float32 {if v >=0.0{return 1.0;};return -1.0;};func (_de *NumSlice )Add (v float32 ){*_de =append (*_de ,v )};func Min (x ,y int )int {if x < y {return x ; 14 | };return y ;};func NewNumSlice (i int )*NumSlice {_fb :=NumSlice (make ([]float32 ,i ));return &_fb };func (_ad IntsMap )GetSlice (key uint64 )([]int ,bool ){_be ,_bf :=_ad [key ];if !_bf {return nil ,false ;};return _be ,true ;};func NewIntSlice (i int )*IntSlice {_cc :=IntSlice (make ([]int ,i )); 15 | return &_cc };type NumSlice []float32 ;type IntSlice []int ;type Stack struct{Data []interface{};Aux *Stack ;};func (_af *Stack )Len ()int {return len (_af .Data )};func (_cg IntSlice )Get (index int )(int ,error ){if index > len (_cg )-1{return 0,_g .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 ); 16 | };return _cg [index ],nil ;};func (_ga NumSlice )GetInt (i int )(int ,error ){const _dd ="\u0047\u0065\u0074\u0049\u006e\u0074";if i < 0||i > len (_ga )-1{return 0,_g .Errorf (_dd ,"\u0069n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u006fu\u0074\u0020\u006f\u0066\u0020\u0072\u0061\u006e\u0067\u0065",i ); 17 | };_ef :=_ga [i ];return int (_ef +Sign (_ef )*0.5),nil ;};func (_c IntsMap )Get (key uint64 )(int ,bool ){_fe ,_b :=_c [key ];if !_b {return 0,false ;};if len (_fe )==0{return 0,false ;};return _fe [0],true ;};func (_gf *Stack )Peek ()(_afd interface{},_ec bool ){return _gf .peek ()}; 18 | func (_ea NumSlice )Get (i int )(float32 ,error ){if i < 0||i > len (_ea )-1{return 0,_g .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 ); 19 | };return _ea [i ],nil ;};func Max (x ,y int )int {if x > y {return x ;};return y ;};func (_fee IntsMap )Delete (key uint64 ){delete (_fee ,key )};func (_a IntsMap )Add (key uint64 ,value int ){_a [key ]=append (_a [key ],value )};func (_d *IntSlice )Copy ()*IntSlice {_e :=IntSlice (make ([]int ,len (*_d ))); 20 | copy (_e ,*_d );return &_e ;};func Abs (v int )int {if v > 0{return v ;};return -v ;};func (_gfe *Stack )Push (v interface{}){_gfe .Data =append (_gfe .Data ,v )};func (_ac *Stack )peek ()(interface{},bool ){_fbf :=_ac .top ();if _fbf ==-1{return nil ,false ; 21 | };return _ac .Data [_fbf ],true ;};func (_dda *Stack )top ()int {return len (_dda .Data )-1};func (_bc *IntSlice )Add (v int )error {if _bc ==nil {return _g .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"); 22 | };*_bc =append (*_bc ,v );return nil ;};type IntsMap map[uint64 ][]int ;func Ceil (numerator ,denominator int )int {if numerator %denominator ==0{return numerator /denominator ;};return (numerator /denominator )+1;};func (_ce *NumSlice )AddInt (v int ){*_ce =append (*_ce ,float32 (v ))}; 23 | -------------------------------------------------------------------------------- /fjson/fjson.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package fjson provides support for loading PDF form field data from JSON data/files. 13 | package fjson ;import (_b "encoding/json";_g "github.com/unidoc/unipdf/v4/common";_be "github.com/unidoc/unipdf/v4/core";_gf "github.com/unidoc/unipdf/v4/model";_bf "io";_a "os";); 14 | 15 | // FieldImageValues implements model.FieldImageProvider interface. 16 | func (_fdd *FieldData )FieldImageValues ()(map[string ]*_gf .Image ,error ){_ae :=make (map[string ]*_gf .Image );for _ ,_dfd :=range _fdd ._c {if _dfd .ImageValue !=nil {_ae [_dfd .Name ]=_dfd .ImageValue ;};};return _ae ,nil ;}; 17 | 18 | // FieldValues implements model.FieldValueProvider interface. 19 | func (_deb *FieldData )FieldValues ()(map[string ]_be .PdfObject ,error ){_bd :=make (map[string ]_be .PdfObject );for _ ,_dbc :=range _deb ._c {if len (_dbc .Value )> 0{_bd [_dbc .Name ]=_be .MakeString (_dbc .Value );};};return _bd ,nil ;};type fieldValue struct{Name string `json:"name"`; 20 | Value string `json:"value"`;ImageValue *_gf .Image `json:"-"`; 21 | 22 | // Options lists allowed values if present. 23 | Options []string `json:"options,omitempty"`;}; 24 | 25 | // LoadFromJSON loads JSON form data from `r`. 26 | func LoadFromJSON (r _bf .Reader )(*FieldData ,error ){var _f FieldData ;_cd :=_b .NewDecoder (r ).Decode (&_f ._c );if _cd !=nil {return nil ,_cd ;};return &_f ,nil ;}; 27 | 28 | // LoadFromJSONFile loads form field data from a JSON file. 29 | func LoadFromJSONFile (filePath string )(*FieldData ,error ){_d ,_cc :=_a .Open (filePath );if _cc !=nil {return nil ,_cc ;};defer _d .Close ();return LoadFromJSON (_d );}; 30 | 31 | // SetImageFromFile assign image file to a specific field identified by fieldName. 32 | func (_ag *FieldData )SetImageFromFile (fieldName string ,imagePath string ,opt []string )error {_bfa ,_cb :=_a .Open (imagePath );if _cb !=nil {return _cb ;};defer _bfa .Close ();_ce ,_cb :=_gf .ImageHandling .Read (_bfa );if _cb !=nil {_g .Log .Error ("\u0045\u0072\u0072or\u0020\u006c\u006f\u0061\u0064\u0069\u006e\u0067\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0073",_cb ); 33 | return _cb ;};return _ag .SetImage (fieldName ,_ce ,opt );}; 34 | 35 | // FieldData represents form field data loaded from JSON file. 36 | type FieldData struct{_c []fieldValue }; 37 | 38 | // LoadFromPDFFile loads form field data from a PDF file. 39 | func LoadFromPDFFile (filePath string )(*FieldData ,error ){_gd ,_gcb :=_a .Open (filePath );if _gcb !=nil {return nil ,_gcb ;};defer _gd .Close ();return LoadFromPDF (_gd );}; 40 | 41 | // JSON returns the field data as a string in JSON format. 42 | func (_gaa FieldData )JSON ()(string ,error ){_bab ,_ee :=_b .MarshalIndent (_gaa ._c ,"","\u0020\u0020\u0020\u0020");return string (_bab ),_ee ;}; 43 | 44 | // SetImage assign model.Image to a specific field identified by fieldName. 45 | func (_dc *FieldData )SetImage (fieldName string ,img *_gf .Image ,opt []string )error {_ea :=fieldValue {Name :fieldName ,ImageValue :img ,Options :opt };_dc ._c =append (_dc ._c ,_ea );return nil ;}; 46 | 47 | // LoadFromPDF loads form field data from a PDF. 48 | func LoadFromPDF (rs _bf .ReadSeeker )(*FieldData ,error ){_ba ,_ad :=_gf .NewPdfReader (rs );if _ad !=nil {return nil ,_ad ;};if _ba .AcroForm ==nil {return nil ,nil ;};var _ca []fieldValue ;_ge :=_ba .AcroForm .AllFields ();for _ ,_df :=range _ge {var _gb []string ; 49 | _gbe :=make (map[string ]struct{});_cg ,_fc :=_df .FullName ();if _fc !=nil {return nil ,_fc ;};if _de ,_ac :=_df .V .(*_be .PdfObjectString );_ac {_ca =append (_ca ,fieldValue {Name :_cg ,Value :_de .Decoded ()});continue ;};var _bfe string ;for _ ,_ed :=range _df .Annotations {_cgc ,_af :=_be .GetName (_ed .AS ); 50 | if _af {_bfe =_cgc .String ();};_fe ,_fa :=_be .GetDict (_ed .AP );if !_fa {continue ;};_gfd ,_ :=_be .GetDict (_fe .Get ("\u004e"));for _ ,_db :=range _gfd .Keys (){_ff :=_db .String ();if _ ,_gfb :=_gbe [_ff ];!_gfb {_gb =append (_gb ,_ff );_gbe [_ff ]=struct{}{}; 51 | };};_ec ,_ :=_be .GetDict (_fe .Get ("\u0044"));for _ ,_fd :=range _ec .Keys (){_baee :=_fd .String ();if _ ,_gc :=_gbe [_baee ];!_gc {_gb =append (_gb ,_baee );_gbe [_baee ]=struct{}{};};};};_add :=fieldValue {Name :_cg ,Value :_bfe ,Options :_gb };_ca =append (_ca ,_add ); 52 | };_ecd :=FieldData {_c :_ca };return &_ecd ,nil ;}; -------------------------------------------------------------------------------- /internal/sampling/sampling.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package sampling ;import (_b "github.com/unidoc/unipdf/v4/internal/bitwise";_ag "github.com/unidoc/unipdf/v4/internal/imageutil";_e "io";);func NewReader (img _ag .ImageBase )*Reader {return &Reader {_adg :_b .NewReader (img .Data ),_g :img ,_ef :img .ColorComponents ,_gc :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width }; 13 | };type SampleWriter interface{WriteSample (_db uint32 )error ;WriteSamples (_bdb []uint32 )error ;};func (_bbf *Reader )ReadSamples (samples []uint32 )(_c error ){for _gf :=0;_gf < len (samples );_gf ++{samples [_gf ],_c =_bbf .ReadSample ();if _c !=nil {return _c ; 14 | };};return nil ;};func NewWriter (img _ag .ImageBase )*Writer {return &Writer {_gfcb :_b .NewWriterMSB (img .Data ),_ec :img ,_cd :img .ColorComponents ,_ee :img .BytesPerLine *8!=img .ColorComponents *img .BitsPerComponent *img .Width };};type SampleReader interface{ReadSample ()(uint32 ,error ); 15 | ReadSamples (_ad []uint32 )error ;};func ResampleUint32 (data []uint32 ,bitsPerInputSample int ,bitsPerOutputSample int )[]uint32 {var _dd []uint32 ;_ab :=bitsPerOutputSample ;var _agd uint32 ;var _ac uint32 ;_dac :=0;_acb :=0;_fad :=0;for _fad < len (data ){if _dac > 0{_gfc :=_dac ; 16 | if _ab < _gfc {_gfc =_ab ;};_agd =(_agd <>uint (bitsPerInputSample -_gfc ));_dac -=_gfc ;if _dac > 0{_ac =_ac <>uint (_dac ));if _bf < bitsPerInputSample {_ac =_adf <=bitsPerOutputSample {_gcag :=_dac ;if _ab < _gcag {_gcag =_ab ;};_agd =(_agd <>uint (bitsPerInputSample -_gcag ));_dac -=_gcag ;if _dac > 0{_ac =_ac < 0&&_ab < bitsPerOutputSample {_agd <<=uint (_ab );_dd =append (_dd ,_agd );};return _dd ;};type Reader struct{_g _ag .ImageBase ;_adg *_b .Reader ; 20 | _d ,_bb ,_ef int ;_gc bool ;};func (_cf *Writer )WriteSample (sample uint32 )error {if _ ,_ce :=_cf ._gfcb .WriteBits (uint64 (sample ),_cf ._ec .BitsPerComponent );_ce !=nil {return _ce ;};_cf ._cd --;if _cf ._cd ==0{_cf ._cd =_cf ._ec .ColorComponents ; 21 | _cf ._baf ++;};if _cf ._baf ==_cf ._ec .Width {if _cf ._ee {_cf ._gfcb .FinishByte ();};_cf ._baf =0;};return nil ;};func (_abb *Writer )WriteSamples (samples []uint32 )error {for _gcc :=0;_gcc < len (samples );_gcc ++{if _bff :=_abb .WriteSample (samples [_gcc ]); 22 | _bff !=nil {return _bff ;};};return nil ;};func ResampleBytes (data []byte ,bitsPerSample int )[]uint32 {var _gd []uint32 ;_f :=bitsPerSample ;var _cc uint32 ;var _fg byte ;_fa :=0;_ba :=0;_bd :=0;for _bd < len (data ){if _fa > 0{_gca :=_fa ;if _f < _gca {_gca =_f ; 23 | };_cc =(_cc <>uint (8-_gca ));_fa -=_gca ;if _fa > 0{_fg =_fg <>uint (_fa ));if _be < 8{_fg =_ga <=bitsPerSample {_da :=_fa ;if _f < _da {_da =_f ;};_cc =(_cc <>uint (8-_da )); 25 | _fa -=_da ;if _fa > 0{_fg =_fg < _dff &&_fb > _dff ;_ag :=_efb > _dff &&_cae > _dff ;return !(_faa ||_ag );};const _efe =1.0e-6;func (_cag Matrix )Translate (tx ,ty float64 )Matrix {return _cag .Mult (TranslationMatrix (tx ,ty ))};const _bca =1e9;func (_ce Matrix )Scale (xScale ,yScale float64 )Matrix {return _ce .Mult (ScaleMatrix (xScale ,yScale ))}; 14 | func NewMatrixFromTransforms (xScale ,yScale ,theta ,tx ,ty float64 )Matrix {return IdentityMatrix ().Scale (xScale ,yScale ).Rotate (theta ).Translate (tx ,ty );};func (_dfaa Point )Rotate (theta float64 )Point {_bef :=_d .Hypot (_dfaa .X ,_dfaa .Y ); 15 | _ff :=_d .Atan2 (_dfaa .Y ,_dfaa .X );_ecg ,_gf :=_d .Sincos (_ff +theta /180.0*_d .Pi );return Point {_bef *_gf ,_bef *_ecg };};func (_be Matrix )ScalingFactorX ()float64 {return _d .Hypot (_be [0],_be [1])};func (_da Matrix )Round (precision float64 )Matrix {for _b :=range _da {_da [_b ]=_d .Round (_da [_b ]/precision )*precision ; 16 | };return _da ;};func (_bc Matrix )Inverse ()(Matrix ,bool ){_acc ,_gg :=_bc [0],_bc [1];_cd ,_bdc :=_bc [3],_bc [4];_ggg ,_gag :=_bc [6],_bc [7];_eaf :=_acc *_bdc -_gg *_cd ;if _d .Abs (_eaf )< _efe {return Matrix {},false ;};_caga ,_cdd :=_bdc /_eaf ,-_gg /_eaf ; 17 | _gbd ,_af :=-_cd /_eaf ,_acc /_eaf ;_ef :=-(_caga *_ggg +_gbd *_gag );_bce :=-(_cdd *_ggg +_af *_gag );return NewMatrix (_caga ,_cdd ,_gbd ,_af ,_ef ,_bce ),true ;};func (_eag Point )String ()string {return _e .Sprintf ("(\u0025\u002e\u0032\u0066\u002c\u0025\u002e\u0032\u0066\u0029",_eag .X ,_eag .Y ); 18 | };const _dff =1e-6;const _gc =1e-10;type Point struct{X float64 ;Y float64 ;};func RotationMatrix (angle float64 )Matrix {_df :=_d .Cos (angle );_c :=_d .Sin (angle );return NewMatrix (_df ,_c ,-_c ,_df ,0,0);};func (_cb Matrix )String ()string {_ga ,_fd ,_dfa ,_bd ,_fg ,_fc :=_cb [0],_cb [1],_cb [3],_cb [4],_cb [6],_cb [7]; 19 | return _e .Sprintf ("\u005b\u00257\u002e\u0034\u0066\u002c%\u0037\u002e4\u0066\u002c\u0025\u0037\u002e\u0034\u0066\u002c%\u0037\u002e\u0034\u0066\u003a\u0025\u0037\u002e\u0034\u0066\u002c\u00257\u002e\u0034\u0066\u005d",_ga ,_fd ,_dfa ,_bd ,_fg ,_fc ); 20 | };func (_fdf Point )Interpolate (b Point ,t float64 )Point {return Point {X :(1-t )*_fdf .X +t *b .X ,Y :(1-t )*_fdf .Y +t *b .Y };};func (_fe Matrix )Angle ()float64 {_bg :=_d .Atan2 (-_fe [1],_fe [0]);if _bg < 0.0{_bg +=2*_d .Pi ;};return _bg /_d .Pi *180.0; 21 | };func (_eg Matrix )Singular ()bool {return _d .Abs (_eg [0]*_eg [4]-_eg [1]*_eg [3])< _gc };func (_ba Matrix )Mult (b Matrix )Matrix {_ba .Concat (b );return _ba };func (_ge Matrix )Transform (x ,y float64 )(float64 ,float64 ){_ac :=x *_ge [0]+y *_ge [3]+_ge [6]; 22 | _dd :=x *_ge [1]+y *_ge [4]+_ge [7];return _ac ,_dd ;};func (_ec Matrix )Identity ()bool {return _ec [0]==1&&_ec [1]==0&&_ec [2]==0&&_ec [3]==0&&_ec [4]==1&&_ec [5]==0&&_ec [6]==0&&_ec [7]==0&&_ec [8]==1;};func (_bgd *Point )transformByMatrix (_eea Matrix ){_bgd .X ,_bgd .Y =_eea .Transform (_bgd .X ,_bgd .Y )}; 23 | func (_daa *Matrix )Shear (x ,y float64 ){_daa .Concat (ShearMatrix (x ,y ))};func (_cc Matrix )ScalingFactorY ()float64 {return _d .Hypot (_cc [3],_cc [4])};func (_ca *Matrix )Concat (b Matrix ){*_ca =Matrix {b [0]*_ca [0]+b [1]*_ca [3],b [0]*_ca [1]+b [1]*_ca [4],0,b [3]*_ca [0]+b [4]*_ca [3],b [3]*_ca [1]+b [4]*_ca [4],0,b [6]*_ca [0]+b [7]*_ca [3]+_ca [6],b [6]*_ca [1]+b [7]*_ca [4]+_ca [7],1}; 24 | _ca .clampRange ();};func (_eeg *Point )Transform (a ,b ,c ,d ,tx ,ty float64 ){_gggg :=NewMatrix (a ,b ,c ,d ,tx ,ty );_eeg .transformByMatrix (_gggg );};type Matrix [9]float64 ;func (_fa *Matrix )clampRange (){for _cdg ,_ecc :=range _fa {if _ecc > _bca {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_ecc ,_bca ); 25 | _fa [_cdg ]=_bca ;}else if _ecc < -_bca {_a .Log .Debug ("\u0043L\u0041M\u0050\u003a\u0020\u0025\u0067\u0020\u002d\u003e\u0020\u0025\u0067",_ecc ,-_bca );_fa [_cdg ]=-_bca ;};};};func NewMatrix (a ,b ,c ,d ,tx ,ty float64 )Matrix {_g :=Matrix {a ,b ,0,c ,d ,0,tx ,ty ,1}; 26 | _g .clampRange ();return _g ;};func ShearMatrix (x ,y float64 )Matrix {return NewMatrix (1,y ,x ,1,0,0)};func (_fda *Matrix )Set (a ,b ,c ,d ,tx ,ty float64 ){_fda [0],_fda [1]=a ,b ;_fda [3],_fda [4]=c ,d ;_fda [6],_fda [7]=tx ,ty ;_fda .clampRange (); 27 | };func (_fdb Matrix )Translation ()(float64 ,float64 ){return _fdb [6],_fdb [7]};func (_fcc Point )Distance (b Point )float64 {return _d .Hypot (_fcc .X -b .X ,_fcc .Y -b .Y )};func (_ab *Point )Set (x ,y float64 ){_ab .X ,_ab .Y =x ,y };func (_ea Matrix )Rotate (theta float64 )Matrix {return _ea .Mult (RotationMatrix (theta ))}; 28 | func (_gb *Matrix )Clone ()Matrix {return NewMatrix (_gb [0],_gb [1],_gb [3],_gb [4],_gb [6],_gb [7])};func ScaleMatrix (x ,y float64 )Matrix {return NewMatrix (x ,0,0,y ,0,0)};func (_bb Point )Displace (delta Point )Point {return Point {_bb .X +delta .X ,_bb .Y +delta .Y }}; 29 | func TranslationMatrix (tx ,ty float64 )Matrix {return NewMatrix (1,0,0,1,tx ,ty )}; -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UniPDF - PDF for Go 2 | 3 | [UniDoc](http://unidoc.io) UniPDF is a PDF library for Go (golang) with capabilities for 4 | creating and reading, processing PDF files. The library is written and supported by 5 | [FoxyUtils.com](https://foxyutils.com), where the library is used to power many of its services. 6 | 7 | [![GitHub (pre-)release](https://img.shields.io/github/release/unidoc/unipdf/all.svg)](https://github.com/unidoc/unipdf/releases) 8 | [![License: UniDoc EULA](https://img.shields.io/badge/license-UniDoc%20EULA-blue)](https://unidoc.io/eula/) 9 | [![ApiDocs](https://img.shields.io/badge/godoc-reference-blue.svg)](https://apidocs.unidoc.io/unipdf/latest/) 10 | 11 | ## Features 12 | 13 | - [Create PDF reports](https://github.com/unidoc/unipdf-examples/blob/master/report/pdf_report.go). Example output: [unidoc-report.pdf](https://github.com/unidoc/unipdf-examples/blob/master/report/unidoc-report.pdf). 14 | - [Table PDF reports](https://github.com/unidoc/unipdf-examples/blob/master/report/pdf_tables.go). Example output: [unipdf-tables.pdf](https://github.com/unidoc/unipdf-examples/blob/master/report/unipdf-tables.pdf). 15 | - [Invoice creation](https://unidoc.io/news/simple-invoices) 16 | - [Styled paragraphs](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_formatted_text.go) 17 | - [Merge PDF pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_merge.go) 18 | - [Split PDF pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_split.go) and change page order 19 | - [Rotate pages](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_rotate.go) 20 | - [Extract text from PDF files](https://github.com/unidoc/unipdf-examples/blob/master/extract/pdf_extract_text.go) 21 | - [Text extraction support with size, position and formatting info](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_text_locations.go) 22 | - [PDF to CSV](https://github.com/unidoc/unipdf-examples/blob/master/text/pdf_to_csv.go) illustrates extracting tabular data from PDF. 23 | - [Extract images](https://github.com/unidoc/unipdf-examples/blob/master/extract/pdf_extract_images.go) with coordinates 24 | - [Images to PDF](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_images_to_pdf.go) 25 | - [Add images to pages](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_add_image_to_page.go) 26 | - [Compress and optimize PDF](https://github.com/unidoc/unipdf-examples/blob/master/compress/pdf_optimize.go) 27 | - [Watermark PDF files](https://github.com/unidoc/unipdf-examples/blob/master/image/pdf_watermark_image.go) 28 | - Advanced page manipulation: [Put 4 pages on 1](https://github.com/unidoc/unipdf-examples/blob/master/pages/pdf_4up.go) 29 | - Load PDF templates and modify 30 | - [Form creation](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_add.go) 31 | - [Fill and flatten forms](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_flatten.go) 32 | - [Fill out forms](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_fill_json.go) and [FDF merging](https://github.com/unidoc/unipdf-examples/blob/master/forms/pdf_form_fill_fdf_merge.go) 33 | - [Unlock PDF files / remove password](https://github.com/unidoc/unipdf-examples/blob/master/security/pdf_unlock.go) 34 | - [Protect PDF files with a password](https://github.com/unidoc/unipdf-examples/blob/master/security/pdf_protect.go) 35 | - [Digital signing validation and signing](https://github.com/unidoc/unipdf-examples/tree/master/signatures) 36 | - CCITTFaxDecode decoding and encoding support 37 | - JBIG2 decoding support 38 | 39 | Multiple examples are provided in our example repository https://github.com/unidoc/unipdf-examples. 40 | 41 | Contact us if you need any specific examples. 42 | 43 | ## Installation 44 | With modules: 45 | ~~~ 46 | go get github.com/unidoc/unipdf/v4 47 | ~~~ 48 | 49 | ## License key 50 | This software package (unipdf) is a commercial product and requires a license code to operate. 51 | 52 | To Get a Metered License API Key in for free in the Free Tier, sign up on https://cloud.unidoc.io 53 | 54 | 55 | ## How can I convince myself and my boss to buy unipdf rather using a free alternative? 56 | 57 | The choice is yours. There are multiple respectable efforts out there that can do many useful things. 58 | 59 | In UniDoc, we work hard to provide production quality builds taking every detail into consideration and providing excellent support to our customers. See our [testimonials](https://unidoc.io) for example. 60 | 61 | Security. We take security very seriously and we restrict access to github.com/unidoc/unipdf repository with protected branches and only the founders have access and every commit is reviewed prior to being accepted. 62 | 63 | The profits are invested back into making unipdf better. We want to make the best possible product and in order to do that we need the best people to contribute. A large fraction of the profits made goes back into developing unipdf. That way we have been able to get many excellent people to work and contribute to unipdf that would not be able to contribute their work for free. 64 | 65 | 66 | ## Contributing 67 | 68 | If you are interested in contributing, please contact us. 69 | 70 | ## Go Version Compatibility 71 | 72 | We support three latest Go versions. 73 | 74 | ## Support and consulting 75 | 76 | Please email us at support@unidoc.io for any queries. 77 | 78 | If you have any specific tasks that need to be done, we offer consulting in certain cases. 79 | Please contact us with a brief summary of what you need and we will get back to you with a quote, if appropriate. 80 | 81 | ## License agreement 82 | 83 | The use of this software package is governed by the end-user license agreement 84 | (EULA) available at: https://unidoc.io/eula/ 85 | -------------------------------------------------------------------------------- /internal/strutils/strutils.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package strutils ;import (_g "bytes";_dc "github.com/unidoc/unipdf/v4/common";_a "unicode/utf16";);func StringToPDFDocEncoding (s string )[]byte {var _df _g .Buffer ;for _ ,_ag :=range s {_fa ,_dd :=_b [_ag ];if !_dd {_dc .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0050\u0044\u0046\u0044\u006f\u0063\u0045\u006e\u0063\u006f\u0064\u0069\u006eg\u0020\u0072\u0075\u006e\u0065\u0020\u006d\u0061\u0070\u0070\u0069\u006e\u0067\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0025\u0063\u002f\u0025\u0058\u0020\u002d\u0020s\u006b\u0069\u0070\u0070\u0069n\u0067",_ag ,_ag ); 13 | continue ;};_df .WriteByte (_fa );};return _df .Bytes ();};func init (){_b =map[rune ]byte {};for _db ,_bb :=range _ec {_b [_bb ]=_db ;};};func StringToUTF16 (s string )string {_dce :=_a .Encode ([]rune (s ));var _ca _g .Buffer ;for _ ,_gb :=range _dce {_ca .WriteByte (byte ((_gb >>8)&0xff)); 14 | _ca .WriteByte (byte (_gb &0xff));};return _ca .String ();};var _b map[rune ]byte ;func PDFDocEncodingToRunes (b []byte )[]rune {var _cf []rune ;for _ ,_ab :=range b {_bc ,_be :=_ec [_ab ];if !_be {_dc .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020P\u0044\u0046\u0044o\u0063\u0045\u006ec\u006f\u0064i\u006e\u0067\u0020\u0069\u006e\u0070u\u0074 m\u0061\u0070\u0070\u0069\u006e\u0067\u0020\u0065\u0072\u0072\u006f\u0072\u0020\u0025\u0064\u0020\u002d\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067",_ab ); 15 | continue ;};_cf =append (_cf ,_bc );};return _cf ;};var _ec =map[byte ]rune {0x01:'\u0001',0x02:'\u0002',0x03:'\u0003',0x04:'\u0004',0x05:'\u0005',0x06:'\u0006',0x07:'\u0007',0x08:'\u0008',0x09:'\u0009',0x0a:'\u000a',0x0b:'\u000b',0x0c:'\u000c',0x0d:'\u000d',0x0e:'\u000e',0x0f:'\u000f',0x10:'\u0010',0x11:'\u0011',0x12:'\u0012',0x13:'\u0013',0x14:'\u0014',0x15:'\u0015',0x16:'\u0017',0x17:'\u0017',0x18:'\u02d8',0x19:'\u02c7',0x1a:'\u02c6',0x1b:'\u02d9',0x1c:'\u02dd',0x1d:'\u02db',0x1e:'\u02da',0x1f:'\u02dc',0x20:'\u0020',0x21:'\u0021',0x22:'\u0022',0x23:'\u0023',0x24:'\u0024',0x25:'\u0025',0x26:'\u0026',0x27:'\u0027',0x28:'\u0028',0x29:'\u0029',0x2a:'\u002a',0x2b:'\u002b',0x2c:'\u002c',0x2d:'\u002d',0x2e:'\u002e',0x2f:'\u002f',0x30:'\u0030',0x31:'\u0031',0x32:'\u0032',0x33:'\u0033',0x34:'\u0034',0x35:'\u0035',0x36:'\u0036',0x37:'\u0037',0x38:'\u0038',0x39:'\u0039',0x3a:'\u003a',0x3b:'\u003b',0x3c:'\u003c',0x3d:'\u003d',0x3e:'\u003e',0x3f:'\u003f',0x40:'\u0040',0x41:'\u0041',0x42:'\u0042',0x43:'\u0043',0x44:'\u0044',0x45:'\u0045',0x46:'\u0046',0x47:'\u0047',0x48:'\u0048',0x49:'\u0049',0x4a:'\u004a',0x4b:'\u004b',0x4c:'\u004c',0x4d:'\u004d',0x4e:'\u004e',0x4f:'\u004f',0x50:'\u0050',0x51:'\u0051',0x52:'\u0052',0x53:'\u0053',0x54:'\u0054',0x55:'\u0055',0x56:'\u0056',0x57:'\u0057',0x58:'\u0058',0x59:'\u0059',0x5a:'\u005a',0x5b:'\u005b',0x5c:'\u005c',0x5d:'\u005d',0x5e:'\u005e',0x5f:'\u005f',0x60:'\u0060',0x61:'\u0061',0x62:'\u0062',0x63:'\u0063',0x64:'\u0064',0x65:'\u0065',0x66:'\u0066',0x67:'\u0067',0x68:'\u0068',0x69:'\u0069',0x6a:'\u006a',0x6b:'\u006b',0x6c:'\u006c',0x6d:'\u006d',0x6e:'\u006e',0x6f:'\u006f',0x70:'\u0070',0x71:'\u0071',0x72:'\u0072',0x73:'\u0073',0x74:'\u0074',0x75:'\u0075',0x76:'\u0076',0x77:'\u0077',0x78:'\u0078',0x79:'\u0079',0x7a:'\u007a',0x7b:'\u007b',0x7c:'\u007c',0x7d:'\u007d',0x7e:'\u007e',0x80:'\u2022',0x81:'\u2020',0x82:'\u2021',0x83:'\u2026',0x84:'\u2014',0x85:'\u2013',0x86:'\u0192',0x87:'\u2044',0x88:'\u2039',0x89:'\u203a',0x8a:'\u2212',0x8b:'\u2030',0x8c:'\u201e',0x8d:'\u201c',0x8e:'\u201d',0x8f:'\u2018',0x90:'\u2019',0x91:'\u201a',0x92:'\u2122',0x93:'\ufb01',0x94:'\ufb02',0x95:'\u0141',0x96:'\u0152',0x97:'\u0160',0x98:'\u0178',0x99:'\u017d',0x9a:'\u0131',0x9b:'\u0142',0x9c:'\u0153',0x9d:'\u0161',0x9e:'\u017e',0xa0:'\u20ac',0xa1:'\u00a1',0xa2:'\u00a2',0xa3:'\u00a3',0xa4:'\u00a4',0xa5:'\u00a5',0xa6:'\u00a6',0xa7:'\u00a7',0xa8:'\u00a8',0xa9:'\u00a9',0xaa:'\u00aa',0xab:'\u00ab',0xac:'\u00ac',0xae:'\u00ae',0xaf:'\u00af',0xb0:'\u00b0',0xb1:'\u00b1',0xb2:'\u00b2',0xb3:'\u00b3',0xb4:'\u00b4',0xb5:'\u00b5',0xb6:'\u00b6',0xb7:'\u00b7',0xb8:'\u00b8',0xb9:'\u00b9',0xba:'\u00ba',0xbb:'\u00bb',0xbc:'\u00bc',0xbd:'\u00bd',0xbe:'\u00be',0xbf:'\u00bf',0xc0:'\u00c0',0xc1:'\u00c1',0xc2:'\u00c2',0xc3:'\u00c3',0xc4:'\u00c4',0xc5:'\u00c5',0xc6:'\u00c6',0xc7:'\u00c7',0xc8:'\u00c8',0xc9:'\u00c9',0xca:'\u00ca',0xcb:'\u00cb',0xcc:'\u00cc',0xcd:'\u00cd',0xce:'\u00ce',0xcf:'\u00cf',0xd0:'\u00d0',0xd1:'\u00d1',0xd2:'\u00d2',0xd3:'\u00d3',0xd4:'\u00d4',0xd5:'\u00d5',0xd6:'\u00d6',0xd7:'\u00d7',0xd8:'\u00d8',0xd9:'\u00d9',0xda:'\u00da',0xdb:'\u00db',0xdc:'\u00dc',0xdd:'\u00dd',0xde:'\u00de',0xdf:'\u00df',0xe0:'\u00e0',0xe1:'\u00e1',0xe2:'\u00e2',0xe3:'\u00e3',0xe4:'\u00e4',0xe5:'\u00e5',0xe6:'\u00e6',0xe7:'\u00e7',0xe8:'\u00e8',0xe9:'\u00e9',0xea:'\u00ea',0xeb:'\u00eb',0xec:'\u00ec',0xed:'\u00ed',0xee:'\u00ee',0xef:'\u00ef',0xf0:'\u00f0',0xf1:'\u00f1',0xf2:'\u00f2',0xf3:'\u00f3',0xf4:'\u00f4',0xf5:'\u00f5',0xf6:'\u00f6',0xf7:'\u00f7',0xf8:'\u00f8',0xf9:'\u00f9',0xfa:'\u00fa',0xfb:'\u00fb',0xfc:'\u00fc',0xfd:'\u00fd',0xfe:'\u00fe',0xff:'\u00ff'}; 16 | func UTF16ToString (b []byte )string {return string (UTF16ToRunes (b ))};func UTF16ToRunes (b []byte )[]rune {if len (b )==1{return []rune {rune (b [0])};};if len (b )%2!=0{b =append (b ,0);_dc .Log .Debug ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0055\u0054\u0046\u0031\u0036\u0054\u006f\u0052\u0075\u006e\u0065\u0073.\u0020\u0050\u0061\u0064\u0064\u0069\u006e\u0067\u0020\u0077it\u0068\u0020\u007ae\u0072o\u0073\u002e"); 17 | };_bg :=len (b )>>1;_c :=make ([]uint16 ,_bg );for _e :=0;_e < _bg ;_e ++{_c [_e ]=uint16 (b [_e <<1])<<8+uint16 (b [_e <<1+1]);};_cc :=_a .Decode (_c );return _cc ;};func PDFDocEncodingToString (b []byte )string {return string (PDFDocEncodingToRunes (b ))}; 18 | -------------------------------------------------------------------------------- /internal/textencoding/internal/syncmap/syncmap.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package syncmap ;import _a "sync";type ByteRuneMap struct{_b map[byte ]rune ;_bc _a .RWMutex ;};func (_gdb *RuneUint16Map )Length ()int {_gdb ._cgd .RLock ();defer _gdb ._cgd .RUnlock ();return len (_gdb ._cea );};func (_ebg *RuneRuneMap )Write (g rune ,r rune ){_ebg ._ad .Lock (); 13 | defer _ebg ._ad .Unlock ();_ebg ._ff [g ]=r ;};func (_eege *StringsMap )Copy ()*StringsMap {_eege ._fg .RLock ();defer _eege ._fg .RUnlock ();_abd :=map[string ]string {};for _fce ,_cde :=range _eege ._ffd {_abd [_fce ]=_cde ;};return &StringsMap {_ffd :_abd }; 14 | };func (_fdg *StringsMap )Read (g string )(string ,bool ){_fdg ._fg .RLock ();defer _fdg ._fg .RUnlock ();_ab ,_bgga :=_fdg ._ffd [g ];return _ab ,_bgga ;};func NewRuneRuneMap (m map[rune ]rune )*RuneRuneMap {return &RuneRuneMap {_ff :m }};func (_cb *RuneSet )Exists (r rune )bool {_cb ._eea .RLock (); 15 | defer _cb ._eea .RUnlock ();_ ,_db :=_cb ._fca [r ];return _db ;};func (_bcf *StringsMap )Range (f func (_agd ,_dge string )(_cbf bool )){_bcf ._fg .RLock ();defer _bcf ._fg .RUnlock ();for _gg ,_beb :=range _bcf ._ffd {if f (_gg ,_beb ){break ;};};};func (_bde *RuneRuneMap )Length ()int {_bde ._ad .RLock (); 16 | defer _bde ._ad .RUnlock ();return len (_bde ._ff );};func (_ac *ByteRuneMap )Range (f func (_be byte ,_ea rune )(_ee bool )){_ac ._bc .RLock ();defer _ac ._bc .RUnlock ();for _d ,_fe :=range _ac ._b {if f (_d ,_fe ){break ;};};};func MakeRuneByteMap (length int )*RuneByteMap {_dd :=make (map[rune ]byte ,length ); 17 | return &RuneByteMap {_ca :_dd };};func (_ag *RuneRuneMap )Read (g rune )(rune ,bool ){_ag ._ad .RLock ();defer _ag ._ad .RUnlock ();_fff ,_bd :=_ag ._ff [g ];return _fff ,_bd ;};func (_eb *ByteRuneMap )Write (b byte ,r rune ){_eb ._bc .Lock ();defer _eb ._bc .Unlock (); 18 | _eb ._b [b ]=r };func NewRuneStringMap (m map[rune ]string )*RuneStringMap {return &RuneStringMap {_cgb :m }};type StringsMap struct{_ffd map[string ]string ;_fg _a .RWMutex ;};func (_dfc *RuneUint16Map )RangeDelete (f func (_ddc rune ,_de uint16 )(_fcg bool ,_egf bool )){_dfc ._cgd .Lock (); 19 | defer _dfc ._cgd .Unlock ();for _ga ,_gd :=range _dfc ._cea {_gbea ,_af :=f (_ga ,_gd );if _gbea {delete (_dfc ._cea ,_ga );};if _af {break ;};};};func (_ec *RuneUint16Map )Write (r rune ,g uint16 ){_ec ._cgd .Lock ();defer _ec ._cgd .Unlock ();_ec ._cea [r ]=g ; 20 | };func MakeRuneUint16Map (length int )*RuneUint16Map {return &RuneUint16Map {_cea :make (map[rune ]uint16 ,length )};};func (_g *ByteRuneMap )Length ()int {_g ._bc .RLock ();defer _g ._bc .RUnlock ();return len (_g ._b )};func NewByteRuneMap (m map[byte ]rune )*ByteRuneMap {return &ByteRuneMap {_b :m }}; 21 | type RuneSet struct{_fca map[rune ]struct{};_eea _a .RWMutex ;};func NewStringsMap (tuples []StringsTuple )*StringsMap {_eba :=map[string ]string {};for _ ,_ece :=range tuples {_eba [_ece .Key ]=_ece .Value ;};return &StringsMap {_ffd :_eba };};func (_bb *RuneUint16Map )Read (r rune )(uint16 ,bool ){_bb ._cgd .RLock (); 22 | defer _bb ._cgd .RUnlock ();_fcc ,_acg :=_bb ._cea [r ];return _fcc ,_acg ;};func (_eeg *RuneUint16Map )Range (f func (_bad rune ,_ge uint16 )(_cdc bool )){_eeg ._cgd .RLock ();defer _eeg ._cgd .RUnlock ();for _fcf ,_gf :=range _eeg ._cea {if f (_fcf ,_gf ){break ; 23 | };};};func (_ae *StringRuneMap )Length ()int {_ae ._dg .RLock ();defer _ae ._dg .RUnlock ();return len (_ae ._acf );};func MakeByteRuneMap (length int )*ByteRuneMap {return &ByteRuneMap {_b :make (map[byte ]rune ,length )}};type RuneByteMap struct{_ca map[rune ]byte ; 24 | _fd _a .RWMutex ;};func (_ebge *StringRuneMap )Write (g string ,r rune ){_ebge ._dg .Lock ();defer _ebge ._dg .Unlock ();_ebge ._acf [g ]=r ;};type RuneUint16Map struct{_cea map[rune ]uint16 ;_cgd _a .RWMutex ;};func (_fdag *StringRuneMap )Range (f func (_dga string ,_cbc rune )(_cc bool )){_fdag ._dg .RLock (); 25 | defer _fdag ._dg .RUnlock ();for _bfb ,_eegg :=range _fdag ._acf {if f (_bfb ,_eegg ){break ;};};};func (_e *ByteRuneMap )Read (b byte )(rune ,bool ){_e ._bc .RLock ();defer _e ._bc .RUnlock ();_f ,_aa :=_e ._b [b ];return _f ,_aa ;};type StringRuneMap struct{_acf map[string ]rune ; 26 | _dg _a .RWMutex ;};func (_cec *RuneSet )Length ()int {_cec ._eea .RLock ();defer _cec ._eea .RUnlock ();return len (_cec ._fca );};func (_fb *StringRuneMap )Read (g string )(rune ,bool ){_fb ._dg .RLock ();defer _fb ._dg .RUnlock ();_bea ,_bdf :=_fb ._acf [g ]; 27 | return _bea ,_bdf ;};func (_bf *RuneRuneMap )Range (f func (_gbb rune ,_aac rune )(_feg bool )){_bf ._ad .RLock ();defer _bf ._ad .RUnlock ();for _df ,_eee :=range _bf ._ff {if f (_df ,_eee ){break ;};};};func MakeRuneSet (length int )*RuneSet {return &RuneSet {_fca :make (map[rune ]struct{},length )}}; 28 | func (_bef *RuneStringMap )Range (f func (_adda rune ,_eef string )(_fee bool )){_bef ._cdg .RLock ();defer _bef ._cdg .RUnlock ();for _age ,_fac :=range _bef ._cgb {if f (_age ,_fac ){break ;};};};type RuneStringMap struct{_cgb map[rune ]string ;_cdg _a .RWMutex ; 29 | };func (_fc *RuneByteMap )Read (r rune )(byte ,bool ){_fc ._fd .RLock ();defer _fc ._fd .RUnlock ();_ce ,_cd :=_fc ._ca [r ];return _ce ,_cd ;};type StringsTuple struct{Key ,Value string ;};func (_fa *RuneStringMap )Write (r rune ,s string ){_fa ._cdg .Lock (); 30 | defer _fa ._cdg .Unlock ();_fa ._cgb [r ]=s ;};func (_gbe *RuneByteMap )Range (f func (_bg rune ,_eg byte )(_ed bool )){_gbe ._fd .RLock ();defer _gbe ._fd .RUnlock ();for _fda ,_bgg :=range _gbe ._ca {if f (_fda ,_bgg ){break ;};};};func (_ebe *StringsMap )Write (g1 ,g2 string ){_ebe ._fg .Lock (); 31 | defer _ebe ._fg .Unlock ();_ebe ._ffd [g1 ]=g2 ;};func (_ef *RuneByteMap )Length ()int {_ef ._fd .RLock ();defer _ef ._fd .RUnlock ();return len (_ef ._ca )};func (_befe *RuneUint16Map )Delete (r rune ){_befe ._cgd .Lock ();defer _befe ._cgd .Unlock (); 32 | delete (_befe ._cea ,r );};func (_gb *RuneByteMap )Write (r rune ,b byte ){_gb ._fd .Lock ();defer _gb ._fd .Unlock ();_gb ._ca [r ]=b };func (_cg *RuneSet )Write (r rune ){_cg ._eea .Lock ();defer _cg ._eea .Unlock ();_cg ._fca [r ]=struct{}{}};func (_bed *RuneStringMap )Length ()int {_bed ._cdg .RLock (); 33 | defer _bed ._cdg .RUnlock ();return len (_bed ._cgb );};func (_dc *RuneSet )Range (f func (_fef rune )(_ead bool )){_dc ._eea .RLock ();defer _dc ._eea .RUnlock ();for _add :=range _dc ._fca {if f (_add ){break ;};};};func (_ba *RuneStringMap )Read (r rune )(string ,bool ){_ba ._cdg .RLock (); 34 | defer _ba ._cdg .RUnlock ();_dbd ,_ada :=_ba ._cgb [r ];return _dbd ,_ada ;};func NewStringRuneMap (m map[string ]rune )*StringRuneMap {return &StringRuneMap {_acf :m }};type RuneRuneMap struct{_ff map[rune ]rune ;_ad _a .RWMutex ;}; -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/adrg/strutil v0.2.2/go.mod h1:EF2fjOFlGTepljfI+FzgTG13oXthR7ZAil9/aginnNQ= 2 | github.com/adrg/strutil v0.3.1 h1:OLvSS7CSJO8lBii4YmBt8jiK9QOtB9CzCzwl4Ic/Fz4= 3 | github.com/adrg/strutil v0.3.1/go.mod h1:8h90y18QLrs11IBffcGX3NW/GFBXCMcNg4M7H6MspPA= 4 | github.com/adrg/sysfont v0.1.2 h1:MSU3KREM4RhsQ+7QgH7wPEPTgAgBIz0Hw6Nd4u7QgjE= 5 | github.com/adrg/sysfont v0.1.2/go.mod h1:6d3l7/BSjX9VaeXWJt9fcrftFaD/t7l11xgSywCPZGk= 6 | github.com/adrg/xdg v0.3.0/go.mod h1:7I2hH/IT30IsupOpKZ5ue7/qNi3CoKzD6tL3HwpaRMQ= 7 | github.com/adrg/xdg v0.5.3 h1:xRnxJXne7+oWDatRhR1JLnvuccuIeCoBu2rtuLqQB78= 8 | github.com/adrg/xdg v0.5.3/go.mod h1:nlTsY+NNiCBGCK2tpm09vRqfVzrc2fLmXGpBLF0zlTQ= 9 | github.com/boombuler/barcode v1.0.2 h1:79yrbttoZrLGkL/oOI8hBrUKucwOL0oOjUgEguGMcJ4= 10 | github.com/boombuler/barcode v1.0.2/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl3JlRe0mD8= 11 | github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= 12 | github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 13 | github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= 14 | github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= 15 | github.com/go-text/typesetting v0.3.0 h1:OWCgYpp8njoxSRpwrdd1bQOxdjOXDj9Rqart9ML4iF4= 16 | github.com/go-text/typesetting v0.3.0/go.mod h1:qjZLkhRgOEYMhU9eHBr3AR4sfnGJvOXNLt8yRAySFuY= 17 | github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066 h1:qCuYC+94v2xrb1PoS4NIDe7DGYtLnU2wWiQe9a1B1c0= 18 | github.com/go-text/typesetting-utils v0.0.0-20241103174707-87a29e9e6066/go.mod h1:DDxDdQEnB70R8owOx3LVpEFvpMK9eeH1o2r0yZhFI9o= 19 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46 h1:N+R2A3fGIr5GucoRMu2xpqyQWQlfY31orbofBCdjMz8= 20 | github.com/gorilla/i18n v0.0.0-20150820051429-8b358169da46/go.mod h1:2Yoiy15Cf7Q3NFwfaJquh7Mk1uGI09ytcD7CUhn8j7s= 21 | github.com/h2non/filetype v1.1.3 h1:FKkx9QbD7HR/zjK1Ia5XiBsq9zdLi5Kf3zGyFTAFkGg= 22 | github.com/h2non/filetype v1.1.3/go.mod h1:319b3zT68BvV+WRj7cwy856M2ehB3HqNOt6sy1HndBY= 23 | github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= 24 | github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= 25 | github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= 26 | github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= 27 | github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= 28 | github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= 29 | github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ= 30 | github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ= 31 | github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= 32 | github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= 33 | github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= 34 | github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= 35 | github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= 36 | github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 37 | github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 38 | github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= 39 | github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= 40 | github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= 41 | github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= 42 | github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= 43 | github.com/trimmer-io/go-xmp v1.0.0 h1:zY8bolSga5kOjBAaHS6hrdxLgEoYuT875xTy0QDwZWs= 44 | github.com/trimmer-io/go-xmp v1.0.0/go.mod h1:Aaptr9sp1lLv7UnCAdQ+gSHZyY2miYaKmcNVj7HRBwA= 45 | github.com/unidoc/freetype v0.2.3 h1:uPqW+AY0vXN6K2tvtg8dMAtHTEvvHTN52b72XpZU+3I= 46 | github.com/unidoc/freetype v0.2.3/go.mod h1:mJ/Q7JnqEoWtajJVrV6S1InbRv0K/fJerPB5SQs32KI= 47 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11 h1:kExUKrbi429KdVVuAc85z4P+W/Rk4bjGWB5KzZLl/l8= 48 | github.com/unidoc/garabic v0.0.0-20220702200334-8c7cb25baa11/go.mod h1:SX63w9Ww4+Z7E96B01OuG59SleQUb+m+dmapZ8o1Jac= 49 | github.com/unidoc/pkcs7 v0.0.0-20200411230602-d883fd70d1df/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 50 | github.com/unidoc/pkcs7 v0.3.0 h1:+RCopNCR8UoZtlf4bu4Y88O3j1MbvrLcOuQj/tbPLoU= 51 | github.com/unidoc/pkcs7 v0.3.0/go.mod h1:UEzOZUEpJfDpywVJMUT8QiugqEZC29pDq7kdIZhWCr8= 52 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a h1:RLtvUhe4DsUDl66m7MJ8OqBjq8jpWBXPK6/RKtqeTkc= 53 | github.com/unidoc/timestamp v0.0.0-20200412005513-91597fd3793a/go.mod h1:j+qMWZVpZFTvDey3zxUkSgPJZEX33tDgU/QIA0IzCUw= 54 | github.com/unidoc/unichart v0.5.1 h1:qnYavwBV5sg9NUF59KbMOqJdh2kA454nVxdDTPPtSz8= 55 | github.com/unidoc/unichart v0.5.1/go.mod h1:/8yJsL49OqBOyG53JFVZOwwDXDquo/ZRMkfz9fNsVgc= 56 | github.com/unidoc/unitype v0.5.1 h1:UwTX15K6bktwKocWVvLoijIeu4JAVEAIeFqMOjvxqQs= 57 | github.com/unidoc/unitype v0.5.1/go.mod h1:3dxbRL+f1otNqFQIRHho8fxdg3CcUKrqS8w1SXTsqcI= 58 | golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4= 59 | golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc= 60 | golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= 61 | golang.org/x/image v0.30.0 h1:jD5RhkmVAnjqaCUXfbGBrn3lpxbknfN9w2UhHHU+5B4= 62 | golang.org/x/image v0.30.0/go.mod h1:SAEUTxCCMWSrJcCy/4HwavEsfZZJlYxeHLc6tTiAe/c= 63 | golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE= 64 | golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg= 65 | golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 66 | golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI= 67 | golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= 68 | golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 69 | golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng= 70 | golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU= 71 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 72 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da h1:noIWHXmPHxILtqtCOPIhSt0ABwskkZKjD3bXGnZGpNY= 73 | golang.org/x/xerrors v0.0.0-20240903120638-7835f813f4da/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= 74 | gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 75 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= 76 | gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= 77 | gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 78 | gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= 79 | gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= 80 | software.sslmate.com/src/go-pkcs12 v0.6.0 h1:f3sQittAeF+pao32Vb+mkli+ZyT+VwKaD014qFGq6oU= 81 | software.sslmate.com/src/go-pkcs12 v0.6.0/go.mod h1:Qiz0EyvDRJjjxGyUQa2cCNZn/wMyzrRJ/qcDXOQazLI= 82 | -------------------------------------------------------------------------------- /common/common.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | // Package common contains common properties used by the subpackages. 13 | package common ;import (_c "fmt";_cf "io";_cb "os";_b "path/filepath";_g "runtime";_ef "time";); 14 | 15 | // Warning logs warning message. 16 | func (_df ConsoleLogger )Warning (format string ,args ...interface{}){if _df .LogLevel >=LogLevelWarning {_cge :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_df .output (_cb .Stdout ,_cge ,format ,args ...);};}; 17 | 18 | // Error logs error message. 19 | func (_ce WriterLogger )Error (format string ,args ...interface{}){if _ce .LogLevel >=LogLevelError {_ecc :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ce .logToWriter (_ce .Output ,_ecc ,format ,args ...);};}; 20 | 21 | // Debug does nothing for dummy logger. 22 | func (DummyLogger )Debug (format string ,args ...interface{}){}; 23 | 24 | // IsLogLevel returns true if log level is greater or equal than `level`. 25 | // Can be used to avoid resource intensive calls to loggers. 26 | func (_cc ConsoleLogger )IsLogLevel (level LogLevel )bool {return _cc .LogLevel >=level }; 27 | 28 | // NewConsoleLogger creates new console logger. 29 | func NewConsoleLogger (logLevel LogLevel )*ConsoleLogger {return &ConsoleLogger {LogLevel :logLevel }}; 30 | 31 | // SetLogger sets 'logger' to be used by the unidoc unipdf library. 32 | func SetLogger (logger Logger ){Log =logger }; 33 | 34 | // Error logs error message. 35 | func (_ffd ConsoleLogger )Error (format string ,args ...interface{}){if _ffd .LogLevel >=LogLevelError {_bbg :="\u005b\u0045\u0052\u0052\u004f\u0052\u005d\u0020";_ffd .output (_cb .Stdout ,_bbg ,format ,args ...);};};const _bee ="\u0032\u0020\u004aan\u0075\u0061\u0072\u0079\u0020\u0032\u0030\u0030\u0036\u0020\u0061\u0074\u0020\u0031\u0035\u003a\u0030\u0034"; 36 | 37 | 38 | // WriterLogger is the logger that writes data to the Output writer 39 | type WriterLogger struct{LogLevel LogLevel ;Output _cf .Writer ;}; 40 | 41 | // Debug logs debug message. 42 | func (_af ConsoleLogger )Debug (format string ,args ...interface{}){if _af .LogLevel >=LogLevelDebug {_bf :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_af .output (_cb .Stdout ,_bf ,format ,args ...);};}; 43 | 44 | // Trace logs trace message. 45 | func (_cgf WriterLogger )Trace (format string ,args ...interface{}){if _cgf .LogLevel >=LogLevelTrace {_ac :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_cgf .logToWriter (_cgf .Output ,_ac ,format ,args ...);};}; 46 | 47 | // IsLogLevel returns true from dummy logger. 48 | func (DummyLogger )IsLogLevel (level LogLevel )bool {return true }; 49 | 50 | // Info logs info message. 51 | func (_cbc WriterLogger )Info (format string ,args ...interface{}){if _cbc .LogLevel >=LogLevelInfo {_cbg :="\u005bI\u004e\u0046\u004f\u005d\u0020";_cbc .logToWriter (_cbc .Output ,_cbg ,format ,args ...);};};const (LogLevelTrace LogLevel =5;LogLevelDebug LogLevel =4; 52 | LogLevelInfo LogLevel =3;LogLevelNotice LogLevel =2;LogLevelWarning LogLevel =1;LogLevelError LogLevel =0;);func (_cce WriterLogger )logToWriter (_da _cf .Writer ,_de string ,_fg string ,_ded ...interface{}){_cfb (_da ,_de ,_fg ,_ded );};const _dc =30; 53 | 54 | 55 | // Notice does nothing for dummy logger. 56 | func (DummyLogger )Notice (format string ,args ...interface{}){};var Log Logger =DummyLogger {}; 57 | 58 | // Error does nothing for dummy logger. 59 | func (DummyLogger )Error (format string ,args ...interface{}){}; 60 | 61 | // Info does nothing for dummy logger. 62 | func (DummyLogger )Info (format string ,args ...interface{}){};const _ddc =11;func (_ec ConsoleLogger )output (_dff _cf .Writer ,_dga string ,_cfa string ,_ba ...interface{}){_cfb (_dff ,_dga ,_cfa ,_ba ...);};const Version ="\u0034\u002e\u0035.\u0030"; 63 | 64 | 65 | // Trace does nothing for dummy logger. 66 | func (DummyLogger )Trace (format string ,args ...interface{}){}; 67 | 68 | // Debug logs debug message. 69 | func (_ed WriterLogger )Debug (format string ,args ...interface{}){if _ed .LogLevel >=LogLevelDebug {_gg :="\u005b\u0044\u0045\u0042\u0055\u0047\u005d\u0020";_ed .logToWriter (_ed .Output ,_gg ,format ,args ...);};}; 70 | 71 | // Warning logs warning message. 72 | func (_gcc WriterLogger )Warning (format string ,args ...interface{}){if _gcc .LogLevel >=LogLevelWarning {_fdg :="\u005b\u0057\u0041\u0052\u004e\u0049\u004e\u0047\u005d\u0020";_gcc .logToWriter (_gcc .Output ,_fdg ,format ,args ...);};}; 73 | 74 | // Warning does nothing for dummy logger. 75 | func (DummyLogger )Warning (format string ,args ...interface{}){}; 76 | 77 | // IsLogLevel returns true if log level is greater or equal than `level`. 78 | // Can be used to avoid resource intensive calls to loggers. 79 | func (_eg WriterLogger )IsLogLevel (level LogLevel )bool {return _eg .LogLevel >=level }; 80 | 81 | // DummyLogger does nothing. 82 | type DummyLogger struct{}; 83 | 84 | // ConsoleLogger is a logger that writes logs to the 'os.Stdout' 85 | type ConsoleLogger struct{LogLevel LogLevel ;};const _beg =17; 86 | 87 | // Info logs info message. 88 | func (_bc ConsoleLogger )Info (format string ,args ...interface{}){if _bc .LogLevel >=LogLevelInfo {_bgb :="\u005bI\u004e\u0046\u004f\u005d\u0020";_bc .output (_cb .Stdout ,_bgb ,format ,args ...);};}; 89 | 90 | // Notice logs notice message. 91 | func (_bbgc ConsoleLogger )Notice (format string ,args ...interface{}){if _bbgc .LogLevel >=LogLevelNotice {_ag :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_bbgc .output (_cb .Stdout ,_ag ,format ,args ...);};};const _dfff =2025; 92 | 93 | // UtcTimeFormat returns a formatted string describing a UTC timestamp. 94 | func UtcTimeFormat (t _ef .Time )string {return t .Format (_bee )+"\u0020\u0055\u0054\u0043"};var ReleasedAt =_ef .Date (_dfff ,_ddc ,_beg ,_gee ,_dc ,0,0,_ef .UTC ); 95 | 96 | // Notice logs notice message. 97 | func (_cd WriterLogger )Notice (format string ,args ...interface{}){if _cd .LogLevel >=LogLevelNotice {_ea :="\u005bN\u004f\u0054\u0049\u0043\u0045\u005d ";_cd .logToWriter (_cd .Output ,_ea ,format ,args ...);};}; 98 | 99 | // NewWriterLogger creates new 'writer' logger. 100 | func NewWriterLogger (logLevel LogLevel ,writer _cf .Writer )*WriterLogger {_bfb :=WriterLogger {Output :writer ,LogLevel :logLevel };return &_bfb ;};func _cfb (_gdb _cf .Writer ,_dab string ,_dag string ,_egg ...interface{}){_ ,_fb ,_cbe ,_dd :=_g .Caller (3); 101 | if !_dd {_fb ="\u003f\u003f\u003f";_cbe =0;}else {_fb =_b .Base (_fb );};_bef :=_c .Sprintf ("\u0025s\u0020\u0025\u0073\u003a\u0025\u0064 ",_dab ,_fb ,_cbe )+_dag +"\u000a";_c .Fprintf (_gdb ,_bef ,_egg ...);}; 102 | 103 | // Logger is the interface used for logging in the unipdf package. 104 | type Logger interface{Error (_f string ,_d ...interface{});Warning (_bg string ,_bb ...interface{});Notice (_fd string ,_cff ...interface{});Info (_gc string ,_efg ...interface{});Debug (_ff string ,_gd ...interface{});Trace (_a string ,_cg ...interface{}); 105 | IsLogLevel (_ge LogLevel )bool ;}; 106 | 107 | // Trace logs trace message. 108 | func (_dg ConsoleLogger )Trace (format string ,args ...interface{}){if _dg .LogLevel >=LogLevelTrace {_ccb :="\u005b\u0054\u0052\u0041\u0043\u0045\u005d\u0020";_dg .output (_cb .Stdout ,_ccb ,format ,args ...);};};const _gee =15; 109 | 110 | // LogLevel is the verbosity level for logging. 111 | type LogLevel int ; -------------------------------------------------------------------------------- /internal/jbig2/decoder/arithmetic/arithmetic.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package arithmetic ;import (_fg "fmt";_ae "github.com/unidoc/unipdf/v4/common";_g "github.com/unidoc/unipdf/v4/internal/bitwise";_gc "github.com/unidoc/unipdf/v4/internal/jbig2/internal";_c "io";_a "strings";);func (_afb *Decoder )DecodeBit (stats *DecoderStats )(int ,error ){var (_dc int ; 13 | _bc =_ga [stats .cx ()][0];_dca =int32 (stats .cx ()););defer func (){_afb ._af ++}();_afb ._fa -=_bc ;if (_afb ._aee >>16)< uint64 (_bc ){_dc =_afb .lpsExchange (stats ,_dca ,_bc );if _gcg :=_afb .renormalize ();_gcg !=nil {return 0,_gcg ;};}else {_afb ._aee -=uint64 (_bc )<<16; 14 | if (_afb ._fa &0x8000)==0{_dc =_afb .mpsExchange (stats ,_dca );if _ab :=_afb .renormalize ();_ab !=nil {return 0,_ab ;};}else {_dc =int (stats .getMps ());};};return _dc ,nil ;};func New (r *_g .Reader )(*Decoder ,error ){_b :=&Decoder {_fc :r ,ContextSize :[]uint32 {16,13,10,10},ReferedToContextSize :[]uint32 {13,10}}; 15 | if _dd :=_b .init ();_dd !=nil {return nil ,_dd ;};return _b ,nil ;};func (_cd *Decoder )readByte ()error {if _cd ._fc .AbsolutePosition ()> _cd ._cb {if _ ,_gdb :=_cd ._fc .Seek (-1,_c .SeekCurrent );_gdb !=nil {return _gdb ;};};_fga ,_ce :=_cd ._fc .ReadByte (); 16 | if _ce !=nil {return _ce ;};_cd ._gf =_fga ;if _cd ._gf ==0xFF{_bf ,_fd :=_cd ._fc .ReadByte ();if _fd !=nil {return _fd ;};if _bf > 0x8F{_cd ._aee +=0xFF00;_cd ._e =8;if _ ,_fb :=_cd ._fc .Seek (-2,_c .SeekCurrent );_fb !=nil {return _fb ;};}else {_cd ._aee +=uint64 (_bf )<<9; 17 | _cd ._e =7;};}else {_fga ,_ce =_cd ._fc .ReadByte ();if _ce !=nil {return _ce ;};_cd ._gf =_fga ;_cd ._aee +=uint64 (_cd ._gf )<<8;_cd ._e =8;};_cd ._aee &=0xFFFFFFFFFF;return nil ;};func (_cdf *Decoder )decodeIntBit (_gg *DecoderStats )(int ,error ){_gg .SetIndex (int32 (_cdf ._d )); 18 | _da ,_de :=_cdf .DecodeBit (_gg );if _de !=nil {_ae .Log .Debug ("\u0041\u0072\u0069\u0074\u0068\u006d\u0065t\u0069\u0063\u0044e\u0063\u006f\u0064e\u0072\u0020'\u0064\u0065\u0063\u006f\u0064\u0065I\u006etB\u0069\u0074\u0027\u002d\u003e\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0042\u0069\u0074\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u002e\u0020\u0025\u0076",_de ); 19 | return _da ,_de ;};if _cdf ._d < 256{_cdf ._d =((_cdf ._d < 0{return -_cf ,nil ; 32 | };return 0,_gc .ErrOOB ;};type Decoder struct{ContextSize []uint32 ;ReferedToContextSize []uint32 ;_fc *_g .Reader ;_gf uint8 ;_aee uint64 ;_fa uint32 ;_d int64 ;_e int32 ;_af int32 ;_cb int64 ;};func (_gdd *DecoderStats )Reset (){for _ca :=0;_ca < len (_gdd ._bfd ); 33 | _ca ++{_gdd ._bfd [_ca ]=0;_gdd ._ddc [_ca ]=0;};};var (_ga =[][4]uint32 {{0x5601,1,1,1},{0x3401,2,6,0},{0x1801,3,9,0},{0x0AC1,4,12,0},{0x0521,5,29,0},{0x0221,38,33,0},{0x5601,7,6,1},{0x5401,8,14,0},{0x4801,9,14,0},{0x3801,10,14,0},{0x3001,11,17,0},{0x2401,12,18,0},{0x1C01,13,20,0},{0x1601,29,21,0},{0x5601,15,14,1},{0x5401,16,14,0},{0x5101,17,15,0},{0x4801,18,16,0},{0x3801,19,17,0},{0x3401,20,18,0},{0x3001,21,19,0},{0x2801,22,19,0},{0x2401,23,20,0},{0x2201,24,21,0},{0x1C01,25,22,0},{0x1801,26,23,0},{0x1601,27,24,0},{0x1401,28,25,0},{0x1201,29,26,0},{0x1101,30,27,0},{0x0AC1,31,28,0},{0x09C1,32,29,0},{0x08A1,33,30,0},{0x0521,34,31,0},{0x0441,35,32,0},{0x02A1,36,33,0},{0x0221,37,34,0},{0x0141,38,35,0},{0x0111,39,36,0},{0x0085,40,37,0},{0x0049,41,38,0},{0x0025,42,39,0},{0x0015,43,40,0},{0x0009,44,41,0},{0x0005,45,42,0},{0x0001,45,43,0},{0x5601,46,46,0}}; 34 | );func (_cba *DecoderStats )cx ()byte {return _cba ._bfd [_cba ._ad ]};func (_gfd *Decoder )mpsExchange (_gda *DecoderStats ,_aaf int32 )int {_bb :=_gda ._ddc [_gda ._ad ];if _gfd ._fa < _ga [_aaf ][0]{if _ga [_aaf ][3]==1{_gda .toggleMps ();};_gda .setEntry (int (_ga [_aaf ][2])); 35 | return int (1-_bb );};_gda .setEntry (int (_ga [_aaf ][1]));return int (_bb );};func (_fcg *DecoderStats )toggleMps (){_fcg ._ddc [_fcg ._ad ]^=1}; -------------------------------------------------------------------------------- /sanitize/sanitize.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package sanitize ;import (_f "github.com/unidoc/unipdf/v4/common";_e "github.com/unidoc/unipdf/v4/core";); 13 | 14 | // New returns a new sanitizer object. 15 | func New (opts SanitizationOpts )*Sanitizer {return &Sanitizer {_g :opts }};func (_bbd *Sanitizer )analyze (_dbd []_e .PdfObject ){_eae :=map[string ]int {};for _ ,_accg :=range _dbd {switch _eba :=_accg .(type ){case *_e .PdfIndirectObject :_fdd ,_aaag :=_e .GetDict (_eba .PdfObject ); 16 | if _aaag {if _bcc ,_dcca :=_e .GetName (_fdd .Get ("\u0054\u0079\u0070\u0065"));_dcca &&*_bcc =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_ccb :=_e .GetIndirect (_fdd .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"));_ccb {_eae ["\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"]++; 17 | };}else if _cfg ,_be :=_e .GetName (_fdd .Get ("\u0053"));_be {_ec :=_cfg .String ();if _ec =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"||_ec =="\u0055\u0052\u0049"||_ec =="\u0047\u006f\u0054\u006f"||_ec =="\u0047\u006f\u0054o\u0052"||_ec =="\u004c\u0061\u0075\u006e\u0063\u0068"{_eae [_ec ]++; 18 | }else if _ec =="\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn"{if _ ,_bf :=_e .GetStream (_fdd .Get ("\u004a\u0053"));_bf {_eae [_ec ]++;};};}else if _cbd :=_fdd .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074");_cbd !=nil {_eae ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; 19 | }else if _dd ,_cbf :=_e .GetIndirect (_fdd .Get ("\u0050\u0061\u0072\u0065\u006e\u0074"));_cbf {if _fcc ,_fdg :=_e .GetDict (_dd .PdfObject );_fdg {if _afd ,_ef :=_e .GetDict (_fcc .Get ("\u0041\u0041"));_ef {_ede :=_afd .Get ("\u004b");_gb ,_cbc :=_e .GetIndirect (_ede ); 20 | if _cbc {if _fgf ,_cac :=_e .GetDict (_gb .PdfObject );_cac {if _ddf ,_gg :=_e .GetName (_fgf .Get ("\u0053"));_gg &&*_ddf =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_eae ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++; 21 | }else if _ ,_ba :=_e .GetString (_fgf .Get ("\u004a\u0053"));_ba {_eae ["\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"]++;}else {_fge :=_afd .Get ("\u0046");if _fge !=nil {_fgd ,_cd :=_e .GetIndirect (_fge );if _cd {if _dac ,_bgb :=_e .GetDict (_fgd .PdfObject ); 22 | _bgb {if _ad ,_ege :=_e .GetName (_dac .Get ("\u0053"));_ege {_ccc :=_ad .String ();_eae [_ccc ]++;};};};};};};};};};};};};};_bbd ._aa =_eae ;}; 23 | 24 | // Optimize optimizes `objects` and returns updated list of objects. 25 | func (_d *Sanitizer )Optimize (objects []_e .PdfObject )([]_e .PdfObject ,error ){return _d .processObjects (objects );}; 26 | 27 | // Sanitizer represents a sanitizer object. 28 | // It implements the Optimizer interface to access the objects field from the writer. 29 | type Sanitizer struct{_g SanitizationOpts ;_aa map[string ]int ;};func (_c *Sanitizer )processObjects (_cc []_e .PdfObject )([]_e .PdfObject ,error ){_ca :=[]_e .PdfObject {};_ccf :=_c ._g ;for _ ,_b :=range _cc {switch _bg :=_b .(type ){case *_e .PdfIndirectObject :_dg ,_eg :=_e .GetDict (_bg ); 30 | if _eg {if _fa ,_gd :=_e .GetName (_dg .Get ("\u0054\u0079\u0070\u0065"));_gd &&*_fa =="\u0043a\u0074\u0061\u006c\u006f\u0067"{if _ ,_de :=_e .GetIndirect (_dg .Get ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"));_de &&_ccf .OpenAction {_dg .Remove ("\u004f\u0070\u0065\u006e\u0041\u0063\u0074\u0069\u006f\u006e"); 31 | };}else if _fc ,_bb :=_e .GetName (_dg .Get ("\u0053"));_bb {switch *_fc {case "\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074":if _ccf .JavaScript {if _acf ,_gf :=_e .GetStream (_dg .Get ("\u004a\u0053"));_gf {_cb :=[]byte {};_ab ,_bbe :=_e .MakeStream (_cb ,nil ); 32 | if _bbe ==nil {*_acf =*_ab ;};};_f .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e");continue ;};case "\u0055\u0052\u0049":if _ccf .URI {_f .Log .Debug ("\u0055\u0052\u0049\u0020ac\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070\u0070\u0065\u0064\u002e"); 33 | continue ;};case "\u0047\u006f\u0054\u006f":if _ccf .GoTo {_f .Log .Debug ("G\u004fT\u004f\u0020\u0061\u0063\u0074\u0069\u006f\u006e \u0073\u006b\u0069\u0070pe\u0064\u002e");continue ;};case "\u0047\u006f\u0054o\u0052":if _ccf .GoToR {_f .Log .Debug ("R\u0065\u006d\u006f\u0074\u0065\u0020G\u006f\u0054\u004f\u0020\u0061\u0063\u0074\u0069\u006fn\u0020\u0073\u006bi\u0070p\u0065\u0064\u002e"); 34 | continue ;};case "\u004c\u0061\u0075\u006e\u0063\u0068":if _ccf .Launch {_f .Log .Debug ("\u004a\u0061\u0076\u0061\u0073\u0063\u0072\u0069\u0070\u0074\u0020a\u0063\u0074\u0069\u006f\u006e\u0020\u0073\u006b\u0069\u0070p\u0065\u0064\u002e");continue ;};case "\u0052e\u006e\u0064\u0069\u0074\u0069\u006fn":if _cf ,_acc :=_e .GetStream (_dg .Get ("\u004a\u0053")); 35 | _acc {_ed :=[]byte {};_aaa ,_da :=_e .MakeStream (_ed ,nil );if _da ==nil {*_cf =*_aaa ;};};};}else if _db :=_dg .Get ("\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074");_db !=nil &&_ccf .JavaScript {continue ;}else if _dba ,_gc :=_e .GetName (_dg .Get ("\u0054\u0079\u0070\u0065")); 36 | _gc &&*_dba =="\u0041\u006e\u006eo\u0074"&&_ccf .JavaScript {if _bbb ,_gfc :=_e .GetIndirect (_dg .Get ("\u0050\u0061\u0072\u0065\u006e\u0074"));_gfc {if _ce ,_gdg :=_e .GetDict (_bbb .PdfObject );_gdg {if _bc ,_eb :=_e .GetDict (_ce .Get ("\u0041\u0041")); 37 | _eb {_fb ,_fe :=_e .GetIndirect (_bc .Get ("\u004b"));if _fe {if _dgd ,_ea :=_e .GetDict (_fb .PdfObject );_ea {if _af ,_df :=_e .GetName (_dgd .Get ("\u0053"));_df &&*_af =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_dgd .Clear (); 38 | }else if _fg :=_bc .Get ("\u0046");_fg !=nil {if _ga ,_gfe :=_e .GetIndirect (_fg );_gfe {if _ced ,_ded :=_e .GetDict (_ga .PdfObject );_ded {if _dc ,_dcc :=_e .GetName (_ced .Get ("\u0053"));_dcc &&*_dc =="\u004a\u0061\u0076\u0061\u0053\u0063\u0072\u0069\u0070\u0074"{_ced .Clear (); 39 | };};};};};};};};};};};case *_e .PdfObjectStream :_f .Log .Debug ("\u0070d\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0073t\u0072e\u0061m\u0020\u0074\u0079\u0070\u0065\u0020\u0025T",_bg );case *_e .PdfObjectStreams :_f .Log .Debug ("\u0070\u0064\u0066\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020s\u0074\u0072\u0065\u0061\u006d\u0073\u0020\u0074\u0079\u0070e\u0020\u0025\u0054",_bg ); 40 | default:_f .Log .Debug ("u\u006e\u006b\u006e\u006fwn\u0020p\u0064\u0066\u0020\u006f\u0062j\u0065\u0063\u0074\u0020\u0025\u0054",_bg );};_ca =append (_ca ,_b );};_c .analyze (_ca );return _ca ,nil ;}; 41 | 42 | // SanitizationOpts specifies the objects to be removed during sanitization. 43 | type SanitizationOpts struct{ 44 | 45 | // JavaScript specifies wether JavaScript action should be removed. JavaScript Actions, section 12.6.4.16 of PDF32000_2008 46 | JavaScript bool ; 47 | 48 | // URI specifies if URI actions should be removed. 12.6.4.7 URI Actions, PDF32000_2008. 49 | URI bool ; 50 | 51 | // GoToR removes remote GoTo actions. 12.6.4.3 Remote Go-To Actions, PDF32000_2008. 52 | GoToR bool ; 53 | 54 | // GoTo specifies wether GoTo actions should be removed. 12.6.4.2 Go-To Actions, PDF32000_2008. 55 | GoTo bool ; 56 | 57 | // RenditionJS enables removing of `JS` entry from a Rendition Action. 58 | // The `JS` entry has a value of text string or stream containing a JavaScript script that shall be executed when the action is triggered. 59 | // 12.6.4.13 Rendition Actions Table 214, PDF32000_2008. 60 | RenditionJS bool ; 61 | 62 | // OpenAction removes OpenAction entry from the document catalog. 63 | OpenAction bool ; 64 | 65 | // Launch specifies wether Launch Action should be removed. 66 | // A launch action launches an application or opens or prints a document. 67 | // 12.6.4.5 Launch Actions, PDF32000_2008. 68 | Launch bool ;}; 69 | 70 | // GetSuspiciousObjects returns a count of each detected suspicious object. 71 | func (_ceg *Sanitizer )GetSuspiciousObjects ()map[string ]int {return _ceg ._aa }; -------------------------------------------------------------------------------- /render/internal/context/context.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package context ;import (_d "errors";_ad "github.com/unidoc/freetype/truetype";_bb "github.com/unidoc/unipdf/v4/core";_c "github.com/unidoc/unipdf/v4/internal/cmap";_dc "github.com/unidoc/unipdf/v4/internal/textencoding";_fb "github.com/unidoc/unipdf/v4/internal/transform"; 13 | _g "github.com/unidoc/unipdf/v4/model";_ff "golang.org/x/image/font";_ba "image";_f "image/color";_b "strconv";_e "strings";);type Gradient interface{Pattern ;AddColorStop (_ac float64 ,_ae _f .Color );};func (_gfd *TextState )ProcTm (a ,b ,c ,d ,e ,f float64 ){_gfd .Tm =_fb .NewMatrix (a ,b ,c ,d ,e ,f ); 14 | _gfd .Tlm =_gfd .Tm .Clone ();};func (_ffg *TextFont )WithSize (size float64 ,originalFont *_g .PdfFont )*TextFont {return &TextFont {Font :_ffg .Font ,Size :size ,_eb :_ffg ._eb ,_bbc :originalFont };};func (_fbcf *TextFont )GetCharMetrics (code _dc .CharCode )(float64 ,float64 ,bool ){if _ed ,_eba :=_fbcf .Font .GetCharMetrics (code ); 15 | _eba &&_ed .Wx !=0{return _ed .Wx ,_ed .Wy ,_eba ;};if _fbcf ._bbc ==nil {return 0,0,false ;};_feeg ,_cf :=_fbcf ._bbc .GetCharMetrics (code );return _feeg .Wx ,_feeg .Wy ,_cf &&_feeg .Wx !=0;};func NewTextFont (font *_g .PdfFont ,size float64 )(*TextFont ,error ){_aed :=font .FontDescriptor (); 16 | if _aed ==nil {return nil ,_d .New ("\u0063\u006fu\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0067\u0065\u0074\u0020\u0066\u006f\u006e\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069pt\u006f\u0072");};_adeg ,_acd :=_bb .GetStream (_aed .FontFile2 );if !_acd {return nil ,_d .New ("\u006di\u0073\u0073\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020f\u0069\u006c\u0065\u0020\u0073\u0074\u0072\u0065\u0061\u006d"); 17 | };_dgde ,_cdf :=_bb .DecodeStream (_adeg );if _cdf !=nil {return nil ,_cdf ;};_cag ,_cdf :=_ad .Parse (_dgde );if _cdf !=nil {return nil ,_cdf ;};_fcb :=font .FontDescriptor ().FontName .String ();_egf :=len (_fcb )> 7&&_fcb [6]=='+';if _aed .Flags !=nil {_abe ,_eea :=_b .Atoi (_aed .Flags .String ()); 18 | if _eea ==nil &&_abe ==32{_egf =false ;};};if !_cag .HasCmap ()&&(!_e .Contains (font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-")||!_egf ){return nil ,_d .New ("\u006e\u006f c\u006d\u0061\u0070 \u0061\u006e\u0064\u0020enc\u006fdi\u006e\u0067\u0020\u0069\u0073\u0020\u006eot\u0020\u0069\u0064\u0065\u006e\u0074\u0069t\u0079"); 19 | };return &TextFont {Font :font ,Size :size ,_eb :_cag },nil ;};func (_cbge *TextFont )NewFace (size float64 )_ff .Face {return _ad .NewFace (_cbge ._eb ,&_ad .Options {Size :size });};type FillRule int ;const (LineCapRound LineCap =iota ;LineCapButt ;LineCapSquare ; 20 | );func (_dfb *TextState )ProcTStar (){_dfb .ProcTd (0,-_dfb .Tl )};func (_edcd *TextState )Reset (){_edcd .Tm =_fb .IdentityMatrix ();_edcd .Tlm =_fb .IdentityMatrix ()};func NewTextState ()TextState {return TextState {Th :100,Tm :_fb .IdentityMatrix (),Tlm :_fb .IdentityMatrix ()}; 21 | };func (_bbb *TextState )ProcTd (tx ,ty float64 ){_bbb .Tlm .Concat (_fb .TranslationMatrix (tx ,ty ));_bbb .Tm =_bbb .Tlm .Clone ();};const (TextRenderingModeFill TextRenderingMode =iota ;TextRenderingModeStroke ;TextRenderingModeFillStroke ;TextRenderingModeInvisible ; 22 | TextRenderingModeFillClip ;TextRenderingModeStrokeClip ;TextRenderingModeFillStrokeClip ;TextRenderingModeClip ;);func (_gec *TextState )ProcTf (font *TextFont ){_gec .Tf =font };func (_eca *TextState )ProcDQ (data []byte ,aw ,ac float64 ,ctx Context ){_eca .Tw =aw ; 23 | _eca .Tc =ac ;_eca .ProcQ (data ,ctx );};func (_dge *TextState )ProcQ (data []byte ,ctx Context ){_dge .ProcTStar ();_dge .ProcTj (data ,ctx )};func (_gfc *TextState )ProcTj (data []byte ,ctx Context ){_cgc :=_gfc .Tf .Size ;_ffb :=_gfc .Th /100.0;_adf :=_gfc .GlobalScale ; 24 | _fd :=_fb .NewMatrix (_cgc *_ffb ,0,0,_cgc ,0,_gfc .Ts );_fa :=ctx .Matrix ();_edc :=_fa .Clone ().Mult (_gfc .Tm .Clone ().Mult (_fd )).ScalingFactorY ();_bab :=_gfc .Tf .NewFace (_edc );_acfa :=_gfc .Tf .BytesToCharcodes (data );for _ ,_ace :=range _acfa {_cdd ,_bcd :=_gfc .Tf .CharcodeToRunes (_ace ); 25 | _dad :=string (_bcd );if _dad =="\u0000"{continue ;};_bacba :=_fa .Clone ().Mult (_gfc .Tm .Clone ().Mult (_fd ));_fgb :=_bacba .ScalingFactorY ();_bacba =_bacba .Scale (1/_fgb ,-1/_fgb );if _gfc .Tr !=TextRenderingModeInvisible {ctx .SetMatrix (_bacba ); 26 | ctx .DrawString (_dad ,_bab ,0,0);ctx .SetMatrix (_fa );};_bdaa :=0.0;if _dad =="\u0020"{_bdaa =_gfc .Tw ;};_gcc ,_ ,_baa :=_gfc .Tf .GetCharMetrics (_cdd );if _baa {_gcc =_gcc *0.001*_cgc ;}else {_gcc ,_ =ctx .MeasureString (_dad ,_bab );_gcc =_gcc /_adf ; 27 | };_bfa :=(_gcc +_gfc .Tc +_bdaa )*_ffb ;_gfc .Tm =_gfc .Tm .Mult (_fb .TranslationMatrix (_bfa ,0));};};func (_dga *TextState )Translate (tx ,ty float64 ){_dga .Tm =_dga .Tm .Mult (_fb .TranslationMatrix (tx ,ty ));};func (_bfe *TextFont )charcodeToRunesSimple (_fbc _dc .CharCode )(_dc .CharCode ,[]rune ){_dgdf :=[]_dc .CharCode {_fbc }; 28 | if _bfe .Font .IsSimple ()&&_bfe ._eb !=nil {if _cdg :=_bfe ._eb .Index (rune (_fbc ));_cdg > 0{return _fbc ,[]rune {rune (_fbc )};};};if _bfe ._eb !=nil &&!_bfe ._eb .HasCmap ()&&_e .Contains (_bfe .Font .Encoder ().String (),"\u0049d\u0065\u006e\u0074\u0069\u0074\u0079-"){if _dda :=_bfe ._eb .Index (rune (_fbc )); 29 | _dda > 0{return _fbc ,[]rune {rune (_fbc )};};};return _fbc ,_bfe .Font .CharcodesToUnicode (_dgdf );};type TextFont struct{Font *_g .PdfFont ;Size float64 ;_eb *_ad .Font ;_bbc *_g .PdfFont ;};func (_egc *TextFont )CharcodeToRunes (charcode _dc .CharCode )(_dc .CharCode ,[]rune ){_efe :=[]_dc .CharCode {charcode }; 30 | if _egc ._bbc ==nil ||_egc ._bbc ==_egc .Font {return _egc .charcodeToRunesSimple (charcode );};_gc :=_egc ._bbc .CharcodesToUnicode (_efe );_cdb ,_ :=_egc .Font .RunesToCharcodeBytes (_gc );_bfd :=_egc .Font .BytesToCharcodes (_cdb );_dcb :=charcode ; 31 | if len (_bfd )> 0&&_bfd [0]!=0{_dcb =_bfd [0];};if string (_gc )==string (_c .MissingCodeRune )&&_egc ._bbc .BaseFont ()==_egc .Font .BaseFont (){return _egc .charcodeToRunesSimple (charcode );};return _dcb ,_gc ;};func (_efb *TextFont )BytesToCharcodes (data []byte )[]_dc .CharCode {if _efb ._bbc !=nil {return _efb ._bbc .BytesToCharcodes (data ); 32 | };return _efb .Font .BytesToCharcodes (data );};type TextRenderingMode int ;type Context interface{Push ();Pop ();Matrix ()_fb .Matrix ;SetMatrix (_gg _fb .Matrix );Translate (_ga ,_ec float64 );Scale (_dg ,_dgc float64 );Rotate (_cc float64 );MoveTo (_acf ,_ggc float64 ); 33 | LineTo (_aa ,_af float64 );CubicTo (_bg ,_ea ,_ccf ,_bad ,_gf ,_ag float64 );QuadraticTo (_df ,_bgg ,_dgg ,_cd float64 );NewSubPath ();ClosePath ();ClearPath ();Clip ();ClipPreserve ();ResetClip ();LineWidth ()float64 ;SetLineWidth (_ee float64 );SetLineCap (_dd LineCap ); 34 | SetLineJoin (_cb LineJoin );SetDash (_bf ...float64 );SetDashOffset (_be float64 );Fill ();FillPreserve ();Stroke ();StrokePreserve ();SetRGBA (_fe ,_fg ,_cda ,_ade float64 );SetFillRGBA (_ab ,_dgd ,_baf ,_da float64 );SetFillStyle (_gd Pattern );SetFillRule (_bacb FillRule ); 35 | SetStrokeRGBA (_bd ,_ca ,_gfg ,_gfe float64 );SetStrokeStyle (_cbg Pattern );FillPattern ()Pattern ;StrokePattern ()Pattern ;TextState ()*TextState ;DrawString (_aeb string ,_bfg _ff .Face ,_aac ,_afd float64 );MeasureString (_fbe string ,_ef _ff .Face )(_fbg ,_bc float64 ); 36 | DrawRectangle (_bff ,_bda ,_db ,_dbf float64 );DrawImage (_fee _ba .Image ,_ddc ,_aace int );DrawImageAnchored (_gb _ba .Image ,_dcc ,_ge int ,_eg ,_gfb float64 );Height ()int ;Width ()int ;};const (FillRuleWinding FillRule =iota ;FillRuleEvenOdd ;);type Pattern interface{ColorAt (_bac ,_fc int )_f .Color ; 37 | };func NewTextFontFromPath (filePath string ,size float64 )(*TextFont ,error ){_acfc ,_aff :=_g .NewPdfFontFromTTFFile (filePath );if _aff !=nil {return nil ,_aff ;};return NewTextFont (_acfc ,size );};type LineCap int ;type LineJoin int ;const (LineJoinRound LineJoin =iota ; 38 | LineJoinBevel ;);func (_acdf *TextState )ProcTD (tx ,ty float64 ){_acdf .Tl =-ty ;_acdf .ProcTd (tx ,ty )};type TextState struct{Tc float64 ;Tw float64 ;Th float64 ;Tl float64 ;Tf *TextFont ;Ts float64 ;Tm _fb .Matrix ;Tlm _fb .Matrix ;Tr TextRenderingMode ; 39 | GlobalScale float64 ;}; -------------------------------------------------------------------------------- /internal/testutils/testutils.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package testutils ;import (_bg "crypto/md5";_d "encoding/hex";_eac "errors";_bgd "fmt";_c "github.com/unidoc/unipdf/v4/common";_dd "github.com/unidoc/unipdf/v4/core";_eb "image";_ea "image/png";_e "io";_ae "os";_be "os/exec";_a "path/filepath";_fg "strings"; 13 | _f "testing";);func RenderPDFToPNGs (pdfPath string ,dpi int ,outpathTpl string )error {if dpi <=0{dpi =100;};if _ ,_ba :=_be .LookPath ("\u0067\u0073");_ba !=nil {return ErrRenderNotSupported ;};return _be .Command ("\u0067\u0073","\u002d\u0073\u0044\u0045\u0056\u0049\u0043\u0045\u003d\u0070\u006e\u0067a\u006c\u0070\u0068\u0061","\u002d\u006f",outpathTpl ,_bgd .Sprintf ("\u002d\u0072\u0025\u0064",dpi ),pdfPath ).Run (); 14 | };func CompareDictionariesDeep (d1 ,d2 *_dd .PdfObjectDictionary )bool {if len (d1 .Keys ())!=len (d2 .Keys ()){_c .Log .Debug ("\u0044\u0069\u0063\u0074\u0020\u0065\u006e\u0074\u0072\u0069\u0065\u0073\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",len (d1 .Keys ()),len (d2 .Keys ())); 15 | _c .Log .Debug ("\u0057\u0061s\u0020\u0027\u0025s\u0027\u0020\u0076\u0073\u0020\u0027\u0025\u0073\u0027",d1 .Write (),d2 .Write ());return false ;};for _ ,_dfa :=range d1 .Keys (){if _dfa =="\u0050\u0061\u0072\u0065\u006e\u0074"{continue ;};_dc :=_dd .TraceToDirectObject (d1 .Get (_dfa )); 16 | _cae :=_dd .TraceToDirectObject (d2 .Get (_dfa ));if _dc ==nil {_c .Log .Debug ("\u00761\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};if _cae ==nil {_c .Log .Debug ("\u00762\u0020\u0069\u0073\u0020\u006e\u0069l");return false ;};switch _ebb :=_dc .(type ){case *_dd .PdfObjectDictionary :_gb ,_bac :=_cae .(*_dd .PdfObjectDictionary ); 17 | if !_bac {_c .Log .Debug ("\u0054\u0079\u0070\u0065 m\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0020\u0025\u0054\u0020\u0076\u0073\u0020%\u0054",_dc ,_cae );return false ;};if !CompareDictionariesDeep (_ebb ,_gb ){return false ;};continue ;case *_dd .PdfObjectArray :_fga ,_ag :=_cae .(*_dd .PdfObjectArray ); 18 | if !_ag {_c .Log .Debug ("\u00762\u0020n\u006f\u0074\u0020\u0061\u006e\u0020\u0061\u0072\u0072\u0061\u0079");return false ;};if _ebb .Len ()!=_fga .Len (){_c .Log .Debug ("\u0061\u0072\u0072\u0061\u0079\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u006d\u0069s\u006da\u0074\u0063\u0068\u0020\u0028\u0025\u0064\u0020\u0021\u003d\u0020\u0025\u0064\u0029",_ebb .Len (),_fga .Len ()); 19 | return false ;};for _bae :=0;_bae < _ebb .Len ();_bae ++{_cdd :=_dd .TraceToDirectObject (_ebb .Get (_bae ));_gbf :=_dd .TraceToDirectObject (_fga .Get (_bae ));if _gcb ,_edca :=_cdd .(*_dd .PdfObjectDictionary );_edca {_gee ,_ced :=_gbf .(*_dd .PdfObjectDictionary ); 20 | if !_ced {return false ;};if !CompareDictionariesDeep (_gcb ,_gee ){return false ;};}else {_dda :=_cdd .Write ();_fde :=_gbf .Write ();if string (_dda )!=string (_fde ){_c .Log .Debug ("M\u0069\u0073\u006d\u0061tc\u0068 \u0027\u0025\u0073\u0027\u0020!\u003d\u0020\u0027\u0025\u0073\u0027",_dda ,_fde ); 21 | return false ;};};};continue ;};if _dc .String ()!=_cae .String (){_c .Log .Debug ("\u006b\u0065y\u003d\u0025\u0073\u0020\u004d\u0069\u0073\u006d\u0061\u0074\u0063\u0068\u0021\u0020\u0027\u0025\u0073\u0027\u0020\u0021\u003d\u0020'%\u0073\u0027",_dfa ,_dc .String (),_cae .String ()); 22 | _c .Log .Debug ("\u0046o\u0072 \u0027\u0025\u0054\u0027\u0020\u002d\u0020\u0027\u0025\u0054\u0027",_dc ,_cae );_c .Log .Debug ("\u0046\u006f\u0072\u0020\u0027\u0025\u002b\u0076\u0027\u0020\u002d\u0020'\u0025\u002b\u0076\u0027",_dc ,_cae );return false ; 23 | };};return true ;};func CopyFile (src ,dst string )error {_g ,_ddd :=_ae .Open (src );if _ddd !=nil {return _ddd ;};defer _g .Close ();_da ,_ddd :=_ae .Create (dst );if _ddd !=nil {return _ddd ;};defer _da .Close ();_ ,_ddd =_e .Copy (_da ,_g );return _ddd ; 24 | };func ParseIndirectObjects (rawpdf string )(map[int64 ]_dd .PdfObject ,error ){_gfd :=_dd .NewParserFromString (rawpdf );_cea :=map[int64 ]_dd .PdfObject {};for {_bd ,_daf :=_gfd .ParseIndirectObject ();if _daf !=nil {if _daf ==_e .EOF {break ;};return nil ,_daf ; 25 | };switch _eec :=_bd .(type ){case *_dd .PdfIndirectObject :_cea [_eec .ObjectNumber ]=_bd ;case *_dd .PdfObjectStream :_cea [_eec .ObjectNumber ]=_bd ;};};for _ ,_beb :=range _cea {_ge (_beb ,_cea );};return _cea ,nil ;};func _ge (_cead _dd .PdfObject ,_bc map[int64 ]_dd .PdfObject )error {switch _eag :=_cead .(type ){case *_dd .PdfIndirectObject :_fef :=_eag ; 26 | _ge (_fef .PdfObject ,_bc );case *_dd .PdfObjectDictionary :_ccd :=_eag ;for _ ,_edg :=range _ccd .Keys (){_db :=_ccd .Get (_edg );if _dac ,_gc :=_db .(*_dd .PdfObjectReference );_gc {_ecf ,_ecd :=_bc [_dac .ObjectNumber ];if !_ecd {return _eac .New ("r\u0065\u0066\u0065\u0072\u0065\u006ec\u0065\u0020\u0074\u006f\u0020\u006f\u0075\u0074\u0073i\u0064\u0065\u0020o\u0062j\u0065\u0063\u0074"); 27 | };_ccd .Set (_edg ,_ecf );}else {_ge (_db ,_bc );};};case *_dd .PdfObjectArray :_dgd :=_eag ;for _cb ,_ede :=range _dgd .Elements (){if _cbf ,_bgg :=_ede .(*_dd .PdfObjectReference );_bgg {_fd ,_dfg :=_bc [_cbf .ObjectNumber ];if !_dfg {return _eac .New ("r\u0065\u0066\u0065\u0072\u0065\u006ec\u0065\u0020\u0074\u006f\u0020\u006f\u0075\u0074\u0073i\u0064\u0065\u0020o\u0062j\u0065\u0063\u0074"); 28 | };_dgd .Set (_cb ,_fd );}else {_ge (_ede ,_bc );};};};return nil ;};func CompareImages (img1 ,img2 _eb .Image )(bool ,error ){_fb :=img1 .Bounds ();_afg :=0;for _cf :=0;_cf < _fb .Size ().X ;_cf ++{for _fa :=0;_fa < _fb .Size ().Y ;_fa ++{_dg ,_dga ,_ed ,_ :=img1 .At (_cf ,_fa ).RGBA (); 29 | _cc ,_dad ,_ab ,_ :=img2 .At (_cf ,_fa ).RGBA ();if _dg !=_cc ||_dga !=_dad ||_ed !=_ab {_afg ++;};};};_ebd :=float64 (_afg )/float64 (_fb .Dx ()*_fb .Dy ());if _ebd > 0.0001{_bgd .Printf ("\u0064\u0069\u0066f \u0066\u0072\u0061\u0063\u0074\u0069\u006f\u006e\u003a\u0020\u0025\u0076\u0020\u0028\u0025\u0064\u0029\u000a",_ebd ,_afg ); 30 | return false ,nil ;};return true ,nil ;};func ComparePNGFiles (file1 ,file2 string )(bool ,error ){_edc ,_eg :=HashFile (file1 );if _eg !=nil {return false ,_eg ;};_ffc ,_eg :=HashFile (file2 );if _eg !=nil {return false ,_eg ;};if _edc ==_ffc {return true ,nil ; 31 | };_dae ,_eg :=ReadPNG (file1 );if _eg !=nil {return false ,_eg ;};_cd ,_eg :=ReadPNG (file2 );if _eg !=nil {return false ,_eg ;};if _dae .Bounds ()!=_cd .Bounds (){return false ,nil ;};return CompareImages (_dae ,_cd );};var (ErrRenderNotSupported =_eac .New ("\u0072\u0065\u006e\u0064\u0065r\u0069\u006e\u0067\u0020\u0050\u0044\u0046\u0020\u0066\u0069\u006c\u0065\u0073 \u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u006f\u006e\u0020\u0074\u0068\u0069\u0073\u0020\u0073\u0079\u0073\u0074\u0065m"); 32 | );func HashFile (file string )(string ,error ){_ef ,_fe :=_ae .Open (file );if _fe !=nil {return "",_fe ;};defer _ef .Close ();_efb :=_bg .New ();if _ ,_fe =_e .Copy (_efb ,_ef );_fe !=nil {return "",_fe ;};return _d .EncodeToString (_efb .Sum (nil )),nil ; 33 | };func RunRenderTest (t *_f .T ,pdfPath ,outputDir ,baselineRenderPath string ,saveBaseline bool ){_ee :=_fg .TrimSuffix (_a .Base (pdfPath ),_a .Ext (pdfPath ));t .Run ("\u0072\u0065\u006e\u0064\u0065\u0072",func (_bb *_f .T ){_ec :=_a .Join (outputDir ,_ee ); 34 | _fea :=_ec +"\u002d%\u0064\u002e\u0070\u006e\u0067";if _ceb :=RenderPDFToPNGs (pdfPath ,0,_fea );_ceb !=nil {_bb .Skip (_ceb );};for _ca :=1;true ;_ca ++{_abf :=_bgd .Sprintf ("\u0025s\u002d\u0025\u0064\u002e\u0070\u006eg",_ec ,_ca );_dde :=_a .Join (baselineRenderPath ,_bgd .Sprintf ("\u0025\u0073\u002d\u0025\u0064\u005f\u0065\u0078\u0070\u002e\u0070\u006e\u0067",_ee ,_ca )); 35 | if _ ,_fgg :=_ae .Stat (_abf );_fgg !=nil {break ;};_bb .Logf ("\u0025\u0073",_dde );if saveBaseline {_bb .Logf ("\u0043\u006fp\u0079\u0069\u006eg\u0020\u0025\u0073\u0020\u002d\u003e\u0020\u0025\u0073",_abf ,_dde );_gg :=CopyFile (_abf ,_dde );if _gg !=nil {_bb .Fatalf ("\u0045\u0052\u0052OR\u0020\u0063\u006f\u0070\u0079\u0069\u006e\u0067\u0020\u0074\u006f\u0020\u0025\u0073\u003a\u0020\u0025\u0076",_dde ,_gg ); 36 | };continue ;};_bb .Run (_bgd .Sprintf ("\u0070\u0061\u0067\u0065\u0025\u0064",_ca ),func (_egd *_f .T ){_egd .Logf ("\u0043o\u006dp\u0061\u0072\u0069\u006e\u0067 \u0025\u0073 \u0076\u0073\u0020\u0025\u0073",_abf ,_dde );_edb ,_bbc :=ComparePNGFiles (_abf ,_dde ); 37 | if _ae .IsNotExist (_bbc ){_egd .Fatal ("\u0069m\u0061g\u0065\u0020\u0066\u0069\u006ce\u0020\u006di\u0073\u0073\u0069\u006e\u0067");}else if !_edb {_egd .Fatal ("\u0077\u0072\u006f\u006eg \u0070\u0061\u0067\u0065\u0020\u0072\u0065\u006e\u0064\u0065\u0072\u0065\u0064"); 38 | };});};});};func ReadPNG (file string )(_eb .Image ,error ){_af ,_ff :=_ae .Open (file );if _ff !=nil {return nil ,_ff ;};defer _af .Close ();return _ea .Decode (_af );}; -------------------------------------------------------------------------------- /internal/integrations/unichart/unichart.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package unichart ;import (_e "bytes";_a "fmt";_ef "github.com/unidoc/unichart/render";_gf "github.com/unidoc/unipdf/v4/common";_eda "github.com/unidoc/unipdf/v4/contentstream";_ed "github.com/unidoc/unipdf/v4/contentstream/draw";_ae "github.com/unidoc/unipdf/v4/core"; 13 | _b "github.com/unidoc/unipdf/v4/model";_ec "image/color";_c "io";_gc "math";);func (_bce *Renderer )SetStrokeColor (color _ec .Color ){_bce ._gfc =color ;_be ,_ecb ,_bf ,_ :=_ece (color );_bce ._cf .Add_RG (_be ,_ecb ,_bf );};func (_ddf *Renderer )SetFontColor (color _ec .Color ){_ddf ._fc =color }; 14 | func (_fe *Renderer )LineTo (x ,y int ){_fe ._cf .Add_l (float64 (x ),float64 (y ))};func (_gac *Renderer )ClearTextRotation (){_gac ._bb =0};func _fde (_ebb float64 )float64 {return _ebb *_gc .Pi /180.0};func _fga (_ada string ,_acf int ,_fgg func (_ae .PdfObjectName )bool )_ae .PdfObjectName {_ebc :=_ae .PdfObjectName (_a .Sprintf ("\u0025\u0073\u0025\u0064",_ada ,_acf )); 15 | for _cc :=_acf ;_fgg (_ebc );{_cc ++;_ebc =_ae .PdfObjectName (_a .Sprintf ("\u0025\u0073\u0025\u0064",_ada ,_cc ));};return _ebc ;};func (_ce *Renderer )Stroke (){_ce ._cf .Add_S ()};func (_ga *Renderer )Circle (radius float64 ,x ,y int ){_abg :=radius ; 16 | if _ea :=_ga ._dd ;_ea !=0{_abg -=_ea /2;};_agd :=_abg *0.551784;_bfb :=_ed .CubicBezierPath {Curves :[]_ed .CubicBezierCurve {_ed .NewCubicBezierCurve (-_abg ,0,-_abg ,_agd ,-_agd ,_abg ,0,_abg ),_ed .NewCubicBezierCurve (0,_abg ,_agd ,_abg ,_abg ,_agd ,_abg ,0),_ed .NewCubicBezierCurve (_abg ,0,_abg ,-_agd ,_agd ,-_abg ,0,-_abg ),_ed .NewCubicBezierCurve (0,-_abg ,-_agd ,-_abg ,-_abg ,-_agd ,-_abg ,0)}}; 17 | if _cdf :=_ga ._dd ;_cdf !=0{_bfb =_bfb .Offset (_cdf /2,_cdf /2);};_bfb =_bfb .Offset (float64 (x ),float64 (y ));_ed .DrawBezierPathWithCreator (_bfb ,_ga ._cf );};func (_fd *Renderer )SetStrokeWidth (width float64 ){_fd ._dd =width ;_fd ._cf .Add_w (width )}; 18 | func (_cbd *Renderer )Save (w _c .Writer )error {if w ==nil {return nil ;};_ ,_cbf :=_c .Copy (w ,_e .NewBuffer (_cbd ._cf .Bytes ()));return _cbf ;};type Renderer struct{_bc int ;_d int ;_dg float64 ;_cf *_eda .ContentCreator ;_gb *_b .PdfPageResources ; 19 | _ee _ec .Color ;_gfc _ec .Color ;_dd float64 ;_gd *_b .PdfFont ;_f float64 ;_fc _ec .Color ;_bb float64 ;_ag map[*_b .PdfFont ]_ae .PdfObjectName ;};func (_dafg *Renderer )getTextWidth (_ffd string )float64 {var _ffc float64 ;for _ ,_fcb :=range _ffd {_bda ,_cee :=_dafg ._gd .GetRuneMetrics (_fcb ); 20 | if !_cee {_gf .Log .Debug ("\u0045\u0052\u0052OR\u003a\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006fr\u0074e\u0064 \u0072u\u006e\u0065\u0020\u0025\u0076\u0020\u0069\u006e\u0020\u0066\u006f\u006e\u0074",_fcb );};_ffc +=_bda .Wx ;};return _dafg ._f *_ffc /1000.0; 21 | };func (_gba *Renderer )wrapText (_dcd string )[]string {var (_dge []string ;_cea []rune ;);for _ ,_cdeb :=range _dcd {if _cdeb =='\n'{_dge =append (_dge ,string (_cea ));_cea =[]rune {};continue ;};_cea =append (_cea ,_cdeb );};if len (_cea )> 0{_dge =append (_dge ,string (_cea )); 22 | };return _dge ;};func (_eb *Renderer )SetFont (font _ef .Font ){_aac ,_bbe :=font .(*_b .PdfFont );if !_bbe {_gf .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0069\u006e\u0076\u0061\u006c\u0069d\u0020\u0066\u006f\u006e\u0074\u0020\u0074\u0079\u0070\u0065"); 23 | return ;};_ad ,_bbe :=_eb ._ag [_aac ];if !_bbe {_ad =_fga ("\u0046\u006f\u006e\u0074",1,_eb ._gb .HasFontByName );if _bag :=_eb ._gb .SetFontByName (_ad ,_aac .ToPdfObject ());_bag !=nil {_gf .Log .Debug ("\u0045\u0052\u0052\u004f\u0052:\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0061\u0064d\u0020\u0066\u006f\u006e\u0074\u0020\u0025\u0076\u0020\u0074\u006f\u0020\u0072\u0065\u0073\u006f\u0075\u0072\u0063\u0065\u0073",_aac ); 24 | };_eb ._ag [_aac ]=_ad ;};_eb ._cf .Add_Tf (_ad ,_eb ._f );_eb ._gd =_aac ;};func (_eca *Renderer )MoveTo (x ,y int ){_eca ._cf .Add_m (float64 (x ),float64 (y ))};func (_cab *Renderer )FillStroke (){_cab ._cf .Add_B ()};func (_aa *Renderer )SetClassName (name string ){}; 25 | func (_ca *Renderer )SetDPI (dpi float64 ){_ca ._dg =dpi };func NewRenderer (cc *_eda .ContentCreator ,res *_b .PdfPageResources )func (int ,int )(_ef .Renderer ,error ){return func (_dc ,_df int )(_ef .Renderer ,error ){_da :=&Renderer {_bc :_dc ,_d :_df ,_dg :72,_cf :cc ,_gb :res ,_ag :map[*_b .PdfFont ]_ae .PdfObjectName {}}; 26 | _da .ResetStyle ();return _da ,nil ;};};func (_cd *Renderer )Close (){_cd ._cf .Add_h ()};func (_dfg *Renderer )Text (text string ,x ,y int ){_dfg ._cf .Add_q ();_dfg .SetFont (_dfg ._gd );_cde ,_bed ,_db ,_ :=_ece (_dfg ._fc );_dfg ._cf .Add_rg (_cde ,_bed ,_db ); 27 | _dfg ._cf .Translate (float64 (x ),float64 (y )).Scale (1,-1);if _bceb :=_dfg ._bb ;_bceb !=0{_dfg ._cf .RotateDeg (_bceb );};_dfg ._cf .Add_BT ().Add_TL (_dfg ._f );var (_gcg =_dfg ._gd .Encoder ();_faf =_dfg .wrapText (text );_ddg =len (_faf ););for _bfd ,_ffg :=range _faf {_dfg ._cf .Add_TJ (_ae .MakeStringFromBytes (_gcg .Encode (_ffg ))); 28 | if _bfd !=_ddg -1{_dfg ._cf .Add_Tstar ();};};_dfg ._cf .Add_ET ();_dfg ._cf .Add_Q ();};func _bdb (_bbed float64 )float64 {return _bbed *180/_gc .Pi };func (_bgf *Renderer )MeasureText (text string )_ef .Box {_gab :=_bgf ._f ;_gg ,_cabb :=_bgf ._gd .GetFontDescriptor (); 29 | if _cabb !=nil {_gf .Log .Debug ("W\u0041\u0052\u004e\u003a\u0020\u0055n\u0061\u0062\u006c\u0065\u0020\u0074o\u0020\u0067\u0065\u0074\u0020\u0066\u006fn\u0074\u0020\u0064\u0065\u0073\u0063\u0072\u0069\u0070\u0074o\u0072");}else {_acc ,_cfa :=_gg .GetCapHeight (); 30 | if _cfa !=nil {_gf .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0055\u006e\u0061\u0062\u006c\u0065\u0020t\u006f\u0020\u0067\u0065\u0074\u0020f\u006f\u006e\u0074\u0020\u0063\u0061\u0070\u0020\u0068\u0065\u0069\u0067\u0068t\u003a\u0020\u0025\u0076",_cfa ); 31 | }else {_gab =_acc /1000.0*_bgf ._f ;};};var (_gbea =0.0;_aaff =_bgf .wrapText (text ););for _ ,_ecac :=range _aaff {if _bge :=_bgf .getTextWidth (_ecac );_bge > _gbea {_gbea =_bge ;};};_gbd :=_ef .NewBox (0,0,int (_gbea ),int (_gab ));if _cac :=_bgf ._bb ; 32 | _cac !=0{_gbd =_gbd .Corners ().Rotate (_cac ).Box ();};return _gbd ;};func (_fa *Renderer )SetFontSize (size float64 ){_fa ._f =size };func (_ba *Renderer )GetDPI ()float64 {return _ba ._dg };func (_bd *Renderer )QuadCurveTo (cx ,cy ,x ,y int ){_bd ._cf .Add_v (float64 (x ),float64 (y ),float64 (cx ),float64 (cy )); 33 | };func (_bcg *Renderer )ArcTo (cx ,cy int ,rx ,ry ,startAngle ,deltaAngle float64 ){startAngle =_bdb (2.0*_gc .Pi -startAngle );deltaAngle =_bdb (-deltaAngle );_dab ,_de :=deltaAngle ,1;if _gc .Abs (deltaAngle )> 90.0{_de =int (_gc .Ceil (_gc .Abs (deltaAngle )/90.0)); 34 | _dab =deltaAngle /float64 (_de );};var (_aaf =_fde (_dab /2);_ecf =_gc .Abs (4.0/3.0*(1.0-_gc .Cos (_aaf ))/_gc .Sin (_aaf ));_af =float64 (cx );_edf =float64 (cy ););for _deg :=0;_deg < _de ;_deg ++{_gbe :=_fde (startAngle +float64 (_deg )*_dab );_afg :=_fde (startAngle +float64 (_deg +1)*_dab ); 35 | _cb :=_gc .Cos (_gbe );_dgb :=_gc .Cos (_afg );_bbc :=_gc .Sin (_gbe );_edd :=_gc .Sin (_afg );var _gfff []float64 ;if _dab > 0{_gfff =[]float64 {_af +rx *_cb ,_edf -ry *_bbc ,_af +rx *(_cb -_ecf *_bbc ),_edf -ry *(_bbc +_ecf *_cb ),_af +rx *(_dgb +_ecf *_edd ),_edf -ry *(_edd -_ecf *_dgb ),_af +rx *_dgb ,_edf -ry *_edd }; 36 | }else {_gfff =[]float64 {_af +rx *_cb ,_edf -ry *_bbc ,_af +rx *(_cb +_ecf *_bbc ),_edf -ry *(_bbc -_ecf *_cb ),_af +rx *(_dgb -_ecf *_edd ),_edf -ry *(_edd +_ecf *_dgb ),_af +rx *_dgb ,_edf -ry *_edd };};if _deg ==0{_bcg ._cf .Add_l (_gfff [0],_gfff [1]); 37 | };_bcg ._cf .Add_c (_gfff [2],_gfff [3],_gfff [4],_gfff [5],_gfff [6],_gfff [7]);};};func _ece (_gaa _ec .Color )(float64 ,float64 ,float64 ,float64 ){_eaf ,_adg ,_ecfd ,_bga :=_dag (_gaa );return float64 (_eaf )/255,float64 (_adg )/255,float64 (_ecfd )/255,float64 (_bga )/255; 38 | };func _dag (_bad _ec .Color )(uint8 ,uint8 ,uint8 ,uint8 ){_fae ,_aacd ,_bgd ,_fab :=_bad .RGBA ();return uint8 (_fae >>8),uint8 (_aacd >>8),uint8 (_bgd >>8),uint8 (_fab >>8);};func (_cg *Renderer )Fill (){_cg ._cf .Add_f ()};func (_eea *Renderer )ResetStyle (){_eea .SetFillColor (_ec .Black ); 39 | _eea .SetStrokeColor (_ec .Transparent );_eea .SetStrokeWidth (0);_eea .SetFont (_b .DefaultFont ());_eea .SetFontColor (_ec .Black );_eea .SetFontSize (12);_eea .SetTextRotation (0);};func (_ffa *Renderer )SetTextRotation (radians float64 ){_ffa ._bb =_bdb (-radians )}; 40 | func (_bg *Renderer )SetStrokeDashArray (dashArray []float64 ){_daf :=make ([]int64 ,len (dashArray ));for _bcf ,_bae :=range dashArray {_daf [_bcf ]=int64 (_bae );};_bg ._cf .Add_d (_daf ,0);};func (_ab *Renderer )SetFillColor (color _ec .Color ){_ab ._ee =color ; 41 | _ff ,_fg ,_gff ,_ :=_ece (color );_ab ._cf .Add_rg (_ff ,_fg ,_gff );}; -------------------------------------------------------------------------------- /model/sigutil/sigutil.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package sigutil ;import (_e "bytes";_fa "crypto";_fac "crypto/x509";_fe "encoding/asn1";_fc "encoding/pem";_cd "errors";_cb "fmt";_fcd "github.com/unidoc/timestamp";_ga "github.com/unidoc/unipdf/v4/common";_a "golang.org/x/crypto/ocsp";_g "io";_ce "net/http"; 13 | _f "time";); 14 | 15 | // NewTimestampRequest returns a new timestamp request based 16 | // on the specified options. 17 | func NewTimestampRequest (body _g .Reader ,opts *_fcd .RequestOptions )(*_fcd .Request ,error ){if opts ==nil {opts =&_fcd .RequestOptions {};};if opts .Hash ==0{opts .Hash =_fa .SHA256 ;};if !opts .Hash .Available (){return nil ,_fac .ErrUnsupportedAlgorithm ; 18 | };_cae :=opts .Hash .New ();if _ ,_bb :=_g .Copy (_cae ,body );_bb !=nil {return nil ,_bb ;};return &_fcd .Request {HashAlgorithm :opts .Hash ,HashedMessage :_cae .Sum (nil ),Certificates :opts .Certificates ,TSAPolicyOID :opts .TSAPolicyOID ,Nonce :opts .Nonce },nil ; 19 | }; 20 | 21 | // MakeRequest makes a OCSP request to the specified server and returns 22 | // the parsed and raw responses. If a server URL is not provided, it is 23 | // extracted from the certificate. 24 | func (_facb *OCSPClient )MakeRequest (serverURL string ,cert ,issuer *_fac .Certificate )(*_a .Response ,[]byte ,error ){if _facb .HTTPClient ==nil {_facb .HTTPClient =_fgbe ();};if serverURL ==""{if len (cert .OCSPServer )==0{return nil ,nil ,_cd .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"); 25 | };serverURL =cert .OCSPServer [0];};_fd ,_ffe :=_a .CreateRequest (cert ,issuer ,&_a .RequestOptions {Hash :_facb .Hash });if _ffe !=nil {return nil ,nil ,_ffe ;};_bg ,_ffe :=_facb .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",_e .NewReader (_fd )); 26 | if _ffe !=nil {return nil ,nil ,_ffe ;};defer _bg .Body .Close ();_da ,_ffe :=_g .ReadAll (_bg .Body );if _ffe !=nil {return nil ,nil ,_ffe ;};if _gec ,_ :=_fc .Decode (_da );_gec !=nil {_da =_gec .Bytes ;};_ac ,_ffe :=_a .ParseResponseForCert (_da ,cert ,issuer ); 27 | if _ffe !=nil {return nil ,nil ,_ffe ;};return _ac ,_da ,nil ;}; 28 | 29 | // GetEncodedToken executes the timestamp request and returns the DER encoded 30 | // timestamp token bytes. 31 | func (_bge *TimestampClient )GetEncodedToken (serverURL string ,req *_fcd .Request )([]byte ,error ){if serverURL ==""{return nil ,_cb .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"); 32 | };if req ==nil {return nil ,_cb .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");};_af ,_fef :=req .Marshal ();if _fef !=nil {return nil ,_fef ; 33 | };_fff ,_fef :=_ce .NewRequest ("\u0050\u004f\u0053\u0054",serverURL ,_e .NewBuffer (_af ));if _fef !=nil {return nil ,_fef ;};_fff .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065","a\u0070\u0070\u006c\u0069\u0063\u0061t\u0069\u006f\u006e\u002f\u0074\u0069\u006d\u0065\u0073t\u0061\u006d\u0070-\u0071u\u0065\u0072\u0079"); 34 | if _bge .BeforeHTTPRequest !=nil {if _be :=_bge .BeforeHTTPRequest (_fff );_be !=nil {return nil ,_be ;};};_cag :=_bge .HTTPClient ;if _cag ==nil {_cag =_fgbe ();};_feg ,_fef :=_cag .Do (_fff );if _fef !=nil {return nil ,_fef ;};defer _feg .Body .Close (); 35 | _ae ,_fef :=_g .ReadAll (_feg .Body );if _fef !=nil {return nil ,_fef ;};if _feg .StatusCode !=_ce .StatusOK {return nil ,_cb .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",_feg .StatusCode ); 36 | };var _fgb struct{Version _fe .RawValue ;Content _fe .RawValue ;};if _ ,_fef =_fe .Unmarshal (_ae ,&_fgb );_fef !=nil {return nil ,_fef ;};return _fgb .Content .FullBytes ,nil ;}; 37 | 38 | // OCSPClient represents a OCSP (Online Certificate Status Protocol) client. 39 | // It is used to request revocation data from OCSP servers. 40 | type OCSPClient struct{ 41 | 42 | // HTTPClient is the HTTP client used to make OCSP requests. 43 | // By default, an HTTP client with a 5 second timeout per request is used. 44 | HTTPClient *_ce .Client ; 45 | 46 | // Hash is the hash function used when constructing the OCSP 47 | // requests. If zero, SHA-1 will be used. 48 | Hash _fa .Hash ;}; 49 | 50 | // IsCA returns true if the provided certificate appears to be a CA certificate. 51 | func (_b *CertClient )IsCA (cert *_fac .Certificate )bool {return cert .IsCA &&_e .Equal (cert .RawIssuer ,cert .RawSubject );}; 52 | 53 | // TimestampClient represents a RFC 3161 timestamp client. 54 | // It is used to obtain signed tokens from timestamp authority servers. 55 | type TimestampClient struct{ 56 | 57 | // HTTPClient is the HTTP client used to make timestamp requests. 58 | // By default, an HTTP client with a 5 second timeout per request is used. 59 | HTTPClient *_ce .Client ; 60 | 61 | // Callbacks. 62 | BeforeHTTPRequest func (_ffef *_ce .Request )error ;}; 63 | 64 | // CertClient represents a X.509 certificate client. Its primary purpose 65 | // is to download certificates. 66 | type CertClient struct{ 67 | 68 | // HTTPClient is the HTTP client used to make certificate requests. 69 | // By default, an HTTP client with a 5 second timeout per request is used. 70 | HTTPClient *_ce .Client ;}; 71 | 72 | // Get retrieves the certificate at the specified URL. 73 | func (_gc *CertClient )Get (url string )(*_fac .Certificate ,error ){if _gc .HTTPClient ==nil {_gc .HTTPClient =_fgbe ();};_ff ,_aa :=_gc .HTTPClient .Get (url );if _aa !=nil {return nil ,_aa ;};defer _ff .Body .Close ();_ge ,_aa :=_g .ReadAll (_ff .Body ); 74 | if _aa !=nil {return nil ,_aa ;};if _ee ,_ :=_fc .Decode (_ge );_ee !=nil {_ge =_ee .Bytes ;};_ec ,_aa :=_fac .ParseCertificate (_ge );if _aa !=nil {return nil ,_aa ;};return _ec ,nil ;}; 75 | 76 | // NewCRLClient returns a new CRL client. 77 | func NewCRLClient ()*CRLClient {return &CRLClient {HTTPClient :_fgbe ()}}; 78 | 79 | // CRLClient represents a CRL (Certificate revocation list) client. 80 | // It is used to request revocation data from CRL servers. 81 | type CRLClient struct{ 82 | 83 | // HTTPClient is the HTTP client used to make CRL requests. 84 | // By default, an HTTP client with a 5 second timeout per request is used. 85 | HTTPClient *_ce .Client ;};func _fgbe ()*_ce .Client {return &_ce .Client {Timeout :5*_f .Second }}; 86 | 87 | // NewTimestampClient returns a new timestamp client. 88 | func NewTimestampClient ()*TimestampClient {return &TimestampClient {HTTPClient :_fgbe ()}}; 89 | 90 | // GetIssuer retrieves the issuer of the provided certificate. 91 | func (_cef *CertClient )GetIssuer (cert *_fac .Certificate )(*_fac .Certificate ,error ){for _ ,_db :=range cert .IssuingCertificateURL {_gg ,_cee :=_cef .Get (_db );if _cee !=nil {_ga .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 ,_cee ); 92 | continue ;};return _gg ,nil ;};return nil ,_cb .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");}; 93 | 94 | // NewOCSPClient returns a new OCSP client. 95 | func NewOCSPClient ()*OCSPClient {return &OCSPClient {HTTPClient :_fgbe (),Hash :_fa .SHA1 }}; 96 | 97 | // NewCertClient returns a new certificate client. 98 | func NewCertClient ()*CertClient {return &CertClient {HTTPClient :_fgbe ()}}; 99 | 100 | // MakeRequest makes a CRL request to the specified server and returns the 101 | // response. If a server URL is not provided, it is extracted from the certificate. 102 | func (_gb *CRLClient )MakeRequest (serverURL string ,cert *_fac .Certificate )([]byte ,error ){if _gb .HTTPClient ==nil {_gb .HTTPClient =_fgbe ();};if serverURL ==""{if len (cert .CRLDistributionPoints )==0{return nil ,_cd .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"); 103 | };serverURL =cert .CRLDistributionPoints [0];};_gag ,_fg :=_gb .HTTPClient .Get (serverURL );if _fg !=nil {return nil ,_fg ;};defer _gag .Body .Close ();_cac ,_fg :=_g .ReadAll (_gag .Body );if _fg !=nil {return nil ,_fg ;};if _geb ,_ :=_fc .Decode (_cac ); 104 | _geb !=nil {_cac =_geb .Bytes ;};return _cac ,nil ;}; -------------------------------------------------------------------------------- /internal/jbig2/decoder/huffman/huffman.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package huffman ;import (_ca "errors";_d "fmt";_b "github.com/unidoc/unipdf/v4/internal/bitwise";_c "github.com/unidoc/unipdf/v4/internal/jbig2/internal";_cc "math";_e "strings";);func _deb (_ec ,_eeg int32 )string {var _feg int32 ;_adc :=make ([]rune ,_eeg ); 13 | for _aed :=int32 (1);_aed <=_eeg ;_aed ++{_feg =_ec >>uint (_eeg -_aed )&1;if _feg !=0{_adc [_aed -1]='1';}else {_adc [_aed -1]='0';};};return string (_adc );};func _bag (_fac *Code )*ValueNode {return &ValueNode {_gag :_fac ._efdf ,_fd :_fac ._ffc ,_eb :_fac ._bgd }}; 14 | func (_bgg *EncodedTable )String ()string {return _bgg ._cf .String ()+"\u000a"};func (_db *OutOfBandNode )Decode (r *_b .Reader )(int64 ,error ){return 0,_c .ErrOOB };func (_be *EncodedTable )Decode (r *_b .Reader )(int64 ,error ){return _be ._cf .Decode (r )}; 15 | func (_bg *EncodedTable )InitTree (codeTable []*Code )error {_dgf (codeTable );for _ ,_ed :=range codeTable {if _ccd :=_bg ._cf .append (_ed );_ccd !=nil {return _ccd ;};};return nil ;};func NewFixedSizeTable (codeTable []*Code )(*FixedSizeTable ,error ){_dd :=&FixedSizeTable {_ae :&InternalNode {}}; 16 | if _geb :=_dd .InitTree (codeTable );_geb !=nil {return nil ,_geb ;};return _dd ,nil ;};var _ Node =&OutOfBandNode {};type EncodedTable struct{BasicTabler ;_cf *InternalNode ;};func (_ge *EncodedTable )parseTable ()error {var (_fa []*Code ;_ded ,_fc ,_dc int32 ; 17 | _ef uint64 ;_a error ;);_edf :=_ge .StreamReader ();_ba :=_ge .HtLow ();for _ba < _ge .HtHigh (){_ef ,_a =_edf .ReadBits (byte (_ge .HtPS ()));if _a !=nil {return _a ;};_ded =int32 (_ef );_ef ,_a =_edf .ReadBits (byte (_ge .HtRS ()));if _a !=nil {return _a ; 18 | };_fc =int32 (_ef );_fa =append (_fa ,NewCode (_ded ,_fc ,_dc ,false ));_ba +=1< len (_bdd ){return nil ,_ca .New ("\u0049n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065"); 25 | };_efc :=_bdd [number -1];if _efc ==nil {var _fga error ;_efc ,_fga =_edfc (_bcb [number -1]);if _fga !=nil {return nil ,_fga ;};_bdd [number -1]=_efc ;};return _efc ,nil ;};type Tabler interface{Decode (_ccf *_b .Reader )(int64 ,error );InitTree (_bfb []*Code )error ; 26 | String ()string ;RootNode ()*InternalNode ;};var _ Node =&InternalNode {};func (_bad *OutOfBandNode )String ()string {return _d .Sprintf ("\u0025\u0030\u00364\u0062",int64 (_cc .MaxInt64 ));};func (_ccg *InternalNode )String ()string {_edg :=&_e .Builder {}; 27 | _edg .WriteString ("\u000a");_ccg .pad (_edg );_edg .WriteString ("\u0030\u003a\u0020");_edg .WriteString (_ccg ._eff .String ()+"\u000a");_ccg .pad (_edg );_edg .WriteString ("\u0031\u003a\u0020");_edg .WriteString (_ccg ._bc .String ()+"\u000a");return _edg .String (); 28 | };func _cae (_dbff ,_ebc int32 )int32 {if _dbff > _ebc {return _dbff ;};return _ebc ;};func (_gad *FixedSizeTable )String ()string {return _gad ._ae .String ()+"\u000a"};type ValueNode struct{_gag int32 ;_fd int32 ;_eb bool ;};func _eaa (_bgb *Code )*OutOfBandNode {return &OutOfBandNode {}}; 29 | func (_aee *InternalNode )Decode (r *_b .Reader )(int64 ,error ){_ag ,_ad :=r .ReadBit ();if _ad !=nil {return 0,_ad ;};if _ag ==0{return _aee ._eff .Decode (r );};return _aee ._bc .Decode (r );};func (_bfc *InternalNode )append (_eac *Code )(_faf error ){if _eac ._dbb ==0{return nil ; 30 | };_aa :=_eac ._dbb -1-_bfc ._gee ;if _aa < 0{return _ca .New ("\u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0073\u0068\u0069\u0066\u0074\u0069n\u0067 \u0069\u0073\u0020\u006e\u006f\u0074\u0020\u0061\u006c\u006c\u006f\u0077\u0065\u0064");};_cb :=(_eac ._ce >>uint (_aa ))&0x1; 31 | if _aa ==0{if _eac ._efdf ==-1{if _cb ==1{if _bfc ._bc !=nil {return _d .Errorf ("O\u004f\u0042\u0020\u0061\u006c\u0072e\u0061\u0064\u0079\u0020\u0073\u0065\u0074\u0020\u0066o\u0072\u0020\u0063o\u0064e\u0020\u0025\u0073",_eac );};_bfc ._bc =_eaa (_eac ); 32 | }else {if _bfc ._eff !=nil {return _d .Errorf ("O\u004f\u0042\u0020\u0061\u006c\u0072e\u0061\u0064\u0079\u0020\u0073\u0065\u0074\u0020\u0066o\u0072\u0020\u0063o\u0064e\u0020\u0025\u0073",_eac );};_bfc ._eff =_eaa (_eac );};}else {if _cb ==1{if _bfc ._bc !=nil {return _d .Errorf ("\u0076\u0061\u006cue\u0020\u004e\u006f\u0064\u0065\u0020\u0061\u006c\u0072e\u0061d\u0079 \u0073e\u0074\u0020\u0066\u006f\u0072\u0020\u0063\u006f\u0064\u0065\u0020\u0025\u0073",_eac ); 33 | };_bfc ._bc =_bag (_eac );}else {if _bfc ._eff !=nil {return _d .Errorf ("\u0076\u0061\u006cue\u0020\u004e\u006f\u0064\u0065\u0020\u0061\u006c\u0072e\u0061d\u0079 \u0073e\u0074\u0020\u0066\u006f\u0072\u0020\u0063\u006f\u0064\u0065\u0020\u0025\u0073",_eac ); 34 | };_bfc ._eff =_bag (_eac );};};}else {if _cb ==1{if _bfc ._bc ==nil {_bfc ._bc =_eae (_bfc ._gee +1);};if _faf =_bfc ._bc .(*InternalNode ).append (_eac );_faf !=nil {return _faf ;};}else {if _bfc ._eff ==nil {_bfc ._eff =_eae (_bfc ._gee +1);};if _faf =_bfc ._eff .(*InternalNode ).append (_eac ); 35 | _faf !=nil {return _faf ;};};};return nil ;};func NewCode (prefixLength ,rangeLength ,rangeLow int32 ,isLowerRange bool )*Code {return &Code {_dbb :prefixLength ,_efdf :rangeLength ,_ffc :rangeLow ,_bgd :isLowerRange ,_ce :-1};};func NewEncodedTable (table BasicTabler )(*EncodedTable ,error ){_cd :=&EncodedTable {_cf :&InternalNode {},BasicTabler :table }; 36 | if _f :=_cd .parseTable ();_f !=nil {return nil ,_f ;};return _cd ,nil ;};type OutOfBandNode struct{};func (_dcc *FixedSizeTable )RootNode ()*InternalNode {return _dcc ._ae };func (_eba *StandardTable )InitTree (codeTable []*Code )error {_dgf (codeTable ); 37 | for _ ,_agb :=range codeTable {if _dfc :=_eba ._ee .append (_agb );_dfc !=nil {return _dfc ;};};return nil ;};type Code struct{_dbb int32 ;_efdf int32 ;_ffc int32 ;_bgd bool ;_ce int32 ;};func (_df *FixedSizeTable )InitTree (codeTable []*Code )error {_dgf (codeTable ); 38 | for _ ,_fg :=range codeTable {_gaa :=_df ._ae .append (_fg );if _gaa !=nil {return _gaa ;};};return nil ;};type InternalNode struct{_gee int32 ;_eff Node ;_bc Node ;};func _dgf (_dfg []*Code ){var _eecd int32 ;for _ ,_dcd :=range _dfg {_eecd =_cae (_eecd ,_dcd ._dbb ); 39 | };_ac :=make ([]int32 ,_eecd +1);for _ ,_egf :=range _dfg {_ac [_egf ._dbb ]++;};var _dbfg int32 ;_acf :=make ([]int32 ,len (_ac )+1);_ac [0]=0;for _edd :=int32 (1);_edd <=int32 (len (_ac ));_edd ++{_acf [_edd ]=(_acf [_edd -1]+(_ac [_edd -1]))<<1;_dbfg =_acf [_edd ]; 40 | for _ ,_bfbf :=range _dfg {if _bfbf ._dbb ==_edd {_bfbf ._ce =_dbfg ;_dbfg ++;};};};};type StandardTable struct{_ee *InternalNode };var _bdd =make ([]Tabler ,len (_bcb ));var _bcb =[][][]int32 {{{1,4,0},{2,8,16},{3,16,272},{3,32,65808}},{{1,0,0},{2,0,1},{3,0,2},{4,3,3},{5,6,11},{6,32,75},{6,-1,0}},{{8,8,-256},{1,0,0},{2,0,1},{3,0,2},{4,3,3},{5,6,11},{8,32,-257,999},{7,32,75},{6,-1,0}},{{1,0,1},{2,0,2},{3,0,3},{4,3,4},{5,6,12},{5,32,76}},{{7,8,-255},{1,0,1},{2,0,2},{3,0,3},{4,3,4},{5,6,12},{7,32,-256,999},{6,32,76}},{{5,10,-2048},{4,9,-1024},{4,8,-512},{4,7,-256},{5,6,-128},{5,5,-64},{4,5,-32},{2,7,0},{3,7,128},{3,8,256},{4,9,512},{4,10,1024},{6,32,-2049,999},{6,32,2048}},{{4,9,-1024},{3,8,-512},{4,7,-256},{5,6,-128},{5,5,-64},{4,5,-32},{4,5,0},{5,5,32},{5,6,64},{4,7,128},{3,8,256},{3,9,512},{3,10,1024},{5,32,-1025,999},{5,32,2048}},{{8,3,-15},{9,1,-7},{8,1,-5},{9,0,-3},{7,0,-2},{4,0,-1},{2,1,0},{5,0,2},{6,0,3},{3,4,4},{6,1,20},{4,4,22},{4,5,38},{5,6,70},{5,7,134},{6,7,262},{7,8,390},{6,10,646},{9,32,-16,999},{9,32,1670},{2,-1,0}},{{8,4,-31},{9,2,-15},{8,2,-11},{9,1,-7},{7,1,-5},{4,1,-3},{3,1,-1},{3,1,1},{5,1,3},{6,1,5},{3,5,7},{6,2,39},{4,5,43},{4,6,75},{5,7,139},{5,8,267},{6,8,523},{7,9,779},{6,11,1291},{9,32,-32,999},{9,32,3339},{2,-1,0}},{{7,4,-21},{8,0,-5},{7,0,-4},{5,0,-3},{2,2,-2},{5,0,2},{6,0,3},{7,0,4},{8,0,5},{2,6,6},{5,5,70},{6,5,102},{6,6,134},{6,7,198},{6,8,326},{6,9,582},{6,10,1094},{7,11,2118},{8,32,-22,999},{8,32,4166},{2,-1,0}},{{1,0,1},{2,1,2},{4,0,4},{4,1,5},{5,1,7},{5,2,9},{6,2,13},{7,2,17},{7,3,21},{7,4,29},{7,5,45},{7,6,77},{7,32,141}},{{1,0,1},{2,0,2},{3,1,3},{5,0,5},{5,1,6},{6,1,8},{7,0,10},{7,1,11},{7,2,13},{7,3,17},{7,4,25},{8,5,41},{8,32,73}},{{1,0,1},{3,0,2},{4,0,3},{5,0,4},{4,1,5},{3,3,7},{6,1,15},{6,2,17},{6,3,21},{6,4,29},{6,5,45},{7,6,77},{7,32,141}},{{3,0,-2},{3,0,-1},{1,0,0},{3,0,1},{3,0,2}},{{7,4,-24},{6,2,-8},{5,1,-4},{4,0,-2},{3,0,-1},{1,0,0},{3,0,1},{4,0,2},{5,1,3},{6,2,5},{7,4,9},{7,32,-25,999},{7,32,25}}}; 41 | func _edfc (_aag [][]int32 )(*StandardTable ,error ){var _af []*Code ;for _dfe :=0;_dfe < len (_aag );_dfe ++{_fda :=_aag [_dfe ][0];_fbf :=_aag [_dfe ][1];_eg :=_aag [_dfe ][2];var _bcc bool ;if len (_aag [_dfe ])> 3{_bcc =true ;};_af =append (_af ,NewCode (_fda ,_fbf ,_eg ,_bcc )); 42 | };_cca :=&StandardTable {_ee :_eae (0)};if _eec :=_cca .InitTree (_af );_eec !=nil {return nil ,_eec ;};return _cca ,nil ;};func (_fb *StandardTable )RootNode ()*InternalNode {return _fb ._ee };type BasicTabler interface{HtHigh ()int32 ;HtLow ()int32 ; 43 | StreamReader ()*_b .Reader ;HtPS ()int32 ;HtRS ()int32 ;HtOOB ()int32 ;};func _eae (_ff int32 )*InternalNode {return &InternalNode {_gee :_ff }};func (_fec *ValueNode )String ()string {return _d .Sprintf ("\u0025\u0064\u002f%\u0064",_fec ._gag ,_fec ._fd ); 44 | }; -------------------------------------------------------------------------------- /internal/jbig2/decoder/mmr/mmr.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package mmr ;import (_dc "errors";_d "fmt";_g "github.com/unidoc/unipdf/v4/common";_c "github.com/unidoc/unipdf/v4/internal/bitwise";_da "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_e "io";);func (_ccc *Decoder )uncompress1d (_cce *runData ,_egg []int ,_af int )(int ,error ){var (_efd =true ; 13 | _dfb int ;_aeb *code ;_edf int ;_feb error ;);_fcc :for _dfb < _af {_cdg :for {if _efd {_aeb ,_feb =_cce .uncompressGetCode (_ccc ._dd );if _feb !=nil {return 0,_feb ;};}else {_aeb ,_feb =_cce .uncompressGetCode (_ccc ._bd );if _feb !=nil {return 0,_feb ; 14 | };};_cce ._dcad +=_aeb ._cc ;if _aeb ._ga < 0{break _fcc ;};_dfb +=_aeb ._ga ;if _aeb ._ga < 64{_efd =!_efd ;_egg [_edf ]=_dfb ;_edf ++;break _cdg ;};};};if _egg [_edf ]!=_af {_egg [_edf ]=_af ;};_afd :=EOL ;if _aeb !=nil &&_aeb ._ga !=EOL {_afd =_edf ; 15 | };return _afd ,nil ;};type mmrCode int ;const (_ba mmrCode =iota ;_cf ;_fg ;_fdc ;_cg ;_gag ;_ae ;_gd ;_gde ;_ab ;_ac ;);func _dfd (_gce *_c .Reader )(*runData ,error ){_bdgc :=&runData {_cfc :_gce ,_dcad :0,_dcb :1};_ebb :=_ce (_fd (_abf ,int (_gce .Length ())),_cccc ); 16 | _bdgc ._aaeb =make ([]byte ,_ebb );if _geg :=_bdgc .fillBuffer (0);_geg !=nil {if _geg ==_e .EOF {_bdgc ._aaeb =make ([]byte ,10);_g .Log .Debug ("F\u0069\u006c\u006c\u0042uf\u0066e\u0072\u0020\u0066\u0061\u0069l\u0065\u0064\u003a\u0020\u0025\u0076",_geg ); 17 | }else {return nil ,_geg ;};};return _bdgc ,nil ;};func New (r *_c .Reader ,width ,height int ,dataOffset ,dataLength int64 )(*Decoder ,error ){_aae :=&Decoder {_cb :width ,_bg :height };_eae ,_cbe :=r .NewPartialReader (int (dataOffset ),int (dataLength ),false ); 18 | if _cbe !=nil {return nil ,_cbe ;};_dda ,_cbe :=_dfd (_eae );if _cbe !=nil {return nil ,_cbe ;};_ ,_cbe =r .Seek (_eae .RelativePosition (),_e .SeekCurrent );if _cbe !=nil {return nil ,_cbe ;};_aae ._gbd =_dda ;if _dfa :=_aae .initTables ();_dfa !=nil {return nil ,_dfa ; 19 | };return _aae ,nil ;};func (_eb *Decoder )createLittleEndianTable (_eaf [][3]int )([]*code ,error ){_aec :=make ([]*code ,_abg +1);for _gfca :=0;_gfca < len (_eaf );_gfca ++{_ff :=_a (_eaf [_gfca ]);if _ff ._cc <=_gdf {_aea :=_gdf -_ff ._cc ;_dg :=_ff ._bf <=0;_gaa --{_ec :=_dg |_gaa ;_aec [_ec ]=_ff ;};}else {_dgb :=_ff ._bf >>uint (_ff ._cc -_gdf );if _aec [_dgb ]==nil {var _ge =_a ([3]int {});_ge ._eg =make ([]*code ,_gb +1);_aec [_dgb ]=_ge ;};if _ff ._cc <=_gdf +_gf {_be :=_gdf +_gf -_ff ._cc ; 21 | _cde :=(_ff ._bf <=0;_fe --{_aec [_dgb ]._eg [_cde |_fe ]=_ff ;};}else {return nil ,_dc .New ("\u0063\u006f\u0064\u0065\u0020\u0074a\u0062\u006c\u0065\u0020\u006f\u0076\u0065\u0072\u0066\u006c\u006f\u0077\u0020i\u006e\u0020\u004d\u004d\u0052\u0044\u0065c\u006f\u0064\u0065\u0072"); 22 | };};};return _aec ,nil ;};func (_gda *runData )uncompressGetNextCodeLittleEndian ()(int ,error ){_edg :=_gda ._dcad -_gda ._dcb ;if _edg < 0||_edg > 24{_ccce :=(_gda ._dcad >>3)-_gda ._bfgg ;if _ccce >=_gda ._bba {_ccce +=_gda ._bfgg ;if _cec :=_gda .fillBuffer (_ccce ); 23 | _cec !=nil {return 0,_cec ;};_ccce -=_gda ._bfgg ;};_dbb :=(uint32 (_gda ._aaeb [_ccce ]&0xFF)<<16)|(uint32 (_gda ._aaeb [_ccce +1]&0xFF)<<8)|(uint32 (_gda ._aaeb [_ccce +2]&0xFF));_bbb :=uint32 (_gda ._dcad &7);_dbb <<=_bbb ;_gda ._ggd =int (_dbb );}else {_fga :=_gda ._dcb &7; 24 | _bgf :=7-_fga ;if _edg <=_bgf {_gda ._ggd <<=uint (_edg );}else {_ded :=(_gda ._dcb >>3)+3-_gda ._bfgg ;if _ded >=_gda ._bba {_ded +=_gda ._bfgg ;if _fdd :=_gda .fillBuffer (_ded );_fdd !=nil {return 0,_fdd ;};_ded -=_gda ._bfgg ;};_fga =8-_fga ;for {_gda ._ggd <<=uint (_fga ); 25 | _gda ._ggd |=int (uint (_gda ._aaeb [_ded ])&0xFF);_edg -=_fga ;_ded ++;_fga =8;if !(_edg >=8){break ;};};_gda ._ggd <<=uint (_edg );};};_gda ._dcb =_gda ._dcad ;return _gda ._ggd ,nil ;};func (_dfda *runData )fillBuffer (_efcc int )error {_dfda ._bfgg =_efcc ; 26 | _ ,_dab :=_dfda ._cfc .Seek (int64 (_efcc ),_e .SeekStart );if _dab !=nil {if _dab ==_e .EOF {_g .Log .Debug ("\u0053\u0065\u0061\u006b\u0020\u0045\u004f\u0046");_dfda ._bba =-1;}else {return _dab ;};};if _dab ==nil {_dfda ._bba ,_dab =_dfda ._cfc .Read (_dfda ._aaeb ); 27 | if _dab !=nil {if _dab ==_e .EOF {_g .Log .Trace ("\u0052\u0065\u0061\u0064\u0020\u0045\u004f\u0046");_dfda ._bba =-1;}else {return _dab ;};};};if _dfda ._bba > -1&&_dfda ._bba < 3{for _dfda ._bba < 3{_dbg ,_egb :=_dfda ._cfc .ReadByte ();if _egb !=nil {if _egb ==_e .EOF {_dfda ._aaeb [_dfda ._bba ]=0; 28 | }else {return _egb ;};}else {_dfda ._aaeb [_dfda ._bba ]=_dbg &0xFF;};_dfda ._bba ++;};};_dfda ._bba -=3;if _dfda ._bba < 0{_dfda ._aaeb =make ([]byte ,len (_dfda ._aaeb ));_dfda ._bba =len (_dfda ._aaeb )-3;};return nil ;};func (_dea *Decoder )fillBitmap (_cdd *_da .Bitmap ,_fb int ,_ffd []int ,_gbb int )error {var _ee byte ; 29 | _ed :=0;_abd :=_cdd .GetByteIndex (_ed ,_fb );for _bed :=0;_bed < _gbb ;_bed ++{_gca :=byte (1);_ag :=_ffd [_bed ];if (_bed &1)==0{_gca =0;};for _ed < _ag {_ee =(_ee <<1)|_gca ;_ed ++;if (_ed &7)==0{if _ca :=_cdd .SetByte (_abd ,_ee );_ca !=nil {return _ca ; 30 | };_abd ++;_ee =0;};};};if (_ed &7)!=0{_ee <<=uint (8-(_ed &7));if _bfg :=_cdd .SetByte (_abd ,_ee );_bfg !=nil {return _bfg ;};};return nil ;};func (_ef *code )String ()string {return _d .Sprintf ("\u0025\u0064\u002f\u0025\u0064\u002f\u0025\u0064",_ef ._cc ,_ef ._bf ,_ef ._ga ); 31 | };type runData struct{_cfc *_c .Reader ;_dcad int ;_dcb int ;_ggd int ;_aaeb []byte ;_bfgg int ;_bba int ;};type Decoder struct{_cb ,_bg int ;_gbd *runData ;_dd []*code ;_bd []*code ;_bcc []*code ;};func (_gcc *Decoder )detectAndSkipEOL ()error {for {_fa ,_efg :=_gcc ._gbd .uncompressGetCode (_gcc ._bcc ); 32 | if _efg !=nil {return _efg ;};if _fa !=nil &&_fa ._ga ==EOL {_gcc ._gbd ._dcad +=_fa ._cc ;}else {return nil ;};};};func (_ede *runData )uncompressGetCodeLittleEndian (_aeae []*code )(*code ,error ){_efc ,_cab :=_ede .uncompressGetNextCodeLittleEndian (); 33 | if _cab !=nil {_g .Log .Debug ("\u0055n\u0063\u006fm\u0070\u0072\u0065\u0073s\u0047\u0065\u0074N\u0065\u0078\u0074\u0043\u006f\u0064\u0065\u004c\u0069tt\u006c\u0065\u0045n\u0064\u0069a\u006e\u0020\u0066\u0061\u0069\u006ce\u0064\u003a \u0025\u0076",_cab ); 34 | return nil ,_cab ;};_efc &=0xffffff;_ffdf :=_efc >>(_cba -_gdf );_cbg :=_aeae [_ffdf ];if _cbg !=nil &&_cbg ._f {_ffdf =(_efc >>(_cba -_gdf -_gf ))&_gb ;_cbg =_cbg ._eg [_ffdf ];};return _cbg ,nil ;};func _fd (_fc ,_ea int )int {if _fc < _ea {return _ea ; 35 | };return _fc ;};var (_bc =[][3]int {{4,0x1,int (_ba )},{3,0x1,int (_cf )},{1,0x1,int (_fg )},{3,0x3,int (_fdc )},{6,0x3,int (_cg )},{7,0x3,int (_gag )},{3,0x2,int (_ae )},{6,0x2,int (_gd )},{7,0x2,int (_gde )},{10,0xf,int (_ab )},{12,0xf,int (_ac )},{12,0x1,int (EOL )}}; 36 | _aca =[][3]int {{4,0x07,2},{4,0x08,3},{4,0x0B,4},{4,0x0C,5},{4,0x0E,6},{4,0x0F,7},{5,0x12,128},{5,0x13,8},{5,0x14,9},{5,0x1B,64},{5,0x07,10},{5,0x08,11},{6,0x17,192},{6,0x18,1664},{6,0x2A,16},{6,0x2B,17},{6,0x03,13},{6,0x34,14},{6,0x35,15},{6,0x07,1},{6,0x08,12},{7,0x13,26},{7,0x17,21},{7,0x18,28},{7,0x24,27},{7,0x27,18},{7,0x28,24},{7,0x2B,25},{7,0x03,22},{7,0x37,256},{7,0x04,23},{7,0x08,20},{7,0xC,19},{8,0x12,33},{8,0x13,34},{8,0x14,35},{8,0x15,36},{8,0x16,37},{8,0x17,38},{8,0x1A,31},{8,0x1B,32},{8,0x02,29},{8,0x24,53},{8,0x25,54},{8,0x28,39},{8,0x29,40},{8,0x2A,41},{8,0x2B,42},{8,0x2C,43},{8,0x2D,44},{8,0x03,30},{8,0x32,61},{8,0x33,62},{8,0x34,63},{8,0x35,0},{8,0x36,320},{8,0x37,384},{8,0x04,45},{8,0x4A,59},{8,0x4B,60},{8,0x5,46},{8,0x52,49},{8,0x53,50},{8,0x54,51},{8,0x55,52},{8,0x58,55},{8,0x59,56},{8,0x5A,57},{8,0x5B,58},{8,0x64,448},{8,0x65,512},{8,0x67,640},{8,0x68,576},{8,0x0A,47},{8,0x0B,48},{9,0x01,_ccb },{9,0x98,1472},{9,0x99,1536},{9,0x9A,1600},{9,0x9B,1728},{9,0xCC,704},{9,0xCD,768},{9,0xD2,832},{9,0xD3,896},{9,0xD4,960},{9,0xD5,1024},{9,0xD6,1088},{9,0xD7,1152},{9,0xD8,1216},{9,0xD9,1280},{9,0xDA,1344},{9,0xDB,1408},{10,0x01,_ccb },{11,0x01,_ccb },{11,0x08,1792},{11,0x0C,1856},{11,0x0D,1920},{12,0x00,EOF },{12,0x01,EOL },{12,0x12,1984},{12,0x13,2048},{12,0x14,2112},{12,0x15,2176},{12,0x16,2240},{12,0x17,2304},{12,0x1C,2368},{12,0x1D,2432},{12,0x1E,2496},{12,0x1F,2560}}; 37 | _cd =[][3]int {{2,0x02,3},{2,0x03,2},{3,0x02,1},{3,0x03,4},{4,0x02,6},{4,0x03,5},{5,0x03,7},{6,0x04,9},{6,0x05,8},{7,0x04,10},{7,0x05,11},{7,0x07,12},{8,0x04,13},{8,0x07,14},{9,0x01,_ccb },{9,0x18,15},{10,0x01,_ccb },{10,0x17,16},{10,0x18,17},{10,0x37,0},{10,0x08,18},{10,0x0F,64},{11,0x01,_ccb },{11,0x17,24},{11,0x18,25},{11,0x28,23},{11,0x37,22},{11,0x67,19},{11,0x68,20},{11,0x6C,21},{11,0x08,1792},{11,0x0C,1856},{11,0x0D,1920},{12,0x00,EOF },{12,0x01,EOL },{12,0x12,1984},{12,0x13,2048},{12,0x14,2112},{12,0x15,2176},{12,0x16,2240},{12,0x17,2304},{12,0x1C,2368},{12,0x1D,2432},{12,0x1E,2496},{12,0x1F,2560},{12,0x24,52},{12,0x27,55},{12,0x28,56},{12,0x2B,59},{12,0x2C,60},{12,0x33,320},{12,0x34,384},{12,0x35,448},{12,0x37,53},{12,0x38,54},{12,0x52,50},{12,0x53,51},{12,0x54,44},{12,0x55,45},{12,0x56,46},{12,0x57,47},{12,0x58,57},{12,0x59,58},{12,0x5A,61},{12,0x5B,256},{12,0x64,48},{12,0x65,49},{12,0x66,62},{12,0x67,63},{12,0x68,30},{12,0x69,31},{12,0x6A,32},{12,0x6B,33},{12,0x6C,40},{12,0x6D,41},{12,0xC8,128},{12,0xC9,192},{12,0xCA,26},{12,0xCB,27},{12,0xCC,28},{12,0xCD,29},{12,0xD2,34},{12,0xD3,35},{12,0xD4,36},{12,0xD5,37},{12,0xD6,38},{12,0xD7,39},{12,0xDA,42},{12,0xDB,43},{13,0x4A,640},{13,0x4B,704},{13,0x4C,768},{13,0x4D,832},{13,0x52,1280},{13,0x53,1344},{13,0x54,1408},{13,0x55,1472},{13,0x5A,1536},{13,0x5B,1600},{13,0x64,1664},{13,0x65,1728},{13,0x6C,512},{13,0x6D,576},{13,0x72,896},{13,0x73,960},{13,0x74,1024},{13,0x75,1088},{13,0x76,1152},{13,0x77,1216}}; 38 | );const (EOF =-3;_ccb =-2;EOL =-1;_gdf =8;_abg =(1<<_gdf )-1;_gf =5;_gb =(1<<_gf )-1;);func _a (_df [3]int )*code {return &code {_cc :_df [0],_bf :_df [1],_ga :_df [2]}};type code struct{_cc int ;_bf int ;_ga int ;_eg []*code ;_f bool ;};func (_gbg *runData )uncompressGetCode (_db []*code )(*code ,error ){return _gbg .uncompressGetCodeLittleEndian (_db ); 39 | };func (_fcd *Decoder )initTables ()(_bb error ){if _fcd ._dd ==nil {_fcd ._dd ,_bb =_fcd .createLittleEndianTable (_aca );if _bb !=nil {return ;};_fcd ._bd ,_bb =_fcd .createLittleEndianTable (_cd );if _bb !=nil {return ;};_fcd ._bcc ,_bb =_fcd .createLittleEndianTable (_bc ); 40 | if _bb !=nil {return ;};};return nil ;};func (_ccbd *Decoder )uncompress2d (_bdf *runData ,_dge []int ,_dcd int ,_edc []int ,_ggg int )(int ,error ){var (_gcd int ;_cbb int ;_eggc int ;_bbc =true ;_abb error ;_deab *code ;);_dge [_dcd ]=_ggg ;_dge [_dcd +1]=_ggg ; 41 | _dge [_dcd +2]=_ggg +1;_dge [_dcd +3]=_ggg +1;_bdg :for _eggc < _ggg {_deab ,_abb =_bdf .uncompressGetCode (_ccbd ._bcc );if _abb !=nil {return EOL ,nil ;};if _deab ==nil {_bdf ._dcad ++;break _bdg ;};_bdf ._dcad +=_deab ._cc ;switch mmrCode (_deab ._ga ){case _fg :_eggc =_dge [_gcd ]; 42 | case _fdc :_eggc =_dge [_gcd ]+1;case _ae :_eggc =_dge [_gcd ]-1;case _cf :for {var _gbf []*code ;if _bbc {_gbf =_ccbd ._dd ;}else {_gbf =_ccbd ._bd ;};_deab ,_abb =_bdf .uncompressGetCode (_gbf );if _abb !=nil {return 0,_abb ;};if _deab ==nil {break _bdg ; 43 | };_bdf ._dcad +=_deab ._cc ;if _deab ._ga < 64{if _deab ._ga < 0{_edc [_cbb ]=_eggc ;_cbb ++;_deab =nil ;break _bdg ;};_eggc +=_deab ._ga ;_edc [_cbb ]=_eggc ;_cbb ++;break ;};_eggc +=_deab ._ga ;};_fbe :=_eggc ;_abc :for {var _fbg []*code ;if !_bbc {_fbg =_ccbd ._dd ; 44 | }else {_fbg =_ccbd ._bd ;};_deab ,_abb =_bdf .uncompressGetCode (_fbg );if _abb !=nil {return 0,_abb ;};if _deab ==nil {break _bdg ;};_bdf ._dcad +=_deab ._cc ;if _deab ._ga < 64{if _deab ._ga < 0{_edc [_cbb ]=_eggc ;_cbb ++;break _bdg ;};_eggc +=_deab ._ga ; 45 | if _eggc < _ggg ||_eggc !=_fbe {_edc [_cbb ]=_eggc ;_cbb ++;};break _abc ;};_eggc +=_deab ._ga ;};for _eggc < _ggg &&_dge [_gcd ]<=_eggc {_gcd +=2;};continue _bdg ;case _ba :_gcd ++;_eggc =_dge [_gcd ];_gcd ++;continue _bdg ;case _cg :_eggc =_dge [_gcd ]+2; 46 | case _gd :_eggc =_dge [_gcd ]-2;case _gag :_eggc =_dge [_gcd ]+3;case _gde :_eggc =_dge [_gcd ]-3;default:if _bdf ._dcad ==12&&_deab ._ga ==EOL {_bdf ._dcad =0;if _ ,_abb =_ccbd .uncompress1d (_bdf ,_dge ,_ggg );_abb !=nil {return 0,_abb ;};_bdf ._dcad ++; 47 | if _ ,_abb =_ccbd .uncompress1d (_bdf ,_edc ,_ggg );_abb !=nil {return 0,_abb ;};_fdcg ,_gad :=_ccbd .uncompress1d (_bdf ,_dge ,_ggg );if _gad !=nil {return EOF ,_gad ;};_bdf ._dcad ++;return _fdcg ,nil ;};_eggc =_ggg ;continue _bdg ;};if _eggc <=_ggg {_bbc =!_bbc ; 48 | _edc [_cbb ]=_eggc ;_cbb ++;if _gcd > 0{_gcd --;}else {_gcd ++;};for _eggc < _ggg &&_dge [_gcd ]<=_eggc {_gcd +=2;};};};if _edc [_cbb ]!=_ggg {_edc [_cbb ]=_ggg ;};if _deab ==nil {return EOL ,nil ;};return _cbb ,nil ;};func (_gfa *Decoder )UncompressMMR ()(_de *_da .Bitmap ,_dcc error ){_de =_da .New (_gfa ._cb ,_gfa ._bg ); 49 | _fcf :=make ([]int ,_de .Width +5);_gg :=make ([]int ,_de .Width +5);_gg [0]=_de .Width ;_gc :=1;var _gfc int ;for _dca :=0;_dca < _de .Height ;_dca ++{_gfc ,_dcc =_gfa .uncompress2d (_gfa ._gbd ,_gg ,_gc ,_fcf ,_de .Width );if _dcc !=nil {return nil ,_dcc ; 50 | };if _gfc ==EOF {break ;};if _gfc > 0{_dcc =_gfa .fillBitmap (_de ,_dca ,_fcf ,_gfc );if _dcc !=nil {return nil ,_dcc ;};};_gg ,_fcf =_fcf ,_gg ;_gc =_gfc ;};if _dcc =_gfa .detectAndSkipEOL ();_dcc !=nil {return nil ,_dcc ;};_gfa ._gbd .align ();return _de ,nil ; 51 | };const (_cccc int =1024<<7;_abf int =3;_cba uint =24;);func (_cda *runData )align (){_cda ._dcad =((_cda ._dcad +7)>>3)<<3};func _ce (_fca ,_aa int )int {if _fca > _aa {return _aa ;};return _fca ;}; -------------------------------------------------------------------------------- /model/internal/docutil/docutil.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package docutil ;import (_bb "errors";_a "fmt";_e "github.com/unidoc/unipdf/v4/common";_ad "github.com/unidoc/unipdf/v4/core";);type OutputIntent struct{Object *_ad .PdfObjectDictionary ;};type OutputIntents struct{_ee *_ad .PdfObjectArray ;_fb *Document ; 13 | _fbe *_ad .PdfIndirectObject ;};type Content struct{Stream *_ad .PdfObjectStream ;_ega int ;_edd Page ;};func _eeb (_fge _ad .PdfObject )(_ad .PdfObjectName ,error ){var _ecc *_ad .PdfObjectName ;var _ffe *_ad .PdfObjectArray ;if _cca ,_ccc :=_fge .(*_ad .PdfIndirectObject ); 14 | _ccc {if _cag ,_dcd :=_cca .PdfObject .(*_ad .PdfObjectArray );_dcd {_ffe =_cag ;}else if _eb ,_bfc :=_cca .PdfObject .(*_ad .PdfObjectName );_bfc {_ecc =_eb ;};}else if _geb ,_acg :=_fge .(*_ad .PdfObjectArray );_acg {_ffe =_geb ;}else if _eee ,_fbgc :=_fge .(*_ad .PdfObjectName ); 15 | _fbgc {_ecc =_eee ;};if _ecc !=nil {switch *_ecc {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return *_ecc ,nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return *_ecc ,nil ; 16 | };};if _ffe !=nil &&_ffe .Len ()> 0{if _dbgg ,_ggb :=_ffe .Get (0).(*_ad .PdfObjectName );_ggb {switch *_dbgg {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":if _ffe .Len ()==1{return *_dbgg ,nil ; 17 | };case "\u0043a\u006c\u0047\u0072\u0061\u0079","\u0043\u0061\u006c\u0052\u0047\u0042","\u004c\u0061\u0062":return *_dbgg ,nil ;case "\u0049\u0043\u0043\u0042\u0061\u0073\u0065\u0064","\u0050a\u0074\u0074\u0065\u0072\u006e","\u0049n\u0064\u0065\u0078\u0065\u0064":return *_dbgg ,nil ; 18 | case "\u0053\u0065\u0070\u0061\u0072\u0061\u0074\u0069\u006f\u006e","\u0044e\u0076\u0069\u0063\u0065\u004e":return *_dbgg ,nil ;};};};return "",nil ;};func (_ceg *Document )GetPages ()([]Page ,bool ){_bf ,_fgg :=_ceg .FindCatalog ();if !_fgg {return nil ,false ; 19 | };return _bf .GetPages ();};func (_fa *Catalog )GetMetadata ()(*_ad .PdfObjectStream ,bool ){return _ad .GetStream (_fa .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061"));};func (_fd *Catalog )GetPages ()([]Page ,bool ){_ab ,_ac :=_ad .GetDict (_fd .Object .Get ("\u0050\u0061\u0067e\u0073")); 20 | if !_ac {return nil ,false ;};_af ,_d :=_ad .GetArray (_ab .Get ("\u004b\u0069\u0064\u0073"));if !_d {return nil ,false ;};_fg :=make ([]Page ,_af .Len ());for _abf ,_ec :=range _af .Elements (){_da ,_aa :=_ad .GetDict (_ec );if !_aa {continue ;};_fg [_abf ]=Page {Object :_da ,_fcf :_abf +1,_cd :_fd ._bd }; 21 | };return _fg ,true ;};type Document struct{ID [2]string ;Version _ad .Version ;Objects []_ad .PdfObject ;Info _ad .PdfObject ;Crypt *_ad .PdfCrypt ;UseHashBasedID bool ;};func (_caeg Page )GetResourcesXObject ()(*_ad .PdfObjectDictionary ,bool ){_ffd ,_gda :=_caeg .GetResources (); 22 | if !_gda {return nil ,false ;};return _ad .GetDict (_ffd .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));};func (_dfb Page )FindXObjectImages ()([]*Image ,error ){_fcc ,_def :=_dfb .GetResourcesXObject ();if !_def {return nil ,nil ;};var _fef []*Image ; 23 | var _egd error ;_feb :=map[*_ad .PdfObjectStream ]int {};_cg :=map[*_ad .PdfObjectStream ]struct{}{};var _eadg int ;for _ ,_ed :=range _fcc .Keys (){_gbf ,_fag :=_ad .GetStream (_fcc .Get (_ed ));if !_fag {continue ;};if _ ,_fbf :=_feb [_gbf ];_fbf {continue ; 24 | };_dce ,_eea :=_ad .GetName (_gbf .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));if !_eea ||_dce .String ()!="\u0049\u006d\u0061g\u0065"{continue ;};_ggbc :=Image {BitsPerComponent :8,Stream :_gbf ,Name :string (_ed )};if _ggbc .Colorspace ,_egd =_eeb (_gbf .Get ("\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065")); 25 | _egd !=nil {_e .Log .Error ("\u0045\u0072\u0072\u006f\u0072\u0020\u0064\u0065\u0074\u0065r\u006d\u0069\u006e\u0065\u0020\u0063\u006fl\u006f\u0072\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u0025\u0073",_egd );continue ;};if _dfe ,_ba :=_ad .GetIntVal (_gbf .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074")); 26 | _ba {_ggbc .BitsPerComponent =_dfe ;};if _dea ,_defg :=_ad .GetIntVal (_gbf .Get ("\u0057\u0069\u0064t\u0068"));_defg {_ggbc .Width =_dea ;};if _ege ,_fcdc :=_ad .GetIntVal (_gbf .Get ("\u0048\u0065\u0069\u0067\u0068\u0074"));_fcdc {_ggbc .Height =_ege ; 27 | };if _dcb ,_cdc :=_ad .GetStream (_gbf .Get ("\u0053\u004d\u0061s\u006b"));_cdc {_ggbc .SMask =&ImageSMask {Image :&_ggbc ,Stream :_dcb };_cg [_dcb ]=struct{}{};};switch _ggbc .Colorspace {case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_ggbc .ColorComponents =3; 28 | case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_ggbc .ColorComponents =1;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_ggbc .ColorComponents =4;default:_ggbc .ColorComponents =-1;};_feb [_gbf ]=_eadg ;_fef =append (_fef ,&_ggbc ); 29 | _eadg ++;};var _gc []int ;for _ ,_gad :=range _fef {if _gad .SMask !=nil {_bfce ,_cea :=_feb [_gad .SMask .Stream ];if _cea {_gc =append (_gc ,_bfce );};};};_bdc :=make ([]*Image ,len (_fef )-len (_gc ));_eadg =0;_aea :for _aac ,_faa :=range _fef {for _ ,_fba :=range _gc {if _aac ==_fba {continue _aea ; 30 | };};_bdc [_eadg ]=_faa ;_eadg ++;};return _fef ,nil ;};func (_fda *Catalog )HasMetadata ()bool {_bdd :=_fda .Object .Get ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061");return _bdd !=nil ;};func (_aead *Content )SetData (data []byte )error {_cgc ,_fbdf :=_ad .MakeStream (data ,_ad .NewFlateEncoder ()); 31 | if _fbdf !=nil {return _fbdf ;};_cdb ,_bfcec :=_ad .GetArray (_aead ._edd .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if !_bfcec &&_aead ._ega ==0{_aead ._edd .Object .Set ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073",_cgc ); 32 | }else {if _fbdf =_cdb .Set (_aead ._ega ,_cgc );_fbdf !=nil {return _fbdf ;};};_aead ._edd ._cd .Objects =append (_aead ._edd ._cd .Objects ,_cgc );return nil ;};func (_ce *OutputIntents )Add (oi _ad .PdfObject )error {_dee ,_ead :=oi .(*_ad .PdfObjectDictionary ); 33 | if !_ead {return _bb .New ("\u0069\u006e\u0070\u0075\u0074\u0020\u006f\u0075\u0074\u0070\u0075\u0074\u0020\u0069\u006e\u0074\u0065\u006et\u0020\u0073\u0068\u006f\u0075\u006c\u0064 \u0062\u0065\u0020\u0061\u006e\u0020\u006f\u0062\u006a\u0065\u0063t\u0020\u0064\u0069\u0063\u0074\u0069\u006f\u006e\u0061\u0072\u0079"); 34 | };if _gde ,_ceb :=_ad .GetStream (_dee .Get ("\u0044\u0065\u0073\u0074\u004f\u0075\u0074\u0070\u0075\u0074\u0050\u0072o\u0066\u0069\u006c\u0065"));_ceb {_ce ._fb .Objects =append (_ce ._fb .Objects ,_gde );};_ged ,_gg :=oi .(*_ad .PdfIndirectObject );if !_gg {_ged =_ad .MakeIndirectObject (oi ); 35 | };if _ce ._ee ==nil {_ce ._ee =_ad .MakeArray (_ged );}else {_ce ._ee .Append (_ged );};_ce ._fb .Objects =append (_ce ._fb .Objects ,_ged );return nil ;};func (_cc *Catalog )GetMarkInfo ()(*_ad .PdfObjectDictionary ,bool ){_db ,_fcd :=_ad .GetDict (_cc .Object .Get ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f")); 36 | return _db ,_fcd ;};func (_g *Catalog )SetStructTreeRoot (structTreeRoot _ad .PdfObject ){if structTreeRoot ==nil {_g .Object .Remove ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074");return ;};_ga :=_ad .MakeIndirectObject (structTreeRoot ); 37 | _g .Object .Set ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074",_ga );_g ._bd .Objects =append (_g ._bd .Objects ,_ga );};func (_cae *Document )FindCatalog ()(*Catalog ,bool ){var _eg *_ad .PdfObjectDictionary ;for _ ,_caa :=range _cae .Objects {_fbg ,_dbg :=_ad .GetDict (_caa ); 38 | if !_dbg {continue ;};if _cb ,_fe :=_ad .GetName (_fbg .Get ("\u0054\u0079\u0070\u0065"));_fe &&*_cb =="\u0043a\u0074\u0061\u006c\u006f\u0067"{_eg =_fbg ;break ;};};if _eg ==nil {return nil ,false ;};return &Catalog {Object :_eg ,_bd :_cae },true ;};func (_bbd Page )FindXObjectForms ()[]*_ad .PdfObjectStream {_bag ,_bbb :=_bbd .GetResourcesXObject (); 39 | if !_bbb {return nil ;};_deeg :=map[*_ad .PdfObjectStream ]struct{}{};var _gdf func (_ebd *_ad .PdfObjectDictionary ,_gcd map[*_ad .PdfObjectStream ]struct{});_gdf =func (_dd *_ad .PdfObjectDictionary ,_debg map[*_ad .PdfObjectStream ]struct{}){for _ ,_aef :=range _dd .Keys (){_bffe ,_gbd :=_ad .GetStream (_dd .Get (_aef )); 40 | if !_gbd {continue ;};if _ ,_gdea :=_debg [_bffe ];_gdea {continue ;};_faf ,_gea :=_ad .GetName (_bffe .Get ("\u0053u\u0062\u0074\u0079\u0070\u0065"));if !_gea ||_faf .String ()!="\u0046\u006f\u0072\u006d"{continue ;};_debg [_bffe ]=struct{}{};_agf ,_gea :=_ad .GetDict (_bffe .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s")); 41 | if !_gea {continue ;};_gdc ,_faga :=_ad .GetDict (_agf .Get ("\u0058O\u0062\u006a\u0065\u0063\u0074"));if _faga {_gdf (_gdc ,_debg );};};};_gdf (_bag ,_deeg );var _ccb []*_ad .PdfObjectStream ;for _edf :=range _deeg {_ccb =append (_ccb ,_edf );};return _ccb ; 42 | };func (_dc *Catalog )GetStructTreeRoot ()(*_ad .PdfObjectDictionary ,bool ){return _ad .GetDict (_dc .Object .Get ("\u0053\u0074\u0072\u0075\u0063\u0074\u0054\u0072\u0065e\u0052\u006f\u006f\u0074"));};func (_f *Catalog )SetVersion (){_f .Object .Set ("\u0056e\u0072\u0073\u0069\u006f\u006e",_ad .MakeName (_a .Sprintf ("\u0025\u0064\u002e%\u0064",_f ._bd .Version .Major ,_f ._bd .Version .Minor ))); 43 | };type Page struct{_fcf int ;Object *_ad .PdfObjectDictionary ;_cd *Document ;};func (_ddf Content )GetData ()([]byte ,error ){_cf ,_be :=_ad .NewEncoderFromStream (_ddf .Stream );if _be !=nil {return nil ,_be ;};_eba ,_be :=_cf .DecodeStream (_ddf .Stream ); 44 | if _be !=nil {return nil ,_be ;};return _eba ,nil ;};type Catalog struct{Object *_ad .PdfObjectDictionary ;_bd *Document ;};func (_gaf *OutputIntents )Len ()int {return _gaf ._ee .Len ()};func (_fbd *Document )AddIndirectObject (indirect *_ad .PdfIndirectObject ){for _ ,_bdg :=range _fbd .Objects {if _bdg ==indirect {return ; 45 | };};_fbd .Objects =append (_fbd .Objects ,indirect );};func (_aaf *Catalog )NewOutputIntents ()*OutputIntents {return &OutputIntents {_fb :_aaf ._bd }};func (_ffa *OutputIntents )Get (i int )(OutputIntent ,bool ){if _ffa ._ee ==nil {return OutputIntent {},false ; 46 | };if i >=_ffa ._ee .Len (){return OutputIntent {},false ;};_fae :=_ffa ._ee .Get (i );_gee ,_gedb :=_ad .GetIndirect (_fae );if !_gedb {_ca ,_eca :=_ad .GetDict (_fae );return OutputIntent {Object :_ca },_eca ;};_gf ,_deb :=_ad .GetDict (_gee .PdfObject ); 47 | return OutputIntent {Object :_gf },_deb ;};func (_c *Catalog )SetMetadata (data []byte )error {_bc ,_fc :=_ad .MakeStream (data ,nil );if _fc !=nil {return _fc ;};_bc .Set ("\u0054\u0079\u0070\u0065",_ad .MakeName ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061")); 48 | _bc .Set ("\u0053u\u0062\u0074\u0079\u0070\u0065",_ad .MakeName ("\u0058\u004d\u004c"));_c .Object .Set ("\u004d\u0065\u0074\u0061\u0064\u0061\u0074\u0061",_bc );_c ._bd .Objects =append (_c ._bd .Objects ,_bc );return nil ;};func (_gd *Catalog )SetMarkInfo (mi _ad .PdfObject ){if mi ==nil {_gd .Object .Remove ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f"); 49 | return ;};_bbe :=_ad .MakeIndirectObject (mi );_gd .Object .Set ("\u004d\u0061\u0072\u006b\u0049\u006e\u0066\u006f",_bbe );_gd ._bd .Objects =append (_gd ._bd .Objects ,_bbe );};func (_ae *Catalog )SetOutputIntents (outputIntents *OutputIntents ){if _ea :=_ae .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073"); 50 | _ea !=nil {for _afe ,_ecf :=range _ae ._bd .Objects {if _ecf ==_ea {if outputIntents ._fbe ==_ea {return ;};_ae ._bd .Objects =append (_ae ._bd .Objects [:_afe ],_ae ._bd .Objects [_afe +1:]...);break ;};};};_bcg :=outputIntents ._fbe ;if _bcg ==nil {_bcg =_ad .MakeIndirectObject (outputIntents ._ee ); 51 | };_ae .Object .Set ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073",_bcg );_ae ._bd .Objects =append (_ae ._bd .Objects ,_bcg );};func (_abff *Page )Number ()int {return _abff ._fcf };func (_de *Catalog )GetOutputIntents ()(*OutputIntents ,bool ){_ge :=_de .Object .Get ("\u004f\u0075\u0074\u0070\u0075\u0074\u0049\u006e\u0074\u0065\u006e\u0074\u0073"); 52 | if _ge ==nil {return nil ,false ;};_df ,_ff :=_ad .GetIndirect (_ge );if !_ff {return nil ,false ;};_cce ,_fgc :=_ad .GetArray (_df .PdfObject );if !_fgc {return nil ,false ;};return &OutputIntents {_fbe :_df ,_ee :_cce ,_fb :_de ._bd },true ;};type ImageSMask struct{Image *Image ; 53 | Stream *_ad .PdfObjectStream ;};func (_bce Page )GetContents ()([]Content ,bool ){_fce ,_bcb :=_ad .GetArray (_bce .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073"));if !_bcb {_ag ,_fdd :=_ad .GetStream (_bce .Object .Get ("\u0043\u006f\u006e\u0074\u0065\u006e\u0074\u0073")); 54 | if !_fdd {return nil ,false ;};return []Content {{Stream :_ag ,_edd :_bce ,_ega :0}},true ;};_ggc :=make ([]Content ,_fce .Len ());for _gb ,_cbd :=range _fce .Elements (){_agc ,_bfd :=_ad .GetStream (_cbd );if !_bfd {continue ;};_ggc [_gb ]=Content {Stream :_agc ,_edd :_bce ,_ega :_gb }; 55 | };return _ggc ,true ;};func (_efc Page )GetResources ()(*_ad .PdfObjectDictionary ,bool ){return _ad .GetDict (_efc .Object .Get ("\u0052e\u0073\u006f\u0075\u0072\u0063\u0065s"));};func (_dbe *Document )AddStream (stream *_ad .PdfObjectStream ){for _ ,_cba :=range _dbe .Objects {if _cba ==stream {return ; 56 | };};_dbe .Objects =append (_dbe .Objects ,stream );};type Image struct{Name string ;Width int ;Height int ;Colorspace _ad .PdfObjectName ;ColorComponents int ;BitsPerComponent int ;SMask *ImageSMask ;Stream *_ad .PdfObjectStream ;}; -------------------------------------------------------------------------------- /ocr/ocr.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package ocr ;import (_d "bytes";_de "context";_b "fmt";_da "github.com/unidoc/unipdf/v4/model";_eg "io";_c "mime/multipart";_g "net/http";_ee "os";_ce "path/filepath";_e "time";); 13 | 14 | // ExtractText extracts text from an image reader. 15 | // The filename parameter is used to set the filename in the multipart form data. 16 | // If filename is empty, a default name based on content type will be used. 17 | // 18 | // Parameters: 19 | // - reader: Image data reader (e.g., file, buffer) 20 | // - filename: Optional filename for the uploaded file (used in multipart form) 21 | func (_cfg *HTTPOCRService )ExtractText (ctx _de .Context ,reader _eg .Reader ,filename string )([]byte ,error ){if _cfg ._fa .Url ==""{return nil ,_b .Errorf ("n\u006f\u0020\u004f\u0043\u0052\u0020s\u0065\u0072\u0076\u0069\u0063\u0065\u0020\u0055\u0052L\u0020\u0070\u0072o\u0076i\u0064\u0065\u0064"); 22 | };if reader ==nil {return nil ,_b .Errorf ("r\u0065a\u0064\u0065\u0072\u0020\u0063\u0061\u006e\u006eo\u0074\u0020\u0062\u0065 n\u0069\u006c");};var _gc _d .Buffer ;_ddf :=_c .NewWriter (&_gc );if filename ==""{_gd :=make ([]byte ,512);_bfa ,_cdd :=reader .Read (_gd ); 23 | if _cdd !=nil &&_cdd !=_eg .EOF {return nil ,_b .Errorf ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0074\u006f\u0020r\u0065\u0061\u0064\u0020\u0066\u0072\u006fm\u0020\u0072\u0065\u0061\u0064\u0065\u0072\u003a\u0020\u0025\u0077",_cdd );};_cbc :=_g .DetectContentType (_gd [:_bfa ]); 24 | switch _cbc {case "\u0069\u006d\u0061\u0067\u0065\u002f\u006a\u0070\u0065\u0067":filename ="\u0069m\u0061\u0067\u0065\u002e\u006a\u0070g";case "\u0069m\u0061\u0067\u0065\u002f\u0070\u006eg":filename ="\u0069m\u0061\u0067\u0065\u002e\u0070\u006eg";case "\u0069m\u0061\u0067\u0065\u002f\u0067\u0069f":filename ="\u0069m\u0061\u0067\u0065\u002e\u0067\u0069f"; 25 | default:filename ="\u0069m\u0061\u0067\u0065\u002e\u006a\u0070g";};reader =_eg .MultiReader (_d .NewReader (_gd [:_bfa ]),reader );};_fbg ,_ebbg :=_ddf .CreateFormFile (_cfg ._fa .FileFieldName ,filename );if _ebbg !=nil {return nil ,_b .Errorf ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0074\u006f\u0020c\u0072\u0065\u0061\u0074\u0065\u0020\u0066o\u0072\u006d\u0020\u0066\u0069\u006c\u0065\u003a\u0020\u0025\u0077",_ebbg ); 26 | };_ ,_ebbg =_eg .Copy (_fbg ,reader );if _ebbg !=nil {return nil ,_b .Errorf ("\u0066\u0061\u0069le\u0064\u0020\u0074\u006f\u0020\u0063\u006f\u0070\u0079\u0020\u0064\u0061\u0074\u0061\u003a\u0020\u0025\u0077",_ebbg );};for _dga ,_bgg :=range _cfg ._fa .FormFields {_ebbg =_ddf .WriteField (_dga ,_bgg ); 27 | if _ebbg !=nil {return nil ,_b .Errorf ("\u0066\u0061\u0069l\u0065\u0064\u0020\u0074o\u0020\u0061\u0064\u0064\u0020\u0066\u006fr\u006d\u0020\u0066\u0069\u0065\u006c\u0064\u0020\u0025\u0073\u003a\u0020\u0025\u0077",_dga ,_ebbg );};};_ebbg =_ddf .Close (); 28 | if _ebbg !=nil {return nil ,_b .Errorf ("\u0066\u0061il\u0065\u0064\u0020t\u006f\u0020\u0063\u006cose\u0020mu\u006c\u0074\u0069\u0070\u0061\u0072\u0074 w\u0072\u0069\u0074\u0065\u0072\u003a\u0020%\u0077",_ebbg );};_eca ,_ebbg :=_g .NewRequestWithContext (ctx ,_cfg ._fa .Method ,_cfg ._fa .Url ,&_gc ); 29 | if _ebbg !=nil {return nil ,_b .Errorf ("\u0066\u0061\u0069\u006ce\u0064\u0020\u0074\u006f\u0020\u0063\u0072\u0065\u0061\u0074e\u0020r\u0065\u0071\u0075\u0065\u0073\u0074\u003a \u0025\u0077",_ebbg );};_eca .Header .Set ("\u0043\u006f\u006et\u0065\u006e\u0074\u002d\u0054\u0079\u0070\u0065",_ddf .FormDataContentType ()); 30 | for _ad ,_dbe :=range _cfg ._fa .Headers {_eca .Header .Set (_ad ,_dbe );};if _cfg ._fa .RequestModifier !=nil {if _cea :=_cfg ._fa .RequestModifier (_eca );_cea !=nil {return nil ,_b .Errorf ("r\u0065\u0071\u0075\u0065\u0073\u0074 \u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0072\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0077",_cea ); 31 | };};return _cfg .executeRequestWithRetry (ctx ,_eca );}; 32 | 33 | // HTTPOCRService implements OCRService using HTTP requests. 34 | // 35 | // This service is mainly designed to work with https://github.com/unidoc/ocrserver 36 | // but can be adapted to other HTTP-based OCR services with similar APIs. 37 | type HTTPOCRService struct{_fa OCROptions }; 38 | 39 | // OCROptions provides configuration for HTTP-based OCR services. 40 | type OCROptions struct{ 41 | 42 | // URL for the OCR service. 43 | Url string ; 44 | 45 | // HTTP method to use for the OCR request (default: POST). 46 | Method string ; 47 | 48 | // Custom headers to add to the request. 49 | Headers map[string ]string ; 50 | 51 | // Form field name for the file upload (default: "file"). 52 | FileFieldName string ; 53 | 54 | // Additional form fields to send with the request. 55 | FormFields map[string ]string ; 56 | 57 | // HTTP client timeout in seconds (default: 30). 58 | TimeoutSeconds int ; 59 | 60 | // Maximum number of retry attempts on failure (default: 0, no retry). 61 | MaxRetries int ; 62 | 63 | // Custom HTTP client (optional - if provided, TimeoutSeconds is ignored). 64 | Client *_g .Client ; 65 | 66 | // Custom request modifier function (called after request is created). 67 | RequestModifier func (*_g .Request )error ;}; 68 | 69 | // Service returns the underlying OCR service. 70 | func (_egf *Client )Service ()OCRService {return _egf ._cg };func (_fcf *HTTPOCRService )executeRequestWithRetry (_ff _de .Context ,_bcb *_g .Request )([]byte ,error ){_bge :=_fcf ._fa .Client ;if _bge ==nil {_bge =&_g .Client {Timeout :_e .Duration (_fcf ._fa .TimeoutSeconds )*_e .Second }; 71 | };_fb :=_fcf ._fa .MaxRetries +1;var _acb error ;for _gf :=0;_gf < _fb ;_gf ++{_ecd :=_bcb .Clone (_ff );_bfg ,_bb :=_bge .Do (_ecd );if _bb !=nil {_acb =_b .Errorf ("\u0066a\u0069\u006ce\u0064\u0020\u0074o\u0020\u0065\u0078\u0065\u0063\u0075\u0074e\u0020\u0072\u0065\u0071\u0075\u0065s\u0074\u0020\u0028\u0061\u0074\u0074\u0065\u006d\u0070\u0074\u0020%\u0064\u002f\u0025\u0064\u0029\u003a\u0020\u0025\u0077",_gf +1,_fb ,_bb ); 72 | if _gf < _fb -1{_e .Sleep (_e .Duration (_gf +1)*_e .Second );continue ;};break ;};defer _bfg .Body .Close ();_cae ,_bb :=_eg .ReadAll (_bfg .Body );if _bb !=nil {_acb =_b .Errorf ("\u0066\u0061\u0069\u006c\u0065\u0064\u0020t\u006f\u0020\u0072e\u0061\u0064\u0020\u0072e\u0073\u0070\u006f\u006e\u0073\u0065\u0020\u0028\u0061\u0074\u0074\u0065\u006d\u0070\u0074\u0020\u0025\u0064\u002f\u0025\u0064\u0029\u003a\u0020\u0025\u0077",_gf +1,_fb ,_bb ); 73 | if _gf < _fb -1{continue ;};break ;};if _bfg .StatusCode < 200||_bfg .StatusCode >=300{_acb =_b .Errorf ("\u0072\u0065\u0071\u0075\u0065\u0073t\u0020\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0077\u0069\u0074\u0068\u0020\u0073\u0074\u0061\u0074\u0075\u0073\u0020%\u0073\u0020\u0028\u0061\u0074\u0074\u0065\u006d\u0070\u0074\u0020\u0025\u0064\u002f%\u0064)\u003a\u0020\u0025\u0073",_bfg .Status ,_gf +1,_fb ,string (_cae )); 74 | if _gf < _fb -1{continue ;};break ;};return _cae ,nil ;};return nil ,_acb ;}; 75 | 76 | // ExtractText extracts text from an image reader 77 | func (_ed *Client )ExtractText (ctx _de .Context ,reader _eg .Reader ,filename string )([]byte ,error ){if reader ==nil {return nil ,_b .Errorf ("r\u0065a\u0064\u0065\u0072\u0020\u0063\u0061\u006e\u006eo\u0074\u0020\u0062\u0065 n\u0069\u006c");};return _ed ._cg .ExtractText (ctx ,reader ,filename ); 78 | }; 79 | 80 | // BatchProcessFiles processes multiple image files concurrently from a list of file paths. 81 | func (_ba *Client )BatchProcessFiles (ctx _de .Context ,filePaths []string )([][]byte ,[]error ){if len (filePaths )==0{return nil ,nil ;};_bca :=make ([][]byte ,len (filePaths ));_fc :=make ([]error ,len (filePaths ));_eag :=make (chan struct{},10);type result struct{_cb int ; 82 | _cc []byte ;_ebb error ;};_bfe :=make (chan result ,len (filePaths ));for _dca ,_bg :=range filePaths {go func (_def int ,_defc string ){_eag <-struct{}{};defer func (){<-_eag }();_acc ,_df :=_ba .ExtractTextFromFile (ctx ,_defc );_bfe <-result {_cb :_def ,_cc :_acc ,_ebb :_df }; 83 | }(_dca ,_bg );};for _aae :=0;_aae < len (filePaths );_aae ++{_cbf :=<-_bfe ;_bca [_cbf ._cb ]=_cbf ._cc ;_fc [_cbf ._cb ]=_cbf ._ebb ;};return _bca ,_fc ;}; 84 | 85 | // NewOCRHTTPClient creates a new OCR client using HTTP service with the given options. 86 | func NewOCRHTTPClient (options OCROptions )*Client {return &Client {_cg :NewHTTPOCRService (options )}}; 87 | 88 | // WithService returns a new client with the given service. 89 | func (_aa *Client )WithService (service OCRService )*Client {return &Client {_cg :service }}; 90 | 91 | // CallEndpoint executes an HTTP request to the configured URL. 92 | // This provides a general method for users to execute HTTP requests using 93 | // the service's configured options (URL, method, headers, timeout, etc.). 94 | // 95 | // The URL, method, and headers are taken from the OCROptions used to create this service. 96 | // To call different endpoints, create separate service instances with different URLs. 97 | // 98 | // Parameters: 99 | // - body: Request body (can be nil for GET requests or when no body is needed) 100 | func (_aec *HTTPOCRService )CallEndpoint (ctx _de .Context ,body _eg .Reader )([]byte ,error ){if _aec ._fa .Url ==""{return nil ,_b .Errorf ("\u006e\u006f\u0020U\u0052\u004c\u0020\u0063o\u006e\u0066\u0069\u0067\u0075\u0072\u0065d\u0020\u0069\u006e\u0020\u004f\u0043\u0052\u004f\u0070\u0074\u0069\u006f\u006e\u0073"); 101 | };_gcg :=_aec ._fa .Method ;if _gcg ==""{_gcg ="\u0047\u0045\u0054";};_fag ,_gb :=_g .NewRequestWithContext (ctx ,_gcg ,_aec ._fa .Url ,body );if _gb !=nil {return nil ,_b .Errorf ("\u0066\u0061\u0069\u006ce\u0064\u0020\u0074\u006f\u0020\u0063\u0072\u0065\u0061\u0074e\u0020r\u0065\u0071\u0075\u0065\u0073\u0074\u003a \u0025\u0077",_gb ); 102 | };for _cfb ,_bbd :=range _aec ._fa .Headers {_fag .Header .Set (_cfb ,_bbd );};if _aec ._fa .RequestModifier !=nil {if _bcd :=_aec ._fa .RequestModifier (_fag );_bcd !=nil {return nil ,_b .Errorf ("r\u0065\u0071\u0075\u0065\u0073\u0074 \u006d\u006f\u0064\u0069\u0066\u0069\u0065\u0072\u0020f\u0061\u0069\u006ce\u0064:\u0020\u0025\u0077",_bcd ); 103 | };};return _aec .executeRequestWithRetry (ctx ,_fag );}; 104 | 105 | // NewHTTPOCRService creates a new HTTP-based OCR service. 106 | func NewHTTPOCRService (options OCROptions )*HTTPOCRService {if options .Method ==""{options .Method ="\u0050\u004f\u0053\u0054";};if options .FileFieldName ==""{options .FileFieldName ="\u0066\u0069\u006c\u0065";};if options .TimeoutSeconds ==0{options .TimeoutSeconds =30; 107 | };if options .Headers ==nil {options .Headers =make (map[string ]string );};if options .FormFields ==nil {options .FormFields =make (map[string ]string );};return &HTTPOCRService {_fa :options };}; 108 | 109 | // ExtractTextFromImage extracts text from a UniPDF image 110 | func (_dad *Client )ExtractTextFromImage (ctx _de .Context ,image *_da .Image )([]byte ,error ){if image ==nil {return nil ,_b .Errorf ("\u0069\u006d\u0061\u0067e \u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062\u0065\u0020\u006e\u0069\u006c");};if len (image .Data )==0{return nil ,_b .Errorf ("\u0069\u006d\u0061\u0067e \u0064\u0061\u0074\u0061\u0020\u0069\u0073\u0020\u0065\u006d\u0070\u0074\u0079"); 111 | };_ca :=_d .NewReader (image .Data );_dc :="\u0069m\u0061\u0067\u0065\u002e\u006a\u0070g";return _dad ._cg .ExtractText (ctx ,_ca ,_dc );}; 112 | 113 | // OCRService defines the interface for OCR services. 114 | type OCRService interface{ 115 | 116 | // ExtractText extracts text from an image reader. 117 | // The filename parameter is used to set the filename in the multipart form data. 118 | // If filename is empty, a default name based on content type will be used. 119 | // 120 | // Parameters: 121 | // - reader: Image data reader (e.g., file, buffer) 122 | // - filename: Optional filename for the uploaded file (used in multipart form) 123 | ExtractText (_ebe _de .Context ,_bbc _eg .Reader ,_gff string )([]byte ,error ); 124 | 125 | // CallEndpoint executes an HTTP request using the service's configured URL and options. 126 | CallEndpoint (_cff _de .Context ,_dgb _eg .Reader )([]byte ,error );}; 127 | 128 | // ExtractTextFromFile extracts text from an image file. 129 | func (_daa *Client )ExtractTextFromFile (ctx _de .Context ,filePath string )([]byte ,error ){if filePath ==""{return nil ,_b .Errorf ("\u0066i\u006c\u0065\u0020\u0070a\u0074\u0068\u0020\u0063\u0061n\u006eo\u0074 \u0062\u0065\u0020\u0065\u006d\u0070\u0074y"); 130 | };_dd ,_f :=_ee .Open (filePath );if _f !=nil {return nil ,_b .Errorf ("\u0065r\u0072\u006f\u0072\u0020o\u0070\u0065\u006e\u0069\u006eg\u0020f\u0069l\u0065\u0020\u0025\u0073\u003a\u0020\u0025w",filePath ,_f );};defer _dd .Close ();_dg :=_ce .Base (filePath ); 131 | return _daa ._cg .ExtractText (ctx ,_dd ,_dg );}; 132 | 133 | // NewClient creates a new OCR client with the given service. 134 | func NewClient (service OCRService )*Client {return &Client {_cg :service }}; 135 | 136 | // BatchProcess processes multiple images concurrently. 137 | func (_bf *Client )BatchProcess (ctx _de .Context ,images []*_da .Image )([][]byte ,[]error ){if len (images )==0{return nil ,nil ;};_ae :=make ([][]byte ,len (images ));_edc :=make ([]error ,len (images ));_ea :=make (chan struct{},10);type result struct{_af int ; 138 | _bc []byte ;_ge error ;};_cd :=make (chan result ,len (images ));for _afb ,_db :=range images {go func (_ced int ,_ceb *_da .Image ){_ea <-struct{}{};defer func (){<-_ea }();_aag ,_ac :=_bf .ExtractTextFromImage (ctx ,_ceb );_cd <-result {_af :_ced ,_bc :_aag ,_ge :_ac }; 139 | }(_afb ,_db );};for _cf :=0;_cf < len (images );_cf ++{_eb :=<-_cd ;_ae [_eb ._af ]=_eb ._bc ;_edc [_eb ._af ]=_eb ._ge ;};return _ae ,_edc ;}; 140 | 141 | // Client provides a high-level interface for OCR operations. 142 | type Client struct{_cg OCRService }; 143 | 144 | // CallEndpoint executes an HTTP request using the underlying service's configured options. 145 | // The URL, method, headers, and other settings are taken from the OCROptions 146 | // used to create the service. 147 | // 148 | // To call different endpoints, create separate service instances with different URLs: 149 | // 150 | // statusService := NewHTTPOCRService(OCROptions{Url: "http://localhost:8080/status", Method: "GET"}) 151 | // ocrService := NewHTTPOCRService(OCROptions{Url: "http://localhost:8080/ocr", Method: "POST"}) 152 | // 153 | // Parameters: 154 | // - body: Request body (can be nil for GET requests or when no body is needed) 155 | // 156 | // Example usage: 157 | // 158 | // result, err := client.CallEndpoint(ctx, nil) // GET request 159 | // result, err := client.CallEndpoint(ctx, requestBody) // POST request with body 160 | func (_ec *Client )CallEndpoint (ctx _de .Context ,body _eg .Reader )([]byte ,error ){return _ec ._cg .CallEndpoint (ctx ,body );}; -------------------------------------------------------------------------------- /core/security/crypt/crypt.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package crypt ;import (_b "crypto/aes";_a "crypto/cipher";_g "crypto/md5";_da "crypto/rand";_eg "crypto/rc4";_e "fmt";_ee "github.com/unidoc/unipdf/v4/common";_af "github.com/unidoc/unipdf/v4/core/security";_ec "io";);func init (){_cbcd ("\u0041\u0045\u0053V\u0032",_ag )}; 13 | 14 | 15 | // MakeKey implements Filter interface. 16 | func (filterAESV3 )MakeKey (_ ,_ uint32 ,ekey []byte )([]byte ,error ){return ekey ,nil }; 17 | 18 | // KeyLength implements Filter interface. 19 | func (_fbb filterV2 )KeyLength ()int {return _fbb ._aed };var (_dgb =make (map[string ]filterFunc ););func (filterIdentity )KeyLength ()int {return 0};type filterFunc func (_bcb FilterDict )(Filter ,error ); 20 | 21 | // PDFVersion implements Filter interface. 22 | func (_bfe filterV2 )PDFVersion ()[2]int {return [2]int {}}; 23 | 24 | // KeyLength implements Filter interface. 25 | func (filterAESV2 )KeyLength ()int {return 128/8};type filterV2 struct{_aed int }; 26 | 27 | // Name implements Filter interface. 28 | func (filterAESV2 )Name ()string {return "\u0041\u0045\u0053V\u0032"};func init (){_cbcd ("\u0041\u0045\u0053V\u0033",_ba )}; 29 | 30 | // FilterDict represents information from a CryptFilter dictionary. 31 | type FilterDict struct{CFM string ;AuthEvent _af .AuthEvent ;Length int ;}; 32 | 33 | // HandlerVersion implements Filter interface. 34 | func (filterAESV3 )HandlerVersion ()(V ,R int ){V ,R =5,6;return ;};func _bfd (_cbcb string )(filterFunc ,error ){_dad :=_dgb [_cbcb ];if _dad ==nil {return nil ,_e .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",_cbcb ); 35 | };return _dad ,nil ;}; 36 | 37 | // NewIdentity creates an identity filter that bypasses all data without changes. 38 | func NewIdentity ()Filter {return filterIdentity {}}; 39 | 40 | // Name implements Filter interface. 41 | func (filterV2 )Name ()string {return "\u0056\u0032"};func (filterAES )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_gg ,_fd :=_b .NewCipher (okey );if _fd !=nil {return nil ,_fd ;};_ee .Log .Trace ("A\u0045\u0053\u0020\u0045nc\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf ); 42 | const _egb =_b .BlockSize ;_dd :=_egb -len (buf )%_egb ;for _ab :=0;_ab < _dd ;_ab ++{buf =append (buf ,byte (_dd ));};_ee .Log .Trace ("\u0050a\u0064d\u0065\u0064\u0020\u0074\u006f \u0025\u0064 \u0062\u0079\u0074\u0065\u0073",len (buf ));_egbg :=make ([]byte ,_egb +len (buf )); 43 | _ecb :=_egbg [:_egb ];if _ ,_ca :=_ec .ReadFull (_da .Reader ,_ecb );_ca !=nil {return nil ,_ca ;};_gf :=_a .NewCBCEncrypter (_gg ,_ecb );_gf .CryptBlocks (_egbg [_egb :],buf );buf =_egbg ;_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf ); 44 | return buf ,nil ;}; 45 | 46 | // HandlerVersion implements Filter interface. 47 | func (filterAESV2 )HandlerVersion ()(V ,R int ){V ,R =4,4;return ;};func _ba (_dfd FilterDict )(Filter ,error ){if _dfd .Length ==256{_ee .Log .Debug ("\u0041\u0045S\u0056\u0033\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_dfd .Length ); 48 | _dfd .Length /=8;};if _dfd .Length !=0&&_dfd .Length !=32{return nil ,_e .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",_dfd .Length ); 49 | };return filterAESV3 {},nil ;}; 50 | 51 | // DecryptBytes implements Filter interface. 52 | func (filterV2 )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_dba ,_gbb :=_eg .NewCipher (okey );if _gbb !=nil {return nil ,_gbb ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf ); 53 | _dba .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;}; 54 | 55 | // NewFilterV2 creates a RC4-based filter with a specified key length (in bytes). 56 | func NewFilterV2 (length int )Filter {_db ,_ff :=_ffa (FilterDict {Length :length });if _ff !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020R\u0043\u0034\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_ff ); 57 | return filterV2 {_aed :length };};return _db ;};func (filterIdentity )PDFVersion ()[2]int {return [2]int {}}; 58 | 59 | // NewFilter creates CryptFilter from a corresponding dictionary. 60 | func NewFilter (d FilterDict )(Filter ,error ){_baa ,_eb :=_bfd (d .CFM );if _eb !=nil {return nil ,_eb ;};_bfa ,_eb :=_baa (d );if _eb !=nil {return nil ,_eb ;};return _bfa ,nil ;};func init (){_cbcd ("\u0056\u0032",_ffa )}; 61 | 62 | // EncryptBytes implements Filter interface. 63 | func (filterV2 )EncryptBytes (buf []byte ,okey []byte )([]byte ,error ){_de ,_ddg :=_eg .NewCipher (okey );if _ddg !=nil {return nil ,_ddg ;};_ee .Log .Trace ("\u0052\u00434\u0020\u0045\u006ec\u0072\u0079\u0070\u0074\u003a\u0020\u0025\u0020\u0078",buf ); 64 | _de .XORKeyStream (buf ,buf );_ee .Log .Trace ("\u0074o\u003a\u0020\u0025\u0020\u0078",buf );return buf ,nil ;};func _ag (_bce FilterDict )(Filter ,error ){if _bce .Length ==128{_ee .Log .Debug ("\u0041\u0045S\u0056\u0032\u0020c\u0072\u0079\u0070\u0074\u0020f\u0069\u006c\u0074\u0065\u0072 l\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072\u0073\u0020\u0074\u006f\u0020\u0062e\u0020i\u006e\u0020\u0062\u0069\u0074\u0073 ra\u0074\u0068\u0065\u0072\u0020\u0074\u0068\u0061\u006e\u0020\u0062\u0079te\u0073 \u002d\u0020\u0061\u0073s\u0075m\u0069n\u0067\u0020b\u0069\u0074s \u0028\u0025\u0064\u0029",_bce .Length ); 65 | _bce .Length /=8;};if _bce .Length !=0&&_bce .Length !=16{return nil ,_e .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",_bce .Length ); 66 | };return filterAESV2 {},nil ;};func (filterIdentity )Name ()string {return "\u0049\u0064\u0065\u006e\u0074\u0069\u0074\u0079"}; 67 | 68 | // MakeKey implements Filter interface. 69 | func (_ccc filterV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ed (objNum ,genNum ,ekey ,false );}; 70 | 71 | // NewFilterAESV3 creates an AES-based filter with a 256 bit key (AESV3). 72 | func NewFilterAESV3 ()Filter {_fe ,_df :=_ba (FilterDict {});if _df !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0033\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_df ); 73 | return filterAESV3 {};};return _fe ;}; 74 | 75 | // PDFVersion implements Filter interface. 76 | func (filterAESV2 )PDFVersion ()[2]int {return [2]int {1,5}};func (filterIdentity )EncryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil }; 77 | 78 | // Filter is a common interface for crypt filter methods. 79 | type Filter interface{ 80 | 81 | // Name returns a name of the filter that should be used in CFM field of Encrypt dictionary. 82 | Name ()string ; 83 | 84 | // KeyLength returns a length of the encryption key in bytes. 85 | KeyLength ()int ; 86 | 87 | // PDFVersion reports the minimal version of PDF document that introduced this filter. 88 | PDFVersion ()[2]int ; 89 | 90 | // HandlerVersion reports V and R parameters that should be used for this filter. 91 | HandlerVersion ()(V ,R int ); 92 | 93 | // MakeKey generates a object encryption key based on file encryption key and object numbers. 94 | // Used only for legacy filters - AESV3 doesn't change the key for each object. 95 | MakeKey (_cac ,_ad uint32 ,_cd []byte )([]byte ,error ); 96 | 97 | // EncryptBytes encrypts a buffer using object encryption key, as returned by MakeKey. 98 | // Implementation may reuse a buffer and encrypt data in-place. 99 | EncryptBytes (_ce []byte ,_aa []byte )([]byte ,error ); 100 | 101 | // DecryptBytes decrypts a buffer using object encryption key, as returned by MakeKey. 102 | // Implementation may reuse a buffer and decrypt data in-place. 103 | DecryptBytes (_ffb []byte ,_ea []byte )([]byte ,error );}; 104 | 105 | // KeyLength implements Filter interface. 106 | func (filterAESV3 )KeyLength ()int {return 256/8};func (filterIdentity )MakeKey (objNum ,genNum uint32 ,fkey []byte )([]byte ,error ){return fkey ,nil };var _ Filter =filterAESV3 {};var _ Filter =filterAESV2 {}; 107 | 108 | // NewFilterAESV2 creates an AES-based filter with a 128 bit key (AESV2). 109 | func NewFilterAESV2 ()Filter {_fb ,_bc :=_ag (FilterDict {});if _bc !=nil {_ee .Log .Error ("E\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0063re\u0061\u0074\u0065\u0020A\u0045\u0053\u0020\u0056\u0032\u0020\u0063\u0072\u0079pt\u0020\u0066i\u006c\u0074\u0065\u0072\u003a\u0020\u0025\u0076",_bc ); 110 | return filterAESV2 {};};return _fb ;};var _ Filter =filterV2 {};type filterIdentity struct{};func (filterIdentity )DecryptBytes (p []byte ,okey []byte )([]byte ,error ){return p ,nil };func (filterAES )DecryptBytes (buf []byte ,okey []byte )([]byte ,error ){_bb ,_dda :=_b .NewCipher (okey ); 111 | if _dda !=nil {return nil ,_dda ;};if len (buf )< 16{_ee .Log .Debug ("\u0045R\u0052\u004f\u0052\u0020\u0041\u0045\u0053\u0020\u0069\u006e\u0076a\u006c\u0069\u0064\u0020\u0062\u0075\u0066\u0020\u0025\u0073",buf );return buf ,_e .Errorf ("\u0041\u0045\u0053\u003a B\u0075\u0066\u0020\u006c\u0065\u006e\u0020\u003c\u0020\u0031\u0036\u0020\u0028\u0025d\u0029",len (buf )); 112 | };_bf :=buf [:16];buf =buf [16:];if len (buf )%16!=0{_ee .Log .Debug ("\u0020\u0069\u0076\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (_bf ),_bf );_ee .Log .Debug ("\u0062\u0075\u0066\u0020\u0028\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf ); 113 | return buf ,_e .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 )); 114 | };_cc :=_a .NewCBCDecrypter (_bb ,_bf );_ee .Log .Trace ("A\u0045\u0053\u0020\u0044ec\u0072y\u0070\u0074\u0020\u0028\u0025d\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );_ee .Log .Trace ("\u0063\u0068\u006f\u0070\u0020\u0041\u0045\u0053\u0020\u0044\u0065c\u0072\u0079\u0070\u0074\u0020\u0028\u0025\u0064\u0029\u003a \u0025\u0020\u0078",len (buf ),buf ); 115 | _cc .CryptBlocks (buf ,buf );_ee .Log .Trace ("\u0074\u006f\u0020(\u0025\u0064\u0029\u003a\u0020\u0025\u0020\u0078",len (buf ),buf );if len (buf )==0{_ee .Log .Trace ("\u0045\u006d\u0070\u0074\u0079\u0020b\u0075\u0066\u002c\u0020\u0072\u0065\u0074\u0075\u0072\u006e\u0069\u006e\u0067 \u0065\u006d\u0070\u0074\u0079\u0020\u0073t\u0072\u0069\u006e\u0067"); 116 | return buf ,nil ;};_fa :=int (buf [len (buf )-1]);if _fa > len (buf ){_ee .Log .Debug ("\u0049\u006c\u006c\u0065g\u0061\u006c\u0020\u0070\u0061\u0064\u0020\u006c\u0065\u006eg\u0074h\u0020\u0028\u0025\u0064\u0020\u003e\u0020%\u0064\u0029",_fa ,len (buf )); 117 | return buf ,_e .Errorf ("\u0069n\u0076a\u006c\u0069\u0064\u0020\u0070a\u0064\u0020l\u0065\u006e\u0067\u0074\u0068");};buf =buf [:len (buf )-_fa ];return buf ,nil ;};type filterAESV3 struct{filterAES };func (filterIdentity )HandlerVersion ()(V ,R int ){return ; 118 | };func _ed (_afb ,_fbd uint32 ,_ga []byte ,_ae bool )([]byte ,error ){_dc :=make ([]byte ,len (_ga )+5);copy (_dc ,_ga );for _dab :=0;_dab < 3;_dab ++{_abd :=byte ((_afb >>uint32 (8*_dab ))&0xff);_dc [_dab +len (_ga )]=_abd ;};for _fea :=0;_fea < 2;_fea ++{_fc :=byte ((_fbd >>uint32 (8*_fea ))&0xff); 119 | _dc [_fea +len (_ga )+3]=_fc ;};if _ae {_dc =append (_dc ,0x73);_dc =append (_dc ,0x41);_dc =append (_dc ,0x6C);_dc =append (_dc ,0x54);};_dcc :=_g .New ();_dcc .Write (_dc );_bbd :=_dcc .Sum (nil );if len (_ga )+5< 16{return _bbd [0:len (_ga )+5],nil ; 120 | };return _bbd ,nil ;}; 121 | 122 | // Name implements Filter interface. 123 | func (filterAESV3 )Name ()string {return "\u0041\u0045\u0053V\u0033"};type filterAESV2 struct{filterAES };type filterAES struct{};func _cbcd (_dabd string ,_add filterFunc ){if _ ,_eed :=_dgb [_dabd ];_eed {panic ("\u0061l\u0072e\u0061\u0064\u0079\u0020\u0072e\u0067\u0069s\u0074\u0065\u0072\u0065\u0064"); 124 | };_dgb [_dabd ]=_add ;}; 125 | 126 | // PDFVersion implements Filter interface. 127 | func (filterAESV3 )PDFVersion ()[2]int {return [2]int {2,0}}; 128 | 129 | // HandlerVersion implements Filter interface. 130 | func (_gb filterV2 )HandlerVersion ()(V ,R int ){V ,R =2,3;return ;}; 131 | 132 | // MakeKey implements Filter interface. 133 | func (filterAESV2 )MakeKey (objNum ,genNum uint32 ,ekey []byte )([]byte ,error ){return _ed (objNum ,genNum ,ekey ,true );};func _ffa (_dg FilterDict )(Filter ,error ){if _dg .Length %8!=0{return nil ,_e .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",_dg .Length ); 134 | };if _dg .Length < 5||_dg .Length > 16{if _dg .Length ==40||_dg .Length ==64||_dg .Length ==128{_ee .Log .Debug ("\u0053\u0054\u0041\u004e\u0044AR\u0044\u0020V\u0049\u004f\u004c\u0041\u0054\u0049\u004f\u004e\u003a\u0020\u0043\u0072\u0079\u0070\u0074\u0020\u004c\u0065\u006e\u0067\u0074\u0068\u0020\u0061\u0070\u0070\u0065\u0061\u0072s\u0020\u0074\u006f \u0062\u0065\u0020\u0069\u006e\u0020\u0062\u0069\u0074\u0073\u0020\u0072\u0061t\u0068\u0065\u0072\u0020\u0074h\u0061\u006e\u0020\u0062\u0079\u0074\u0065\u0073\u0020-\u0020\u0061s\u0073u\u006d\u0069\u006e\u0067\u0020\u0062\u0069t\u0073\u0020\u0028\u0025\u0064\u0029",_dg .Length ); 135 | _dg .Length /=8;}else {return nil ,_e .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",_dg .Length ); 136 | };};return filterV2 {_aed :_dg .Length },nil ;}; -------------------------------------------------------------------------------- /internal/jbig2/encoder/arithmetic/arithmetic.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package arithmetic ;import (_g "bytes";_ac "github.com/unidoc/unipdf/v4/common";_d "github.com/unidoc/unipdf/v4/internal/jbig2/bitmap";_f "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_a "io";);func (_eef *Encoder )codeMPS (_fc *codingContext ,_agc uint32 ,_abc uint16 ,_cecb byte ){_eef ._fd -=_abc ; 13 | if _eef ._fd &0x8000!=0{_eef ._ea +=uint32 (_abc );return ;};if _eef ._fd < _abc {_eef ._fd =_abc ;}else {_eef ._ea +=uint32 (_abc );};_fc ._fb [_agc ]=_ebd [_cecb ]._gdf ;_eef .renormalize ();};func (_gbd *Encoder )flush (){_gbd .setBits ();_gbd ._ea <<=_gbd ._gec ; 14 | _gbd .byteOut ();_gbd ._ea <<=_gbd ._gec ;_gbd .byteOut ();_gbd .emit ();if _gbd ._fbf !=0xff{_gbd ._efd ++;_gbd ._fbf =0xff;_gbd .emit ();};_gbd ._efd ++;_gbd ._fbf =0xac;_gbd ._efd ++;_gbd .emit ();};func (_fba *Encoder )Reset (){_fba ._fd =0x8000;_fba ._ea =0; 15 | _fba ._gec =12;_fba ._efd =-1;_fba ._fbf =0;_fba ._ad =nil ;_fba ._ba =_geb (_fca );};func (_bg *Encoder )EncodeInteger (proc Class ,value int )(_dg error ){_ac .Log .Trace ("\u0045\u006eco\u0064\u0065\u0020I\u006e\u0074\u0065\u0067er:\u0027%d\u0027\u0020\u0077\u0069\u0074\u0068\u0020Cl\u0061\u0073\u0073\u003a\u0020\u0027\u0025s\u0027",value ,proc ); 16 | if _dg =_bg .encodeInteger (proc ,value );_dg !=nil {return _f .Wrap (_dg ,"\u0045\u006e\u0063\u006f\u0064\u0065\u0049\u006e\u0074\u0065\u0067\u0065\u0072","");};return nil ;};type codingContext struct{_fb []byte ;_da []byte ;};func (_fffe *Encoder )code1 (_gd *codingContext ,_bda uint32 ,_ccc uint16 ,_cae byte ){if _gd .mps (_bda )==1{_fffe .codeMPS (_gd ,_bda ,_ccc ,_cae ); 17 | }else {_fffe .codeLPS (_gd ,_bda ,_ccc ,_cae );};};const (IAAI Class =iota ;IADH ;IADS ;IADT ;IADW ;IAEX ;IAFS ;IAIT ;IARDH ;IARDW ;IARDX ;IARDY ;IARI ;);func (_ccg *Encoder )EncodeOOB (proc Class )(_beb error ){_ac .Log .Trace ("E\u006e\u0063\u006f\u0064\u0065\u0020O\u004f\u0042\u0020\u0077\u0069\u0074\u0068\u0020\u0043l\u0061\u0073\u0073:\u0020'\u0025\u0073\u0027",proc ); 18 | if _beb =_ccg .encodeOOB (proc );_beb !=nil {return _f .Wrap (_beb ,"\u0045n\u0063\u006f\u0064\u0065\u004f\u004fB","");};return nil ;};func New ()*Encoder {_ff :=&Encoder {};_ff .Init ();return _ff };func (_gg *Encoder )DataSize ()int {return _gg .dataSize ()}; 19 | func (_eb *Encoder )Refine (iTemp ,iTarget *_d .Bitmap ,ox ,oy int )error {for _ffc :=0;_ffc < iTarget .Height ;_ffc ++{var _acb int ;_aga :=_ffc +oy ;var (_fec ,_ab ,_ed ,_ee ,_agf uint16 ;_cda ,_gca ,_ecb ,_fbe ,_cdf byte ;);if _aga >=1&&(_aga -1)< iTemp .Height {_cda =iTemp .Data [(_aga -1)*iTemp .RowStride ]; 20 | };if _aga >=0&&_aga < iTemp .Height {_gca =iTemp .Data [_aga *iTemp .RowStride ];};if _aga >=-1&&_aga +1< iTemp .Height {_ecb =iTemp .Data [(_aga +1)*iTemp .RowStride ];};if _ffc >=1{_fbe =iTarget .Data [(_ffc -1)*iTarget .RowStride ];};_cdf =iTarget .Data [_ffc *iTarget .RowStride ]; 21 | _ecf :=uint (6+ox );_fec =uint16 (_cda >>_ecf );_ab =uint16 (_gca >>_ecf );_ed =uint16 (_ecb >>_ecf );_ee =uint16 (_fbe >>6);_cee :=uint (2-ox );_cda <<=_cee ;_gca <<=_cee ;_ecb <<=_cee ;_fbe <<=2;for _acb =0;_acb < iTarget .Width ;_acb ++{_dc :=(_fec <<10)|(_ab <<7)|(_ed <<4)|(_ee <<1)|_agf ; 22 | _ffde :=_cdf >>7;_bdc :=_eb .encodeBit (_eb ._ba ,uint32 (_dc ),_ffde );if _bdc !=nil {return _bdc ;};_fec <<=1;_ab <<=1;_ed <<=1;_ee <<=1;_fec |=uint16 (_cda >>7);_ab |=uint16 (_gca >>7);_ed |=uint16 (_ecb >>7);_ee |=uint16 (_fbe >>7);_agf =uint16 (_ffde ); 23 | _cgb :=_acb %8;_gcc :=_acb /8+1;if _cgb ==5+ox {_cda ,_gca ,_ecb =0,0,0;if _gcc < iTemp .RowStride &&_aga >=1&&(_aga -1)< iTemp .Height {_cda =iTemp .Data [(_aga -1)*iTemp .RowStride +_gcc ];};if _gcc < iTemp .RowStride &&_aga >=0&&_aga < iTemp .Height {_gca =iTemp .Data [_aga *iTemp .RowStride +_gcc ]; 24 | };if _gcc < iTemp .RowStride &&_aga >=-1&&(_aga +1)< iTemp .Height {_ecb =iTemp .Data [(_aga +1)*iTemp .RowStride +_gcc ];};}else {_cda <<=1;_gca <<=1;_ecb <<=1;};if _cgb ==5&&_ffc >=1{_fbe =0;if _gcc < iTarget .RowStride {_fbe =iTarget .Data [(_ffc -1)*iTarget .RowStride +_gcc ]; 25 | };}else {_fbe <<=1;};if _cgb ==7{_cdf =0;if _gcc < iTarget .RowStride {_cdf =iTarget .Data [_ffc *iTarget .RowStride +_gcc ];};}else {_cdf <<=1;};_fec &=7;_ab &=7;_ed &=7;_ee &=7;};};return nil ;};func (_cc *Encoder )EncodeBitmap (bm *_d .Bitmap ,duplicateLineRemoval bool )error {_ac .Log .Trace ("\u0045n\u0063\u006f\u0064\u0065 \u0042\u0069\u0074\u006d\u0061p\u0020[\u0025d\u0078\u0025\u0064\u005d\u002c\u0020\u0025s",bm .Width ,bm .Height ,bm ); 26 | var (_cba ,_fff uint8 ;_cde ,_cbc ,_cbf uint16 ;_afc ,_cef ,_aed byte ;_bd ,_ffe ,_ga int ;_fa ,_be []byte ;);for _eabd :=0;_eabd < bm .Height ;_eabd ++{_afc ,_cef =0,0;if _eabd >=2{_afc =bm .Data [(_eabd -2)*bm .RowStride ];};if _eabd >=1{_cef =bm .Data [(_eabd -1)*bm .RowStride ]; 27 | if duplicateLineRemoval {_ffe =_eabd *bm .RowStride ;_fa =bm .Data [_ffe :_ffe +bm .RowStride ];_ga =(_eabd -1)*bm .RowStride ;_be =bm .Data [_ga :_ga +bm .RowStride ];if _g .Equal (_fa ,_be ){_fff =_cba ^1;_cba =1;}else {_fff =_cba ;_cba =0;};};};if duplicateLineRemoval {if _ffd :=_cc .encodeBit (_cc ._ba ,_af ,_fff ); 28 | _ffd !=nil {return _ffd ;};if _cba !=0{continue ;};};_aed =bm .Data [_eabd *bm .RowStride ];_cde =uint16 (_afc >>5);_cbc =uint16 (_cef >>4);_afc <<=3;_cef <<=4;_cbf =0;for _bd =0;_bd < bm .Width ;_bd ++{_gc :=uint32 (_cde <<11|_cbc <<4|_cbf );_ec :=(_aed &0x80)>>7; 29 | _cfe :=_cc .encodeBit (_cc ._ba ,_gc ,_ec );if _cfe !=nil {return _cfe ;};_cde <<=1;_cbc <<=1;_cbf <<=1;_cde |=uint16 ((_afc &0x80)>>7);_cbc |=uint16 ((_cef &0x80)>>7);_cbf |=uint16 (_ec );_ece :=_bd %8;_bfc :=_bd /8+1;if _ece ==4&&_eabd >=2{_afc =0;if _bfc < bm .RowStride {_afc =bm .Data [(_eabd -2)*bm .RowStride +_bfc ]; 30 | };}else {_afc <<=1;};if _ece ==3&&_eabd >=1{_cef =0;if _bfc < bm .RowStride {_cef =bm .Data [(_eabd -1)*bm .RowStride +_bfc ];};}else {_cef <<=1;};if _ece ==7{_aed =0;if _bfc < bm .RowStride {_aed =bm .Data [_eabd *bm .RowStride +_bfc ];};}else {_aed <<=1; 31 | };_cde &=31;_cbc &=127;_cbf &=15;};};return nil ;};var _ebd =[]state {{0x5601,1,1,1},{0x3401,2,6,0},{0x1801,3,9,0},{0x0AC1,4,12,0},{0x0521,5,29,0},{0x0221,38,33,0},{0x5601,7,6,1},{0x5401,8,14,0},{0x4801,9,14,0},{0x3801,10,14,0},{0x3001,11,17,0},{0x2401,12,18,0},{0x1C01,13,20,0},{0x1601,29,21,0},{0x5601,15,14,1},{0x5401,16,14,0},{0x5101,17,15,0},{0x4801,18,16,0},{0x3801,19,17,0},{0x3401,20,18,0},{0x3001,21,19,0},{0x2801,22,19,0},{0x2401,23,20,0},{0x2201,24,21,0},{0x1C01,25,22,0},{0x1801,26,23,0},{0x1601,27,24,0},{0x1401,28,25,0},{0x1201,29,26,0},{0x1101,30,27,0},{0x0AC1,31,28,0},{0x09C1,32,29,0},{0x08A1,33,30,0},{0x0521,34,31,0},{0x0441,35,32,0},{0x02A1,36,33,0},{0x0221,37,34,0},{0x0141,38,35,0},{0x0111,39,36,0},{0x0085,40,37,0},{0x0049,41,38,0},{0x0025,42,39,0},{0x0015,43,40,0},{0x0009,44,41,0},{0x0005,45,42,0},{0x0001,45,43,0},{0x5601,46,46,0}}; 32 | func (_eca *Encoder )renormalize (){for {_eca ._fd <<=1;_eca ._ea <<=1;_eca ._gec --;if _eca ._gec ==0{_eca .byteOut ();};if (_eca ._fd &0x8000)!=0{break ;};};};func (_gga *Encoder )WriteTo (w _a .Writer )(int64 ,error ){const _bc ="\u0045n\u0063o\u0064\u0065\u0072\u002e\u0057\u0072\u0069\u0074\u0065\u0054\u006f"; 33 | var _faf int64 ;for _ecbf ,_cbe :=range _gga ._cec {_ggb ,_edb :=w .Write (_cbe );if _edb !=nil {return 0,_f .Wrapf (_edb ,_bc ,"\u0066\u0061\u0069\u006c\u0065\u0064\u0020\u0061\u0074\u0020\u0069'\u0074\u0068\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u0063h\u0075\u006e\u006b",_ecbf ); 34 | };_faf +=int64 (_ggb );};_gga ._ae =_gga ._ae [:_gga ._eab ];_ffa ,_eg :=w .Write (_gga ._ae );if _eg !=nil {return 0,_f .Wrap (_eg ,_bc ,"\u0062u\u0066f\u0065\u0072\u0065\u0064\u0020\u0063\u0068\u0075\u006e\u006b\u0073");};_faf +=int64 (_ffa );return _faf ,nil ; 35 | };func (_ca *Encoder )Init (){_ca ._ba =_geb (_fca );_ca ._fd =0x8000;_ca ._ea =0;_ca ._gec =12;_ca ._efd =-1;_ca ._fbf =0;_ca ._eab =0;_ca ._ae =make ([]byte ,_fedc );for _fdb :=0;_fdb < len (_ca ._cf );_fdb ++{_ca ._cf [_fdb ]=_geb (512);};_ca ._ad =nil ; 36 | };func (_de *Encoder )codeLPS (_baf *codingContext ,_db uint32 ,_beg uint16 ,_age byte ){_de ._fd -=_beg ;if _de ._fd < _beg {_de ._ea +=uint32 (_beg );}else {_de ._fd =_beg ;};if _ebd [_age ]._gcce ==1{_baf .flipMps (_db );};_baf ._fb [_db ]=_ebd [_age ]._abb ; 37 | _de .renormalize ();};type state struct{_fgbe uint16 ;_gdf ,_abb uint8 ;_gcce uint8 ;};func (_afa *Encoder )lBlock (){if _afa ._efd >=0{_afa .emit ();};_afa ._efd ++;_afa ._fbf =uint8 (_afa ._ea >>19);_afa ._ea &=0x7ffff;_afa ._gec =8;};func (_eag *Encoder )encodeOOB (_gaef Class )error {_fbfc :=_eag ._cf [_gaef ]; 38 | _ecec :=_eag .encodeBit (_fbfc ,1,1);if _ecec !=nil {return _ecec ;};_ecec =_eag .encodeBit (_fbfc ,3,0);if _ecec !=nil {return _ecec ;};_ecec =_eag .encodeBit (_fbfc ,6,0);if _ecec !=nil {return _ecec ;};_ecec =_eag .encodeBit (_fbfc ,12,0);if _ecec !=nil {return _ecec ; 39 | };return nil ;};func (_aag *Encoder )setBits (){_eaa :=_aag ._ea +uint32 (_aag ._fd );_aag ._ea |=0xffff;if _aag ._ea >=_eaa {_aag ._ea -=0x8000;};};func (_dad *Encoder )encodeIAID (_dcca ,_gee int )error {if _dad ._ad ==nil {_dad ._ad =_geb (1<>31);if _bce :=_dad .encodeBit (_dad ._ad ,_ded ,_fef );_bce !=nil {return _bce ; 41 | };_aede =(_aede <<1)|uint32 (_fef );_gee <<=1;};return nil ;};func (_gb *Encoder )emit (){if _gb ._eab ==_fedc {_gb ._cec =append (_gb ._cec ,_gb ._ae );_gb ._ae =make ([]byte ,_fedc );_gb ._eab =0;};_gb ._ae [_gb ._eab ]=_gb ._fbf ;_gb ._eab ++;};type Class int ; 42 | func (_fgb *Encoder )encodeInteger (_fed Class ,_cbg int )error {const _adg ="E\u006e\u0063\u006f\u0064er\u002ee\u006e\u0063\u006f\u0064\u0065I\u006e\u0074\u0065\u0067\u0065\u0072";if _cbg > 2000000000||_cbg < -2000000000{return _f .Errorf (_adg ,"\u0061\u0072\u0069\u0074\u0068\u006d\u0065\u0074i\u0063\u0020\u0065nc\u006f\u0064\u0065\u0072\u0020\u002d \u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0069\u006e\u0074\u0065\u0067\u0065\u0072 \u0076\u0061\u006c\u0075\u0065\u003a\u0020\u0027%\u0064\u0027",_cbg ); 43 | };_dcd :=_fgb ._cf [_fed ];_ggf :=uint32 (1);var _fae int ;for ;;_fae ++{if _e [_fae ]._dd <=_cbg &&_e [_fae ]._cg >=_cbg {break ;};};if _cbg < 0{_cbg =-_cbg ;};_cbg -=int (_e [_fae ]._ag );_gae :=_e [_fae ]._cb ;for _ffff :=uint8 (0);_ffff < _e [_fae ]._cd ; 44 | _ffff ++{_bbg :=_gae &1;if _fgba :=_fgb .encodeBit (_dcd ,_ggf ,_bbg );_fgba !=nil {return _f .Wrap (_fgba ,_adg ,"");};_gae >>=1;if _ggf &0x100> 0{_ggf =(((_ggf <<1)|uint32 (_bbg ))&0x1ff)|0x100;}else {_ggf =(_ggf <<1)|uint32 (_bbg );};};_cbg <<=32-_e [_fae ]._bf ; 45 | for _adb :=uint8 (0);_adb < _e [_fae ]._bf ;_adb ++{_bdg :=uint8 ((uint32 (_cbg )&0x80000000)>>31);if _ddf :=_fgb .encodeBit (_dcd ,_ggf ,_bdg );_ddf !=nil {return _f .Wrap (_ddf ,_adg ,"\u006d\u006f\u0076\u0065 \u0064\u0061\u0074\u0061\u0020\u0074\u006f\u0020\u0074\u0068e\u0020t\u006f\u0070\u0020\u006f\u0066\u0020\u0077o\u0072\u0064"); 46 | };_cbg <<=1;if _ggf &0x100!=0{_ggf =(((_ggf <<1)|uint32 (_bdg ))&0x1ff)|0x100;}else {_ggf =(_ggf <<1)|uint32 (_bdg );};};return nil ;};func (_bed *Encoder )Final (){_bed .flush ()};func (_acg *Encoder )byteOut (){if _acg ._fbf ==0xff{_acg .rBlock ();return ; 47 | };if _acg ._ea < 0x8000000{_acg .lBlock ();return ;};_acg ._fbf ++;if _acg ._fbf !=0xff{_acg .lBlock ();return ;};_acg ._ea &=0x7ffffff;_acg .rBlock ();};func (_cdb *Encoder )code0 (_cbb *codingContext ,_bb uint32 ,_eccb uint16 ,_aa byte ){if _cbb .mps (_bb )==0{_cdb .codeMPS (_cbb ,_bb ,_eccb ,_aa ); 48 | }else {_cdb .codeLPS (_cbb ,_bb ,_eccb ,_aa );};};const (_fca =65536;_fedc =20*1024;);var _e =[]intEncRangeS {{0,3,0,2,0,2},{-1,-1,9,4,0,0},{-3,-2,5,3,2,1},{4,19,2,3,4,4},{-19,-4,3,3,4,4},{20,83,6,4,20,6},{-83,-20,7,4,20,6},{84,339,14,5,84,8},{-339,-84,15,5,84,8},{340,4435,30,6,340,12},{-4435,-340,31,6,340,12},{4436,2000000000,62,6,4436,32},{-2000000000,-4436,63,6,4436,32}}; 49 | func _geb (_gf int )*codingContext {return &codingContext {_fb :make ([]byte ,_gf ),_da :make ([]byte ,_gf )};};func (_bfd *Encoder )Flush (){_bfd ._eab =0;_bfd ._cec =nil ;_bfd ._efd =-1};func (_c Class )String ()string {switch _c {case IAAI :return "\u0049\u0041\u0041\u0049"; 50 | case IADH :return "\u0049\u0041\u0044\u0048";case IADS :return "\u0049\u0041\u0044\u0053";case IADT :return "\u0049\u0041\u0044\u0054";case IADW :return "\u0049\u0041\u0044\u0057";case IAEX :return "\u0049\u0041\u0045\u0058";case IAFS :return "\u0049\u0041\u0046\u0053"; 51 | case IAIT :return "\u0049\u0041\u0049\u0054";case IARDH :return "\u0049\u0041\u0052D\u0048";case IARDW :return "\u0049\u0041\u0052D\u0057";case IARDX :return "\u0049\u0041\u0052D\u0058";case IARDY :return "\u0049\u0041\u0052D\u0059";case IARI :return "\u0049\u0041\u0052\u0049"; 52 | default:return "\u0055N\u004b\u004e\u004f\u0057\u004e";};};func (_dcc *Encoder )encodeBit (_dbd *codingContext ,_aad uint32 ,_fbg uint8 )error {const _bcb ="\u0045\u006e\u0063\u006f\u0064\u0065\u0072\u002e\u0065\u006e\u0063\u006fd\u0065\u0042\u0069\u0074"; 53 | _dcc ._ged ++;if _aad >=uint32 (len (_dbd ._fb )){return _f .Errorf (_bcb ,"\u0061r\u0069\u0074h\u006d\u0065\u0074i\u0063\u0020\u0065\u006e\u0063\u006f\u0064e\u0072\u0020\u002d\u0020\u0069\u006ev\u0061\u006c\u0069\u0064\u0020\u0063\u0074\u0078\u0020\u006e\u0075m\u0062\u0065\u0072\u003a\u0020\u0027\u0025\u0064\u0027",_aad ); 54 | };_gcf :=_dbd ._fb [_aad ];_gedg :=_dbd .mps (_aad );_fg :=_ebd [_gcf ]._fgbe ;_ac .Log .Trace ("\u0045\u0043\u003a\u0020\u0025d\u0009\u0020D\u003a\u0020\u0025d\u0009\u0020\u0049\u003a\u0020\u0025d\u0009\u0020\u004dPS\u003a \u0025\u0064\u0009\u0020\u0051\u0045\u003a \u0025\u0030\u0034\u0058\u0009\u0020\u0020\u0041\u003a\u0020\u0025\u0030\u0034\u0058\u0009\u0020\u0043\u003a %\u0030\u0038\u0058\u0009\u0020\u0043\u0054\u003a\u0020\u0025\u0064\u0009\u0020\u0042\u003a\u0020\u0025\u0030\u0032\u0058\u0009\u0020\u0042\u0050\u003a\u0020\u0025\u0064",_dcc ._ged ,_fbg ,_gcf ,_gedg ,_fg ,_dcc ._fd ,_dcc ._ea ,_dcc ._gec ,_dcc ._fbf ,_dcc ._efd ); 55 | if _fbg ==0{_dcc .code0 (_dbd ,_aad ,_fg ,_gcf );}else {_dcc .code1 (_dbd ,_aad ,_fg ,_gcf );};return nil ;};var _ _a .WriterTo =&Encoder {};func (_ef *codingContext )flipMps (_fe uint32 ){_ef ._da [_fe ]=1-_ef ._da [_fe ]};type intEncRangeS struct{_dd ,_cg int ; 56 | _cb ,_cd uint8 ;_ag uint16 ;_bf uint8 ;};func (_ce *codingContext )mps (_ge uint32 )int {return int (_ce ._da [_ge ])};func (_ecc *Encoder )EncodeIAID (symbolCodeLength ,value int )(_gag error ){_ac .Log .Trace ("\u0045\u006e\u0063\u006f\u0064\u0065\u0020\u0049A\u0049\u0044\u002e S\u0079\u006d\u0062\u006f\u006c\u0043o\u0064\u0065\u004c\u0065\u006e\u0067\u0074\u0068\u003a\u0020\u0027\u0025\u0064\u0027\u002c \u0056\u0061\u006c\u0075\u0065\u003a\u0020\u0027%\u0064\u0027",symbolCodeLength ,value ); 57 | if _gag =_ecc .encodeIAID (symbolCodeLength ,value );_gag !=nil {return _f .Wrap (_gag ,"\u0045\u006e\u0063\u006f\u0064\u0065\u0049\u0041\u0049\u0044","");};return nil ;};const _af =0x9b25;func (_ada *Encoder )dataSize ()int {return _fedc *len (_ada ._cec )+_ada ._eab }; 58 | type Encoder struct{_ea uint32 ;_fd uint16 ;_gec ,_fbf uint8 ;_efd int ;_ged int ;_cec [][]byte ;_ae []byte ;_eab int ;_ba *codingContext ;_cf [13]*codingContext ;_ad *codingContext ;};func (_acgd *Encoder )rBlock (){if _acgd ._efd >=0{_acgd .emit ();}; 59 | _acgd ._efd ++;_acgd ._fbf =uint8 (_acgd ._ea >>20);_acgd ._ea &=0xfffff;_acgd ._gec =7;}; -------------------------------------------------------------------------------- /internal/bitwise/bitwise.go: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright 2020 FoxyUtils ehf. All rights reserved. 3 | // 4 | // This is a commercial product and requires a license to operate. 5 | // A trial license can be obtained at https://unidoc.io 6 | // 7 | // DO NOT EDIT: generated by unitwist Go source code obfuscator. 8 | // 9 | // Use of this source code is governed by the UniDoc End User License Agreement 10 | // terms that can be accessed at https://unidoc.io/eula/ 11 | 12 | package bitwise ;import (_f "encoding/binary";_e "errors";_g "fmt";_ag "github.com/unidoc/unipdf/v4/common";_ec "github.com/unidoc/unipdf/v4/internal/jbig2/errors";_a "io";);var _ BinaryWriter =&Writer {};func (_dac *Reader )NewPartialReader (offset ,length int ,relative bool )(*Reader ,error ){if offset < 0{return nil ,_e .New ("p\u0061\u0072\u0074\u0069\u0061\u006c\u0020\u0072\u0065\u0061\u0064\u0065\u0072\u0020\u006f\u0066\u0066\u0073e\u0074\u0020\u0063\u0061\u006e\u006e\u006f\u0074\u0020\u0062e \u006e\u0065\u0067a\u0074i\u0076\u0065"); 13 | };if relative {offset =_dac ._gad ._fac +offset ;};if length > 0{_de :=len (_dac ._gad ._cgg );if relative {_de =_dac ._gad ._aab ;};if offset +length > _de {return nil ,_g .Errorf ("\u0070\u0061r\u0074\u0069\u0061l\u0020\u0072\u0065\u0061\u0064e\u0072\u0020\u006f\u0066\u0066se\u0074\u0028\u0025\u0064\u0029\u002b\u006c\u0065\u006e\u0067\u0074\u0068\u0028\u0025\u0064\u0029\u003d\u0025d\u0020i\u0073\u0020\u0067\u0072\u0065\u0061ter\u0020\u0074\u0068\u0061\u006e\u0020\u0074\u0068\u0065\u0020\u006f\u0072ig\u0069n\u0061\u006c\u0020\u0072e\u0061d\u0065r\u0020\u006ce\u006e\u0067th\u003a\u0020\u0025\u0064",offset ,length ,offset +length ,_dac ._gad ._aab ); 14 | };};if length < 0{_cad :=len (_dac ._gad ._cgg );if relative {_cad =_dac ._gad ._aab ;};length =_cad -offset ;};return &Reader {_gad :readerSource {_cgg :_dac ._gad ._cgg ,_aab :length ,_fac :offset }},nil ;};type BufferedWriter struct{_bg []byte ;_eb uint8 ; 15 | _ge int ;_ece bool ;};func (_ba *BufferedWriter )grow (_fa int ){if _ba ._bg ==nil &&_fa < _d {_ba ._bg =make ([]byte ,_fa ,_d );return ;};_gc :=len (_ba ._bg );if _ba ._eb !=0{_gc ++;};_gd :=cap (_ba ._bg );switch {case _fa <=_gd /2-_gc :_ag .Log .Trace ("\u005b\u0042\u0075\u0066\u0066\u0065r\u0065\u0064\u0057\u0072\u0069t\u0065\u0072\u005d\u0020\u0067\u0072o\u0077\u0020\u002d\u0020\u0072e\u0073\u006c\u0069\u0063\u0065\u0020\u006f\u006e\u006c\u0079\u002e\u0020L\u0065\u006e\u003a\u0020\u0027\u0025\u0064\u0027\u002c\u0020\u0043\u0061\u0070\u003a\u0020'\u0025\u0064\u0027\u002c\u0020\u006e\u003a\u0020'\u0025\u0064\u0027",len (_ba ._bg ),cap (_ba ._bg ),_fa ); 16 | _ag .Log .Trace ("\u0020\u006e\u0020\u003c\u003d\u0020\u0063\u0020\u002f\u0020\u0032\u0020\u002d\u006d\u002e \u0043:\u0020\u0027\u0025\u0064\u0027\u002c\u0020\u006d\u003a\u0020\u0027\u0025\u0064\u0027",_gd ,_gc );copy (_ba ._bg ,_ba ._bg [_ba .fullOffset ():]); 17 | case _gd > _b -_gd -_fa :_ag .Log .Error ("\u0042\u0055F\u0046\u0045\u0052 \u0074\u006f\u006f\u0020\u006c\u0061\u0072\u0067\u0065");return ;default:_ddg :=make ([]byte ,2*_gd +_fa );copy (_ddg ,_ba ._bg );_ba ._bg =_ddg ;};_ba ._bg =_ba ._bg [:_gc +_fa ]; 18 | };type BinaryWriter interface{BitWriter ;_a .Writer ;_a .ByteWriter ;Data ()[]byte ;};type BitWriter interface{WriteBit (_fcf int )error ;WriteBits (_efd uint64 ,_fg int )(_cc int ,_eba error );FinishByte ();SkipBits (_cd int )error ;};func (_def *Reader )AbsolutePosition ()int64 {return _def ._ccb +int64 (_def ._gad ._fac )}; 19 | func (_fbd *Reader )ReadBits (n byte )(_ac uint64 ,_ecab error ){if n < _fbd ._baa {_cfe :=_fbd ._baa -n ;_ac =uint64 (_fbd ._cgb >>_cfe );_fbd ._cgb &=1<<_cfe -1;_fbd ._baa =_cfe ;return _ac ,nil ;};if n > _fbd ._baa {if _fbd ._baa > 0{_ac =uint64 (_fbd ._cgb ); 20 | n -=_fbd ._baa ;};for n >=8{_bdfc ,_dee :=_fbd .readBufferByte ();if _dee !=nil {return 0,_dee ;};_ac =_ac <<8+uint64 (_bdfc );n -=8;};if n > 0{if _fbd ._cgb ,_ecab =_fbd .readBufferByte ();_ecab !=nil {return 0,_ecab ;};_cda :=8-n ;_ac =_ac <>_cda ); 21 | _fbd ._cgb &=1<<_cda -1;_fbd ._baa =_cda ;}else {_fbd ._baa =0;};return _ac ,nil ;};_fbd ._baa =0;return uint64 (_fbd ._cgb ),nil ;};func NewReader (data []byte )*Reader {return &Reader {_gad :readerSource {_cgg :data ,_aab :len (data ),_fac :0}};};func (_fce *Reader )readBufferByte ()(byte ,error ){if _fce ._ccb >=int64 (_fce ._gad ._aab ){return 0,_a .EOF ; 22 | };_fce ._aadb =-1;_ebd :=_fce ._gad ._cgg [int64 (_fce ._gad ._fac )+_fce ._ccb ];_fce ._ccb ++;_fce ._cee =int (_ebd );return _ebd ,nil ;};func (_bd *Reader )Length ()uint64 {return uint64 (_bd ._gad ._aab )};var (_ _a .Reader =&Reader {};_ _a .ByteReader =&Reader {}; 23 | _ _a .Seeker =&Reader {};_ StreamReader =&Reader {};);var _ BinaryWriter =&BufferedWriter {};func (_ebc *Reader )BitPosition ()int {return int (_ebc ._baa )};func (_af *BufferedWriter )Data ()[]byte {return _af ._bg };func BufferedMSB ()*BufferedWriter {return &BufferedWriter {_ece :true }}; 24 | func (_ega *BufferedWriter )writeShiftedBytes (_da []byte )int {for _ ,_bgd :=range _da {_ega .writeByte (_bgd );};return len (_da );};func (_ed *BufferedWriter )FinishByte (){if _ed ._eb ==0{return ;};_ed ._eb =0;_ed ._ge ++;};const (_d =64;_b =int (^uint (0)>>1); 25 | );func (_dc *BufferedWriter )WriteByte (bt byte )error {if _dc ._ge > len (_dc ._bg )-1||(_dc ._ge ==len (_dc ._bg )-1&&_dc ._eb !=0){_dc .expandIfNeeded (1);};_dc .writeByte (bt );return nil ;};func (_eae *Writer )WriteByte (c byte )error {return _eae .writeByte (c )}; 26 | type Reader struct{_gad readerSource ;_cgb byte ;_baa byte ;_ccb int64 ;_cee int ;_aadb int ;_ea int64 ;_bae byte ;_fdb byte ;_geda int ;};func (_fcag *Writer )ResetBit (){_fcag ._bcc =0};func (_fcc *BufferedWriter )Write (d []byte )(int ,error ){_fcc .expandIfNeeded (len (d )); 27 | if _fcc ._eb ==0{return _fcc .writeFullBytes (d ),nil ;};return _fcc .writeShiftedBytes (d ),nil ;};func (_ebb *BufferedWriter )writeFullBytes (_dg []byte )int {_gbd :=copy (_ebb ._bg [_ebb .fullOffset ():],_dg );_ebb ._ge +=_gbd ;return _gbd ;};func (_ged *BufferedWriter )Reset (){_ged ._bg =_ged ._bg [:0]; 28 | _ged ._ge =0;_ged ._eb =0};func NewWriter (data []byte )*Writer {return &Writer {_edf :data }};func (_faf *Reader )ReadBit ()(_ecg int ,_dgg error ){_cde ,_dgg :=_faf .readBool ();if _dgg !=nil {return 0,_dgg ;};if _cde {_ecg =1;};return _ecg ,nil ;};func (_gdg *Reader )AbsoluteLength ()uint64 {return uint64 (len (_gdg ._gad ._cgg ))}; 29 | func (_fbf *Reader )Seek (offset int64 ,whence int )(int64 ,error ){_fbf ._aadb =-1;_fbf ._baa =0;_fbf ._cgb =0;_fbf ._cee =0;var _dcgd int64 ;switch whence {case _a .SeekStart :_dcgd =offset ;case _a .SeekCurrent :_dcgd =_fbf ._ccb +offset ;case _a .SeekEnd :_dcgd =int64 (_fbf ._gad ._aab )+offset ; 30 | default:return 0,_e .New ("\u0072\u0065\u0061de\u0072\u002e\u0052\u0065\u0061\u0064\u0065\u0072\u002eS\u0065e\u006b:\u0020i\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0068\u0065\u006e\u0063\u0065");};if _dcgd < 0{return 0,_e .New ("\u0072\u0065a\u0064\u0065\u0072\u002eR\u0065\u0061d\u0065\u0072\u002e\u0053\u0065\u0065\u006b\u003a \u006e\u0065\u0067\u0061\u0074\u0069\u0076\u0065\u0020\u0070\u006f\u0073i\u0074\u0069\u006f\u006e"); 31 | };_fbf ._ccb =_dcgd ;_fbf ._baa =0;return _dcgd ,nil ;};func (_bac *BufferedWriter )tryGrowByReslice (_ga int )bool {if _gf :=len (_bac ._bg );_ga <=cap (_bac ._bg )-_gf {_bac ._bg =_bac ._bg [:_gf +_ga ];return true ;};return false ;};func (_fca *Reader )Align ()(_fba byte ){_fba =_fca ._baa ; 32 | _fca ._baa =0;return _fba };func (_ab *Writer )Data ()[]byte {return _ab ._edf };func (_dd *BufferedWriter )expandIfNeeded (_db int ){if !_dd .tryGrowByReslice (_db ){_dd .grow (_db );};};var _ _a .ByteWriter =&BufferedWriter {};func (_gb *BufferedWriter )SkipBits (skip int )error {if skip ==0{return nil ; 33 | };_agc :=int (_gb ._eb )+skip ;if _agc >=0&&_agc < 8{_gb ._eb =uint8 (_agc );return nil ;};_agc =int (_gb ._eb )+_gb ._ge *8+skip ;if _agc < 0{return _ec .Errorf ("\u0057r\u0069t\u0065\u0072\u002e\u0053\u006b\u0069\u0070\u0042\u0069\u0074\u0073","\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065"); 34 | };_fc :=_agc /8;_be :=_agc %8;_gb ._eb =uint8 (_be );if _bc :=_fc -_gb ._ge ;_bc > 0&&len (_gb ._bg )-1< _fc {if _gb ._eb !=0{_bc ++;};_gb .expandIfNeeded (_bc );};_gb ._ge =_fc ;return nil ;};func (_ecac *Reader )RelativePosition ()int64 {return _ecac ._ccb }; 35 | type Writer struct{_edf []byte ;_bcc uint8 ;_cgc int ;_afe bool ;};type readerSource struct{_cgg []byte ;_fac int ;_aab int ;};func (_dge *Writer )Write (p []byte )(int ,error ){if len (p )> _dge .byteCapacity (){return 0,_a .EOF ;};for _ ,_dad :=range p {if _cfa :=_dge .writeByte (_dad ); 36 | _cfa !=nil {return 0,_cfa ;};};return len (p ),nil ;};func (_ddb *Writer )WriteBit (bit int )error {switch bit {case 0,1:return _ddb .writeBit (uint8 (bit ));};return _ec .Error ("\u0057\u0072\u0069\u0074\u0065\u0042\u0069\u0074","\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0062\u0069\u0074\u0020v\u0061\u006c\u0075\u0065"); 37 | };func (_bdd *Reader )Mark (){_bdd ._ea =_bdd ._ccb ;_bdd ._bae =_bdd ._baa ;_bdd ._fdb =_bdd ._cgb ;_bdd ._geda =_bdd ._cee ;};func (_ad *Reader )ReadByte ()(byte ,error ){if _ad ._baa ==0{return _ad .readBufferByte ();};return _ad .readUnalignedByte (); 38 | };func (_aga *BufferedWriter )Len ()int {return _aga .byteCapacity ()};func (_dda *Reader )ConsumeRemainingBits ()(uint64 ,error ){if _dda ._baa !=0{return _dda .ReadBits (_dda ._baa );};return 0,nil ;};func (_fdg *Reader )read (_gcc []byte )(int ,error ){if _fdg ._ccb >=int64 (_fdg ._gad ._aab ){return 0,_a .EOF ; 39 | };_fdg ._aadb =-1;_cca :=copy (_gcc ,_fdg ._gad ._cgg [(int64 (_fdg ._gad ._fac )+_fdg ._ccb ):(_fdg ._gad ._fac +_fdg ._gad ._aab )]);_fdg ._ccb +=int64 (_cca );return _cca ,nil ;};func (_bcaa *BufferedWriter )fullOffset ()int {_cf :=_bcaa ._ge ;if _bcaa ._eb !=0{_cf ++; 40 | };return _cf ;};func (_aa *BufferedWriter )WriteBits (bits uint64 ,number int )(_fd int ,_df error ){const _fb ="\u0042u\u0066\u0066\u0065\u0072e\u0064\u0057\u0072\u0069\u0074e\u0072.\u0057r\u0069\u0074\u0065\u0072\u0042\u0069\u0074s";if number < 0||number > 64{return 0,_ec .Errorf (_fb ,"\u0062i\u0074\u0073 \u006e\u0075\u006db\u0065\u0072\u0020\u006d\u0075\u0073\u0074 \u0062\u0065\u0020\u0069\u006e\u0020r\u0061\u006e\u0067\u0065\u0020\u003c\u0030\u002c\u0036\u0034\u003e,\u0020\u0069\u0073\u003a\u0020\u0027\u0025\u0064\u0027",number ); 41 | };_bcg :=number /8;if _bcg > 0{_dcg :=number -_bcg *8;for _beg :=_bcg -1;_beg >=0;_beg --{_ae :=byte ((bits >>uint (_beg *8+_dcg ))&0xff);if _df =_aa .WriteByte (_ae );_df !=nil {return _fd ,_ec .Wrapf (_df ,_fb ,"\u0062\u0079\u0074\u0065\u003a\u0020\u0027\u0025\u0064\u0027",_bcg -_beg +1); 42 | };};number -=_bcg *8;if number ==0{return _bcg ,nil ;};};var _ebg int ;for _aad :=0;_aad < number ;_aad ++{if _aa ._ece {_ebg =int ((bits >>uint (number -1-_aad ))&0x1);}else {_ebg =int (bits &0x1);bits >>=1;};if _df =_aa .WriteBit (_ebg );_df !=nil {return _fd ,_ec .Wrapf (_df ,_fb ,"\u0062i\u0074\u003a\u0020\u0025\u0064",_aad ); 43 | };};return _bcg ,nil ;};func (_gbb *Writer )writeBit (_ebdd uint8 )error {if len (_gbb ._edf )-1< _gbb ._cgc {return _a .EOF ;};_ceg :=_gbb ._bcc ;if _gbb ._afe {_ceg =7-_gbb ._bcc ;};_gbb ._edf [_gbb ._cgc ]|=byte (uint16 (_ebdd <<_ceg )&0xff);_gbb ._bcc ++; 44 | if _gbb ._bcc ==8{_gbb ._cgc ++;_gbb ._bcc =0;};return nil ;};func (_afd *Writer )UseMSB ()bool {return _afd ._afe };func (_ff *BufferedWriter )byteCapacity ()int {_geg :=len (_ff ._bg )-_ff ._ge ;if _ff ._eb !=0{_geg --;};return _geg ;};var _ _a .Writer =&BufferedWriter {}; 45 | func (_ecd *Writer )SkipBits (skip int )error {const _gfd ="\u0057r\u0069t\u0065\u0072\u002e\u0053\u006b\u0069\u0070\u0042\u0069\u0074\u0073";if skip ==0{return nil ;};_ffa :=int (_ecd ._bcc )+skip ;if _ffa >=0&&_ffa < 8{_ecd ._bcc =uint8 (_ffa );return nil ; 46 | };_ffa =int (_ecd ._bcc )+_ecd ._cgc *8+skip ;if _ffa < 0{return _ec .Errorf (_gfd ,"\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065");};_ccaf :=_ffa /8;_dbc :=_ffa %8;_ag .Log .Trace ("\u0053\u006b\u0069\u0070\u0042\u0069\u0074\u0073"); 47 | _ag .Log .Trace ("\u0042\u0069\u0074\u0049\u006e\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u0020\u0042\u0079\u0074\u0065\u0049n\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027\u002c\u0020\u0046\u0075\u006c\u006c\u0042\u0069\u0074\u0073\u003a\u0020'\u0025\u0064\u0027\u002c\u0020\u004c\u0065\u006e\u003a\u0020\u0027\u0025\u0064\u0027,\u0020\u0043\u0061p\u003a\u0020\u0027\u0025\u0064\u0027",_ecd ._bcc ,_ecd ._cgc ,int (_ecd ._bcc )+(_ecd ._cgc )*8,len (_ecd ._edf ),cap (_ecd ._edf )); 48 | _ag .Log .Trace ("S\u006b\u0069\u0070\u003a\u0020\u0027%\u0064\u0027\u002c\u0020\u0064\u003a \u0027\u0025\u0064\u0027\u002c\u0020\u0062i\u0074\u0049\u006e\u0064\u0065\u0078\u003a\u0020\u0027\u0025d\u0027",skip ,_ffa ,_dbc );_ecd ._bcc =uint8 (_dbc );if _bcef :=_ccaf -_ecd ._cgc ; 49 | _bcef > 0&&len (_ecd ._edf )-1< _ccaf {_ag .Log .Trace ("\u0042\u0079\u0074e\u0044\u0069\u0066\u0066\u003a\u0020\u0025\u0064",_bcef );return _ec .Errorf (_gfd ,"\u0069n\u0064e\u0078\u0020\u006f\u0075\u0074 \u006f\u0066 \u0072\u0061\u006e\u0067\u0065"); 50 | };_ecd ._cgc =_ccaf ;_ag .Log .Trace ("\u0042\u0069\u0074I\u006e\u0064\u0065\u0078:\u0020\u0027\u0025\u0064\u0027\u002c\u0020B\u0079\u0074\u0065\u0049\u006e\u0064\u0065\u0078\u003a\u0020\u0027\u0025\u0064\u0027",_ecd ._bcc ,_ecd ._cgc );return nil ;};func (_aea *BufferedWriter )writeByte (_gec byte ){switch {case _aea ._eb ==0:_aea ._bg [_aea ._ge ]=_gec ; 51 | _aea ._ge ++;case _aea ._ece :_aea ._bg [_aea ._ge ]|=_gec >>_aea ._eb ;_aea ._ge ++;_aea ._bg [_aea ._ge ]=byte (uint16 (_gec )<<(8-_aea ._eb )&0xff);default:_aea ._bg [_aea ._ge ]|=byte (uint16 (_gec )<<_aea ._eb &0xff);_aea ._ge ++;_aea ._bg [_aea ._ge ]=_gec >>(8-_aea ._eb ); 52 | };};func (_dae *Reader )ReadUint32 ()(uint32 ,error ){_ecc :=make ([]byte ,4);_ ,_gca :=_dae .Read (_ecc );if _gca !=nil {return 0,_gca ;};return _f .BigEndian .Uint32 (_ecc ),nil ;};func (_bdf *Reader )Read (p []byte )(_dbb int ,_afg error ){if _bdf ._baa ==0{return _bdf .read (p ); 53 | };for ;_dbb < len (p );_dbb ++{if p [_dbb ],_afg =_bdf .readUnalignedByte ();_afg !=nil {return 0,_afg ;};};return _dbb ,nil ;};func (_fcef *Writer )WriteBits (bits uint64 ,number int )(_fgb int ,_ccg error ){const _bb ="\u0057\u0072\u0069\u0074\u0065\u0072\u002e\u0057\u0072\u0069\u0074\u0065r\u0042\u0069\u0074\u0073"; 54 | if number < 0||number > 64{return 0,_ec .Errorf (_bb ,"\u0062i\u0074\u0073 \u006e\u0075\u006db\u0065\u0072\u0020\u006d\u0075\u0073\u0074 \u0062\u0065\u0020\u0069\u006e\u0020r\u0061\u006e\u0067\u0065\u0020\u003c\u0030\u002c\u0036\u0034\u003e,\u0020\u0069\u0073\u003a\u0020\u0027\u0025\u0064\u0027",number ); 55 | };if number ==0{return 0,nil ;};_ee :=number /8;if _ee > 0{_ecb :=number -_ee *8;for _aee :=_ee -1;_aee >=0;_aee --{_gcd :=byte ((bits >>uint (_aee *8+_ecb ))&0xff);if _ccg =_fcef .WriteByte (_gcd );_ccg !=nil {return _fgb ,_ec .Wrapf (_ccg ,_bb ,"\u0062\u0079\u0074\u0065\u003a\u0020\u0027\u0025\u0064\u0027",_ee -_aee +1); 56 | };};number -=_ee *8;if number ==0{return _ee ,nil ;};};var _dfdg int ;for _cge :=0;_cge < number ;_cge ++{if _fcef ._afe {_dfdg =int ((bits >>uint (number -1-_cge ))&0x1);}else {_dfdg =int (bits &0x1);bits >>=1;};if _ccg =_fcef .WriteBit (_dfdg );_ccg !=nil {return _fgb ,_ec .Wrapf (_ccg ,_bb ,"\u0062i\u0074\u003a\u0020\u0025\u0064",_cge ); 57 | };};return _ee ,nil ;};func (_efg *Writer )byteCapacity ()int {_edc :=len (_efg ._edf )-_efg ._cgc ;if _efg ._bcc !=0{_edc --;};return _edc ;};func (_ce *BufferedWriter )WriteBit (bit int )error {if bit !=1&&bit !=0{return _ec .Errorf ("\u0042\u0075\u0066fe\u0072\u0065\u0064\u0057\u0072\u0069\u0074\u0065\u0072\u002e\u0057\u0072\u0069\u0074\u0065\u0042\u0069\u0074","\u0062\u0069\u0074\u0020\u0076\u0061\u006cu\u0065\u0020\u006du\u0073\u0074\u0020\u0062e\u0020\u0069\u006e\u0020\u0072\u0061\u006e\u0067\u0065\u0020\u007b\u0030\u002c\u0031\u007d\u0020\u0062\u0075\u0074\u0020\u0069\u0073\u003a\u0020\u0025\u0064",bit ); 58 | };if len (_ce ._bg )-1< _ce ._ge {_ce .expandIfNeeded (1);};_bce :=_ce ._eb ;if _ce ._ece {_bce =7-_ce ._eb ;};_ce ._bg [_ce ._ge ]|=byte (uint16 (bit <<_bce )&0xff);_ce ._eb ++;if _ce ._eb ==8{_ce ._ge ++;_ce ._eb =0;};return nil ;};func (_cdg *Reader )readBool ()(_fbag bool ,_aed error ){if _cdg ._baa ==0{_cdg ._cgb ,_aed =_cdg .readBufferByte (); 59 | if _aed !=nil {return false ,_aed ;};_fbag =(_cdg ._cgb &0x80)!=0;_cdg ._cgb ,_cdg ._baa =_cdg ._cgb &0x7f,7;return _fbag ,nil ;};_cdg ._baa --;_fbag =(_cdg ._cgb &(1<<_cdg ._baa ))!=0;_cdg ._cgb &=1<<_cdg ._baa -1;return _fbag ,nil ;};func (_efde *Reader )ReadBool ()(bool ,error ){return _efde .readBool ()}; 60 | type StreamReader interface{_a .Reader ;_a .ByteReader ;_a .Seeker ;Align ()byte ;BitPosition ()int ;Mark ();Length ()uint64 ;ReadBit ()(int ,error );ReadBits (_dgd byte )(uint64 ,error );ReadBool ()(bool ,error );ReadUint32 ()(uint32 ,error );Reset (); 61 | AbsolutePosition ()int64 ;};func (_agd *Reader )readUnalignedByte ()(_efdb byte ,_bf error ){_aabb :=_agd ._baa ;_efdb =_agd ._cgb <<(8-_aabb );_agd ._cgb ,_bf =_agd .readBufferByte ();if _bf !=nil {return 0,_bf ;};_efdb |=_agd ._cgb >>_aabb ;_agd ._cgb &=1<<_aabb -1; 62 | return _efdb ,nil ;};func (_daf *Writer )writeByte (_bacd byte )error {if _daf ._cgc > len (_daf ._edf )-1{return _a .EOF ;};if _daf ._cgc ==len (_daf ._edf )-1&&_daf ._bcc !=0{return _a .EOF ;};if _daf ._bcc ==0{_daf ._edf [_daf ._cgc ]=_bacd ;_daf ._cgc ++; 63 | return nil ;};if _daf ._afe {_daf ._edf [_daf ._cgc ]|=_bacd >>_daf ._bcc ;_daf ._cgc ++;_daf ._edf [_daf ._cgc ]=byte (uint16 (_bacd )<<(8-_daf ._bcc )&0xff);}else {_daf ._edf [_daf ._cgc ]|=byte (uint16 (_bacd )<<_daf ._bcc &0xff);_daf ._cgc ++;_daf ._edf [_daf ._cgc ]=_bacd >>(8-_daf ._bcc ); 64 | };return nil ;};func (_bcgf *Writer )FinishByte (){if _bcgf ._bcc ==0{return ;};_bcgf ._bcc =0;_bcgf ._cgc ++;};func NewWriterMSB (data []byte )*Writer {return &Writer {_edf :data ,_afe :true }};func (_ef *BufferedWriter )ResetBitIndex (){_ef ._eb =0}; 65 | func (_dfd *Reader )Reset (){_dfd ._ccb =_dfd ._ea ;_dfd ._baa =_dfd ._bae ;_dfd ._cgb =_dfd ._fdb ;_dfd ._cee =_dfd ._geda ;}; --------------------------------------------------------------------------------