Richtextfx: Consecutive border/underline styles that are the same are rendered with multiple shapes, not one

Created on 28 Mar 2018  路  10Comments  路  Source: FXMisc/RichTextFX

Expected Behavior

Overlaying some style spans should not break down the border and box individual spans. The border should be around the original span, not individual spans resulting from the overlay.

Actual Behavior

capture du 2018-03-27 21-48-01

There are two StyleSpans here that are overlayed :

  • One with the border outline and background variation. Each styled span in this layer is applied from opening brace to closing brace (in one continuous span for each block)
  • One with the syntax highlighting.

Overlaying both layers breaks down the big spans with borders into smaller spans around the other styled spans. But the borders are shown around each particular span instead of around the original span, which is undesired. It's not entirely unexpected given the contract of overlay though, which is why I'm not sure I should submit a bug report. What do you think?

I think, if it's entirely expected, then one feature that could allow to work around that would be allowing to select the styles of the border for each side, somewhat like -fx-border-style: none solid solid solid;. With that, I could probably adjust the borders of the overlaid spans during the overlaying.

Thanks for any help/ feedback.

Minimal reproducible demo

https://gist.github.com/oowekyala/8319f98f7ed77042e2a4fa0e79116aad#file-app-java

Environment info:

  • RichTextFX Version: 0.8.1
  • Operating System: Ubuntu 16.04
  • Java version: 8
bug

All 10 comments

I hope to respond to this later today or potentially tomorrow.

So... This seems like a bug because the border shape is supposed to be shared between two or more consecutive texts with the same border style. Given the gist you provided (I'll provide a text version of it), the border shape's left/right part being represented by a vertical line ("|") should not be there:
[Lorem |ipsum dolo|r sit amet]
When I added some printlns to figure out what the underlying state looks like, there doesn't seem to be a problem with BorderAttributes, the object we use to evaluate shared styles between Text objects regardless of whether inline CSS or style classes are used. The values are the same between the three spans' borders:
java Given text: Text[text="Lorem ", x=0.0, y=0.0, alignment=LEFT, origin=TOP, boundsType=LOGICAL, font=Font[name=System Regular, family=System, style=Regular, size=16.0], fontSmoothingType=GRAY, fill=0x000000ff] Result is: BorderAttributes[type=OUTSIDE width=1.0 color=0xb8860bff dashArray=null] Given text: Text[text="ipsum dolo", x=0.0, y=0.0, alignment=LEFT, origin=TOP, boundsType=LOGICAL, font=Font[name=System Bold, family=System, style=Bold, size=16.0], fontSmoothingType=GRAY, fill=0x0000ffff] Result is: BorderAttributes[type=OUTSIDE width=1.0 color=0xb8860bff dashArray=null] Given text: Text[text="r sit amet", x=0.0, y=0.0, alignment=LEFT, origin=TOP, boundsType=LOGICAL, font=Font[name=System Regular, family=System, style=Regular, size=16.0], fontSmoothingType=GRAY, fill=0x000000ff] Result is: BorderAttributes[type=OUTSIDE width=1.0 color=0xb8860bff dashArray=null]
When I manually created the style spans using this code:
java StyleSpansBuilder<String> builder = new StyleSpansBuilder<>(); builder.add(BOXED_STYLE, 6); builder.add(BOXED_STYLE + ";", 10); builder.add(BOXED_STYLE, 10); builder.add("", 29); StyleSpans<String> spans = builder.create(); System.out.println(spans.length() + " " + spans.getSpanCount()); int offset = 0; for (StyleSpan<String> span : spans) { System.out.println("\t" + "offset: " + offset + " length: " + span.getLength() + " style: " + span.getStyle()); offset += span.getLength(); }
the vertical lines would disappear if I removed the + ";" after the second BOXED_STYLE since the builder would reduce the three style spans into one. Once added back in, the vertical lines reappear.

Thus, it seems there is an issue with CustomCssHelper in ParagraphText.

Nay, the issue is with the BorderAttributes#equals method.

Lol.... Looks like a copy and past error. It fails because the wrong class is used in the instanceOf check:
java private static LineAttributesBase { // rest of class @Override public boolean equals(Object obj) { if (obj instanceof UnderlineAttributes) { UnderlineAttributes attr = (UnderlineAttributes) obj; return Objects.equals(width, attr.width) && Objects.equals(color, attr.color) && Arrays.equals(dashArray, attr.dashArray); } else { return false; } }

This bug would also occur with underline shapes, which was also fixed in the PR.

Just made a new snapshot release if you need something quick to work with.

Thanks for your quick reaction :) Will try this out right away

Looks neat !

capture du 2018-03-29 00-50-49

Do you know if there's a reasonably easy to implement way of removing the borders between each line to keep only the outline of the full area?

Please, open a new issue for that. It's not too difficult (I think), but it really comes down to what you're trying to do. For example, do you only want the left and right vertical lines for lines 360-370 and only the top/left/right line for 359 and left/bottom/right lines for 371?

Something like that yes. I'll open a new issue tomorrow

Was this page helpful?
0 / 5 - 0 ratings