discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [ANN] MyLibrary 0.3.1


From: Alexander Malmberg
Subject: Re: [ANN] MyLibrary 0.3.1
Date: Thu, 29 Jul 2004 03:10:41 +0200

Yen-Ju Chen wrote:
> >From: Stefan Urbanek <stefan@agentfarms.net>
[snip]
> >Btw. why do you use "Simple tags to render note (<b>,<i>,<link>...)."
> >instead of rich text directly? Rich text (attributed string) is nicely
> >supported by GNUstep. So instead of writing "<b>something</b>" I would
> >write "something", select it and use font panel or menu item to make it
> >bold. Same for links: mark a word or piece of text and say: "create a lnk
> >here!" (as it was in the WorldWideWeb.app -
> >http://www.w3.org/MarkUp/tims_editor). No need for tags nor tag parsing,
> >just attributed string.
> >
> >I'm just courious.
> 
>   I do think about it before.
>   The only reason to use tag is because I want to be able to access the data
>   without any graphic tool when data is corrupted or something went wrong.
>   The best situation is that user can set the tag and font attributes
> graphically
>   and save it as XML or other plain text format.

True, and this can be done very easily.

>   In other word, it is kind of RTF <-> XML conversion.

This sounds like a misunderstanding. An NSAttributedString is just a
string with attributes. It doesn't have any special relationship with
rtf, so there's no need for any conversion to or from rtf. Converting
the attributed string to some tagged format would just be a matter of a
loop along the lines of:


NSAttributedString *theText;
NSMutableString *output;
unsigned int i;
NSRange r;
NSDictionary *d;

for (i=0;i<[[theText string] length];i=r.location+r.length)
{
  d=[theText attributesAtIndex: i
        effectiveRange: &r];

  if ([d objectForKey: @"LinkAttribute"])
    add_to_output(@"<link ...>");
  if ([theSharedFontManager weightOfFont: [d objectForKey:
NSFontAttributeName]]>=9)
    add_to_output(@"<bold>");
  ...

  add_to_output([[theText string] substringFromRange: r);

  /* check attributes again and close tags */
  if ([d objectForKey: @"LinkAttribute"])
    add_to_output(@"</link>");
  ...
}

- Alexander Malmberg




reply via email to

[Prev in Thread] Current Thread [Next in Thread]