WWDC2003 Session 427
Transcript
Kind: captions
Language: en
you guys are hardcore excellent it's
been a long long week but we got
somebody here is going to make it all
worthwhile Doug Davidson is going to
talk to you about some of the really
cool stuff in Cocoa tech so help me
welcome to Sage Doug Davidson okay
thanks Jason I'd like to thank you all
for coming I like to think we've saved
the best for the last as i said i'm doug
davidson and i'm here to talk to you
about the cocoa text system now anyone
has worked with cocoa at all has seen
the text system in action because in
almost any case where cocoa application
puts up text on the screen the text
system is responsible for it in one way
or another so the cocoa tech system is
at the heart of a lot of the things we
do in cocoa now what I'm going to do in
this session is first of all I want to
go briefly through some of the features
of the cocoa tech system then we're
going to dive in and explain how to
start using them but the primary
emphasis that I want to have is on what
I think is the most interesting part of
the tech system that is customizing it
for your particular application because
one of the principal design points the
cocoa tech system is that it should be
highly customizable throughout now as
far as features go if you've used text
edit you're probably familiar with a lot
of the features of the cocoa tech system
already because most of what you get
with text edit are things that you will
get for free whenever you use the tech
system provided that you check the
appropriate boxes and interface builder
so showing this better than telling so
let's move on over to the demo and let's
take a look
now what I have here is my version I
just wrote of a very simple editor that
you've probably seen demoed over and
over very little code but it has all the
features that you would expect features
that we know and love but now this is
running on Panther so we might expect
something more for example fine panel
and Panther the fine panel is now built
into the text system it took me 0 lines
of code to add this to my app and it's
fully functional and actually quite cool
features also for Panther we have
completely redone the text ruler the old
confusing line spacing controls that
nobody can understand are gone by
popular request in their place we have
this neat little pop up here that by
default allows you to pick single
spacing or double spacing or in fact
just about any kind of spacing you might
like now we certainly didn't have user
interface in Jaguar for most of these
features and in fact some of them are
completely new for Panther so for
example the line hide multiple let's try
picking one and a half line spacing and
you'll notice that when we go back
that's now showing up on the pop up so I
can get to it easily again we also have
this other little pop-up over on the
other side this is the style pop up and
what this allows you to do is to save
any styles that you might like or use
frequently so you can have them right at
your fingertips whenever you want them
now for demo purposes I've already
pre-loaded this with a number of styles
because I want to show off some of the
new absolute features that we have in
Panther for example underlined in jag
where I think we had two different
underline styles on Panther we have I
think its authority for example you
could get a double underline or a dotted
underline or colored online it's
basically just about anything you'd
expect also we have taken the strike
throughs and separated them from the
underlines and given them the same sort
of options so you can get double strike
through cause strike through and so
forth what else we now have outlined
common request but we don't just have a
single outline style we have a fully
adjustable parameter so that you could
get for example heavier outline if you
like or a lighter outline but that's not
all you also get to set independently
the colors of the outline and the
interior of the text so you can get some
sexay like this now if you want to Coco
update talk you've heard about a new
class and a shadow that allows the
setting of a drop shadow on drawing but
it's also available as a text attribute
so that you could have a figural shadow
maybe a little tiny shadow I'm not sure
if you can see it on this big monitor or
perhaps a sum up large or somewhat
slower shadow or essentially any shadow
you want
now what I'd really been intending to
type here was something more spectacular
but I forgot how to spell spectacular
but that's okay in cancer because I just
start typing and complete and then oh
there it is now now this this text
completion is fully customizable and
i'll be showing a demo of that later on
but for this particular application i
decided i wanted to write zero lines of
code for it and so all i got is the
default built-in functionality which
uses the system spelling dictionary plus
anything i happen to have in my document
already so let's put it all together I
have a somewhat more complicated style
here so a little something more
spectacular for Panther oh yes there's
one more thing when i go to save this
document i can save it as rich text so
or plain text just as you'd expect but
there's one more option here i can also
save this as a word document so this
simple 51 application can read and write
word document as a matter of fact in
Panther any cocoa application can now
read work documents without changes of
code provided with using the standard in
it with path or knit with URL ap is
writing word documents is a little more
difficult you need to have one line of
code for that
as far as reading word documents we go
back as far as words six I think it is
for writing muse the most recent format
which is roughly word 97 and later you
may have heard that word has a new xml
file format called word ml and we need
that too now I have to caution you of
course there is going to be some loss of
fidelity because the cocoa tech system
does not support all the features that
word does and vice versa well most
notably for example the tech system
doesn't have support for tables yeah but
whereas before what you have to do is
open up the document in word save it as
RTF then open it in a cocoa application
now we cut out that stuff entirely you
can just open it directly in cocoa
application and get the same effect okay
so now let's go back to the slides
and so what I want to do is review
briefly
there we go review briefly the new
features that we've added to Panther so
we have the new attributes and attribute
features that I've showed you that
outline shadows underline strikethrough
and so forth we also have a couple of
new attributes the tooltip and purser
attributes that allow you to set a tool
tip or a custom cursor associated with a
particular region of text and we have a
little something called a link
attributes that i'll be showing you
later on we have new paragraph style
features such as the new line spacing
options that I showed you and there are
also some new tab stop features that I
won't have time to go into right now we
have some whole new API sets and it
slipped generator and NSA TS types that
are will be discussing more later on and
then we have the most obvious invisible
new features like the new font panel
you've probably seen the new text ruler
I showed you the fine panel completion
reading and writing diplo word documents
and there are quite a few other
individual AP is that I may not be able
to go into in detail here but I wrote a
number of pages of release notes about
them so i urge you to take a look the
release notes take a look at the headers
with all the new things for Panther are
clearly marked in the headers and I
think the release notes should go into
quite a bit of detail describing what
these things are what they do one other
thing that's new for Panther is the
WebKit and some of you may be wondering
what's the relationship between Texas
and text views and WebKit in the web
views well the short answer is is
they're different in much the same way
that a web browser is different from
word processor the fact that matter is
that most web pages that they don't look
very much like text pages and WebKit
they know they're full of frames and
plugins and JavaScript and so forth and
WebKit is aimed squarely at the display
the most complex HTML so if what you
want is to display a chunk of HTML in
your application probably what you want
is a webview on the other hand if you
want what you want to show is really
text or in particular if you want edit
ability then you want to text view and
there's a sort of a bridge between them
and that is that the cocoa tech system
does have an HTML import feature which
is necessarily lossy but it does at
least allow you to get the text rich
text content of HTML into the text
system so now it's time to dive in and
start showing you how to use all these
features and new features and so forth
but before I do that I want to put some
structure and organization on my
discussion of the text system and the
paradigm I like to use is
[Music]
model-view-controller you we've heard it
many times within the context of the
text system the model is the text
document the characters and their
attributes the view is the text view
seen that handles the user input and
display and the controller classes
handle everything in between you can do
quite a lot in the text system just by
dealing with in a text view as we'll see
the text view is the visible face of the
text system for most purposes and what a
text view is is a representation of a
single region within which texas laid
out such as a page and it handles all of
this display and all the user
interaction for the text on that page if
you have say multiple pages then you
would have multiple text views and those
sibling text views would know about each
other and work together a nav a certain
amount of shared state there are a few
other tax classes that come in and work
with the text system at the view level
for example that its standard cocoa
ruler classes are used and displaying
the ruler for text and then there's a
class called and a text attachment sell
its especial kind of self that is used
for displaying the icons or images
corresponding to in line attached file
and the most visible new features for
Pantha come in at the view level the
updated font towel I mentioned that
new text rulers fine panel completion
and the curses and tool tips that I
talked about and in the context of the
text system the model as i said the text
document and the class is all serious
and it's text storage now and it's text
storage is a direct subclasses and it's
mutable attributed string and that's how
you should think of it as a mutable
attributed string with a few extra
features primarily being that the text
storage notifies the rest of the text
system whenever it changes so the
technician can respond what is an
attributed string an attributed string
contains and in a string which is
conceptually sequence of unicode
characters but in addition it has
attributes so conceptually to each
character it applies a dictionary of
attributes and this dictionary has keys
that are in a strings and there are a
bunch of standard values you can also
use custom values of your own and the
values in this dictionary well they
depend on the key so for example the
value for the font attribute is Anna
spot value for various color attributes
or ennis colors and so on so there are a
number of different classes that come in
to the model layer here as values of
attributes and its font and its color
and it's paragraph style that I'll be
talking about and a shadow that you've
heard about before in addition to the
standard value classes like in this
number there are a couple of other
classes that are used to your shuffle
special classes and if text attachment
is a model for the contents of an inline
attached file and I like to put in a
text container as a model level because
it's a purely geometric object at what
Anna text container is is modeled the
geometry of a page for example the shape
and size and so there's one associated
with each text view
so what are these attributes the
standard ones that are recognized and
understood by the text system are listed
in an appt get header called and it's
attributed string dot H in the app kit
and they include most of what you'd
expect fonts colors underline
strikethrough and so on and so forth
there are a few things that don't appear
as individual separate attributes for
example bold and italic are not separate
attributes they're treated as straight
to the font and we use an ass Pont
manager to add these trades or remove
these trades from fonte also anything
that is part of a paragraph style like
margins tab stops line spacing and so
forth it's not a separate attribute but
instead it's a feature of and a
paragraph style object that encapsulates
all that information and then there are
some special attributes that deal with
view and display and interaction like
the cursor and tooltip attributes as I
mentioned before and then there's a link
attribute that's used whenever Texas as
a hyperlink associated to it and the
attachment attribute that's used when
there's an inline attached file and we
have quite a lot of new features in
Panther the absolute level we have the
stroke width and stroke color that I
demonstrated for reviews for outlines
the new underline styles and colors
rights yourselves divorce the shadows a
couple i haven't mentioned those
bleakness and expansion you can look at
so they can look up those up and the
cursor and tooltip attributes so now we
have enough to talk about it was more or
less the first level of customization of
the text system where you deal with the
view and the model layers only and you
don't worry about what comes in between
so the first thing you should think
about when trying to customize this
level is receiving notifications from
the text view or acting as a text youth
delegate now the text views delegate is
actually very powerful for example the
text youth delegate is notified whenever
the user makes any change the text and
the delegate has the opportunity at that
point to accept or deny or modify that
change so the text use delegate control
whatever the user does
text you the text to delegate is also
notified if the user makes a change to
the selection in the text view and again
has the opportunity to accept or deny or
modify that change and there are many
other text view delegate methods to give
the the delegate control over a lot of
things that are going on with the text
view and its user interaction but in
some cases you'll find you want to do
some kind of customization that you
can't do as an excuse delegate at that
point then it's time to start thinking
of sub classing in a text view if you
went to the tips and tricks session
earlier today I gave an example of a
custom subclass aventis text view that
was intended to do some additional
drawing it was drawing bubbles around
the text so much the sword way that I
chat does resemble and you can also a
subclass for to customize the user
interaction of the text view number by
the way I'm going to give an example in
a minute that will I think show clearly
the distinction between delegation and
sub classing and working within a text
view now when you go to customize the
Texas and it will often happen that you
want to make modifications to the text
that you're working on and the way this
typically works in the tech system is
that user initiated changes to the text
go first the text view and then threw it
to the text storage whereas programmatic
changes will typically go directly to
the text story but they all end up with
the text storage in the end and the text
storage as I said is a mutable
attributed string when you want to
change it you just use mutable
attributed string methods to alter it
but as I also said it has this
additional feature that it notifies the
rest of the Texas and whatever it
changes so if you're going to be making
multiple changes to the same text
storage in a row what you want to do is
wrap those in a call to begin editing
and end editing and what that will do is
cause those notifications be coalesce
into a single one at the end for
efficiency's sake you can also subclass
in a sec stories but that's a little
more difficult
talking about that later on so let's go
over to the demo again and i want to
show an example of customizing text view
both is delegate and subclass so we have
here we're going back to text completion
and you'll recall I told you that text
completion was fully customizable so
here's a custom completion that you
might use if you are working and say
financial reporting what this will do if
you type in the name of a company until
you complete it will complete the name
of the company it will also add the
stock ticker symbol and if there's more
than one and you get a list and you get
the pic right and you'll notice that
these things are the stock tickers here
are blue and underlined and it fax line
mouse over then i get a pointing hand
cursor which is a clue that these are
actually linked and i chose to set them
up this links to the stock price i see
we're not doing so well so how do we do
this let's see if we can take a look at
the code there we go
okay so I set this up as a text view
that has both a delegate and it's also a
custom subclass now that what the text
views delegate can do in the context of
completion the delegate is allowed to
have complete control over the list of
completions that's presented their order
and which one is first selected so
that's the first thing we're doing as a
delegate we implement text view
completions for partial word ranges and
so forth and we have a dictionary hear
that whose values are the company names
and keys are the symbol ticker symbols
and so the possible completions are just
the whole list of company aims all the
keys in the dictionary and all we do is
go through and see if the partial word
that we're completing has one is a
prefix to one of those then we add a
holistic completions and we're done so
that's what you could do acting with
completion acting with the text views
delegate but we also did something more
when the completion was actually
accepted and confirmed we added in the
stock ticker symbol and made it awake
now there are a number of methods
associated with completion that are
designed to be over I double x sub
classes and one of them is this method
and search completion for partial word
range that handles putting the
completion back into the text now
there's one thing I just skipped over
that I probably should mention and that
is this we made a call to set link text
attributes now when you set link text
attributes on a text view this is a
special set of attributes that the text
view will automatically apply to text
that has a link on it so in this case
we're making it blue and we're giving it
underlined and we're adding pointing
hand cursor to it so all text it has a
link will automatically get those
attributes applied to it
so now our subclasses method for
inserting completion what it's going to
do is it gets told whether this is a
tentative completion or final confirmed
completion and if it's a final confirmed
completion and we have the stock ticker
symbol for it then what we're going to
do is let it be inserted as usual we
call super method and then we're going
to create a proprietary ng to be
inserted so we add the ticker symbol to
it then we got a URL and you add this
link attributes to the appropriate range
corresponding to the ticker symbol and
then the textview automatically does the
rest applying the blue color of the line
and cursor to it because he said the
link text attributes you could also have
complete control over the list of
completions presented as a textview
subclass but I chose extended in a
delegate in this case just to make the
distinction clear okay so let's go back
to the slides
okay now you could do quite a bit with
the cocoa text system by dealing only
with the view and the model layers and
never worrying about what happens in
between but at some point you're
probably going to get curious and wonder
how it is the Dakota Texas and actually
goes from the characters and their
attributes in the text storage to the
pixels you see on the screen but before
I discuss that I'm going to need to
introduce another concept and not as a
cliff now characters in the text storage
are unicode characters but a glyph is
something different a glyph is a single
displayable element of a particular font
it has no meaning outside of the
particular font that is in so in some
sense the job of the text system at
least at the controller level is to take
the characters and attributes in the
text storage and to convert them to a
sequence of glyphs and their positions
that can be displayed that's not quite
as simple to might sound for example the
relationship between characters and
glyphs is not one to one it's
potentially many dimension so for
example if we look at the character we
recognized as an accented a cute accent
at a in Unicode this can be represented
either as a single axon to a character
or as two characters in a and accent
likewise depending on the thought it
might potentially be represented by one
acted at a cliff or might be represented
by two glyphs and a accent and the tech
system has to keep track of all that in
the relationship between the two and
then it has to calculate the appropriate
position for the glyphs so that we end
up with a final displayed result that is
appropriate glyphs in the appropriate
places of the appropriate attributes so
one of the classes that are actually
involved in doing this the principal
class that ball cheers and it's layout
manager and a flap manager is the heart
of the text system it is the controller
class in the cocoa text system I said
that the text storage notifies the rest
of the text system when a chain
well it's the layout manager that gets
notified by the tech storage and when
that happens the layout manager keeps
track and it ranges for all the
necessary work to be performed so that
the glyph and their positions are
available when needed for displaying the
text there are a couple of subsidiary
classes that it calls upon to do this
and it's glyph generator and NS
typesetter and these are new for Panther
and it slipped generator is new on and
it's typesetter itself is not new but
the main concrete subclass and it's 80s
types that are is new for panther and
i'll be discussing these in more detail
later on and then the layout manager
stores all the information about the
sequence of glyphs and where their
position and it's actually a layout
manager that does the display ranges for
them to be displayed as necessary when
requested to do so by the view so how is
it the text gets from the characters and
attributes in the text storage to the
pixels you see on the screen there are
four separate steps I want to go through
them in order first attribute fixing we
make sure the attributes are consistent
second glyphs jason where we convert the
characters and their fonts into glyphs
third layout where these glyphs are
broken up into lines the glyphs the
position in the line lines a position on
the page and finally display where the
glyphs are marshaled up and sent down to
ports to actually be rasterized and it
fits on the screen or displayed on the
printer or PDF or what have you and in
the Coco tech system all these processes
are usually done lazily and on-demand so
what typically happens is that although
these occur in this order they get
pulled through from the end so what will
happen is that the text view will be
required to redisplay a certain region
so it will call on the layout manager do
that and the layout manager in order to
do that needs the layout information so
the layout information have to be
calculated but to do the layout you need
to have generated the cliff
so it causes that to be done but in
order before you generate the cliff you
need to fix the attributes so it causes
all that to occur in order pull through
from the end attribute fixing now
attributed fixing is actually performed
by the text storage there are several
different kinds first of all there's
font fixing where we make sure that the
thought that's applied to a particular
character is actually font that can
render that character and we will the
Coco tech system will substitute fonts
as necessary in order to get one that
can render the specified character and
there's paragraph fixing you remember I
talked about the end of paragraph style
attribute that encapsulates all the
paragraph style level features well what
we need to do is make sure that that
attribute is actually constant over the
length of an entire paragraph of text we
can't have more than one for a given
paragraph and then there's attachment
fixing which makes sure that the
attachment attributes applies only to
the attachment character what it's
supposed to and can all these be
customized yes they can be customized by
subclassing and a text storage and
overriding the appropriate methods next
glyph generation now when the layout
manager is informed by the text stories
that things have changed it will have to
invalidate a certain portion of any
information that already has due to that
change you can also manually cause the
layout manager to do this invalidation
if you want to force them recalculation
and so then when that information is
needed again the layout manager will
call on the glyph generator typesetter
to recalculate the information about
what the glyphs are and where they were
positioned and it is and it's glyph
generator that actually does a
conversion from characters and fonts to
the glyphs and the layout manager stores
the sequence of glyphs that it has
produced and the lamp because the
relationship between characters and
glyphs
not one to one the layout manager also
has to keep track of the relationship
between character indexes and glyph
indexes and if you ever need that
information you go back to the lab
measure and ask it then comes layout and
the layout manager calls on the
typesetter to perform the layout the
types that are goes back to the layout
manager to find out what the glyphs are
but they're already been generated and
it goes to the text container to
determine the geometry of the page to
figure out where it can put lines on the
page and then the typesetter is the
class that actually calculates the
layout it breaks the text up in two
lines positions eclipse in the lines and
it is also allowed at this point to
insert or change glyphs and the glyph
stream for example if it's doing
hyphenation it may need to insert a
hyphen cliff and then the types that are
called back to the layout manager and
tells it what it did that it tells it
where each line ended up and which lifts
ended up in the line and where it goes
through positioned in the line and the
layout manager stores that information
then display when the textview needs to
redisplay a certain region first thing
it does is go to the layup measure and
ask it what glyphs are involved what
glisten needed to display that
particular region of text and then it
calls back on the layout manager again
first to cause the layout manager to
display the background appropriate to
those glyphs that's typically things
like the selection rectangles and
finally to ask the layout manager to
display the glyph and along with any
other additional drawing that's needed
like underline strikethrough attachments
and so forth now it's not just in a text
view that can do this your custom view
can do it too in fact there's an example
developer examples app kids circle view
that does this there are a couple things
you have to remember if you're going to
do this when you call on the layout
manager to do this sort of drawing you
must already have focus locked on a flip
view if you view is clipped and you're
in your drawer ex method that's all
nautic another thing you have to keep in
mind is that the layout manager keeps
track of all its positions relative to
the origin of the text container for the
positions of lines and so forth which
may not be the same as the origin of
your view in fact that organisms so
you'll have to translate between
coordinate system and it keeps track of
the location of positions of glyphs
relative to the origin of the line in
which they live so there's a certain
amount of translation that have to go on
and we'll see an example of that so now
we have enough to talk about what is
more or less the second level of
customization where you are actually
getting information about where
individual pieces of text our position
on the screen and the source of all such
information is the layout manager layout
manager knows all the goop on the layout
manager if you need to go from a
character range to cliff range or vice
versa which you will often need to do
you call on the layout manager to get
the position of a particular glyph or a
petition and pods pick your line or to
go backwards and give it a position the
locator glyph or given a rectangle
locate the glyphs in it all that sort of
thing is on the layout manager there are
quite a few methods do this it's also
possible to subclass the layout manager
if you want to customize any of its
particular features so for example if
you have a custom attribute that you
want to affect drawing at the individual
glyph level one way to do that is by
subclassing and ass layout manager and I
give an example of that so let's go on
over the demo again
well let me see if I can bring this up
okay so here I have some chinese test
now these characters are beautiful and
concise but one thing that they don't
necessarily do except especially for
someone like me who doesn't read very
well is make it obvious how that they're
intended to be pronounced so over the
years that have evolved a number of
schemes for adding some sort of phonetic
annotation to characters in some cases
the annotation appears above the
characters or in some cases it appears
decide the characters but either way it
makes it crystal clear how these are
intended to be pronounced for example
this is to be Georgie by son who died
but fortunately the dictionary where I
got these pronunciations also gave me
some clue as the meanings of these
characters so we can display that and
that will help us to recognize this
quotation air from the art of war which
might be rendered as if you know your
adversary and you know yourself you need
not fear the result of a hundred battles
so the Texas and doesn't have any
built-in facilities for this sort of
thing this is all customization how do
we do it let's take a look
what I've done is to define some custom
attributes and I have some code that is
fairly simple and kind of simplistic
actually that sets these attributes
based on a dictionary that I provided it
and so what I'm going to show you
actually all this code should be
available for download from ABC if not
now then very soon what I've done is the
subclass in a sleigh up major and
override the primary draw map that draw
with griff range at Point and so what
we're going to do here is we're given a
glyph range we need to look at some of
these attributes so first we convert it
back to a character range now before we
do any of our own drawing we're going to
call on the super method to actually
draw the glyph the original if and then
the next thing we're going to do is draw
all these annotations and it's actually
not that complicated what we do is it go
through they text the characters in the
text storage and we look what we do is
here we look for any characters that
have our custom attribute and we also
have calculated what glyph corresponds
to this character and where it's located
as far as a point and where it's line
lives and then you remember I talked
about all the translation that needs to
be done well to get from the coordinates
of a glyph a as the layout matter gives
them to you to coordinates in your view
you need to add you need to translate by
the origin of the line rectangle that it
lives in and by the origin of the
container and all that is available this
is a very standard idiom and we also get
some information about the glyphs and
the thought that we're going to use in
doing our siding so the value of this
attribute is just the little string that
we're going to show as an annotation and
basically all we do is figure out a
wreck where we
to put it and some attributes draw with
and to destroy the bottom annotations
for the meanings are essentially the
same the right annotations between fool
how are a little more complicated
because in that case each glyph has to
be positioned individually but i'll let
you look at that once you've downloaded
this and that I think is all this so let
us go back to the slide so now we come
to most difficult part of the talk where
we discussed and a typesetter as I said
and it's typesetters a class that
actually performs the layout and that's
what Megan Lee makes this topic so
complex because layout is inherently
complex and as typesetter itself is a
mostly abstract superclass if you wanted
to provide your own complete layout
engine and it's highly replaced the one
that's Texas and uses then you can sub
that in a typesetter directly but most
people probably not going to want to do
that the main concrete subclass of ennis
typesetter is NF 80s typesetter which
performs the standard system layout and
if you want to use that for the most
part but make some minor modifications
to it then you can sub class in its 80s
typesetter now this is new for Panther a
new class new lots of new public API and
it's 80s types that are actually existed
before but it was completely private the
methods were all different so you can't
use it before Panther now what generally
happens is that when the layout manager
needs a certain portion of text to be
laid out it calls on the types that are
an asset to lay out a certain number of
lines
then the typesetter goes back to the
layout manager to get information about
the glyphs that need to be laid out and
it goes to the text container to get
information about the geometry where the
lines can be placed and then it does its
thing it does all the layout and it
calls back to the layout measure and
tells it what it did tells it where each
line went which glyphs went in line and
where all the glyphs the position in the
line and at this point the typesetter is
allowed to insert or modify cliffs in
the glyph stream and it tells the layout
manager about that too for example as I
said if it's doing hyphenation it may
need to insert a hyphen now for those
have you been waiting for it now in
Panther we have implemented truncation
with ellipses that is no now implemented
the types that are level so you can use
it and in that case the typesetter would
need to work with the glyph dream to
make sure they look sources in there and
it may happen in the number of cases
that a certain glyphs need to be
modified if they should appear at the
end of the line and in that case the
types that are would have to do that at
this stage because it's only the
typesetters knows which where the end of
the line is and NSF to acs typesetter
has a number of methods and they're
divided into several different groups
for several different purposes there is
a interface that is intended primarily
for sub pastors who want to modify
layout in the text system and they're
allowed to do various things to that
always Gus later on there is also a
glyph storage interface to annex 80th
typesetter that has a slightly different
purpose the purpose of the glue storage
interface it may be that in some cases
you want to use NS 80s types that are by
itself without any of the rest of the
text system and what the glyphs stories
interface does is to encapsulate all the
calls that the layout manager Mick
that the types that are accuse me makes
back to the remainder of the text system
so you can override that and replace all
this interaction with your own custom
method of storing cliffs or storing text
or what have you and what this allows
you to do is to make use of the system
line layout algorithms without having to
use any of the rest of the text system
if that is what you want to do but in
most cases if you're going to sub bass
in it's the 80s typesetter it's going to
be because you want to make some custom
modification to lay out that it does so
what you can do with this is that you
can be notified as the text is being
laid out you allowed to modify the
position and size of the line fragments
as the lines are being laid out you get
some control over line breaking
hyphenation and so forth so I have a
demo of this let's go back to the demo
machine
this is actually the same demo I had
before it would one thing you'll notice
is that as the annotation secure and
disappear the height of the line changes
correspondingly and to do that I
actually sub fast and a typesetter and
implemented a particular method it has
this is also the means for example by
which I chat make sure that the
paragraphs of text line up with little
pictures of your body on the side and
what this method does is the types of
sub class gets cold whenever a line has
been laid out and you get passed by
reference the wrecks of the line the
glyph range and they used wrecked that
is the portion of that rectangle that
was actually occupied by text and a
baseline and you get a chance to modify
them before they get set off to go out
manager so what we're doing here is
fairly simple again we have we're past
in the glyph range we need to convert it
back to a character range and we go
through it and all we do is we look for
our custom attributes and see if we find
them make a note of the font that they
appear in so we can calculate how much
space is actually needed and if we found
any and we have some space then we add
it to the line fragment and adjust that
as we need so that here let me once
again
so that the line fragment expands but
only for those lines that actually have
that characters with this attribute all
the rest are unaffected all right let's
go back to the slides so now it's time
to wrap up of course there's no longer
any opportunity to go to any further
session but you will presumably be able
to view all these on DVD or by some
other means there have been a number of
other sessions on Coco Coco update
session discussed briefly some of the
changes we made to text for Panther the
cocoa tips and tricks session as I
mentioned earlier today had an example
actually several examples that make use
of text for various things we're adding
particular for adding drawing to the
text view so if you're interested in
that you should probably take a look at
that session and you can take a look at
the code from that which is we have
verified now available for download
already and there are a number of other
sessions that may be interesting for
those of you who want to deal with text