use of java.awt.geom.GeneralPath in project android_frameworks_base by AOSPA.
the class Path_Delegate method transform.
/**
* Transform the points in this path by matrix, and write the answer
* into dst. If dst is null, then the the original path is modified.
*
* @param matrix The matrix to apply to the path
* @param dst The transformed path is written here. If dst is null,
* then the the original path is modified
*/
public void transform(Matrix_Delegate matrix, Path_Delegate dst) {
if (matrix.hasPerspective()) {
assert false;
Bridge.getLog().fidelityWarning(LayoutLog.TAG_MATRIX_AFFINE, "android.graphics.Path#transform() only " + "supports affine transformations.", null, null);
}
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(matrix.getAffineTransform());
newPath.append(iterator, false);
if (dst != null) {
dst.mPath = newPath;
} else {
mPath = newPath;
}
}
use of java.awt.geom.GeneralPath in project android_frameworks_base by ResurrectionRemix.
the class Path_Delegate method offset.
/**
* Offset the path by (dx,dy), returning true on success
*
* @param dx The amount in the X direction to offset the entire path
* @param dy The amount in the Y direction to offset the entire path
*/
public void offset(float dx, float dy) {
GeneralPath newPath = new GeneralPath();
PathIterator iterator = mPath.getPathIterator(new AffineTransform(0, 0, dx, 0, 0, dy));
newPath.append(iterator, false);
mPath = newPath;
}
use of java.awt.geom.GeneralPath in project geode by apache.
the class Arrow method paintNormal.
private void paintNormal(Graphics2D g) {
Lifeline startingLine = getStartingLine();
Lifeline endingLine = getEndingLine();
int x1 = startingLine.getX();
int x2 = endingLine.getX();
int y = endingState.getStartY();
if (x2 > x1) {
int startX = x1 + startingLine.getWidth();
int endX = x2;
GeneralPath path = new GeneralPath();
path.moveTo(startX, y);
path.lineTo(endX, y);
path.lineTo(endX - ARROW_WIDTH, y - ARROW_WIDTH);
path.moveTo(endX, y);
path.lineTo(endX - ARROW_WIDTH, y + ARROW_WIDTH);
g.draw(path);
g.fillArc(startX, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
g.drawString(label, startX + LABEL_OFFSET, y - LABEL_OFFSET);
} else {
int startX = x1;
int endX = x2 + endingLine.getWidth();
GeneralPath path = new GeneralPath();
path.moveTo(startX, y);
path.lineTo(endX, y);
path.lineTo(endX + ARROW_WIDTH, y - ARROW_WIDTH);
path.moveTo(endX, y);
path.lineTo(endX + ARROW_WIDTH, y + ARROW_WIDTH);
g.draw(path);
int labelWidth = g.getFontMetrics().stringWidth(label);
g.fillArc(startX - CIRCLE_WIDTH / 2, y - CIRCLE_WIDTH / 2, CIRCLE_WIDTH, CIRCLE_WIDTH, 0, 360);
g.drawString(label, startX - LABEL_OFFSET - labelWidth, y - LABEL_OFFSET);
}
}
use of java.awt.geom.GeneralPath in project intellij-community by JetBrains.
the class EditorPainter method paintCaret.
private void paintCaret(Graphics2D g_) {
EditorImpl.CaretRectangle[] locations = myEditor.getCaretLocations(true);
if (locations == null)
return;
Graphics2D g = IdeBackgroundUtil.getOriginalGraphics(g_);
int nominalLineHeight = myView.getNominalLineHeight();
int topOverhang = myView.getTopOverhang();
EditorSettings settings = myEditor.getSettings();
Color caretColor = myEditor.getColorsScheme().getColor(EditorColors.CARET_COLOR);
if (caretColor == null)
caretColor = new JBColor(CARET_DARK, CARET_LIGHT);
int minX = getMinX();
for (EditorImpl.CaretRectangle location : locations) {
float x = location.myPoint.x;
int y = location.myPoint.y - topOverhang;
Caret caret = location.myCaret;
CaretVisualAttributes attr = caret == null ? CaretVisualAttributes.DEFAULT : caret.getVisualAttributes();
g.setColor(attr.getColor() != null ? attr.getColor() : caretColor);
boolean isRtl = location.myIsRtl;
if (myEditor.isInsertMode() != settings.isBlockCursor()) {
int lineWidth = JBUI.scale(attr.getWidth(settings.getLineCursorWidth()));
// see IDEA-148843 for more details
if (x > minX && lineWidth > 1)
x -= 1 / JBUI.sysScale(g);
g.fill(new Rectangle2D.Float(x, y, lineWidth, nominalLineHeight));
if (myDocument.getTextLength() > 0 && caret != null && !myView.getTextLayoutCache().getLineLayout(caret.getLogicalPosition().line).isLtr()) {
GeneralPath triangle = new GeneralPath(Path2D.WIND_NON_ZERO, 3);
triangle.moveTo(isRtl ? x + lineWidth : x, y);
triangle.lineTo(isRtl ? x + lineWidth - CARET_DIRECTION_MARK_SIZE : x + CARET_DIRECTION_MARK_SIZE, y);
triangle.lineTo(isRtl ? x + lineWidth : x, y + CARET_DIRECTION_MARK_SIZE);
triangle.closePath();
g.fill(triangle);
}
} else {
int width = location.myWidth;
float startX = Math.max(minX, isRtl ? x - width : x);
g.fill(new Rectangle2D.Float(startX, y, width, nominalLineHeight - 1));
if (myDocument.getTextLength() > 0 && caret != null) {
int charCount = DocumentUtil.isSurrogatePair(myDocument, caret.getOffset()) ? 2 : 1;
int targetVisualColumn = caret.getVisualPosition().column;
for (VisualLineFragmentsIterator.Fragment fragment : VisualLineFragmentsIterator.create(myView, caret.getVisualLineStart(), false)) {
if (fragment.getCurrentInlays() != null)
continue;
int startVisualColumn = fragment.getStartVisualColumn();
int endVisualColumn = fragment.getEndVisualColumn();
if (startVisualColumn < targetVisualColumn && endVisualColumn > targetVisualColumn || startVisualColumn == targetVisualColumn && !isRtl || endVisualColumn == targetVisualColumn && isRtl) {
g.setColor(ColorUtil.isDark(caretColor) ? CARET_LIGHT : CARET_DARK);
fragment.draw(g, startX, y + topOverhang + myView.getAscent(), targetVisualColumn - startVisualColumn - (isRtl ? charCount : 0), targetVisualColumn - startVisualColumn + (isRtl ? 0 : charCount));
break;
}
}
ComplexTextFragment.flushDrawingCache(g);
}
}
}
}
use of java.awt.geom.GeneralPath in project jdk8u_jdk by JetBrains.
the class TextLayout method getVisualHighlightShape.
/**
* Returns a path enclosing the visual selection in the specified range,
* extended to <code>bounds</code>.
* <p>
* If the selection includes the leftmost (topmost) position, the selection
* is extended to the left (top) of <code>bounds</code>. If the
* selection includes the rightmost (bottommost) position, the selection
* is extended to the right (bottom) of the bounds. The height
* (width on vertical lines) of the selection is always extended to
* <code>bounds</code>.
* <p>
* Although the selection is always contiguous, the logically selected
* text can be discontiguous on lines with mixed-direction text. The
* logical ranges of text selected can be retrieved using
* <code>getLogicalRangesForVisualSelection</code>. For example,
* consider the text 'ABCdef' where capital letters indicate
* right-to-left text, rendered on a right-to-left line, with a visual
* selection from 0L (the leading edge of 'A') to 3T (the trailing edge
* of 'd'). The text appears as follows, with bold underlined areas
* representing the selection:
* <br><pre>
* d<u><b>efCBA </b></u>
* </pre>
* The logical selection ranges are 0-3, 4-6 (ABC, ef) because the
* visually contiguous text is logically discontiguous. Also note that
* since the rightmost position on the layout (to the right of 'A') is
* selected, the selection is extended to the right of the bounds.
* @param firstEndpoint one end of the visual selection
* @param secondEndpoint the other end of the visual selection
* @param bounds the bounding rectangle to which to extend the selection.
* This is in baseline-relative coordinates.
* @return a <code>Shape</code> enclosing the selection. This is in
* standard coordinates.
* @see #getLogicalRangesForVisualSelection(TextHitInfo, TextHitInfo)
* @see #getLogicalHighlightShape(int, int, Rectangle2D)
*/
public Shape getVisualHighlightShape(TextHitInfo firstEndpoint, TextHitInfo secondEndpoint, Rectangle2D bounds) {
ensureCache();
checkTextHit(firstEndpoint);
checkTextHit(secondEndpoint);
if (bounds == null) {
throw new IllegalArgumentException("Null Rectangle2D passed to TextLayout.getVisualHighlightShape()");
}
GeneralPath result = new GeneralPath(GeneralPath.WIND_EVEN_ODD);
int firstCaret = hitToCaret(firstEndpoint);
int secondCaret = hitToCaret(secondEndpoint);
result.append(caretBoundingShape(firstCaret, secondCaret, bounds), false);
if (firstCaret == 0 || secondCaret == 0) {
GeneralPath ls = leftShape(bounds);
if (!ls.getBounds().isEmpty())
result.append(ls, false);
}
if (firstCaret == characterCount || secondCaret == characterCount) {
GeneralPath rs = rightShape(bounds);
if (!rs.getBounds().isEmpty()) {
result.append(rs, false);
}
}
LayoutPathImpl lp = textLine.getLayoutPath();
if (lp != null) {
// dlf cast safe?
result = (GeneralPath) lp.mapShape(result);
}
return result;
}
Aggregations