// // Copyright 2020 FoxyUtils ehf. All rights reserved. // // This is a commercial product and requires a license to operate. // A trial license can be obtained at https://unidoc.io // // DO NOT EDIT: generated by unitwist Go source code obfuscator. // // Use of this source code is governed by the UniDoc End User License Agreement // terms that can be accessed at https://unidoc.io/eula/ package pdfutil ;import (_ef "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/contentstream";_bd "github.com/unidoc/unipdf/v3/contentstream/draw";_f "github.com/unidoc/unipdf/v3/core";_b "github.com/unidoc/unipdf/v3/model";); // NormalizePage performs the following operations on the passed in page: // - Normalize the page rotation. // Rotates the contents of the page according to the Rotate entry, thus // flattening the rotation. The Rotate entry of the page is set to nil. // - Normalize the media box. // If the media box of the page is offsetted (Llx != 0 or Lly != 0), // the contents of the page are translated to (-Llx, -Lly). After // normalization, the media box is updated (Llx and Lly are set to 0 and // Urx and Ury are updated accordingly). // - Normalize the crop box. // The crop box of the page is updated based on the previous operations. // After normalization, the page should look the same if openend using a // PDF viewer. // NOTE: This function does not normalize annotations, outlines other parts // that are not part of the basic geometry and page content streams. func NormalizePage (page *_b .PdfPage )error {_fg ,_ecc :=page .GetMediaBox ();if _ecc !=nil {return _ecc ;};_bb :=page .Rotate ;_a :=_bb !=nil &&*_bb %360!=0&&*_bb %90==0;_fg .Normalize ();_ee ,_eg ,_bda ,_bg :=_fg .Llx ,_fg .Lly ,_fg .Width (),_fg .Height ();_af :=_ee !=0||_eg !=0;if !_a &&!_af {return nil ;};_c :=func (_d ,_eb ,_ab float64 )_bd .BoundingBox {return _bd .Path {Points :[]_bd .Point {_bd .NewPoint (0,0).Rotate (_ab ),_bd .NewPoint (_d ,0).Rotate (_ab ),_bd .NewPoint (0,_eb ).Rotate (_ab ),_bd .NewPoint (_d ,_eb ).Rotate (_ab )}}.GetBoundingBox ();};_g :=_ec .NewContentCreator ();var _ebb float64 ;if _a {_ebb =-float64 (*page .Rotate );_ce :=_c (_bda ,_bg ,_ebb );_g .Translate ((_ce .Width -_bda )/2+_bda /2,(_ce .Height -_bg )/2+_bg /2);_g .RotateDeg (_ebb );_g .Translate (-_bda /2,-_bg /2);_bda ,_bg =_ce .Width ,_ce .Height ;};if _af {_g .Translate (-_ee ,-_eg );};_de :=_g .Operations ();_cg ,_ecc :=_f .MakeStream (_de .Bytes (),_f .NewFlateEncoder ());if _ecc !=nil {return _ecc ;};_bdf :=_f .MakeArray (_cg );_bdf .Append (page .GetContentStreamObjs ()...);*_fg =_b .PdfRectangle {Urx :_bda ,Ury :_bg };if _ga :=page .CropBox ;_ga !=nil {_ga .Normalize ();_ebbd ,_ea ,_gg ,_gc :=_ga .Llx -_ee ,_ga .Lly -_eg ,_ga .Width (),_ga .Height ();if _a {_aa :=_c (_gg ,_gc ,_ebb );_gg ,_gc =_aa .Width ,_aa .Height ;};*_ga =_b .PdfRectangle {Llx :_ebbd ,Lly :_ea ,Urx :_ebbd +_gg ,Ury :_ea +_gc };};_ef .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ebb ,_de ,_fg );page .Contents =_bdf ;page .Rotate =nil ;return nil ;};