Exemplo n.º 1
0
 public override void EventOccurred(IEventData data, EventType type)
 {
     if (type.Equals(EventType.RENDER_TEXT) || type.Equals(EventType.RENDER_IMAGE))
     {
         String tagName = GetTagName(data, type);
         if ((tagName == null && layerName == null) || (layerName != null && layerName.Equals(tagName)))
         {
             if (type.Equals(EventType.RENDER_TEXT))
             {
                 TextRenderInfo renderInfo = (TextRenderInfo)data;
                 SetFillColor(renderInfo.GetGraphicsState().GetFillColor());
                 SetPdfFont(renderInfo.GetGraphicsState().GetFont());
                 base.EventOccurred(data, type);
             }
             else
             {
                 if (type.Equals(EventType.RENDER_IMAGE))
                 {
                     ImageRenderInfo renderInfo = (ImageRenderInfo)data;
                     Matrix          ctm        = renderInfo.GetImageCtm();
                     SetImageBBoxRectangle(new Rectangle(ctm.Get(6), ctm.Get(7), ctm.Get(0), ctm.Get(4)));
                 }
             }
         }
     }
 }
Exemplo n.º 2
0
 public virtual void EventOccurred(IEventData data, EventType type)
 {
     if (data is TextRenderInfo)
     {
         TextRenderInfo renderInfo = (TextRenderInfo)data;
         map.Put("String", renderInfo.GetPdfString().ToUnicodeString());
         map.Put("FillOpacity", renderInfo.GetGraphicsState().GetFillOpacity());
         map.Put("StrokeOpacity", renderInfo.GetGraphicsState().GetStrokeOpacity());
     }
 }
Exemplo n.º 3
0
        public Color?GetColor(TextRenderInfo text)
        {
            iText.Kernel.Colors.Color color;

            float alpha;

            switch (text.GetTextRenderMode())
            {
            case 0:     // Fill text
            case 4:     // Fill text and add to path for clipping
                color = text.GetFillColor();
                alpha = text.GetGraphicsState().GetFillOpacity();
                break;

            case 1:     //  Stroke text
            case 2:     //Fill, then stroke text
            case 5:     // Stroke text and add to path for clipping
            case 6:     // Fill, then stroke text and add to path for clipping
                color = text.GetStrokeColor();
                alpha = text.GetGraphicsState().GetStrokeOpacity();
                break;

            case 3:     // Invisible
                return(System.Drawing.Color.Transparent);

            case 7:     // Add text to padd for clipping
                return(System.Drawing.Color.Black);

            default: throw new ApplicationException("wrong render mode");
            }


//           var value = text.GetStrokeColor().GetColorValue();
//           if(value.Length==1&&value[0]==0)
//               value = text.GetFillColor().GetColorValue();
            return(GetColor(color, alpha));
        }
Exemplo n.º 4
0
        public float GetFontSize(TextRenderInfo textRenderInfo, LineSegment baseline, LineSegment ascentLine)
        {
            var fontSize = textRenderInfo.GetFontSize();
            var height   = ascentLine.GetStartPoint().Get(1) - baseline.GetStartPoint().Get(1);

            if (fontSize > 0.99 && fontSize < 1.01)
            {
                LogWrongFontSize("no font size. take height of line:" + height);

                return(height * 1.05F);
            }

            var ctm        = textRenderInfo.GetGraphicsState().GetCtm();
            var heightFont = ctm.Get(Matrix.I22);

            if (heightFont > 0.99 && heightFont < 1.01)
            {
                if (fontSize > height * 1.3)
                {
                    LogWrongFontSize("big fontSize:" + fontSize + ". take height of line:" + height);
                    return(height * 1.3F);
                }
            }
            else
            {
                if (heightFont > 0)
                {
                    fontSize *= heightFont;
                    LogWrongFontSize("height font positive: " + heightFont);
                }
                else
                {
                    fontSize *= -heightFont;
                }
            }

            return(fontSize);
        }