summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-11-10 01:52:40 +0100
committerTor Andersson <tor.andersson@artifex.com>2011-11-10 01:52:40 +0100
commit97d00440c043b712a2d16134e3b52850c7b36d47 (patch)
treee7b838f3b7c714037bb238b0c4d17ab4aaa3e0ed /ios
parentc445538b312a45435df87086eed2e19b68ed5bc1 (diff)
downloadmupdf-97d00440c043b712a2d16134e3b52850c7b36d47.tar.xz
Add XPS outline parsing and move outline data struct to fz_outline.
Diffstat (limited to 'ios')
-rw-r--r--ios/document.c11
-rw-r--r--ios/document.h1
-rw-r--r--ios/main.m66
3 files changed, 39 insertions, 39 deletions
diff --git a/ios/document.c b/ios/document.c
index 85f8e381..6d30a0bc 100644
--- a/ios/document.c
+++ b/ios/document.c
@@ -43,6 +43,17 @@ open_document(char *filename)
}
}
+fz_outline *
+load_outline(struct document *doc)
+{
+ if (doc->pdf)
+ return pdf_load_outline(doc->pdf);
+ else if (doc->xps)
+ return xps_load_outline(doc->xps);
+ else
+ return NULL;
+}
+
int
count_pages(struct document *doc)
{
diff --git a/ios/document.h b/ios/document.h
index a16de309..1f59ccdd 100644
--- a/ios/document.h
+++ b/ios/document.h
@@ -23,6 +23,7 @@ struct document
};
struct document *open_document(char *filename);
+fz_outline *load_outline(struct document *doc);
int count_pages(struct document *doc);
void measure_page(struct document *doc, int number, float *w, float *h);
void draw_page(struct document *doc, int number, fz_device *dev, fz_matrix ctm);
diff --git a/ios/main.m b/ios/main.m
index 4b1c5f1c..3a6a45f3 100644
--- a/ios/main.m
+++ b/ios/main.m
@@ -1,7 +1,5 @@
#import <UIKit/UIKit.h>
-// TODO: [[UIScreen mainScreen] scale]; -- for retina iphone 4 displays we want double resolution!
-
#undef ABS
#undef MIN
#undef MAX
@@ -118,37 +116,27 @@ static void showAlert(NSString *msg)
[alert release];
}
-static int pageNumberFromLink(pdf_xref *xref, pdf_link *link)
+static void flattenOutline(NSMutableArray *titles, NSMutableArray *pages, fz_outline *outline, int level)
{
- if (link->kind == PDF_LINK_GOTO)
- return pdf_find_page_number(xref, fz_array_get(link->dest, 0));
- return -1;
-}
-
-static void loadOutlineImp(NSMutableArray *titles, NSMutableArray *pages, pdf_xref *xref, pdf_outline *outline, int level)
-{
- char buf[512];
- memset(buf, 0, sizeof buf);
- memset(buf, ' ', level * 4);
+ char indent[8*4+1];
+ if (level > 8)
+ level = 8;
+ memset(indent, ' ', level * 4);
+ indent[level * 4] = 0;
while (outline)
{
- int number = pageNumberFromLink(xref, outline->link);
- if (number >= 0) {
- [titles addObject: [NSString stringWithFormat: @"%s%s", buf, outline->title]];
- [pages addObject: [NSNumber numberWithInt: number]];
+ if (outline->page >= 0 && outline->title) {
+ NSString *title = [NSString stringWithUTF8String: outline->title];
+ [titles addObject: [NSString stringWithFormat: @"%s%@", indent, title]];
+ [pages addObject: [NSNumber numberWithInt: outline->page]];
}
- loadOutlineImp(titles, pages, xref, outline->child, level + 1);
+ flattenOutline(titles, pages, outline->down, level + 1);
outline = outline->next;
}
}
-static void loadOutline(NSMutableArray *titles, NSMutableArray *pages, pdf_xref *xref)
+static void loadOutline(NSMutableArray *titles, NSMutableArray *pages, struct document *doc)
{
- pdf_outline *outline = pdf_load_outline(xref);
- if (outline) {
- loadOutlineImp(titles, pages, xref, outline, 0);
- pdf_free_outline(outline);
- }
}
static void releasePixmap(void *info, const void *data, size_t size)
@@ -686,9 +674,7 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
- (id) initWithFile: (NSString*)nsfilename
{
- fz_error error;
char filename[PATH_MAX];
- char *password = "";
self = [super init];
if (!self)
@@ -711,20 +697,22 @@ static UIImage *renderTile(struct document *doc, int number, CGSize screenSize,
return nil;
}
- if (doc->pdf) {
- NSMutableArray *titles = [[NSMutableArray alloc] init];
- NSMutableArray *pages = [[NSMutableArray alloc] init];
- loadOutline(titles, pages, doc->pdf);
- if ([titles count]) {
- outline = [[MuOutlineController alloc] initWithTarget: self titles: titles pages: pages];
- [[self navigationItem] setRightBarButtonItem:
- [[UIBarButtonItem alloc]
- initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks
- target:self action:@selector(onShowOutline:)]];
- }
- [titles release];
- [pages release];
+ NSMutableArray *titles = [[NSMutableArray alloc] init];
+ NSMutableArray *pages = [[NSMutableArray alloc] init];
+ fz_outline *root = load_outline(doc);
+ if (root) {
+ flattenOutline(titles, pages, root, 0);
+ fz_free_outline(root);
+ }
+ if ([titles count]) {
+ outline = [[MuOutlineController alloc] initWithTarget: self titles: titles pages: pages];
+ [[self navigationItem] setRightBarButtonItem:
+ [[UIBarButtonItem alloc]
+ initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks
+ target:self action:@selector(onShowOutline:)]];
}
+ [titles release];
+ [pages release];
return self;
}