Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates.
* All rights reserved. Use is subject to license terms.
*
* This file is available and licensed under the following license:
Expand Down Expand Up @@ -56,6 +56,10 @@ public class ParagraphAttributesDemoModel extends SimpleViewOnlyStyledModel {
private final static StyleAttributeMap FIRST_LINE_INDENT = StyleAttributeMap.builder().
setFirstLineIndent(100).
build();
private final static StyleAttributeMap HL = StyleAttributeMap.builder().
setUnderline(true).
setStrikeThrough(true).
build();

public ParagraphAttributesDemoModel() {
registerDataFormatHandler(RtfFormatHandler.getInstance(), true, false, 1000);
Expand Down Expand Up @@ -108,31 +112,37 @@ public static void insert(SimpleViewOnlyStyledModel m) {

// space

m.addSegment("✓ Space Above");
m.addSegment("✓ Space ");
m.addSegment("Above", HL);
m.setParagraphAttributes(StyleAttributeMap.builder().
setSpaceAbove(20).
setBackground(Color.gray(0.95, 0.5)).
setBullet("•").
build());
m.nl();

m.addSegment("✓ Space Below");
m.addSegment("✓ Space ");
m.addSegment("Below", HL);
m.setParagraphAttributes(StyleAttributeMap.builder().
setSpaceBelow(20).
setBackground(Color.gray(0.9, 0.5)).
setBullet("◦").
build());
m.nl();

m.addSegment("✓ Space Left " + words(50));
m.addSegment("✓ Space ");
m.addSegment("Left", HL);
m.addSegment(" " + words(50));
m.setParagraphAttributes(StyleAttributeMap.builder().
setSpaceLeft(20).
setBackground(Color.gray(0.85, 0.5)).
setBullet("∙").
build());
m.nl();

m.addSegment("✓ Space Right " + words(10));
m.addSegment("✓ Space ");
m.addSegment("Right", HL);
m.addSegment(" " + words(10));
m.setParagraphAttributes(StyleAttributeMap.builder().
setSpaceRight(20).
setBackground(Color.gray(0.8, 0.5)).
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -137,9 +137,8 @@ public TextPos getTextPos(double cellX, double cellY) {
return TextPos.ofLeading(cell.getIndex(), 0);
} else if (y < cell.getCellHeight()) {
if (r instanceof TextFlow f) {
double x = cellX - f.snappedLeftInset();
Point2D p = new Point2D(x - r.getLayoutX(), y - r.getLayoutY());
HitInfo h = f.hitTest(p);
Point2D p = new Point2D(cellX - r.getLayoutX(), y - r.getLayoutY());
HitInfo h = f.getHitInfo(p);
int ii = h.getInsertionIndex();
int ci = h.getCharIndex();
boolean leading = h.isLeading();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -64,9 +64,9 @@ public HighlightShape(Type t, int start, int end) {
private PathElement[] createPath(TextFlow f) {
switch (type) {
case HIGHLIGHT:
return f.rangeShape(start, end);
return f.getRangeShape(start, end, true);
case SQUIGGLY:
PathElement[] pe = f.underlineShape(start, end);
PathElement[] pe = f.getUnderlineShape(start, end);
return generateSquiggly(pe);
default:
// never happens
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,8 @@ public void addBoxOutline(FxPathBuilder b, double x, double w, double h) {
*/
public PathElement[] getCaretShape(Region target, int charIndex, boolean leading) {
PathElement[] p;
double dx;
double dy;
if (content instanceof TextFlow f) {
dx = f.snappedLeftInset(); // TODO RTL?
dy = f.snappedTopInset();

p = f.caretShape(charIndex, leading);

p = f.getCaretShape(charIndex, leading);
if (p.length == 2) {
PathElement p0 = p[0];
PathElement p1 = p[1];
Expand All @@ -215,14 +209,12 @@ public PathElement[] getCaretShape(Region target, int charIndex, boolean leading
}
}
} else {
dx = 0.0;
dy = 0.0;
p = new PathElement[] {
new MoveTo(0.0, 0.0),
new LineTo(0.0, content.getHeight())
};
}
return RichUtils.translatePath(target, content, p, dx, dy);
return RichUtils.translatePath(target, content, p);
}

/**
Expand All @@ -236,16 +228,9 @@ public PathElement[] getCaretShape(Region target, int charIndex, boolean leading
*/
public PathElement[] getUnderlineShape(Region target, int start, int end) {
PathElement[] p;
double dx;
double dy;
if (content instanceof TextFlow f) {
dx = f.snappedLeftInset(); // TODO RTL?
dy = f.snappedTopInset();

p = f.getUnderlineShape(start, end);
} else {
dx = 0.0;
dy = 0.0;
double w = getWidth();
double h = getHeight();

Expand All @@ -254,7 +239,7 @@ public PathElement[] getUnderlineShape(Region target, int start, int end) {
new LineTo(w, h)
};
}
return RichUtils.translatePath(target, content, p, dx, dy);
return RichUtils.translatePath(target, content, p);
}

/**
Expand All @@ -268,23 +253,15 @@ public PathElement[] getUnderlineShape(Region target, int start, int end) {
*/
public PathElement[] getRangeShape(Region target, int start, int end) {
PathElement[] p;
double dx;
double dy;
if (content instanceof TextFlow f) {
dx = f.snappedLeftInset(); // TODO RTL?
dy = f.snappedTopInset();

p = f.rangeShape(start, end); // TODO new api, no null

if ((p == null) || (p.length == 0)) {
p = f.getRangeShape(start, end, true);
if (p.length == 0) {
p = new PathElement[] {
new MoveTo(0.0, 0.0),
new LineTo(0.0, f.getHeight())
};
}
} else {
dx = 0.0;
dy = 0.0;
double w = getWidth();
double h = getHeight();

Expand All @@ -296,7 +273,7 @@ public PathElement[] getRangeShape(Region target, int start, int end) {
new LineTo(0.0, 0.0)
};
}
return RichUtils.translatePath(target, content, p, dx, dy);
return RichUtils.translatePath(target, content, p);
}

/**
Expand Down Expand Up @@ -410,7 +387,7 @@ public Integer lineEnd(int line) {
private RangeInfo getTextRange() {
if (content instanceof TextFlow f) {
int len = getTextLength();
PathElement[] pe = f.rangeShape(0, len); // TODO new api
PathElement[] pe = f.getRangeShape(0, len, true);
if (pe.length > 0) {
double sp = f.getLineSpacing();
return RangeInfo.of(pe, sp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,24 @@ public static int getTextLength(TextFlow f) {
return len;
}

// TODO javadoc
// translates path elements from src frame of reference to target, with additional shift by dx, dy
// only MoveTo, LineTo are supported
// may return null
public static PathElement[] translatePath(Region tgt, Region src, PathElement[] elements, double deltax, double deltay) {
//System.out.println("translatePath from=" + dump(elements) + " dx=" + deltax + " dy=" + deltay); // FIX
/**
* Translates path (which must contain only LineTo and MoveTo elements) from src frame of reference
* to the target frame of reference.
* @param tgt the target Region
* @param src the source Region
* @param elements the path elements
* @return translated path array, or null
* @throws RuntimeException if path elements contain something other than LineTo or MoveTo
*/
public static PathElement[] translatePath(Region tgt, Region src, PathElement[] elements) {
Point2D ps = src.localToScreen(0.0, 0.0);
if (ps == null) {
return null;
}

Point2D pt = tgt.localToScreen(tgt.snappedLeftInset(), tgt.snappedTopInset());
double dx = ps.getX() - pt.getX() + deltax;
double dy = ps.getY() - pt.getY() + deltay;
//System.out.println("dx=" + dx + " dy=" + dy); // FIX
double dx = ps.getX() - pt.getX();
double dy = ps.getY() - pt.getY();

for (int i = 0; i < elements.length; i++) {
PathElement em = elements[i];
Expand All @@ -208,7 +211,6 @@ public static PathElement[] translatePath(Region tgt, Region src, PathElement[]

elements[i] = em;
}
//System.out.println("translatePath to=" + dump(elements)); // FIX
return elements;
}

Expand Down