public virtual void EventOccurred(IEventData data, EventType type) { if (type.Equals(EventType.RENDER_TEXT)) { TextRenderInfo renderInfo = (TextRenderInfo)data; LineSegment segment = renderInfo.GetBaseline(); if (renderInfo.GetRise() != 0) { // remove the rise from the baseline - we do this because the text from a super/subscript render operations should probably be considered as part of the baseline of the text the super/sub is relative to Matrix riseOffsetTransform = new Matrix(0, -renderInfo.GetRise()); segment = segment.TransformBy(riseOffsetTransform); } if (useActualText) { CanvasTag lastTagWithActualText = lastTextRenderInfo != null?FindLastTagWithActualText(lastTextRenderInfo .GetCanvasTagHierarchy()) : null; if (lastTagWithActualText != null && lastTagWithActualText == FindLastTagWithActualText(renderInfo.GetCanvasTagHierarchy ())) { // Merge two text pieces, assume they will be in the same line LocationTextExtractionStrategy.TextChunk lastTextChunk = locationalResult[locationalResult.Count - 1]; Vector mergedStart = new Vector(Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(0), segment.GetStartPoint ().Get(0)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(1), segment.GetStartPoint().Get (1)), Math.Min(lastTextChunk.GetLocation().GetStartLocation().Get(2), segment.GetStartPoint().Get(2))); Vector mergedEnd = new Vector(Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(0), segment.GetEndPoint ().Get(0)), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(1), segment.GetEndPoint().Get(1) ), Math.Max(lastTextChunk.GetLocation().GetEndLocation().Get(2), segment.GetEndPoint().Get(2))); LocationTextExtractionStrategy.TextChunk merged = new LocationTextExtractionStrategy.TextChunk(lastTextChunk .GetText(), tclStrat.CreateLocation(renderInfo, new LineSegment(mergedStart, mergedEnd))); locationalResult[locationalResult.Count - 1] = merged; } else { String actualText = renderInfo.GetActualText(); LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(actualText != null ? actualText : renderInfo.GetText(), tclStrat.CreateLocation(renderInfo, segment)); locationalResult.Add(tc); } } else { LocationTextExtractionStrategy.TextChunk tc = new LocationTextExtractionStrategy.TextChunk(renderInfo.GetText (), tclStrat.CreateLocation(renderInfo, segment)); locationalResult.Add(tc); } lastTextRenderInfo = renderInfo; } }
public virtual void EventOccurred(IEventData data, EventType type) { if (type.Equals(EventType.RENDER_TEXT)) { TextRenderInfo textRenderInfo = (TextRenderInfo)data; LineSegment lineSegment = textRenderInfo.GetBaseline(); if (textRenderInfo.GetRise() != 0f) { Matrix m = new Matrix(0f, -textRenderInfo.GetRise()); lineSegment = lineSegment.TransformBy(m); } if (this.useActualText) { CanvasTag canvasTag = (this.lastTextRenderInfo != null) ? this.FindLastTagWithActualText(this.lastTextRenderInfo.GetCanvasTagHierarchy()) : null; if (canvasTag != null && canvasTag == this.FindLastTagWithActualText(textRenderInfo.GetCanvasTagHierarchy())) { LocationTextExtractionStrategy2.TextChunk textChunk = this.locationalResult[this.locationalResult.Count - 1]; Vector startPoint = new Vector(Math.Min(textChunk.GetLocation().GetStartLocation().Get(0), lineSegment.GetStartPoint().Get(0)), Math.Min(textChunk.GetLocation().GetStartLocation().Get(1), lineSegment.GetStartPoint().Get(1)), Math.Min(textChunk.GetLocation().GetStartLocation().Get(2), lineSegment.GetStartPoint().Get(2))); Vector endPoint = new Vector(Math.Max(textChunk.GetLocation().GetEndLocation().Get(0), lineSegment.GetEndPoint().Get(0)), Math.Max(textChunk.GetLocation().GetEndLocation().Get(1), lineSegment.GetEndPoint().Get(1)), Math.Max(textChunk.GetLocation().GetEndLocation().Get(2), lineSegment.GetEndPoint().Get(2))); LocationTextExtractionStrategy2.TextChunk value = new LocationTextExtractionStrategy2.TextChunk(textChunk.GetText(), this.tclStrat.CreateLocation(textRenderInfo, new LineSegment(startPoint, endPoint))); this.locationalResult[this.locationalResult.Count - 1] = value; } else { string actualText = textRenderInfo.GetActualText(); LocationTextExtractionStrategy2.TextChunk item = new LocationTextExtractionStrategy2.TextChunk((actualText != null) ? actualText : textRenderInfo.GetText(), this.tclStrat.CreateLocation(textRenderInfo, lineSegment)); this.locationalResult.Add(item); } } else { LocationTextExtractionStrategy2.TextChunk item2 = new LocationTextExtractionStrategy2.TextChunk(textRenderInfo.GetText(), this.tclStrat.CreateLocation(textRenderInfo, lineSegment)); this.locationalResult.Add(item2); } this.lastTextRenderInfo = textRenderInfo; } }