Best way to compare NSParagraphStyles?

  • Hello,

    In my app I have the need to compare two
    NSParagraphStyles to see if they are the same. I
    basically have a dictionary of preset text attributes,
    and the user can pick from a list to switch between
    them while writing. The app needs to keep track of
    which attribute is currently in use, so that it can
    display this information in a status bar along with
    other things.

    I do this by comparing the NSParagraphStyle in the
    typing attributes dictionary with the paragraph styles
    in the attributes inside my preset dictionary. This
    works fine until a file is saved to disk (as RTFD) and
    then reloaded. Once this happens, it seems that the
    reloaded text is no longer the same as it used to be.
    For instance, the paragraph style's first line head
    indent and normal head indent can be off by a
    fraction. Also, NSLeftTextAlignment can become
    NSNaturalTextAlignment after a save and load (and I
    bet this could also happen to NSRightTextAlignment
    where that was natural for the used script).

    So, my question is, what is the best way to compare
    two NSParagraphStyles, which will work even after the
    text has been saved as RTFD and opened again? At the
    moment I am going through every paragraph style
    setting I actually use and comparing them manually,
    but I have to round certain values (because the head
    indent can be off) and count NSNaturalTextAlignment as
    NSLeftTextAlignment, all of which seems awkward and
    could conceivably break.

    Thanks in advance for any suggestions or advice.
    All the best,
    Keith

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
  • On Oct 4, 2006, at 1:56 PM, Keith Blount wrote:

    > I do this by comparing the NSParagraphStyle in the
    > typing attributes dictionary with the paragraph styles
    > in the attributes inside my preset dictionary. This
    > works fine until a file is saved to disk (as RTFD) and
    > then reloaded. Once this happens, it seems that the
    > reloaded text is no longer the same as it used to be.
    > For instance, the paragraph style's first line head
    > indent and normal head indent can be off by a
    > fraction. Also, NSLeftTextAlignment can become
    > NSNaturalTextAlignment after a save and load (and I
    > bet this could also happen to NSRightTextAlignment
    > where that was natural for the used script).

    These and other imprecisions are related to peculiarities of the RTF
    format.  For example, RTF stores many length measurements as integral
    multiples of 1/20 of a point, colors as 24-bit RGB, etc.  If you know
    that you are going to be using RTF, then you can account for these
    individually, as you have been doing.

    Douglas Davidson
  • On Oct 4, 2006, at 1:56 PM, Keith Blount wrote:

    > So, my question is, what is the best way to compare
    > two NSParagraphStyles, which will work even after the
    > text has been saved as RTFD and opened again? At the
    > moment I am going through every paragraph style
    > setting I actually use and comparing them manually,
    > but I have to round certain values (because the head
    > indent can be off) and count NSNaturalTextAlignment as
    > NSLeftTextAlignment, all of which seems awkward and
    > could conceivably break.

    One other possible solution to this, by the way, would be to
    normalize a given paragraph style by attaching it to a small piece of
    text, converting it to RTF and back in memory, and obtaining the
    paragraph style of the result.  You could then compare the resulting
    normalized paragraph styles.

    Douglas Davidson
  • Thanks for your reply - this sounds like a very good
    solution, which had not occurred to me. I will take
    this route.

    Thanks for all your help (as ever - the amount of help
    you have given me with the text parts of my app
    through this list is incredible - your name was in the
    credits a year ago :) ),
    Keith

    --- Douglas Davidson <ddavidso...> wrote:

    >
    > On Oct 4, 2006, at 1:56 PM, Keith Blount wrote:
    >
    >> So, my question is, what is the best way to
    > compare
    >> two NSParagraphStyles, which will work even after
    > the
    >> text has been saved as RTFD and opened again? At
    > the
    >> moment I am going through every paragraph style
    >> setting I actually use and comparing them
    > manually,
    >> but I have to round certain values (because the
    > head
    >> indent can be off) and count
    > NSNaturalTextAlignment as
    >> NSLeftTextAlignment, all of which seems awkward
    > and
    >> could conceivably break.
    >
    > One other possible solution to this, by the way,
    > would be to
    > normalize a given paragraph style by attaching it to
    > a small piece of
    > text, converting it to RTF and back in memory, and
    > obtaining the
    > paragraph style of the result.  You could then
    > compare the resulting
    > normalized paragraph styles.
    >
    > Douglas Davidson
    >
    >

    __________________________________________________
    Do You Yahoo!?
    Tired of spam?  Yahoo! Mail has the best spam protection around
    http://mail.yahoo.com
previous month october 2006 next month
MTWTFSS
            1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31          
Go to today