summaryrefslogtreecommitdiff
path: root/ios
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2011-10-25 00:01:21 +0200
committerTor Andersson <tor.andersson@artifex.com>2011-11-01 23:46:57 +0100
commitd2bed7099b64a6792adefc9bf0bef7da3e2cbd0e (patch)
tree7028f3a72335f42ee6953e100b493fc97b1169aa /ios
parentc9987c352a3cd23f1ef5f5d5ffa444fb3634ffdd (diff)
downloadmupdf-d2bed7099b64a6792adefc9bf0bef7da3e2cbd0e.tar.xz
Add Table of Contents / Outline view.
Diffstat (limited to 'ios')
-rw-r--r--ios/MuPDF.xcodeproj/project.pbxproj3
-rw-r--r--ios/build_libs.sh38
-rw-r--r--ios/main.m115
3 files changed, 124 insertions, 32 deletions
diff --git a/ios/MuPDF.xcodeproj/project.pbxproj b/ios/MuPDF.xcodeproj/project.pbxproj
index a960180b..a70ca95e 100644
--- a/ios/MuPDF.xcodeproj/project.pbxproj
+++ b/ios/MuPDF.xcodeproj/project.pbxproj
@@ -107,8 +107,8 @@
96A3B27414539BAD00D0A895 = {
isa = PBXGroup;
children = (
- 968F2EB214539F230085264E /* Libraries */,
968F2E9214539BF10085264E /* Sources */,
+ 968F2EB214539F230085264E /* Libraries */,
968F2E9A14539C880085264E /* Frameworks */,
968F2E9814539C880085264E /* Products */,
);
@@ -292,6 +292,7 @@
968F2EAF14539C880085264E /* Release */,
);
defaultConfigurationIsVisible = 0;
+ defaultConfigurationName = Release;
};
96A3B27914539BAD00D0A895 /* Build configuration list for PBXProject "MuPDF" */ = {
isa = XCConfigurationList;
diff --git a/ios/build_libs.sh b/ios/build_libs.sh
index 255289f3..8095571f 100644
--- a/ios/build_libs.sh
+++ b/ios/build_libs.sh
@@ -10,35 +10,23 @@ make -C .. generate || exit 1
export OS=ios
export build=$(echo $CONFIGURATION | tr A-Z a-z)
-for ARCH in $ARCHS
-do
- case $ARCH in
- armv6) ARCHFLAGS="-arch armv6 -mno-thumb" ;;
- armv7) ARCHFLAGS="-arch armv7 -mthumb" ;;
- *) ARCHFLAGS="-arch $ARCH" ;;
- esac
+case $ARCHS in
+ armv6) ARCHFLAGS="-arch armv6 -mno-thumb" ;;
+ armv7) ARCHFLAGS="-arch armv7 -mthumb" ;;
+ i386) ARCHFLAGS="-arch i386" ;;
+ *) echo "Unknown architecture!"; exit 1 ;;
+esac
- export CFLAGS="$ARCHFLAGS -isysroot $SDKROOT"
- export LDFLAGS="$ARCHFLAGS -isysroot $SDKROOT"
- export OUT=build/$build-$OS-$ARCH
+export CFLAGS="$ARCHFLAGS -isysroot $SDKROOT"
+export LDFLAGS="$ARCHFLAGS -isysroot $SDKROOT"
+export OUT=build/$build-$OS-$ARCHS
- echo Building libraries for $ARCH.
- make -C .. libs || exit 1
-done
+echo Building libraries for $ARCHS.
+make -C .. libs || exit 1
-echo Performing liposuction into $BUILT_PRODUCTS_DIR.
+echo Copying files into $BUILT_PRODUCTS_DIR.
mkdir -p "$BUILT_PRODUCTS_DIR"
-
-for LIB in ../$OUT/lib*.a
-do
- LIB=$(basename $LIB)
- IN=""
- for ARCH in $ARCHS
- do
- IN="$IN ../build/$build-$OS-$ARCH/$LIB"
- done
- lipo $IN -output $BUILT_PRODUCTS_DIR/$LIB -create
-done
+cp ../$OUT/lib*.a $BUILT_PRODUCTS_DIR
echo Done.
diff --git a/ios/main.m b/ios/main.m
index f82dd0d9..4d23936a 100644
--- a/ios/main.m
+++ b/ios/main.m
@@ -29,9 +29,20 @@
- (void) reconfigure;
- (void) loadPage: (int)number;
- (void) unloadPage: (int)number;
-- (void) gotoPage: (int)number;
+- (void) gotoPage: (int)number animated: (BOOL)animated;
- (void) didSingleTap: (UITapGestureRecognizer*)sender;
- (void) toggleNavigationBar;
+- (void) showOutline: (id)sender;
+@end
+
+@interface MuOutlineController : UITableViewController
+{
+ MuDocumentController *document;
+ NSMutableArray *titles;
+ NSMutableArray *pages;
+}
+- (id) initWithStyle: (UITableViewStyle)style xref: (pdf_xref*)xref outline: (pdf_outline*)outline;
+- (void) gotoPage: (int)number;
@end
@interface MuAppDelegate : NSObject <UIApplicationDelegate, UINavigationControllerDelegate>
@@ -213,6 +224,89 @@ static UIImageView *new_page_view(pdf_xref *xref, int number, float width, float
#pragma mark -
+@implementation MuOutlineController
+
+static void loadOutline(NSMutableArray *titles, NSMutableArray *pages, pdf_xref *xref, pdf_outline *outline, int level)
+{
+ char buf[512];
+ memset(buf, 0, sizeof buf);
+ memset(buf, ' ', level * 4);
+ while (outline)
+ {
+ [titles addObject: [NSString stringWithFormat: @"%s%s", buf, outline->title]];
+ [pages addObject: [NSNumber numberWithInt: get_page_number(xref, outline->link)]];
+ printf("-- %s\n", outline->title);
+ loadOutline(titles, pages, xref, outline->child, level + 1);
+ outline = outline->next;
+ }
+}
+
+- (id) initWithStyle: (UITableViewStyle)style document: (MuDocumentController*)document xref: (pdf_xref*)xref outline: (pdf_outline*)outline;
+{
+ self = [super initWithStyle: style];
+ if (self)
+ {
+ [self setTitle: @"Table of Contents"];
+ self->document = [document retain];
+ titles = [[NSMutableArray alloc] init];
+ pages = [[NSMutableArray alloc] init];
+ loadOutline(titles, pages, xref, outline, 0);
+ }
+ return self;
+}
+
+- (void) dealloc
+{
+ [document release];
+ [titles release];
+ [pages release];
+ [super dealloc];
+}
+
+- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)o
+{
+ return YES;
+}
+
+- (NSInteger) numberOfSectionsInTableView: (UITableView*)tableView
+{
+ return 1;
+}
+
+- (NSInteger) tableView: (UITableView*)tableView numberOfRowsInSection: (NSInteger)section
+{
+ return [titles count];
+}
+
+- (UITableViewCell*) tableView: (UITableView*)tableView cellForRowAtIndexPath: (NSIndexPath*)indexPath
+{
+ static NSString *cellid = @"MuCellIdent";
+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: cellid];
+ if (!cell)
+ cell = [[[UITableViewCell alloc] initWithStyle: UITableViewCellStyleValue1 reuseIdentifier: cellid] autorelease];
+ NSString *title = [titles objectAtIndex: [indexPath row]];
+ NSString *page = [pages objectAtIndex: [indexPath row]];
+ [[cell textLabel] setText: title];
+ [[cell detailTextLabel] setText: [NSString stringWithFormat: @"%d", [page intValue]+1]];
+ return cell;
+}
+
+- (void) tableView: (UITableView*)tableView didSelectRowAtIndexPath: (NSIndexPath*)indexPath
+{
+ NSNumber *page = [pages objectAtIndex: [indexPath row]];
+ [self gotoPage: [page intValue]];
+}
+
+- (void) gotoPage: (int)number
+{
+ [[self navigationController] popViewControllerAnimated: YES];
+ [document gotoPage: number animated: NO];
+}
+
+@end
+
+#pragma mark -
+
@implementation MuDocumentController
- (id) initWithFile: (NSString*)nsfilename
@@ -266,7 +360,7 @@ static UIImageView *new_page_view(pdf_xref *xref, int number, float width, float
[[self navigationItem] setRightBarButtonItem:
[[UIBarButtonItem alloc]
initWithBarButtonSystemItem: UIBarButtonSystemItemBookmarks
- target:self action:@selector(toggleNavigationBar)]];
+ target:self action:@selector(showOutline:)]];
[self setToolbarItems:
[NSArray arrayWithObjects:
@@ -367,14 +461,14 @@ printf("unload %d\n", number);
}
}
-- (void) gotoPage: (int)number
+- (void) gotoPage: (int)number animated: (BOOL)animated
{
if (number < 0)
number = 0;
if (number >= pdf_count_pages(xref))
number = pdf_count_pages(xref) - 1;
current = number;
- [canvas setContentOffset: CGPointMake(current * width, 0) animated: YES];
+ [canvas setContentOffset: CGPointMake(current * width, 0) animated: animated];
}
- (void) scrollViewDidScroll: (UIScrollView*)scrollview
@@ -425,8 +519,8 @@ printf("unload %d\n", number);
float x1 = width - x0;
p.x -= ofs.x;
p.y -= ofs.y;
- if (p.x < x0) [self gotoPage: current - 1];
- else if (p.x > x1) [self gotoPage: current + 1];
+ if (p.x < x0) [self gotoPage: current - 1 animated: YES];
+ else if (p.x > x1) [self gotoPage: current + 1 animated: YES];
else [self toggleNavigationBar];
}
@@ -443,6 +537,15 @@ printf("unload %d\n", number);
[canvas setContentInset: UIEdgeInsetsZero];
}
+- (void) showOutline: (id)sender
+{
+ pdf_outline *outline = pdf_load_outline(xref);
+ MuOutlineController *ctl = [[MuOutlineController alloc] initWithStyle: UITableViewStylePlain document: self xref: xref outline: outline];
+ [[self navigationController] pushViewController: ctl animated: YES];
+ [ctl release];
+// pdf_free_outline(outline);
+}
+
@end
#pragma mark -