RTFData : Can Someone take a look at this?

Seems if you attempt to extract the RTFData from a StyledText string (to store in a database for example)
and then load it back later… you are pretty much messed up…

It seems that an assignment to RTFData messes with Fontnames, and Alignment codes and who knows what else… suffice it to say… what you put IN is not what you will get back out again

Fontnames end up looking like Oriental Characters (and Styled text then sets it all to “System”, since it can’t “understand”)
Alignment codes ( \ql \qc \qr) are dropped completely

Now MacOSLib has example TextArea that works PERFECTLY… but the code is so convoluted it is near impossible to figure out the minimum pieces required (There are a dozen levels of menu subclassing, and everything seems to pass pieces of commands for Cocoa events…)

And this project cannot afford the investement in FTC or similar items, if the syntax as described in the LR worked, I’d be golden

Does it work if you don’t store it and and read it back in? Ie.,

s = textarea1.rtfdata
textarea1.rtfdata = s

[quote=15371:@Dave S]Seems if you attempt to extract the RTFData from a StyledText string (to store in a database for example)
and then load it back later… you are pretty much messed up…

It seems that an assignment to RTFData messes with Fontnames, and Alignment codes and who knows what else… suffice it to say… what you put IN is not what you will get back out again

Fontnames end up looking like Oriental Characters (and Styled text then sets it all to “System”, since it can’t “understand”)
Alignment codes ( \ql \qc \qr) are dropped completely

Now MacOSLib has example TextArea that works PERFECTLY… but the code is so convoluted it is near impossible to figure out the minimum pieces required (There are a dozen levels of menu subclassing, and everything seems to pass pieces of commands for Cocoa events…)

And this project cannot afford the investement in FTC or similar items, if the syntax as described in the LR worked, I’d be golden[/quote]

Have you filed a bug report?

Does it work if I don’t export/import it?

As long as it is in the TextArea, Fonts work… alignment… no way (the RTF data has the codes… but Cocoa ignores them, and then strips them out… when I try to re-populate the TextArea)

Bug Report? From what I can tell there are over 20 bug reports with variations of this problem out there already… wiith one having a rank of 340!!!

for example…

myLog master.rtfdata
clone.rtfdata=master.rtfdata
mylog clone.rtfdata

myLog simply writes a message to a textfile …

I would expect that the data from the 1st and 3rd line would be 100% identical

but if multiple fonts or alignments are included… the show in the 1st line, but are gone from the 2nd line

let me thow together a sample project

NOW I am REAL confused

A sample with two TextAreas… it works…

How can ONE line work differently in two projects?

Well not 100%… I set the font to ARIAL… it set it to gibberish… but in this test the alignment stayed

will post the project test in a bit

Ok… I almost have it working…

First thing I did was changed all the STYLEDTEXT properties of my classes to PLAIN TEXT… and shuffled the RTFDATA in and out of those. This way it was treated as a regular string for storage purposes and I didn’t have to worry about the STYLEDTEXT or TEXTAREA mucking with it too much.

So now all my fonts stay what I want for the most part, some fonts revert to SYSTEM, and I think this is due to the difference in how CARBON and COCOA seem to deal with FONT FAMILIES.

Now I have ONE remaining strange item.
As you can see from my images above, I have LEFT/CENTER/RIGHT align buttons.
These buttons set the Textarea1.SelAlignment= (approprite value)

HOWEVER… the TEXTAREA doen’t change (it did in my little test project), but not in the big one.

BUT… when I say the data FROM that exact same TextArea, and use DRAWBLOCK… The Alignments ARE drawn

So… no matter what I set any alignment to. the TA always SHOWS LEFT
but DrawBlock shows what I set

here is a small project… it is an export of the TextEdit Window from my main app.
The only change I made was the [UPDATE] button which will use DRAWBLOCK to show what the TA data describes.

This shows that you can SET the alignment in the TA, and it will show on the CANVAS, but not in the TA itself.

Can someone see if
a) I’m messing something up
b) yup, it is a XOJO/COCOA problem

I’m running under OSX 10.8.4

http://www.rdS.com/teststuff.zip

This is the code, and support icons

Thanks

nobody willing to look at this for me? :frowning:

Just tested it.

  • Alignment: I believe that TextAreas don’t handle line-by-line alignment. It’s all or nothing. So to simulate this you’d need to set TextArea.Alignment rather than (or in parallel with) setting the alignment within the RTF, and not expect line-by-line alignment to work.
  • Font names: here’s some code (I adapted from MacOSLib) to translate a Carbon-type font name to a PostScript type font name. Xojo Cocoa builds currently use a mix of these internally, and it’s a bit of a mess - I’ve already submitted a bug report on this but perhaps it’s been overlooked:
Function ConvertFontName(name as String) As string
  ' converts PostScript type font name to Cocoa-style font name
  #if TargetCocoa
    const kATSOptionFlagsDefault = 0
    const kInvalidFont = 0
    soft declare function ATSFontFindFromPostScriptName lib kCarbonLib (iName as CFStringRef, iOptions as UInt32) as UInt32
    
    dim theRef as UInt32 = ATSFontFindFromPostScriptName(name, kATSOptionFlagsDefault)
    if theRef = kInvalidFont then
      //LogWarning CurrentMethodName + " invalid font for " + name
      return name  ' returns the original name which may be OK
    end if
    
    soft declare function ATSFontGetName lib kCarbonLib (iFamily as UInt32, iOptions as UInt32, ByRef oName as CFStringRef) as Integer
    dim CFname2 as CFStringRef
    dim OSError as Integer = ATSFontGetName(theRef, kATSOptionFlagsDefault, CFname2)
    if OSError = 0 then
      //LogWarning CurrentMethodName + " ATSFontGetName error for " + name
    end if
    dim fname2 as string=cfname2
     return fname2
       
    
  #endif
End Function

The LR indicates that ALignment can be set on a paragraph basis (text between endofline markers), and it DOES work for the Text coming out of the TA… just not while display BY the TA.

And while Thanks for your code snippet… It is a Carbon-based-lifeform :), and if I recall ATS has even been deprecated by Apple.

See https://forum.xojo.com/2279-27595-cocoa-font-names-are-inconsistent-in-textare

Note that different font faces have different font PS font names. And for my purposes I need to know them all. So I use a simpler, Xojo-only, method to get the PS font names.

  1. Create a styled text TextArea.
  2. Set field.TextFont to the Carbon/Cocoa name.
  3. Insert one character.
  4. field.selectAll
  5. Get field.selFont -> PS name
  6. field.selItalic = true
  7. Get field.selFont -> PS italic font name
  8. etc.

ATS is deprecated, but you can do this via CoreText. CTFontCreateWithName will get you a CTFontRef and from there you can call any of the following to get name information:

  • CTFontCopyPostScriptName
  • CTFontCopyFamilyName
  • CTFontCopyFullName
  • CTFontCopyDisplayName

There’s more name types like subfamily that can be accessed via CTFontCopyName, but I don’t think you’ll need that.

This can also be accomplished via the appropriate NSFontManager methods.

[quote=15836:@Jonathan Ashwell]Note that different font faces have different font PS font names. And for my purposes I need to know them all. So I use a simpler, Xojo-only, method to get the PS font names.

  1. Create a styled text TextArea.
  2. Set field.TextFont to the Carbon/Cocoa name.
  3. Insert one character.
  4. field.selectAll
  5. Get field.selFont -> PS name
  6. field.selItalic = true
  7. Get field.selFont -> PS italic font name
  8. etc.[/quote]

This will break if the behavior is changed to be what Michael is expecting. You probably should be using declares to get at the information, but it’s a bit more complicated than I have time to research now. You should probably create a new thread for this.

Not really sure how this went from “Why doesn’t ALIGNMENT work within a TEXTAREA control, but it is stored and honored by DRAWBLOCK from that same TEXTAREA”…

Font are important… but that is NOT what I started this thread about

Agreed, it has gotten quite a bit off topic. I haven’t gotten enough time to look into your original problem yet, but I will reply when I do.

Thanks Joe… I appreciate it :slight_smile:

SelAlignment definitely seems to be broken.

As for your RTF issue, I don’t see anything about it in your demo project. Can you create a small demo project that reproduces the issue?

Alignment is the issue…

If in the project I linked above… if you select some text and center align it… .the TA does not change… but if you access the RTFData from the TA… \qc codes are there… if you use DRAWBLOCK to display the text in a canvas it is center alligned.

This is my only issue… is that a user cannot tell exactly how they have changed the text by looking at the TA, which happens to be WHERE they are editting the text.

That test application… IS the window used in my main project (minus the canvas I added for testing purposes)