Gs() private method

private Gs ( ) : GraphicsState
return GraphicsState
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi)
            {
                PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES);

                // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted
                // this is probably not necessary (if we fail on this, probably the entire content stream processing
                // operation should be rejected
                byte[] contentBytes;
                contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream);
                PdfArray matrix = stream.GetAsArray(PdfName.MATRIX);

                new PushGraphicsState().Invoke(processor, null, null);

                if (matrix != null)
                {
                    float  a          = matrix.GetAsNumber(0).FloatValue;
                    float  b          = matrix.GetAsNumber(1).FloatValue;
                    float  c          = matrix.GetAsNumber(2).FloatValue;
                    float  d          = matrix.GetAsNumber(3).FloatValue;
                    float  e          = matrix.GetAsNumber(4).FloatValue;
                    float  f          = matrix.GetAsNumber(5).FloatValue;
                    Matrix formMatrix = new Matrix(a, b, c, d, e, f);

                    processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm);
                }

                processor.ProcessContent(contentBytes, resources);

                new PopGraphicsState().Invoke(processor, null, null);
            }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfName       dictionaryName = (PdfName)operands[0];
                PdfDictionary extGState      = processor.resources.GetAsDict(PdfName.EXTGSTATE);

                if (extGState == null)
                {
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("resources.do.not.contain.extgstate.entry.unable.to.process.oper.1", oper));
                }
                PdfDictionary gsDic = extGState.GetAsDict(dictionaryName);

                if (gsDic == null)
                {
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("1.is.an.unknown.graphics.state.dictionary", dictionaryName));
                }

                // at this point, all we care about is the FONT entry in the GS dictionary
                PdfArray fontParameter = gsDic.GetAsArray(PdfName.FONT);

                if (fontParameter != null)
                {
                    CMapAwareDocumentFont font = processor.GetFont((PRIndirectReference)fontParameter[0]);
                    float size = fontParameter.GetAsNumber(1).FloatValue;

                    processor.Gs().font     = font;
                    processor.Gs().fontSize = size;
                }
            }
Beispiel #3
0
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfName fontResourceName = (PdfName)operands[0];
                float   size             = ((PdfNumber)operands[1]).FloatValue;

                PdfDictionary         fontsDictionary = processor.resources.GetAsDict(PdfName.FONT);
                CMapAwareDocumentFont font            = processor.GetFont((PRIndirectReference)fontsDictionary.Get(fontResourceName));

                processor.Gs().font     = font;
                processor.Gs().fontSize = size;
            }
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi)
            {
                PdfDictionary   colorSpaceDic = processor.resources.GetAsDict(PdfName.COLORSPACE);
                ImageRenderInfo renderInfo    = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi, colorSpaceDic);

                processor.renderListener.RenderImage(renderInfo);
            }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                List <PdfObject> tdoperands = new List <PdfObject>(2);

                tdoperands.Insert(0, new PdfNumber(0));
                tdoperands.Insert(1, new PdfNumber(-processor.Gs().leading));
                moveStartNextLine.Invoke(processor, null, tdoperands);
            }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     LineDashPattern pattern = new LineDashPattern(((PdfArray) operands[0]),
                                                   ((PdfNumber) operands[1]).FloatValue);
     processor.Gs().SetLineDashPattern(pattern);
 }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber wordSpace = (PdfNumber)operands[0];

                processor.Gs().wordSpacing = wordSpace.FloatValue;
            }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber leading = (PdfNumber)operands[0];

                processor.Gs().leading = leading.FloatValue;
            }
		    public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
			    processor.Gs().colorSpaceStroke = (PdfName)operands[0];		
		    }
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream stream, PdfIndirectReference refi) {
                
                PdfDictionary resources = stream.GetAsDict(PdfName.RESOURCES);

                // we read the content bytes up here so if it fails we don't leave the graphics state stack corrupted
                // this is probably not necessary (if we fail on this, probably the entire content stream processing
                // operation should be rejected
                byte[] contentBytes;
                contentBytes = ContentByteUtils.GetContentBytesFromContentObject(stream);
                PdfArray matrix = stream.GetAsArray(PdfName.MATRIX);

                new PushGraphicsState().Invoke(processor, null, null);

                if (matrix != null){
                    float a = matrix.GetAsNumber(0).FloatValue;
                    float b = matrix.GetAsNumber(1).FloatValue;
                    float c = matrix.GetAsNumber(2).FloatValue;
                    float d = matrix.GetAsNumber(3).FloatValue;
                    float e = matrix.GetAsNumber(4).FloatValue;
                    float f = matrix.GetAsNumber(5).FloatValue;
                    Matrix formMatrix = new Matrix(a, b, c, d, e, f);

                    processor.Gs().ctm = formMatrix.Multiply(processor.Gs().ctm);
                }

                processor.ProcessContent(contentBytes, resources);

                new PopGraphicsState().Invoke(processor, null, null);
                
            }
 virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
 {
     processor.Gs().strokeColor = GetColor(processor.Gs().colorSpaceStroke, operands);
 }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {

                PdfName dictionaryName = (PdfName)operands[0];
                PdfDictionary extGState = processor.resources.GetAsDict(PdfName.EXTGSTATE);
                if (extGState == null)
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("resources.do.not.contain.extgstate.entry.unable.to.process.oper.1", oper));
                PdfDictionary gsDic = extGState.GetAsDict(dictionaryName);
                if (gsDic == null)
                    throw new ArgumentException(MessageLocalization.GetComposedMessage("1.is.an.unknown.graphics.state.dictionary", dictionaryName));

                // at this point, all we care about is the FONT entry in the GS dictionary
                PdfArray fontParameter = gsDic.GetAsArray(PdfName.FONT);
                if (fontParameter != null){
                    CMapAwareDocumentFont font = processor.GetFont((PRIndirectReference)fontParameter[0]);
                    float size = fontParameter.GetAsNumber(1).FloatValue;

                    processor.Gs().font = font;
                    processor.Gs().fontSize = size;
                }
            }
 virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
 {
     processor.Gs().fillColor = GetColor(4, operands);
 }
 virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
 {
     processor.Gs().colorSpaceStroke = (PdfName)operands[0];
 }
            virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber charSpace = (PdfNumber)operands[0];

                processor.Gs().characterSpacing = charSpace.FloatValue;
            }
            virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber rise = (PdfNumber)operands[0];

                processor.Gs().rise = rise.FloatValue;
            }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     float lineWidth = ((PdfNumber) operands[0]).FloatValue;
     processor.Gs().LineWidth = lineWidth;
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber scale = (PdfNumber)operands[0];
     processor.Gs().horizontalScaling = scale.FloatValue/100f;
 }
        public virtual void Invoke(PdfContentStreamProcessor pdfContentStreamProcessor, PdfLiteral oper, List<PdfObject> operands) {
            String operatorStr = oper.ToString();
            PdfContentByte canvas = cleanUpStrategy.Context.Canvas;
            PRStream xFormStream = null;
            bool disableOutput = pathConstructionOperators.Contains(operatorStr) || pathPaintingOperators.Contains(operatorStr) || clippingPathOperators.Contains(operatorStr);

            // key - number of a string in the TJ operator, value - number following the string; the first number without string (if it's presented) is stored under 0.
            // BE AWARE: zero-length strings are ignored!!!
            IDictionary<int, float> structuredTJoperands = null;

            if ("Do" == operatorStr) {
                if (operands.Count == 2 && operands[0].IsName()) {
                    PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);

                    if (xObjResources != null) {
                        PdfStream xObj = xObjResources.GetAsStream((PdfName) operands[0]);

                        if (xObj is PRStream && xObj.GetAsName(PdfName.SUBTYPE) != null &&
                                xObj.GetAsName(PdfName.SUBTYPE).CompareTo(PdfName.FORM) == 0) {
                            xFormStream = (PRStream) xObj;
                            cleanUpStrategy.RegisterNewContext(xObj.GetAsDict(PdfName.RESOURCES), null);
                        }
                    }
                }
            }

            originalContentOperator.Invoke(pdfContentStreamProcessor, oper, operands);
            IList<PdfCleanUpContentChunk> chunks = cleanUpStrategy.Chunks;

            if (xFormStream != null) {
                xFormStream.SetData(cleanUpStrategy.Context.Canvas.ToPdf(cleanUpStrategy.Context.Canvas.PdfWriter));
                cleanUpStrategy.PopContext();
                canvas = cleanUpStrategy.Context.Canvas;
            }

            if ("Do" == operatorStr) {
                if (chunks.Count > 0 && chunks[0] is PdfCleanUpContentChunk.Image) {
                    PdfCleanUpContentChunk.Image chunk = (PdfCleanUpContentChunk.Image) chunks[0];

                    if (chunk.Visible) {
                        PdfDictionary xObjResources = cleanUpStrategy.Context.Resources.GetAsDict(PdfName.XOBJECT);
                        PRStream imageStream = (PRStream) xObjResources.GetAsStream((PdfName) operands[0]);
                        UpdateImageStream(imageStream, chunk.NewImageData);
                    } else {
                        disableOutput = true;
                    }
                }
            } else if (lineStyleOperators.Contains(operatorStr)) {
                disableOutput = true;
            } else if (textShowingOperators.Contains(operatorStr) && !AllChunksAreVisible(cleanUpStrategy.Chunks)) {
                disableOutput = true;

                if ("'" == operatorStr) {
                    canvas.InternalBuffer.Append(TStar);
                } else if ("\"" == operatorStr) {
                    operands[0].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(Tw);

                    operands[1].ToPdf(canvas.PdfWriter, canvas.InternalBuffer);
                    canvas.InternalBuffer.Append(TcTStar);
                } else if ("TJ" == operatorStr) {
                    structuredTJoperands = StructureTJarray((PdfArray) operands[0]);
                }

                GraphicsState gs = pdfContentStreamProcessor.Gs();

                WriteTextChunks(structuredTJoperands, chunks, canvas, gs.CharacterSpacing, gs.WordSpacing, 
                    gs.FontSize, gs.HorizontalScaling);
            } else if (pathPaintingOperators.Contains(operatorStr)) {
                WritePath(operatorStr, canvas);
            } else if (strokeColorOperators.Contains(operatorStr)) {
                // Replace current color with the new one.
                cleanUpStrategy.Context.PopStrokeColor();
                cleanUpStrategy.Context.PushStrokeColor(operands);
            } else if ("q" == operatorStr) {
                cleanUpStrategy.Context.PushStrokeColor(cleanUpStrategy.Context.PeekStrokeColor());
            } else if ("Q" == operatorStr) {
                cleanUpStrategy.Context.PopStrokeColor();
            }

            if (!disableOutput) {
                WriteOperands(canvas, operands);
            }

            cleanUpStrategy.ClearChunks();
        }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber wordSpace = (PdfNumber)operands[0];
     processor.Gs().wordSpacing = wordSpace.FloatValue;
 }
 virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber rise = (PdfNumber)operands[0];
     processor.Gs().rise = rise.FloatValue;
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     processor.Gs().fillColor = GetColor(4, operands);
 }
 virtual public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber charSpace = (PdfNumber)operands[0];
     processor.Gs().characterSpacing = charSpace.FloatValue;
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     processor.Gs().strokeColor = GetColor(processor.Gs().colorSpaceStroke, operands);
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     List<PdfObject> tdoperands = new List<PdfObject>(2);
     tdoperands.Insert(0, new PdfNumber(0));
     tdoperands.Insert(1, new PdfNumber(-processor.Gs().leading));
     moveStartNextLine.Invoke(processor, null, tdoperands);
 }
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) {
     PdfDictionary colorSpaceDic = processor.resources.GetAsDict(PdfName.COLORSPACE);
     ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi, colorSpaceDic);
     processor.renderListener.RenderImage(renderInfo);
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     int lineJoin = ((PdfNumber) operands[0]).IntValue;
     processor.Gs().LineJoinStyle = lineJoin;
 }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber render = (PdfNumber)operands[0];

                processor.Gs().renderMode = render.IntValue;
            }
Beispiel #29
0
            public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi)
            {
                ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi);

                processor.renderListener.RenderImage(renderInfo);
            }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List <PdfObject> operands)
            {
                PdfNumber scale = (PdfNumber)operands[0];

                processor.Gs().horizontalScaling = scale.FloatValue / 100f;
            }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber leading = (PdfNumber)operands[0];
     processor.Gs().leading = leading.FloatValue;
 }
            public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
                PdfName fontResourceName = (PdfName)operands[0];
                float size = ((PdfNumber)operands[1]).FloatValue;

                PdfDictionary fontsDictionary = processor.resources.GetAsDict(PdfName.FONT);
                CMapAwareDocumentFont font;
                PdfObject fontObject = fontsDictionary.Get(fontResourceName);
                if (fontObject is PdfDictionary)
                    font = processor.GetFont((PdfDictionary)fontObject);
                else
                    font = processor.GetFont((PRIndirectReference)fontObject);

                processor.Gs().font = font;
                processor.Gs().fontSize = size;

            }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     float miterLimit = ((PdfNumber) operands[0]).FloatValue;
     processor.Gs().MiterLimit = miterLimit;
 }
 public void Invoke(PdfContentStreamProcessor processor, PdfLiteral oper, List<PdfObject> operands) {
     PdfNumber render = (PdfNumber)operands[0];
     processor.Gs().renderMode = render.IntValue;
 }
Beispiel #35
0
 public void HandleXObject(PdfContentStreamProcessor processor, PdfStream xobjectStream, PdfIndirectReference refi) {
     ImageRenderInfo renderInfo = ImageRenderInfo.CreateForXObject(processor.Gs().ctm, refi);
     processor.renderListener.RenderImage(renderInfo);
 }