Very interesting. You have given me an idea but I will not be able to really
try it until tomorrow. It got me thinking whether there is a bug tied to the
line endings in the text data of the styledtext object. I am probably wrong,
but I can only base that on the fact when I was emitting the debug strings, I
could see the paragraph.startpos and paragraph.length properties changing (in
the way I expected them to based on the text I had entered). I also know that
the text from an editfield can be UTF-8 encoded... I wonder if that plays some
odd role in the way the styledtext object handles the text data being given to
it... But, like I said, if that parsing is automatic within the styledtext
class, and it is detecting the correct paragraph breaks (based on line
endings), then why would it only have a problem with the alignment parameter?
Odd 'eh? As I said in my original post, it -does- pay attention to the
alignment and it updates correctly, just that the last setting (to the last
paragraph) is the only alignment setting it will pay attention to... So why?
An honest bug?
-----Original Message-----
From: realbasic-nug-bounces at lists dot realsoftware dot com on behalf of Lars
Jensen
Sent: Thu 6/30/2005 5:49 PM
To: realbasic-nug at lists dot realsoftware dot com
Subject: Re: StyledText Not Holding ParagraphAlignment Assignment
> I have a duplicate method that will allocate a new StyledText object, then
> copy all of the StyleRuns from the source object. It then steps through and
> copies all of the paragraph alignments. However, if I set an editfield's
> styledtext property to my new object, I get all the stylings, but I lose the
> alignment settings. Actually worse, I don't lose them, it just makes
> everything the same as the last alignment setting.
I've spent much of the last couple of days investigating this very problem.
In addition, I find that if my original StyledText object contains a
newline, I see different arrangements of StyleRuns in the original vs the
copy.
> Now for the kicker... If I create a slightly different version of the =
> clone routine that takes a source and target editfield, my same code =
> (with the prepended 'editfield.') doing the same functions as described =
> above, works like a champ.
Most interesting...I wonder if the ones attached to the EditField use
different line endings -- this might relate to my newline problem.
BTW, I'm seeing this with Mac OS 10.3.9 using RB 5.5.2 and RB 2005. I just
make a copy and compare dumps of the copy and original. Here are my copy and
dump routines, pretty straightforward:
============================
Function CopyOf(Source as StyledText) As StyledText
// Returns a new copy of the source object.
// Copy the style runs, which include the text.
Dim NewText As New StyledText
Dim SourceRun, NewRun As StyleRun
Dim StyleRunIndex As Integer
For StyleRunIndex = 0 to Source.StyleRunCount - 1
SourceRun = Source.StyleRun(StyleRunIndex)
NewRun = New StyleRun
NewRun.Bold = SourceRun.Bold
NewRun.Font = SourceRun.Font
NewRun.Italic = SourceRun.Italic
NewRun.Size = SourceRun.Size
NewRun.Text = SourceRun.Text
NewRun.TextColor = SourceRun.TextColor
NewRun.Underline = SourceRun.Underline
NewText.AppendStyleRun NewRun
Next StyleRunIndex
// Copy the paragraph info.
Dim Alignment As Integer
Dim Para As Paragraph
Dim ParagraphIndex As Integer
For ParagraphIndex = 0 to Source.ParagraphCount - 1
Para = Source.Paragraph(ParagraphIndex)
Alignment = Para.Alignment
NewText.ParagraphAlignment(ParagraphIndex) = Alignment
Next ParagraphIndex
Return NewText
End Function
============================
Function Dump(extends Text as StyledText) As string
// This function returns a string containing the state of the
// given styled text object. The format is unspecified, subject
// to change, and not necessarily complete -- this is a debugging
// aid, not a serialization tool.
Dim ret As String
Dim Run As StyleRun
Dim StyleRunIndex As Integer
Dim MaxStyleRunIndex As Integer = Text.StyleRunCount - 1
For StyleRunIndex = 0 To MaxStyleRunIndex
Run = Text.StyleRun(StyleRunIndex)
// If we have output so far, add a blank line for readability.
If ret <> "" Then ret = ret + EndOfLine
ret = ret + "StyleRun(" + str(StyleRunIndex) + "):"
// For now, these seem to work, so exclude for readability.
'If Run.Bold Then ret = ret + " Bold"
'If Run.Italic Then ret = ret + " Italic"
'If Run.Underline Then ret = ret + " Underline"
'ret = ret + " Size=" + str(Run.Size)
'ret = ret + " Font=" + Run.Font
'If Run.TextColor <> &c000000 Then
'ret = ret + " RGB=" + Str(Run.TextColor.Red) _
'+ Str(Run.TextColor.Green) + Str(Run.TextColor.Blue)
'End If
ret = ret + EndOfLine + "Text=""" + Run.Text + """"
Next StyleRunIndex
// If we have output so far, add a blank line for readability.
If ret <> "" Then ret = ret + EndOfLine
// Now we do alignment. StyledText is split up into StyleRuns, but
// it's also split into Paragraphs, whose sole purpose (at present
// at least) seems to be keeping track of alignment. We'll have to
// store the starts and lengths of each paragraph too, because they
// overlap StyleRuns.
Dim ParagraphIndex As Integer
Dim MaxParagraphIndex As Integer = Text.ParagraphCount - 1
For ParagraphIndex = 0 to MaxParagraphIndex
ret = ret + EndOfLine + "Paragraph(" + str(ParagraphIndex) + "):"
ret = ret + " Alignment=" + _
str(Text.Paragraph(ParagraphIndex).Alignment)
Next ParagraphIndex
Return ret
End Function
============================
lj
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>
|