mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
29 lines
3.1 KiB
Go
29 lines
3.1 KiB
Go
//
|
|
// 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 (_de "github.com/unidoc/unipdf/v3/common";_g "github.com/unidoc/unipdf/v3/contentstream";_b "github.com/unidoc/unipdf/v3/contentstream/draw";_c "github.com/unidoc/unipdf/v3/core";_a "github.com/unidoc/unipdf/v3/model";);
|
|
|
|
// NormalizePage performs the following operations on the passed in page:
|
|
// - Normalize the page rotation.
|
|
// 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 *_a .PdfPage )error {_bf ,_e :=page .GetMediaBox ();if _e !=nil {return _e ;};_dee :=page .Rotate ;_ae :=_dee !=nil &&*_dee %360!=0&&*_dee %90==0;_bf .Normalize ();_ab ,_f ,_ff ,_cf :=_bf .Llx ,_bf .Lly ,_bf .Width (),_bf .Height ();_bc :=_ab !=0||_f !=0;if !_ae &&!_bc {return nil ;};_eg :=func (_deb ,_ca ,_be float64 )_b .BoundingBox {return _b .Path {Points :[]_b .Point {_b .NewPoint (0,0).Rotate (_be ),_b .NewPoint (_deb ,0).Rotate (_be ),_b .NewPoint (0,_ca ).Rotate (_be ),_b .NewPoint (_deb ,_ca ).Rotate (_be )}}.GetBoundingBox ();};_ea :=_g .NewContentCreator ();var _aa float64 ;if _ae {_aa =-float64 (*page .Rotate );_ge :=_eg (_ff ,_cf ,_aa );_ea .Translate ((_ge .Width -_ff )/2+_ff /2,(_ge .Height -_cf )/2+_cf /2);_ea .RotateDeg (_aa );_ea .Translate (-_ff /2,-_cf /2);_ff ,_cf =_ge .Width ,_ge .Height ;};if _bc {_ea .Translate (-_ab ,-_f );};_ga :=_ea .Operations ();_ac ,_e :=_c .MakeStream (_ga .Bytes (),_c .NewFlateEncoder ());if _e !=nil {return _e ;};_cd :=_c .MakeArray (_ac );_cd .Append (page .GetContentStreamObjs ()...);*_bf =_a .PdfRectangle {Urx :_ff ,Ury :_cf };if _ffd :=page .CropBox ;_ffd !=nil {_ffd .Normalize ();_df ,_eb ,_bca ,_bfe :=_ffd .Llx -_ab ,_ffd .Lly -_f ,_ffd .Width (),_ffd .Height ();if _ae {_ffa :=_eg (_bca ,_bfe ,_aa );_bca ,_bfe =_ffa .Width ,_ffa .Height ;};*_ffd =_a .PdfRectangle {Llx :_df ,Lly :_eb ,Urx :_df +_bca ,Ury :_eb +_bfe };};_de .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_aa ,_ga ,_bf );page .Contents =_cd ;page .Rotate =nil ;return nil ;}; |