RTFData loses paragraph alignments ?

I experience a strange behaviour when reading RTFData from a database and handing it over to a StyledText object.

Example 1 (rs As RecordSet):

TextArea1.StyledText.RTFData = rs.Field("Text").NativeValue

Anything works as intended.

Example 2:

Dim RecordText As New StyledText RecordText.RTFData = rs.Field("Text").NativeValue ... (adding some more StyledRuns using AppendStyleRun) TextArea1.StyledText = RecordText

Well, the text is shown as intended, but without any paragraph alignment set.

In example 2, I notice that RecordText.RTF data does not contain paragraph alignments and some chars in the RTFData source appear to be Chinese (although no Chinese has been added).

Anyway, I can exclude problems with the database, because when I hand over the RTFData stored in database directly to the text area (see example 1), anything is fine.

I would appreciate any comments and help.

Tobias.

Feedback Case? Mit Beispiel?
Dann kann man vielleicht mal schauen, woran es liegt.

I don’t have the time to fill in a feedback case. The software has to be completed in about four weeks. My last case I reported in April just did it to the state “Reviewed” yet.

But if you like, I can prepare a small app that makes it easier to reproduce the error.

Tobias.

Here is a demo project that shows the problem. Maybe I made a mistake, but can’t think of what went wrong exactly.

https://www.amazon.de/clouddrive/share?s=onk2vJHJT1wuGZLim1n3bo

Tobias.

Dieser Link ist nicht verfügbar

I’m guessing but I’m thinking this means… “No such link”

Sorry, please give it another try. It should work now !

I had this EXACT same problem in a app I’m working on… and somehow managed to fix it…

But I cannot for the life of me remember what I had to do to make it work

the only thing I see different is how I assign the RTFdata

ta.Styledtext.RTFdata=Trim(ConvertEncoding(RTF_Str,Encodings.UTF8))

Thanks, Dave. It’s worth to give it a try on my code, too.

I also played with different encodings, but without luck. What was the reason why you have used trim ? I assumed that the database record contains nothing else than the field value (I even used NativeValue to really ensure that no “special” encoding is applied).

Tobias.

Well, I altered line 31 of my sample project that it contains

TextArea1.StyledText.RTFData = Trim(ConvertEncoding(rs.Field("Text").NativeValue,Encodings.UTF8))

instead of

TextArea1.StyledText.RTFData = rs.Field("Text").NativeValue

But no luck… still no parapgraph alignments.

@Dave S : If you remember your trick… please let me know ! :slight_smile:

I remember THIS Dave’s case.

problem is … I did SOMETHING the fixed it… but I cannot for the life of me remember what… and normally I’m good about putting notes in my code for items that are not “intuitive”

Well, if you look at code like this:

Dim st As New StyledText
st.RTFData = rs.Field(“Text”).NativeValue

dim c as integer = st.ParagraphCount
for i as integer = 0 to c-1
dim p as Paragraph = st.Paragraph(i)
System.DebugLog "Alignment: "+str(p.Alignment)
System.DebugLog "Length: "+str(p.Length)
next

you clearly see that the RTF parsing does not work with paragraph alignments, if the styledtext is not linked to a textarea.

I made a case for the problem I saw: 29612.
Seems like alignments in styledText does not work at all in that case.

Besides Dave method he forgot about, is there any workaround ?

It’s bad enough that RTF is so much limited in RS/Xojo (no justification, no picture support, no …), but it would be more worse to even disable the last few options of text editing.

@Christian Schmitz : Thanks for opening a case; I just fear that the issue becomes solved in one year or so.

Tobias.

Well, if you are Mac only, you could still use the NSTextViewMBS plugin class for RTF.

No, it should run on Windows as well. In addition (not offending), I don’t want to use third party plugin solutions.