• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to draw a horizontal line in a NSTextView?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to draw a horizontal line in a NSTextView?


  • Subject: Re: How to draw a horizontal line in a NSTextView?
  • From: Mike Ferris <email@hidden>
  • Date: Tue, 10 Dec 2002 11:35:58 -0800

The HTML stuff does pretty much exactly as I described earlier. It implements horizontal rules using attachments. You cannot really use the implementation in the HTML stuff because it is private and the only public entry point is to ask it to parse an HTML stream.

The way attachments work is:

- A special character (0xfffc, or NSAttachmentCharacter from NSTextAttachment.h) is inserted in the text.
- The NSAttachment attribute is set on that character with a value that is an instance of NSTextAttachment.
- The NSTextAttachment has an (id <NSTextAttachmentCell>)
- When the text is being laid out, attachment characters are laid out by asking their cells how big they are.
- When the text is being drawn, attachment characters are drawn by asking their cells to draw themselves.

The easiest way to do this is to write a very simple subclass of NSTextAttachmentCell that always measures the width of the text container it is being laid out in and draws itself in the obvious way. Then, just insert an attachment character, create an NSTextAttachment with an oinstance of your subclass as its cell, and assign the attachment to the NSAttachment attribute of the attachment character.

Mike


Begin forwarded message:

From: Arthur Clemens <email@hidden>
Date: Tue Dec 10, 2002 6:03:48 AM US/Pacific
To: Cocoa Developer List <email@hidden>
Subject: Re: How to draw a horizontal line in a NSTextView?

On zaterdag, dec 7, 2002, at 05:37 Europe/Amsterdam, Dietrich Epp wrote:

On Friday, December 6, 2002, at 04:13 , Arthur Clemens wrote:

It's probably simple, but I cannot find a way how to draw a
horizontal line in a NSTextView.
What I have in mind is something similar to a <hr> tag in HTML: it
gets wider as the text view is scaled.
I could use a NSBezierPath, but how to manage that it scrolls
together with the text?

Read the big spiel about it on Apple's website. It is not trivial.

http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/
ProgrammingTopics/
Misc/TextHandlingPage.html


Still, if I use a NSTextView as browser (I was trying out sample code
from CocoaBB: http://jrepp.com/cocoabb/viewtopic.php?t=32 ), <hr> tags
are rendered normally.
So it seems there is an easier way.

When I print out the NSMutableAttributedString that stores the HTML data

[[NSMutableAttributedString alloc] initWithHTML:[[myURL
URLHandleUsingCache:YES] resourceData] baseURL:myURL
documentAttributes:nil];

I get this with an HTML document with only a <hr> in the body:

\\ufffc{
"HTML_Tree_Retain" = <HTMLDocument: 0xacbfe0>;
NSAttachment = Name "<No name>";
}
{
"HTML_Tree_Retain" = <HTMLDocument: 0xacbfe0>;
NSFont = "CGS Times-Roman 12.00 pt. P [] (0x00b3a760)
fobj=0x00b35930, spc=3.00";
}

How can I pull out this and use it in another application? And what is
in this NSAttachment?


Arthur Clemens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: How to draw a horizontal line in a NSTextView?
      • From: Arthur Clemens <email@hidden>
References: 
 >Re: How to draw a horizontal line in a NSTextView? (From: Arthur Clemens <email@hidden>)

  • Prev by Date: Re: how do I get the "key" sub view of a window?
  • Next by Date: Re: Best way to do multimedia app
  • Previous by thread: Re: How to draw a horizontal line in a NSTextView?
  • Next by thread: Re: How to draw a horizontal line in a NSTextView?
  • Index(es):
    • Date
    • Thread