mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-27 13:48:51 +08:00
36 lines
3.4 KiB
Go
36 lines
3.4 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 (_a "github.com/unidoc/unipdf/v3/common";_db "github.com/unidoc/unipdf/v3/contentstream";_c "github.com/unidoc/unipdf/v3/contentstream/draw";_g "github.com/unidoc/unipdf/v3/core";_f "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 *_f .PdfPage )error {_gf ,_ac :=page .GetMediaBox ();if _ac !=nil {return _ac ;};_fd ,_ac :=page .GetRotate ();if _ac !=nil {_a .Log .Debug ("\u0045\u0052R\u004f\u0052\u003a\u0020\u0025\u0073\u0020\u002d\u0020\u0069\u0067\u006e\u006f\u0072\u0069\u006e\u0067\u0020\u0061\u006e\u0064\u0020\u0061\u0073\u0073\u0075\u006d\u0069\u006e\u0067\u0020\u006e\u006f\u0020\u0072\u006f\u0074\u0061\u0074\u0069\u006f\u006e\u000a",_ac .Error ());
|
|
};_gb :=_fd %360!=0&&_fd %90==0;_gf .Normalize ();_ca ,_cd ,_e ,_cg :=_gf .Llx ,_gf .Lly ,_gf .Width (),_gf .Height ();_ee :=_ca !=0||_cd !=0;if !_gb &&!_ee {return nil ;};_fg :=func (_b ,_ae ,_fa float64 )_c .BoundingBox {return _c .Path {Points :[]_c .Point {_c .NewPoint (0,0).Rotate (_fa ),_c .NewPoint (_b ,0).Rotate (_fa ),_c .NewPoint (0,_ae ).Rotate (_fa ),_c .NewPoint (_b ,_ae ).Rotate (_fa )}}.GetBoundingBox ();
|
|
};_be :=_db .NewContentCreator ();var _ec float64 ;if _gb {_ec =-float64 (_fd );_ge :=_fg (_e ,_cg ,_ec );_be .Translate ((_ge .Width -_e )/2+_e /2,(_ge .Height -_cg )/2+_cg /2);_be .RotateDeg (_ec );_be .Translate (-_e /2,-_cg /2);_e ,_cg =_ge .Width ,_ge .Height ;
|
|
};if _ee {_be .Translate (-_ca ,-_cd );};_ea :=_be .Operations ();_gd ,_ac :=_g .MakeStream (_ea .Bytes (),_g .NewFlateEncoder ());if _ac !=nil {return _ac ;};_gfb :=_g .MakeArray (_gd );_gfb .Append (page .GetContentStreamObjs ()...);*_gf =_f .PdfRectangle {Urx :_e ,Ury :_cg };
|
|
if _ad :=page .CropBox ;_ad !=nil {_ad .Normalize ();_fc ,_cdf ,_gc ,_eg :=_ad .Llx -_ca ,_ad .Lly -_cd ,_ad .Width (),_ad .Height ();if _gb {_bb :=_fg (_gc ,_eg ,_ec );_gc ,_eg =_bb .Width ,_bb .Height ;};*_ad =_f .PdfRectangle {Llx :_fc ,Lly :_cdf ,Urx :_fc +_gc ,Ury :_cdf +_eg };
|
|
};_a .Log .Debug ("\u0052\u006f\u0074\u0061\u0074\u0065\u003d\u0025\u0066\u00b0\u0020\u004f\u0070\u0073\u003d%\u0071 \u004d\u0065\u0064\u0069\u0061\u0042\u006f\u0078\u003d\u0025\u002e\u0032\u0066",_ec ,_ea ,_gf );page .Contents =_gfb ;page .Rotate =nil ;
|
|
return nil ;}; |