2020-09-14 09:32:45 +00:00
|
|
|
package document ;import (_ed "encoding/binary";_g "fmt";_ec "github.com/unidoc/unipdf/v3/common";_cg "github.com/unidoc/unipdf/v3/internal/bitwise";_fb "github.com/unidoc/unipdf/v3/internal/jbig2/basic";_b "github.com/unidoc/unipdf/v3/internal/jbig2/bitmap";_ecc "github.com/unidoc/unipdf/v3/internal/jbig2/document/segments";_gg "github.com/unidoc/unipdf/v3/internal/jbig2/encoder/classer";_cd "github.com/unidoc/unipdf/v3/internal/jbig2/errors";_c "io";_a "math";_f "runtime/debug";);func (_cgc *Document )addSymbolDictionary (_cege int ,_fee *_b .Bitmaps ,_cba []int ,_add map[int ]int ,_de bool )(*_ecc .Header ,error ){const _eab ="\u0061\u0064\u0064\u0053ym\u0062\u006f\u006c\u0044\u0069\u0063\u0074\u0069\u006f\u006e\u0061\u0072\u0079";_ba :=&_ecc .SymbolDictionary {};if _bbg :=_ba .InitEncode (_fee ,_cba ,_add ,_de );_bbg !=nil {return nil ,_bbg ;};_be :=&_ecc .Header {Type :_ecc .TSymbolDictionary ,PageAssociation :_cege ,SegmentData :_ba };if _cege ==0{if _cgc .GlobalSegments ==nil {_cgc .GlobalSegments =&Globals {};};_cgc .GlobalSegments .AddSegment (_be );return _be ,nil ;};_cgd ,_gf :=_cgc .Pages [_cege ];if !_gf {return nil ,_cd .Errorf (_eab ,"p\u0061g\u0065\u003a\u0020\u0027\u0025\u0064\u0027\u0020n\u006f\u0074\u0020\u0066ou\u006e\u0064",_cege );};var (_db int ;_fea *_ecc .Header ;);for _db ,_fea =range _cgd .Segments {if _fea .Type ==_ecc .TPageInformation {break ;};};_db ++;_cgd .Segments =append (_cgd .Segments ,nil );copy (_cgd .Segments [_db +1:],_cgd .Segments [_db :]);_cgd .Segments [_db ]=_be ;return _be ,nil ;};func _gcc (_dde _cg .StreamReader ,_gcb *Globals )(*Document ,error ){_cbe :=&Document {Pages :make (map[int ]*Page ),InputStream :_dde ,OrganizationType :_ecc .OSequential ,NumberOfPagesUnknown :true ,GlobalSegments :_gcb ,_fe :9};if _cbe .GlobalSegments ==nil {_cbe .GlobalSegments =&Globals {};};if _afbd :=_cbe .mapData ();_afbd !=nil {return nil ,_afbd ;};return _cbe ,nil ;};func (_degff *Page )getResolutionY ()(int ,error ){const _eceb ="\u0067\u0065\u0074\u0052\u0065\u0073\u006f\u006c\u0075t\u0069\u006f\u006e\u0059";if _degff .ResolutionY !=0{return _degff .ResolutionY ,nil ;};_bffg :=_degff .getPageInformationSegment ();if _bffg ==nil {return 0,_cd .Error (_eceb ,"n\u0069l\u0020\u0070\u0061\u0067\u0065\u0020\u0069\u006ef\u006f\u0072\u006d\u0061ti\u006f\u006e");};_ddd ,_edgag :=_bffg .GetSegmentData ();if _edgag !=nil {return 0,_cd .Wrap (_edgag ,_eceb ,"");};_bgb ,_daa :=_ddd .(*_ecc .PageInformationSegment );if !_daa {return 0,_cd .Errorf (_eceb ,"\u0070\u0061\u0067\u0065\u0020\u0069\u006e\u0066o\u0072\u006d\u0061ti\u006f\u006e\u0020\u0073\u0065\u0067m\u0065\u006e\u0074\u0020\u0069\u0073\u0020\u006f\u0066\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0074\u0079\u0070\u0065\u003a\u0027%\u0054\u0027",_ddd );};_degff .ResolutionY =_bgb .ResolutionY ;return _degff .ResolutionY ,nil ;};func (_egc *Document )encodeEOFHeader (_ega _cg .BinaryWriter )(_bgg int ,_dgf error ){_fbb :=&_ecc .Header {SegmentNumber :_egc .nextSegmentNumber (),Type :_ecc .TEndOfFile };if _bgg ,_dgf =_fbb .Encode (_ega );_dgf !=nil {return 0,_cd .Wrap (_dgf ,"\u0065n\u0063o\u0064\u0065\u0045\u004f\u0046\u0048\u0065\u0061\u0064\u0065\u0072","");};return _bgg ,nil ;};func (_eccb *Document )produceClassifiedPage (_dc *Page ,_eef *_ecc .Header )(_ad error ){const _ab ="p\u0072\u006f\u0064\u0075ce\u0043l\u0061\u0073\u0073\u0069\u0066i\u0065\u0064\u0050\u0061\u0067\u0065";var _bbd map[int ]int ;_fad :=_eccb ._ce ;_gcg :=[]*_ecc .Header {_eef };if len (_eccb ._fa [_dc .PageNumber ])> 0{_bbd =map[int ]int {};_ebf ,_cf :=_eccb .addSymbolDictionary (_dc .PageNumber ,_eccb .Classer .UndilatedTemplates ,_eccb ._fa [_dc .PageNumber ],_bbd ,false );if _cf !=nil {return _cd .Wrap (_cf ,_ab ,"");};_gcg =append (_gcg ,_ebf );_fad +=len (_eccb ._fa [_dc .PageNumber ]);};_fge :=_eccb ._d [_dc .PageNumber ];_ec .Log .Debug ("P\u0061g\u0065\u003a\u0020\u0027\u0025\u0064\u0027\u0020c\u006f\u006d\u0070\u0073: \u0025\u0076",_dc .PageNumber ,_fge );_dc .addTextRegionSegment (_gcg ,_eccb ._bb ,_bbd ,_eccb ._d [_dc .PageNumber ],_eccb .Classer .
|