2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// 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 contentstream provides functionality for parsing and creating content streams for PDF files.
|
|
|
|
//
|
|
|
|
// For processing and manipulating content streams, it allows parse the content stream into a list of
|
|
|
|
// operands that can then be processed further for rendering or extraction of information.
|
|
|
|
// The ContentStreamProcessor offers a basic engine for processing the content stream and can be used
|
|
|
|
// to render or modify the contents.
|
|
|
|
//
|
|
|
|
// For creating content streams, see NewContentCreator. It allows adding multiple operands and then can
|
|
|
|
// be converted to a string for embedding in a PDF file.
|
|
|
|
//
|
|
|
|
// The contentstream package uses the core and model packages.
|
2020-08-31 21:12:07 +00:00
|
|
|
package contentstream ;import (_dd "bufio";_f "bytes";_gf "encoding/hex";_g "errors";_e "fmt";_bgc "github.com/unidoc/unipdf/v3/common";_ga "github.com/unidoc/unipdf/v3/core";_fc "github.com/unidoc/unipdf/v3/internal/imageutil";_db "github.com/unidoc/unipdf/v3/internal/transform";_ea "github.com/unidoc/unipdf/v3/model";_c "image/color";_dg "image/jpeg";_ddb "io";_bg "math";_d "strconv";);func (_dbgd *ContentStreamProcessor )handleCommand_RG (_bab *ContentStreamOperation ,_aed *_ea .PdfPageResources )error {_gfab :=_ea .NewPdfColorspaceDeviceRGB ();if len (_bab .Params )!=_gfab .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020R\u0047");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_bab .Params ),_gfab );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_ecgf ,_bgff :=_gfab .ColorFromPdfObjects (_bab .Params );if _bgff !=nil {return _bgff ;};_dbgd ._bgba .ColorspaceStroking =_gfab ;_dbgd ._bgba .ColorStroking =_ecgf ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Bytes converts the content stream operations to a content stream byte presentation, i.e. the kind that can be
|
|
|
|
// stored as a PDF stream or string format.
|
|
|
|
func (_dab *ContentCreator )Bytes ()[]byte {return _dab ._da .Bytes ()};func (_ffff *ContentStreamProcessor )handleCommand_CS (_gafe *ContentStreamOperation ,_fgf *_ea .PdfPageResources )error {if len (_gafe .Params )< 1{_bgc .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069d\u0020\u0063\u0073\u0020\u0063\u006f\u006d\u006d\u0061\u006e\u0064\u002c\u0020s\u006b\u0069\u0070\u0070\u0069\u006e\u0067 \u006f\u0076\u0065\u0072");return _g .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_gafe .Params )> 1{_bgc .Log .Debug ("\u0063\u0073\u0020\u0063\u006f\u006d\u006d\u0061n\u0064\u0020\u0077it\u0068\u0020\u0074\u006f\u006f\u0020m\u0061\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020-\u0020\u0063\u006f\u006e\u0074\u0069\u006e\u0075i\u006e\u0067");return _g .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_cgb ,_daag :=_gafe .Params [0].(*_ga .PdfObjectName );if !_daag {_bgc .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020c\u0073\u0020\u0063o\u006d\u006d\u0061n\u0064\u0020w\u0069\u0074\u0068\u0020\u0069\u006ev\u0061li\u0064\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u002c\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067\u0020\u006f\u0076\u0065\u0072");return _g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_cca ,_feca :=_ffff .getColorspace (string (*_cgb ),_fgf );if _feca !=nil {return _feca ;};_ffff ._bgba .ColorspaceStroking =_cca ;_cag ,_feca :=_ffff .getInitialColor (_cca );if _feca !=nil {return _feca ;};_ffff ._bgba .ColorStroking =_cag ;return nil ;};
|
2017-03-01 16:02:53 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// SetStrokingColor sets the stroking `color` where color can be one of
|
|
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
|
|
func (_cec *ContentCreator )SetStrokingColor (color _ea .PdfColor )*ContentCreator {switch _debe :=color .(type ){case *_ea .PdfColorDeviceGray :_cec .Add_G (_debe .Val ());case *_ea .PdfColorDeviceRGB :_cec .Add_RG (_debe .R (),_debe .G (),_debe .B ());case *_ea .PdfColorDeviceCMYK :_cec .Add_K (_debe .C (),_debe .M (),_debe .Y (),_debe .K ());default:_bgc .Log .Debug ("\u0053\u0065\u0074\u0053\u0074\u0072\u006f\u006b\u0069\u006e\u0067\u0043\u006fl\u006f\u0072\u003a\u0020\u0075\u006es\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006fr\u003a\u0020\u0025\u0054",_debe );};return _cec ;};
|
2017-03-01 16:02:53 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Operations returns the list of operations.
|
|
|
|
func (_fg *ContentCreator )Operations ()*ContentStreamOperations {return &_fg ._da };
|
2017-03-01 16:02:53 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ContentStreamInlineImage is a representation of an inline image in a Content stream. Everything between the BI and EI operands.
|
|
|
|
// ContentStreamInlineImage implements the core.PdfObject interface although strictly it is not a PDF object.
|
|
|
|
type ContentStreamInlineImage struct{BitsPerComponent _ga .PdfObject ;ColorSpace _ga .PdfObject ;Decode _ga .PdfObject ;DecodeParms _ga .PdfObject ;Filter _ga .PdfObject ;Height _ga .PdfObject ;ImageMask _ga .PdfObject ;Intent _ga .PdfObject ;Interpolate _ga .PdfObject ;Width _ga .PdfObject ;_bfg []byte ;_gdb *_fc .ImageBase ;};var _ead =map[string ]struct{}{"\u0062":struct{}{},"\u0042":struct{}{},"\u0062\u002a":struct{}{},"\u0042\u002a":struct{}{},"\u0042\u0044\u0043":struct{}{},"\u0042\u0049":struct{}{},"\u0042\u004d\u0043":struct{}{},"\u0042\u0054":struct{}{},"\u0042\u0058":struct{}{},"\u0063":struct{}{},"\u0063\u006d":struct{}{},"\u0043\u0053":struct{}{},"\u0063\u0073":struct{}{},"\u0064":struct{}{},"\u0064\u0030":struct{}{},"\u0064\u0031":struct{}{},"\u0044\u006f":struct{}{},"\u0044\u0050":struct{}{},"\u0045\u0049":struct{}{},"\u0045\u004d\u0043":struct{}{},"\u0045\u0054":struct{}{},"\u0045\u0058":struct{}{},"\u0066":struct{}{},"\u0046":struct{}{},"\u0066\u002a":struct{}{},"\u0047":struct{}{},"\u0067":struct{}{},"\u0067\u0073":struct{}{},"\u0068":struct{}{},"\u0069":struct{}{},"\u0049\u0044":struct{}{},"\u006a":struct{}{},"\u004a":struct{}{},"\u004b":struct{}{},"\u006b":struct{}{},"\u006c":struct{}{},"\u006d":struct{}{},"\u004d":struct{}{},"\u004d\u0050":struct{}{},"\u006e":struct{}{},"\u0071":struct{}{},"\u0051":struct{}{},"\u0072\u0065":struct{}{},"\u0052\u0047":struct{}{},"\u0072\u0067":struct{}{},"\u0072\u0069":struct{}{},"\u0073":struct{}{},"\u0053":struct{}{},"\u0053\u0043":struct{}{},"\u0073\u0063":struct{}{},"\u0053\u0043\u004e":struct{}{},"\u0073\u0063\u006e":struct{}{},"\u0073\u0068":struct{}{},"\u0054\u002a":struct{}{},"\u0054\u0063":struct{}{},"\u0054\u0064":struct{}{},"\u0054\u0044":struct{}{},"\u0054\u0066":struct{}{},"\u0054\u006a":struct{}{},"\u0054\u004a":struct{}{},"\u0054\u004c":struct{}{},"\u0054\u006d":struct{}{},"\u0054\u0072":struct{}{},"\u0054\u0073":struct{}{},"\u0054\u0077":struct{}{},"\u0054\u007a":struct{}{},"\u0076":struct{}{},"\u0077":struct{}{},"\u0057":struct{}{},"\u0057\u002a":struct{}{},"\u0079":struct{}{},"\u0027":struct{}{},"\u0022":struct{}{}};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// HandlerFunc is the function syntax that the ContentStreamProcessor handler must implement.
|
|
|
|
type HandlerFunc func (_gccf *ContentStreamOperation ,_fdad GraphicsState ,_bbc *_ea .PdfPageResources )error ;
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_d adds 'd' operand to the content stream: Set the line dash pattern.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_gg *ContentCreator )Add_d (dashArray []int64 ,dashPhase int64 )*ContentCreator {_adf :=ContentStreamOperation {};_adf .Operand ="\u0064";_adf .Params =[]_ga .PdfObject {};_adf .Params =append (_adf .Params ,_ga .MakeArrayFromIntegers64 (dashArray ));_adf .Params =append (_adf .Params ,_ga .MakeInteger (dashPhase ));_gg ._da =append (_gg ._da ,&_adf );return _gg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_y appends 'y' operand to the content stream: Append a Bezier curve to the current path from the
|
|
|
|
// current point to (x3,y3) with (x1, y1) and (x3,y3) as control points.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
|
|
func (_geb *ContentCreator )Add_y (x1 ,y1 ,x3 ,y3 float64 )*ContentCreator {_def :=ContentStreamOperation {};_def .Operand ="\u0079";_def .Params =_gegg ([]float64 {x1 ,y1 ,x3 ,y3 });_geb ._da =append (_geb ._da ,&_def );return _geb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
|
|
|
// Add_i adds 'i' operand to the content stream: Set the flatness tolerance in the graphics state.
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_ade *ContentCreator )Add_i (flatness float64 )*ContentCreator {_eebb :=ContentStreamOperation {};_eebb .Operand ="\u0069";_eebb .Params =_gegg ([]float64 {flatness });_ade ._da =append (_ade ._da ,&_eebb );return _ade ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_TJ appends 'TJ' operand to the content stream:
|
|
|
|
// Show one or more text string. Array of numbers (displacement) and strings.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
|
|
|
func (_dcd *ContentCreator )Add_TJ (vals ..._ga .PdfObject )*ContentCreator {_bgf :=ContentStreamOperation {};_bgf .Operand ="\u0054\u004a";_bgf .Params =[]_ga .PdfObject {_ga .MakeArray (vals ...)};_dcd ._da =append (_dcd ._da ,&_bgf );return _dcd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_b_starred appends 'b*' operand to the content stream:
|
|
|
|
// Close, fill and then stroke the path (even-odd winding number rule).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
|
|
func (_ccb *ContentCreator )Add_b_starred ()*ContentCreator {_fgd :=ContentStreamOperation {};_fgd .Operand ="\u0062\u002a";_ccb ._da =append (_ccb ._da ,&_fgd );return _ccb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// NewContentCreator returns a new initialized ContentCreator.
|
|
|
|
func NewContentCreator ()*ContentCreator {_eeb :=&ContentCreator {};_eeb ._da =ContentStreamOperations {};return _eeb ;};func _bed (_baa string )bool {_ ,_baeb :=_ead [_baa ];return _baeb };
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Translate applies a simple x-y translation to the transformation matrix.
|
|
|
|
func (_gfdf *ContentCreator )Translate (tx ,ty float64 )*ContentCreator {return _gfdf .Add_cm (1,0,0,1,tx ,ty );};const (HandlerConditionEnumOperand HandlerConditionEnum =iota ;HandlerConditionEnumAllOperands ;);
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_f_starred appends 'f*' operand to the content stream.
|
|
|
|
// f*: Fill the path using the even-odd rule to determine fill region.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
|
|
func (_cff *ContentCreator )Add_f_starred ()*ContentCreator {_aec :=ContentStreamOperation {};_aec .Operand ="\u0066\u002a";_cff ._da =append (_cff ._da ,&_aec );return _cff ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_re appends 're' operand to the content stream:
|
|
|
|
// Append a rectangle to the current path as a complete subpath, with lower left corner (x,y).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
|
|
func (_deff *ContentCreator )Add_re (x ,y ,width ,height float64 )*ContentCreator {_gce :=ContentStreamOperation {};_gce .Operand ="\u0072\u0065";_gce .Params =_gegg ([]float64 {x ,y ,width ,height });_deff ._da =append (_deff ._da ,&_gce );return _deff ;};func (_edbe *ContentStreamProcessor )handleCommand_cm (_bdcca *ContentStreamOperation ,_dfdge *_ea .PdfPageResources )error {if len (_bdcca .Params )!=6{_bgc .Log .Debug ("\u0045\u0052R\u004f\u0052\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020\u006f\u0066\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020\u0063\u006d\u003a\u0020\u0025\u0064",len (_bdcca .Params ));return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_agaf ,_ffaf :=_ga .GetNumbersAsFloat (_bdcca .Params );if _ffaf !=nil {return _ffaf ;};_gebe :=_db .NewMatrix (_agaf [0],_agaf [1],_agaf [2],_agaf [3],_agaf [4],_agaf [5]);_edbe ._bgba .CTM .Concat (_gebe );return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_ET appends 'ET' operand to the content stream:
|
|
|
|
// End text.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
|
|
|
|
func (_gge *ContentCreator )Add_ET ()*ContentCreator {_dbbf :=ContentStreamOperation {};_dbbf .Operand ="\u0045\u0054";_gge ._da =append (_gge ._da ,&_dbbf );return _gge ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Do adds 'Do' operation to the content stream:
|
|
|
|
// Displays an XObject (image or form) specified by `name`.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.8 "External Objects" and Table 87 (pp. 209-220 PDF32000_2008).
|
|
|
|
func (_gee *ContentCreator )Add_Do (name _ga .PdfObjectName )*ContentCreator {_eab :=ContentStreamOperation {};_eab .Operand ="\u0044\u006f";_eab .Params =_dfef ([]_ga .PdfObjectName {name });_gee ._da =append (_gee ._da ,&_eab );return _gee ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_j adds 'j' operand to the content stream: Set the line join style (graphics state).
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_fd *ContentCreator )Add_j (lineJoinStyle string )*ContentCreator {_fde :=ContentStreamOperation {};_fde .Operand ="\u006a";_fde .Params =_dfef ([]_ga .PdfObjectName {_ga .PdfObjectName (lineJoinStyle )});_fd ._da =append (_fd ._da ,&_fde );return _fd ;};func (_edd *ContentStreamProcessor )handleCommand_sc (_eaad *ContentStreamOperation ,_fbd *_ea .PdfPageResources )error {_bff :=_edd ._bgba .ColorspaceNonStroking ;if !_eabc (_bff ){if len (_eaad .Params )!=_bff .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_eaad .Params ),_bff );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_gcgg ,_egcg :=_bff .ColorFromPdfObjects (_eaad .Params );if _egcg !=nil {return _egcg ;};_edd ._bgba .ColorNonStroking =_gcgg ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_K appends 'K' operand to the content stream:
|
|
|
|
// Set the stroking colorspace to DeviceCMYK and sets the c,m,y,k color (0-1 each component).
|
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_fcgd *ContentCreator )Add_K (c ,m ,y ,k float64 )*ContentCreator {_gdf :=ContentStreamOperation {};_gdf .Operand ="\u004b";_gdf .Params =_gegg ([]float64 {c ,m ,y ,k });_fcgd ._da =append (_fcgd ._da ,&_gdf );return _fcgd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tm appends 'Tm' operand to the content stream:
|
|
|
|
// Set the text line matrix.
|
|
|
|
//
|
|
|
|
// See section 9.4.2 "Text Positioning Operators" and
|
|
|
|
// Table 108 (pp. 257-258 PDF32000_2008).
|
|
|
|
func (_ceca *ContentCreator )Add_Tm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_gca :=ContentStreamOperation {};_gca .Operand ="\u0054\u006d";_gca .Params =_gegg ([]float64 {a ,b ,c ,d ,e ,f });_ceca ._da =append (_ceca ._da ,&_gca );return _ceca ;};type handlerEntry struct{Condition HandlerConditionEnum ;Operand string ;Handler HandlerFunc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Ts appends 'Ts' operand to the content stream:
|
|
|
|
// Set text rise.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_ddd *ContentCreator )Add_Ts (rise float64 )*ContentCreator {_gde :=ContentStreamOperation {};_gde .Operand ="\u0054\u0073";_gde .Params =_gegg ([]float64 {rise });_ddd ._da =append (_ddd ._da ,&_gde );return _ddd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_rg appends 'rg' operand to the content stream:
|
|
|
|
// Same as RG but used for nonstroking operations.
|
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_aga *ContentCreator )Add_rg (r ,g ,b float64 )*ContentCreator {_bca :=ContentStreamOperation {};_bca .Operand ="\u0072\u0067";_bca .Params =_gegg ([]float64 {r ,g ,b });_aga ._da =append (_aga ._da ,&_bca );return _aga ;};
|
2017-03-01 16:02:53 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ContentStreamOperation represents an operation in PDF contentstream which consists of
|
|
|
|
// an operand and parameters.
|
|
|
|
type ContentStreamOperation struct{Params []_ga .PdfObject ;Operand string ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_cs appends 'cs' operand to the content stream:
|
|
|
|
// Same as CS but for non-stroking operations.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_acc *ContentCreator )Add_cs (name _ga .PdfObjectName )*ContentCreator {_bef :=ContentStreamOperation {};_bef .Operand ="\u0063\u0073";_bef .Params =_dfef ([]_ga .PdfObjectName {name });_acc ._da =append (_acc ._da ,&_bef );return _acc ;};func _gbbe (_cbeg []int64 )[]_ga .PdfObject {var _edg []_ga .PdfObject ;for _ ,_ecgfg :=range _cbeg {_edg =append (_edg ,_ga .MakeInteger (_ecgfg ));};return _edg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_J adds 'J' operand to the content stream: Set the line cap style (graphics state).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_cdc *ContentCreator )Add_J (lineCapStyle string )*ContentCreator {_deb :=ContentStreamOperation {};_deb .Operand ="\u004a";_deb .Params =_dfef ([]_ga .PdfObjectName {_ga .PdfObjectName (lineCapStyle )});_cdc ._da =append (_cdc ._da ,&_deb );return _cdc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// GraphicsState is a basic graphics state implementation for PDF processing.
|
|
|
|
// Initially only implementing and tracking a portion of the information specified. Easy to add more.
|
|
|
|
type GraphicsState struct{ColorspaceStroking _ea .PdfColorspace ;ColorspaceNonStroking _ea .PdfColorspace ;ColorStroking _ea .PdfColor ;ColorNonStroking _ea .PdfColor ;CTM _db .Matrix ;};
|
|
|
|
|
|
|
|
// Add_f appends 'f' operand to the content stream:
|
|
|
|
// Fill the path using the nonzero winding number rule to determine fill region.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
|
|
func (_af *ContentCreator )Add_f ()*ContentCreator {_bag :=ContentStreamOperation {};_bag .Operand ="\u0066";_af ._da =append (_af ._da ,&_bag );return _af ;};
|
|
|
|
|
|
|
|
// AddOperand adds a specified operand.
|
|
|
|
func (_be *ContentCreator )AddOperand (op ContentStreamOperation )*ContentCreator {_be ._da =append (_be ._da ,&op );return _be ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
|
|
|
// Add_scn appends 'scn' operand to the content stream:
|
|
|
|
// Same as SC but for nonstroking operations.
|
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_edc *ContentCreator )Add_scn (c ...float64 )*ContentCreator {_baga :=ContentStreamOperation {};_baga .Operand ="\u0073\u0063\u006e";_baga .Params =_gegg (c );_edc ._da =append (_edc ._da ,&_baga );return _edc ;};func (_gcc *ContentStreamParser )parseString ()(*_ga .PdfObjectString ,error ){_gcc ._bdec .ReadByte ();var _cgec []byte ;_fba :=1;for {_gfc ,_cfca :=_gcc ._bdec .Peek (1);if _cfca !=nil {return _ga .MakeString (string (_cgec )),_cfca ;};if _gfc [0]=='\\'{_gcc ._bdec .ReadByte ();_ebf ,_dfg :=_gcc ._bdec .ReadByte ();if _dfg !=nil {return _ga .MakeString (string (_cgec )),_dfg ;};if _ga .IsOctalDigit (_ebf ){_bac ,_faag :=_gcc ._bdec .Peek (2);if _faag !=nil {return _ga .MakeString (string (_cgec )),_faag ;};var _bacg []byte ;_bacg =append (_bacg ,_ebf );for _ ,_dgdd :=range _bac {if _ga .IsOctalDigit (_dgdd ){_bacg =append (_bacg ,_dgdd );}else {break ;};};_gcc ._bdec .Discard (len (_bacg )-1);_bgc .Log .Trace ("\u004e\u0075\u006d\u0065ri\u0063\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u0020\u0022\u0025\u0073\u0022",_bacg );_abed ,_faag :=_d .ParseUint (string (_bacg ),8,32);if _faag !=nil {return _ga .MakeString (string (_cgec )),_faag ;};_cgec =append (_cgec ,byte (_abed ));continue ;};switch _ebf {case 'n':_cgec =append (_cgec ,'\n');case 'r':_cgec =append (_cgec ,'\r');case 't':_cgec =append (_cgec ,'\t');case 'b':_cgec =append (_cgec ,'\b');case 'f':_cgec =append (_cgec ,'\f');case '(':_cgec =append (_cgec ,'(');case ')':_cgec =append (_cgec ,')');case '\\':_cgec =append (_cgec ,'\\');};continue ;}else if _gfc [0]=='('{_fba ++;}else if _gfc [0]==')'{_fba --;if _fba ==0{_gcc ._bdec .ReadByte ();break ;};};_caee ,_ :=_gcc ._bdec .ReadByte ();_cgec =append (_cgec ,_caee );};return _ga .MakeString (string (_cgec )),nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_M adds 'M' operand to the content stream: Set the miter limit (graphics state).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_fcaf *ContentCreator )Add_M (miterlimit float64 )*ContentCreator {_deg :=ContentStreamOperation {};_deg .Operand ="\u004d";_deg .Params =_gegg ([]float64 {miterlimit });_fcaf ._da =append (_fcaf ._da ,&_deg );return _fcaf ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
|
|
|
// GraphicStateStack represents a stack of GraphicsState.
|
|
|
|
type GraphicStateStack []GraphicsState ;
|
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_l adds 'l' operand to the content stream:
|
|
|
|
// Append a straight line segment from the current point to (x,y).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
|
|
func (_gaf *ContentCreator )Add_l (x ,y float64 )*ContentCreator {_edb :=ContentStreamOperation {};_edb .Operand ="\u006c";_edb .Params =_gegg ([]float64 {x ,y });_gaf ._da =append (_gaf ._da ,&_edb );return _gaf ;};func _bgd (_ecbe *ContentStreamInlineImage )(_ga .StreamEncoder ,error ){if _ecbe .Filter ==nil {return _ga .NewRawEncoder (),nil ;};_cdd ,_cdbc :=_ecbe .Filter .(*_ga .PdfObjectName );if !_cdbc {_aeg ,_gede :=_ecbe .Filter .(*_ga .PdfObjectArray );if !_gede {return nil ,_e .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072 \u006e\u006f\u0074\u0020\u0061\u0020\u004e\u0061\u006d\u0065\u0020\u006f\u0072 \u0041\u0072\u0072\u0061\u0079\u0020\u006fb\u006a\u0065\u0063\u0074");};if _aeg .Len ()==0{return _ga .NewRawEncoder (),nil ;};if _aeg .Len ()!=1{_fgdc ,_bfc :=_dffe (_ecbe );if _bfc !=nil {_bgc .Log .Error ("\u0046\u0061\u0069\u006c\u0065\u0064 \u0063\u0072\u0065\u0061\u0074\u0069\u006e\u0067\u0020\u006d\u0075\u006c\u0074i\u0020\u0065\u006e\u0063\u006f\u0064\u0065r\u003a\u0020\u0025\u0076",_bfc );return nil ,_bfc ;};_bgc .Log .Trace ("\u004d\u0075\u006c\u0074\u0069\u0020\u0065\u006e\u0063:\u0020\u0025\u0073\u000a",_fgdc );return _fgdc ,nil ;};_efcd :=_aeg .Get (0);_cdd ,_gede =_efcd .(*_ga .PdfObjectName );if !_gede {return nil ,_e .Errorf ("\u0066\u0069l\u0074\u0065\u0072\u0020a\u0072\u0072a\u0079\u0020\u006d\u0065\u006d\u0062\u0065\u0072 \u006e\u006f\u0074\u0020\u0061\u0020\u004e\u0061\u006d\u0065\u0020\u006fb\u006a\u0065\u0063\u0074");};};switch *_cdd {case "\u0041\u0048\u0078","\u0041\u0053\u0043\u0049\u0049\u0048\u0065\u0078\u0044e\u0063\u006f\u0064\u0065":return _ga .NewASCIIHexEncoder (),nil ;case "\u0041\u0038\u0035","\u0041\u0053\u0043\u0049\u0049\u0038\u0035\u0044\u0065\u0063\u006f\u0064\u0065":return _ga .NewASCII85Encoder (),nil ;case "\u0044\u0043\u0054","\u0044C\u0054\u0044\u0065\u0063\u006f\u0064e":return _dcg (_ecbe );case "\u0046\u006c","F\u006c\u0061\u0074\u0065\u0044\u0065\u0063\u006f\u0064\u0065":return _bce (_ecbe ,nil );case "\u004c\u005a\u0057","\u004cZ\u0057\u0044\u0065\u0063\u006f\u0064e":return _dde (_ecbe ,nil );case "\u0043\u0043\u0046","\u0043\u0043\u0049\u0054\u0054\u0046\u0061\u0078\u0044e\u0063\u006f\u0064\u0065":return _ga .NewCCITTFaxEncoder (),nil ;case "\u0052\u004c","\u0052u\u006eL\u0065\u006e\u0067\u0074\u0068\u0044\u0065\u0063\u006f\u0064\u0065":return _ga .NewRunLengthEncoder (),nil ;default:_bgc .Log .Debug ("\u0055\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065 \u0069\u006d\u0061\u0067\u0065\u0020\u0065n\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0074e\u0072\u0020\u006e\u0061\u006d\u0065\u0020\u003a\u0020\u0025\u0073",*_cdd );return nil ,_g .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006el\u0069n\u0065 \u0065n\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u006d\u0065\u0074\u0068\u006f\u0064");};};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_SCN_pattern appends 'SCN' operand to the content stream for pattern `name`:
|
|
|
|
// SCN with name attribute (for pattern). Syntax: c1 ... cn name SCN.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_bgg *ContentCreator )Add_SCN_pattern (name _ga .PdfObjectName ,c ...float64 )*ContentCreator {_ag :=ContentStreamOperation {};_ag .Operand ="\u0053\u0043\u004e";_ag .Params =_gegg (c );_ag .Params =append (_ag .Params ,_ga .MakeName (string (name )));_bgg ._da =append (_bgg ._da ,&_ag );return _bgg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_TD appends 'TD' operand to the content stream:
|
2020-08-27 21:45:09 +00:00
|
|
|
// Move to start of next line with offset (`tx`, `ty`).
|
|
|
|
//
|
|
|
|
// See section 9.4.2 "Text Positioning Operators" and
|
|
|
|
// Table 108 (pp. 257-258 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_ffe *ContentCreator )Add_TD (tx ,ty float64 )*ContentCreator {_aeb :=ContentStreamOperation {};_aeb .Operand ="\u0054\u0044";_aeb .Params =_gegg ([]float64 {tx ,ty });_ffe ._da =append (_ffe ._da ,&_aeb );return _ffe ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ContentCreator is a builder for PDF content streams.
|
|
|
|
type ContentCreator struct{_da ContentStreamOperations };func (_bcec *ContentStreamProcessor )handleCommand_k (_bgag *ContentStreamOperation ,_dfa *_ea .PdfPageResources )error {_agd :=_ea .NewPdfColorspaceDeviceCMYK ();if len (_bgag .Params )!=_agd .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_bgag .Params ),_agd );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_babd ,_dcfa :=_agd .ColorFromPdfObjects (_bgag .Params );if _dcfa !=nil {return _dcfa ;};_bcec ._bgba .ColorspaceNonStroking =_agd ;_bcec ._bgba .ColorNonStroking =_babd ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_B_starred appends 'B*' operand to the content stream:
|
|
|
|
// Fill and then stroke the path (even-odd rule).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
|
|
func (_fbb *ContentCreator )Add_B_starred ()*ContentCreator {_cbg :=ContentStreamOperation {};_cbg .Operand ="\u0042\u002a";_fbb ._da =append (_fbb ._da ,&_cbg );return _fbb ;};func (_ccdc *ContentStreamParser )parseHexString ()(*_ga .PdfObjectString ,error ){_ccdc ._bdec .ReadByte ();_aagf :=[]byte ("\u0030\u0031\u0032\u003345\u0036\u0037\u0038\u0039\u0061\u0062\u0063\u0064\u0065\u0066\u0041\u0042\u0043\u0044E\u0046");var _fcgg []byte ;for {_ccdc .skipSpaces ();_efcg ,_bfge :=_ccdc ._bdec .Peek (1);if _bfge !=nil {return _ga .MakeString (""),_bfge ;};if _efcg [0]=='>'{_ccdc ._bdec .ReadByte ();break ;};_gbba ,_ :=_ccdc ._bdec .ReadByte ();if _f .IndexByte (_aagf ,_gbba )>=0{_fcgg =append (_fcgg ,_gbba );};};if len (_fcgg )%2==1{_fcgg =append (_fcgg ,'0');};_ddga ,_ :=_gf .DecodeString (string (_fcgg ));return _ga .MakeHexString (string (_ddga )),nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_h appends 'h' operand to the content stream:
|
|
|
|
// Close the current subpath by adding a line between the current position and the starting position.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
|
|
func (_cde *ContentCreator )Add_h ()*ContentCreator {_eca :=ContentStreamOperation {};_eca .Operand ="\u0068";_cde ._da =append (_cde ._da ,&_eca );return _cde ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Parse parses all commands in content stream, returning a list of operation data.
|
|
|
|
func (_egce *ContentStreamParser )Parse ()(*ContentStreamOperations ,error ){_fcf :=ContentStreamOperations {};for {_gfgff :=ContentStreamOperation {};for {_ddgc ,_abb ,_eabd :=_egce .parseObject ();if _eabd !=nil {if _eabd ==_ddb .EOF {return &_fcf ,nil ;};return &_fcf ,_eabd ;};if _abb {_gfgff .Operand ,_ =_ga .GetStringVal (_ddgc );_fcf =append (_fcf ,&_gfgff );break ;}else {_gfgff .Params =append (_gfgff .Params ,_ddgc );};};if _gfgff .Operand =="\u0042\u0049"{_dgda ,_fdaf :=_egce .ParseInlineImage ();if _fdaf !=nil {return &_fcf ,_fdaf ;};_gfgff .Params =append (_gfgff .Params ,_dgda );};};};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// GetEncoder returns the encoder of the inline image.
|
|
|
|
func (_fadb *ContentStreamInlineImage )GetEncoder ()(_ga .StreamEncoder ,error ){return _bgd (_fadb )};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_quote appends "'" operand to the content stream:
|
|
|
|
// Move to next line and show a string.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_eaf *ContentCreator )Add_quote (textstr _ga .PdfObjectString )*ContentCreator {_adfb :=ContentStreamOperation {};_adfb .Operand ="\u0027";_adfb .Params =_fabc ([]_ga .PdfObjectString {textstr });_eaf ._da =append (_eaf ._da ,&_adfb );return _eaf ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// RotateDeg applies a rotation to the transformation matrix.
|
|
|
|
func (_add *ContentCreator )RotateDeg (angle float64 )*ContentCreator {_ecb :=_bg .Cos (angle *_bg .Pi /180.0);_cd :=_bg .Sin (angle *_bg .Pi /180.0);_dbb :=-_bg .Sin (angle *_bg .Pi /180.0);_fcad :=_bg .Cos (angle *_bg .Pi /180.0);return _add .Add_cm (_ecb ,_cd ,_dbb ,_fcad ,0,0);};func _dffe (_cba *ContentStreamInlineImage )(*_ga .MultiEncoder ,error ){_ecag :=_ga .NewMultiEncoder ();var _ddg *_ga .PdfObjectDictionary ;var _acg []_ga .PdfObject ;if _aef :=_cba .DecodeParms ;_aef !=nil {_cbfc ,_abec :=_aef .(*_ga .PdfObjectDictionary );if _abec {_ddg =_cbfc ;};_ega ,_ceg :=_aef .(*_ga .PdfObjectArray );if _ceg {for _ ,_gbfb :=range _ega .Elements (){if _gaa ,_afg :=_gbfb .(*_ga .PdfObjectDictionary );_afg {_acg =append (_acg ,_gaa );}else {_acg =append (_acg ,nil );};};};};_eb :=_cba .Filter ;if _eb ==nil {return nil ,_e .Errorf ("\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u006d\u0069s\u0073\u0069\u006e\u0067");};_ecgg ,_ecd :=_eb .(*_ga .PdfObjectArray );if !_ecd {return nil ,_e .Errorf ("m\u0075\u006c\u0074\u0069\u0020\u0066\u0069\u006c\u0074\u0065\u0072\u0020\u0063\u0061\u006e\u0020\u006f\u006el\u0079\u0020\u0062\u0065\u0020\u006d\u0061\u0064\u0065\u0020fr\u006f\u006d\u0020a\u0072r\u0061\u0079");};for _age ,_bgbb :=range _ecgg .Elements (){_abc ,_fad :=_bgbb .(*_ga .PdfObjectName );if !_fad {return nil ,_e .Errorf ("\u006d\u0075l\u0074\u0069\u0020\u0066i\u006c\u0074e\u0072\u0020\u0061\u0072\u0072\u0061\u0079\u0020e\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u006e\u006f\u0074\u0020\u0061 \u006e\u0061\u006d\u0065");};var _cdcc _ga .PdfObject ;if _ddg !=nil {_cdcc =_ddg ;}else {if len (_acg )> 0{if _age >=len (_acg ){return nil ,_e .Errorf ("\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u0065\u006c\u0065\u006d\u0065n\u0074\u0073\u0020\u0069\u006e\u0020d\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006d\u0073\u0020a\u0072\u0072\u0061\u0079");};_cdcc =_acg [_age ];};};var _ceef *_ga .PdfObjectDictionary ;if _cge ,_bcd :=_cdcc .(*_ga .PdfObjectDictionary );_bcd {_ceef =_cge ;};if *_abc ==_ga .StreamEncodingFilterNameFlate ||*_abc =="\u0046\u006c"{_fgef ,_agea :=_bce (_cba ,_ceef );if _agea !=nil {return nil ,_agea ;};_ecag .AddEncoder (_fgef );}else if *_abc ==_ga .StreamEncodingFilterNameLZW {_cbef ,_bbec :=_dde (_cba ,_ceef );if _bbec !=nil {return nil ,_bbec ;};_ecag .AddEncoder (_cbef );}else if *_abc ==_ga .StreamEncodingFilterNameASCIIHex {_dgg :=_ga .NewASCIIHexEncoder ();_ecag .AddEncoder (_dgg );}else if *_abc ==_ga .StreamEncodingFilterNameASCII85 ||*_abc =="\u0041\u0038\u0035"{_fag :=_ga .NewASCII85Encoder ();_ecag .AddEncoder (_fag );}else {_bgc .Log .Error ("U\u006e\u0073\u0075\u0070po\u0072t\u0065\u0064\u0020\u0066\u0069l\u0074\u0065\u0072\u0020\u0025\u0073",*_abc );return nil ,_e .Errorf ("\u0069\u006eva\u006c\u0069\u0064 \u0066\u0069\u006c\u0074er \u0069n \u006d\u0075\u006c\u0074\u0069\u0020\u0066il\u0074\u0065\u0072\u0020\u0061\u0072\u0072a\u0079");};};return _ecag ,nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// GetColorSpace returns the colorspace of the inline image.
|
|
|
|
func (_efd *ContentStreamInlineImage )GetColorSpace (resources *_ea .PdfPageResources )(_ea .PdfColorspace ,error ){if _efd .ColorSpace ==nil {_bgc .Log .Debug ("\u0049\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u006e\u006f\u0074\u0020\u0068\u0061\u0076i\u006e\u0067\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u002c\u0020\u0061\u0073\u0073\u0075\u006di\u006e\u0067\u0020\u0047\u0072a\u0079");return _ea .NewPdfColorspaceDeviceGray (),nil ;};if _aag ,_aegc :=_efd .ColorSpace .(*_ga .PdfObjectArray );_aegc {return _adgb (_aag );};_dgfg ,_dca :=_efd .ColorSpace .(*_ga .PdfObjectName );if !_dca {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020I\u006e\u0076\u0061\u006c\u0069\u0064 \u006f\u0062\u006a\u0065\u0063\u0074\u0020t\u0079\u0070\u0065\u0020\u0028\u0025\u0054\u003b\u0025\u002bv\u0029",_efd .ColorSpace ,_efd .ColorSpace );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_dgfg =="\u0047"||*_dgfg =="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"{return _ea .NewPdfColorspaceDeviceGray (),nil ;}else if *_dgfg =="\u0052\u0047\u0042"||*_dgfg =="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"{return _ea .NewPdfColorspaceDeviceRGB (),nil ;}else if *_dgfg =="\u0043\u004d\u0059\u004b"||*_dgfg =="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{return _ea .NewPdfColorspaceDeviceCMYK (),nil ;}else if *_dgfg =="\u0049"||*_dgfg =="\u0049n\u0064\u0065\u0078\u0065\u0064"{return nil ,_g .New ("\u0075\u006e\u0073\u0075p\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0049\u006e\u0064e\u0078 \u0063\u006f\u006c\u006f\u0072\u0073\u0070a\u0063\u0065");}else {if resources .ColorSpace ==nil {_bgc .Log .Debug ("\u0045\u0072r\u006f\u0072\u002c\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u003a\u0020\u0025\u0073",*_dgfg );return nil ,_g .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};_abcc ,_ebe :=resources .GetColorspaceByName (*_dgfg );if !_ebe {_bgc .Log .Debug ("\u0045\u0072r\u006f\u0072\u002c\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065\u003a\u0020\u0025\u0073",*_dgfg );return nil ,_g .New ("\u0075n\u006bn\u006f\u0077\u006e\u0020\u0063o\u006c\u006fr\u0073\u0070\u0061\u0063\u0065");};return _abcc ,nil ;};};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_G appends 'G' operand to the content stream:
|
|
|
|
// Set the stroking colorspace to DeviceGray and sets the gray level (0-1).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_geee *ContentCreator )Add_G (gray float64 )*ContentCreator {_ecg :=ContentStreamOperation {};_ecg .Operand ="\u0047";_ecg .Params =_gegg ([]float64 {gray });_geee ._da =append (_geee ._da ,&_ecg );return _geee ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_gs adds 'gs' operand to the content stream: Set the graphics state.
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_ffg *ContentCreator )Add_gs (dictName _ga .PdfObjectName )*ContentCreator {_gbg :=ContentStreamOperation {};_gbg .Operand ="\u0067\u0073";_gbg .Params =_dfef ([]_ga .PdfObjectName {dictName });_ffg ._da =append (_ffg ._da ,&_gbg );return _ffg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_scn_pattern appends 'scn' operand to the content stream for pattern `name`:
|
|
|
|
// scn with name attribute (for pattern). Syntax: c1 ... cn name scn.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_ceb *ContentCreator )Add_scn_pattern (name _ga .PdfObjectName ,c ...float64 )*ContentCreator {_beb :=ContentStreamOperation {};_beb .Operand ="\u0073\u0063\u006e";_beb .Params =_gegg (c );_beb .Params =append (_beb .Params ,_ga .MakeName (string (name )));_ceb ._da =append (_ceb ._da ,&_beb );return _ceb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_W_starred appends 'W*' operand to the content stream:
|
|
|
|
// Modify the current clipping path by intersecting with the current path (even odd rule).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
|
|
|
|
func (_eccb *ContentCreator )Add_W_starred ()*ContentCreator {_bf :=ContentStreamOperation {};_bf .Operand ="\u0057\u002a";_eccb ._da =append (_eccb ._da ,&_bf );return _eccb ;};func _dfef (_dbca []_ga .PdfObjectName )[]_ga .PdfObject {var _dbcd []_ga .PdfObject ;for _ ,_adff :=range _dbca {_dbcd =append (_dbcd ,_ga .MakeName (string (_adff )));};return _dbcd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ContentStreamParser represents a content stream parser for parsing content streams in PDFs.
|
|
|
|
type ContentStreamParser struct{_bdec *_dd .Reader };
|
2017-06-28 15:13:37 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Operand returns true if `hce` is equivalent to HandlerConditionEnumOperand.
|
|
|
|
func (_bcag HandlerConditionEnum )Operand ()bool {return _bcag ==HandlerConditionEnumOperand };func _adgb (_ecfa _ga .PdfObject )(_ea .PdfColorspace ,error ){_agf ,_bffb :=_ecfa .(*_ga .PdfObjectArray );if !_bffb {_bgc .Log .Debug ("\u0045r\u0072\u006fr\u003a\u0020\u0049\u006ev\u0061\u006c\u0069d\u0020\u0069\u006e\u0064\u0065\u0078\u0065\u0064\u0020cs\u0020\u006e\u006ft\u0020\u0069n\u0020\u0061\u0072\u0072\u0061\u0079 \u0028\u0025#\u0076\u0029",_ecfa );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if _agf .Len ()!=4{_bgc .Log .Debug ("\u0045\u0072\u0072\u006f\u0072:\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061r\u0072\u0061\u0079\u002c\u0020\u006c\u0065\u006e\u0067\u0074\u0068\u0020\u0021\u003d\u0020\u0034\u0020\u0028\u0025\u0064\u0029",_agf .Len ());return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_cecg ,_bffb :=_agf .Get (0).(*_ga .PdfObjectName );if !_bffb {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072\u0072\u0061\u0079\u0020\u0066\u0069\u0072s\u0074 \u0065\u006c\u0065\u006de\u006e\u0074 \u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u0020\u0028\u0061\u0072\u0072\u0061\u0079\u003a\u0020\u0025\u0023\u0076\u0029",*_agf );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_cecg !="\u0049"&&*_cecg !="\u0049n\u0064\u0065\u0078\u0065\u0064"{_bgc .Log .Debug ("\u0045\u0072r\u006f\u0072\u003a\u0020\u0049n\u0076\u0061\u006c\u0069\u0064 \u0063\u0073\u0020\u0061\u0072\u0072\u0061\u0079\u0020\u0066\u0069\u0072\u0073\u0074\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u0021\u003d\u0020\u0049\u0020\u0028\u0067\u006f\u0074\u003a\u0020\u0025\u0076\u0029",*_cecg );return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_cecg ,_bffb =_agf .Get (1).(*_ga .PdfObjectName );if !_bffb {_bgc .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072r\u0061\u0079\u0020\u0032\u006e\u0064\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u006e\u006f\u0074\u0020\u0061\u0020\u006e\u0061\u006d\u0065\u0020\u0028\u0061\u0072\u0072a\u0079\u003a\u0020\u0025\u0023v\u0029",*_agf );return nil ,_g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};if *_cecg !="\u0047"&&*_cecg !="\u0052\u0047\u0042"&&*_cecg !="\u0043\u004d\u0059\u004b"&&*_cecg !="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079"&&*_cecg !="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B"&&*_cecg !="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b"{_bgc .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0063\u0073\u0020\u0061\u0072r\u0061\u0079\u0020\u0032\u006e\u0064\u0020\u0065\u006c\u0065\u006d\u0065\u006e\u0074\u0020\u0021\u003d\u0020\u0047\u002f\u0052\u0047\u0042\u002f\u0043\u004d\u0059\u004b\u0020\u0028g\u006f\u0074\u003a\u0020\u0025v\u0029",*_cecg );return nil ,_g .New ("\u0072\u0061\u006e\u0067\u0065\u0020\u0063\u0068\u0065\u0063\u006b\u0020e\u0072\u0072\u006f\u0072");};_fcae :="";switch *_cecg {case "\u0047","\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":_fcae ="\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079";case "\u0052\u0047\u0042","\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":_fcae ="\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B";case "\u0043\u004d\u0059\u004b","\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":_fcae ="\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b";};_ebed :=_ga .MakeArray (_ga .MakeName ("\u0049n\u0064\u0065\u0078\u0065\u0064"),_ga .MakeName (_fcae ),_agf .Get (2),_agf .Get (3));return _ea .NewPdfColorspaceFromPdfObject (_ebed );};func (_cebe *ContentStreamParser )parseName ()(_ga .PdfObjectNa
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Wrap ensures that the contentstream is wrapped within a balanced q ... Q expression.
|
|
|
|
func (_gc *ContentCreator )Wrap (){_gc ._da .WrapIfNeeded ()};func (_ddbeg *ContentStreamProcessor )handleCommand_cs (_fcfg *ContentStreamOperation ,_bcdc *_ea .PdfPageResources )error {if len (_fcfg .Params )< 1{_bgc .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069d\u0020\u0043\u0053\u0020\u0063\u006f\u006d\u006d\u0061\u006e\u0064\u002c\u0020s\u006b\u0069\u0070\u0070\u0069\u006e\u0067 \u006f\u0076\u0065\u0072");return _g .New ("\u0074o\u006f \u0066\u0065\u0077\u0020\u0070a\u0072\u0061m\u0065\u0074\u0065\u0072\u0073");};if len (_fcfg .Params )> 1{_bgc .Log .Debug ("\u0043\u0053\u0020\u0063\u006f\u006d\u006d\u0061n\u0064\u0020\u0077it\u0068\u0020\u0074\u006f\u006f\u0020m\u0061\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020-\u0020\u0063\u006f\u006e\u0074\u0069\u006e\u0075i\u006e\u0067");return _g .New ("\u0074\u006f\u006f\u0020ma\u006e\u0079\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u0073");};_gecf ,_efef :=_fcfg .Params [0].(*_ga .PdfObjectName );if !_efef {_bgc .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020C\u0053\u0020\u0063o\u006d\u006d\u0061n\u0064\u0020w\u0069\u0074\u0068\u0020\u0069\u006ev\u0061li\u0064\u0020\u0070\u0061\u0072\u0061\u006d\u0065\u0074\u0065\u0072\u002c\u0020\u0073\u006b\u0069\u0070\u0070\u0069\u006e\u0067\u0020\u006f\u0076\u0065\u0072");return _g .New ("\u0074\u0079p\u0065\u0020\u0063h\u0065\u0063\u006b\u0020\u0065\u0072\u0072\u006f\u0072");};_bdc ,_bdeg :=_ddbeg .getColorspace (string (*_gecf ),_bcdc );if _bdeg !=nil {return _bdeg ;};_ddbeg ._bgba .ColorspaceNonStroking =_bdc ;_befd ,_bdeg :=_ddbeg .getInitialColor (_bdc );if _bdeg !=nil {return _bdeg ;};_ddbeg ._bgba .ColorNonStroking =_befd ;return nil ;};func _dcg (_cedd *ContentStreamInlineImage )(*_ga .DCTEncoder ,error ){_fdg :=_ga .NewDCTEncoder ();_abe :=_f .NewReader (_cedd ._bfg );_gcef ,_gbf :=_dg .DecodeConfig (_abe );if _gbf !=nil {_bgc .Log .Debug ("\u0045\u0072\u0072or\u0020\u0064\u0065\u0063\u006f\u0064\u0069\u006e\u0067\u0020\u0066\u0069\u006c\u0065\u003a\u0020\u0025\u0073",_gbf );return nil ,_gbf ;};switch _gcef .ColorModel {case _c .RGBAModel :_fdg .BitsPerComponent =8;_fdg .ColorComponents =3;case _c .RGBA64Model :_fdg .BitsPerComponent =16;_fdg .ColorComponents =3;case _c .GrayModel :_fdg .BitsPerComponent =8;_fdg .ColorComponents =1;case _c .Gray16Model :_fdg .BitsPerComponent =16;_fdg .ColorComponents =1;case _c .CMYKModel :_fdg .BitsPerComponent =8;_fdg .ColorComponents =4;case _c .YCbCrModel :_fdg .BitsPerComponent =8;_fdg .ColorComponents =3;default:return nil ,_g .New ("\u0075\u006e\u0073up\u0070\u006f\u0072\u0074\u0065\u0064\u0020\u0063\u006f\u006c\u006f\u0072\u0020\u006d\u006f\u0064\u0065\u006c");};_fdg .Width =_gcef .Width ;_fdg .Height =_gcef .Height ;_bgc .Log .Trace ("\u0044\u0043T\u0020\u0045\u006ec\u006f\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076",_fdg );return _fdg ,nil ;};func _dde (_eafb *ContentStreamInlineImage ,_fff *_ga .PdfObjectDictionary )(*_ga .LZWEncoder ,error ){_dcc :=_ga .NewLZWEncoder ();if _fff ==nil {if _eafb .DecodeParms !=nil {_fdb ,_dbe :=_ga .GetDict (_eafb .DecodeParms );if !_dbe {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073\u0020n\u006f\u0074\u0020\u0061\u0020\u0064\u0069\u0063\u0074\u0069on\u0061\u0072\u0079 \u0028%\u0054\u0029",_eafb .DecodeParms );return nil ,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_fff =_fdb ;};};if _fff ==nil {return _dcc ,nil ;};_efb :=_fff .Get ("E\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065");if _efb !=nil {_cee ,_caf :=_efb .(*_ga .PdfObjectInteger );if !_caf {_bgc .Log .Debug ("\u0045\u0072\u0072\u006f\u0072\u003a \u0045\u0061\u0072\u006c\u0079\u0043\u0068\u0061\u006e\u0067\u0065\u0020\u0073\u0070\u0065\u0063\u0069\u0066\u0069\u0065d\u0020\u0062\u0075\u0074\u0020\u006e\u006f\u0074\u0020\u006e\u0075\u006d\u0065\u0072i\u0063 \u0028\u0025\u0054\u0029",_efb );return nil ,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_g appends 'g' operand to the content stream:
|
|
|
|
// Same as G but used for nonstroking operations.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_bcb *ContentCreator )Add_g (gray float64 )*ContentCreator {_ged :=ContentStreamOperation {};_ged .Operand ="\u0067";_ged .Params =_gegg ([]float64 {gray });_bcb ._da =append (_bcb ._da ,&_ged );return _bcb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_q adds 'q' operand to the content stream: Pushes the current graphics state on the stack.
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_fgg *ContentCreator )Add_q ()*ContentCreator {_gcg :=ContentStreamOperation {};_gcg .Operand ="\u0071";_fgg ._da =append (_fgg ._da ,&_gcg );return _fgg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Td appends 'Td' operand to the content stream:
|
|
|
|
// Move to start of next line with offset (`tx`, `ty`).
|
|
|
|
//
|
|
|
|
// See section 9.4.2 "Text Positioning Operators" and
|
|
|
|
// Table 108 (pp. 257-258 PDF32000_2008).
|
|
|
|
func (_bagg *ContentCreator )Add_Td (tx ,ty float64 )*ContentCreator {_eeee :=ContentStreamOperation {};_eeee .Operand ="\u0054\u0064";_eeee .Params =_gegg ([]float64 {tx ,ty });_bagg ._da =append (_bagg ._da ,&_eeee );return _bagg ;};func (_bfaa *ContentStreamParser )skipSpaces ()(int ,error ){_bgde :=0;for {_defc ,_bbg :=_bfaa ._bdec .Peek (1);if _bbg !=nil {return 0,_bbg ;};if _ga .IsWhiteSpace (_defc [0]){_bfaa ._bdec .ReadByte ();_bgde ++;}else {break ;};};return _bgde ,nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_S appends 'S' operand to the content stream: Stroke the path.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_faa *ContentCreator )Add_S ()*ContentCreator {_egc :=ContentStreamOperation {};_egc .Operand ="\u0053";_faa ._da =append (_faa ._da ,&_egc );return _faa ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_RG appends 'RG' operand to the content stream:
|
|
|
|
// Set the stroking colorspace to DeviceRGB and sets the r,g,b colors (0-1 each).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_ced *ContentCreator )Add_RG (r ,g ,b float64 )*ContentCreator {_fcb :=ContentStreamOperation {};_fcb .Operand ="\u0052\u0047";_fcb .Params =_gegg ([]float64 {r ,g ,b });_ced ._da =append (_ced ._da ,&_fcb );return _ced ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// NewContentStreamParser creates a new instance of the content stream parser from an input content
|
|
|
|
// stream string.
|
|
|
|
func NewContentStreamParser (contentStr string )*ContentStreamParser {_fbf :=ContentStreamParser {};_ada :=_f .NewBufferString (contentStr +"\u000a");_fbf ._bdec =_dd .NewReader (_ada );return &_fbf ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// SetNonStrokingColor sets the non-stroking `color` where color can be one of
|
|
|
|
// PdfColorDeviceGray, PdfColorDeviceRGB, or PdfColorDeviceCMYK.
|
|
|
|
func (_cfb *ContentCreator )SetNonStrokingColor (color _ea .PdfColor )*ContentCreator {switch _ccef :=color .(type ){case *_ea .PdfColorDeviceGray :_cfb .Add_g (_ccef .Val ());case *_ea .PdfColorDeviceRGB :_cfb .Add_rg (_ccef .R (),_ccef .G (),_ccef .B ());case *_ea .PdfColorDeviceCMYK :_cfb .Add_k (_ccef .C (),_ccef .M (),_ccef .Y (),_ccef .K ());default:_bgc .Log .Debug ("\u0053\u0065\u0074N\u006f\u006e\u0053\u0074\u0072\u006f\u006b\u0069\u006e\u0067\u0043\u006f\u006c\u006f\u0072\u003a\u0020\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064\u0020c\u006f\u006c\u006f\u0072\u003a\u0020\u0025\u0054",_ccef );};return _cfb ;};func (_bcgg *ContentStreamProcessor )handleCommand_rg (_cgaa *ContentStreamOperation ,_gae *_ea .PdfPageResources )error {_bbecc :=_ea .NewPdfColorspaceDeviceRGB ();if len (_cgaa .Params )!=_bbecc .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_cgaa .Params ),_bbecc );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_bad ,_gfeb :=_bbecc .ColorFromPdfObjects (_cgaa .Params );if _gfeb !=nil {return _gfeb ;};_bcgg ._bgba .ColorspaceNonStroking =_bbecc ;_bcgg ._bgba .ColorNonStroking =_bad ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Transform returns coordinates x, y transformed by the CTM.
|
|
|
|
func (_aac *GraphicsState )Transform (x ,y float64 )(float64 ,float64 ){return _aac .CTM .Transform (x ,y );};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// NewInlineImageFromImage makes a new content stream inline image object from an image.
|
|
|
|
func NewInlineImageFromImage (img _ea .Image ,encoder _ga .StreamEncoder )(*ContentStreamInlineImage ,error ){if encoder ==nil {encoder =_ga .NewRawEncoder ();};encoder .UpdateParams (img .GetParamsDict ());_adg :=ContentStreamInlineImage {};if img .ColorComponents ==1{_adg .ColorSpace =_ga .MakeName ("\u0047");}else if img .ColorComponents ==3{_adg .ColorSpace =_ga .MakeName ("\u0052\u0047\u0042");}else if img .ColorComponents ==4{_adg .ColorSpace =_ga .MakeName ("\u0043\u004d\u0059\u004b");}else {_bgc .Log .Debug ("\u0049\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006db\u0065\u0072\u0020o\u0066\u0020c\u006f\u006c\u006f\u0072\u0020\u0063o\u006dpo\u006e\u0065\u006e\u0074\u0073\u0020\u0066\u006f\u0072\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u003a\u0020\u0025\u0064",img .ColorComponents );return nil ,_g .New ("\u0069\u006e\u0076al\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072 \u006ff\u0020c\u006fl\u006f\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0073");};_adg .BitsPerComponent =_ga .MakeInteger (img .BitsPerComponent );_adg .Width =_ga .MakeInteger (img .Width );_adg .Height =_ga .MakeInteger (img .Height );_fdc ,_ecba :=encoder .EncodeBytes (img .Data );if _ecba !=nil {return nil ,_ecba ;};_adg ._bfg =_fdc ;_agee :=encoder .GetFilterName ();if _agee !=_ga .StreamEncodingFilterNameRaw {_adg .Filter =_ga .MakeName (_agee );};return &_adg ,nil ;};func (_eaa *ContentStreamParser )parseNull ()(_ga .PdfObjectNull ,error ){_ ,_fdgdd :=_eaa ._bdec .Discard (4);return _ga .PdfObjectNull {},_fdgdd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tw appends 'Tw' operand to the content stream:
|
|
|
|
// Set word spacing.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
|
|
func (_debce *ContentCreator )Add_Tw (wordSpace float64 )*ContentCreator {_dgd :=ContentStreamOperation {};_dgd .Operand ="\u0054\u0077";_dgd .Params =_gegg ([]float64 {wordSpace });_debce ._da =append (_debce ._da ,&_dgd );return _debce ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ParseInlineImage parses an inline image from a content stream, both reading its properties and binary data.
|
|
|
|
// When called, "BI" has already been read from the stream. This function
|
|
|
|
// finishes reading through "EI" and then returns the ContentStreamInlineImage.
|
|
|
|
func (_fac *ContentStreamParser )ParseInlineImage ()(*ContentStreamInlineImage ,error ){_dgbe :=ContentStreamInlineImage {};for {_fac .skipSpaces ();_eeeg ,_aecb ,_dae :=_fac .parseObject ();if _dae !=nil {return nil ,_dae ;};if !_aecb {_dcb ,_cdg :=_ga .GetName (_eeeg );if !_cdg {_bgc .Log .Debug ("\u0049\u006e\u0076\u0061\u006ci\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067e\u0020\u0070\u0072\u006f\u0070\u0065\u0072\u0074\u0079\u0020\u0028\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067\u0020\u006e\u0061\u006d\u0065\u0029\u0020\u002d\u0020\u0025T",_eeeg );return nil ,_e .Errorf ("\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067e\u0020\u0070\u0072\u006f\u0070\u0065\u0072\u0074\u0079\u0020\u0028\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067\u0020\u006e\u0061\u006d\u0065\u0029\u0020\u002d\u0020\u0025T",_eeeg );};_cegb ,_agc ,_fadf :=_fac .parseObject ();if _fadf !=nil {return nil ,_fadf ;};if _agc {return nil ,_e .Errorf ("\u006eo\u0074\u0020\u0065\u0078\u0070\u0065\u0063\u0074\u0069\u006e\u0067 \u0061\u006e\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};switch *_dcb {case "\u0042\u0050\u0043","\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074":_dgbe .BitsPerComponent =_cegb ;case "\u0043\u0053","\u0043\u006f\u006c\u006f\u0072\u0053\u0070\u0061\u0063\u0065":_dgbe .ColorSpace =_cegb ;case "\u0044","\u0044\u0065\u0063\u006f\u0064\u0065":_dgbe .Decode =_cegb ;case "\u0044\u0050","D\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073":_dgbe .DecodeParms =_cegb ;case "\u0046","\u0046\u0069\u006c\u0074\u0065\u0072":_dgbe .Filter =_cegb ;case "\u0048","\u0048\u0065\u0069\u0067\u0068\u0074":_dgbe .Height =_cegb ;case "\u0049\u004d","\u0049m\u0061\u0067\u0065\u004d\u0061\u0073k":_dgbe .ImageMask =_cegb ;case "\u0049\u006e\u0074\u0065\u006e\u0074":_dgbe .Intent =_cegb ;case "\u0049","I\u006e\u0074\u0065\u0072\u0070\u006f\u006c\u0061\u0074\u0065":_dgbe .Interpolate =_cegb ;case "\u0057","\u0057\u0069\u0064t\u0068":_dgbe .Width =_cegb ;case "\u004c\u0065\u006e\u0067\u0074\u0068","\u0053u\u0062\u0074\u0079\u0070\u0065","\u0054\u0079\u0070\u0065":_bgc .Log .Debug ("\u0049\u0067\u006e\u006fr\u0069\u006e\u0067\u0020\u0069\u006e\u006c\u0069\u006e\u0065 \u0070a\u0072\u0061\u006d\u0065\u0074\u0065\u0072 \u0025\u0073",*_dcb );default:return nil ,_e .Errorf ("\u0075\u006e\u006b\u006e\u006f\u0077n\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0020\u0025\u0073",*_dcb );};};if _aecb {_dcdf ,_bdd :=_eeeg .(*_ga .PdfObjectString );if !_bdd {return nil ,_e .Errorf ("\u0066a\u0069\u006ce\u0064\u0020\u0074o\u0020\u0072\u0065\u0061\u0064\u0020\u0069n\u006c\u0069\u006e\u0065\u0020\u0069m\u0061\u0067\u0065\u0020\u002d\u0020\u0069\u006e\u0076\u0061\u006ci\u0064\u0020\u006f\u0070\u0065\u0072\u0061\u006e\u0064");};if _dcdf .Str ()=="\u0045\u0049"{_bgc .Log .Trace ("\u0049n\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020f\u0069\u006e\u0069\u0073\u0068\u0065\u0064\u002e\u002e\u002e");return &_dgbe ,nil ;}else if _dcdf .Str ()=="\u0049\u0044"{_bgc .Log .Trace ("\u0049\u0044\u0020\u0073\u0074\u0061\u0072\u0074");_gff ,_cege :=_fac ._bdec .Peek (1);if _cege !=nil {return nil ,_cege ;};if _ga .IsWhiteSpace (_gff [0]){_fac ._bdec .Discard (1);};_dgbe ._bfg =[]byte {};_cddd :=0;var _gffd []byte ;for {_aefb ,_gda :=_fac ._bdec .ReadByte ();if _gda !=nil {_bgc .Log .Debug ("\u0055\u006e\u0061\u0062\u006ce\u0020\u0074\u006f\u0020\u0066\u0069\u006e\u0064\u0020\u0065\u006e\u0064\u0020o\u0066\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0045\u0049\u0020\u0069\u006e\u0020\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065\u0020\u0064\u0061\u0074a");return nil ,_gda ;};if _cddd ==0{if _ga .IsWhiteSpace (_aefb ){_gffd =[]byte {};_gffd =append (_gffd ,_aefb );_cddd =1;}else if _aefb =='E'{_gffd =append (_gffd ,_aefb );_cddd =2;}else {_dgbe ._bfg =append (_dgbe ._bfg ,_aefb );};}else if _cddd ==1{_gffd
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Scale applies x-y scaling to the transformation matrix.
|
|
|
|
func (_fca *ContentCreator )Scale (sx ,sy float64 )*ContentCreator {return _fca .Add_cm (sx ,0,0,sy ,0,0);};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_quotes appends `"` operand to the content stream:
|
|
|
|
// Move to next line and show a string, using `aw` and `ac` as word
|
|
|
|
// and character spacing respectively.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_gcdc *ContentCreator )Add_quotes (textstr _ga .PdfObjectString ,aw ,ac float64 )*ContentCreator {_ggag :=ContentStreamOperation {};_ggag .Operand ="\u0022";_ggag .Params =_gegg ([]float64 {aw ,ac });_ggag .Params =append (_ggag .Params ,_fabc ([]_ga .PdfObjectString {textstr })...);_gcdc ._da =append (_gcdc ._da ,&_ggag );return _gcdc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// WrapIfNeeded wraps the entire contents within q ... Q. If unbalanced, then adds extra Qs at the end.
|
|
|
|
// Only does if needed. Ensures that when adding new content, one start with all states
|
|
|
|
// in the default condition.
|
|
|
|
func (_ed *ContentStreamOperations )WrapIfNeeded ()*ContentStreamOperations {if len (*_ed )==0{return _ed ;};if _ed .isWrapped (){return _ed ;};*_ed =append ([]*ContentStreamOperation {{Operand :"\u0071"}},*_ed ...);_bc :=0;for _ ,_ff :=range *_ed {if _ff .Operand =="\u0071"{_bc ++;}else if _ff .Operand =="\u0051"{_bc --;};};for _bc > 0{*_ed =append (*_ed ,&ContentStreamOperation {Operand :"\u0051"});_bc --;};return _ed ;};func (_dfgg *ContentStreamProcessor )handleCommand_scn (_cfce *ContentStreamOperation ,_gcfc *_ea .PdfPageResources )error {_cbefg :=_dfgg ._bgba .ColorspaceNonStroking ;if !_eabc (_cbefg ){if len (_cfce .Params )!=_cbefg .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_cfce .Params ),_cbefg );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_bfd ,_fcca :=_cbefg .ColorFromPdfObjects (_cfce .Params );if _fcca !=nil {_bgc .Log .Debug ("\u0045\u0052\u0052\u004f\u0052\u003a\u0020\u0046\u0061\u0069\u006c \u0074\u006f\u0020\u0067\u0065\u0074\u0020\u0063o\u006co\u0072\u0020\u0066\u0072\u006f\u006d\u0020\u0070\u0061\u0072\u0061\u006d\u0073\u003a\u0020\u0025\u002b\u0076 \u0028\u0043\u0053\u0020\u0069\u0073\u0020\u0025\u002b\u0076\u0029",_cfce .Params ,_cbefg );return _fcca ;};_dfgg ._bgba .ColorNonStroking =_bfd ;return nil ;};func _eabc (_efba _ea .PdfColorspace )bool {_ ,_beec :=_efba .(*_ea .PdfColorspaceSpecialPattern );return _beec ;};func (_gea *ContentStreamParser )parseNumber ()(_ga .PdfObject ,error ){return _ga .ParseNumber (_gea ._bdec );};func (_gcdg *ContentStreamProcessor )handleCommand_g (_eagd *ContentStreamOperation ,_gdc *_ea .PdfPageResources )error {_ece :=_ea .NewPdfColorspaceDeviceGray ();if len (_eagd .Params )!=_ece .GetNumComponents (){_bgc .Log .Debug ("\u0049\u006e\u0076al\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072 \u006ff\u0020p\u0061r\u0061\u006d\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020\u0067");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_eagd .Params ),_ece );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_fage ,_bbdg :=_ece .ColorFromPdfObjects (_eagd .Params );if _bbdg !=nil {_bgc .Log .Debug ("\u0045\u0052\u0052\u004fR\u003a\u0020\u0068\u0061\u006e\u0064\u006c\u0065\u0043o\u006d\u006d\u0061\u006e\u0064\u005f\u0067\u0020\u0049\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061r\u0061\u006d\u0073\u002e\u0020c\u0073\u003d\u0025\u0054\u0020\u006f\u0070\u003d\u0025\u0073\u0020\u0065\u0072\u0072\u003d\u0025\u0076",_ece ,_eagd ,_bbdg );return _bbdg ;};_gcdg ._bgba .ColorspaceNonStroking =_ece ;_gcdg ._bgba .ColorNonStroking =_fage ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tf appends 'Tf' operand to the content stream:
|
|
|
|
// Set font and font size specified by font resource `fontName` and `fontSize`.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
|
|
func (_fgb *ContentCreator )Add_Tf (fontName _ga .PdfObjectName ,fontSize float64 )*ContentCreator {_ede :=ContentStreamOperation {};_ede .Operand ="\u0054\u0066";_ede .Params =_dfef ([]_ga .PdfObjectName {fontName });_ede .Params =append (_ede .Params ,_gegg ([]float64 {fontSize })...);_fgb ._da =append (_fgb ._da ,&_ede );return _fgb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_m adds 'm' operand to the content stream: Move the current point to (x,y).
|
|
|
|
//
|
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
|
|
|
func (_adeg *ContentCreator )Add_m (x ,y float64 )*ContentCreator {_dabb :=ContentStreamOperation {};_dabb .Operand ="\u006d";_dabb .Params =_gegg ([]float64 {x ,y });_adeg ._da =append (_adeg ._da ,&_dabb );return _adeg ;};func (_agcg *ContentStreamParser )parseObject ()(_agb _ga .PdfObject ,_eag bool ,_ddeb error ){_agcg .skipSpaces ();for {_begd ,_adgc :=_agcg ._bdec .Peek (2);if _adgc !=nil {return nil ,false ,_adgc ;};_bgc .Log .Trace ("\u0050e\u0065k\u0020\u0073\u0074\u0072\u0069\u006e\u0067\u003a\u0020\u0025\u0073",string (_begd ));if _begd [0]=='%'{_agcg .skipComments ();continue ;}else if _begd [0]=='/'{_ffd ,_eecg :=_agcg .parseName ();_bgc .Log .Trace ("\u002d\u003e\u004ea\u006d\u0065\u003a\u0020\u0027\u0025\u0073\u0027",_ffd );return &_ffd ,false ,_eecg ;}else if _begd [0]=='('{_bgc .Log .Trace ("\u002d>\u0053\u0074\u0072\u0069\u006e\u0067!");_ebg ,_ddff :=_agcg .parseString ();return _ebg ,false ,_ddff ;}else if _begd [0]=='<'&&_begd [1]!='<'{_bgc .Log .Trace ("\u002d\u003e\u0048\u0065\u0078\u0020\u0053\u0074\u0072\u0069\u006e\u0067\u0021");_gged ,_cda :=_agcg .parseHexString ();return _gged ,false ,_cda ;}else if _begd [0]=='['{_bgc .Log .Trace ("\u002d\u003e\u0041\u0072\u0072\u0061\u0079\u0021");_gcf ,_fgea :=_agcg .parseArray ();return _gcf ,false ,_fgea ;}else if _ga .IsFloatDigit (_begd [0])||(_begd [0]=='-'&&_ga .IsFloatDigit (_begd [1])){_bgc .Log .Trace ("\u002d>\u004e\u0075\u006d\u0062\u0065\u0072!");_caeea ,_fgce :=_agcg .parseNumber ();return _caeea ,false ,_fgce ;}else if _begd [0]=='<'&&_begd [1]=='<'{_dfdg ,_gfb :=_agcg .parseDict ();return _dfdg ,false ,_gfb ;}else {_bgc .Log .Trace ("\u002d>\u004fp\u0065\u0072\u0061\u006e\u0064 \u006f\u0072 \u0062\u006f\u006f\u006c\u003f");_begd ,_ =_agcg ._bdec .Peek (5);_fgga :=string (_begd );_bgc .Log .Trace ("\u0063\u006f\u006e\u0074\u0020\u0050\u0065\u0065\u006b\u0020\u0073\u0074r\u003a\u0020\u0025\u0073",_fgga );if (len (_fgga )> 3)&&(_fgga [:4]=="\u006e\u0075\u006c\u006c"){_ccf ,_dagb :=_agcg .parseNull ();return &_ccf ,false ,_dagb ;}else if (len (_fgga )> 4)&&(_fgga [:5]=="\u0066\u0061\u006cs\u0065"){_dbef ,_egcc :=_agcg .parseBool ();return &_dbef ,false ,_egcc ;}else if (len (_fgga )> 3)&&(_fgga [:4]=="\u0074\u0072\u0075\u0065"){_abecf ,_dbg :=_agcg .parseBool ();return &_abecf ,false ,_dbg ;};_dfcf ,_fbc :=_agcg .parseOperand ();if _fbc !=nil {return _dfcf ,false ,_fbc ;};if len (_dfcf .String ())< 1{return _dfcf ,false ,ErrInvalidOperand ;};return _dfcf ,true ,nil ;};};};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_ri adds 'ri' operand to the content stream, which sets the color rendering intent.
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_dbc *ContentCreator )Add_ri (intent _ga .PdfObjectName )*ContentCreator {_fbe :=ContentStreamOperation {};_fbe .Operand ="\u0072\u0069";_fbe .Params =_dfef ([]_ga .PdfObjectName {intent });_dbc ._da =append (_dbc ._da ,&_fbe );return _dbc ;};func (_cfbc *ContentStreamParser )parseOperand ()(*_ga .PdfObjectString ,error ){var _gaag []byte ;for {_dag ,_cbb :=_cfbc ._bdec .Peek (1);if _cbb !=nil {return _ga .MakeString (string (_gaag )),_cbb ;};if _ga .IsDelimiter (_dag [0]){break ;};if _ga .IsWhiteSpace (_dag [0]){break ;};_fed ,_ :=_cfbc ._bdec .ReadByte ();_gaag =append (_gaag ,_fed );};return _ga .MakeString (string (_gaag )),nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// String returns `ops.Bytes()` as a string.
|
|
|
|
func (_aa *ContentStreamOperations )String ()string {return string (_aa .Bytes ())};func (_gfcb *ContentStreamProcessor )handleCommand_SC (_gbfbc *ContentStreamOperation ,_fdba *_ea .PdfPageResources )error {_fecf :=_gfcb ._bgba .ColorspaceStroking ;if len (_gbfbc .Params )!=_fecf .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_gbfbc .Params ),_fecf );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_baeg ,_bdfa :=_fecf .ColorFromPdfObjects (_gbfbc .Params );if _bdfa !=nil {return _bdfa ;};_gfcb ._bgba .ColorStroking =_baeg ;return nil ;};func (_dge *ContentStreamProcessor )getInitialColor (_dbcca _ea .PdfColorspace )(_ea .PdfColor ,error ){switch _acb :=_dbcca .(type ){case *_ea .PdfColorspaceDeviceGray :return _ea .NewPdfColorDeviceGray (0.0),nil ;case *_ea .PdfColorspaceDeviceRGB :return _ea .NewPdfColorDeviceRGB (0.0,0.0,0.0),nil ;case *_ea .PdfColorspaceDeviceCMYK :return _ea .NewPdfColorDeviceCMYK (0.0,0.0,0.0,1.0),nil ;case *_ea .PdfColorspaceCalGray :return _ea .NewPdfColorCalGray (0.0),nil ;case *_ea .PdfColorspaceCalRGB :return _ea .NewPdfColorCalRGB (0.0,0.0,0.0),nil ;case *_ea .PdfColorspaceLab :_ffgd :=0.0;_cfe :=0.0;_egd :=0.0;if _acb .Range [0]> 0{_ffgd =_acb .Range [0];};if _acb .Range [2]> 0{_cfe =_acb .Range [2];};return _ea .NewPdfColorLab (_ffgd ,_cfe ,_egd ),nil ;case *_ea .PdfColorspaceICCBased :if _acb .Alternate ==nil {_bgc .Log .Trace ("\u0049\u0043\u0043\u0020\u0042\u0061\u0073\u0065\u0064\u0020\u006eo\u0074\u0020\u0064\u0065\u0066\u0069\u006e\u0065d\u0020-\u0020\u0061\u0074\u0074\u0065\u006d\u0070\u0074\u0069\u006e\u0067\u0020\u0066\u0061\u006c\u006c\u0020\u0062a\u0063\u006b\u0020\u0028\u004e\u0020\u003d\u0020\u0025\u0064\u0029",_acb .N );if _acb .N ==1{_bgc .Log .Trace ("\u0046\u0061\u006c\u006c\u0069\u006e\u0067\u0020\u0062\u0061\u0063k\u0020\u0074\u006f\u0020\u0044\u0065\u0076\u0069\u0063\u0065G\u0072\u0061\u0079");return _dge .getInitialColor (_ea .NewPdfColorspaceDeviceGray ());}else if _acb .N ==3{_bgc .Log .Trace ("\u0046a\u006c\u006c\u0069\u006eg\u0020\u0062\u0061\u0063\u006b \u0074o\u0020D\u0065\u0076\u0069\u0063\u0065\u0052\u0047B");return _dge .getInitialColor (_ea .NewPdfColorspaceDeviceRGB ());}else if _acb .N ==4{_bgc .Log .Trace ("\u0046\u0061\u006c\u006c\u0069\u006e\u0067\u0020\u0062\u0061\u0063k\u0020\u0074\u006f\u0020\u0044\u0065\u0076\u0069\u0063\u0065C\u004d\u0059\u004b");return _dge .getInitialColor (_ea .NewPdfColorspaceDeviceCMYK ());}else {return nil ,_g .New ("a\u006c\u0074\u0065\u0072\u006e\u0061t\u0065\u0020\u0073\u0070\u0061\u0063e\u0020\u006e\u006f\u0074\u0020\u0064\u0065f\u0069\u006e\u0065\u0064\u0020\u0066\u006f\u0072\u0020\u0049C\u0043");};};return _dge .getInitialColor (_acb .Alternate );case *_ea .PdfColorspaceSpecialIndexed :if _acb .Base ==nil {return nil ,_g .New ("\u0069\u006e\u0064\u0065\u0078\u0065\u0064\u0020\u0062\u0061\u0073e\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069f\u0069\u0065\u0064");};return _dge .getInitialColor (_acb .Base );case *_ea .PdfColorspaceSpecialSeparation :if _acb .AlternateSpace ==nil {return nil ,_g .New ("\u0061\u006ct\u0065\u0072\u006e\u0061\u0074\u0065\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069fi\u0065\u0064");};return _dge .getInitialColor (_acb .AlternateSpace );case *_ea .PdfColorspaceDeviceN :if _acb .AlternateSpace ==nil {return nil ,_g .New ("\u0061\u006ct\u0065\u0072\u006e\u0061\u0074\u0065\u0020\u0073\u0070\u0061\u0063\u0065\u0020\u006e\u006f\u0074\u0020\u0073\u0070\u0065\u0063\u0069fi\u0065\u0064");};return _dge .getInitialColor (_acb .AlternateSpace );case *_ea .PdfColo
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Push pushes `gs` on the `gsStack`.
|
|
|
|
func (_fdca *GraphicStateStack )Push (gs GraphicsState ){*_fdca =append (*_fdca ,gs )};func (_dfe *ContentStreamProcessor )handleCommand_SCN (_bcgc *ContentStreamOperation ,_aae *_ea .PdfPageResources )error {_dbd :=_dfe ._bgba .ColorspaceStroking ;if !_eabc (_dbd ){if len (_bcgc .Params )!=_dbd .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_bcgc .Params ),_dbd );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};};_bcbf ,_afaa :=_dbd .ColorFromPdfObjects (_bcgc .Params );if _afaa !=nil {return _afaa ;};_dfe ._bgba .ColorStroking =_bcbf ;return nil ;};
|
|
|
|
|
|
|
|
// Add_Tc appends 'Tc' operand to the content stream:
|
|
|
|
// Set character spacing.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
|
|
func (_efa *ContentCreator )Add_Tc (charSpace float64 )*ContentCreator {_gcd :=ContentStreamOperation {};_gcd .Operand ="\u0054\u0063";_gcd .Params =_gegg ([]float64 {charSpace });_efa ._da =append (_efa ._da ,&_gcd );return _efa ;};func (_gbff *ContentStreamParser )parseBool ()(_ga .PdfObjectBool ,error ){_bbb ,_gddg :=_gbff ._bdec .Peek (4);if _gddg !=nil {return _ga .PdfObjectBool (false ),_gddg ;};if (len (_bbb )>=4)&&(string (_bbb [:4])=="\u0074\u0072\u0075\u0065"){_gbff ._bdec .Discard (4);return _ga .PdfObjectBool (true ),nil ;};_bbb ,_gddg =_gbff ._bdec .Peek (5);if _gddg !=nil {return _ga .PdfObjectBool (false ),_gddg ;};if (len (_bbb )>=5)&&(string (_bbb [:5])=="\u0066\u0061\u006cs\u0065"){_gbff ._bdec .Discard (5);return _ga .PdfObjectBool (false ),nil ;};return _ga .PdfObjectBool (false ),_g .New ("\u0075n\u0065\u0078\u0070\u0065c\u0074\u0065\u0064\u0020\u0062o\u006fl\u0065a\u006e\u0020\u0073\u0074\u0072\u0069\u006eg");};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// AddHandler adds a new ContentStreamProcessor `handler` of type `condition` for `operand`.
|
|
|
|
func (_cfba *ContentStreamProcessor )AddHandler (condition HandlerConditionEnum ,operand string ,handler HandlerFunc ){_dcag :=handlerEntry {};_dcag .Condition =condition ;_dcag .Operand =operand ;_dcag .Handler =handler ;_cfba ._fab =append (_cfba ._fab ,_dcag );};func (_fgeaf *ContentStreamProcessor )handleCommand_K (_gedc *ContentStreamOperation ,_dfgd *_ea .PdfPageResources )error {_bdcc :=_ea .NewPdfColorspaceDeviceCMYK ();if len (_gedc .Params )!=_bdcc .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_gedc .Params ),_bdcc );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_gedf ,_aad :=_bdcc .ColorFromPdfObjects (_gedc .Params );if _aad !=nil {return _aad ;};_fgeaf ._bgba .ColorspaceStroking =_bdcc ;_fgeaf ._bgba .ColorStroking =_gedf ;return nil ;};
|
|
|
|
|
|
|
|
// Add_b appends 'b' operand to the content stream:
|
|
|
|
// Close, fill and then stroke the path (nonzero winding number rule).
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_ac *ContentCreator )Add_b ()*ContentCreator {_egg :=ContentStreamOperation {};_egg .Operand ="\u0062";_ac ._da =append (_ac ._da ,&_egg );return _ac ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_sh appends 'sh' operand to the content stream:
|
|
|
|
// Paints the shape and colour shading described by a shading dictionary specified by `name`,
|
|
|
|
// subject to the current clipping path
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.7.4 "Shading Patterns" and Table 77 (p. 190 PDF32000_2008).
|
|
|
|
func (_bd *ContentCreator )Add_sh (name _ga .PdfObjectName )*ContentCreator {_gab :=ContentStreamOperation {};_gab .Operand ="\u0073\u0068";_gab .Params =_dfef ([]_ga .PdfObjectName {name });_bd ._da =append (_bd ._da ,&_gab );return _bd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_SC appends 'SC' operand to the content stream:
|
|
|
|
// Set color for stroking operations. Input: c1, ..., cn.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_gdg *ContentCreator )Add_SC (c ...float64 )*ContentCreator {_cg :=ContentStreamOperation {};_cg .Operand ="\u0053\u0043";_cg .Params =_gegg (c );_gdg ._da =append (_gdg ._da ,&_cg );return _gdg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// HandlerConditionEnum represents the type of operand content stream processor (handler).
|
|
|
|
// The handler may process a single specific named operand or all operands.
|
|
|
|
type HandlerConditionEnum int ;
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Process processes the entire list of operations. Maintains the graphics state that is passed to any
|
|
|
|
// handlers that are triggered during processing (either on specific operators or all).
|
|
|
|
func (_aeac *ContentStreamProcessor )Process (resources *_ea .PdfPageResources )error {_aeac ._bgba .ColorspaceStroking =_ea .NewPdfColorspaceDeviceGray ();_aeac ._bgba .ColorspaceNonStroking =_ea .NewPdfColorspaceDeviceGray ();_aeac ._bgba .ColorStroking =_ea .NewPdfColorDeviceGray (0);_aeac ._bgba .ColorNonStroking =_ea .NewPdfColorDeviceGray (0);_aeac ._bgba .CTM =_db .IdentityMatrix ();for _ ,_dbeg :=range _aeac ._cfcad {var _fabf error ;switch _dbeg .Operand {case "\u0071":_aeac ._cdda .Push (_aeac ._bgba );case "\u0051":if len (_aeac ._cdda )==0{_bgc .Log .Debug ("\u0057\u0041\u0052\u004e\u003a\u0020\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0060\u0051\u0060\u0020\u006f\u0070e\u0072\u0061\u0074\u006f\u0072\u002e\u0020\u0047\u0072\u0061\u0070\u0068\u0069\u0063\u0073\u0020\u0073\u0074\u0061\u0074\u0065 \u0073\u0074\u0061\u0063\u006b\u0020\u0069\u0073\u0020\u0065\u006d\u0070\u0074\u0079.\u0020\u0053\u006bi\u0070\u0070\u0069\u006e\u0067\u002e");continue ;};_aeac ._bgba =_aeac ._cdda .Pop ();case "\u0043\u0053":_fabf =_aeac .handleCommand_CS (_dbeg ,resources );case "\u0063\u0073":_fabf =_aeac .handleCommand_cs (_dbeg ,resources );case "\u0053\u0043":_fabf =_aeac .handleCommand_SC (_dbeg ,resources );case "\u0053\u0043\u004e":_fabf =_aeac .handleCommand_SCN (_dbeg ,resources );case "\u0073\u0063":_fabf =_aeac .handleCommand_sc (_dbeg ,resources );case "\u0073\u0063\u006e":_fabf =_aeac .handleCommand_scn (_dbeg ,resources );case "\u0047":_fabf =_aeac .handleCommand_G (_dbeg ,resources );case "\u0067":_fabf =_aeac .handleCommand_g (_dbeg ,resources );case "\u0052\u0047":_fabf =_aeac .handleCommand_RG (_dbeg ,resources );case "\u0072\u0067":_fabf =_aeac .handleCommand_rg (_dbeg ,resources );case "\u004b":_fabf =_aeac .handleCommand_K (_dbeg ,resources );case "\u006b":_fabf =_aeac .handleCommand_k (_dbeg ,resources );case "\u0063\u006d":_fabf =_aeac .handleCommand_cm (_dbeg ,resources );};if _fabf !=nil {_bgc .Log .Debug ("\u0050\u0072\u006f\u0063\u0065\u0073s\u006f\u0072\u0020\u0068\u0061\u006e\u0064\u006c\u0069\u006e\u0067\u0020\u0065r\u0072\u006f\u0072\u0020\u0028\u0025\u0073)\u003a\u0020\u0025\u0076",_dbeg .Operand ,_fabf );_bgc .Log .Debug ("\u004f\u0070\u0065r\u0061\u006e\u0064\u003a\u0020\u0025\u0023\u0076",_dbeg .Operand );return _fabf ;};for _ ,_ebge :=range _aeac ._fab {var _ebfd error ;if _ebge .Condition .All (){_ebfd =_ebge .Handler (_dbeg ,_aeac ._bgba ,resources );}else if _ebge .Condition .Operand ()&&_dbeg .Operand ==_ebge .Operand {_ebfd =_ebge .Handler (_dbeg ,_aeac ._bgba ,resources );};if _ebfd !=nil {_bgc .Log .Debug ("P\u0072\u006f\u0063\u0065\u0073\u0073o\u0072\u0020\u0068\u0061\u006e\u0064\u006c\u0065\u0072 \u0065\u0072\u0072o\u0072:\u0020\u0025\u0076",_ebfd );return _ebfd ;};};};return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_SCN appends 'SCN' operand to the content stream:
|
|
|
|
// Same as SC but supports more colorspaces.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
|
|
|
func (_egb *ContentCreator )Add_SCN (c ...float64 )*ContentCreator {_fge :=ContentStreamOperation {};_fge .Operand ="\u0053\u0043\u004e";_fge .Params =_gegg (c );_egb ._da =append (_egb ._da ,&_fge );return _egb ;};
|
2017-06-28 15:13:37 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ContentStreamOperations is a slice of ContentStreamOperations.
|
|
|
|
type ContentStreamOperations []*ContentStreamOperation ;func _gegg (_eeeeb []float64 )[]_ga .PdfObject {var _eccg []_ga .PdfObject ;for _ ,_gbdd :=range _eeeeb {_eccg =append (_eccg ,_ga .MakeFloat (_gbdd ));};return _eccg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_TL appends 'TL' operand to the content stream:
|
|
|
|
// Set leading.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_dgb *ContentCreator )Add_TL (leading float64 )*ContentCreator {_efc :=ContentStreamOperation {};_efc .Operand ="\u0054\u004c";_efc .Params =_gegg ([]float64 {leading });_dgb ._da =append (_dgb ._da ,&_efc );return _dgb ;};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// WriteString outputs the object as it is to be written to file.
|
|
|
|
func (_gdde *ContentStreamInlineImage )WriteString ()string {var _dggc _f .Buffer ;_fcgdb :="";if _gdde .BitsPerComponent !=nil {_fcgdb +="\u002f\u0042\u0050C\u0020"+_gdde .BitsPerComponent .WriteString ()+"\u000a";};if _gdde .ColorSpace !=nil {_fcgdb +="\u002f\u0043\u0053\u0020"+_gdde .ColorSpace .WriteString ()+"\u000a";};if _gdde .Decode !=nil {_fcgdb +="\u002f\u0044\u0020"+_gdde .Decode .WriteString ()+"\u000a";};if _gdde .DecodeParms !=nil {_fcgdb +="\u002f\u0044\u0050\u0020"+_gdde .DecodeParms .WriteString ()+"\u000a";};if _gdde .Filter !=nil {_fcgdb +="\u002f\u0046\u0020"+_gdde .Filter .WriteString ()+"\u000a";};if _gdde .Height !=nil {_fcgdb +="\u002f\u0048\u0020"+_gdde .Height .WriteString ()+"\u000a";};if _gdde .ImageMask !=nil {_fcgdb +="\u002f\u0049\u004d\u0020"+_gdde .ImageMask .WriteString ()+"\u000a";};if _gdde .Intent !=nil {_fcgdb +="\u002f\u0049\u006e\u0074\u0065\u006e\u0074\u0020"+_gdde .Intent .WriteString ()+"\u000a";};if _gdde .Interpolate !=nil {_fcgdb +="\u002f\u0049\u0020"+_gdde .Interpolate .WriteString ()+"\u000a";};if _gdde .Width !=nil {_fcgdb +="\u002f\u0057\u0020"+_gdde .Width .WriteString ()+"\u000a";};_dggc .WriteString (_fcgdb );_dggc .WriteString ("\u0049\u0044\u0020");_dggc .Write (_gdde ._bfg );_dggc .WriteString ("\u000a\u0045\u0049\u000a");return _dggc .String ();};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_CS appends 'CS' operand to the content stream:
|
|
|
|
// Set the current colorspace for stroking operations.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_gfa *ContentCreator )Add_CS (name _ga .PdfObjectName )*ContentCreator {_dc :=ContentStreamOperation {};_dc .Operand ="\u0043\u0053";_dc .Params =_dfef ([]_ga .PdfObjectName {name });_gfa ._da =append (_gfa ._da ,&_dc );return _gfa ;};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tj appends 'Tj' operand to the content stream:
|
|
|
|
// Show a text string.
|
|
|
|
//
|
|
|
|
// See section 9.4.3 "Text Showing Operators" and
|
|
|
|
// Table 209 (pp. 258-259 PDF32000_2008).
|
|
|
|
func (_dga *ContentCreator )Add_Tj (textstr _ga .PdfObjectString )*ContentCreator {_egf :=ContentStreamOperation {};_egf .Operand ="\u0054\u006a";_egf .Params =_fabc ([]_ga .PdfObjectString {textstr });_dga ._da =append (_dga ._da ,&_egf );return _dga ;};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// String is same as Bytes() except returns as a string for convenience.
|
|
|
|
func (_eg *ContentCreator )String ()string {return string (_eg ._da .Bytes ())};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_w adds 'w' operand to the content stream, which sets the line width.
|
|
|
|
//
|
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_eee *ContentCreator )Add_w (lineWidth float64 )*ContentCreator {_fcg :=ContentStreamOperation {};_fcg .Operand ="\u0077";_fcg .Params =_gegg ([]float64 {lineWidth });_eee ._da =append (_eee ._da ,&_fcg );return _eee ;};
|
|
|
|
|
|
|
|
// ContentStreamProcessor defines a data structure and methods for processing a content stream, keeping track of the
|
|
|
|
// current graphics state, and allowing external handlers to define their own functions as a part of the processing,
|
|
|
|
// for example rendering or extracting certain information.
|
|
|
|
type ContentStreamProcessor struct{_cdda GraphicStateStack ;_cfcad []*ContentStreamOperation ;_bgba GraphicsState ;_fab []handlerEntry ;_abdb int ;};
|
|
|
|
|
|
|
|
// Bytes converts a set of content stream operations to a content stream byte presentation,
|
|
|
|
// i.e. the kind that can be stored as a PDF stream or string format.
|
|
|
|
func (_fb *ContentStreamOperations )Bytes ()[]byte {var _bgb _f .Buffer ;for _ ,_ef :=range *_fb {if _ef ==nil {continue ;};if _ef .Operand =="\u0042\u0049"{_bgb .WriteString (_ef .Operand +"\u000a");_bgb .WriteString (_ef .Params [0].WriteString ());}else {for _ ,_cb :=range _ef .Params {_bgb .WriteString (_cb .WriteString ());_bgb .WriteString ("\u0020");};_bgb .WriteString (_ef .Operand +"\u000a");};};return _bgb .Bytes ();};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-27 21:45:09 +00:00
|
|
|
// Add_BT appends 'BT' operand to the content stream:
|
|
|
|
// Begin text.
|
|
|
|
//
|
|
|
|
// See section 9.4 "Text Objects" and Table 107 (p. 256 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_eegd *ContentCreator )Add_BT ()*ContentCreator {_gec :=ContentStreamOperation {};_gec .Operand ="\u0042\u0054";_eegd ._da =append (_eegd ._da ,&_gec );return _eegd ;};func (_dffa *ContentStreamInlineImage )toImageBase (_fdgb *_ea .PdfPageResources )(*_fc .ImageBase ,error ){if _dffa ._gdb !=nil {return _dffa ._gdb ,nil ;};_defff :=_fc .ImageBase {};if _dffa .Height ==nil {return nil ,_g .New ("\u0068e\u0069\u0067\u0068\u0074\u0020\u0061\u0074\u0074\u0072\u0069\u0062u\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_cea ,_gaad :=_dffa .Height .(*_ga .PdfObjectInteger );if !_gaad {return nil ,_g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0068e\u0069\u0067\u0068\u0074");};_defff .Height =int (*_cea );if _dffa .Width ==nil {return nil ,_g .New ("\u0077\u0069\u0064th\u0020\u0061\u0074\u0074\u0072\u0069\u0062\u0075\u0074\u0065\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067");};_geg ,_gaad :=_dffa .Width .(*_ga .PdfObjectInteger );if !_gaad {return nil ,_g .New ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0077\u0069\u0064\u0074\u0068");};_defff .Width =int (*_geg );_afd ,_adce :=_dffa .IsMask ();if _adce !=nil {return nil ,_adce ;};if _afd {_defff .BitsPerComponent =1;_defff .ColorComponents =1;}else {if _dffa .BitsPerComponent ==nil {_bgc .Log .Debug ("\u0049\u006el\u0069\u006e\u0065\u0020\u0042\u0069\u0074\u0073\u0020\u0070\u0065\u0072\u0020\u0063\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067\u0020\u002d\u0020\u0061\u0073\u0073\u0075\u006d\u0069\u006e\u0067\u0020\u0038");_defff .BitsPerComponent =8;}else {_dbcc ,_aea :=_dffa .BitsPerComponent .(*_ga .PdfObjectInteger );if !_aea {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u0020\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u0062\u0069\u0074\u0073 p\u0065\u0072\u0020\u0063o\u006d\u0070\u006f\u006e\u0065\u006e\u0074\u0020\u0076al\u0075\u0065,\u0020\u0074\u0079\u0070\u0065\u0020\u0025\u0054",_dffa .BitsPerComponent );return nil ,_g .New ("\u0042\u0050\u0043\u0020\u0054\u0079\u0070\u0065\u0020e\u0072\u0072\u006f\u0072");};_defff .BitsPerComponent =int (*_dbcc );};if _dffa .ColorSpace !=nil {_deag ,_eae :=_dffa .GetColorSpace (_fdgb );if _eae !=nil {return nil ,_eae ;};_defff .ColorComponents =_deag .GetNumComponents ();}else {_bgc .Log .Debug ("\u0049\u006el\u0069\u006e\u0065\u0020\u0049\u006d\u0061\u0067\u0065\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063e\u0020\u006e\u006f\u0074\u0020\u0073p\u0065\u0063\u0069\u0066\u0069\u0065\u0064\u0020\u002d\u0020\u0061\u0073\u0073\u0075m\u0069\u006eg\u0020\u0031\u0020\u0063o\u006c\u006f\u0072\u0020\u0063o\u006d\u0070\u006f\u006e\u0065\u006e\u0074");_defff .ColorComponents =1;};};if _ddf ,_deae :=_ga .GetArray (_dffa .Decode );_deae {_defff .Decode ,_adce =_ddf .ToFloat64Array ();if _adce !=nil {return nil ,_adce ;};};_dffa ._gdb =&_defff ;return _dffa ._gdb ,nil ;};
|
2017-03-14 13:04:51 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ExtractText parses and extracts all text data in content streams and returns as a string.
|
|
|
|
// Does not take into account Encoding table, the output is simply the character codes.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// Deprecated: More advanced text extraction is offered in package extractor with character encoding support.
|
|
|
|
func (_ce *ContentStreamParser )ExtractText ()(string ,error ){_bbd ,_fe :=_ce .Parse ();if _fe !=nil {return "",_fe ;};_gb :=false ;_ca ,_cc :=float64 (-1),float64 (-1);_gag :="";for _ ,_dff :=range *_bbd {if _dff .Operand =="\u0042\u0054"{_gb =true ;}else if _dff .Operand =="\u0045\u0054"{_gb =false ;};if _dff .Operand =="\u0054\u0064"||_dff .Operand =="\u0054\u0044"||_dff .Operand =="\u0054\u002a"{_gag +="\u000a";};if _dff .Operand =="\u0054\u006d"{if len (_dff .Params )!=6{continue ;};_ba ,_ab :=_dff .Params [4].(*_ga .PdfObjectFloat );if !_ab {_aaf ,_ec :=_dff .Params [4].(*_ga .PdfObjectInteger );if !_ec {continue ;};_ba =_ga .MakeFloat (float64 (*_aaf ));};_gfd ,_ab :=_dff .Params [5].(*_ga .PdfObjectFloat );if !_ab {_ecc ,_ad :=_dff .Params [5].(*_ga .PdfObjectInteger );if !_ad {continue ;};_gfd =_ga .MakeFloat (float64 (*_ecc ));};if _cc ==-1{_cc =float64 (*_gfd );}else if _cc > float64 (*_gfd ){_gag +="\u000a";_ca =float64 (*_ba );_cc =float64 (*_gfd );continue ;};if _ca ==-1{_ca =float64 (*_ba );}else if _ca < float64 (*_ba ){_gag +="\u0009";_ca =float64 (*_ba );};};if _gb &&_dff .Operand =="\u0054\u004a"{if len (_dff .Params )< 1{continue ;};_ge ,_abg :=_dff .Params [0].(*_ga .PdfObjectArray );if !_abg {return "",_e .Errorf ("\u0069\u006ev\u0061\u006c\u0069\u0064 \u0070\u0061r\u0061\u006d\u0065\u0074\u0065\u0072\u0020\u0074y\u0070\u0065\u002c\u0020\u006e\u006f\u0020\u0061\u0072\u0072\u0061\u0079 \u0028\u0025\u0054\u0029",_dff .Params [0]);};for _ ,_baf :=range _ge .Elements (){switch _faf :=_baf .(type ){case *_ga .PdfObjectString :_gag +=_faf .Str ();case *_ga .PdfObjectFloat :if *_faf < -100{_gag +="\u0020";};case *_ga .PdfObjectInteger :if *_faf < -100{_gag +="\u0020";};};};}else if _gb &&_dff .Operand =="\u0054\u006a"{if len (_dff .Params )< 1{continue ;};_abf ,_ee :=_dff .Params [0].(*_ga .PdfObjectString );if !_ee {return "",_e .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0070\u0061\u0072\u0061\u006de\u0074\u0065\u0072\u0020\u0074\u0079p\u0065\u002c\u0020\u006e\u006f\u0074\u0020\u0073\u0074\u0072\u0069\u006e\u0067 \u0028\u0025\u0054\u0029",_dff .Params [0]);};_gag +=_abf .Str ();};};return _gag ,nil ;};func _fabc (_babb []_ga .PdfObjectString )[]_ga .PdfObject {var _abbc []_ga .PdfObject ;for _ ,_dcfg :=range _babb {_abbc =append (_abbc ,_ga .MakeString (_dcfg .Str ()));};return _abbc ;};
|
2018-10-05 01:59:19 +00:00
|
|
|
|
2020-08-27 21:45:09 +00:00
|
|
|
// Add_Q adds 'Q' operand to the content stream: Pops the most recently stored state from the stack.
|
2018-03-22 13:01:04 +00:00
|
|
|
//
|
2020-08-27 21:45:09 +00:00
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_cbe *ContentCreator )Add_Q ()*ContentCreator {_eeg :=ContentStreamOperation {};_eeg .Operand ="\u0051";_cbe ._da =append (_cbe ._da ,&_eeg );return _cbe ;};func (_gef *ContentStreamProcessor )getColorspace (_geba string ,_fdcg *_ea .PdfPageResources )(_ea .PdfColorspace ,error ){switch _geba {case "\u0044\u0065\u0076\u0069\u0063\u0065\u0047\u0072\u0061\u0079":return _ea .NewPdfColorspaceDeviceGray (),nil ;case "\u0044e\u0076\u0069\u0063\u0065\u0052\u0047B":return _ea .NewPdfColorspaceDeviceRGB (),nil ;case "\u0044\u0065\u0076\u0069\u0063\u0065\u0043\u004d\u0059\u004b":return _ea .NewPdfColorspaceDeviceCMYK (),nil ;case "\u0050a\u0074\u0074\u0065\u0072\u006e":return _ea .NewPdfColorspaceSpecialPattern (),nil ;};_aacf ,_fbed :=_fdcg .GetColorspaceByName (_ga .PdfObjectName (_geba ));if _fbed {return _aacf ,nil ;};switch _geba {case "\u0043a\u006c\u0047\u0072\u0061\u0079":return _ea .NewPdfColorspaceCalGray (),nil ;case "\u0043\u0061\u006c\u0052\u0047\u0042":return _ea .NewPdfColorspaceCalRGB (),nil ;case "\u004c\u0061\u0062":return _ea .NewPdfColorspaceLab (),nil ;};_bgc .Log .Debug ("\u0055\u006e\u006b\u006e\u006f\u0077\u006e\u0020\u0063\u006f\u006c\u006f\u0072\u0073\u0070a\u0063e\u0020\u0072\u0065\u0071\u0075\u0065\u0073\u0074\u0065\u0064\u003a\u0020\u0025\u0073",_geba );return nil ,_e .Errorf ("\u0075\u006e\u0073\u0075\u0070\u0070\u006f\u0072\u0074\u0065\u0064 \u0063\u006f\u006c\u006f\u0072\u0073\u0070\u0061\u0063\u0065:\u0020\u0025\u0073",_geba );};func _bce (_accd *ContentStreamInlineImage ,_bcg *_ga .PdfObjectDictionary )(*_ga .FlateEncoder ,error ){_cae :=_ga .NewFlateEncoder ();if _accd ._gdb !=nil {_cae .SetImage (_accd ._gdb );};if _bcg ==nil {_bebc :=_accd .DecodeParms ;if _bebc !=nil {_eec ,_ddbc :=_ga .GetDict (_bebc );if !_ddbc {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073\u0020n\u006f\u0074\u0020\u0061\u0020\u0064\u0069\u0063\u0074\u0069on\u0061\u0072\u0079 \u0028%\u0054\u0029",_bebc );return nil ,_e .Errorf ("\u0069\u006e\u0076\u0061li\u0064\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073");};_bcg =_eec ;};};if _bcg ==nil {return _cae ,nil ;};_bgc .Log .Trace ("\u0064\u0065\u0063\u006f\u0064\u0065\u0020\u0070\u0061\u0072\u0061\u006ds\u003a\u0020\u0025\u0073",_bcg .String ());_bdf :=_bcg .Get ("\u0050r\u0065\u0064\u0069\u0063\u0074\u006fr");if _bdf ==nil {_bgc .Log .Debug ("E\u0072\u0072o\u0072\u003a\u0020\u0050\u0072\u0065\u0064\u0069\u0063\u0074\u006f\u0072\u0020\u006d\u0069\u0073\u0073\u0069\u006e\u0067 \u0066\u0072\u006f\u006d\u0020\u0044\u0065\u0063\u006f\u0064\u0065\u0050\u0061\u0072\u006d\u0073 \u002d\u0020\u0043\u006f\u006e\u0074\u0069\u006e\u0075\u0065\u0020\u0077\u0069t\u0068\u0020\u0064\u0065\u0066\u0061\u0075\u006c\u0074\u0020\u00281\u0029");}else {_bga ,_gabf :=_bdf .(*_ga .PdfObjectInteger );if !_gabf {_bgc .Log .Debug ("E\u0072\u0072\u006f\u0072\u003a\u0020\u0050\u0072\u0065d\u0069\u0063\u0074\u006f\u0072\u0020\u0073pe\u0063\u0069\u0066\u0069e\u0064\u0020\u0062\u0075\u0074\u0020\u006e\u006f\u0074 n\u0075\u006de\u0072\u0069\u0063\u0020\u0028\u0025\u0054\u0029",_bdf );return nil ,_e .Errorf ("\u0069\u006e\u0076\u0061\u006c\u0069\u0064\u0020\u0050\u0072\u0065\u0064i\u0063\u0074\u006f\u0072");};_cae .Predictor =int (*_bga );};_bdf =_bcg .Get ("\u0042\u0069t\u0073\u0050\u0065r\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");if _bdf !=nil {_gfe ,_cbf :=_bdf .(*_ga .PdfObjectInteger );if !_cbf {_bgc .Log .Debug ("\u0045\u0052\u0052O\u0052\u003a\u0020\u0049n\u0076\u0061\u006c\u0069\u0064\u0020\u0042i\u0074\u0073\u0050\u0065\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");return nil ,_e .Errorf ("\u0069n\u0076\u0061\u006c\u0069\u0064\u0020\u0042\u0069\u0074\u0073\u0050e\u0072\u0043\u006f\u006d\u0070\u006f\u006e\u0065\u006e\u0074");};_cae .BitsPerComponent =int (*_gfe );};if _cae .Predictor > 1{_cae .Columns =1;_bdf =_bcg .Get ("\u0043o\u006c\u0075\u006d\u006e\u0073");if _bdf !=nil {_ecce ,_fgc :=_bdf .(*_ga .PdfObjectInteger );if !_fgc {return nil ,_e .Errorf ("\u0070r\u00
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_n appends 'n' operand to the content stream:
|
|
|
|
// End the path without filling or stroking.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_ffa *ContentCreator )Add_n ()*ContentCreator {_debc :=ContentStreamOperation {};_debc .Operand ="\u006e";_ffa ._da =append (_ffa ._da ,&_debc );return _ffa ;};func (_cga *ContentStreamProcessor )handleCommand_G (_agba *ContentStreamOperation ,_cef *_ea .PdfPageResources )error {_cbbf :=_ea .NewPdfColorspaceDeviceGray ();if len (_agba .Params )!=_cbbf .GetNumComponents (){_bgc .Log .Debug ("I\u006e\u0076\u0061\u006c\u0069\u0064 \u006e\u0075\u006d\u0062\u0065\u0072 \u006f\u0066\u0020\u0070\u0061\u0072\u0061m\u0065\u0074\u0065\u0072\u0073\u0020\u0066\u006f\u0072\u0020S\u0043");_bgc .Log .Debug ("\u004e\u0075mb\u0065\u0072\u0020%\u0064\u0020\u006e\u006ft m\u0061tc\u0068\u0069\u006e\u0067\u0020\u0063\u006flo\u0072\u0073\u0070\u0061\u0063\u0065\u0020%\u0054",len (_agba .Params ),_cbbf );return _g .New ("\u0069\u006e\u0076\u0061l\u0069\u0064\u0020\u006e\u0075\u006d\u0062\u0065\u0072\u0020o\u0066 \u0070\u0061\u0072\u0061\u006d\u0065\u0074e\u0072\u0073");};_bace ,_fgbd :=_cbbf .ColorFromPdfObjects (_agba .Params );if _fgbd !=nil {return _fgbd ;};_cga ._bgba .ColorspaceStroking =_cbbf ;_cga ._bgba .ColorStroking =_bace ;return nil ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_cm adds 'cm' operation to the content stream: Modifies the current transformation matrix (ctm)
|
|
|
|
// of the graphics state.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 8.4.4 "Graphic State Operators" and Table 57 (pp. 135-136 PDF32000_2008).
|
|
|
|
func (_ae *ContentCreator )Add_cm (a ,b ,c ,d ,e ,f float64 )*ContentCreator {_ddbe :=ContentStreamOperation {};_ddbe .Operand ="\u0063\u006d";_ddbe .Params =_gegg ([]float64 {a ,b ,c ,d ,e ,f });_ae ._da =append (_ae ._da ,&_ddbe );return _ae ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// IsMask checks if an image is a mask.
|
|
|
|
// The image mask entry in the image dictionary specifies that the image data shall be used as a stencil
|
|
|
|
// mask for painting in the current color. The mask data is 1bpc, grayscale.
|
|
|
|
func (_ddc *ContentStreamInlineImage )IsMask ()(bool ,error ){if _ddc .ImageMask !=nil {_fdgd ,_edcg :=_ddc .ImageMask .(*_ga .PdfObjectBool );if !_edcg {_bgc .Log .Debug ("\u0049m\u0061\u0067\u0065\u0020\u006d\u0061\u0073\u006b\u0020\u006e\u006ft\u0020\u0061\u0020\u0062\u006f\u006f\u006c\u0065\u0061\u006e");return false ,_g .New ("\u0069\u006e\u0076\u0061li\u0064\u0020\u006f\u0062\u006a\u0065\u0063\u0074\u0020\u0074\u0079\u0070\u0065");};return bool (*_fdgd ),nil ;};return false ,nil ;};
|
|
|
|
|
|
|
|
// Add_EMC appends 'EMC' operand to the content stream:
|
|
|
|
// Ends a marked-content sequence.
|
|
|
|
//
|
|
|
|
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
|
|
|
|
func (_ccbg *ContentCreator )Add_EMC ()*ContentCreator {_fafb :=ContentStreamOperation {};_fafb .Operand ="\u0045\u004d\u0043";_ccbg ._da =append (_ccbg ._da ,&_fafb );return _ccbg ;};
|
|
|
|
|
|
|
|
// Add_v appends 'v' operand to the content stream: Append a Bezier curve to the current path from the
|
|
|
|
// current point to (x3,y3) with the current point and (x2,y2) as control points.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_fafg *ContentCreator )Add_v (x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_cf :=ContentStreamOperation {};_cf .Operand ="\u0076";_cf .Params =_gegg ([]float64 {x2 ,y2 ,x3 ,y3 });_fafg ._da =append (_fafg ._da ,&_cf );return _fafg ;};
|
|
|
|
|
|
|
|
// Add_Tstar appends 'T*' operand to the content stream:
|
|
|
|
// Move to the start of next line.
|
|
|
|
//
|
|
|
|
// See section 9.4.2 "Text Positioning Operators" and
|
|
|
|
// Table 108 (pp. 257-258 PDF32000_2008).
|
|
|
|
func (_cdb *ContentCreator )Add_Tstar ()*ContentCreator {_eeeb :=ContentStreamOperation {};_eeeb .Operand ="\u0054\u002a";_cdb ._da =append (_cdb ._da ,&_eeeb );return _cdb ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
|
|
|
// Add_s appends 's' operand to the content stream: Close and stroke the path.
|
|
|
|
//
|
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_gdd *ContentCreator )Add_s ()*ContentCreator {_bbe :=ContentStreamOperation {};_bbe .Operand ="\u0073";_gdd ._da =append (_gdd ._da ,&_bbe );return _gdd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_BMC appends 'BMC' operand to the content stream:
|
|
|
|
// Begins a marked-content sequence terminated by a balancing EMC operator.
|
|
|
|
// `tag` shall be a name object indicating the role or significance of
|
|
|
|
// the sequence.
|
|
|
|
//
|
|
|
|
// See section 14.6 "Marked Content" and Table 320 (p. 561 PDF32000_2008).
|
|
|
|
func (_ccd *ContentCreator )Add_BMC (tag _ga .PdfObjectName )*ContentCreator {_dcf :=ContentStreamOperation {};_dcf .Operand ="\u0042\u004d\u0043";_dcf .Params =_dfef ([]_ga .PdfObjectName {tag });_ccd ._da =append (_ccd ._da ,&_dcf );return _ccd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_k appends 'k' operand to the content stream:
|
|
|
|
// Same as K but used for nonstroking operations.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.6.8 "Colour Operators" and Table 74 (p. 179-180 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_cfc *ContentCreator )Add_k (c ,m ,y ,k float64 )*ContentCreator {_fcc :=ContentStreamOperation {};_fcc .Operand ="\u006b";_fcc .Params =_gegg ([]float64 {c ,m ,y ,k });_cfc ._da =append (_cfc ._da ,&_fcc );return _cfc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// NewContentStreamProcessor returns a new ContentStreamProcessor for operations `ops`.
|
|
|
|
func NewContentStreamProcessor (ops []*ContentStreamOperation )*ContentStreamProcessor {_ageea :=ContentStreamProcessor {};_ageea ._cdda =GraphicStateStack {};_abcge :=GraphicsState {};_ageea ._bgba =_abcge ;_ageea ._fab =[]handlerEntry {};_ageea ._abdb =0;_ageea ._cfcad =ops ;return &_ageea ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// All returns true if `hce` is equivalent to HandlerConditionEnumAllOperands.
|
|
|
|
func (_abcb HandlerConditionEnum )All ()bool {return _abcb ==HandlerConditionEnumAllOperands };func (_adaa *ContentStreamParser )parseArray ()(*_ga .PdfObjectArray ,error ){_gabb :=_ga .MakeArray ();_adaa ._bdec .ReadByte ();for {_adaa .skipSpaces ();_bacd ,_caa :=_adaa ._bdec .Peek (1);if _caa !=nil {return _gabb ,_caa ;};if _bacd [0]==']'{_adaa ._bdec .ReadByte ();break ;};_bagaa ,_ ,_caa :=_adaa .parseObject ();if _caa !=nil {return _gabb ,_caa ;};_gabb .Append (_bagaa );};return _gabb ,nil ;};func (_dgf *ContentStreamInlineImage )String ()string {_adfd :=_e .Sprintf ("I\u006el\u0069\u006e\u0065\u0049\u006d\u0061\u0067\u0065(\u006c\u0065\u006e\u003d%d\u0029\u000a",len (_dgf ._bfg ));if _dgf .BitsPerComponent !=nil {_adfd +="\u002d\u0020\u0042\u0050\u0043\u0020"+_dgf .BitsPerComponent .WriteString ()+"\u000a";};if _dgf .ColorSpace !=nil {_adfd +="\u002d\u0020\u0043S\u0020"+_dgf .ColorSpace .WriteString ()+"\u000a";};if _dgf .Decode !=nil {_adfd +="\u002d\u0020\u0044\u0020"+_dgf .Decode .WriteString ()+"\u000a";};if _dgf .DecodeParms !=nil {_adfd +="\u002d\u0020\u0044P\u0020"+_dgf .DecodeParms .WriteString ()+"\u000a";};if _dgf .Filter !=nil {_adfd +="\u002d\u0020\u0046\u0020"+_dgf .Filter .WriteString ()+"\u000a";};if _dgf .Height !=nil {_adfd +="\u002d\u0020\u0048\u0020"+_dgf .Height .WriteString ()+"\u000a";};if _dgf .ImageMask !=nil {_adfd +="\u002d\u0020\u0049M\u0020"+_dgf .ImageMask .WriteString ()+"\u000a";};if _dgf .Intent !=nil {_adfd +="\u002d \u0049\u006e\u0074\u0065\u006e\u0074 "+_dgf .Intent .WriteString ()+"\u000a";};if _dgf .Interpolate !=nil {_adfd +="\u002d\u0020\u0049\u0020"+_dgf .Interpolate .WriteString ()+"\u000a";};if _dgf .Width !=nil {_adfd +="\u002d\u0020\u0057\u0020"+_dgf .Width .WriteString ()+"\u000a";};return _adfd ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Pop pops and returns the topmost GraphicsState off the `gsStack`.
|
|
|
|
func (_dfb *GraphicStateStack )Pop ()GraphicsState {_dcgg :=(*_dfb )[len (*_dfb )-1];*_dfb =(*_dfb )[:len (*_dfb )-1];return _dcgg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tz appends 'Tz' operand to the content stream:
|
|
|
|
// Set horizontal scaling.
|
|
|
|
//
|
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
|
|
func (_fafc *ContentCreator )Add_Tz (scale float64 )*ContentCreator {_gga :=ContentStreamOperation {};_gga .Operand ="\u0054\u007a";_gga .Params =_gegg ([]float64 {scale });_fafc ._da =append (_fafc ._da ,&_gga );return _fafc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_Tr appends 'Tr' operand to the content stream:
|
|
|
|
// Set text rendering mode.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
2020-08-31 21:12:07 +00:00
|
|
|
// See section 9.3 "Text State Parameters and Operators" and
|
|
|
|
// Table 105 (pp. 251-252 PDF32000_2008).
|
|
|
|
func (_ccg *ContentCreator )Add_Tr (render int64 )*ContentCreator {_ceba :=ContentStreamOperation {};_ceba .Operand ="\u0054\u0072";_ceba .Params =_gbbe ([]int64 {render });_ccg ._da =append (_ccg ._da ,&_ceba );return _ccg ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_W appends 'W' operand to the content stream:
|
|
|
|
// Modify the current clipping path by intersecting with the current path (nonzero winding rule).
|
|
|
|
//
|
|
|
|
// See section 8.5.4 "Clipping Path Operators" and Table 61 (p. 146 PDF32000_2008).
|
|
|
|
func (_edbc *ContentCreator )Add_W ()*ContentCreator {_dea :=ContentStreamOperation {};_dea .Operand ="\u0057";_edbc ._da =append (_edbc ._da ,&_dea );return _edbc ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// Add_B appends 'B' operand to the content stream:
|
|
|
|
// Fill and then stroke the path (nonzero winding number rule).
|
|
|
|
//
|
|
|
|
// See section 8.5.3 "Path Painting Operators" and Table 60 (p. 143 PDF32000_2008).
|
|
|
|
func (_gfg *ContentCreator )Add_B ()*ContentCreator {_dba :=ContentStreamOperation {};_dba .Operand ="\u0042";_gfg ._da =append (_gfg ._da ,&_dba );return _gfg ;};
|
|
|
|
|
|
|
|
// Add_c adds 'c' operand to the content stream: Append a Bezier curve to the current path from
|
|
|
|
// the current point to (x3,y3) with (x1,x1) and (x2,y2) as control points.
|
2020-08-27 21:45:09 +00:00
|
|
|
//
|
|
|
|
// See section 8.5.2 "Path Construction Operators" and Table 59 (pp. 140-141 PDF32000_2008).
|
2020-08-31 21:12:07 +00:00
|
|
|
func (_eda *ContentCreator )Add_c (x1 ,y1 ,x2 ,y2 ,x3 ,y3 float64 )*ContentCreator {_bba :=ContentStreamOperation {};_bba .Operand ="\u0063";_bba .Params =_gegg ([]float64 {x1 ,y1 ,x2 ,y2 ,x3 ,y3 });_eda ._da =append (_eda ._da ,&_bba );return _eda ;};
|
2020-08-27 21:45:09 +00:00
|
|
|
|
2020-08-31 21:12:07 +00:00
|
|
|
// ToImage exports the inline image to Image which can be transformed or exported easily.
|
|
|
|
// Page resources are needed to look up colorspace information.
|
|
|
|
func (_dfc *ContentStreamInlineImage )ToImage (resources *_ea .PdfPageResources )(*_ea .Image ,error ){_ebb ,_deab :=_dfc .toImageBase (resources );if _deab !=nil {return nil ,_deab ;};_bae ,_deab :=_bgd (_dfc );if _deab !=nil {return nil ,_deab ;};_bgc .Log .Trace ("\u0065n\u0063o\u0064\u0065\u0072\u003a\u0020\u0025\u002b\u0076\u0020\u0025\u0054",_bae ,_bae );_bgc .Log .Trace ("\u0069\u006e\u006c\u0069\u006e\u0065\u0020\u0069\u006d\u0061\u0067\u0065:\u0020\u0025\u002b\u0076",_dfc );_eed ,_deab :=_bae .DecodeBytes (_dfc ._bfg );if _deab !=nil {return nil ,_deab ;};_eff :=&_ea .Image {Width :int64 (_ebb .Width ),Height :int64 (_ebb .Height ),BitsPerComponent :int64 (_ebb .BitsPerComponent ),ColorComponents :_ebb .ColorComponents ,Data :_eed };if len (_ebb .Decode )> 0{for _egab :=0;_egab < len (_ebb .Decode );_egab ++{_ebb .Decode [_egab ]*=float64 ((int (1)<<uint (_ebb .BitsPerComponent ))-1);};_eff .SetDecode (_ebb .Decode );};return _eff ,nil ;};
|