realbasic-nug
[Top] [All Lists]

Re: StyledText Not Holding ParagraphAlignment Assignment

To: <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: StyledText Not Holding ParagraphAlignment Assignment
From: Lars Jensen <larsjensen at rcn dot com>
Date: Thu, 30 Jun 2005 17:49:15 -0400
Delivered-to: realbasic-nug at lists dot realsoftware dot com
> 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>

<Prev in Thread] Current Thread [Next in Thread>