unipdf/render/render.go
2020-12-06 13:03:03 +00:00

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 (_f "errors";_e "fmt";_dce "github.com/adrg/sysfont";_df "github.com/unidoc/unipdf/v3/common";_ec "github.com/unidoc/unipdf/v3/contentstream";_dc "github.com/unidoc/unipdf/v3/core";_add "github.com/unidoc/unipdf/v3/internal/transform";_ad "github.com/unidoc/unipdf/v3/model";_da "github.com/unidoc/unipdf/v3/render/internal/context";_ca "github.com/unidoc/unipdf/v3/render/internal/context/imagerender";_c "image";_aa "image/draw";_d "image/jpeg";_fd "image/png";_fe "os";_g "path/filepath";_a "strings";);func _bc (_dde string ,_fead _c .Image )error {_gea ,_fdg :=_fe .Create (_dde );if _fdg !=nil {return _fdg ;};defer _gea .Close ();return _fd .Encode (_gea ,_fead );};
// RenderToPath converts the specified PDF page into an image and saves the
// result at the specified location.
func (_ef *ImageDevice )RenderToPath (page *_ad .PdfPage ,outputPath string )error {_fa ,_cgb :=_ef .Render (page );if _cgb !=nil {return _cgb ;};_dd :=_a .ToLower (_g .Ext (outputPath ));if _dd ==""{return _f .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 _dd {case "\u002e\u0070\u006e\u0067":return _bc (outputPath ,_fa );case "\u002e\u006a\u0070\u0067","\u002e\u006a\u0070e\u0067":return _ff (outputPath ,_fa ,100);};return _e .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",_dd );};
// ImageDevice is used to render PDF pages to image targets.
type ImageDevice struct{renderer };func (_ac renderer )renderContentStream (_eg _da .Context ,_eaa string ,_efe *_ad .PdfPageResources )error {_dfb ,_gd :=_ec .NewContentStreamParser (_eaa ).Parse ();if _gd !=nil {return _gd ;};_aba :=_eg .TextState ();_cd :=map[string ]*_da .TextFont {};_bcg :=_dce .NewFinder (&_dce .FinderOpts {Extensions :[]string {"\u002e\u0074\u0074\u0066","\u002e\u0074\u0074\u0063"}});_fed :=_ec .NewContentStreamProcessor (*_dfb );_fed .AddHandler (_ec .HandlerConditionEnumAllOperands ,"",func (_ga *_ec .ContentStreamOperation ,_aab _ec .GraphicsState ,_eag *_ad .PdfPageResources )error {_df .Log .Debug ("\u0050\u0072\u006f\u0063\u0065\u0073\u0073\u0069\u006e\u0067\u0020\u0025\u0073",_ga .Operand );switch _ga .Operand {case "\u0071":_eg .Push ();case "\u0051":_eg .Pop ();case "\u0063\u006d":if len (_ga .Params )!=6{return _cba ;};_daf ,_faa :=_dc .GetNumbersAsFloat (_ga .Params );if _faa !=nil {return _faa ;};_adcf :=_add .NewMatrix (_daf [0],_daf [1],_daf [2],_daf [3],_daf [4],_daf [5]);_df .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",_adcf );_eg .SetMatrix (_eg .Matrix ().Mult (_adcf ));_cc :=(_aab .CTM .ScalingFactorX ()+_aab .CTM .ScalingFactorY ())/2.0;_eg .SetLineWidth (_cc *_eg .LineWidth ());case "\u0077":if len (_ga .Params )!=1{return _cba ;};_fge ,_af :=_dc .GetNumbersAsFloat (_ga .Params );if _af !=nil {return _af ;};_dfe :=(_aab .CTM .ScalingFactorX ()+_aab .CTM .ScalingFactorY ())/2.0;_eg .SetLineWidth (_dfe *_fge [0]);case "\u004a":if len (_ga .Params )!=1{return _cba ;};_de ,_bd :=_dc .GetIntVal (_ga .Params [0]);if !_bd {return _gc ;};switch _de {case 0:_eg .SetLineCap (_da .LineCapButt );case 1:_eg .SetLineCap (_da .LineCapRound );case 2:_eg .SetLineCap (_da .LineCapSquare );default:_df .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",_de );return _cba ;};case "\u006a":if len (_ga .Params )!=1{return _cba ;};_eee ,_dfa :=_dc .GetIntVal (_ga .Params [0]);if !_dfa {return _gc ;};switch _eee {case 0:_eg .SetLineJoin (_da .LineJoinBevel );case 1:_eg .SetLineJoin (_da .LineJoinRound );case 2:_eg .SetLineJoin (_da .LineJoinBevel );default:_df .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",_eee );return _cba ;};case "\u004d":if len (_ga .Params )!=1{return _cba ;};_cce ,_ggd :=_dc .GetNumbersAsFloat (_ga .Params );if _ggd !=nil {return _ggd ;};_ =_cce ;_df .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 (_ga .Params )!=2{return _cba ;};_bg ,_eea :=_dc .GetArray (_ga .Params [0]);if !_eea {return _gc ;};_cgg ,_eea :=_dc .GetIntVal (_ga .Params [1]);if !_eea {return _gc ;};_fad ,_aca :=_dc .GetNumbersAsFloat (_bg .Elements ());if _aca !=nil {return _aca ;};_eg .SetDash (_fad ...);_ =_cgg ;_df .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":_df .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":_df .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 (_ga .Params )!=1{return _cba ;};_gca ,_cga :=_dc .GetName (_ga .Params [0]);if !_cga {return _gc ;};if _gca ==nil {return _cba ;};_ffc ,_cga :=_eag .GetExtGState (*_gca );if !_cga {_df .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",*_gca );return _f .New ("\u0072e\u0073o\u0075\u0072\u0063\u0065\u0020n\u006f\u0074 \u0066\u006f\u0075\u006e\u0064");};_caef ,_cga :=_dc .GetDict (_ffc );if !_cga {_df .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 _gc ;};_df .Log .Debug ("G\u0053\u0020\u0064\u0069\u0063\u0074\u003a\u0020\u0025\u0073",_caef .String ());case "\u006d":if len (_ga .Params )!=2{_df .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",_cba );return nil ;};_afg ,_dcb :=_dc .GetNumbersAsFloat (_ga .Params );if _dcb !=nil {return _dcb ;};_df .Log .Debug ("M\u006f\u0076\u0065\u0020\u0074\u006f\u003a\u0020\u0025\u0076",_afg );_eg .NewSubPath ();_eg .MoveTo (_afg [0],_afg [1]);case "\u006c":if len (_ga .Params )!=2{_df .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",_cba );return nil ;};_gb ,_db :=_dc .GetNumbersAsFloat (_ga .Params );if _db !=nil {return _db ;};_eg .LineTo (_gb [0],_gb [1]);case "\u0063":if len (_ga .Params )!=6{return _cba ;};_be ,_gac :=_dc .GetNumbersAsFloat (_ga .Params );if _gac !=nil {return _gac ;};_df .Log .Debug ("\u0043u\u0062\u0069\u0063\u0020\u0062\u0065\u007a\u0069\u0065\u0072\u0020p\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076",_be );_eg .CubicTo (_be [0],_be [1],_be [2],_be [3],_be [4],_be [5]);case "\u0076","\u0079":if len (_ga .Params )!=4{return _cba ;};_aag ,_gcg :=_dc .GetNumbersAsFloat (_ga .Params );if _gcg !=nil {return _gcg ;};_df .Log .Debug ("\u0043u\u0062\u0069\u0063\u0020\u0062\u0065\u007a\u0069\u0065\u0072\u0020p\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076",_aag );_eg .QuadraticTo (_aag [0],_aag [1],_aag [2],_aag [3]);case "\u0068":_eg .ClosePath ();_eg .NewSubPath ();case "\u0072\u0065":if len (_ga .Params )!=4{return _cba ;};_gf ,_abab :=_dc .GetNumbersAsFloat (_ga .Params );if _abab !=nil {return _abab ;};_eg .DrawRectangle (_gf [0],_gf [1],_gf [2],_gf [3]);_eg .NewSubPath ();case "\u0053":_caed ,_dcgg :=_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _dcgg !=nil {_df .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",_dcgg );return _dcgg ;};_gfd ,_agf :=_caed .(*_ad .PdfColorDeviceRGB );if !_agf {_df .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _dcgg ;};_eg .SetRGBA (_gfd .R (),_gfd .G (),_gfd .B (),1);_eg .Stroke ();case "\u0073":_bgf ,_dee :=_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _dee !=nil {_df .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",_dee );return _dee ;};_bdc ,_acf :=_bgf .(*_ad .PdfColorDeviceRGB );if !_acf {_df .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _dee ;};_eg .ClosePath ();_eg .NewSubPath ();_eg .SetRGBA (_bdc .R (),_bdc .G (),_bdc .B (),1);_eg .Stroke ();case "\u0066","\u0046":_gfg ,_dg :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _dg !=nil {_df .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",_dg );return _dg ;};_fgc ,_gacb :=_gfg .(*_ad .PdfColorDeviceRGB );if !_gacb {_df .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _dg ;};_eg .SetRGBA (_fgc .R (),_fgc .G (),_fgc .B (),1);_eg .SetFillRule (_da .FillRuleWinding );_eg .Fill ();case "\u0066\u002a":_ebf ,_eeb :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _eeb !=nil {_df .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",_eeb );return _eeb ;};_cf ,_gbc :=_ebf .(*_ad .PdfColorDeviceRGB );if !_gbc {_df .Log .Debug ("\u0045\u0072\u0072\u006fr \u0063\u006f\u006e\u0076\u0065\u0072\u0074\u0069\u006e\u0067\u0020\u0063\u006f\u006co\u0072");return _eeb ;};_eg .SetRGBA (_cf .R (),_cf .G (),_cf .B (),1);_eg .SetFillRule (_da .FillRuleEvenOdd );_eg .Fill ();case "\u0042":_adg ,_efd :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _efd !=nil {_df .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",_efd );return _efd ;};_ccc :=_adg .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_ccc .R (),_ccc .G (),_ccc .B (),1);_eg .SetFillRule (_da .FillRuleWinding );_eg .FillPreserve ();_adg ,_efd =_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _efd !=nil {_df .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",_efd );return _efd ;};_ccc =_adg .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_ccc .R (),_ccc .G (),_ccc .B (),1);_eg .Stroke ();case "\u0042\u002a":_fdd ,_ce :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _ce !=nil {_df .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",_ce );return _ce ;};_fb :=_fdd .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_fb .R (),_fb .G (),_fb .B (),1);_eg .SetFillRule (_da .FillRuleEvenOdd );_eg .FillPreserve ();_fdd ,_ce =_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _ce !=nil {_df .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",_ce );return _ce ;};_fb =_fdd .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_fb .R (),_fb .G (),_fb .B (),1);_eg .Stroke ();case "\u0062":_beg ,_ega :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _ega !=nil {_df .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",_ega );return _ega ;};_ded :=_beg .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_ded .R (),_ded .G (),_ded .B (),1);_eg .ClosePath ();_eg .NewSubPath ();_eg .SetFillRule (_da .FillRuleWinding );_eg .FillPreserve ();_beg ,_ega =_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _ega !=nil {_df .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",_ega );return _ega ;};_ded =_beg .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_ded .R (),_ded .G (),_ded .B (),1);_eg .Stroke ();case "\u0062\u002a":_eg .ClosePath ();_fc ,_dcgf :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _dcgf !=nil {_df .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",_dcgf );return _dcgf ;};_eaf :=_fc .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_eaf .R (),_eaf .G (),_eaf .B (),1);_eg .NewSubPath ();_eg .SetFillRule (_da .FillRuleEvenOdd );_eg .FillPreserve ();_fc ,_dcgf =_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _dcgf !=nil {_df .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",_dcgf );return _dcgf ;};_eaf =_fc .(*_ad .PdfColorDeviceRGB );_eg .SetRGBA (_eaf .R (),_eaf .G (),_eaf .B (),1);_eg .Stroke ();case "\u006e":_eg .ClearPath ();case "\u0057":_eg .SetFillRule (_da .FillRuleWinding );_eg .ClipPreserve ();case "\u0057\u002a":_eg .SetFillRule (_da .FillRuleEvenOdd );_eg .ClipPreserve ();case "\u0072\u0067":_cccc ,_cac :=_aab .ColorNonStroking .(*_ad .PdfColorDeviceRGB );if !_cac {_df .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",_aab .ColorNonStroking );return nil ;};_eg .SetFillRGBA (_cccc .R (),_cccc .G (),_cccc .B (),1);case "\u0052\u0047":_faac ,_gge :=_aab .ColorStroking .(*_ad .PdfColorDeviceRGB );if !_gge {_df .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",_aab .ColorStroking );return nil ;};_eg .SetStrokeRGBA (_faac .R (),_faac .G (),_faac .B (),1);case "\u006b":_ae ,_ddc :=_aab .ColorNonStroking .(*_ad .PdfColorDeviceCMYK );if !_ddc {_df .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",_aab .ColorNonStroking );return nil ;};_faag ,_fgea :=_aab .ColorspaceNonStroking .ColorToRGB (_ae );if _fgea !=nil {_df .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",_aab .ColorNonStroking );return nil ;};_eeac ,_ddc :=_faag .(*_ad .PdfColorDeviceRGB );if !_ddc {_df .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",_faag );return nil ;};_eg .SetFillRGBA (_eeac .R (),_eeac .G (),_eeac .B (),1);case "\u004b":_cbb ,_gdd :=_aab .ColorStroking .(*_ad .PdfColorDeviceCMYK );if !_gdd {_df .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",_aab .ColorStroking );return nil ;};_cbe ,_abd :=_aab .ColorspaceStroking .ColorToRGB (_cbb );if _abd !=nil {_df .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",_aab .ColorStroking );return nil ;};_afa ,_gdd :=_cbe .(*_ad .PdfColorDeviceRGB );if !_gdd {_df .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",_cbe );return nil ;};_eg .SetStrokeRGBA (_afa .R (),_afa .G (),_afa .B (),1);case "\u0067":_ed ,_bad :=_aab .ColorNonStroking .(*_ad .PdfColorDeviceGray );if !_bad {_df .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",_aab .ColorNonStroking );return nil ;};_bff ,_cea :=_aab .ColorspaceNonStroking .ColorToRGB (_ed );if _cea !=nil {_df .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",_aab .ColorNonStroking );return nil ;};_efeb ,_bad :=_bff .(*_ad .PdfColorDeviceRGB );if !_bad {_df .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",_bff );return nil ;};_eg .SetFillRGBA (_efeb .R (),_efeb .G (),_efeb .B (),1);case "\u0047":_afaa ,_bcd :=_aab .ColorStroking .(*_ad .PdfColorDeviceGray );if !_bcd {_df .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",_aab .ColorStroking );return nil ;};_cgbd ,_aac :=_aab .ColorspaceStroking .ColorToRGB (_afaa );if _aac !=nil {_df .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",_aab .ColorStroking );return nil ;};_aaf ,_bcd :=_cgbd .(*_ad .PdfColorDeviceRGB );if !_bcd {_df .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",_cgbd );return nil ;};_eg .SetStrokeRGBA (_aaf .R (),_aaf .G (),_aaf .B (),1);case "\u0063\u0073","\u0073\u0063","\u0073\u0063\u006e":_fda ,_bec :=_aab .ColorspaceNonStroking .ColorToRGB (_aab .ColorNonStroking );if _bec !=nil {_df .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",_aab .ColorNonStroking );return nil ;};_cggg ,_edg :=_fda .(*_ad .PdfColorDeviceRGB );if !_edg {_df .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",_fda );return nil ;};_eg .SetFillRGBA (_cggg .R (),_cggg .G (),_cggg .B (),1);case "\u0043\u0053","\u0053\u0043","\u0053\u0043\u004e":_gce ,_ece :=_aab .ColorspaceStroking .ColorToRGB (_aab .ColorStroking );if _ece !=nil {_df .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",_aab .ColorStroking );return nil ;};_cbf ,_becg :=_gce .(*_ad .PdfColorDeviceRGB );if !_becg {_df .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",_gce );return nil ;};_eg .SetStrokeRGBA (_cbf .R (),_cbf .G (),_cbf .B (),1);case "\u0044\u006f":if len (_ga .Params )!=1{return _cba ;};_cfg ,_fga :=_dc .GetName (_ga .Params [0]);if !_fga {return _gc ;};_ ,_dbf :=_eag .GetXObjectByName (*_cfg );switch _dbf {case _ad .XObjectTypeImage :_df .Log .Debug ("\u0058\u004f\u0062\u006a\u0065\u0063\u0074\u0020\u0069\u006d\u0061\u0067e\u003a\u0020\u0025\u0073",_cfg .String ());_dba ,_egaf :=_eag .GetXObjectImageByName (*_cfg );if _egaf !=nil {return _egaf ;};_cdc ,_egaf :=_dba .ToImage ();if _egaf !=nil {return _egaf ;};_cad ,_egaf :=_cdc .ToGoImage ();if _egaf !=nil {return _egaf ;};_dca :=_cad .Bounds ();_eg .Push ();_eg .Scale (1.0/float64 (_dca .Dx ()),-1.0/float64 (_dca .Dy ()));_eg .DrawImageAnchored (_cad ,0,0,0,1);_eg .Pop ();case _ad .XObjectTypeForm :_df .Log .Debug ("\u0058\u004fb\u006a\u0065\u0063t\u0020\u0066\u006f\u0072\u006d\u003a\u0020\u0025\u0073",_cfg .String ());_edd ,_eae :=_eag .GetXObjectFormByName (*_cfg );if _eae !=nil {return _eae ;};_abc ,_eae :=_edd .GetContentStream ();if _eae !=nil {return _eae ;};_aea :=_edd .Resources ;if _aea ==nil {_aea =_eag ;};_eg .Push ();if _edd .Matrix !=nil {_efb ,_efec :=_dc .GetArray (_edd .Matrix );if !_efec {return _gc ;};_bdf ,_agd :=_dc .GetNumbersAsFloat (_efb .Elements ());if _agd !=nil {return _agd ;};if len (_bdf )!=6{return _cba ;};_gcc :=_add .NewMatrix (_bdf [0],_bdf [1],_bdf [2],_bdf [3],_bdf [4],_bdf [5]);_eg .SetMatrix (_eg .Matrix ().Mult (_gcc ));};if _edd .BBox !=nil {_dge ,_dab :=_dc .GetArray (_edd .BBox );if !_dab {return _gc ;};_dgg ,_cec :=_dc .GetNumbersAsFloat (_dge .Elements ());if _cec !=nil {return _cec ;};if len (_dgg )!=4{_df .Log .Debug ("\u004c\u0065\u006e\u0020\u003d\u0020\u0025\u0064",len (_dgg ));return _cba ;};_eg .DrawRectangle (_dgg [0],_dgg [1],_dgg [2]-_dgg [0],_dgg [3]-_dgg [1]);_eg .SetRGBA (1,0,0,1);_eg .Clip ();}else {_df .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");};_eae =_ac .renderContentStream (_eg ,string (_abc ),_aea );if _eae !=nil {return _eae ;};_eg .Pop ();};case "\u0042\u0049":if len (_ga .Params )!=1{return _cba ;};_egb ,_bfb :=_ga .Params [0].(*_ec .ContentStreamInlineImage );if !_bfb {return nil ;};_fac ,_bge :=_egb .ToImage (_eag );if _bge !=nil {return _bge ;};_bgg ,_bge :=_fac .ToGoImage ();if _bge !=nil {return _bge ;};_cadd :=_bgg .Bounds ();_eg .Push ();_eg .Scale (1.0/float64 (_cadd .Dx ()),-1.0/float64 (_cadd .Dy ()));_eg .DrawImageAnchored (_bgg ,0,0,0,1);_eg .Pop ();case "\u0042\u0054":_aba .Reset ();case "\u0045\u0054":_aba .Reset ();case "\u0054\u004c":if len (_ga .Params )!=1{return _cba ;};_faf ,_fec :=_dc .GetNumberAsFloat (_ga .Params [0]);if _fec !=nil {return _fec ;};_aba .Tl =_faf ;case "\u0054\u0063":if len (_ga .Params )!=1{return _cba ;};_deg ,_ceg :=_dc .GetNumberAsFloat (_ga .Params [0]);if _ceg !=nil {return _ceg ;};_aba .Tc =_deg ;case "\u0054\u0077":if len (_ga .Params )!=1{return _cba ;};_ggg ,_cgba :=_dc .GetNumberAsFloat (_ga .Params [0]);if _cgba !=nil {return _cgba ;};_aba .Tw =_ggg ;case "\u0054\u007a":if len (_ga .Params )!=1{return _cba ;};_ebfa ,_aee :=_dc .GetNumberAsFloat (_ga .Params [0]);if _aee !=nil {return _aee ;};_aba .Th =_ebfa ;case "\u0054\u0073":if len (_ga .Params )!=1{return _cba ;};_cbea ,_abdf :=_dc .GetNumberAsFloat (_ga .Params [0]);if _abdf !=nil {return _abdf ;};_aba .Ts =_cbea ;case "\u0054\u0064":if len (_ga .Params )!=2{return _cba ;};_dccb ,_bgea :=_dc .GetNumbersAsFloat (_ga .Params );if _bgea !=nil {return _bgea ;};_df .Log .Debug ("\u0054\u0064\u003a\u0020\u0025\u0076",_dccb );_aba .ProcTd (_dccb [0],_dccb [1]);case "\u0054\u0044":if len (_ga .Params )!=2{return _cba ;};_ffa ,_ddb :=_dc .GetNumbersAsFloat (_ga .Params );if _ddb !=nil {return _ddb ;};_df .Log .Debug ("\u0054\u0044\u003a\u0020\u0025\u0076",_ffa );_aba .ProcTD (_ffa [0],_ffa [1]);case "\u0054\u002a":_aba .ProcTStar ();case "\u0054\u006d":if len (_ga .Params )!=6{return _cba ;};_geg ,_ffd :=_dc .GetNumbersAsFloat (_ga .Params );if _ffd !=nil {return _ffd ;};_df .Log .Debug ("\u0054\u0065x\u0074\u0020\u006da\u0074\u0072\u0069\u0078\u003a\u0020\u0025\u002b\u0076",_geg );_aba .ProcTm (_geg [0],_geg [1],_geg [2],_geg [3],_geg [4],_geg [5]);case "\u0027":if len (_ga .Params )!=1{return _cba ;};_feb ,_fag :=_dc .GetStringBytes (_ga .Params [0]);if !_fag {return _gc ;};_df .Log .Debug ("\u0027\u0020\u0073t\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_feb ));_aba .ProcQ (_feb ,_eg );case "\u0022":if len (_ga .Params )!=3{return _cba ;};_gdg ,_dcca :=_dc .GetNumberAsFloat (_ga .Params [0]);if _dcca !=nil {return _dcca ;};_agdf ,_dcca :=_dc .GetNumberAsFloat (_ga .Params [1]);if _dcca !=nil {return _dcca ;};_gdb ,_gec :=_dc .GetStringBytes (_ga .Params [2]);if !_gec {return _gc ;};_aba .ProcDQ (_gdb ,_gdg ,_agdf ,_eg );case "\u0054\u006a":if len (_ga .Params )!=1{return _cba ;};_ceaa ,_bab :=_dc .GetStringBytes (_ga .Params [0]);if !_bab {return _gc ;};_df .Log .Debug ("\u0054j\u0020s\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0060\u0025\u0073\u0060",string (_ceaa ));_aba .ProcTj (_ceaa ,_eg );case "\u0054\u004a":if len (_ga .Params )!=1{return _cba ;};_dcgb ,_efda :=_dc .GetArray (_ga .Params [0]);if !_efda {_df .Log .Debug ("\u0054\u0079\u0070\u0065\u003a\u0020\u0025\u0054",_dcgb );return _gc ;};_df .Log .Debug ("\u0054\u004a\u0020\u0061\u0072\u0072\u0061\u0079\u003a\u0020\u0025\u002b\u0076",_dcgb );for _ ,_bea :=range _dcgb .Elements (){switch _dcf :=_bea .(type ){case *_dc .PdfObjectString :if _dcf !=nil {_aba .ProcTj (_dcf .Bytes (),_eg );};case *_dc .PdfObjectFloat ,*_dc .PdfObjectInteger :_bcb ,_bca :=_dc .GetNumberAsFloat (_dcf );if _bca ==nil {_aba .Translate (-_bcb *0.001*_aba .Tf .Size ,0);};};};case "\u0054\u0066":if len (_ga .Params )!=2{return _cba ;};_df .Log .Debug ("\u0025\u0023\u0076",_ga .Params );_gacc ,_geaa :=_dc .GetName (_ga .Params [0]);if !_geaa ||_gacc ==nil {_df .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",_ga .Params [0]);return _gc ;};_df .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u006e\u0061\u006d\u0065\u003a\u0020\u0025\u0073",_gacc .String ());_egg ,_abg :=_dc .GetNumberAsFloat (_ga .Params [1]);if _abg !=nil {_df .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",_ga .Params [1]);return _gc ;};_df .Log .Debug ("\u0046\u006f\u006e\u0074\u0020\u0073\u0069\u007a\u0065\u003a\u0020\u0025\u0076",_egg );_gbb ,_cag :=_eag .GetFontByName (*_gacc );if !_cag {_df .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0046\u006f\u006e\u0074\u0020\u0025s\u0020\u006e\u006f\u0074\u0020\u0066\u006f\u0075\u006e\u0064",_gacc .String ());return _f .New ("\u0066\u006f\u006e\u0074\u0020\u006e\u006f\u0074\u0020f\u006f\u0075\u006e\u0064");};_df .Log .Debug ("\u0046\u006f\u006e\u0074\u003a\u0020\u0025\u0054",_gbb );_dec ,_geaa :=_dc .GetDict (_gbb );if !_geaa {_df .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 _gc ;};_facd ,_abg :=_ad .NewPdfFontFromPdfObject (_dec );if _abg !=nil {_df .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 _abg ;};_bee :=_facd .BaseFont ();if _bee ==""{_bee =_gacc .String ();};_bgb ,_geaa :=_cd [_bee ];if !_geaa {_bgb ,_abg =_da .NewTextFont (_facd ,_egg );if _abg !=nil {_df .Log .Debug ("\u0045R\u0052\u004f\u0052\u003a\u0020\u0025v",_abg );};};if _bgb ==nil {if len (_bee )> 7&&_bee [6]=='+'{_bee =_bee [7:];};_caf :=[]string {_bee ,"\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 _ ,_fca :=range _caf {_df .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",_fca );if _bgb ,_geaa =_cd [_fca ];_geaa {break ;};_ggc :=_bcg .Match (_fca );if _ggc ==nil {_df .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",_fca );continue ;};_bgb ,_abg =_da .NewTextFontFromPath (_ggc .Filename ,_egg );if _abg !=nil {_df .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",_ggc .Filename );continue ;};_df .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",_bee ,_ggc .Name ,_ggc .Filename );_cd [_fca ]=_bgb ;break ;};};if _bgb ==nil {_df .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 _f .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");};_aba .ProcTf (_bgb .WithSize (_egg ,_facd ));case "\u0042\u004d\u0043","\u0042\u0044\u0043":case "\u0045\u004d\u0043":default:_df .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",_ga .Operand );};return nil ;});_gd =_fed .Process (_efe );if _gd !=nil {return _gd ;};return nil ;};
// Render converts the specified PDF page into an image and returns the result.
func (_fg *ImageDevice )Render (page *_ad .PdfPage )(_c .Image ,error ){_gg ,_aae :=page .GetMediaBox ();if _aae !=nil {return nil ,_aae ;};_adc ,_eb :=_gg .Llx +_gg .Width (),_gg .Lly +_gg .Height ();_ee :=_ca .NewContext (int (_adc ),int (_eb ));if _bf :=_fg .renderPage (_ee ,page );_bf !=nil {return nil ,_bf ;};_fea :=_ee .Image ();if _ge :=page .CropBox ;_ge !=nil {_dcg :=_c .Rect (0,0,int (_ge .Width ()),int (_ge .Height ()));_dcc :=_c .Pt (int (_ge .Llx ),int (_eb -_ge .Ury ));_cg :=_c .NewRGBA (_dcg );_aa .Draw (_cg ,_dcg ,_fea ,_dcc ,_aa .Src );_fea =_cg ;};return _fea ,nil ;};var (_gc =_f .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");_cba =_f .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072"););type renderer struct{};func _ff (_geb string ,_cb _c .Image ,_cgd int )error {_ba ,_cae :=_fe .Create (_geb );if _cae !=nil {return _cae ;};defer _ba .Close ();return _d .Encode (_ba ,_cb ,&_d .Options {Quality :_cgd });};func (_ab renderer )renderPage (_cbd _da .Context ,_bb *_ad .PdfPage )error {_ea ,_ebd :=_bb .GetAllContentStreams ();if _ebd !=nil {return _ebd ;};_cbd .Translate (0,float64 (_cbd .Height ()));_cbd .Scale (1,-1);_cbd .Push ();_cbd .SetRGBA (1,1,1,1);_cbd .DrawRectangle (0,0,float64 (_cbd .Width ()),float64 (_cbd .Height ()));_cbd .Fill ();_cbd .Pop ();_cbd .SetLineWidth (1.0);_cbd .SetRGBA (0,0,0,1);return _ab .renderContentStream (_cbd ,_ea ,_bb .Resources );};
// NewImageDevice returns a new image device.
func NewImageDevice ()*ImageDevice {return &ImageDevice {}};