Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the -rtfx prefix for RichTextFX specific underline properties, us… #324

Merged
merged 1 commit into from
Jun 10, 2016
Merged
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,6 +1,6 @@
.underlined {
-fx-underline-color: red;
-fx-underline-dash-array: 2 2;
-fx-underline-width: 1;
-fx-underline-cap: butt;
-rtfx-underline-color: red;
-rtfx-underline-dash-array: 2 2;
-rtfx-underline-width: 1;
-rtfx-underline-cap: butt;
}
79 changes: 38 additions & 41 deletions richtextfx/src/main/java/org/fxmisc/richtext/ParagraphText.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.fxmisc.richtext;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.function.BiConsumer;
Expand Down Expand Up @@ -235,55 +234,53 @@ private void updateBackground(TextExt text, int start, int end, int index) {
*/
private void updateUnderline(TextExt text, int start, int end, int index) {

// get all CSS properties for the underline

Paint underlineColor = text.underlineColorProperty().get();
Number underlineWidth = text.underlineWidthProperty().get();
if (underlineWidth != null && underlineWidth.doubleValue() > 0) {

Path underlineShape = underlineShapes.get(index);
underlineShape.setStrokeWidth(underlineWidth.doubleValue());

// get the dash array - JavaFX CSS parser seems to return either a Number[] array
// or a single value, depending on whether only one or more than one value has been
// specified in the CSS
Double[] underlineDashArray = null;
Object underlineDashArrayProp = text.underlineDashArrayProperty().get();
if (underlineDashArrayProp != null) {
if (underlineDashArrayProp.getClass().isArray()) {
Number[] numberArray = (Number[]) underlineDashArrayProp;
underlineDashArray = new Double[numberArray.length];
int idx = 0;
for (Number d : numberArray) {
underlineDashArray[idx++] = (Double) d;
// get remaining CSS properties for the underline style

Paint underlineColor = text.underlineColorProperty().get();

// get the dash array - JavaFX CSS parser seems to return either a Number[] array
// or a single value, depending on whether only one or more than one value has been
// specified in the CSS
Double[] underlineDashArray = null;
Object underlineDashArrayProp = text.underlineDashArrayProperty().get();
if (underlineDashArrayProp != null) {
if (underlineDashArrayProp.getClass().isArray()) {
Number[] numberArray = (Number[]) underlineDashArrayProp;
underlineDashArray = new Double[numberArray.length];
int idx = 0;
for (Number d : numberArray) {
underlineDashArray[idx++] = (Double) d;
}
} else {
underlineDashArray = new Double[1];
underlineDashArray[0] = ((Double) underlineDashArrayProp).doubleValue();
}
} else {
underlineDashArray = new Double[1];
underlineDashArray[0] = ((Double) underlineDashArrayProp).doubleValue();
}
}

StrokeLineCap underlineCap = text.underlineCapProperty().get();

// apply style and render the underline

Path underlineShape = underlineShapes.get(index);
if (underlineColor != null) {
underlineShape.setStroke(underlineColor);
}
if (underlineWidth != null) {
underlineShape.setStrokeWidth(underlineWidth.doubleValue());
}
if (underlineDashArray != null) {
underlineShape.getStrokeDashArray().addAll(underlineDashArray);
underlineShape.setStrokeLineCap(StrokeLineCap.BUTT);
}
if (underlineCap != null) {
underlineShape.setStrokeLineCap(underlineCap);
}

StrokeLineCap underlineCap = text.underlineCapProperty().get();

// apply style
if (underlineColor != null) {
underlineShape.setStroke(underlineColor);
}
if (underlineDashArray != null) {
underlineShape.getStrokeDashArray().addAll(underlineDashArray);
}
if (underlineCap != null) {
underlineShape.setStrokeLineCap(underlineCap);
}

if (underlineColor != null || underlineWidth != null) {

// Set path elements
PathElement[] shape = getUnderlineShape(start, end);
underlineShape.getElements().setAll(shape);
}

}


Expand Down
8 changes: 4 additions & 4 deletions richtextfx/src/main/java/org/fxmisc/richtext/TextExt.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ public StyleableProperty<Paint> getStyleableProperty(TextExt node) {


private static final CssMetaData<TextExt, Paint> UNDERLINE_COLOR = new CssMetaData<TextExt, Paint>(
"-fx-underline-color",
"-rtfx-underline-color",
StyleConverter.getPaintConverter(),
Color.TRANSPARENT) {
@Override
Expand All @@ -191,7 +191,7 @@ public StyleableProperty<Paint> getStyleableProperty(TextExt node) {
};

private static final CssMetaData<TextExt, Number> UNDERLINE_WIDTH = new CssMetaData<TextExt, Number>(
"-fx-underline-width",
"-rtfx-underline-width",
StyleConverter.getSizeConverter(),
0) {

Expand All @@ -207,7 +207,7 @@ public StyleableProperty<Number> getStyleableProperty(TextExt node) {
};

private static final CssMetaData<TextExt, Number[]> UNDERLINE_DASH_ARRAY = new CssMetaData<TextExt, Number[]>(
"-fx-underline-dash-array",
"-rtfx-underline-dash-array",
SizeConverter.SequenceConverter.getInstance(),
new Double[0]) {

Expand All @@ -223,7 +223,7 @@ public StyleableProperty<Number[]> getStyleableProperty(TextExt node) {
};

private static final CssMetaData<TextExt, StrokeLineCap> UNDERLINE_CAP = new CssMetaData<TextExt, StrokeLineCap>(
"-fx-underline-cap",
"-rtfx-underline-cap",
new EnumConverter<StrokeLineCap>(StrokeLineCap.class),
StrokeLineCap.SQUARE) {

Expand Down