/** * @param height the height, in text space * @return the height in user space */ private float convertHeightFromTextSpaceToUserSpace(float height) { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(0, height, 1)); LineSegment userSpace = textSpace.transformBy(textToUserSpaceTransformMatrix); return userSpace.getLength(); }
/** * Checks if a segment contains another segment in itself * @param other a segment to be checked * @return true if this segment contains other one, false otherwise */ public boolean containsSegment(LineSegment other) { return other != null && containsPoint(other.startPoint) && containsPoint(other.endPoint); }
public ITextChunkLocation createLocation(TextRenderInfo renderInfo, LineSegment baseline) { return new TextChunkLocationDefaultImp(baseline.getStartPoint(), baseline.getEndPoint(), renderInfo.getSingleSpaceWidth()); } });
/** * @param as the location to compare to * @return true is this location is on the the same line as the other */ public boolean sameLine(ITextChunkLocation as) { if (orientationMagnitude() != as.orientationMagnitude()) { return false; } float distPerpendicularDiff = distPerpendicular() - as.distPerpendicular(); if (distPerpendicularDiff == 0) { return true; } LineSegment mySegment = new LineSegment(startLocation, endLocation); LineSegment otherSegment = new LineSegment(as.getStartLocation(), as.getEndLocation()); return Math.abs(distPerpendicularDiff) <= DIACRITICAL_MARKS_ALLOWED_VERTICAL_DEVIATION && (mySegment.getLength() == 0 || otherSegment.getLength() == 0); }
segment = segment.transformBy(riseOffsetTransform); 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))); TextChunk merged = new TextChunk(lastTextChunk.getText(), tclStrat.createLocation(renderInfo, new LineSegment(mergedStart, mergedEnd))); locationalResult.set(locationalResult.size() - 1, merged); } else {
/** * Gets the baseline for the text (i.e. the line that the text 'sits' on) * This value includes the Rise of the draw operation - see {@link #getRise()} for the amount added by Rise * * @return the baseline line segment */ public LineSegment getBaseline() { checkGraphicsState(); return getUnscaledBaselineWithOffset(0 + gs.getTextRise()).transformBy(textToUserSpaceTransformMatrix); }
/** * Transforms the segment by the specified matrix * @param m the matrix for the transformation * @return the transformed segment */ public LineSegment transformBy(Matrix m){ Vector newStart = startPoint.cross(m); Vector newEnd = endPoint.cross(m); return new LineSegment(newStart, newEnd); }
@Override public void eventOccurred(IEventData data, EventType type) { if (type == EventType.RENDER_TEXT) { TextRenderInfo info = (TextRenderInfo) data; if (textRectangle == null) { textRectangle = info.getDescentLine().getBoundingRectangle(); } else { textRectangle = Rectangle.getCommonRectangle(textRectangle, info.getDescentLine().getBoundingRectangle()); } textRectangle = Rectangle.getCommonRectangle(textRectangle, info.getAscentLine().getBoundingRectangle()); } else { throw new IllegalStateException(MessageFormatUtil.format("Event type not supported: {0}", type)); } }
/** * Gets the ascentline for the text (i.e. the line that represents the topmost extent that a string of the current font could have) * This value includes the Rise of the draw operation - see {@link #getRise()} for the amount added by Rise * * @return the ascentline line segment */ public LineSegment getAscentLine() { checkGraphicsState(); return getUnscaledBaselineWithOffset(getAscentDescent()[0] + gs.getTextRise()).transformBy(textToUserSpaceTransformMatrix); }
private LineSegment getUnscaledBaselineWithOffset(float yOffset) { checkGraphicsState(); // we need to correct the width so we don't have an extra character and word spaces at the end. The extra character and word spaces // are important for tracking relative text coordinate systems, but should not be part of the baseline String unicodeStr = string.toUnicodeString(); float correctedUnscaledWidth = getUnscaledWidth() - (gs.getCharSpacing() + (unicodeStr.length() > 0 && unicodeStr.charAt(unicodeStr.length() - 1) == ' ' ? gs.getWordSpacing() : 0)) * (gs.getHorizontalScaling() / 100f); return new LineSegment(new Vector(0, yOffset, 1), new Vector(correctedUnscaledWidth, yOffset, 1)); }
/** * Computes the bounding rectangle for this line segment. The rectangle has a rotation 0 degrees * with respect to the coordinate system that the line system is in. For example, if a line segment * is 5 unit long and sits at a 37 degree angle from horizontal, the bounding rectangle will have * origin of the lower left hand end point of the segment, with width = 4 and height = 3. * @return the bounding rectangle */ public Rectangle getBoundingRectangle(){ float x1 = getStartPoint().get(Vector.I1); float y1 = getStartPoint().get(Vector.I2); float x2 = getEndPoint().get(Vector.I1); float y2 = getEndPoint().get(Vector.I2); return new Rectangle(Math.min(x1, x2), Math.min(y1, y2), Math.abs(x2-x1), Math.abs(y2-y1)); }
/** * @param width the width, in text space * @return the width in user space */ private float convertWidthFromTextSpaceToUserSpace(float width) { LineSegment textSpace = new LineSegment(new Vector(0, 0, 1), new Vector(width, 0, 1)); LineSegment userSpace = textSpace.transformBy(textToUserSpaceTransformMatrix); return userSpace.getLength(); }
/** * Gets the descentline for the text (i.e. the line that represents the bottom most extent that a string of the current font could have). * This value includes the Rise of the draw operation - see {@link #getRise()} for the amount added by Rise * * @return the descentline line segment */ public LineSegment getDescentLine() { checkGraphicsState(); return getUnscaledBaselineWithOffset(getAscentDescent()[1] + gs.getTextRise()).transformBy(textToUserSpaceTransformMatrix); }
private static ITextChunkLocation getLocation(TextRenderInfo tri) { LineSegment baseline = tri.getBaseline(); return new TextChunkLocationDefaultImp(baseline.getStartPoint(), baseline.getEndPoint(), tri.getSingleSpaceWidth()); }
public CharacterRenderInfo(TextRenderInfo tri) { super(tri == null ? "" : tri.getText(), tri == null ? null : getLocation(tri)); if (tri == null) throw new IllegalArgumentException("TextRenderInfo argument is not nullable."); // determine bounding box float x0 = tri.getDescentLine().getStartPoint().get(0); float y0 = tri.getDescentLine().getStartPoint().get(1); float h = tri.getAscentLine().getStartPoint().get(1) - tri.getDescentLine().getStartPoint().get(1); float w = Math.abs(tri.getBaseline().getStartPoint().get(0) - tri.getBaseline().getEndPoint().get(0)); this.boundingBox = new Rectangle(x0, y0, w, h); }
@Override public boolean accept(IEventData data, EventType type) { if (type.equals(EventType.RENDER_TEXT)) { TextRenderInfo renderInfo = (TextRenderInfo) data; LineSegment segment = renderInfo.getBaseline(); Vector startPoint = segment.getStartPoint(); Vector endPoint = segment.getEndPoint(); float x1 = startPoint.get(Vector.I1); float y1 = startPoint.get(Vector.I2); float x2 = endPoint.get(Vector.I1); float y2 = endPoint.get(Vector.I2); return filterRect == null || filterRect.intersectsLine(x1, y1, x2, y2); } else { return false; } } }
Vector start = segment.getStartPoint(); Vector end = segment.getEndPoint();