mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-26 13:48:55 +08:00
25 lines
31 KiB
Go
25 lines
31 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 render ;import (_c "errors";_da "fmt";_bd "github.com/adrg/sysfont";_ca "github.com/unidoc/unipdf/v3/common";_fb "github.com/unidoc/unipdf/v3/contentstream";_gc "github.com/unidoc/unipdf/v3/core";_g "github.com/unidoc/unipdf/v3/internal/transform";_db "github.com/unidoc/unipdf/v3/model";_ag "github.com/unidoc/unipdf/v3/render/internal/context";_bfa "github.com/unidoc/unipdf/v3/render/internal/context/imagerender";_bf "image";_a "image/draw";_f "image/jpeg";_dc "image/png";_b "os";_de "path/filepath";_e "strings";);func _gb (_caf string ,_dg _bf .Image )error {_gcc ,_bdf :=_b .Create (_caf );if _bdf !=nil {return _bdf ;};defer _gcc .Close ();return _dc .Encode (_gcc ,_dg );};
|
|
|
|
// NewImageDevice returns a new image device.
|
|
func NewImageDevice ()*ImageDevice {return &ImageDevice {}};
|
|
|
|
// Render converts the specified PDF page into an image and returns the result.
|
|
func (_dbg *ImageDevice )Render (page *_db .PdfPage )(_bf .Image ,error ){_ec ,_bfag :=page .GetMediaBox ();if _bfag !=nil {return nil ,_bfag ;};_ef ,_dcc :=_ec .Llx +_ec .Width (),_ec .Lly +_ec .Height ();_fc :=_bfa .NewContext (int (_ef ),int (_dcc ));if _ecg :=_dbg .renderPage (_fc ,page );_ecg !=nil {return nil ,_ecg ;};_dd :=_fc .Image ();if _gf :=page .CropBox ;_gf !=nil {_ae :=_bf .Rect (0,0,int (_gf .Width ()),int (_gf .Height ()));_bb :=_bf .Pt (int (_gf .Llx ),int (_dcc -_gf .Ury ));_aea :=_bf .NewRGBA (_ae );_a .Draw (_aea ,_ae ,_dd ,_bb ,_a .Src );_dd =_aea ;};return _dd ,nil ;};type renderer struct{};func (_eg renderer )renderPage (_ffa _ag .Context ,_ee *_db .PdfPage )error {_efb ,_ge :=_ee .GetAllContentStreams ();if _ge !=nil {return _ge ;};_ffa .Translate (0,float64 (_ffa .Height ()));_ffa .Scale (1,-1);_ffa .Push ();_ffa .SetRGBA (1,1,1,1);_ffa .DrawRectangle (0,0,float64 (_ffa .Width ()),float64 (_ffa .Height ()));_ffa .Fill ();_ffa .Pop ();_ffa .SetLineWidth (1.0);_ffa .SetRGBA (0,0,0,1);return _eg .renderContentStream (_ffa ,_efb ,_ee .Resources );};
|
|
|
|
// ImageDevice is used to render PDF pages to image targets.
|
|
type ImageDevice struct{renderer };func _gg (_cac string ,_cb _bf .Image ,_dce int )error {_feb ,_dcd :=_b .Create (_cac );if _dcd !=nil {return _dcd ;};defer _feb .Close ();return _f .Encode (_feb ,_cb ,&_f .Options {Quality :_dce });};func (_ad renderer )renderContentStream (_aa _ag .Context ,_ada string ,_ggg *_db .PdfPageResources )error {_fbd ,_fea :=_fb .NewContentStreamParser (_ada ).Parse ();if _fea !=nil {return _fea ;};_cc :=_aa .TextState ();_agcc :=map[string ]*_ag .TextFont {};_ffb :=_bd .NewFinder (&_bd .FinderOpts {Extensions :[]string {"\u002e\u0074\u0074\u0066","\u002e\u0074\u0074\u0063"}});_ce :=_fb .NewContentStreamProcessor (*_fbd );_ce .AddHandler (_fb .HandlerConditionEnumAllOperands ,"",func (_cea *_fb .ContentStreamOperation ,_eca _fb .GraphicsState ,_be *_db .PdfPageResources )error {_ca .Log .Debug ("\u0050\u0072\u006f\u0063\u0065\u0073\u0073\u0069\u006e\u0067\u0020\u0025\u0073",_cea .Operand );switch _cea .Operand {case "\u0071":_aa .Push ();case "\u0051":_aa .Pop ();case "\u0063\u006d":if len (_cea .Params )!=6{return _agc ;};_ga ,_fbf :=_gc .GetNumbersAsFloat (_cea .Params );if _fbf !=nil {return _fbf ;};_fg :=_g .NewMatrix (_ga [0],_ga [1],_ga [2],_ga [3],_ga [4],_ga [5]);_ca .Log .Debug ("\u0047\u0072\u0061\u0070\u0068\u0069\u0063\u0073\u0020\u0073\u0074a\u0074\u0065\u0020\u006d\u0061\u0074\u0072\u0069\u0078\u003a \u0025\u002b\u0076",_fg );_aa .SetMatrix (_aa .Matrix ().Mult (_fg ));_abd :=(_eca .CTM .ScalingFactorX ()+_eca .CTM .ScalingFactorY ())/2.0;_aa .SetLineWidth (_abd *_aa .LineWidth ());case "\u0077":if len (_cea .Params )!=1{return _agc ;};_ed ,_eda :=_gc .GetNumbersAsFloat (_cea .Params );if _eda !=nil {return _eda ;};_adb :=(_eca .CTM .ScalingFactorX ()+_eca .CTM .ScalingFactorY ())/2.0;_aa .SetLineWidth (_adb *_ed [0]);case "\u004a":if len (_cea .Params )!=1{return _agc ;};_fa ,_fcg :=_gc .GetIntVal (_cea .Params [0]);if !_fcg {return _dbag ;};switch _fa {case 0:_aa .SetLineCap (_ag .LineCapButt );case 1:_aa .SetLineCap (_ag .LineCapRound );case 2:_aa .SetLineCap (_ag .LineCapSquare );default:_ca .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006c\u0069\u006ee\u0020\u0063\u0061\u0070\u0020\u0073\u0074\u0079\u006c\u0065:\u0020\u0025\u0064",_fa );return _agc ;};case "\u006a":if len (_cea .Params )!=1{return _agc ;};_gd ,_aead :=_gc .GetIntVal (_cea .Params [0]);if !_aead {return _dbag ;};switch _gd {case 0:_aa .SetLineJoin (_ag .LineJoinBevel );case 1:_aa .SetLineJoin (_ag .LineJoinRound );case 2:_aa .SetLineJoin (_ag .LineJoinBevel );default:_ca .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006c\u0069\u006e\u0065\u0020\u006a\u006f\u0069\u006e \u0073\u0074\u0079l\u0065:\u0020\u0025\u0064",_gd );return _agc ;};case "\u004d":if len (_cea .Params )!=1{return _agc ;};_caa ,_gae :=_gc .GetNumbersAsFloat (_cea .Params );if _gae !=nil {return _gae ;};_ =_caa ;_ca .Log .Debug ("\u004di\u0074\u0065\u0072\u0020l\u0069\u006d\u0069\u0074\u0020n\u006ft\u0020s\u0075\u0070\u0070\u006f\u0072\u0074\u0065d");case "\u0064":if len (_cea .Params )!=2{return _agc ;};_gbg ,_dbe :=_gc .GetArray (_cea .Params [0]);if !_dbe {return _dbag ;};_cf ,_dbe :=_gc .GetIntVal (_cea .Params [1]);if !_dbe {return _dbag ;};_af ,_agca :=_gc .GetNumbersAsFloat (_gbg .Elements ());if _agca !=nil {return _agca ;};_aa .SetDash (_af ...);_ =_cf ;_ca .Log .Debug ("\u004c\u0069n\u0065\u0020\u0064\u0061\u0073\u0068\u0020\u0070\u0068\u0061\u0073\u0065\u0020\u006e\u006f\u0074\u0020\u0073\u0075\u0070\u0070\u006frt\u0065\u0064");case "\u0072\u0069":_ca .Log .Debug ("\u0052\u0065\u006e\u0064\u0065\u0072\u0069\u006e\u0067\u0020i\u006e\u0074\u0065\u006e\u0074\u0020\u006eo\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064");case "\u0069":_ca .Log .Debug ("\u0046\u006c\u0061\u0074\u006e\u0065\u0073\u0073\u0020\u0074\u006f\u006c\u0065\u0072\u0061n\u0063e\u0020\u006e\u006f\u0074\u0020\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064");case "\u0067\u0073":if len (_cea .Params )!=1{return _agc ;};_aee ,_faf :=_gc .GetName (_cea .Params [0]);if !_faf {return _dbag ;};if _aee ==nil {return _agc ;};_gccc ,_faf :=_be .GetExtGState (*_aee );if !_faf {_ca .Log .Debug ("\u0045\u0052\u0052OR\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006eo\u0074 \u0066i\u006ed\u0020\u0072\u0065\u0073\u006f\u0075\u0072\u0063\u0065\u003a\u0020\u0025\u0073",*_aee );return _c .New ("\u0072e\u0073o\u0075\u0072\u0063\u0065\u0020n\u006f\u0074 \u0066\u006f\u0075\u006e\u0064");};_age ,_faf :=_gc .GetDict (_gccc );if !_faf {_ca .Log .Debug ("\u0045\u0052RO\u0052\u003a\u0020c\u006f\u0075\u006c\u0064 ge\u0074 g\u0072\u0061\u0070\u0068\u0069\u0063\u0073 s\u0074\u0061\u0074\u0065\u0020\u0064\u0069c\u0074");return _dbag ;};_ca .Log .Debug ("G\u0053\u0020\u0064\u0069\u0063\u0074\u003a\u0020\u0025\u0073",_age .String ());case "\u006d":if len (_cea .Params )!=2{_ca .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0065\u0072\u0072o\u0072\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0072\u006f\u0063\u0065\u0073\u0073\u0069\u006e\u0067\u0020\u0060\u006d\u0060\u0020o\u0070\u0065r\u0061\u0074o\u0072\u003a\u0020\u0025\u0073\u002e\u0020\u004f\u0075\u0074\u0070\u0075\u0074 m\u0061\u0079\u0020\u0062\u0065\u0020\u0069\u006e\u0063o\u0072\u0072\u0065\u0063\u0074\u002e",_agc );return nil ;};_df ,_fef :=_gc .GetNumbersAsFloat (_cea .Params );if _fef !=nil {return _fef ;};_ca .Log .Debug ("M\u006f\u0076\u0065\u0020\u0074\u006f\u003a\u0020\u0025\u0076",_df );_aa .NewSubPath ();_aa .MoveTo (_df [0],_df [1]);case "\u006c":if len (_cea .Params )!=2{_ca .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0065\u0072\u0072o\u0072\u0020\u0077\u0068\u0069\u006c\u0065\u0020\u0070\u0072\u006f\u0063\u0065\u0073\u0073\u0069\u006e\u0067\u0020\u0060\u006c\u0060\u0020o\u0070\u0065r\u0061\u0074o\u0072\u003a\u0020\u0025\u0073\u002e\u0020\u004f\u0075\u0074\u0070\u0075\u0074 m\u0061\u0079\u0020\u0062\u0065\u0020\u0069\u006e\u0063o\u0072\u0072\u0065\u0063\u0074\u002e",_agc );return nil ;};_fcgf ,_ffg :=_gc .GetNumbersAsFloat (_cea .Params );if _ffg !=nil {return _ffg ;};_aa .LineTo (_fcgf [0],_fcgf [1]);case "\u0063":if len (_cea .Params )!=6{return _agc ;};_fd ,_bff :=_gc .GetNumbersAsFloat (_cea .Params );if _bff !=nil {return _bff ;};_ca .Log .Debug ("\u0043u\u0062\u0069\u0063\u0020\u0062\u0065\u007a\u0069\u0065\u0072\u0020p\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076",_fd );_aa .CubicTo (_fd [0],_fd [1],_fd [2],_fd [3],_fd [4],_fd [5]);case "\u0076","\u0079":if len (_cea .Params )!=4{return _agc ;};_fac ,_cfa :=_gc .GetNumbersAsFloat (_cea .Params );if _cfa !=nil {return _cfa ;};_ca .Log .Debug ("\u0043u\u0062\u0069\u0063\u0020\u0062\u0065\u007a\u0069\u0065\u0072\u0020p\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076",_fac );_aa .QuadraticTo (_fac [0],_fac [1],_fac [2],_fac [3]);case "\u0068":_aa .ClosePath ();_aa .NewSubPath ();case "\u0072\u0065":if len (_cea .Params )!=4{return _agc ;};_eef ,_aeac :=_gc .GetNumbersAsFloat (_cea .Params );if _aeac !=nil {return _aeac ;};_aa .DrawRectangle (_eef [0],_eef [1],_eef [2],_eef [3]);_aa .NewSubPath ();case "\u0053":_fcgb ,_cfc :=_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _cfc !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_cfc );return _cfc ;};_abdd ,_fbg :=_fcgb .(*_db .PdfColorDeviceRGB );if !_fbg {_ca .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _cfc ;};_aa .SetRGBA (_abdd .R (),_abdd .G (),_abdd .B (),1);_aa .Stroke ();case "\u0073":_dda ,_ea :=_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _ea !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_ea );return _ea ;};_feaa ,_febb :=_dda .(*_db .PdfColorDeviceRGB );if !_febb {_ca .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _ea ;};_aa .ClosePath ();_aa .NewSubPath ();_aa .SetRGBA (_feaa .R (),_feaa .G (),_feaa .B (),1);_aa .Stroke ();case "\u0066","\u0046":_abdc ,_bg :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _bg !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_bg );return _bg ;};_bffg ,_dcf :=_abdc .(*_db .PdfColorDeviceRGB );if !_dcf {_ca .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _bg ;};_aa .SetRGBA (_bffg .R (),_bffg .G (),_bffg .B (),1);_aa .SetFillRule (_ag .FillRuleWinding );_aa .Fill ();case "\u0066\u002a":_bed ,_ged :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _ged !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_ged );return _ged ;};_aef ,_dad :=_bed .(*_db .PdfColorDeviceRGB );if !_dad {_ca .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _ged ;};_aa .SetRGBA (_aef .R (),_aef .G (),_aef .B (),1);_aa .SetFillRule (_ag .FillRuleEvenOdd );_aa .Fill ();case "\u0042":_ead ,_bfc :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _bfc !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_bfc );return _bfc ;};_agb :=_ead .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_agb .R (),_agb .G (),_agb .B (),1);_aa .SetFillRule (_ag .FillRuleWinding );_aa .FillPreserve ();_ead ,_bfc =_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _bfc !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_bfc );return _bfc ;};_agb =_ead .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_agb .R (),_agb .G (),_agb .B (),1);_aa .Stroke ();case "\u0042\u002a":_dbc ,_dga :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _dga !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_dga );return _dga ;};_ac :=_dbc .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_ac .R (),_ac .G (),_ac .B (),1);_aa .SetFillRule (_ag .FillRuleEvenOdd );_aa .FillPreserve ();_dbc ,_dga =_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _dga !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_dga );return _dga ;};_ac =_dbc .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_ac .R (),_ac .G (),_ac .B (),1);_aa .Stroke ();case "\u0062":_afa ,_cbf :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _cbf !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_cbf );return _cbf ;};_cbe :=_afa .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_cbe .R (),_cbe .G (),_cbe .B (),1);_aa .ClosePath ();_aa .NewSubPath ();_aa .SetFillRule (_ag .FillRuleWinding );_aa .FillPreserve ();_afa ,_cbf =_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _cbf !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_cbf );return _cbf ;};_cbe =_afa .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_cbe .R (),_cbe .G (),_cbe .B (),1);_aa .Stroke ();case "\u0062\u002a":_aa .ClosePath ();_agg ,_dgd :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _dgd !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_dgd );return _dgd ;};_geg :=_agg .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_geg .R (),_geg .G (),_geg .B (),1);_aa .NewSubPath ();_aa .SetFillRule (_ag .FillRuleEvenOdd );_aa .FillPreserve ();_agg ,_dgd =_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _dgd !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_dgd );return _dgd ;};_geg =_agg .(*_db .PdfColorDeviceRGB );_aa .SetRGBA (_geg .R (),_geg .G (),_geg .B (),1);_aa .Stroke ();case "\u006e":_aa .ClearPath ();case "\u0057":_aa .SetFillRule (_ag .FillRuleWinding );_aa .ClipPreserve ();case "\u0057\u002a":_aa .SetFillRule (_ag .FillRuleEvenOdd );_aa .ClipPreserve ();case "\u0072\u0067":_bc ,_cg :=_eca .ColorNonStroking .(*_db .PdfColorDeviceRGB );if !_cg {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_aa .SetFillRGBA (_bc .R (),_bc .G (),_bc .B (),1);case "\u0052\u0047":_ddf ,_eb :=_eca .ColorStroking .(*_db .PdfColorDeviceRGB );if !_eb {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_aa .SetStrokeRGBA (_ddf .R (),_ddf .G (),_ddf .B (),1);case "\u006b":_bbd ,_dadd :=_eca .ColorNonStroking .(*_db .PdfColorDeviceCMYK );if !_dadd {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_gde ,_gaec :=_eca .ColorspaceNonStroking .ColorToRGB (_bbd );if _gaec !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_bgd ,_dadd :=_gde .(*_db .PdfColorDeviceRGB );if !_dadd {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_gde );return nil ;};_aa .SetFillRGBA (_bgd .R (),_bgd .G (),_bgd .B (),1);case "\u004b":_aged ,_dbb :=_eca .ColorStroking .(*_db .PdfColorDeviceCMYK );if !_dbb {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_bcb ,_ba :=_eca .ColorspaceStroking .ColorToRGB (_aged );if _ba !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_fdd ,_dbb :=_bcb .(*_db .PdfColorDeviceRGB );if !_dbb {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_bcb );return nil ;};_aa .SetStrokeRGBA (_fdd .R (),_fdd .G (),_fdd .B (),1);case "\u0067":_bdd ,_cga :=_eca .ColorNonStroking .(*_db .PdfColorDeviceGray );if !_cga {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_fff ,_abg :=_eca .ColorspaceNonStroking .ColorToRGB (_bdd );if _abg !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_abc ,_cga :=_fff .(*_db .PdfColorDeviceRGB );if !_cga {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_fff );return nil ;};_aa .SetFillRGBA (_abc .R (),_abc .G (),_abc .B (),1);case "\u0047":_fae ,_deg :=_eca .ColorStroking .(*_db .PdfColorDeviceGray );if !_deg {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_acf ,_gbgc :=_eca .ColorspaceStroking .ColorToRGB (_fae );if _gbgc !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_bag ,_deg :=_acf .(*_db .PdfColorDeviceRGB );if !_deg {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_acf );return nil ;};_aa .SetStrokeRGBA (_bag .R (),_bag .G (),_bag .B (),1);case "\u0063\u0073","\u0073\u0063","\u0073\u0063\u006e":_dfb ,_ggb :=_eca .ColorspaceNonStroking .ColorToRGB (_eca .ColorNonStroking );if _ggb !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorNonStroking );return nil ;};_cfe ,_dcg :=_dfb .(*_db .PdfColorDeviceRGB );if !_dcg {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_dfb );return nil ;};_aa .SetFillRGBA (_cfe .R (),_cfe .G (),_cfe .B (),1);case "\u0043\u0053","\u0053\u0043","\u0053\u0043\u004e":_bdg ,_cdb :=_eca .ColorspaceStroking .ColorToRGB (_eca .ColorStroking );if _cdb !=nil {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_eca .ColorStroking );return nil ;};_dgf ,_ebg :=_bdg .(*_db .PdfColorDeviceRGB );if !_ebg {_ca .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u0020\u0063\u006f\u006e\u0076\u0065r\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006c\u006f\u0072:\u0020\u0025\u0076",_bdg );return nil ;};_aa .SetStrokeRGBA (_dgf .R (),_dgf .G (),_dgf .B (),1);case "\u0044\u006f":if len (_cea .Params )!=1{return _agc ;};_gdeb ,_bgg :=_gc .GetName (_cea .Params [0]);if !_bgg {return _dbag ;};_ ,_dfba :=_be .GetXObjectByName (*_gdeb );switch _dfba {case _db .XObjectTypeImage :_ca .Log .Debug ("\u0058\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u0069\u006d\u0061\u0067e\u003a\u0020\u0025\u0073",_gdeb .String ());_ccc ,_ecad :=_be .GetXObjectImageByName (*_gdeb );if _ecad !=nil {return _ecad ;};_egg ,_ecad :=_ccc .ToImage ();if _ecad !=nil {return _ecad ;};_aac ,_ecad :=_egg .ToGoImage ();if _ecad !=nil {return _ecad ;};_gff :=_aac .Bounds ();_aa .Push ();_aa .Scale (1.0/float64 (_gff .Dx ()),-1.0/float64 (_gff .Dy ()));_aa .DrawImageAnchored (_aac ,0,0,0,1);_aa .Pop ();case _db .XObjectTypeForm :_ca .Log .Debug ("\u0058\u004fb\u006a\u0065\u0063t\u0020\u0066\u006f\u0072\u006d\u003a\u0020\u0025\u0073",_gdeb .String ());_dge ,_dfc :=_be .GetXObjectFormByName (*_gdeb );if _dfc !=nil {return _dfc ;};_gcf ,_dfc :=_dge .GetContentStream ();if _dfc !=nil {return _dfc ;};_dde :=_dge .Resources ;if _dde ==nil {_dde =_be ;};_aa .Push ();if _dge .Matrix !=nil {_gac ,_bfaa :=_gc .GetArray (_dge .Matrix );if !_bfaa {return _dbag ;};_faa ,_eaa :=_gc .GetNumbersAsFloat (_gac .Elements ());if _eaa !=nil {return _eaa ;};if len (_faa )!=6{return _agc ;};_fec :=_g .NewMatrix (_faa [0],_faa [1],_faa [2],_faa [3],_faa [4],_faa [5]);_aa .SetMatrix (_aa .Matrix ().Mult (_fec ));};if _dge .BBox !=nil {_ffd ,_ggf :=_gc .GetArray (_dge .BBox );if !_ggf {return _dbag ;};_cbc ,_ebb :=_gc .GetNumbersAsFloat (_ffd .Elements ());if _ebb !=nil {return _ebb ;};if len (_cbc )!=4{_ca .Log .Debug ("\u004c\u0065\u006e\u0020\u003d\u0020\u0025\u0064",len (_cbc ));return _agc ;};_aa .DrawRectangle (_cbc [0],_cbc [1],_cbc [2]-_cbc [0],_cbc [3]-_cbc [1]);_aa .SetRGBA (1,0,0,1);_aa .Clip ();}else {_ca .Log .Debug ("\u0045R\u0052\u004fR\u003a\u0020\u0052\u0065q\u0075\u0069\u0072e\u0064\u0020\u0042\u0042\u006f\u0078\u0020\u006d\u0069ss\u0069\u006e\u0067 \u006f\u006e \u0058\u004f\u0062\u006a\u0065\u0063t\u0020\u0046o\u0072\u006d");};_dfc =_ad .renderContentStream (_aa ,string (_gcf ),_dde );if _dfc !=nil {return _dfc ;};_aa .Pop ();};case "\u0042\u0049":if len (_cea .Params )!=1{return _agc ;};_ccf ,_gfc :=_cea .Params [0].(*_fb .ContentStreamInlineImage );if !_gfc {return nil ;};_dgg ,_fee :=_ccf .ToImage (_be );if _fee !=nil {return _fee ;};_bfe ,_fee :=_dgg .ToGoImage ();if _fee !=nil {return _fee ;};_cdd :=_bfe .Bounds ();_aa .Push ();_aa .Scale (1.0/float64 (_cdd .Dx ()),-1.0/float64 (_cdd .Dy ()));_aa .DrawImageAnchored (_bfe ,0,0,0,1);_aa .Pop ();case "\u0042\u0054":_cc .Reset ();case "\u0045\u0054":_cc .Reset ();case "\u0054\u004c":if len (_cea .Params )!=1{return _agc ;};_fafc ,_beg :=_gc .GetNumberAsFloat (_cea .Params [0]);if _beg !=nil {return _beg ;};_cc .Tl =_fafc ;case "\u0054\u0063":if len (_cea .Params )!=1{return _agc ;};_dcdf ,_efg :=_gc .GetNumberAsFloat (_cea .Params [0]);if _efg !=nil {return _efg ;};_cc .Tc =_dcdf ;case "\u0054\u0077":if len (_cea .Params )!=1{return _agc ;};_gbb ,_agd :=_gc .GetNumberAsFloat (_cea .Params [0]);if _agd !=nil {return _agd ;};_cc .Tw =_gbb ;case "\u0054\u007a":if len (_cea .Params )!=1{return _agc ;};_bfec ,_efge :=_gc .GetNumberAsFloat (_cea .Params [0]);if _efge !=nil {return _efge ;};_cc .Th =_bfec ;case "\u0054\u0073":if len (_cea .Params )!=1{return _agc ;};_fcd ,_dbac :=_gc .GetNumberAsFloat (_cea .Params [0]);if _dbac !=nil {return _dbac ;};_cc .Ts =_fcd ;case "\u0054\u0064":if len (_cea .Params )!=2{return _agc ;};_dag ,_ffc :=_gc .GetNumbersAsFloat (_cea .Params );if _ffc !=nil {return _ffc ;};_ca .Log .Debug ("\u0054\u0064\u003a\u0020\u0025\u0076",_dag );_cc .ProcTd (_dag [0],_dag [1]);case "\u0054\u0044":if len (_cea .Params )!=2{return _agc ;};_cgc ,_dccb :=_gc .GetNumbersAsFloat (_cea .Params );if _dccb !=nil {return _dccb ;};_ca .Log .Debug ("\u0054\u0044\u003a\u0020\u0025\u0076",_cgc );_cc .ProcTD (_cgc [0],_cgc [1]);case "\u0054\u002a":_cc .ProcTStar ();case "\u0054\u006d":if len (_cea .Params )!=6{return _agc ;};_dca ,_dbf :=_gc .GetNumbersAsFloat (_cea .Params );if _dbf !=nil {return _dbf ;};_ca .Log .Debug ("\u0054\u0065x\u0074\u0020\u006da\u0074\u0072\u0069\u0078\u003a\u0020\u0025\u002b\u0076",_dca );_cc .ProcTm (_dca [0],_dca [1],_dca [2],_dca [3],_dca [4],_dca [5]);case "\u0027":if len (_cea .Params )!=1{return _agc ;};_eba ,_bddb :=_gc .GetStringBytes (_cea .Params [0]);if !_bddb {return _dbag ;};_ca .Log .Debug ("\u0027\u0020\u0073t\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_eba ));_cc .ProcQ (_eba ,_aa );case "\u0022":if len (_cea .Params )!=3{return _agc ;};_ede ,_aec :=_gc .GetNumberAsFloat (_cea .Params [0]);if _aec !=nil {return _aec ;};_bef ,_aec :=_gc .GetNumberAsFloat (_cea .Params [1]);if _aec !=nil {return _aec ;};_cce ,_gfa :=_gc .GetStringBytes (_cea .Params [2]);if !_gfa {return _dbag ;};_cc .ProcDQ (_cce ,_ede ,_bef ,_aa );case "\u0054\u006a":if len (_cea .Params )!=1{return _agc ;};_dfe ,_ded :=_gc .GetStringBytes (_cea .Params [0]);if !_ded {return _dbag ;};_ca .Log .Debug ("\u0054j\u0020s\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0060\u0025\u0073\u0060",string (_dfe ));_cc .ProcTj (_dfe ,_aa );case "\u0054\u004a":if len (_cea .Params )!=1{return _agc ;};_bbda ,_gba :=_gc .GetArray (_cea .Params [0]);if !_gba {_ca .Log .Debug ("\u0054\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_bbda );return _dbag ;};_ca .Log .Debug ("\u0054\u004a\u0020\u0061\u0072\u0072\u0061\u0079\u003a\u0020\u0025\u002b\u0076",_bbda );for _ ,_fdf :=range _bbda .Elements (){switch _bac :=_fdf .(type ){case *_gc .PdfObjectString :if _bac !=nil {_cc .ProcTj (_bac .Bytes (),_aa );};case *_gc .PdfObjectFloat ,*_gc .PdfObjectInteger :_adc ,_fad :=_gc .GetNumberAsFloat (_bac );if _fad ==nil {_cc .Translate (-_adc *0.001*_cc .Tf .Size ,0);};};};case "\u0054\u0066":if len (_cea .Params )!=2{return _agc ;};_ca .Log .Debug ("\u0025\u0023\u0076",_cea .Params );_cbb ,_gga :=_gc .GetName (_cea .Params [0]);if !_gga ||_cbb ==nil {_ca .Log .Debug ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u0066\u006f\u006e\u0074\u0020\u006e\u0061m\u0065 \u006f\u0062\u006a\u0065\u0063\u0074\u003a \u0025\u0076",_cea .Params [0]);return _dbag ;};_ca .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u006e\u0061\u006d\u0065\u003a\u0020\u0025\u0073",_cbb .String ());_edc ,_fda :=_gc .GetNumberAsFloat (_cea .Params [1]);if _fda !=nil {_ca .Log .Debug ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u0066\u006f\u006e\u0074\u0020\u0073\u0069z\u0065 \u006f\u0062\u006a\u0065\u0063\u0074\u003a \u0025\u0076",_cea .Params [1]);return _dbag ;};_ca .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0076",_edc );_gbf ,_adca :=_be .GetFontByName (*_cbb );if !_adca {_ca .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0046\u006f\u006e\u0074\u0020\u0025s\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064",_cbb .String ());return _c .New ("\u0066\u006f\u006e\u0074\u0020\u006e\u006f\u0074\u0020f\u006f\u0075\u006e\u0064");};_ca .Log .Debug ("\u0046\u006f\u006e\u0074\u003a\u0020\u0025\u0054",_gbf );_fgf ,_gga :=_gc .GetDict (_gbf );if !_gga {_ca .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075l\u0064\u0020\u006e\u006f\u0074\u0020\u0067e\u0074\u0020\u0066\u006f\u006e\u0074\u0020\u0064\u0069\u0063\u0074");return _dbag ;};_fba ,_fda :=_db .NewPdfFontFromPdfObject (_fgf );if _fda !=nil {_ca .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u006c\u006f\u0061\u0064\u0020\u0066\u006fn\u0074\u0020\u0066\u0072\u006fm\u0020\u006fb\u006a\u0065\u0063\u0074");return _fda ;};_gdb :=_fba .BaseFont ();if _gdb ==""{_gdb =_cbb .String ();};_fga ,_gga :=_agcc [_gdb ];if !_gga {_fga ,_fda =_ag .NewTextFont (_fba ,_edc );if _fda !=nil {_ca .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025v",_fda );};};if _fga ==nil {if len (_gdb )> 7&&_gdb [6]=='+'{_gdb =_gdb [7:];};_ecgc :=[]string {_gdb ,"\u0054i\u006de\u0073\u0020\u004e\u0065\u0077\u0020\u0052\u006f\u006d\u0061\u006e","\u0041\u0072\u0069a\u006c","D\u0065\u006a\u0061\u0056\u0075\u0020\u0053\u0061\u006e\u0073"};for _ ,_aad :=range _ecgc {_ca .Log .Debug ("\u0044\u0045\u0042\u0055\u0047\u003a \u0073\u0065\u0061\u0072\u0063\u0068\u0069\u006e\u0067\u0020\u0073\u0079\u0073t\u0065\u006d\u0020\u0066\u006f\u006e\u0074 \u0060\u0025\u0073\u0060",_aad );if _fga ,_gga =_agcc [_aad ];_gga {break ;};_bbc :=_ffb .Match (_aad );if _bbc ==nil {_ca .Log .Debug ("c\u006f\u0075\u006c\u0064\u0020\u006eo\u0074\u0020\u0066\u0069\u006e\u0064\u0020\u0066\u006fn\u0074\u0020\u0066i\u006ce\u0020\u0025\u0073",_aad );continue ;};_fga ,_fda =_ag .NewTextFontFromPath (_bbc .Filename ,_edc );if _fda !=nil {_ca .Log .Debug ("c\u006f\u0075\u006c\u0064\u0020\u006eo\u0074\u0020\u006c\u006f\u0061\u0064\u0020\u0066\u006fn\u0074\u0020\u0066i\u006ce\u0020\u0025\u0073",_bbc .Filename );continue ;};_ca .Log .Debug ("\u0053\u0075\u0062\u0073\u0074\u0069t\u0075\u0074\u0069\u006e\u0067\u0020\u0066\u006f\u006e\u0074\u0020\u0025\u0073 \u0077\u0069\u0074\u0068\u0020\u0025\u0073 \u0028\u0025\u0073\u0029",_gdb ,_bbc .Name ,_bbc .Filename );_agcc [_aad ]=_fga ;break ;};};if _fga ==nil {_ca .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0063\u006f\u0075\u006c\u0064\u0020n\u006f\u0074\u0020\u0066\u0069\u006ed\u0020\u0061\u006e\u0079\u0020\u0073\u0075\u0069\u0074\u0061\u0062\u006c\u0065 \u0066\u006f\u006e\u0074");return _c .New ("\u0063\u006f\u0075\u006c\u0064\u0020\u006e\u006f\u0074\u0020\u0066\u0069\u006e\u0064\u0020a\u006ey\u0020\u0073\u0075\u0069\u0074\u0061\u0062\u006c\u0065\u0020\u0066\u006f\u006e\u0074");};_cc .ProcTf (_fga .WithSize (_edc ,_fba ));case "\u0042\u004d\u0043","\u0042\u0044\u0043":case "\u0045\u004d\u0043":default:_ca .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0075\u006e\u0073u\u0070\u0070\u006f\u0072\u0074\u0065\u0064 \u006f\u0070\u0065\u0072\u0061\u006e\u0064\u003a\u0020\u0025\u0073",_cea .Operand );};return nil ;});_fea =_ce .Process (_ggg );if _fea !=nil {return _fea ;};return nil ;};
|
|
|
|
// RenderToPath converts the specified PDF page into an image and saves the
|
|
// result at the specified location.
|
|
func (_ff *ImageDevice )RenderToPath (page *_db .PdfPage ,outputPath string )error {_ab ,_dba :=_ff .Render (page );if _dba !=nil {return _dba ;};_fe :=_e .ToLower (_de .Ext (outputPath ));if _fe ==""{return _c .New ("\u0063\u006ful\u0064\u0020\u006eo\u0074\u0020\u0072\u0065cog\u006eiz\u0065\u0020\u006f\u0075\u0074\u0070\u0075t \u0066\u0069\u006c\u0065\u0020\u0074\u0079p\u0065");};switch _fe {case "\u002e\u0070\u006e\u0067":return _gb (outputPath ,_ab );case "\u002e\u006a\u0070\u0067","\u002e\u006a\u0070e\u0067":return _gg (outputPath ,_ab ,100);};return _da .Errorf ("\u0075\u006e\u0072\u0065\u0063\u006fg\u006e\u0069\u007a\u0065\u0064\u0020\u006f\u0075\u0074\u0070\u0075\u0074\u0020f\u0069\u006c\u0065\u0020\u0074\u0079\u0070e\u003a\u0020\u0025\u0073",_fe );};var (_dbag =_c .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");_agc =_c .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");); |