WWDC2004 Session 202

Transcript

Kind: captions
Language: en
good afternoon everyone I'm Travis
Browne I'm the graphics and imaging
evangelist for Apple and I'm one of the
people who put together essentially all
the content you're seeing in the graphs
of media track this year and if you look
at at least what we've talked about the
sessions that we've had thus far it's
been a lot of new technology that you
know flashy things like core image
really powerful new trend tarnishing
harnessing the GPU which are all very
exciting but one of the other things you
want to bring this table to the table is
here in tiger essentially looking at the
technologies that we've already embraced
in Mac OS 10 and figure out ways to help
developers better leverage those
technologies and one of the significant
technologies that we do use in the 2d
space in matte goes tennis pdf.pdf is a
fantastic you know graphic file format
which is the way we primarily use it
today where we use it as sort of a
system-wide meta file that is not only
you know high fidelity but also give
this ability to change our concept with
other platforms but really PDF is much
more than that you know Adobe's been
very innovative with PDF and continues
to move it forward and is really created
sort of a standard for rich documents
and this is one area where they just in
courts 2d 2d API which is primarily
about drawing PDF was you know not
sufficient for a lot of what needs that
PDF could power or at least solve so for
Tiger we've created something called PDF
kick which is a essentially technology
that's designed to help developers
leverage PDF and their applications by
handling a lot of the work we're mating
relating to managing a PDF document this
is navigation searching various other
features like printing and we want to
make it as easy as possible for all
applications to participate in the PDF
experience because we think that's a
very important feature of Makela skin
and it's also very beneficial to our
mutual users so I'd like to bring John
Calhoun up on stage to actually take you
through the session thank you
hi let's see okay well I'm going to talk
real quickly about PDF get just to tell
you what it is and then I'm going to go
quickly to a demo to kind of show you
what it is here's sort of a diagram
shows you more or less where your
application fits in PDF kit it's
basically a suite of cocoa classes so
you know to make a parallel to WebKit
isn't a big stretch in fact there was a
lot of inspiration that we had from from
the web kit demo last year and this year
when we were working on preview for
Tiger what we decided to do was to
create like a PDF kit there was a lot
like WebKit and you'll see that the
preview application that's in Tiger is
using for these for the PDF portion of
preview is using PDF get so i guess i'll
go ahead and show you yeah the new
preview so i'll start the demo and this
is tiger this is on your developer disk
and here's the preview and probably at
this point this being sort of early and
tiger there's not going to be a lot
different from what you've seen say in
panther but i'll show you a couple of
new things and keep in mind that unlike
Panther this version of preview is
strictly using PDF get so I've opened up
a PDF you can select text we can scroll
through the taxes per usual but also PDF
kid is going to handle links and you see
the hand turning into a pointer and
returning to a pointing hand the cursor
you click on it it takes you to that
page that sort of thing one of the new
features we added to preview by way of
PDF get is you can now view facing pages
for example and so here's two up and if
you want the cover sheet to be or the
first page to be separated itself I can
turn on what we call book mode
and so now the first page is stands by
itself and then it starts with the even
numbered pages from then on one of the
other nice thing that we're able to do
for example in two up is you can select
text across multiple pages if i zoom out
I can you know grab text across four six
eight however many pages you can you can
see and all this again is using PDF get
I'll show you another document that's
kind of interesting i clicked on this
widget up here and it doesn't work
because this document doesn't have a
crop box that's any different from its
media box I do want to point that out
because one of the reasons is showing
these demos and advances I'll show you
something graphically and then when I
get talking more about PDF kit you'll
see you know what you'll know what
concepts I'm talking about so I've got a
document here it's a PDF and when you
default open it up on the screen you see
you see the part of the PDF page that's
defined by the pdfs crop box but if I
flip this little widget you can see the
whole PDF and you can see that there are
some registration marks and some other
things this is actually the way the PDF
would go off to the printer but one of
the things they try to do not only just
for the crop boxes are sorry for the
registration marks and such is sometimes
the way a PDF gets printed will have a
lot of white space around the margin so
oftentimes the PDF will define a crop
box so that when you're viewing it on a
computer screen you're not wasting
screen real estate with all this you
know extra margin so this is the way you
might you might want to you might view
it on the computer and the last thing
I'll show you on this sort of
introduction to the preview demo is
something we just added for tiger here's
a 1040ez and if I click somewhere here
I can then cab does hit testing that
sort of thing and I think this checkbox
should check and uncheck that sort of
thing so we're starting to add more
annotation support and the Panther
version of preview just had links those
were the only annotations we supported
and as you'll see when I show you the
rest of these slides we've got a lot
more annotation support in the new
version of preview but the point I'm
trying to make is that we got this by
way of PDF kits so in the same sense
that if your application uses PDF gade
you're going to get these same features
yourself so I'll switch back to the
slides and where did I leave that
clicker okay well I'm going to backtrack
just just briefly and talk about the PDF
file format I'm going to talk a lot
about it but if you know the PDF is a
file format and inside that PDF file you
have dictionaries you have objects like
page objects font objects that sort of
thing there's streams for drawing a PDF
can be encrypted and you in which case
you need a password to decrypt it
they're very rich it's a very rich file
format and as I showed with like the the
forms in 1040ez and with links there can
be annotations inside of PDF and I
pointed out the display boxes the media
box crop box so you know PDFs have all
this kind of you know sort of rich
features in them I'll briefly mention
the coordinate system too because it
turns out it comes into play quite a bit
when I talk about some of the kind of
lower levels of the PDF get PDFs our
Cartesian coordinate system it's
quadrant one so the lower left corner of
the page is the origin 0 0 and as you
move to the right numbers increase as
you move up they increase and the units
that are used inside a PDF our endpoints
so 72 points to an inch
well so core graphics has a rich API for
dealing with PDFs and that's been in
there for a long long time but there are
sea functions and they may sit up on
they sit on top of core foundation so
they have core foundation type objects
you have things like CG PDF document ref
cg PDF page raf and that sort of thing
but it's relatively low level in in that
it's it's it's fairly close to the file
it kind of mirrors more or less the file
format itself so what we tried to do in
PDF kit is to create a suite of cocoa
classes and in some ways we mirrored
core graphics in you know our decision
to make a document object and a page
object and I'll get more I'll talk more
about that later but you know it's
probably interesting to know that
internally we're calling core graphics
and we're calling core foundation and
we're doing some of these things but
what we present because the developers
is you know the objective-c the methods
and objects and that sort of thing and
as I mentioned there's you'll see that
there's like PDF documents and pages so
in that way it's we kind of borrowed
from core graphics here's a class
hierarchy I'll go into a lot more detail
so I'm just putting this up for now you
see that I haven't showed all the
classes here but you see there are a
number of a number of classes in blue
that are subclass of nsobject and then
the PDF view the one orange one is I
guess you'd call more or less the higher
level class and that's probably a good
way to start talking about PDF kit is
that there's kind of I guess two levels
of classes there's the high level PDF
view and that's nice because you can
just drop it into your app it does the
kind most of the kinds of things you see
in preview it will display a PDF that
allow you to select tax copy traversal
links that sort of thing so it makes it
very simple if you want to get PDF
display up and you up in your app very
quickly but if you want to do more
powerful things and have more
flexibility there's a whole suite of
these utility classes
and in fact the PDF view itself is built
on top of those utility classes and
those are the ones in blue like the PDF
border destination that sort of thing so
i'll show you another demo I'm kind of
doing this in reverse order i'm showing
you the demo first and then talking
about what you saw i'm going to do the i
guess this is a kind of a famous no code
demo the WebKit did it so we're going to
do it too so i'm going to fire up
interface builder and one thing that I
did before I before I came up here is I
went to interface builder I went ahead
and added the PDF kit palette which
you'll find in developer extras palettes
and so since I've added the PDF kit
palette I just create a new Koko
application here you'll see that there's
this new PDF icon in the in the palette
and so this object here is a PDF view
I'll just drag it in and into this
window here and let's see I think I'll
just add a couple of buttons you know
put a back button in and i'll do a doom
button and i'll do some of the worst you
I you've ever seen it's not too bad ok
so let's zoom in zoom out and and we set
the sizes on all these like that stretch
and this guy do this and this guy do
that and then and I guess the last thing
I need to do is wire them up so I'll
just make that do and here's some of the
some of the outlets or some of the
methods that are exported from the PDF
you go back that's pretty nice one
interface builder guess is that well
couldn't guess that one that's zoom out
and we'll make this one zoom in so what
I'll do is so you may wonder how you're
going to actually display PDF I'll test
the interface here and there we go PDF
view supports drag and drop so let me
just take a PDF here here's a nikon
documentation and there you go so I
haven't written any code it looks like I
messed up my bounds on the PDF you and I
dropped it in but I can see there were
some links up front here see we can jump
down to page 12 back good we can zoom
out zoom back in no okay we try one
other thing the PDF he also has a
contextual menu oh there we go I don't
know what my failing is there with the
with those buttons but so there there's
a PDF view all done an interface builder
so I'll switch back to the slides and
talk about the PDF view itself so you
saw the PDF view I put it in interface
builder it's subclass of NS view so good
they fix that slide so it inherits
everything that NS view inherence its
responder so it has mouth down mouth up
type methods that sort of thing and as I
mentioned earlier it uses all the
utility classes so it uses a PDF
document object PDF page object that
sort of thing in fact in as much as it's
just sitting on top of those utility
classes there's nothing to keep you
developers from you know if you don't
like what PDF view does maybe one up and
and two up isn't enough you want to do
three up you can write your own PDF you
you can just call the utility classes
yourself and do all the sorts of things
that PDF view does for displaying the
pages and that sort of thing and it's
just going to say it's not a lot of work
but obviously it's a lot easier to use
the PDF view itself and one of them's
but weddings we try to do
is so that you didn't have to go and
write your own PDF view we tried where
we could to make the PDF you itself sort
of flexible for sub classes so that you
could come in and subclass and override
the events the mouse down mouth up Mouse
drag and do your own thing and I'll show
you at the end of the session here I'll
show you kind of a demo where I do that
there's also every time the PDF few
drawers there's draw method that gets
called if you want a sub class or
override that then you can handle the
page drawing yourself so some general
features of PDF you as you saw you can
display PDF and several modes one up two
up continuous not continuous that sort
of thing it also works to a screen
reader so this is kind of interesting if
you're someone like an accessibility if
like someone who's not sighted and comes
across a PDF if your app is using PDF
view they'll be able to using screen
reader be able to get the text of the
PDF for free so you don't have to write
any code to enable that as copy select
text those kinds of preview type things
just you get for free in PDF view as
well as printing so I'm I'm going to get
more specific features then so a PDF
view needs a document in a way so you
you tell PDF you here's a PDF document
and once the document has been
associated with the view then it'll just
it will display that document and you
know give you you know allow the user to
navigate the pages and that sort of
thing the way you create a document is
you create one of the PDF document
objects and I'll talk about that a
little later in the session let you
create these objects with either URL
which maybe you have a file on disk so
you create a URL for that create this
PDF document pass it to the view and now
you're Rita now you're looking at that
you looking at that PDF or sometimes you
might be you might be a plugin for a
browser and you don't get a PDF file per
se you get a chunk of NS data so NS data
is another way to initialize to create a
PDF documents and then then the view is
there
or you know displaying the contents of
that NS data as I showed you in the
interface builder demo the view also
supports drag and drop so there's some
pretty complicated display modes we
tried to make it flexible enough
initially for preview but then you know
we're trying to think sort of you know
beyond preview and what other people
might want so you know you can choose
whether you want one up to continuous
non-continuous but you can also specify
whether you want the crop box or the
media box what display box you want
they're scaling you saw me zoom in zoom
out you can control that text creaking
you can specify at what pixel size you
want the text to be Greek which is to
say once it falls below a certain size
like say three pixels it gets to be kind
of wasting performance wise to draw each
little you know curve of the letter C so
you turn Greek enon set it to say three
pixels and the text will just be drawn
very quickly as gray boxes and I showed
you the book mode it's another mode and
there's other kinds of ways you can
control the display of the PDF you
turning on and off page breaks that sort
of thing and then there's a really rich
navigation API so you can say go to the
next page previous page first page last
page or go to page in also apart from
just sort of that sort of page level
navigation PDF view is maintaining a
history for you so as you tell it go to
page in its keeping a stack of where the
user has been so that go back and go
forward you know is another way of
navigating and you just tell the PDF you
go back and it'll jump back to the last
place the user is that before you said
you know go to page in and finally
there's other ways of navigating the PDF
you can say go to a specific destination
and i'll talk more about destinations
later or you can say you know scroll to
make the current selection visible that
sort of thing
and then there are other kinds of I just
called additional functionality other
things that don't really fit into an ice
bucket if the PDF is encrypted you can
pass in is a strength because there's a
method to pass in a string to try as a
password to decrypt it you can select
all you can specify selection you can
clear a selection and you can of course
select text copy and and it puts it up
on the pasteboard for you and and it
also allows you to print you just tell
the PDF for you to print and it prints
the current document okay so I guess
this time around I'm going to show
preview again and what's that going to
do this time I guess I was going to show
I guess what I might call slightly more
advanced preview functions that are
going to that are going to I think
they're going to make sense when I start
talking about the utility classes let's
see I guess I'll open up a PDF that has
a kind of a rich outline because we'll
talk about outlines and at court
studiare okay on the right-hand side
you'll see the outline and this is just
the way Panther displayed it as well and
I can twist down some of these some of
these little outline objects have
children and you can twist down the
disclosure triangle and see some of the
children of these outline objects and
when I click on one of these things PDF
you just zip Scrolls down to the
destination that this outline points to
another thing that I'll just show you
it's created obvious stuff but let's do
a search like it'll search for PDF okay
so here's here's a list of you know all
the instances of PDF that are found and
again as i go and scroll through this
list of of the search results PDF view
is jumping around and showing you and
selecting and highlighting the selection
so I want to show you one other thing
before I switch back to the slides I'll
show you as an annotations PDF I made up
so here's a here's kind of a nutty file
I made up that has all kinds of patience
on it and you see well I the first one
up there it's actually a text annotation
and you see squares and circles and ink
and that sort of thing if I if I drag
across here to select you'll see that
you'll be able to see kind of what part
of the PDF is the text and what part is
the annotation all the stuff that's
getting selected there is text obviously
but you know i can't select the ink and
I can't you know select the squares and
that sort of thing so I guess with that
I'll go back to the slides and I'll tell
you more about some of the utility
classes and and we'll talk about
annotations a little more so here's
here's actually the full list of utility
classes and what I'd left off on the
previous example when I showed this was
I left off all the annotation subclasses
we'll get to those in a second I'll have
to start with PDF document PDF document
is sort of well it represents the file
or the data that you have the actual PDF
file and so it's the most important
object you have to have a PDF document
even a PDF view needs a PDF document and
it's kind of a wellspring I mean that's
where pages are going to come from
that's where you know eventually outline
is going to come from and that sort of
thing as I already told you you can give
it a URL or you can give it data and
that's how you initialize the PDF
document you once you have this PDF
document object there's all kinds of
methods to give you the attributes of
the document is a what PDF version is it
is it encrypted is you know is who is
the author of the Creator the title
keywords that sort of thing and if it's
encrypted there's methods on the
document that allow you to try to
decrypt it and if it's a kind of
document where they have both sort of
like owner privileges and user
privileges you can find out what
privileges you have like
have the ability to print you and can
you copy that sort of thing in fact PDF
view respects the privileges so if you
open a PDF using PDF view and the the
user doesn't have owner privileges isn't
able to print then the print method will
just fail I'm you can call down to the
document and find out that there's no
print permissions if you want to disable
the print menu or put up a dialog or
something like that PDF document also
has a right writing methods now if you
got the PDF from a file and you want to
write the PDF document out since you
already have this file you might as well
just you know copy the file but when you
call the PDF documents right methods
what it does is it sort of encapsulates
anything any changes you may have made
to the PDF document so if you've removed
the page or rotated a page or removed an
annotation or something like that then
when the PDF document is written out to
disk it will reflect all these changes
you've made and I showed you a quick
find in preview PDF document is the
level that you do that so you you you
call find methods on the PDF document
what that allows you to do is since it's
at the document level is first of all it
can start going through in sort of an
asynchronous way and walk through page
by page by page for you and just in
notifications each time it finds you
know the search term that you're looking
for also there's the capability to find
a phrase say that's broken across page
boundaries so if you were looking for a
phrase and part of it was on one page
and the second part was you know
following on the next page at the
document level you'll be able to find
that sort of thing and finally I don't
have to get into more detail a little
later about this a PDF document is one
area where you can ask for a PDF
selection object a probably a trivial
example for the PDF document level is if
you wanted to do a select all then
that's where you do it at the document
level and the document would give you
back a PDF selection object that
represents all the text in the PDF in
the entire document and finally and this
is probably the most important part of
the PDF document
that's where you get the pages that's
where you get the page objects so i'll
talk about pages next oh I guess
obviously there's method on the document
where you can ask for the number of
pages say 43 so on the document you
would say okay 43 pages give me page
number 41 and what you'll get return is
a PDF page object now this one has a
graphic the slide has a graphic and
that's because pages are the first class
that I'm going to talk about that have
draw method so I've got a screenshot of
preview here and I've circled a few
things so that you can see just give you
an idea of some of the methods that a
page a PDF page has you've got of course
balance and rotation so that'll tell you
how many points wide and tall that sort
of thing the pages page can return to
you a label now I've circled that in the
lower corner I think it's page 41 there
so if you ask for this page is label
you'd get back the string 41 but there's
some pdf.pdf swear they'll describe the
page label as you know I or I i if it's
you know a preface or something like
that so the page label tells you you
know gives you a string that represents
you know what to label that page of
course you can get texts from a PDF and
I've shown a orange box around the
bottom that's at the page levels where
you can extract text annotations and
I've circled a link annotation us you
access those at the page level and as I
mentioned the PDF page has a draw method
so you can tell the PDF page you know
bra draw using your crop box drawing
this rectangle and then PDF page will
take care of scaling to that rectangle
that sort of thing you can kind of maybe
as I'm describing this maybe you can
kind of in your head sort of see how PDF
you really is just calling these sorts
of things and it's it's asking it's
asking the document for the number of
pages it's laying out its views when the
user Scrolls and it wants to show page
three at tap it gets page 3 from the
document tell us that page to draw that
sort of thing annotations so PDF
annotation itself the class PDF
annotation is an abstract class
so it's an error if you call the
initializer on it doesn't mean anything
the two things that an annotation
absolutely is required to have is a type
and a bounds so what we've done is you
actually call the subclass initializer
so if you wanted a PF annotation circle
for example you'd call PDF annotation
circle Alec and then the method is a
nitwit bounce so once you've done that
the annotation is legal it has a type
circle and it has a balance now a lot of
the annotations share a lot of things
besides the bounds and type things like
color is one that's common so you'll
find inside the PDF annotation class
you'll find methods like color kind
bound that sort of thing contents these
are things that are just generally used
by annotations but for some of the
annotations subclasses like you know
circle and ink annotation lines there
are going to be some attributes specific
to that subclass I think line is a good
example you see there's starting and
ending type so it can either have a
square on the end or triangle or it'd be
dashed and that sort of thing so it's
only going to make sense to call you
know get line ending style on a PDF
annotation line so that's kind of the
way the annotations are organized they
also have a draw method and if you can
you can draw them individually if you
want but if a bit is set on the page
when you tell the page draw the page
will go and draw all of its annotations
and I probably should have mentioned
there's a way on PDF page that you can
add and remove annotations and turn on
and off this bit to say whether or not
to display or not display its
annotations okay I'll get to okay
outline so I guess we're going to step
back again to the document PDF outline I
showed you that in the preview example
you ask the document not all pdfs have
an outline it's in in other words the
the author that created the PDF may not
have taken the time to you know add a
list of chapters and subchapters and
subheadings and that sort of thing
but if they did then you asked the PDF
document for the route outline and what
you get back is one of these PDF outline
objects and i guess i can probably best
described them by referring to the
example that's on the screen there so
the first thing that PDF outline objects
will have our i probably should tell
describe these in a different order can
have children and the route outline
always has children it's kind of the one
outlined object that doesn't have a
label it just has children and in this
example the children are all the outline
objects that you see i guess the first
level i say of the of the objects you
see so the first child being one that's
called contents the next one figures and
the next one about this book you see the
disclosure triangle that PDF outline
will have children so if you turn down
the triangle you'll see the children of
that PDF outline object all of these
outline objects have a label that's
what's actually being displayed there so
contents is the label for the first
child PDF outline the other important
thing and I showed this in preview is
that PF outlines have a destination so
that specifies when the user clicks on
this outline where do we go most of the
time the destination will refer to some
place within the PDF document you know
maybe page 27 you know at certain point
on the on that page but they can just as
well describe a URL or something they
can actually point to another PDF
document itself or point to some place
on the web and that's a good sort of
segue into PDF destination so PF
destination is kind of an abstraction of
like I this idea of where you're going
to go when you click on a thing or
something PDF outlines as i mentioned
have destinations but also a PDF
annotation link has a destination when
user clicks on this link is it going to
open you know your browser and take you
to a web page or is it going to go down
to page you know 13 or whatever if the
document so it can be a destination can
be a point
on a page and a page for a document or
it can be a URL and I made a comment
here about the back and forward history
PDF view internally is using PDF
destinations to keep the back forward
history so when user says when when you
say go to page you know say 10 PDF view
will make a destination for the current
location say the users at page one and
push that on to a stack so then when you
later say to the PDF you go back it just
pulls that destination off the stack and
says to the view says to itself go to
this destination and PDF selection so
this is another one that's kind of an
abstraction you see an example there
there's some text that's selected I mean
that's a pretty obvious you know that's
what a PDF selection is visually but
internally what it is is it's it's
always associated with a specific PDF
document doesn't make sense to have you
know a selection on one document and
then you ask another document to make
this the current selection selections
are you know document specific can span
multiple pages so it's not just a range
it's not just you know from character 5
on this page to character 9 can span
multiple pages and can be discontinuous
it doesn't have to be continuous can be
the whole document they so I mentioned
that the that the PDF document class
itself has a methods where you can say
give me a selection representing I gave
the example you know the entire document
you did select all and within a page
level their selection methods so that
you can say for within a page you know
give me a selection that represents text
that's inside this rectangle or from
this character to that character so
that's how you create these PDFs
elections another way you get these PDFs
elections is that's actually a PDF
selection object is actually sort of the
coin that the search uses so that when
you ask to search for you know a word
like you know PDF in a document
every time it finds the instance of PDF
what it does this creates a PDF
selection object for that and returns
that to you and so there are methods
that you can call on the selection you
can find out the bounds of the selection
given you know for a given page space or
you can find out what page it's on and
that sort of thing and as you can also
see a PDF selection has a draw method as
well in this case it takes whatever the
current users highlight color is and it
draws in like i can multiply mode to
sort of overlay and you know PDF page
your PDF view but itself will draw the
selection for you so it's the kind of
thing that if you're using the higher
level PDF you don't have to really worry
about oh I skip this I might as well
mention you can you can add PDF
selections they're kind of bullying in
that way if you have a selection here in
a selection here you can tell this
selection to add that one likes say they
don't have to be contiguous if they
overlap you can the when you add the two
selections the parts that are overlaps
get removed so when you ask for the
string for a selection like in this
example here if you ask for the string
you'd get update the in if there was
overlap and you had two selections added
you might get you know multiple
characters but we get rid of all those
overlaps for you ok this is the fund mo
the more fun demo ah it's see ok so i
wrote this little app and I'd like to
say I wrote it in an hour but it took a
little longer than that and i called it
PDF kit linker and it's using PDF view
i'm just going to open this this
document here but one of the nice things
about it is since i'm using its if I
just use PDF you straight I get all
these kinds of things for free like you
know I can you know you see the tooltip
comes up this link is going to take me
to page 12 you see the cursor change
into the hand for free if I click on it
it handles the mouth down it jumps me
down to page 12 if I say go back
I've got that go back it jumps back to
the beginning so it's kind of recorded
all that but what i've done here is i've
added this little widget and if you
click on this i call it like edit mode
this is where the subclass of PDF you
really kicks in when you're not in edit
mode when you're what i call view mode
I'm just letting PDF view handle
everything so I'm still subclassing and
I'm still overriding the mouth down
mouth up but I'm just calling super I
call super and then let PDF you deal
with you know the hit testing the linked
reversal that sort of thing but if
you're in edit mode I thought well this
is where I'll have fun I'll take over
the mouth down the mouse drag that sort
of thing all even since I've subclassed
and overridden the draw method I'll call
super just so a PDF you can draw the
page but then I'm going to come along
after and I'm going to draw a gray
rectangle around any annotation that I
find so I can ask the view since the
draw method gets called I can say okay
give me all the annotations for that
page I could walk through the
annotations figure out which ones are
links i can get the bounds of those
linked annotations and i can draw a gray
rectangle and so that's what i'm doing
here and since I can handle hit testing
I can jump in and say oh you've clicked
on one of these linked annotations so
I'm going to remember that one and I'll
draw red and then i'll make this little
get info button up here enabled and then
when you click on it i'll ask that link
annotation what page you linked to and
it tells me page 12 so I say okay well I
want to change that I see there's 12 77
here somos 77 pages i'll just type in
i'll type in 77 okay i'll go back into
view mode now when i move the mouse over
you can see that I've actually modified
that annotation I've changed its
destination 2.2 page 77 and when i click
on it sure enough i'm down here at page
77 and as just kind of more fun i go
back into edit mode create click on new
link I've just now created basically on
new annotation and I've told the page to
add this and I've specified the bounds
I'm doing hit testing here myself so I'm
allowing the user to resize the bounds
and if I get in so I just put some sort
of default values in page one well
here's that URL aspect I can a
destination can also have a URL so i'll
type in nikon's web page and hit done
now when I so what I've done now is I've
told that I've created this annotation
link I've said its destination to be
this URL I've added to the page so now
when i switch back to to view mode you
can see i'm kind of dragging on and off
that pfu recognizes oh there's an
annotation here and I click on it sure
enough it grabs the you it grabs the URL
it called Safari launches it takes you
to the nikon website so i think it took
maybe I don't know there's a lot of you
I here probably took a day or two
probably two days to write this so I'll
switch back to slides and I'll kind of
go into a little more detail on the sub
classing and you'll kind of know what
I'm talking about because you just saw
an example of it there so PDF view as I
mentioned earlier it's a subclass of NF
view subclasses and it's respond or so
it has mouse down mouse mouse drag so
you can you can override all these
yourself and that's what I was doing
when you know when I was in edit mode I
was going to hit I handled the mouse
down but when you want to be lazy and
you're in like I had View mode you can
always just call super and let you know
PDF you handle the mouse down itself one
thing that makes it a little easier and
this is why you know I mentioned I we
tried to make PDF you sort of extensible
and flexible so we have this method
called area of interest for mouse it's a
PDF view method and when you call area
of interest for mouse you pass a point
you know you pass you generally an NS
event and it takes that point and it
determines basically what interesting
area you're over it returns a bit feel
so it tells you whether you're over the
curve
for examples / page silver pages that
over texts over text is is there an
annotation there's an annotation is it a
link annotation so that makes a lot
easier certainly for like you know
cursor handling and that sort of thing
in fact eternally that's what PDF view
is doing is whenever there's a mouse
drag it calls or mouse move it calls you
know area of interest for mouth and then
it calls this other function other
methods set cursor for area of entrance
and that's where we have our logic where
we say okay well you know if you're over
a link that's more important than text
so change the cursor to be a pointing
finger if you're over text but no links
do an i-beam and that sort of thing but
if you want to change that behavior use
a subclass and override the set curse
your area of interest and put whatever
cursor you want I think in the example
there since I kind of was taking over I
didn't want the I didn't since you're
not going to be able to select text
because I'm handling the mouse down when
you're in edit mode I just set the
cursor to always be an arrow cursor or
accept no I guess I guess when you were
resizing the the link I changed to an
appropriate cursor to show you that you
could move the balance left and right up
and down that sort of thing one thing
that you have to do a lot if you
subclass and of course PDF view has to
do a lot of this internally it's kind of
converting from view space what I'll
call it to page space so if user have a
mouse down you know by way of PDF view
you have it sort of in view coordinates
you know that they clicked here in the
view so what you need to figure out is
first what page they click on if you're
trying to figure out if they clicked on
a link annotation you need to first
figure out if they click on a page so we
have this page for point method and you
pass in a point and it returns you the
page that the user page object
representing the point that the user
clicked on you know since there's border
sometimes around the page if the user
has zoomed out sometimes they can click
and it's not on a page but if you pass
in true for nearest then it will return
the nearest page in case the user didn't
actually click physically on a page so
once you have the page you want to
figure out okay
figure out what annotation I may have
these are may have clicked on I need to
get that point into that page of space
so there's the methods convert point and
convert Rex to page and convert point or
convert wrecked from page to page means
from the views coordinate system to the
page that I pass in so you know if I
found out from page for a point that I
was on you know a PDF page object that
represented page two and then I say
convert this point to page you know page
object that represents page 2 then this
function will return that point back in
that page is coordinates and say okay
it's this point this is the coordinate
in in that space so then I can ask the
PDF page page 2 or for example give me
your annotations and I can do a real
simple hit test on the balance of that
point now in page base to all the bounds
of the annotation because all these
methods on like the the PDF annotation
and on the page all the coordinates that
they use all the points and all the
bounds and rectangles are all in page
space they don't really care if the user
has zoomed in or is in to up mode or
anything like that so that's what these
methods do is they kind of bridge the
gap from the PDF view to you know the
pages space and the last thing is the
draw method so every time the PDF view
is resized or the user Scrolls or jumps
to a new page anytime a page needs to be
drawn there's this draw page method that
gets called and the only thing passed to
it is the PDF page object that needs to
be drawing now what I was doing and I
kind of describe it briefly in my demo
app is I've subclass PDF you and I've
overridden draw page but i'm lazy and i
want to let PDF you sort of draw the PDF
the selection and the annotations so i
just call super super draw page but when
that returns then i can go through and
draw you know the little gray rectangles
or that sort of thing each time if
you're in two up for example it'll get
called twice if your users looking at
two pages it'll get called twice so it's
not really you know like a direct method
I mean it's not called for the few it's
called for each page in the view or if
the user has scrolled down and you can
see bits and pieces of three pages then
the PDF the drop
method will get called three times once
for each page and i think that's it I
Travis going to come up and describe
this stuff I can tell you right off that
the PDF get palette is in extras develop
or developer extras palettes and there's
already sample code in developer
examples PDF kit and that app that I
just showed PDF linker will crop will
make that available but I started in
writing that app I started with this
sample code that's on your tiger DVD
does travis or somebody from the various
so we have some
so we have some documentation other
information that probably be will be
available to you later tonight what
we're doing with our sessions this year
is when we complete a session we have
supplementary information that we have
made of you know basically created after
everything was set and frozen to go in
the DVDs that you receive the tiger DVDs
we have these disc images you can
download off connect alkyl calm and
generally most sessions are going to
have them so you just basically go there
and look and general it's sometimes
going to be sample code so none just be
sample code and preliminary
documentation or both so we evidently
have some available for you for PDF kit
and then also we included a handy RL up
there for anyone who needs to really
take a close look at the adobe PDF
specification or as it is a
specification that it continues to grow
and then changes and get more powerful
it's handy to have the PDF reference on
hand if you're doing anything with PDF